diff --git a/app/Config/Events.php b/app/Config/Events.php index 14b7c4074..d96b22394 100644 --- a/app/Config/Events.php +++ b/app/Config/Events.php @@ -86,8 +86,9 @@ Events::on('item_return', static function (): void { * This event triggered when an item is changed. This can be an item create, update or delete. * Plugin functionality is triggered here. */ -Events::on('item_change', static function (): void { +Events::on('item_change', static function (int $itemId): void { // Call plugin controller methods to handle the item change data sent in the static function. + log_message('debug', "Item change event triggered on item ID: $itemId"); }); /** diff --git a/app/Config/Validation/OSPOSRules.php b/app/Config/Validation/OSPOSRules.php index eb965ab53..0f1cfaa8c 100644 --- a/app/Config/Validation/OSPOSRules.php +++ b/app/Config/Validation/OSPOSRules.php @@ -133,6 +133,6 @@ class OSPOSRules */ public function decimal_locale(string $candidate, ?string &$error = null): bool { - return parse_decimals($candidate) !== false; + return parseDecimals($candidate) !== false; } } diff --git a/app/Controllers/Cashups.php b/app/Controllers/Cashups.php index e5c8b8799..d98caa995 100644 --- a/app/Controllers/Cashups.php +++ b/app/Controllers/Cashups.php @@ -94,8 +94,8 @@ class Cashups extends Secure_Controller if ($cash_ups_info->cashup_id == NEW_ENTRY) { $cash_ups_info->open_date = date('Y-m-d H:i:s'); $cash_ups_info->close_date = $cash_ups_info->open_date; - $cash_ups_info->open_employee_id = $this->employee->get_logged_in_employee_info()->person_id; - $cash_ups_info->close_employee_id = $this->employee->get_logged_in_employee_info()->person_id; + $cash_ups_info->open_employee_id = $this->employee->getLoggedInEmployeeInfo()->person_id; + $cash_ups_info->close_employee_id = $this->employee->getLoggedInEmployeeInfo()->person_id; } // If all the amounts are null or 0 that means it's a close cashup elseif ( @@ -210,13 +210,13 @@ class Cashups extends Secure_Controller $cash_up_data = [ 'open_date' => $open_date_formatter->format('Y-m-d H:i:s'), 'close_date' => $close_date_formatter->format('Y-m-d H:i:s'), - 'open_amount_cash' => parse_decimals($this->request->getPost('open_amount_cash')), - 'transfer_amount_cash' => parse_decimals($this->request->getPost('transfer_amount_cash')), - 'closed_amount_cash' => parse_decimals($this->request->getPost('closed_amount_cash')), - 'closed_amount_due' => parse_decimals($this->request->getPost('closed_amount_due')), - 'closed_amount_card' => parse_decimals($this->request->getPost('closed_amount_card')), - 'closed_amount_check' => parse_decimals($this->request->getPost('closed_amount_check')), - 'closed_amount_total' => parse_decimals($this->request->getPost('closed_amount_total')), + 'open_amount_cash' => parseDecimals($this->request->getPost('open_amount_cash')), + 'transfer_amount_cash' => parseDecimals($this->request->getPost('transfer_amount_cash')), + 'closed_amount_cash' => parseDecimals($this->request->getPost('closed_amount_cash')), + 'closed_amount_due' => parseDecimals($this->request->getPost('closed_amount_due')), + 'closed_amount_card' => parseDecimals($this->request->getPost('closed_amount_card')), + 'closed_amount_check' => parseDecimals($this->request->getPost('closed_amount_check')), + 'closed_amount_total' => parseDecimals($this->request->getPost('closed_amount_total')), 'note' => $this->request->getPost('note') != null, 'description' => $this->request->getPost('description', FILTER_SANITIZE_FULL_SPECIAL_CHARS), 'open_employee_id' => $this->request->getPost('open_employee_id', FILTER_SANITIZE_NUMBER_INT), @@ -258,12 +258,12 @@ class Cashups extends Secure_Controller */ public function postAjax_cashup_total(): void { - $open_amount_cash = parse_decimals($this->request->getPost('open_amount_cash')); - $transfer_amount_cash = parse_decimals($this->request->getPost('transfer_amount_cash')); - $closed_amount_cash = parse_decimals($this->request->getPost('closed_amount_cash')); - $closed_amount_due = parse_decimals($this->request->getPost('closed_amount_due')); - $closed_amount_card = parse_decimals($this->request->getPost('closed_amount_card')); - $closed_amount_check = parse_decimals($this->request->getPost('closed_amount_check')); + $open_amount_cash = parseDecimals($this->request->getPost('open_amount_cash')); + $transfer_amount_cash = parseDecimals($this->request->getPost('transfer_amount_cash')); + $closed_amount_cash = parseDecimals($this->request->getPost('closed_amount_cash')); + $closed_amount_due = parseDecimals($this->request->getPost('closed_amount_due')); + $closed_amount_card = parseDecimals($this->request->getPost('closed_amount_card')); + $closed_amount_check = parseDecimals($this->request->getPost('closed_amount_check')); $total = $this->_calculate_total($open_amount_cash, $transfer_amount_cash, $closed_amount_due, $closed_amount_cash, $closed_amount_card, $closed_amount_check); // TODO: hungarian notation diff --git a/app/Controllers/Config.php b/app/Controllers/Config.php index 9f1da31f3..0788678dc 100644 --- a/app/Controllers/Config.php +++ b/app/Controllers/Config.php @@ -366,9 +366,9 @@ class Config extends Secure_Controller 'theme' => $this->request->getPost('theme'), 'login_form' => $this->request->getPost('login_form'), 'default_sales_discount_type' => $this->request->getPost('default_sales_discount_type') != null, - 'default_sales_discount' => parse_decimals($this->request->getPost('default_sales_discount')), + 'default_sales_discount' => parseDecimals($this->request->getPost('default_sales_discount')), 'default_receivings_discount_type' => $this->request->getPost('default_receivings_discount_type') != null, - 'default_receivings_discount' => parse_decimals($this->request->getPost('default_receivings_discount')), + 'default_receivings_discount' => parseDecimals($this->request->getPost('default_receivings_discount')), 'enforce_privacy' => $this->request->getPost('enforce_privacy') != null, 'receiving_calculate_average_price' => $this->request->getPost('receiving_calculate_average_price') != null, 'lines_per_page' => $this->request->getPost('lines_per_page', FILTER_SANITIZE_NUMBER_INT), @@ -775,9 +775,9 @@ class Config extends Secure_Controller $default_tax_2_rate = $this->request->getPost('default_tax_2_rate'); $batch_save_data = [ - 'default_tax_1_rate' => parse_tax(filter_var($default_tax_1_rate, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION)), + 'default_tax_1_rate' => parseTax(filter_var($default_tax_1_rate, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION)), 'default_tax_1_name' => $this->request->getPost('default_tax_1_name'), - 'default_tax_2_rate' => parse_tax(filter_var($default_tax_2_rate, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION)), + 'default_tax_2_rate' => parseTax(filter_var($default_tax_2_rate, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION)), 'default_tax_2_name' => $this->request->getPost('default_tax_2_name'), 'tax_included' => $this->request->getPost('tax_included') != null, 'use_destination_based_tax' => $this->request->getPost('use_destination_based_tax') != null, diff --git a/app/Controllers/Customers.php b/app/Controllers/Customers.php index d81dc05b6..127a6587a 100644 --- a/app/Controllers/Customers.php +++ b/app/Controllers/Customers.php @@ -152,7 +152,7 @@ class Customers extends Persons if (empty($info->person_id) || empty($info->date) || empty($info->employee_id)) { $data['person_info']->date = date('Y-m-d H:i:s'); - $data['person_info']->employee_id = $this->employee->get_logged_in_employee_info()->person_id; + $data['person_info']->employee_id = $this->employee->getLoggedInEmployeeInfo()->person_id; } $employee_info = $this->employee->get_info($info->employee_id); @@ -265,7 +265,7 @@ class Customers extends Persons 'account_number' => $this->request->getPost('account_number') == '' ? null : $this->request->getPost('account_number'), 'tax_id' => $this->request->getPost('tax_id'), 'company_name' => $this->request->getPost('company_name') == '' ? null : $this->request->getPost('company_name'), - 'discount' => $this->request->getPost('discount') == '' ? 0.00 : parse_decimals($this->request->getPost('discount')), + 'discount' => $this->request->getPost('discount') == '' ? 0.00 : parseDecimals($this->request->getPost('discount')), 'discount_type' => $this->request->getPost('discount_type') == null ? PERCENT : $this->request->getPost('discount_type', FILTER_SANITIZE_NUMBER_INT), 'package_id' => $this->request->getPost('package_id') == '' ? null : $this->request->getPost('package_id'), 'taxable' => $this->request->getPost('taxable') != null, @@ -436,7 +436,7 @@ class Customers extends Persons 'discount_type' => $data[16], 'taxable' => $data[17] == '' ? 0 : 1, 'date' => date('Y-m-d H:i:s'), - 'employee_id' => $this->employee->get_logged_in_employee_info()->person_id + 'employee_id' => $this->employee->getLoggedInEmployeeInfo()->person_id ]; $account_number = $data[14]; diff --git a/app/Controllers/Expenses.php b/app/Controllers/Expenses.php index bb5363d6c..856954d82 100644 --- a/app/Controllers/Expenses.php +++ b/app/Controllers/Expenses.php @@ -110,7 +110,7 @@ class Expenses extends Secure_Controller if ($expense_id == NEW_ENTRY) { $data['expenses_info']->date = date('Y-m-d H:i:s'); - $data['expenses_info']->employee_id = $this->employee->get_logged_in_employee_info()->person_id; + $data['expenses_info']->employee_id = $this->employee->getLoggedInEmployeeInfo()->person_id; } $data['payments'] = []; @@ -155,8 +155,8 @@ class Expenses extends Secure_Controller 'date' => $date_formatter->format('Y-m-d H:i:s'), 'supplier_id' => $this->request->getPost('supplier_id') == '' ? null : $this->request->getPost('supplier_id', FILTER_SANITIZE_NUMBER_INT), 'supplier_tax_code' => $this->request->getPost('supplier_tax_code', FILTER_SANITIZE_FULL_SPECIAL_CHARS), - 'amount' => parse_decimals($this->request->getPost('amount')), - 'tax_amount' => parse_decimals($this->request->getPost('tax_amount')), + 'amount' => parseDecimals($this->request->getPost('amount')), + 'tax_amount' => parseDecimals($this->request->getPost('tax_amount')), 'payment_type' => $this->request->getPost('payment_type', FILTER_SANITIZE_FULL_SPECIAL_CHARS), 'expense_category_id' => $this->request->getPost('expense_category_id', FILTER_SANITIZE_NUMBER_INT), 'description' => $this->request->getPost('description', FILTER_SANITIZE_FULL_SPECIAL_CHARS), diff --git a/app/Controllers/Giftcards.php b/app/Controllers/Giftcards.php index f8f5048e0..0f0f1d6a3 100644 --- a/app/Controllers/Giftcards.php +++ b/app/Controllers/Giftcards.php @@ -124,7 +124,7 @@ class Giftcards extends Secure_Controller $giftcard_data = [ 'record_time' => date('Y-m-d H:i:s'), 'giftcard_number' => $giftcard_number, - 'value' => parse_decimals($this->request->getPost('giftcard_amount')), + 'value' => parseDecimals($this->request->getPost('giftcard_amount')), 'person_id' => $this->request->getPost('person_id') == '' ? null : $this->request->getPost('person_id', FILTER_SANITIZE_NUMBER_INT) ]; @@ -160,7 +160,7 @@ class Giftcards extends Secure_Controller */ public function postCheckNumberGiftcard(): void { - $giftcard_amount = parse_decimals($this->request->getPost('giftcard_amount')); + $giftcard_amount = parseDecimals($this->request->getPost('giftcard_amount')); $parsed_value = filter_var($giftcard_amount, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION); echo json_encode(['success' => $parsed_value !== false && $parsed_value > 0 && $giftcard_amount !== false, 'giftcard_amount' => to_currency_no_money($parsed_value)]); } diff --git a/app/Controllers/Item_kits.php b/app/Controllers/Item_kits.php index 6191cef71..8c0c8c177 100644 --- a/app/Controllers/Item_kits.php +++ b/app/Controllers/Item_kits.php @@ -166,7 +166,7 @@ class Item_kits extends Secure_Controller 'name' => $this->request->getPost('name'), 'item_kit_number' => $this->request->getPost('item_kit_number'), 'item_id' => $this->request->getPost('kit_item_id') ? null : intval($this->request->getPost('kit_item_id')), - 'kit_discount' => parse_decimals($this->request->getPost('kit_discount')), + 'kit_discount' => parseDecimals($this->request->getPost('kit_discount')), 'kit_discount_type' => $this->request->getPost('kit_discount_type') === null ? PERCENT : intval($this->request->getPost('kit_discount_type')), 'price_option' => $this->request->getPost('price_option') === null ? PRICE_ALL : intval($this->request->getPost('price_option')), 'print_option' => $this->request->getPost('print_option') === null ? PRINT_ALL : intval($this->request->getPost('print_option')), @@ -188,7 +188,7 @@ class Item_kits extends Secure_Controller foreach ($item_kit_items_array as $item_id => $item_kit_qty) { $item_kit_items[] = [ 'item_id' => $item_id, - 'quantity' => $item_kit_qty === null ? 0 : parse_quantity($item_kit_qty), + 'quantity' => $item_kit_qty === null ? 0 : parseQuantity($item_kit_qty), 'kit_sequence' => $this->request->getPost("item_kit_seq[$item_id]") === null ? 0 : intval($this->request->getPost("item_kit_seq[$item_id]")) ]; } diff --git a/app/Controllers/Items.php b/app/Controllers/Items.php index e864d76e3..ac6bd97c4 100644 --- a/app/Controllers/Items.php +++ b/app/Controllers/Items.php @@ -15,6 +15,7 @@ use App\Models\Stock_location; use App\Models\Supplier; use App\Models\Tax_category; +use CodeIgniter\Events\Events; use CodeIgniter\Images\Handlers\BaseHandler; use CodeIgniter\HTTP\DownloadResponse; use Config\OSPOS; @@ -274,7 +275,7 @@ class Items extends Secure_Controller $data['item_tax_info'] = $this->item_taxes->get_info($item_id); $data['default_tax_1_rate'] = ''; $data['default_tax_2_rate'] = ''; - $data['item_kit_disabled'] = !$this->employee->has_grant('item_kits', $this->employee->get_logged_in_employee_info()->person_id); + $data['item_kit_disabled'] = !$this->employee->has_grant('item_kits', $this->employee->getLoggedInEmployeeInfo()->person_id); $data['definition_values'] = $this->attribute->get_attributes_by_item($item_id); $data['definition_names'] = $this->attribute->get_definition_names(); @@ -376,10 +377,10 @@ class Items extends Secure_Controller $data['image_path'] = ''; } - $stock_locations = $this->stock_location->get_undeleted_all()->getResultArray(); + $stock_locations = $this->stock_location->getUndeletedAll()->getResultArray(); foreach ($stock_locations as $location) { - $quantity = $this->item_quantity->get_item_quantity($item_id, $location['location_id'])->quantity; + $quantity = $this->item_quantity->getItemQuantity($item_id, $location['location_id'])->quantity; $quantity = ($item_id === NEW_ENTRY) ? 0 : $quantity; $location_array[$location['location_id']] = ['location_name' => $location['location_name'], 'quantity' => $quantity]; $data['stock_locations'] = $location_array; @@ -414,10 +415,10 @@ class Items extends Secure_Controller $data['item_info'] = $item_info; $data['stock_locations'] = []; - $stock_locations = $this->stock_location->get_undeleted_all()->getResultArray(); + $stock_locations = $this->stock_location->getUndeletedAll()->getResultArray(); foreach ($stock_locations as $location) { - $quantity = $this->item_quantity->get_item_quantity($item_id, $location['location_id'])->quantity; + $quantity = $this->item_quantity->getItemQuantity($item_id, $location['location_id'])->quantity; $data['stock_locations'][$location['location_id']] = $location['location_name']; $data['item_quantities'][$location['location_id']] = $quantity; @@ -441,10 +442,10 @@ class Items extends Secure_Controller $data['item_info'] = $item_info; $data['stock_locations'] = []; - $stock_locations = $this->stock_location->get_undeleted_all()->getResultArray(); + $stock_locations = $this->stock_location->getUndeletedAll()->getResultArray(); foreach ($stock_locations as $location) { - $quantity = $this->item_quantity->get_item_quantity($item_id, $location['location_id'])->quantity; + $quantity = $this->item_quantity->getItemQuantity($item_id, $location['location_id'])->quantity; $data['stock_locations'][$location['location_id']] = $location['location_name']; $data['item_quantities'][$location['location_id']] = $quantity; @@ -470,7 +471,7 @@ class Items extends Secure_Controller if (isset($item['item_number']) && empty($item['item_number']) && $this->config['barcode_generate_if_empty']) { if (isset($item['item_id'])) { $save_item = ['item_number' => $item['item_number']]; - $this->item->save_value($save_item, $item['item_id']); + $this->item->saveValue($save_item, $item['item_id']); } } } @@ -583,32 +584,27 @@ class Items extends Secure_Controller } /** - * @param int $item_id + * @param int $itemId * @throws ReflectionException */ - public function postSave(int $item_id = NEW_ENTRY): void + public function postSave(int $itemId = NEW_ENTRY): void { - $upload_data = $this->upload_image(); - $upload_success = empty($upload_data['error']); - - $raw_receiving_quantity = $this->request->getPost('receiving_quantity'); - - $receiving_quantity = parse_quantity($raw_receiving_quantity); + // Save item data + $rawReceivingQuantity = $this->request->getPost('receiving_quantity'); + $receivingQuantity = parseQuantity($rawReceivingQuantity); $item_type = $this->request->getPost('item_type') === null ? ITEM : intval($this->request->getPost('item_type')); - if ($receiving_quantity === 0.0 && $item_type !== ITEM_TEMP) { - $receiving_quantity = 1; + if ($receivingQuantity === 0.0 && $item_type !== ITEM_TEMP) { + $receivingQuantity = 1; } - $default_pack_name = lang('Items.default_pack_name'); + $defaultPackName = lang('Items.default_pack_name'); + $costPrice = parseDecimals($this->request->getPost('cost_price')); + $unitPrice = parseDecimals($this->request->getPost('unit_price')); + $reorderLevel = parseQuantity($this->request->getPost('reorder_level')); + $quantityPerPack = parseQuantity($this->request->getPost('qty_per_pack') ?? ''); - $cost_price = parse_decimals($this->request->getPost('cost_price')); - $unit_price = parse_decimals($this->request->getPost('unit_price')); - $reorder_level = parse_quantity($this->request->getPost('reorder_level')); - $qty_per_pack = parse_quantity($this->request->getPost('qty_per_pack') ?? ''); - - // Save item data - $item_data = [ + $itemData = [ 'name' => $this->request->getPost('name'), 'description' => $this->request->getPost('description'), 'category' => $this->request->getPost('category'), @@ -616,114 +612,115 @@ class Items extends Secure_Controller 'stock_type' => $this->request->getPost('stock_type') === null ? HAS_STOCK : intval($this->request->getPost('stock_type')), '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' => $cost_price, - 'unit_price' => $unit_price, - 'reorder_level' => $reorder_level, - 'receiving_quantity' => $receiving_quantity, + 'cost_price' => $costPrice, + 'unit_price' => $unitPrice, + 'reorder_level' => $reorderLevel, + 'receiving_quantity' => $receivingQuantity, '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($qty_per_pack), - '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')), + 'qty_per_pack' => $this->request->getPost('qty_per_pack') == null ? 1 : parseQuantity($quantityPerPack), + 'pack_name' => $this->request->getPost('pack_name') == null ? $defaultPackName : $this->request->getPost('pack_name'), + 'low_sell_item_id' => $this->request->getPost('low_sell_item_id') === null ? $itemId : intval($this->request->getPost('low_sell_item_id')), 'deleted' => $this->request->getPost('is_deleted') != null, 'hsn_code' => $this->request->getPost('hsn_code') === null ? '' : $this->request->getPost('hsn_code') ]; - if ($item_data['item_type'] == ITEM_TEMP) { - $item_data['stock_type'] = HAS_NO_STOCK; - $item_data['receiving_quantity'] = 0; - $item_data['reorder_level'] = 0; + if ($itemData['item_type'] == ITEM_TEMP) { + $itemData['stock_type'] = HAS_NO_STOCK; + $itemData['receiving_quantity'] = 0; + $itemData['reorder_level'] = 0; } - $tax_category_id = intval($this->request->getPost('tax_category_id')); + $taxCategoryId = intval($this->request->getPost('tax_category_id')); - if (!isset($tax_category_id)) { - $item_data['tax_category_id'] = ''; + if (!isset($taxCategoryId)) { + $itemData['tax_category_id'] = ''; } else { - $item_data['tax_category_id'] = empty($this->request->getPost('tax_category_id')) ? null : intval($this->request->getPost('tax_category_id')); + $itemData['tax_category_id'] = empty($this->request->getPost('tax_category_id')) ? null : intval($this->request->getPost('tax_category_id')); } - if (!empty($upload_data['orig_name']) && $upload_data['raw_name']) { - $item_data['pic_filename'] = $upload_data['raw_name'] . '.' . $upload_data['file_ext']; + $uploadData = $this->uploadImage(); + if (!empty($uploadData['orig_name']) && $uploadData['raw_name']) { + $itemData['pic_filename'] = $uploadData['raw_name'] . '.' . $uploadData['file_ext']; } - $employee_id = $this->employee->get_logged_in_employee_info()->person_id; - - if ($this->item->save_value($item_data, $item_id)) { + if ($this->item->saveValue($itemData, $itemId)) { $success = true; - $new_item = false; + $newItem = false; - if ($item_id === NEW_ENTRY) { - $item_id = $item_data['item_id']; - $new_item = true; + if ($itemId === NEW_ENTRY) { + $itemId = $itemData['item_id']; + $newItem = true; } - $use_destination_based_tax = (bool)$this->config['use_destination_based_tax']; + $useDestinationBasedTax = (bool)$this->config['use_destination_based_tax']; - if (!$use_destination_based_tax) { - $items_taxes_data = []; - $tax_names = $this->request->getPost('tax_names'); - $tax_percents = $this->request->getPost('tax_percents'); + if (!$useDestinationBasedTax) { + $itemTaxesData = []; + $taxNames = $this->request->getPost('tax_names'); + $taxPercents = $this->request->getPost('tax_percents'); - $tax_name_index = 0; + $taxNameIndex = 0; - foreach ($tax_percents as $tax_percent) { - $tax_percentage = parse_tax($tax_percent); + foreach ($taxPercents as $tax_percent) { + $taxPercentage = parseTax($tax_percent); - if (is_numeric($tax_percentage)) { - $items_taxes_data[] = ['name' => $tax_names[$tax_name_index], 'percent' => $tax_percentage]; + if (is_numeric($taxPercentage)) { + $itemTaxesData[] = ['name' => $taxNames[$taxNameIndex], 'percent' => $taxPercentage]; } - $tax_name_index++; + $taxNameIndex++; } - $success &= $this->item_taxes->save_value($items_taxes_data, $item_id); + $success &= $this->item_taxes->saveValue($itemTaxesData, $itemId); } // Save item quantity - $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'])); + $stockLocations = $this->stock_location->getUndeletedAll()->getResultArray(); + foreach ($stockLocations as $location) { + $updatedQuantity = parseQuantity($this->request->getPost('quantity_' . $location['location_id'])); - if ($item_data['item_type'] == ITEM_TEMP) { - $updated_quantity = 0; + if ($itemData['item_type'] == ITEM_TEMP) { + $updatedQuantity = 0; } - $location_detail = [ - 'item_id' => $item_id, + $locationDetail = [ + 'item_id' => $itemId, 'location_id' => $location['location_id'], - 'quantity' => $updated_quantity + 'quantity' => $updatedQuantity ]; - $item_quantity = $this->item_quantity->get_item_quantity($item_id, $location['location_id']); + $itemQuantity = $this->item_quantity->getItemQuantity($itemId, $location['location_id']); - if ($item_quantity->quantity != $updated_quantity || $new_item) { - $success &= $this->item_quantity->save_value($location_detail, $item_id, $location['location_id']); + if ($itemQuantity->quantity != $updatedQuantity || $newItem) { + $success &= $this->item_quantity->saveValue($locationDetail, $itemId, $location['location_id']); - $inv_data = [ + $employeeId = $this->employee->getLoggedInEmployeeInfo()->person_id; + $inventoryData = [ 'trans_date' => date('Y-m-d H:i:s'), - 'trans_items' => $item_id, - 'trans_user' => $employee_id, + 'trans_items' => $itemId, + 'trans_user' => $employeeId, 'trans_location' => $location['location_id'], 'trans_comment' => lang('Items.manually_editing_of_quantity'), - 'trans_inventory' => $updated_quantity - $item_quantity->quantity + 'trans_inventory' => $updatedQuantity - $itemQuantity->quantity ]; - $success &= $this->inventory->insert($inv_data, false); + $success &= $this->inventory->insert($inventoryData, false); } } - $this->saveItemAttributes($item_id); + $this->saveItemAttributes($itemId); - if ($success && $upload_success) { - $message = lang('Items.successful_' . ($new_item ? 'adding' : 'updating')) . ' ' . $item_data['name']; + $uploadSuccess = empty($uploadData['error']); + if ($success && $uploadSuccess) { + $message = lang('Items.successful_' . ($newItem ? 'adding' : 'updating')) . ' ' . $itemData['name']; + echo json_encode(['success' => true, 'message' => $message, 'id' => $itemId]); - echo json_encode(['success' => true, 'message' => $message, 'id' => $item_id]); + Events::trigger('item_change', $itemId); } else { - $message = $upload_success ? lang('Items.error_adding_updating') . ' ' . $item_data['name'] : strip_tags($upload_data['error']); - - echo json_encode(['success' => false, 'message' => $message, 'id' => $item_id]); + $message = $uploadSuccess ? lang('Items.error_adding_updating') . ' ' . $itemData['name'] : strip_tags($uploadData['error']); + echo json_encode(['success' => false, 'message' => $message, 'id' => $itemId]); } } else { - $message = lang('Items.error_adding_updating') . ' ' . $item_data['name']; + $message = lang('Items.error_adding_updating') . ' ' . $itemData['name']; echo json_encode(['success' => false, 'message' => $message, 'id' => NEW_ENTRY]); } @@ -733,7 +730,7 @@ class Items extends Secure_Controller * Let files be uploaded with their original name * @return array */ - private function upload_image(): array + private function uploadImage(): array { $file = $this->request->getFile('items_image'); if (!$file) { @@ -809,7 +806,7 @@ class Items extends Secure_Controller public function getRemoveLogo($item_id): void { $item_data = ['pic_filename' => null]; - $result = $this->item->save_value($item_data, $item_id); + $result = $this->item->saveValue($item_data, $item_id); echo json_encode(['success' => $result]); } @@ -820,7 +817,7 @@ class Items extends Secure_Controller */ public function postSaveInventory($item_id = NEW_ENTRY): void { - $employee_id = $this->employee->get_logged_in_employee_info()->person_id; + $employee_id = $this->employee->getLoggedInEmployeeInfo()->person_id; $cur_item_info = $this->item->get_info($item_id); $location_id = $this->request->getPost('stock_location'); $new_quantity = $this->request->getPost('newquantity'); @@ -830,20 +827,20 @@ class Items extends Secure_Controller 'trans_user' => $employee_id, 'trans_location' => $location_id, 'trans_comment' => $this->request->getPost('trans_comment'), - 'trans_inventory' => parse_quantity($new_quantity) + 'trans_inventory' => parseQuantity($new_quantity) ]; $this->inventory->insert($inv_data, false); // Update stock quantity - $item_quantity = $this->item_quantity->get_item_quantity($item_id, $location_id); + $item_quantity = $this->item_quantity->getItemQuantity($item_id, $location_id); $item_quantity_data = [ 'item_id' => $item_id, 'location_id' => $location_id, - 'quantity' => $item_quantity->quantity + parse_quantity($this->request->getPost('newquantity')) + 'quantity' => $item_quantity->quantity + parseQuantity($this->request->getPost('newquantity')) ]; - if ($this->item_quantity->save_value($item_quantity_data, $item_id, $location_id)) { + if ($this->item_quantity->saveValue($item_quantity_data, $item_id, $location_id)) { $message = lang('Items.successful_updating') . " $cur_item_info->name"; echo json_encode(['success' => true, 'message' => $message, 'id' => $item_id]); @@ -900,11 +897,15 @@ class Items extends Secure_Controller */ public function postDelete(): void { - $items_to_delete = $this->request->getPost('ids'); + $itemsToDelete = $this->request->getPost('ids'); - if ($this->item->delete_list($items_to_delete)) { - $message = lang('Items.successful_deleted') . ' ' . count($items_to_delete) . ' ' . lang('Items.one_or_multiple'); + if ($this->item->deleteList($itemsToDelete)) { + $message = lang('Items.successful_deleted') . ' ' . count($itemsToDelete) . ' ' . lang('Items.one_or_multiple'); echo json_encode(['success' => true, 'message' => $message]); + + foreach ($itemsToDelete as $itemId) { + Events::trigger('item_change', (int)$itemId); + } } else { echo json_encode(['success' => false, 'message' => lang('Items.cannot_be_deleted')]); } @@ -952,7 +953,7 @@ class Items extends Secure_Controller $failCodes = []; $csv_rows = get_csv_file($_FILES['file_path']['tmp_name']); - $employee_id = $this->employee->get_logged_in_employee_info()->person_id; + $employee_id = $this->employee->getLoggedInEmployeeInfo()->person_id; $allowed_stock_locations = $this->stock_location->get_allowed_locations(); $attribute_definition_names = $this->attribute->get_definition_names(); @@ -1013,7 +1014,7 @@ class Items extends Secure_Controller return $value !== null && strlen($value); }); - if (!$is_failed_row && $this->item->save_value($item_data, $item_id)) { + if (!$is_failed_row && $this->item->saveValue($item_data, $item_id)) { $this->save_tax_data($row, $item_data); $this->save_inventory_quantities($row, $item_data, $allowed_stock_locations, $employee_id); $is_failed_row = $this->save_attribute_data($row, $item_data, $attribute_data); // TODO: $is_failed_row never gets used after this. @@ -1222,7 +1223,7 @@ class Items extends Secure_Controller if (!empty($row["location_$location_name"]) || $row["location_$location_name"] === '0') { $item_quantity_data['quantity'] = $row["location_$location_name"]; - $this->item_quantity->save_value($item_quantity_data, $item_data['item_id'], $location_id); + $this->item_quantity->saveValue($item_quantity_data, $item_data['item_id'], $location_id); $csv_data['trans_inventory'] = $row["location_$location_name"]; $this->inventory->insert($csv_data, false); @@ -1230,7 +1231,7 @@ class Items extends Secure_Controller return; } else { $item_quantity_data['quantity'] = 0; - $this->item_quantity->save_value($item_quantity_data, $item_data['item_id'], $location_id); + $this->item_quantity->saveValue($item_quantity_data, $item_data['item_id'], $location_id); $csv_data['trans_inventory'] = 0; $this->inventory->insert($csv_data, false); @@ -1257,7 +1258,7 @@ class Items extends Secure_Controller } if (isset($items_taxes_data)) { - $this->item_taxes->save_value($items_taxes_data, $item_data['item_id']); + $this->item_taxes->saveValue($items_taxes_data, $item_data['item_id']); } } @@ -1278,14 +1279,14 @@ class Items extends Secure_Controller if (sizeof($images) > 0) { $new_pic_filename = pathinfo($images[0], PATHINFO_BASENAME); $item_data = ['pic_filename' => $new_pic_filename]; - $this->item->save_value($item_data, $item->item_id); + $this->item->saveValue($item_data, $item->item_id); } } } } /** - * Saves item attributes for a given item. + * Saves item attributes for a given item. It gets attribute data from the request and saves it to the database. * * @param int $itemId The item for which attributes need to be saved to. * @return void @@ -1305,7 +1306,7 @@ class Items extends Secure_Controller $attributeId = $attributeValue; break; case DECIMAL: - $attributeValue = parse_decimals($attributeValue); + $attributeValue = parseDecimals($attributeValue); // Fall through to save the attribute value default: $attributeId = $this->attribute->saveAttributeValue($attributeValue, $definitionId, $itemId, $attributeIds[$definitionId], $definitionType); diff --git a/app/Controllers/Receivings.php b/app/Controllers/Receivings.php index 5edcffa7b..30323f0ff 100644 --- a/app/Controllers/Receivings.php +++ b/app/Controllers/Receivings.php @@ -203,16 +203,16 @@ class Receivings extends Secure_Controller 'discount' => 'trim|permit_empty|decimal_locale', ]; - $price = parse_decimals($this->request->getPost('price')); - $quantity = parse_quantity($this->request->getPost('quantity')); - $raw_receiving_quantity = parse_quantity($this->request->getPost('receiving_quantity')); + $price = parseDecimals($this->request->getPost('price')); + $quantity = parseQuantity($this->request->getPost('quantity')); + $raw_receiving_quantity = parseQuantity($this->request->getPost('receiving_quantity')); $description = $this->request->getPost('description', FILTER_SANITIZE_FULL_SPECIAL_CHARS); // TODO: Duplicated code $serialnumber = $this->request->getPost('serialnumber', FILTER_SANITIZE_FULL_SPECIAL_CHARS) ?? ''; $discount_type = $this->request->getPost('discount_type', FILTER_SANITIZE_NUMBER_INT); $discount = $discount_type - ? parse_quantity(filter_var($this->request->getPost('discount'), FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION)) - : parse_decimals(filter_var($this->request->getPost('discount'), FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION)); + ? parseQuantity(filter_var($this->request->getPost('discount'), FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION)) + : parseDecimals(filter_var($this->request->getPost('discount'), FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION)); $receiving_quantity = filter_var($raw_receiving_quantity, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION); @@ -273,7 +273,7 @@ class Receivings extends Secure_Controller */ public function postDelete(int $receiving_id = -1, bool $update_inventory = true): void { - $employee_id = $this->employee->get_logged_in_employee_info()->person_id; + $employee_id = $this->employee->getLoggedInEmployeeInfo()->person_id; $receiving_ids = $receiving_id == -1 ? $this->request->getPost('ids', FILTER_SANITIZE_NUMBER_INT) : [$receiving_id]; // TODO: Replace -1 with constant if ($this->receiving->delete_list($receiving_ids, $employee_id, $update_inventory)) { // TODO: Likely need to surround this block of code in a try-catch to catch the ReflectionException @@ -322,11 +322,11 @@ class Receivings extends Secure_Controller $data['show_stock_locations'] = $this->stock_location->show_locations('receivings'); $data['stock_location'] = $this->receiving_lib->get_stock_source(); if ($this->request->getPost('amount_tendered') != null) { - $data['amount_tendered'] = parse_decimals($this->request->getPost('amount_tendered')); + $data['amount_tendered'] = parseDecimals($this->request->getPost('amount_tendered')); $data['amount_change'] = to_currency($data['amount_tendered'] - $data['total']); } - $employee_id = $this->employee->get_logged_in_employee_info()->person_id; + $employee_id = $this->employee->getLoggedInEmployeeInfo()->person_id; $employee_info = $this->employee->get_info($employee_id); $data['employee'] = $employee_info->first_name . ' ' . $employee_info->last_name; @@ -447,7 +447,7 @@ class Receivings extends Secure_Controller } $data['total'] = $this->receiving_lib->get_total(); - $data['items_module_allowed'] = $this->employee->has_grant('items', $this->employee->get_logged_in_employee_info()->person_id); + $data['items_module_allowed'] = $this->employee->has_grant('items', $this->employee->getLoggedInEmployeeInfo()->person_id); $data['comment'] = $this->receiving_lib->get_comment(); $data['reference'] = $this->receiving_lib->get_reference(); $data['payment_options'] = $this->receiving->get_payment_options(); diff --git a/app/Controllers/Reports.php b/app/Controllers/Reports.php index 69f242c61..d18645228 100644 --- a/app/Controllers/Reports.php +++ b/app/Controllers/Reports.php @@ -83,7 +83,7 @@ class Reports extends Secure_Controller $submodule_id = $matches[1] . ((count($matches) > 2) ? $matches[2] : 's'); // Check access to report submodule - if (!$this->employee->has_grant('reports_' . $submodule_id, $this->employee->get_logged_in_employee_info()->person_id)) { + if (!$this->employee->has_grant('reports_' . $submodule_id, $this->employee->getLoggedInEmployeeInfo()->person_id)) { redirect('no_access/reports/reports_' . $submodule_id); } } diff --git a/app/Controllers/Sales.php b/app/Controllers/Sales.php index 3cce20b59..5372fd1b7 100644 --- a/app/Controllers/Sales.php +++ b/app/Controllers/Sales.php @@ -347,7 +347,7 @@ class Sales extends Secure_Controller */ public function postSetPriceWorkOrders(): void { - $price_work_orders = parse_decimals($this->request->getPost('price_work_orders')); + $price_work_orders = parseDecimals($this->request->getPost('price_work_orders')); $this->sale_lib->set_price_work_orders($price_work_orders); } @@ -389,7 +389,7 @@ class Sales extends Secure_Controller } else { if ($payment_type === lang('Sales.giftcard')) { // In the case of giftcard payment the register input amount_tendered becomes the giftcard number - $amount_tendered = parse_decimals($this->request->getPost('amount_tendered')); + $amount_tendered = parseDecimals($this->request->getPost('amount_tendered')); $giftcard_num = $amount_tendered; $payments = $this->sale_lib->get_payments(); @@ -441,7 +441,7 @@ class Sales extends Secure_Controller } elseif ($payment_type === lang('Sales.cash')) { $amount_due = $this->sale_lib->get_total(); $sales_total = $this->sale_lib->get_total(false); - $amount_tendered = parse_decimals($this->request->getPost('amount_tendered')); + $amount_tendered = parseDecimals($this->request->getPost('amount_tendered')); $this->sale_lib->add_payment($payment_type, $amount_tendered); $cash_adjustment_amount = $amount_due - $sales_total; if ($cash_adjustment_amount <> 0) { @@ -449,7 +449,7 @@ class Sales extends Secure_Controller $this->sale_lib->add_payment(lang('Sales.cash_adjustment'), $cash_adjustment_amount, CASH_ADJUSTMENT_TRUE); } } else { - $amount_tendered = parse_decimals($this->request->getPost('amount_tendered')); + $amount_tendered = parseDecimals($this->request->getPost('amount_tendered')); $this->sale_lib->add_payment($payment_type, $amount_tendered); } } @@ -571,16 +571,16 @@ class Sales extends Secure_Controller if ($this->validate($rules)) { $description = $this->request->getPost('description', FILTER_SANITIZE_FULL_SPECIAL_CHARS); $serialnumber = $this->request->getPost('serialnumber', FILTER_SANITIZE_FULL_SPECIAL_CHARS); - $price = parse_decimals($this->request->getPost('price')); - $quantity = parse_decimals($this->request->getPost('quantity')); + $price = parseDecimals($this->request->getPost('price')); + $quantity = parseDecimals($this->request->getPost('quantity')); $discount_type = $this->request->getPost('discount_type', FILTER_SANITIZE_FULL_SPECIAL_CHARS); $discount = $discount_type - ? parse_quantity($this->request->getPost('discount')) - : parse_decimals($this->request->getPost('discount')); + ? parseQuantity($this->request->getPost('discount')) + : parseDecimals($this->request->getPost('discount')); $item_location = $this->request->getPost('location', FILTER_SANITIZE_NUMBER_INT); $discounted_total = $this->request->getPost('discounted_total') != '' - ? parse_decimals($this->request->getPost('discounted_total') ?? '') + ? parseDecimals($this->request->getPost('discounted_total') ?? '') : null; @@ -652,7 +652,7 @@ class Sales extends Secure_Controller $data['transaction_date'] = to_date($__time); $data['show_stock_locations'] = $this->stock_location->show_locations('sales'); $data['comments'] = $this->sale_lib->get_comment(); - $employee_id = $this->employee->get_logged_in_employee_info()->person_id; + $employee_id = $this->employee->getLoggedInEmployeeInfo()->person_id; $employee_info = $this->employee->get_info($employee_id); $data['employee'] = $employee_info->first_name . ' ' . mb_substr($employee_info->last_name, 0, 1); @@ -1176,8 +1176,8 @@ class Sales extends Secure_Controller $data['payment_options'] = $this->sale->get_payment_options(); } - $data['items_module_allowed'] = $this->employee->has_grant('items', $this->employee->get_logged_in_employee_info()->person_id); - $data['change_price'] = $this->employee->has_grant('sales_change_price', $this->employee->get_logged_in_employee_info()->person_id); + $data['items_module_allowed'] = $this->employee->has_grant('items', $this->employee->getLoggedInEmployeeInfo()->person_id); + $data['change_price'] = $this->employee->has_grant('sales_change_price', $this->employee->getLoggedInEmployeeInfo()->person_id); $temp_invoice_number = $this->sale_lib->get_invoice_number(); $invoice_format = $this->config['sales_invoice_format']; @@ -1300,7 +1300,7 @@ class Sales extends Secure_Controller */ public function postDelete(int $sale_id = NEW_ENTRY, bool $update_inventory = true): void { - $employee_id = $this->employee->get_logged_in_employee_info()->person_id; + $employee_id = $this->employee->getLoggedInEmployeeInfo()->person_id; $has_grant = $this->employee->has_grant('sales_delete', $employee_id); if (!$has_grant) { @@ -1327,7 +1327,7 @@ class Sales extends Secure_Controller */ public function restore(int $sale_id = NEW_ENTRY, bool $update_inventory = true): void { - $employee_id = $this->employee->get_logged_in_employee_info()->person_id; + $employee_id = $this->employee->getLoggedInEmployeeInfo()->person_id; $has_grant = $this->employee->has_grant('sales_delete', $employee_id); if (!$has_grant) { @@ -1356,7 +1356,7 @@ class Sales extends Secure_Controller public function postSave(int $sale_id = NEW_ENTRY): void { $newdate = $this->request->getPost('date', FILTER_SANITIZE_FULL_SPECIAL_CHARS); - $employee_id = $this->employee->get_logged_in_employee_info()->person_id; + $employee_id = $this->employee->getLoggedInEmployeeInfo()->person_id; $inventory = model(Inventory::class); $date_formatter = date_create_from_format($this->config['dateformat'] . ' ' . $this->config['timeformat'], $newdate); $sale_time = $date_formatter->format('Y-m-d H:i:s'); @@ -1375,9 +1375,9 @@ class Sales extends Secure_Controller for ($i = 0; $i < $number_of_payments; ++$i) { $payment_id = $this->request->getPost("payment_id_$i", FILTER_SANITIZE_NUMBER_INT); $payment_type = $this->request->getPost("payment_type_$i", FILTER_SANITIZE_FULL_SPECIAL_CHARS); - $payment_amount = parse_decimals($this->request->getPost("payment_amount_$i")); + $payment_amount = parseDecimals($this->request->getPost("payment_amount_$i")); $refund_type = $this->request->getPost("refund_type_$i", FILTER_SANITIZE_FULL_SPECIAL_CHARS); - $cash_refund = parse_decimals($this->request->getPost("refund_amount_$i")); + $cash_refund = parseDecimals($this->request->getPost("refund_amount_$i")); $cash_adjustment = $payment_type == lang('Sales.cash_adjustment') ? CASH_ADJUSTMENT_TRUE : CASH_ADJUSTMENT_FALSE; @@ -1408,7 +1408,7 @@ class Sales extends Secure_Controller $payment_type = $this->request->getPost('payment_type_new', FILTER_SANITIZE_FULL_SPECIAL_CHARS); if ($payment_type != PAYMENT_TYPE_UNASSIGNED && !empty($payment_amount_new)) { - $payment_amount = parse_decimals($payment_amount_new); + $payment_amount = parseDecimals($payment_amount_new); $cash_refund = 0; if ($payment_type == lang('Sales.cash_adjustment')) { $cash_adjustment = CASH_ADJUSTMENT_TRUE; @@ -1502,7 +1502,7 @@ class Sales extends Secure_Controller $dinner_table = $this->sale_lib->get_dinner_table(); $cart = $this->sale_lib->get_cart(); $payments = $this->sale_lib->get_payments(); - $employee_id = $this->employee->get_logged_in_employee_info()->person_id; + $employee_id = $this->employee->getLoggedInEmployeeInfo()->person_id; $customer_id = $this->sale_lib->get_customer(); $invoice_number = $this->sale_lib->get_invoice_number(); $work_order_number = $this->sale_lib->get_work_order_number(); diff --git a/app/Controllers/Secure_Controller.php b/app/Controllers/Secure_Controller.php index b346ad992..1f5c6da72 100644 --- a/app/Controllers/Secure_Controller.php +++ b/app/Controllers/Secure_Controller.php @@ -44,7 +44,7 @@ class Secure_Controller extends BaseController exit(); } - $logged_in_employee_info = $this->employee->get_logged_in_employee_info(); + $logged_in_employee_info = $this->employee->getLoggedInEmployeeInfo(); if ( !$this->employee->has_module_grant($module_id, $logged_in_employee_info->person_id) || (isset($submodule_id) && !$this->employee->has_module_grant($submodule_id, $logged_in_employee_info->person_id)) @@ -91,7 +91,7 @@ class Secure_Controller extends BaseController public function getCheckNumeric(): void { foreach ($this->request->getGet() as $value) { - if (parse_decimals($value) === false) { + if (parseDecimals($value) === false) { echo 'false'; return; } diff --git a/app/Controllers/Taxes.php b/app/Controllers/Taxes.php index c6a4bff3c..1ea1e62c4 100644 --- a/app/Controllers/Taxes.php +++ b/app/Controllers/Taxes.php @@ -372,7 +372,7 @@ class Taxes extends Secure_Controller public function postSave(int $tax_rate_id = NEW_ENTRY): void { $tax_category_id = $this->request->getPost('rate_tax_category_id', FILTER_SANITIZE_NUMBER_INT); - $tax_rate = parse_tax($this->request->getPost('tax_rate')); + $tax_rate = parseTax($this->request->getPost('tax_rate')); if ($tax_rate == 0) { // TODO: Replace 0 with constant? $tax_category_info = $this->tax_category->get_info($tax_category_id); // TODO: this variable is not used anywhere in the code diff --git a/app/Helpers/locale_helper.php b/app/Helpers/locale_helper.php index 0fc5523d3..07022c1ac 100644 --- a/app/Helpers/locale_helper.php +++ b/app/Helpers/locale_helper.php @@ -15,7 +15,7 @@ function current_language_code(bool $load_system_language = false): string $config = config(OSPOS::class)->settings; if ($employee->is_logged_in() && !$load_system_language) { - $employee_info = $employee->get_logged_in_employee_info(); + $employee_info = $employee->getLoggedInEmployeeInfo(); if (property_exists($employee_info, 'language_code') && !empty($employee_info->language_code)) { return $employee_info->language_code; @@ -38,7 +38,7 @@ function current_language(bool $load_system_language = false): string // Returns the language of the employee if set or system language if not if ($employee->is_logged_in() && !$load_system_language) { - $employee_info = $employee->get_logged_in_employee_info(); + $employee_info = $employee->getLoggedInEmployeeInfo(); if (property_exists($employee_info, 'language') && !empty($employee_info->language)) { return $employee_info->language; @@ -441,18 +441,18 @@ function to_decimals(?string $number, ?string $decimals = null, int $type = Numb * @param string $number * @return false|float|int|mixed|string */ -function parse_quantity(string $number): mixed +function parseQuantity(string $number): mixed { - return parse_decimals($number, quantity_decimals()); + return parseDecimals($number, quantity_decimals()); } /** * @param string $number * @return false|float|int|mixed|string */ -function parse_tax(string $number): mixed +function parseTax(string $number): mixed { - return parse_decimals($number, tax_decimals()); + return parseDecimals($number, tax_decimals()); } /** @@ -460,7 +460,7 @@ function parse_tax(string $number): mixed * @param int|null $decimals * @return false|float|int|mixed|string */ -function parse_decimals(string $number, ?int $decimals = null): mixed +function parseDecimals(string $number, ?int $decimals = null): mixed { if (empty($number)) { return $number; diff --git a/app/Libraries/Receiving_lib.php b/app/Libraries/Receiving_lib.php index b3cb794db..eaeffc7f5 100644 --- a/app/Libraries/Receiving_lib.php +++ b/app/Libraries/Receiving_lib.php @@ -353,7 +353,7 @@ class Receiving_lib 'quantity' => $quantity, 'discount' => $discount, 'discount_type' => $discount_type, - 'in_stock' => $this->item_quantity->get_item_quantity($item_id, $item_location)->quantity, + 'in_stock' => $this->item_quantity->getItemQuantity($item_id, $item_location)->quantity, 'price' => $price, 'receiving_quantity' => $receiving_quantity, 'receiving_quantity_choices' => $receiving_quantity_choices, diff --git a/app/Libraries/Sale_lib.php b/app/Libraries/Sale_lib.php index 2ad233ac7..f05ad76f5 100644 --- a/app/Libraries/Sale_lib.php +++ b/app/Libraries/Sale_lib.php @@ -1088,7 +1088,7 @@ class Sale_lib 'quantity' => $quantity, 'discount' => $applied_discount, 'discount_type' => $discount_type, - 'in_stock' => $this->item_quantity->get_item_quantity($item_id, $item_location)->quantity, + 'in_stock' => $this->item_quantity->getItemQuantity($item_id, $item_location)->quantity, 'price' => $price, 'cost_price' => $cost_price, 'total' => $total, @@ -1127,7 +1127,7 @@ class Sale_lib $item_info = $this->item->get_info_by_id_or_number($item_id); if ($item_info->stock_type == HAS_STOCK) { // TODO: === ? - $item_quantity = $this->item_quantity->get_item_quantity($item_id, $item_location)->quantity; + $item_quantity = $this->item_quantity->getItemQuantity($item_id, $item_location)->quantity; $quantity_added = $this->get_quantity_already_added($item_id, $item_location); if ($item_quantity - $quantity_added < 0) { diff --git a/app/Models/Employee.php b/app/Models/Employee.php index 02e627e23..f1599de26 100644 --- a/app/Models/Employee.php +++ b/app/Models/Employee.php @@ -181,7 +181,7 @@ class Employee extends Person $success = false; // Don't let employees delete themselves - if ($employee_id == $this->get_logged_in_employee_info()->person_id) { + if ($employee_id == $this->getLoggedInEmployeeInfo()->person_id) { return false; } @@ -210,7 +210,7 @@ class Employee extends Person $success = false; // Don't let employees delete themselves - if (in_array($this->get_logged_in_employee_info()->person_id, $person_ids)) { + if (in_array($this->getLoggedInEmployeeInfo()->person_id, $person_ids)) { return false; } @@ -407,7 +407,7 @@ class Employee extends Person /** * Gets information about the currently logged in employee. */ - public function get_logged_in_employee_info() + public function getLoggedInEmployeeInfo() { if ($this->is_logged_in()) { return $this->get_info($this->session->get('person_id')); diff --git a/app/Models/Inventory.php b/app/Models/Inventory.php index ff9c56ad6..502f4a725 100644 --- a/app/Models/Inventory.php +++ b/app/Models/Inventory.php @@ -76,7 +76,7 @@ class Inventory extends Model 'trans_items' => $item_id, 'trans_location' => $inventory_sum['location_id'], 'trans_comment' => lang('Items.is_deleted'), - 'trans_user' => $employee->get_logged_in_employee_info()->person_id + 'trans_user' => $employee->getLoggedInEmployeeInfo()->person_id ]); } } diff --git a/app/Models/Item.php b/app/Models/Item.php index b871291c1..c1386dc31 100644 --- a/app/Models/Item.php +++ b/app/Models/Item.php @@ -420,7 +420,7 @@ class Item extends Model /** * Inserts or updates an item */ - public function save_value(array &$item_data, int $item_id = NEW_ENTRY): bool // TODO: need to bring this in line with parent or change the name + public function saveValue(array &$item_data, int $item_id = NEW_ENTRY): bool // TODO: need to bring this in line with parent or change the name { $builder = $this->db->table('items'); @@ -497,7 +497,7 @@ class Item extends Model /** * Deletes a list of items */ - public function delete_list(array $item_ids): bool + public function deleteList(array $item_ids): bool { // Run these queries as a transaction, we want to make sure we do all or nothing $this->db->transStart(); @@ -1043,7 +1043,7 @@ class Item extends Model $data = ['cost_price' => $average_price]; - return $this->save_value($data, $item_id); + return $this->saveValue($data, $item_id); } /** diff --git a/app/Models/Item_quantity.php b/app/Models/Item_quantity.php index f7c95c6e5..7a90883ce 100644 --- a/app/Models/Item_quantity.php +++ b/app/Models/Item_quantity.php @@ -42,7 +42,7 @@ class Item_quantity extends Model * @param int $location_id * @return bool */ - public function save_value(array $location_detail, int $item_id, int $location_id): bool + public function saveValue(array $location_detail, int $item_id, int $location_id): bool { if (!$this->exists($item_id, $location_id)) { $builder = $this->db->table('item_quantities'); @@ -61,7 +61,7 @@ class Item_quantity extends Model * @param int $location_id * @return array|Item_quantity|stdClass|null */ - public function get_item_quantity(int $item_id, int $location_id): array|Item_quantity|StdClass|null + public function getItemQuantity(int $item_id, int $location_id): array|Item_quantity|StdClass|null { $builder = $this->db->table('item_quantities'); $builder->where('item_id', $item_id); @@ -90,11 +90,11 @@ class Item_quantity extends Model */ public function change_quantity(int $item_id, int $location_id, int $quantity_change): bool { - $quantity_old = $this->get_item_quantity($item_id, $location_id); + $quantity_old = $this->getItemQuantity($item_id, $location_id); $quantity_new = $quantity_old->quantity + $quantity_change; $location_detail = ['item_id' => $item_id, 'location_id' => $location_id, 'quantity' => $quantity_new]; - return $this->save_value($location_detail, $item_id, $location_id); + return $this->saveValue($location_detail, $item_id, $location_id); } /** diff --git a/app/Models/Item_taxes.php b/app/Models/Item_taxes.php index 0f42aff52..b6e9bea6a 100644 --- a/app/Models/Item_taxes.php +++ b/app/Models/Item_taxes.php @@ -33,7 +33,7 @@ class Item_taxes extends Model /** * Inserts or updates an item's taxes */ - public function save_value(array &$items_taxes_data, int $item_id): bool + public function saveValue(array &$items_taxes_data, int $item_id): bool { $success = true; diff --git a/app/Models/Receiving.php b/app/Models/Receiving.php index 2627418e3..ae7e8344e 100644 --- a/app/Models/Receiving.php +++ b/app/Models/Receiving.php @@ -159,8 +159,8 @@ class Receiving extends Model } // Update stock quantity - $item_quantity_value = $item_quantity->get_item_quantity($item_data['item_id'], $item_data['item_location']); - $item_quantity->save_value( + $item_quantity_value = $item_quantity->getItemQuantity($item_data['item_id'], $item_data['item_location']); + $item_quantity->saveValue( [ 'quantity' => $item_quantity_value->quantity + $items_received, 'item_id' => $item_data['item_id'], diff --git a/app/Models/Sale.php b/app/Models/Sale.php index cfea92233..37dd68da3 100644 --- a/app/Models/Sale.php +++ b/app/Models/Sale.php @@ -619,9 +619,9 @@ class Sale extends Model if ($cur_item_info->stock_type == HAS_STOCK && $sale_status == COMPLETED) { // TODO: === ? // Update stock quantity if item type is a standard stock item and the sale is a standard sale - $item_quantity_data = $item_quantity->get_item_quantity($item_data['item_id'], $item_data['item_location']); + $item_quantity_data = $item_quantity->getItemQuantity($item_data['item_id'], $item_data['item_location']); - $item_quantity->save_value( + $item_quantity->saveValue( [ 'quantity' => $item_quantity_data->quantity - $item_data['quantity'], 'item_id' => $item_data['item_id'], diff --git a/app/Models/Stock_location.php b/app/Models/Stock_location.php index 678f71455..19505db9e 100644 --- a/app/Models/Stock_location.php +++ b/app/Models/Stock_location.php @@ -62,7 +62,7 @@ class Stock_location extends Model * @param string $module_id * @return ResultInterface */ - public function get_undeleted_all(string $module_id = 'items'): ResultInterface + public function getUndeletedAll(string $module_id = 'items'): ResultInterface { $builder = $this->db->table('stock_locations'); $builder->join('permissions AS permissions', 'permissions.location_id = stock_locations.location_id'); @@ -99,7 +99,7 @@ class Stock_location extends Model */ public function get_allowed_locations(string $module_id = 'items'): array { - $stock = $this->get_undeleted_all($module_id)->getResultArray(); + $stock = $this->getUndeletedAll($module_id)->getResultArray(); $stock_locations = []; foreach ($stock as $location_data) { diff --git a/app/Views/item_kits/form.php b/app/Views/item_kits/form.php index 4cce6522d..717a8f904 100644 --- a/app/Views/item_kits/form.php +++ b/app/Views/item_kits/form.php @@ -193,7 +193,7 @@ - + diff --git a/app/Views/items/manage.php b/app/Views/items/manage.php index 71d0428df..a5196462e 100644 --- a/app/Views/items/manage.php +++ b/app/Views/items/manage.php @@ -47,7 +47,7 @@ use App\Models\Employee; ?> table_support.init({ - employee_id: get_logged_in_employee_info()->person_id ?>, + employee_id: getLoggedInEmployeeInfo()->person_id ?>, resource: '', headers: , pageSize: ,