mirror of
https://github.com/opensourcepos/opensourcepos.git
synced 2026-03-29 04:11:37 -04:00
Attribute item form and decimal fixes
- Updated formatting to reflect standard - Wrapped Decimal type in to_decimals() function for localization - Fixed function name - Removed unneeded TODO - Fixed problems with sales register not receiving decimals with comma for separator properly. Signed-off-by: objecttothis <objecttothis@gmail.com>
This commit is contained in:
@@ -14,6 +14,7 @@ class OSPOSRules
|
||||
{
|
||||
private IncomingRequest $request;
|
||||
private array $config;
|
||||
|
||||
/**
|
||||
* Validates the username and password sent to the login view. User is logged in on successful validation.
|
||||
*
|
||||
@@ -128,4 +129,26 @@ class OSPOSRules
|
||||
|
||||
return $is_installed;
|
||||
}
|
||||
|
||||
public function decimal_locale(string $candidate, ?string &$error = null): bool
|
||||
{
|
||||
$candidate = prepare_decimal($candidate);
|
||||
$validation = Services::validation();
|
||||
|
||||
$validation->setRules([
|
||||
'candidate' => 'decimal'
|
||||
]);
|
||||
|
||||
$data = [
|
||||
'candidate' => $candidate
|
||||
];
|
||||
|
||||
if (!$validation->run($data))
|
||||
{
|
||||
$error = $validation->getErrors();
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -370,10 +370,9 @@ class Sales extends Secure_Controller
|
||||
$giftcard = model(Giftcard::class);
|
||||
$payment_type = $this->request->getPost('payment_type', FILTER_SANITIZE_FULL_SPECIAL_CHARS);
|
||||
|
||||
//TODO: See the code block below. This too needs to be ternary notation.
|
||||
if($payment_type !== lang('Sales.giftcard'))
|
||||
{
|
||||
$rules = ['amount_tendered' => 'trim|required|decimal',];
|
||||
$rules = ['amount_tendered' => 'trim|required|decimal_locale',];
|
||||
$messages = ['amount_tendered' => lang('Sales.must_enter_numeric')];
|
||||
}
|
||||
else
|
||||
@@ -383,19 +382,10 @@ class Sales extends Secure_Controller
|
||||
}
|
||||
|
||||
if(!$this->validate($rules, $messages))
|
||||
{//TODO: the code below should be refactored to the following ternary notation since it's much more readable and concise:
|
||||
//$data['error'] = $payment_type === lang('Sales.giftcard')
|
||||
// ? $data['error'] = lang('Sales.must_enter_numeric_giftcard')
|
||||
// : $data['error'] = lang('Sales.must_enter_numeric');
|
||||
|
||||
if($payment_type === lang('Sales.giftcard'))
|
||||
{
|
||||
$data['error'] = lang('Sales.must_enter_numeric_giftcard');
|
||||
}
|
||||
else
|
||||
{
|
||||
$data['error'] = lang('Sales.must_enter_numeric');
|
||||
}
|
||||
{
|
||||
$data['error'] = $payment_type === lang('Sales.giftcard')
|
||||
? lang('Sales.must_enter_numeric_giftcard')
|
||||
: lang('Sales.must_enter_numeric');
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -466,8 +456,8 @@ class Sales extends Secure_Controller
|
||||
{
|
||||
$amount_due = $this->sale_lib->get_total();
|
||||
$sales_total = $this->sale_lib->get_total(false);
|
||||
|
||||
$amount_tendered = $this->request->getPost('amount_tendered', FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION);
|
||||
$raw_amount_tendered = $this->request->getPost('amount_tendered');
|
||||
$amount_tendered = filter_var(prepare_decimal($raw_amount_tendered), FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION);
|
||||
$this->sale_lib->add_payment($payment_type, $amount_tendered);
|
||||
$cash_adjustment_amount = $amount_due - $sales_total;
|
||||
if($cash_adjustment_amount <> 0)
|
||||
@@ -1590,7 +1580,7 @@ class Sales extends Secure_Controller
|
||||
* Work orders can be canceled but are not physically removed from the sales history
|
||||
* @throws ReflectionException
|
||||
*/
|
||||
public function cancel(): void
|
||||
public function postCancel(): void
|
||||
{
|
||||
$sale_id = $this->sale_lib->get_sale_id();
|
||||
if($sale_id != NEW_ENTRY && $sale_id != '')
|
||||
|
||||
@@ -484,7 +484,7 @@ function parse_decimals(string $number, int $decimals = null)
|
||||
|
||||
$locale_safe_number = prepare_decimal($number);
|
||||
|
||||
if ($locale_safe_number > MAX_PRECISION) //TODO: This breaks when the string passed does not use . as the decimal separator.
|
||||
if ($locale_safe_number > MAX_PRECISION)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user