mirror of
https://github.com/FOSSBilling/FOSSBilling.git
synced 2026-11-22 21:03:01 +09:00
commit
d150443e95
6 files changed
+81
-3
No files matched your search
@@ -319,4 +319,9 @@ class Client extends \Api_Abstract
|
||||
return $service->getClientBalance($this->identity);
|
||||
}
|
||||
|
||||
public function is_taxable()
|
||||
{
|
||||
return $this->getService()->isClientTaxable($this->identity);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -141,13 +141,22 @@
|
||||
</tr>
|
||||
<tr>
|
||||
<td><strong>{% trans 'Discount:' %}</strong></td>
|
||||
<td><strong>{{ cart.discount | money_convert }}</strong></td>
|
||||
<td><strong>- {{ cart.discount | money_convert }}</strong></td>
|
||||
</tr>
|
||||
{% 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 %}
|
||||
<tr>
|
||||
<td><strong>{% trans 'VAT'%} ({{ tax_rate }}%) :</strong></td>
|
||||
<td><strong>{{ tax_amount | money_convert }}</strong></td>
|
||||
</tr>
|
||||
{% endif %}
|
||||
<tr>
|
||||
<td><strong>{% trans 'Total:' %}</strong></td>
|
||||
<td><strong>{{ cart.total | money_convert }}</strong></td>
|
||||
<td><strong>{{ (cart.total + tax_amount) | money_convert }}</strong></td>
|
||||
</tr>
|
||||
|
||||
</table>
|
||||
|
||||
@@ -86,8 +86,17 @@
|
||||
<div class="grid_5 omega">
|
||||
<div class="box">
|
||||
<div class="block pricing">
|
||||
{% 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 %}
|
||||
|
||||
<p>{% trans 'VAT'%} ({{ tax_rate }}%) :</p>
|
||||
|
||||
<div class="currency">{{ tax_amount | money_convert }}</div>
|
||||
{% endif %}
|
||||
<p>{% trans 'Total:' %}</p>
|
||||
<div class="currency">{{ cart.total | money_convert }}</div>
|
||||
<div class="currency">{{ (cart.total + tax_amount) | money_convert }}</div>
|
||||
<form method="post" action="{{ 'api/client/cart/checkout'|link }}" class="api-form" data-api-jsonp="onAfterCartCheckout">
|
||||
{% set enough_in_balance = client.client_balance_get_total >= cart.total %}
|
||||
{% if cart.total and not enough_in_balance %}
|
||||
|
||||
@@ -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);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user