mirror of
https://github.com/opensourcepos/opensourcepos.git
synced 2026-05-24 16:28:40 -04:00
Divide quantity and price according to configured precision
This commit is contained in:
@@ -88,10 +88,10 @@ class Token_lib
|
||||
foreach($barcode_formats as $barcode_format)
|
||||
{
|
||||
$parsed_results = $this->parse($item_id_or_number_or_item_kit_or_receipt, $barcode_format, $barcode_tokens);
|
||||
$quantity = (isset($parsed_results['W'])) ? (int) $parsed_results['W'] / 1000 : 1;
|
||||
$quantity = (isset($parsed_results['W'])) ? (int) $parsed_results['W'] / pow(10, $this->CI->config->item('quantity_decimals')) : 1;
|
||||
$item_id_or_number_or_item_kit_or_receipt = (isset($parsed_results['I'])) ?
|
||||
$parsed_results['I'] : $item_id_or_number_or_item_kit_or_receipt;
|
||||
$price = (isset($parsed_results['P'])) ? (double) $parsed_results['P'] : NULL;
|
||||
$price = (isset($parsed_results['P'])) ? (double) $parsed_results['P'] / pow(10, $this->CI->config->item('currency_decimals') - 1) : NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,9 @@ class Token_lib_test extends UnitTestCase
|
||||
$this->resetInstance();
|
||||
|
||||
$this->obj = $this->newLibrary('Token_lib');
|
||||
$this->CI->config->set_item('currency_decimals', 3);
|
||||
$this->CI->config->set_item('quantity_decimals', 3);
|
||||
|
||||
}
|
||||
|
||||
public function test_token_parser()
|
||||
@@ -46,7 +49,7 @@ class Token_lib_test extends UnitTestCase
|
||||
$this->obj->parse_barcode($quantity, $price, $item_number);
|
||||
|
||||
|
||||
$this->assertEquals($price, 10);
|
||||
$this->assertEquals($price, 0.10);
|
||||
$this->assertEquals($item_number, 123456);
|
||||
$this->assertEquals($quantity, 50.001);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user