Skip to content

Commit

Permalink
Added the backend functionality for the tax classes, tax rate and tax…
Browse files Browse the repository at this point in the history
… geo.
  • Loading branch information
rasseljandavid committed Jul 12, 2011
1 parent 07d5085 commit 20f7c27
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 4 deletions.
96 changes: 94 additions & 2 deletions framework/modules/ecommerce/controllers/taxController.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,99 @@ function manage() {
assign_to_template(array('taxes'=>$taxes));
}

function edit() {
global $db;

if(!empty($this->params['id'])) {
//Get the data from the 3 tables
$tax_class = $db->selectObject('tax_class', 'id =' .$this->params['id']);
$tax_rate = $db->selectObject('tax_rate', 'class_id =' .$this->params['id']);
$tax_geo = $db->selectObject('tax_geo', 'zone_id =' . $tax_rate->zone_id);
//Store it in a single object all the data needed
$record->id = $tax_class->id;
$record->classname = $tax_class->name;
$record->rate = $tax_rate->rate;
$record->zone = $tax_rate->zone_id;
$record->state = $tax_geo->region_id;
$record->country = $tax_geo->country_id;
}

//Get the tax_zone
$records = $db->selectObjects('tax_zone');
foreach($records as $item) {
$zones[$item->id] = $item->name;
}

assign_to_template(array('zones'=>$zones, 'record'=>$record));
}

function update() {
global $db;

if(empty($this->params['id'])) {
//Add data in tax class
$tax_class->name = $this->params['name'];
$class_id = $db->insertObject($tax_class,'tax_class');

//Add data in the tax geo
$tax_geo->zone_id = $this->params['zone'];
$tax_geo->country_id = $this->params['country'];
$tax_geo->region_id = $this->params['state'];
$db->insertObject($tax_geo,'tax_geo');

//Add data in the tax rate
$tax_rate->zone_id = $this->params['zone'];
$tax_rate->class_id = $class_id;
$tax_rate->rate = $this->params['rate'];
$db->insertObject($tax_rate,'tax_rate');
} else {

//Update the Tax class table
$tax_class = $db->selectObject('tax_class', 'id =' .$this->params['id']);
$tax_class->name = $this->params['name'];
$db->updateObject($tax_class, 'tax_class');

//Update the Tax rate table
$tax_rate = $db->selectObject('tax_rate', 'class_id =' .$this->params['id']);
$zone_id = $tax_rate->zone_id;
$tax_rate->zone_id = $this->params['zone'];
$tax_rate->rate = $this->params['rate'];
$db->updateObject($tax_rate,'tax_rate');

//Update the Tax geo table
$tax_geo = $db->selectObject('tax_geo', 'zone_id =' .$zone_id);
$tax_geo->zone_id = $this->params['zone'];
$tax_geo->country_id = $this->params['country'];
$tax_geo->region_id = $this->params['state'];
$db->updateObject($tax_geo,'tax_geo');
}

expHistory::back();
}

function delete() {
global $db;

if (empty($this->params['id'])) return false;
$zone = $db->selectObject('tax_zone', 'id =' .$this->params['id']);

//Get the data from the text rate to get the zone id
$rate = $db->selectObject('tax_rate', 'class_id=' . $this->params['id']);

//Delete record in tax rate
$db->delete('tax_rate', 'class_id =' .$this->params['id']);

//Delete record in tax geo
$db->delete('tax_geo', 'zone_id =' . $rate->zone_id);

//Finally delete the record in tax class
$db->delete('tax_class', 'id =' .$this->params['id']);


expHistory::back();

}

function manage_zones() {
global $db;

Expand Down Expand Up @@ -96,7 +189,7 @@ function update_zone() {
$obj->name = $this->params['name'];
$db->insertObject($obj,'tax_zone');
} else {
$zone = $db->selectObject('tax_zone', 'id =' .$this->params['id']);
$zone = $db->selectObject('tax_zone', 'id =' .$this->params['id']);
$zone->name = $this->params['name'];
$db->updateObject($zone, 'tax_zone');
}
Expand All @@ -108,7 +201,6 @@ function delete_zone() {
global $db;

if (empty($this->params['id'])) return false;
$zone = $db->selectObject('tax_zone', 'id =' .$this->params['id']);
$db->delete('tax_zone', 'id =' .$this->params['id']);

expHistory::back();
Expand Down
3 changes: 1 addition & 2 deletions framework/modules/ecommerce/views/tax/edit.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,11 @@
* GPL: http://www.gnu.org/licenses/gpl.txt
*
*}

{form action=update}
{control type="hidden" name="id" value=$record->id}
{control type="text" name="name" label="Class Name" value=$record->classname}
{control type="text" name="rate" label="Rate" value=$record->rate}
{control type="dropdown" name="zone" label="Zone" values=$record->zones default=$record->zonename}
{control type="dropdown" name="zone" label="Zone" items=$zones value=$record->zone}
{control type=state name=state label="State/Province" value=$record->state}
{control type=country name=country label="Country" value=$record->country}

Expand Down
7 changes: 7 additions & 0 deletions framework/modules/ecommerce/views/tax/manage.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@
</th>
<th>
Country
</th>
<th>
Action
</th>
</tr>
</thead>
Expand All @@ -61,6 +64,10 @@
</td>
<td>
{$tax->country}
</td>
<td>
{icon action=edit record=$tax img="edit.png"}
{icon action=delete record=$tax img="delete.png"}
</td>
</tr>
{/foreach}
Expand Down

0 comments on commit 20f7c27

Please sign in to comment.