2010-11-29 22:41:08 +00:00
|
|
|
<?php defined('SYSPATH') or die('No direct access allowed.');
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This class provides a tax information
|
|
|
|
*
|
|
|
|
* @package OSB
|
|
|
|
* @subpackage Tax
|
|
|
|
* @category Helpers
|
|
|
|
* @author Deon George
|
|
|
|
* @copyright (c) 2010 Deon George
|
|
|
|
* @license http://dev.leenooks.net/license.html
|
|
|
|
*/
|
|
|
|
class Tax {
|
|
|
|
/**
|
|
|
|
* Return array of taxes
|
|
|
|
*
|
|
|
|
* @param $cid
|
|
|
|
* @param $zone
|
|
|
|
* @param $value
|
|
|
|
* @return array Tax Information
|
|
|
|
*/
|
|
|
|
public static function detail($cid,$zone,$value=0) {
|
2012-11-09 23:13:57 +00:00
|
|
|
$tax = ORM::factory('Tax')
|
2010-11-29 22:41:08 +00:00
|
|
|
->where('country_id','=',$cid)
|
2011-10-11 08:52:31 +00:00
|
|
|
->and_where('zone','=',$zone)
|
|
|
|
->find_all();
|
2010-11-29 22:41:08 +00:00
|
|
|
|
|
|
|
$taxes = array();
|
2011-10-11 08:52:31 +00:00
|
|
|
foreach ($tax as $to) {
|
2010-11-29 22:41:08 +00:00
|
|
|
$total = array();
|
|
|
|
|
2011-10-11 08:52:31 +00:00
|
|
|
$total['id'] = $to->id;
|
|
|
|
$total['description'] = $to->description;
|
|
|
|
$total['amount'] = $to->rate*$value;
|
|
|
|
$total['rate'] = $to->rate;
|
2010-11-29 22:41:08 +00:00
|
|
|
|
|
|
|
array_push($taxes,$total);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $taxes;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Calculate the tax amount
|
|
|
|
public static function total($cid,$zone,$value) {
|
|
|
|
$total = 0;
|
|
|
|
|
|
|
|
foreach (static::detail($cid,$zone,$value) as $tax)
|
|
|
|
$total += $tax['amount'];
|
|
|
|
|
|
|
|
return $total;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function add($value) {
|
|
|
|
// @todo Tax details should come from session
|
|
|
|
// @todo Rounding should be a global config
|
|
|
|
return round($value+static::total(61,NULL,$value),2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
?>
|