From 7b5b94a8d86545b52e25651fec1deb17a5c67bf4 Mon Sep 17 00:00:00 2001 From: Vaidas Lungis Date: Thu, 29 Jan 2015 10:00:45 +0200 Subject: [PATCH 1/3] add new client api calls: client_is_taxable and invoice_get_tax_rate --- src/bb-modules/Client/Api/Client.php | 5 ++++ src/bb-modules/Invoice/Api/Client.php | 6 +++++ tests/bb-modules/Client/Api/ClientTest.php | 22 +++++++++++++++++ tests/bb-modules/Invoice/Api/ClientTest.php | 27 +++++++++++++++++++++ 4 files changed, 60 insertions(+) diff --git a/src/bb-modules/Client/Api/Client.php b/src/bb-modules/Client/Api/Client.php index 20f5cecdc..f5efa0889 100644 --- a/src/bb-modules/Client/Api/Client.php +++ b/src/bb-modules/Client/Api/Client.php @@ -319,4 +319,9 @@ class Client extends \Api_Abstract 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/Invoice/Api/Client.php b/src/bb-modules/Invoice/Api/Client.php index 1031cf9f2..d0c4c6348 100644 --- a/src/bb-modules/Invoice/Api/Client.php +++ b/src/bb-modules/Invoice/Api/Client.php @@ -195,4 +195,10 @@ class Client extends \Api_Abstract return $pager; } + + public function get_tax_rate() + { + $service = $this->di['mod_service']('Invoice', 'Tax'); + return $service->getTaxRateForClient($this->identity); + } } \ No newline at end of file diff --git a/tests/bb-modules/Client/Api/ClientTest.php b/tests/bb-modules/Client/Api/ClientTest.php index e63912588..09d26e1f3 100644 --- a/tests/bb-modules/Client/Api/ClientTest.php +++ b/tests/bb-modules/Client/Api/ClientTest.php @@ -200,5 +200,27 @@ class ClientTest extends \PHPUnit_Framework_TestCase { $this->assertEquals($balanceAmount, $result); } + + public function testis_taxable() + { + $clientIsTaxable = true; + + $serviceMock = $this->getMockBuilder('\Box\Mod\Client\Service')->getMock(); + $serviceMock->expects($this->atLeastOnce()) + ->method('isClientTaxable') + ->willReturn($clientIsTaxable); + + $client = new \Model_Client(); + $client->loadBean(new \RedBeanPHP\OODBBean()); + + $api = new \Box\Mod\Client\Api\Client(); + $api->setService($serviceMock); + $api->setIdentity($client); + + $result = $api->is_taxable(); + $this->assertInternalType('bool', $result); + $this->assertEquals($clientIsTaxable, $result); + + } } \ No newline at end of file diff --git a/tests/bb-modules/Invoice/Api/ClientTest.php b/tests/bb-modules/Invoice/Api/ClientTest.php index c21151ea4..fdd5aad9f 100644 --- a/tests/bb-modules/Invoice/Api/ClientTest.php +++ b/tests/bb-modules/Invoice/Api/ClientTest.php @@ -367,6 +367,33 @@ class ClientTest extends \PHPUnit_Framework_TestCase { $this->assertInternalType('array', $result); } + public function testget_tax_rate() + { + $client = new \Model_Client(); + $client->loadBean(new \RedBeanPHP\OODBBean()); + + $taxRate = 20; + + $invoiceTaxService = $this->getMockBuilder('\Box\Mod\Invoice\ServiceTax') + ->getMock(); + $invoiceTaxService->expects($this->atLeastOnce()) + ->method('getTaxRateForClient') + ->willReturn($taxRate); + + + $di = new \Box_Di(); + $di['mod_service'] = $di->protect(function ($service, $sub) use($invoiceTaxService){ + if ($service == 'Invoice' && $sub == 'Tax'){ + return $invoiceTaxService; + } + }); + $this->api->setDi($di); + $this->api->setIdentity($client); + + $result = $this->api->get_tax_rate(); + $this->assertEquals($taxRate, $result); + } + } From a11b08c9e42d280db299f55e665489b666e60cf4 Mon Sep 17 00:00:00 2001 From: Vaidas Lungis Date: Thu, 29 Jan 2015 10:38:57 +0200 Subject: [PATCH 2/3] add tax row at checkout summary --- .../html_client/mod_orderbutton_checkout.phtml | 11 ++++++++++- src/bb-themes/boxbilling/html/mod_cart_index.phtml | 11 ++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/bb-modules/Orderbutton/html_client/mod_orderbutton_checkout.phtml b/src/bb-modules/Orderbutton/html_client/mod_orderbutton_checkout.phtml index 900e2f7cb..13d92c014 100644 --- a/src/bb-modules/Orderbutton/html_client/mod_orderbutton_checkout.phtml +++ b/src/bb-modules/Orderbutton/html_client/mod_orderbutton_checkout.phtml @@ -145,9 +145,18 @@ {% endif %} + {% set tax_amount = 0 %} + {% if client.client_is_taxable %} + {% set tax_rate = client.invoice_get_tax_rate %} + {% set tax_amount = cart.total * tax_rate / 100 %} + + {% trans 'VAT'%} ({{ tax_rate }}%) : + {{ tax_amount | money_convert }} + + {% endif %} {% trans 'Total:' %} - {{ cart.total | money_convert }} + {{ (cart.total + tax_amount) | money_convert }} diff --git a/src/bb-themes/boxbilling/html/mod_cart_index.phtml b/src/bb-themes/boxbilling/html/mod_cart_index.phtml index c70322d90..7f5861afd 100644 --- a/src/bb-themes/boxbilling/html/mod_cart_index.phtml +++ b/src/bb-themes/boxbilling/html/mod_cart_index.phtml @@ -86,8 +86,17 @@
+ {% set tax_amount = 0 %} + {% if client.client_is_taxable %} + {% set tax_rate = client.invoice_get_tax_rate %} + {% set tax_amount = cart.total * tax_rate / 100 %} + +

{% trans 'VAT'%} ({{ tax_rate }}%) :

+ +
{{ tax_amount | money_convert }}
+ {% endif %}

{% trans 'Total:' %}

-
{{ cart.total | money_convert }}
+
{{ (cart.total + tax_amount) | money_convert }}
{% set enough_in_balance = client.client_balance_get_total >= cart.total %} {% if cart.total and not enough_in_balance %} From 6f65771b5bf676fec33b15a9c179859da4a51cdb Mon Sep 17 00:00:00 2001 From: Vaidas Lungis Date: Thu, 29 Jan 2015 10:39:31 +0200 Subject: [PATCH 3/3] add minus sign before discount price --- .../Orderbutton/html_client/mod_orderbutton_checkout.phtml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bb-modules/Orderbutton/html_client/mod_orderbutton_checkout.phtml b/src/bb-modules/Orderbutton/html_client/mod_orderbutton_checkout.phtml index 13d92c014..0ca4442b3 100644 --- a/src/bb-modules/Orderbutton/html_client/mod_orderbutton_checkout.phtml +++ b/src/bb-modules/Orderbutton/html_client/mod_orderbutton_checkout.phtml @@ -141,7 +141,7 @@ {% trans 'Discount:' %} - {{ cart.discount | money_convert }} + - {{ cart.discount | money_convert }} {% endif %}