diff --git a/CHANGELOG.md b/CHANGELOG.md index 9d9402641..0868ee482 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,30 @@ +Release 4.14 (2015-02-03) +------------------------------------------------------------------------------ + +* New event hook: + * onBeforeThemeSettingsSave +* New API(client) calls: + * invoice_get_tax_rate + * client_is_taxable + * client_balance_get_total +* Taxes are shown in the cart checkout summary +* Email templates are generated after install +* Footer links fix for Huraga theme +* Only one coupon code name can be created and used; +* Fixed CKEditor issue with canned responses +* Custom payment gateway render error fixed +* Fixed Centova Cast module +* Password hash in email resolved +* Orderbutton module popup improved +* Client email confirmation logic updated +* Variables in email templates list fixed +* Generating email templates just after installing of BoxBilling +* Allow only text in Notification module messages +* Fixed constantly regenerating invoices issue +* Add funds logic updated +* Settings of footer links updated +* Security and performance fixes and updates + Release 4.13 (2015-01-15) ------------------------------------------------------------------------------ diff --git a/Vagrantfile b/Vagrantfile index 67f178920..2545df21c 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -5,7 +5,11 @@ dir = File.dirname(File.expand_path(__FILE__)) configValues = YAML.load_file("#{dir}/puphpet/config.yaml") data = configValues['vagrantfile-local'] -Vagrant.require_version '>= 1.6.0' +begin + Vagrant.require_version ">= 1.6.0" +rescue NoMethodError + raise 'BoxBilling is only supported on Vagrant >= 1.6. Please upgrade.' +end Vagrant.configure('2') do |config| config.vm.box = "#{data['vm']['box']}" diff --git a/puphpet/config.yaml b/puphpet/config.yaml index d8d9e7a17..9f5eb4e3f 100644 --- a/puphpet/config.yaml +++ b/puphpet/config.yaml @@ -3,7 +3,7 @@ vagrantfile-local: vm: box: puphpet/ubuntu1204-x64 box_url: puphpet/ubuntu1204-x64 - hostname: 'boxbilling' + hostname: 'boxbilling.test' memory: '512' cpus: '1' chosen_provider: virtualbox diff --git a/src/bb-modules/Activity/Service.php b/src/bb-modules/Activity/Service.php index 1b88454a7..bf063e5cd 100644 --- a/src/bb-modules/Activity/Service.php +++ b/src/bb-modules/Activity/Service.php @@ -92,6 +92,7 @@ class Service implements InjectionAwareInterface $search = isset($data['search']) ? $data['search'] : NULL; $priority = isset($data['priority']) ? $data['priority'] : NULL; $only_staff = isset($data['only_staff']) ? $data['only_staff'] : NULL; + $admin_id = isset($data['admin_id']) ? $data['admin_id'] : NULL; $only_clients = isset($data['only_clients']) ? $data['only_clients'] : NULL; $no_info = isset($data['no_info']) ? $data['no_info'] : NULL; $no_debug = isset($data['no_debug']) ? $data['no_debug'] : NULL; @@ -115,6 +116,11 @@ class Service implements InjectionAwareInterface $where[] = 'm.admin_id IS NOT NULL'; } + if($admin_id) { + $where[] = 'm.admin_id = :admin_id'; + $params[':admin_id'] = $admin_id; + } + if($only_clients) { $where[] = 'm.client_id IS NOT NULL'; } diff --git a/src/bb-modules/Cart/Service.php b/src/bb-modules/Cart/Service.php index 799259a4c..84ef27301 100644 --- a/src/bb-modules/Cart/Service.php +++ b/src/bb-modules/Cart/Service.php @@ -425,7 +425,7 @@ class Service implements InjectionAwareInterface ) ); - list($order, $invoice_id, $orders) = $this->createFromCart($client, $gateway_id); + list($order, $invoice, $orders) = $this->createFromCart($client, $gateway_id); $this->rm($cart); @@ -450,9 +450,8 @@ class Service implements InjectionAwareInterface ); // invoice may not be created if total is 0 - if ($invoice_id) { - $idata = $this->di['db']->getExistingModelById('Invoice', $invoice_id, 'Invoice not found'); - $result['invoice_hash'] = $idata->hash; + if ($invoice instanceof \Model_Invoice && $invoice->status == \Model_Invoice::STATUS_UNPAID) { + $result['invoice_hash'] = $invoice->hash; } return $result; @@ -460,18 +459,12 @@ class Service implements InjectionAwareInterface public function createFromCart(\Model_Client $client, $gateway_id = null) { - $cart = $this->getSessionCart(); - $cartProducts = $this->di['db']->find('CartProduct', 'cart_id = :cart_id', array(':cart_id' => $cart->id)); - if (count($cartProducts) == 0) { + $cart = $this->getSessionCart(); + $ca = $this->toApiArray($cart); + if (count($ca['items']) == 0) { throw new \Box_Exception('Can not checkout empty cart.'); } - $ca = $this->toApiArray($cart); - - $create_invoice = true; - if ($ca['total'] == 0) { - $create_invoice = false; - } $currency = $this->di['db']->getExistingModelById('Currency', $cart->currency_id, 'Currency not found.'); @@ -521,7 +514,7 @@ class Service implements InjectionAwareInterface $order->updated_at = date('c'); $this->di['db']->store($order); - $orders[] = $order->id; + $orders[] = $order; // mark promo as used if ($cart->promo_id) { @@ -568,44 +561,58 @@ class Service implements InjectionAwareInterface $i++; } - if ($create_invoice) { + if ($ca['total'] > 0) { //crete invoice if order total > 0 $invoiceService = $this->di['mod_service']('Invoice'); - $invoice_id = $invoiceService->prepareInvoice($client, array('client_id' => $client->id, 'items' => $invoice_items, 'gateway_id' => $gateway_id)); - $invoiceModel = $this->di['db']->load('Invoice', $invoice_id); - $invoiceService->approveInvoice($invoiceModel, array('id' => $invoice_id, 'use_credits' => true)); + $invoiceModel = $invoiceService->prepareInvoice($client, array('client_id' => $client->id, 'items' => $invoice_items, 'gateway_id' => $gateway_id)); - foreach ($orders as $oid) { - $o = $this->di['db']->load('ClientOrder', $oid); - $o->unpaid_invoice_id = $invoice_id; - $this->di['db']->store($o); - } + $clientBalanceService = $this->di['mod_service']('Client', 'Balance'); + $balanceAmount = $clientBalanceService->getClientBalance($client); + $useCredits = $balanceAmount >= $ca['total']; - $result = array($master_order, $invoice_id, $orders); - } else { - $result = array($master_order, null, $orders); - } + $invoiceService->approveInvoice($invoiceModel, array('id' => $invoiceModel->id, 'use_credits' => $useCredits)); - //activate orders if product is setup to be activated after order place or order total is $0 - $orderService = $this->di['mod_service']('Order'); - foreach ($orders as $oid) { - - $order = $this->di['db']->load('ClientOrder', $oid); - $oa = $orderService->toApiArray($order, false, $client); - $product = $this->di['db']->getExistingModelById('Product', $oa['product_id']); - if ($product->setup == \Model_ProductTable::SETUP_AFTER_ORDER || ($product->setup == \Model_ProductTable::SETUP_AFTER_PAYMENT && $oa['total'] - $oa['discount'] <= 0)) { - try { - $orderService->activateOrder($order); - } catch (\Exception $e) { - error_log($e->getMessage()); - $status = 'error'; - $notes = 'Order could not be activated after checkout due to error: ' . $e->getMessage(); - $orderService->orderStatusAdd($order, $status, $notes); + if ($invoiceModel->status == \Model_Invoice::STATUS_UNPAID) { + foreach ($orders as $order) { + $order->unpaid_invoice_id = $invoiceModel->id; + $this->di['db']->store($order); } } } - return $result; + //activate orders if product is setup to be activated after order place or order total is $0 + $orderService = $this->di['mod_service']('Order'); + $ids = array(); + foreach ($orders as $order) { + $ids[] = $order->id; + $oa = $orderService->toApiArray($order, false, $client); + $product = $this->di['db']->getExistingModelById('Product', $oa['product_id']); + try { + if ($product->setup == \Model_ProductTable::SETUP_AFTER_ORDER){ + $orderService->activateOrder($order); + } + + if ($ca['total'] <= 0 && $product->setup == \Model_ProductTable::SETUP_AFTER_PAYMENT && $oa['total'] - $oa['discount'] <= 0){ + $orderService->activateOrder($order); + } + + if ($ca['total'] > 0 && $product->setup == \Model_ProductTable::SETUP_AFTER_PAYMENT && $invoiceModel->status == \Model_Invoice::STATUS_PAID ){ + $orderService->activateOrder($order); + } + } + catch (\Exception $e) { + error_log($e->getMessage()); + $status = 'error'; + $notes = 'Order could not be activated after checkout due to error: ' . $e->getMessage(); + $orderService->orderStatusAdd($order, $status, $notes); + } + } + + return array( + $master_order, + isset($invoiceModel) ? $invoiceModel : null, + $ids, + ); } public function usePromo(\Model_Promo $promo) diff --git a/src/bb-modules/Client/Api/Client.php b/src/bb-modules/Client/Api/Client.php index 4558c2b97..f5efa0889 100644 --- a/src/bb-modules/Client/Api/Client.php +++ b/src/bb-modules/Client/Api/Client.php @@ -309,4 +309,19 @@ class Client extends \Api_Abstract return $pager; } + /** + * Get client balance + * @return float + */ + public function balance_get_total() + { + $service = $this->di['mod_service']('Client', 'Balance'); + return $service->getClientBalance($this->identity); + } + + public function is_taxable() + { + return $this->getService()->isClientTaxable($this->identity); + } + } \ No newline at end of file diff --git a/src/bb-modules/Client/Api/Guest.php b/src/bb-modules/Client/Api/Guest.php index feee154c6..47f87afed 100644 --- a/src/bb-modules/Client/Api/Guest.php +++ b/src/bb-modules/Client/Api/Guest.php @@ -119,9 +119,17 @@ class Guest extends \Api_Abstract $client = $service->guestCreateClient($data); + + if (isset($config['require_email_confirmation']) && (int)$config['require_email_confirmation']) { + if (!$client->email_approved) { + throw new \Box_Exception('Account has been created. Please check your mailbox and confirm email address.', null, 7777); + } + } + if(isset($data['auto_login']) && $data['auto_login']) { + try { - $this->login(array('email'=>$client->email, 'password' => $client->pass)); + $this->login(array('email'=>$client->email, 'password' => $data['password'])); } catch(\Exception $e) { error_log($e->getMessage()); } diff --git a/src/bb-modules/Client/Service.php b/src/bb-modules/Client/Service.php index 6a7847aa1..bed70300f 100644 --- a/src/bb-modules/Client/Service.php +++ b/src/bb-modules/Client/Service.php @@ -530,7 +530,7 @@ class Service implements InjectionAwareInterface { $this->di['events_manager']->fire(array('event'=>'onBeforeAdminCreateClient', 'params'=>$data)); $client = $this->createClient($data); - $this->di['events_manager']->fire(array('event'=>'onAfterAdminCreateClient', 'params'=>array('id'=>$client->id, 'password'=>$client->pass))); + $this->di['events_manager']->fire(array('event'=>'onAfterAdminCreateClient', 'params'=>array('id'=>$client->id, 'password'=>$data['password']))); $this->di['logger']->info('Created new client #%s', $client->id); return $client->id; @@ -546,7 +546,7 @@ class Service implements InjectionAwareInterface $data['status'] = \Model_Client::ACTIVE; $client = $this->createClient($data); - $this->di['events_manager']->fire(array('event'=>'onAfterClientSignUp', 'params'=>array('id'=>$client->id, 'password'=>$client->pass))); + $this->di['events_manager']->fire(array('event'=>'onAfterClientSignUp', 'params'=>array('id'=>$client->id, 'password'=>$data['password']))); $this->di['logger']->info('Client #%s signed up', $client->id); return $client; @@ -592,7 +592,13 @@ class Service implements InjectionAwareInterface return null; } - return $this->di['auth']->authorizeUser($model, $plainTextPassword); + $config = $this->di['mod_config']('client'); + if (isset($config['require_email_confirmation']) && (int)$config['require_email_confirmation']) { + if (!$model->email_approved) { + throw new \Box_Exception('Please check your mailbox and confirm email address.'); + } + } + return $this->di['auth']->authorizeUser($model, $plainTextPassword); } } \ No newline at end of file diff --git a/src/bb-modules/Client/html_admin/mod_client_settings.phtml b/src/bb-modules/Client/html_admin/mod_client_settings.phtml index 422c83f73..4e726e559 100644 --- a/src/bb-modules/Client/html_admin/mod_client_settings.phtml +++ b/src/bb-modules/Client/html_admin/mod_client_settings.phtml @@ -86,7 +86,7 @@
{% trans 'INFORMATION' %}: {% trans 'Email logging is not enabled. If you want to log sent mails to database, enable it in' %} + {% trans 'email settings.' %} +
+