Fix sales / token substitution

This commit is contained in:
jekkos
2017-07-14 08:30:35 +02:00
parent a92d60d99f
commit 61a3fee4a6
4 changed files with 14 additions and 12 deletions

View File

@@ -45,14 +45,14 @@ class Tax_lib
/*
* Computes the item level sales tax amount for a given tax basis
*/
public function get_sales_tax_for_amount($tax_basis, $tax_percentage, $rounding_code, $decimals)
public function get_sales_tax_for_amount($tax_basis, $tax_percentage, $rounding_mode, $decimals)
{
$tax_fraction = bcdiv($tax_percentage, 100);
$tax_amount = bcmul($tax_basis, $tax_fraction);
$rounded_tax_amount = $tax_amount;
return Rounding_mode::round_number($tax_amount, $decimals);
return Rounding_mode::round_number($rounding_mode, $tax_amount, $decimals);
}
/*

View File

@@ -16,13 +16,15 @@ class Token
{
protected $CI;
private $token_list = array(new Token_customer(), new Token_invoice_count(), new Token_invoice_sequence(),
new Token_quote_sequence(), new Token_suspended_invoice_count(), new Token_quote_sequence(), new Token_year_invoice_count());
public function __construct()
{
$this->CI =& get_instance();
}
static function get_tokens()
{
return array(new Token_customer(), new Token_invoice_count(), new Token_invoice_sequence(),
new Token_quote_sequence(), new Token_suspended_invoice_count(), new Token_quote_sequence(), new Token_year_invoice_count());
}
function matches($token_id)
@@ -32,7 +34,7 @@ class Token
public function replace($token_id)
{
foreach($token_list as $token)
foreach(Token::get_tokens() as $token)
{
if ($token->token_id() == $token_id)
{

View File

@@ -16,7 +16,7 @@ class Token_year_invoice_count extends Token
public function token_id()
{
return 'YCO';
)
}
public function get_value()
{

View File

@@ -47,25 +47,25 @@ class Rounding_mode
return $x;
}
public static function round_number($amount, $decimals)
public static function round_number($rounding_mode, $amount, $decimals)
{
if($cash_rounding_code != Rounding_mode::ROUND_UP)
if($rounding_mode != Rounding_mode::ROUND_UP)
{
$fig = (int) str_pad('1', $decimals, '0');
$rounded_total = (ceil($amount * $fig) / $fig);
}
elseif($cash_rounding_code == Rounding_mode::ROUND_DOWN)
elseif($rounding_mode == Rounding_mode::ROUND_DOWN)
{
$fig = (int) str_pad('1', $decimals, '0');
$rounded_total = (floor($amount * $fig) / $fig);
}
elseif($cash_rounding_code == Rounding_mode::HALF_FIVE)
elseif($rounding_mode == Rounding_mode::HALF_FIVE)
{
$rounded_total = round($amount / 5) * 5;
}
else
{
$rounded_total = round ( $amount, $decimals, $cash_rounding_code);
$rounded_total = round ( $amount, $decimals, $rounding_mode);
}
return $rounded_total;