Filtering

- Added filtering to decimals which may have different comma separator
- Added formatting of decimals before concatenating into string
- Cast int to string in form_hidden() call

Signed-off-by: objecttothis <objecttothis@gmail.com>
This commit is contained in:
objecttothis
2024-04-16 15:36:54 +04:00
committed by jekkos
parent 73cec25468
commit 5500d3989f
5 changed files with 40 additions and 11 deletions

View File

@@ -329,7 +329,7 @@ class Config extends Secure_Controller
'company' => $this->request->getPost('company'),
'address' => $this->request->getPost('address'),
'phone' => $this->request->getPost('phone'),
'email' => $this->request->getPost('email', FILTER_SANITIZE_EMAIL),
'email' => strtolower($this->request->getPost('email', FILTER_SANITIZE_EMAIL)),
'fax' => $this->request->getPost('fax'),
'website' => $this->request->getPost('website', FILTER_SANITIZE_URL),
'return_policy' => $this->request->getPost('return_policy')

View File

@@ -353,7 +353,10 @@ class Customers extends Persons
*/
public function postCheckEmail(): void
{
$exists = $this->customer->check_email_exists(strtolower($this->request->getPost('email')), $this->request->getPost('person_id', FILTER_SANITIZE_NUMBER_INT));
$email = strtolower($this->request->getPost('email', FILTER_SANITIZE_EMAIL));
$person_id = $this->request->getPost('person_id', FILTER_SANITIZE_NUMBER_INT);
$exists = $this->customer->check_email_exists($email, $person_id);
echo !$exists ? 'true' : 'false';
}

View File

@@ -645,6 +645,9 @@ class Items extends Secure_Controller
$default_pack_name = lang('Items.default_pack_name');
$cost_price = prepare_decimal($this->request->getPost('cost_price'));
$unit_price = prepare_decimal($this->request->getPost('unit_price'));
$reorder_level = prepare_decimal($this->request->getPost('reorder_level'));
$qty_per_pack = prepare_decimal($this->request->getPost('qty_per_pack'));
//Save item data
$item_data = [
@@ -656,12 +659,12 @@ class Items extends Secure_Controller
'supplier_id' => empty($this->request->getPost('supplier_id')) ? null : intval($this->request->getPost('supplier_id')),
'item_number' => empty($this->request->getPost('item_number')) ? null : $this->request->getPost('item_number'),
'cost_price' => parse_decimals(filter_var($cost_price, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION)),
'unit_price' => parse_decimals($this->request->getPost('unit_price')),
'reorder_level' => parse_quantity($this->request->getPost('reorder_level')),
'unit_price' => parse_decimals(filter_var($unit_price, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION)),
'reorder_level' => parse_quantity(filter_var($reorder_level, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION)),
'receiving_quantity' => $receiving_quantity,
'allow_alt_description' => $this->request->getPost('allow_alt_description') != null,
'is_serialized' => $this->request->getPost('is_serialized') != null,
'qty_per_pack' => $this->request->getPost('qty_per_pack') == null ? 1 : parse_quantity($this->request->getPost('qty_per_pack')),
'qty_per_pack' => $this->request->getPost('qty_per_pack') == null ? 1 : parse_quantity(filter_var($qty_per_pack, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION)),
'pack_name' => $this->request->getPost('pack_name') == null ? $default_pack_name : $this->request->getPost('pack_name'),
'low_sell_item_id' => $this->request->getPost('low_sell_item_id') === null ? $item_id : intval($this->request->getPost('low_sell_item_id')),
'deleted' => $this->request->getPost('is_deleted') != null,
@@ -731,7 +734,8 @@ class Items extends Secure_Controller
$stock_locations = $this->stock_location->get_undeleted_all()->getResultArray();
foreach($stock_locations as $location)
{
$updated_quantity = parse_quantity($this->request->getPost('quantity_' . $location['location_id']));
$stock_quantity = prepare_decimal($this->request->getPost('quantity_' . $location['location_id']));
$updated_quantity = parse_quantity(filter_var($stock_quantity, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION));
if($item_data['item_type'] == ITEM_TEMP)
{
@@ -898,13 +902,14 @@ class Items extends Secure_Controller
$employee_id = $this->employee->get_logged_in_employee_info()->person_id;
$cur_item_info = $this->item->get_info($item_id);
$location_id = $this->request->getPost('stock_location');
$new_quantity = prepare_decimal($this->request->getPost('newquantity'));
$inv_data = [
'trans_date' => date('Y-m-d H:i:s'),
'trans_items' => $item_id,
'trans_user' => $employee_id,
'trans_location' => $location_id,
'trans_comment' => $this->request->getPost('trans_comment'),
'trans_inventory' => parse_quantity($this->request->getPost('newquantity'))
'trans_inventory' => parse_quantity(filter_var($new_quantity, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION))
];
$this->inventory->insert($inv_data, false);

View File

@@ -595,17 +595,20 @@ class Item extends Model
}
/**
* @param $result_row
* @param object $result_row
* @return string
*/
public function get_search_suggestion_label($result_row): string
public function get_search_suggestion_label(object $result_row): string
{
$config = config(OSPOS::class)->settings;
$label = '';
$label1 = $config['suggestions_first_column'];
$label2 = $config['suggestions_second_column'];
$label3 = $config['suggestions_third_column'];
$this->format_result_numbers($result_row);
// If multi_pack enabled then if "name" is part of the search suggestions then append pack
if($config['multi_pack_enabled'])
{
@@ -631,6 +634,24 @@ class Item extends Model
return $label;
}
/**
* Converts decimal money values to their correct locale format.
*
* @param object $result_row
* @return void
*/
private function format_result_numbers(object &$result_row): void
{
if(isset($result_row->cost_price))
{
$result_row->cost_price = to_currency_no_money($result_row->cost_price);
}
if(isset($result_row->unit_price))
{
$result_row->unit_price = to_currency_no_money($result_row->unit_price);
}
}
/**
* @param string $label
* @param string $item_field_name

View File

@@ -154,9 +154,9 @@ if (isset($success))
<tr>
<td><?= anchor("$controller_name/deleteItem/$line", '<span class="glyphicon glyphicon-trash"></span>') ?></td>
<td><?= esc($item['item_number']) ?></td>
<td style="align:center;">
<td style="text-align:center;">
<?= esc($item['name'] . ' '. implode(' ', [$item['attribute_values'], $item['attribute_dtvalues']])) ?><br /> <?= '[' . to_quantity_decimals($item['in_stock']) . ' in ' . $item['stock_name'] . ']' ?>
<?= form_hidden('location', $item['item_location']) ?>
<?= form_hidden('location', (string)$item['item_location']) ?>
</td>
<?php