This repository has been archived on 2024-04-08. You can view files and clone it, but cannot push or open issues or pull requests.
khosb/modules/tax/classes/Tax.php

64 lines
1.3 KiB
PHP
Raw Permalink Normal View History

2013-10-10 02:44:53 +00:00
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* This class provides a tax information
*
* @package Tax
* @category Helpers
* @author Deon George
* @copyright (c) 2009-2013 Open Source Billing
* @license http://dev.osbill.net/license.html
*/
class Tax {
2013-10-08 02:34:56 +00:00
public static function add($value) {
return Currency::round($value+self::amount($value));
2013-10-08 02:34:56 +00:00
}
/**
* Return the total of tax for an amount
*/
public static function amount($value,$round=FALSE) {
return Currency::round(self::total(Company::instance()->country()->id,NULL,$value));
2013-10-08 02:34:56 +00:00
}
2013-10-10 02:44:53 +00:00
/**
* Return array of taxes
*
* @param $cid
* @param $zone
* @param $value
* @return array Tax Information
*/
public static function detail($cid,$zone,$value=0) {
$tax = ORM::factory('Tax')
->where('country_id','=',$cid)
->and_where('zone','=',$zone)
->find_all();
$taxes = array();
foreach ($tax as $to) {
$total = array();
$total['id'] = $to->id;
$total['description'] = $to->description;
$total['amount'] = $to->rate*$value;
$total['rate'] = $to->rate;
array_push($taxes,$total);
}
return $taxes;
}
// Calculate the tax amount
public static function total($cid,$zone,$value) {
$total = 0;
foreach (self::detail($cid,$zone,$value) as $tax)
2013-10-10 02:44:53 +00:00
$total += $tax['amount'];
return $total;
}
}
?>