Tax rules update implemented

This commit is contained in:
4Giedrius committed 2015-02-18 16:26:43 +02:00
1 parent 4aa08e15a2
commit cbcb3677f5
5 files changed
+127 -6

No files matched your search

+48 -2
View File
@@ -807,7 +807,7 @@ class Admin extends \Api_Abstract
* @param int $id - tax id
*
* @return boolean
* @throws Box_Exception
* @throws \Box_Exception
*/
public function tax_delete($data)
{
@@ -825,7 +825,7 @@ class Admin extends \Api_Abstract
* Create new tax rule
*
* @param string $name - tax name
* @param flaot $taxrate - tax rate
* @param float $taxrate - tax rate
*
* @return int - new tax id
*/
@@ -841,6 +841,52 @@ class Admin extends \Api_Abstract
return $taxService->create($data);
}
/**
* Update tax rule
*
* @param string $id - tax ID
*
* @return array
*/
public function tax_get($data)
{
$required = array(
'id' => 'Tax id is missing'
);
$this->di['validator']->checkRequiredParamsForArray($required, $data);
$tax = $this->di['db']->getExistingModelById('Tax', $data['id'], 'Tax rule not found');
$taxService = $this->di['mod_service']('Invoice', 'Tax');
return $taxService->toApiArray($tax);
}
/**
* Update tax rule
*
* @param int $id - tax ID
* @param string $name - tax name
* @param float $taxrate - tax rate
*
* @return boolean
*/
public function tax_update($data)
{
$required = array(
'id' => 'Tax id is missing',
'taxrate' => 'Tax rate is missing',
'name' => 'Tax name is missing'
);
$tax = $this->di['db']->getExistingModelById('Tax', $data['id'], 'Tax rule not found');
$this->di['validator']->checkRequiredParamsForArray($required, $data);
$taxService = $this->di['mod_service']('Invoice', 'Tax');
return $taxService->update($tax, $data);
}
/**
* Get list of taxes
*
+12 -3
View File
@@ -96,7 +96,7 @@ class Admin implements \Box\InjectionAwareInterface
),
);
}
public function register(\Box_App &$app)
{
$app->get('/invoice', 'get_index', array(), get_class($this));
@@ -107,15 +107,24 @@ class Admin implements \Box\InjectionAwareInterface
$app->get('/invoice/manage/:id','get_invoice', array('id'=>'[0-9]+'), get_class($this));
$app->get('/invoice/transaction/:id','get_transaction', array('id'=>'[0-9]+'), get_class($this));
$app->get('/invoice/subscription/:id','get_subscription', array('id'=>'[0-9]+'), get_class($this));
$app->get('/invoice/tax', 'get_tax', array(), get_class($this));
$app->get('/invoice/tax', 'get_taxes', array(), get_class($this));
$app->get('/invoice/tax/:id', 'get_tax', array(), get_class($this));
$app->get('/invoice/pdf/:hash', 'get_pdf', array('hash'=>'[a-z0-9]+'), get_class($this));
}
public function get_tax(\Box_App $app)
public function get_taxes(\Box_App $app)
{
$api = $app->getApiAdmin();
return $app->render('mod_invoice_tax');
}
public function get_tax(\Box_App $app, $id)
{
$api = $app->getApiAdmin();
$tax = $api->invoice_tax_get(array('id' => $id));
return $app->render('mod_invoice_taxupdate', array('tax' => $tax));
}
public function get_index(\Box_App $app)
{
+14
View File
@@ -108,6 +108,20 @@ class ServiceTax implements InjectionAwareInterface
return $newId ;
}
public function update(\Model_Tax $model, array $data)
{
$model->name = $data['name'];
$model->country = (!isset($data['country']) || empty($data['country'])) ? NULL : $data['country'];
$model->state = (!isset($data['state']) || empty($data['state'])) ? NULL : $data['state'];
$model->taxrate = $data['taxrate'];
$model->created_at = date('c');
$model->updated_at = date('c');
$this->di['db']->store($model);
$this->di['logger']->info('Created new tax rule %s', $model->name);
return true ;
}
public function getSearchQuery($data)
{
$sql = 'SELECT *
@@ -47,7 +47,8 @@
{% endif %}
</td>
<td>{{ tax.taxrate }}%</td>
<td class="actions" style="width: 5%;">
<td class="actions" style="width: 8%;">
<a class="bb-button btn14" href="{{ 'invoice/tax'|alink}}/{{ tax.id }}"><img src="images/icons/dark/pencil.png" alt=""></a>
<a class="bb-button btn14 bb-rm-tr api-link" data-api-reload="1" data-api-confirm="Are you sure?" href="{{ 'api/admin/invoice/tax_delete'|link({'id' : tax.id}) }}"><img src="images/icons/dark/trash.png" alt=""></a>
</td>
@@ -0,0 +1,51 @@
{% extends "layout_default.phtml" %}
{% block meta_title %}Tax{% endblock %}
{% set active_menu = 'system' %}
{% block content %}
<div class="widget">
<div class="head"><h5 class="iMagnify">Update tax rule</h5></div>
<div class="fix"></div>
<div class="tab_content nopadding" id="tab-new">
<form method="post" action="{{ 'api/admin/invoice/tax_update'|link }}" data-api-redirect="{{ 'invoice/tax'|alink }}" class="mainForm save api-form">
<fieldset>
<div class="rowElem noborder">
<label>{% trans 'Tax title' %}:</label>
<div class="formRight">
<input type="text" name="name" value="{{tax.name}}" required="required" placeholder="{% trans 'sales Tax' %}"/>
</div>
<div class="fix"></div>
</div>
<div class="rowElem">
<label>{% trans 'Tax rate' %}:</label>
<div class="formRight">
<input type="text" name="taxrate" value="{{tax.taxrate}}" required="required" placeholder="{% trans '18' %}" style="width: 100px"/> %
</div>
<div class="fix"></div>
</div>
<div class="rowElem">
<label>{% trans 'Country' %}:</label>
<div class="formRight">
{{ mf.selectbox('country', guest.system_countries, tax.country, 0, 'Apply to all countries') }}
</div>
<div class="fix"></div>
</div>
<div class="rowElem">
<label>{% trans 'State' %}:</label>
<div class="formRight">
{# mf.selectbox('state', guest.system_states, tax.state, 0, 'Apply to all states') #}
<input type="text" name="state" value="{{ tax.state }}" placeholder="{% trans 'Leave empty to apply to all states' %}"/>
</div>
<div class="fix"></div>
</div>
<input type="hidden" name="id" value="{{ tax.id }}"/>
<input type="submit" value="{% trans 'Update' %}" class="greyishBtn submitForm" />
</fieldset>
</form>
</div>
</div>
{% endblock %}