refactor: extract PSR-12 renames and independent bugfixes from plugin system PR (#4784)

build/refactor/fix: tighten tooling, rename accessors to camelCase, and correct model bugs

* build: tighten gitignore, lockfile, and script config
- gitignore /build and /.php-cs-fixer.cache
- allow core-js@3.50.0 postinstall script in package.json

* refactor: rename snake_case data accessors to camelCase
Rename get_info, get_multiple_info, get_sale_items, get_sale_payments,
and save_customer across Customer, Employee, Item, Sale, and Supplier
models to PSR-12 camelCase, updating every call site in controllers,
libraries, and views.

* test: update calls to match renamed camelCase accessors
Update HomeTest, ItemsControllerTest, and ItemTest to call
getInfo()/getMultipleInfo() instead of the old snake_case model methods.

* fix: correct independent bugs in Item, Item_taxes, and Attribute models
- Item::delete()/delete_list(): let $this->db->transStatus() alone decide
  success instead of accumulating a bitwise-AND over intermediate results,
  which could report failure (and trigger error toasts) even when the
  delete had actually completed
- Item_taxes: correct $table property from 'item_taxes' to 'items_taxes'
- Attribute::getDefinitionNames(): pass an array to
  QueryBuilder->whereNotIn(), which requires one

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
objecttothisandClaude Sonnet 5 authored and GitHub committed 2026-10-28 13:00:30 +04:00
1 parent b07f5e3ebb
commit 600417bfdf
36 files changed
+141 -142

No files matched your search

+2
View File
@@ -90,3 +90,5 @@ auth.json
/app/Database/database.sql
/writable/cache/*
/.env.bak
/.php-cs-fixer.cache
/build
+12 -12
View File
@@ -56,7 +56,7 @@ class Customers extends Persons
*/
public function getRow(int $row_id): ResponseInterface
{
$person = $this->customer->get_info($row_id);
$person = $this->customer->getInfo($row_id);
// Retrieve the total amount the customer spent so far together with min, max and average values
$stats = $this->customer->get_stats($person->person_id); // TODO: This and the next 11 lines are duplicated in search(). Extract a method.
@@ -148,7 +148,7 @@ class Customers extends Persons
// Set default values
if ($customer_id == null) $customer_id = NEW_ENTRY;
$info = $this->customer->get_info($customer_id);
$info = $this->customer->getInfo($customer_id);
foreach (get_object_vars($info) as $property => $value) {
$info->$property = $value;
}
@@ -159,7 +159,7 @@ class Customers extends Persons
$data['person_info']->employee_id = $this->employee->get_logged_in_employee_info()->person_id;
}
$employee_info = $this->employee->get_info($info->employee_id);
$employee_info = $this->employee->getInfo($info->employee_id);
$data['employee'] = $employee_info->first_name . ' ' . $employee_info->last_name;
$tax_code_info = $this->tax_code->get_info($info->sales_tax_code_id);
@@ -279,7 +279,7 @@ class Customers extends Persons
'sales_tax_code_id' => $this->request->getPost('sales_tax_code_id') == '' ? null : $this->request->getPost('sales_tax_code_id', FILTER_SANITIZE_NUMBER_INT)
];
if ($this->customer->save_customer($person_data, $customer_data, $customer_id)) {
if ($this->customer->saveCustomer($person_data, $customer_data, $customer_id)) {
// Save customer to Mailchimp selected list // TODO: addOrUpdateMember should be refactored. Potentially pass an array or object instead of 6 parameters.
$mailchimp_status = $this->request->getPost('mailchimp_status');
$this->mailchimp_lib->addOrUpdateMember(
@@ -411,7 +411,7 @@ class Customers extends Persons
if (($handle = fopen($_FILES['file_path']['tmp_name'], 'r')) !== false) {
// Skip the first row as it's the table description
fgetcsv($handle);
$i = 1;
$rowNumber = 1;
$failCodes = [];
@@ -423,8 +423,8 @@ class Customers extends Persons
// Empty email is allowed, but if provided it must be valid
if ($email !== '' && !filter_var($email, FILTER_VALIDATE_EMAIL)) {
$failCodes[] = 'Row ' . $i . ': Invalid email format';
$i++;
$failCodes[] = 'Row ' . $rowNumber . ': Invalid email format';
++$rowNumber;
continue;
}
@@ -466,16 +466,16 @@ class Customers extends Persons
}
if ($invalidated) {
$failCodes[] = $i;
log_message('error', "Row $i was not imported: Either email or account number already exist or data was invalid.");
} elseif ($this->customer->save_customer($person_data, $customer_data)) {
$failCodes[] = $rowNumber;
log_message('error', "Row $rowNumber was not imported: Either email or account number already exist or data was invalid.");
} elseif ($this->customer->saveCustomer($person_data, $customer_data)) {
// Save customer to Mailchimp selected list
$this->mailchimp_lib->addOrUpdateMember($this->_list_id, $person_data['email'], $person_data['first_name'], '', $person_data['last_name']);
} else {
$failCodes[] = $i;
$failCodes[] = $rowNumber;
}
++$i;
++$rowNumber;
}
if (count($failCodes) > 0) {
+2 -2
View File
@@ -76,7 +76,7 @@ class Employees extends Persons
*/
public function getView(int $employee_id = NEW_ENTRY): string
{
$person_info = $this->employee->get_info($employee_id);
$person_info = $this->employee->getInfo($employee_id);
$current_user = $this->employee->get_logged_in_employee_info();
if ($employee_id != NEW_ENTRY && !$this->employee->canModifyEmployee($person_info->person_id, $current_user->person_id)) {
@@ -119,7 +119,7 @@ class Employees extends Persons
$currentUser = $this->employee->get_logged_in_employee_info();
if ($employeeId != NEW_ENTRY) {
$targetEmployee = $this->employee->get_info($employeeId);
$targetEmployee = $this->employee->getInfo($employeeId);
if (!$this->employee->canModifyEmployee($targetEmployee->person_id, $currentUser->person_id)) {
return $this->response->setJSON([
'success' => false,
+1 -1
View File
@@ -106,7 +106,7 @@ class Expenses extends Secure_Controller
}
} else {
$stored_employee_id = $expense_id == NEW_ENTRY ? $current_employee_id : $data['expenses_info']->employee_id;
$stored_employee = $this->employee->get_info($stored_employee_id);
$stored_employee = $this->employee->getInfo($stored_employee_id);
$data['employees'][$stored_employee_id] = $stored_employee->first_name . ' ' . $stored_employee->last_name;
}
$data['can_assign_employee'] = $can_assign_employee;
+1 -1
View File
@@ -59,7 +59,7 @@ class Home extends Secure_Controller
return $this->response->setStatusCode(403)->setBody(lang('Employees.unauthorized_modify'));
}
$person_info = $this->employee->get_info($employeeId);
$person_info = $this->employee->getInfo($employeeId);
foreach (get_object_vars($person_info) as $property => $value) {
$person_info->$property = $value;
}
+3 -3
View File
@@ -30,14 +30,14 @@ class Item_kits extends Secure_Controller
*/
private function _add_totals_to_item_kit(object $item_kit): object // TODO: Hungarian notation
{
$kit_item_info = $this->item->get_info($item_kit->kit_item_id ?? $item_kit->item_id);
$kit_item_info = $this->item->getInfo($item_kit->kit_item_id ?? $item_kit->item_id);
$item_kit->total_cost_price = 0;
$item_kit->total_unit_price = $kit_item_info->unit_price;
$total_quantity = 0;
foreach ($this->item_kit_items->get_info($item_kit->item_kit_id) as $item_kit_item) {
$item_info = $this->item->get_info($item_kit_item['item_id']);
$item_info = $this->item->getInfo($item_kit_item['item_id']);
foreach (get_object_vars($item_info) as $property => $value) {
$item_info->$property = $value;
}
@@ -142,7 +142,7 @@ class Item_kits extends Secure_Controller
foreach ($this->item_kit_items->get_info($item_kit_id) as $item_kit_item) {
$item['kit_sequence'] = $item_kit_item['kit_sequence'];
$item['name'] = $this->item->get_info($item_kit_item['item_id'])->name;
$item['name'] = $this->item->getInfo($item_kit_item['item_id'])->name;
$item['item_id'] = $item_kit_item['item_id'];
$item['quantity'] = $item_kit_item['quantity'];
+7 -7
View File
@@ -338,7 +338,7 @@ class Items extends Secure_Controller
public function getRow(string $itemIds): ResponseInterface // TODO: An array would be better for parameter.
{
$locationId = $this->item_lib->get_item_location();
$itemInfos = $this->item->get_multiple_info(explode(':', $itemIds), $locationId === null ? null : (int) $locationId);
$itemInfos = $this->item->getMultipleInfo(explode(':', $itemIds), $locationId === null ? null : (int) $locationId);
$itemResults = $itemInfos->getResult();
$definitionNames = $this->attribute->getDefinitionsByFlags(Attribute::SHOW_IN_ITEMS, true);
@@ -377,7 +377,7 @@ class Items extends Secure_Controller
unset($data['definition_names'][$definition_id]);
}
$item_info = $this->item->get_info($item_id);
$item_info = $this->item->getInfo($item_id);
$data['allow_temp_item'] = ($data['allow_temp_item'] === 1 && $item_id !== NEW_ENTRY && $item_info->item_type != ITEM_TEMP) ? 0 : 1;
@@ -483,7 +483,7 @@ class Items extends Secure_Controller
$data['selected_low_sell_item_id'] = $item_info->low_sell_item_id;
if ($item_id !== NEW_ENTRY && $item_info->item_id !== $item_info->low_sell_item_id) {
$low_sell_item_info = $this->item->get_info($item_info->low_sell_item_id);
$low_sell_item_info = $this->item->getInfo($item_info->low_sell_item_id);
$data['selected_low_sell_item'] = implode(NAME_SEPARATOR, [$low_sell_item_info->name, $low_sell_item_info->pack_name]);
} else {
$data['selected_low_sell_item'] = '';
@@ -501,7 +501,7 @@ class Items extends Secure_Controller
*/
public function getInventory(int $item_id = NEW_ENTRY): string
{
$item_info = $this->item->get_info($item_id); // TODO: Duplicate code
$item_info = $this->item->getInfo($item_id); // TODO: Duplicate code
foreach (get_object_vars($item_info) as $property => $value) {
$item_info->$property = $value;
@@ -530,7 +530,7 @@ class Items extends Secure_Controller
*/
public function getCountDetails(int $item_id = NEW_ENTRY): string
{
$item_info = $this->item->get_info($item_id); // TODO: Duplicate code
$item_info = $this->item->getInfo($item_id); // TODO: Duplicate code
foreach (get_object_vars($item_info) as $property => $value) {
$item_info->$property = $value;
@@ -563,7 +563,7 @@ class Items extends Secure_Controller
{
$item_ids = explode(':', $item_ids);
$locationId = $this->item_lib->get_item_location();
$result = $this->item->get_multiple_info($item_ids, $locationId === null ? null : (int) $locationId)->getResultArray();
$result = $this->item->getMultipleInfo($item_ids, $locationId === null ? null : (int) $locationId)->getResultArray();
$data['barcode_config'] = $this->barcode_lib->get_barcode_config();
foreach ($result as &$item) {
@@ -1013,7 +1013,7 @@ class Items extends Secure_Controller
public function postSaveInventory($item_id = NEW_ENTRY): ResponseInterface
{
$employee_id = $this->employee->get_logged_in_employee_info()->person_id;
$cur_item_info = $this->item->get_info($item_id);
$cur_item_info = $this->item->getInfo($item_id);
$location_id = $this->request->getPost('stock_location');
$new_quantity = $this->request->getPost('newquantity');
$inv_data = [
+1 -1
View File
@@ -33,7 +33,7 @@ class Messages extends Secure_Controller
public function getView(int $person_id = NEW_ENTRY): string
{
$person = model(Person::class);
$info = $person->get_info($person_id);
$info = $person->getInfo($person_id);
foreach (get_object_vars($info) as $property => $value) {
$info->$property = $value;
+1 -1
View File
@@ -49,7 +49,7 @@ abstract class Persons extends Secure_Controller
*/
public function getRow(int $row_id): ResponseInterface
{
$data_row = get_person_data_row($this->person->get_info($row_id));
$data_row = get_person_data_row($this->person->getInfo($row_id));
return $this->response->setJSON($data_row);
}
+6 -6
View File
@@ -253,7 +253,7 @@ class Receivings extends Secure_Controller
}
} else {
$stored_employee_id = $receiving_info['employee_id'];
$stored_employee = $this->employee->get_info($stored_employee_id);
$stored_employee = $this->employee->getInfo($stored_employee_id);
$data['employees'][$stored_employee_id] = $stored_employee->first_name . ' ' . $stored_employee->last_name;
}
@@ -342,12 +342,12 @@ class Receivings extends Secure_Controller
}
$employee_id = $this->employee->get_logged_in_employee_info()->person_id;
$employee_info = $this->employee->get_info($employee_id);
$employee_info = $this->employee->getInfo($employee_id);
$data['employee'] = $employee_info->first_name . ' ' . $employee_info->last_name;
$supplier_id = $this->receiving_lib->get_supplier();
if ($supplier_id != -1) {
$supplier_info = $this->supplier->get_info($supplier_id);
$supplier_info = $this->supplier->getInfo($supplier_id);
$data['supplier'] = $supplier_info->company_name; // TODO: duplicated code
$data['first_name'] = $supplier_info->first_name;
$data['last_name'] = $supplier_info->last_name;
@@ -422,12 +422,12 @@ class Receivings extends Secure_Controller
$data['reference'] = $this->receiving_lib->get_reference();
$data['receiving_id'] = 'RECV ' . $receiving_id;
$data['barcode'] = $this->barcode_lib->generate_receipt_barcode($data['receiving_id']);
$employee_info = $this->employee->get_info($receiving_info['employee_id']);
$employee_info = $this->employee->getInfo($receiving_info['employee_id']);
$data['employee'] = $employee_info->first_name . ' ' . $employee_info->last_name;
$supplier_id = $this->receiving_lib->get_supplier(); // TODO: Duplicated code
if ($supplier_id != -1) {
$supplier_info = $this->supplier->get_info($supplier_id);
$supplier_info = $this->supplier->getInfo($supplier_id);
$data['supplier'] = $supplier_info->company_name;
$data['first_name'] = $supplier_info->first_name;
$data['last_name'] = $supplier_info->last_name;
@@ -475,7 +475,7 @@ class Receivings extends Secure_Controller
$supplier_id = $this->receiving_lib->get_supplier();
if ($supplier_id != -1) { // TODO: Duplicated Code... replace -1 with a constant
$supplier_info = $this->supplier->get_info($supplier_id);
$supplier_info = $this->supplier->getInfo($supplier_id);
$data['supplier'] = $supplier_info->company_name;
$data['first_name'] = $supplier_info->first_name;
$data['last_name'] = $supplier_info->last_name;
+3 -3
View File
@@ -1364,7 +1364,7 @@ class Reports extends Secure_Controller
}
}
$customer_info = $this->customer->get_info($customer_id);
$customer_info = $this->customer->getInfo($customer_id);
$customer_name = !empty($customer_info->company_name) // TODO: This variable is not used anywhere in the code. Should it be or can it be deleted?
? "[ $customer_info->company_name ]"
: $customer_info->company_name;
@@ -1491,7 +1491,7 @@ class Reports extends Secure_Controller
}
}
$employee_info = $this->employee->get_info($employee_id);
$employee_info = $this->employee->getInfo($employee_id);
// TODO: Duplicated Code
$data = [
'title' => $employee_info->first_name . ' ' . $employee_info->last_name . ' ' . lang('Reports.report'),
@@ -1757,7 +1757,7 @@ class Reports extends Secure_Controller
];
}
$supplier_info = $this->supplier->get_info((int) $supplier_id);
$supplier_info = $this->supplier->getInfo((int) $supplier_id);
$data = [
'title' => $supplier_info->company_name . ' (' . $supplier_info->first_name . ' ' . $supplier_info->last_name . ') ' . lang('Reports.report'),
'subtitle' => $this->_get_subtitle_report(['start_date' => $start_date, 'end_date' => $end_date]),
+17 -17
View File
@@ -136,7 +136,7 @@ class Sales extends Secure_Controller
return $this->response->setStatusCode(403)->setJSON(['success' => false, 'message' => lang('Sales.not_authorized')]);
}
$saleInfo = $this->sale->get_info($rowId)->getRow();
$saleInfo = $this->sale->getInfo($rowId)->getRow();
$dataRow = getSaleDataRow($saleInfo);
return $this->response->setJSON($dataRow);
@@ -245,8 +245,8 @@ class Sales extends Secure_Controller
$customer_id = (int)$this->request->getPost('customer', FILTER_SANITIZE_NUMBER_INT);
if ($this->customer->exists($customer_id)) {
$this->sale_lib->set_customer($customer_id);
$discount = $this->customer->get_info($customer_id)->discount;
$discount_type = $this->customer->get_info($customer_id)->discount_type;
$discount = $this->customer->getInfo($customer_id)->discount;
$discount_type = $this->customer->getInfo($customer_id)->discount_type;
// Apply customer default discount to items that have 0 discount
if ($discount != '') {
@@ -493,9 +493,9 @@ class Sales extends Secure_Controller
}
} elseif ($paymentType === lang('Sales.rewards')) {
$customerId = $this->sale_lib->get_customer();
$packageId = $this->customer->get_info($customerId)->package_id;
$packageId = $this->customer->getInfo($customerId)->package_id;
if (!empty($packageId)) {
$points = $this->customer->get_info($customerId)->points;
$points = $this->customer->getInfo($customerId)->points;
$points = ($points == null ? 0 : $points);
$payments = $this->sale_lib->getPayments();
@@ -568,8 +568,8 @@ class Sales extends Secure_Controller
$customer_id = $this->sale_lib->get_customer();
if ($customer_id != NEW_ENTRY) {
// Load the customer discount if any
$customer_discount = $this->customer->get_info($customer_id)->discount;
$customer_discount_type = $this->customer->get_info($customer_id)->discount_type;
$customer_discount = $this->customer->getInfo($customer_id)->discount;
$customer_discount_type = $this->customer->getInfo($customer_id)->discount_type;
if ($customer_discount != '') {
$discount = $customer_discount;
$discount_type = $customer_discount_type;
@@ -770,7 +770,7 @@ class Sales extends Secure_Controller
$data['show_stock_locations'] = $this->stock_location->showLocations('sales');
$data['comments'] = $this->sale_lib->get_comment();
$employeeId = $this->employee->get_logged_in_employee_info()->person_id;
$employeeInfo = $this->employee->get_info($employeeId);
$employeeInfo = $this->employee->getInfo($employeeId);
$data['employee'] = $employeeInfo->first_name . ' ' . mb_substr($employeeInfo->last_name, 0, 1);
$data['company_info'] = implode("\n", [$this->config['address'], $this->config['phone']]);
@@ -1138,7 +1138,7 @@ class Sales extends Secure_Controller
$customer_info = '';
if ($customer_id != NEW_ENTRY) {
$customer_info = $this->customer->get_info($customer_id);
$customer_info = $this->customer->getInfo($customer_id);
$data['customer_id'] = $customer_id;
if (!empty($customer_info->company_name)) {
@@ -1161,11 +1161,11 @@ class Sales extends Secure_Controller
$data['customer_account_number'] = $customer_info->account_number;
$data['customer_discount'] = $customer_info->discount;
$data['customer_discount_type'] = $customer_info->discount_type;
$package_id = $this->customer->get_info($customer_id)->package_id;
$package_id = $this->customer->getInfo($customer_id)->package_id;
if ($package_id != null) {
$package_name = $this->customer_rewards->get_name($package_id);
$points = $this->customer->get_info($customer_id)->points;
$points = $this->customer->getInfo($customer_id)->points;
$data['customer_rewards']['package_id'] = $package_id;
$data['customer_rewards']['points'] = empty($points) ? 0 : $points;
$data['customer_rewards']['package_name'] = $package_name;
@@ -1205,7 +1205,7 @@ class Sales extends Secure_Controller
$cash_rounding = $this->sale_lib->reset_cash_rounding();
$data['cash_rounding'] = $cash_rounding;
$sale_info = $this->sale->get_info($sale_id)->getRowArray();
$sale_info = $this->sale->getInfo($sale_id)->getRowArray();
$this->sale_lib->copy_entire_sale($sale_id);
$data = [];
$data['cart'] = $this->sale_lib->get_cart();
@@ -1244,7 +1244,7 @@ class Sales extends Secure_Controller
$data['amount_change'] = $data['amount_due'] * -1;
$employee_info = $this->employee->get_info($this->sale_lib->get_employee());
$employee_info = $this->employee->getInfo($this->sale_lib->get_employee());
$data['employee'] = $employee_info->first_name . ' ' . mb_substr($employee_info->last_name, 0, 1);
$this->_load_customer_data($this->sale_lib->get_customer(), $data);
@@ -1476,10 +1476,10 @@ class Sales extends Secure_Controller
$data = [];
$saleInfo = $this->sale->get_info($saleId)->getRowArray();
$saleInfo = $this->sale->getInfo($saleId)->getRowArray();
$data['selected_customer_id'] = $saleInfo['customer_id'];
$data['selected_customer_name'] = $saleInfo['customer_name'];
$employeeInfo = $this->employee->get_info($saleInfo['employee_id']);
$employeeInfo = $this->employee->getInfo($saleInfo['employee_id']);
$data['selected_employee_id'] = $saleInfo['employee_id'];
$data['selected_employee_name'] = $employeeInfo->first_name . ' ' . $employeeInfo->last_name;
$data['sale_info'] = $saleInfo;
@@ -1491,7 +1491,7 @@ class Sales extends Secure_Controller
$data['payments'] = [];
foreach ($this->sale->get_sale_payments($saleId)->getResult() as $payment) {
foreach ($this->sale->getSalePayments($saleId)->getResult() as $payment) {
foreach (get_object_vars($payment) as $property => $value) {
$payment->$property = $value;
}
@@ -1677,7 +1677,7 @@ class Sales extends Secure_Controller
} else {
$cashAdjustment = CASH_ADJUSTMENT_FALSE;
$amountTendered += $paymentAmount;
$saleInfo = $this->sale->get_info($saleId)->getRowArray();
$saleInfo = $this->sale->getInfo($saleId)->getRowArray();
if ($amountTendered > $saleInfo['amount_due']) {
$cashRefund = $amountTendered - $saleInfo['amount_due'];
+2 -2
View File
@@ -34,7 +34,7 @@ class Suppliers extends Persons
*/
public function getRow($row_id): ResponseInterface
{
$data_row = get_supplier_data_row($this->supplier->get_info($row_id));
$data_row = get_supplier_data_row($this->supplier->getInfo($row_id));
$data_row['category'] = $this->supplier->get_category_name($data_row['category']);
return $this->response->setJSON($data_row);
@@ -97,7 +97,7 @@ class Suppliers extends Persons
*/
public function getView(int $supplier_id = NEW_ENTRY): string
{
$info = $this->supplier->get_info($supplier_id);
$info = $this->supplier->getInfo($supplier_id);
foreach (get_object_vars($info) as $property => $value) {
$info->$property = $value;
}
+1 -1
View File
@@ -303,7 +303,7 @@ class Receiving_lib
}
$insertKey = $maxKey + 1;
$itemInfo = $this->item->get_info((int) $itemId);
$itemInfo = $this->item->getInfo((int) $itemId);
$price = $price != null ? $price : $itemInfo->cost_price;
+3 -3
View File
@@ -1377,7 +1377,7 @@ class Sale_lib
// Establish cash_mode for this sale by inspecting the payments
if ($this->session->get('cash_rounding')) {
$cash_types_only = true;
foreach ($this->sale->get_sale_payments($sale_id)->getResult() as $row) {
foreach ($this->sale->getSalePayments($sale_id)->getResult() as $row) {
if ($row->payment_type != lang('Sales.cash') && $row->payment_type != lang('Sales.cash_adjustment')) {
$cash_types_only = false;
}
@@ -1394,7 +1394,7 @@ class Sale_lib
}
// Now load payments
foreach ($this->sale->get_sale_payments($sale_id)->getResult() as $row) {
foreach ($this->sale->getSalePayments($sale_id)->getResult() as $row) {
$this->addPayment($row->payment_type, $row->payment_amount, $row->reference_code ?? null, $row->cash_adjustment);
}
@@ -1473,7 +1473,7 @@ class Sale_lib
public function is_customer_taxable(): bool // TODO: This function is never called in the code
{
$customer_id = $this->get_customer();
$customer = $this->customer->get_info($customer_id);
$customer = $this->customer->getInfo($customer_id);
// Do not charge sales tax if we have a customer that is not taxable
return $customer->taxable or $customer_id == -1; // TODO: Replace with constant. Also, I'm not sure we should be using the or operator instead of || here. $a || $b guarantees that the result of those two get returned. It's possible that return $a or $b could return just the result of $a since `or` has a lower precedence.
+1 -1
View File
@@ -88,7 +88,7 @@ class Tax_lib
$register_mode = $this->sale_lib->get_mode();
$tax_decimals = tax_decimals();
$customer_id = $this->sale_lib->get_customer();
$customer_info = $this->customer->get_info($customer_id);
$customer_info = $this->customer->getInfo($customer_id);
$taxes = [];
$item_taxes = [];
+1 -1
View File
@@ -304,7 +304,7 @@ class Attribute extends Model
$builder->orderBy('definition_name', 'ASC');
if (!$groups) {
$builder->whereNotIn('definition_type', GROUP);
$builder->whereNotIn('definition_type', [GROUP]);
}
$results = $builder->get()->getResultArray();
+1 -1
View File
@@ -55,7 +55,7 @@ class Cashup extends Model
$employee = model(Employee::class);
return $employee->get_info($builder->get()->getRow()->employee_id);
return $employee->getInfo($builder->get()->getRow()->employee_id);
}
/**
+11 -12
View File
@@ -89,7 +89,7 @@ class Customer extends Person
/**
* Gets information about a particular customer
*/
public function get_info(?int $person_id): object
public function getInfo(?int $person_id): object
{
$builder = $this->db->table('customers');
$builder->join('people', 'people.person_id = customers.person_id');
@@ -109,7 +109,7 @@ class Customer extends Person
private function getEmptyObject(string $table_name): object
{
// Return an empty base parent object, as $item_id is NOT an item
$empty_obj = parent::get_info(NEW_ENTRY);
$empty_obj = parent::getInfo(NEW_ENTRY);
// Iterate through field definitions to determine how the fields should be initialized
foreach ($this->db->getFieldData($table_name) as $field) {
@@ -210,27 +210,26 @@ class Customer extends Person
/**
* Inserts or updates a customer
*/
public function save_customer(array &$person_data, array &$customer_data, int $customer_id = NEW_ENTRY): bool
public function saveCustomer(array &$personData, array &$customerData, int $customerId = NEW_ENTRY): bool
{
$success = false;
$this->db->transStart();
if (parent::save_value($person_data, $customer_id)) {
if (parent::save_value($personData, $customerId)) {
$builder = $this->db->table('customers');
if ($customer_id == NEW_ENTRY || !$customer_id || !$this->exists($customer_id)) {
$customer_data['person_id'] = $person_data['person_id'];
$success = $builder->insert($customer_data);
if ($customerId == NEW_ENTRY || !$customerId || !$this->exists($customerId)) {
$customerData['person_id'] = $personData['person_id'];
$success = $builder->insert($customerData);
} else {
$builder->where('person_id', $customer_id);
$success = $builder->update($customer_data);
$builder->where('person_id', $customerId);
$success = $builder->update($customerData);
$customerData['person_id'] = $customerId;
}
}
$this->db->transComplete();
$success &= $this->db->transStatus();
return $success;
return $success && $this->db->transStatus();
}
/**
+3 -3
View File
@@ -89,7 +89,7 @@ class Employee extends Person
/**
* Gets information about a particular employee
*/
public function get_info(int $person_id): object
public function getInfo(int $person_id): object
{
$builder = $this->db->table('employees');
$builder->join('people', 'people.person_id = employees.person_id');
@@ -101,7 +101,7 @@ class Employee extends Person
}
// Get empty base parent object, as $employee_id is NOT an employee
$person_obj = parent::get_info(NEW_ITEM);
$person_obj = parent::getInfo(NEW_ITEM);
// Get all the fields from employee table
// Append those fields to base parent object, we have a complete empty object
@@ -432,7 +432,7 @@ class Employee extends Person
public function get_logged_in_employee_info(): float|false|array|int|string|stdClass|null
{
if ($this->is_logged_in()) {
return $this->get_info($this->session->get('person_id'));
return $this->getInfo($this->session->get('person_id'));
}
return false;
+1 -1
View File
@@ -62,7 +62,7 @@ class Expense extends Model
$employee = model(Employee::class);
return $employee->get_info($builder->get()->getRow()->employee_id); // TODO: refactor out the nested function call.
return $employee->getInfo($builder->get()->getRow()->employee_id); // TODO: refactor out the nested function call.
}
/**
+15 -19
View File
@@ -589,7 +589,7 @@ class Item extends Model
/**
* Gets information about a particular item
*/
public function get_info(int $item_id): object
public function getInfo(int $item_id): object
{
$builder = $this->db->table('items');
$builder->select('items.*');
@@ -695,15 +695,15 @@ class Item extends Model
/**
* Gets information about multiple items
*/
public function get_multiple_info(array $item_ids, ?int $location_id): ResultInterface
public function getMultipleInfo(array $itemIds, ?int $locationId): ResultInterface
{
if ($location_id === null) {
return $this->db->table('items')->where('item_id', -1)->get();
if ($locationId === null) {
return $this->db->table($this->table)->where('item_id', -1)->get();
}
$format = $this->db->escape(dateformat_mysql());
$builder = $this->db->table('items');
$builder = $this->db->table($this->table);
$builder->select('items.*');
$builder->select('MAX(company_name) AS company_name');
$builder->select('GROUP_CONCAT(DISTINCT CONCAT_WS(\'_\', definition_id, attribute_value) ORDER BY definition_id SEPARATOR \'|\') AS attribute_values');
@@ -716,8 +716,8 @@ class Item extends Model
$builder->join('attribute_links', 'attribute_links.item_id = items.item_id AND sale_id IS NULL AND receiving_id IS NULL', 'left');
$builder->join('attribute_values', 'attribute_links.attribute_id = attribute_values.attribute_id', 'left');
$builder->where('location_id', $location_id);
$builder->whereIn('items.item_id', $item_ids);
$builder->where('location_id', $locationId);
$builder->whereIn('items.item_id', $itemIds);
$builder->groupBy('items.item_id');
@@ -825,7 +825,7 @@ class Item extends Model
/**
* Deletes one item
*/
public function delete($item_id = null, bool $purge = false): bool|int|string
public function delete($item_id = null, bool $purge = false): bool
{
$this->db->transStart();
@@ -835,16 +835,14 @@ class Item extends Model
$builder = $this->db->table('items');
$builder->where('item_id', $item_id);
$success = $builder->update(['deleted' => 1]);
$builder->update(['deleted' => 1]);
$inventory = model(Inventory::class);
$success &= $inventory->reset_quantity($item_id);
$inventory->reset_quantity($item_id);
$this->db->transComplete();
$success &= $this->db->transStatus();
return $success;
return $this->db->transStatus();
}
/**
@@ -872,19 +870,17 @@ class Item extends Model
$builder = $this->db->table('items');
$builder->whereIn('item_id', $item_ids);
$success = $builder->update(['deleted' => 1]);
$builder->update(['deleted' => 1]);
$inventory = model(Inventory::class);
foreach ($item_ids as $item_id) {
$success &= $inventory->reset_quantity($item_id);
$inventory->reset_quantity($item_id);
}
$this->db->transComplete();
$success &= $this->db->transStatus();
return $success;
return $this->db->transStatus();
}
/**
@@ -1412,7 +1408,7 @@ class Item extends Model
public function change_cost_price(int $item_id, float $items_received, float $new_price, ?float $old_price = null): bool
{
if ($old_price === null) {
$item_info = $this->get_info($item_id);
$item_info = $this->getInfo($item_id);
$old_price = $item_info->cost_price;
}
+1 -1
View File
@@ -9,7 +9,7 @@ use CodeIgniter\Model;
*/
class Item_taxes extends Model
{
protected $table = 'item_taxes';
protected $table = 'items_taxes';
protected $primaryKey = 'item_id';
protected $useAutoIncrement = false;
protected $useSoftDeletes = false;
+1 -1
View File
@@ -81,7 +81,7 @@ class Person extends Model
*
* @return object containing all the fields of the table row
*/
public function get_info(int $person_id): object
public function getInfo(int $person_id): object
{
$builder = $this->db->table('people');
$query = $builder->getWhere(['person_id' => $person_id], 1);
+2 -2
View File
@@ -132,7 +132,7 @@ class Receiving extends Model
foreach ($items as $line => $item_data) {
$config = config(OSPOS::class)->settings;
$cur_item_info = $item->get_info($item_data['item_id']);
$cur_item_info = $item->getInfo($item_data['item_id']);
$receivings_items_data = [
'receiving_id' => $receiving_id,
@@ -281,7 +281,7 @@ class Receiving extends Model
$builder->where('receiving_id', $receiving_id);
$supplier = model(Supplier::class);
return $supplier->get_info($builder->get()->getRow()->supplier_id);
return $supplier->getInfo($builder->get()->getRow()->supplier_id);
}
/**
+10 -10
View File
@@ -40,7 +40,7 @@ class Sale extends Model
/**
* Get sale info
*/
public function get_info(int $sale_id): ResultInterface
public function getInfo(int $sale_id): ResultInterface
{
$config = config(OSPOS::class)->settings;
$this->create_temp_table(['sale_id' => $sale_id]);
@@ -615,10 +615,10 @@ class Sale extends Model
$this->save_customer_rewards($customerId, $saleId, $totalAmount, $totalAmountUsed);
$customer = $customer->get_info($customerId);
$customer = $customer->getInfo($customerId);
foreach ($items as $line => $itemData) {
$curItemInfo = $item->get_info($itemData['item_id']);
$curItemInfo = $item->getInfo($itemData['item_id']);
if ($itemData['price'] == 0.00) {
$itemData['discount'] = 0.00;
@@ -814,10 +814,10 @@ class Sale extends Model
$item = model(Item::class);
$item_quantity = model(Item_quantity::class);
$items = $this->get_sale_items($sale_id)->getResultArray();
$items = $this->getSaleItems($sale_id)->getResultArray();
foreach ($items as $item_data) {
$cur_item_info = $item->get_info($item_data['item_id']);
$cur_item_info = $item->getInfo($item_data['item_id']);
if ($cur_item_info->stock_type == HAS_STOCK) {
// Create query to update inventory tracking
@@ -849,7 +849,7 @@ class Sale extends Model
/**
* Gets sale item
*/
public function get_sale_items(int $sale_id): ResultInterface
public function getSaleItems(int $sale_id): ResultInterface
{
$builder = $this->db->table('sales_items');
$builder->where('sale_id', $sale_id);
@@ -915,7 +915,7 @@ class Sale extends Model
/**
* Gets sale payments
*/
public function get_sale_payments(int $sale_id): ResultInterface
public function getSalePayments(int $sale_id): ResultInterface
{
$builder = $this->db->table('sales_payments');
$builder->where('sale_id', $sale_id);
@@ -956,7 +956,7 @@ class Sale extends Model
$builder = $this->db->table('sales');
$builder->where('sale_id', $sale_id);
return $customer->get_info($builder->get()->getRow()->customer_id);
return $customer->getInfo($builder->get()->getRow()->customer_id);
}
/**
@@ -969,7 +969,7 @@ class Sale extends Model
$employee = model(Employee::class);
return $employee->get_info($builder->get()->getRow()->employee_id);
return $employee->getInfo($builder->get()->getRow()->employee_id);
}
/**
@@ -1394,7 +1394,7 @@ class Sale extends Model
$customerRewards = model(Customer_rewards::class);
$rewards = model(Rewards::class);
$packageId = $customer->get_info($customer_id)->package_id;
$packageId = $customer->getInfo($customer_id)->package_id;
if (! empty($packageId)) {
$pointsPercent = $customerRewards->get_points_percent($packageId);
+3 -4
View File
@@ -66,7 +66,7 @@ class Supplier extends Person
/**
* Gets information about a particular supplier
*/
public function get_info(?int $person_id): object
public function getInfo(?int $person_id): object
{
$builder = $this->db->table('suppliers');
$builder->join('people', 'people.person_id = suppliers.person_id');
@@ -76,8 +76,7 @@ class Supplier extends Person
if ($query->getNumRows() == 1) { // TODO: ===
return $query->getRow();
} else {
// Get empty base parent object, as $supplier_id is NOT a supplier
$person_obj = parent::get_info(NEW_ENTRY);
$person_obj = parent::getInfo(NEW_ENTRY);
// Get all the fields from supplier table
// Append those fields to base parent object, we have a complete empty object
@@ -103,7 +102,7 @@ class Supplier extends Person
}
/**
* Inserts or updates a suppliers
* Inserts or updates a supplier
*/
public function save_supplier(array &$person_data, array &$supplier_data, int $supplier_id = NEW_ENTRY): bool
{
+1 -1
View File
@@ -41,7 +41,7 @@ class Token_customer extends Token
$customer_id = $this->sale_lib->get_customer();
if ($customer_id != NEW_ITEM && empty($this->customer_info)) {
$customer = model(Customer::class);
$customer_info = $customer->get_info($customer_id);
$customer_info = $customer->getInfo($customer_id);
if ($customer_info != '') {
return trim($customer_info->first_name . ' ' . $customer_info->last_name);
+1 -1
View File
@@ -103,7 +103,7 @@ use App\Models\Inventory;
$employeeName = [];
foreach ($inventoryArray as $row) {
$employeeData = $employee->get_info($row['trans_user']);
$employeeData = $employee->getInfo($row['trans_user']);
$employeeName[] = $employeeData->first_name . ' ' . $employeeData->last_name;
}
?>
+2 -2
View File
@@ -43,7 +43,7 @@ $this->dinner_table = model(Dinner_table::class);
<?php
if (isset($suspended_sale['customer_id'])) {
$customer = model(Customer::class); // TODO: Should we be accessing a model in a view rather than passing this data to the view via the controller?
$customer_data = $customer->get_info($suspended_sale['customer_id']);
$customer_data = $customer->getInfo($suspended_sale['customer_id']);
echo esc("$customer_data->first_name $customer_data->last_name");
} else {
?>
@@ -54,7 +54,7 @@ $this->dinner_table = model(Dinner_table::class);
<?php
if (isset($suspended_sale['employee_id'])) {
$employee = model(Employee::class);
$employee_data = $employee->get_info($suspended_sale['employee_id']);
$employee_data = $employee->getInfo($suspended_sale['employee_id']);
echo esc("$employee_data->first_name $employee_data->last_name");
} else {
?>
Generated
+2 -2
View File
@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "b43336b819b59fc4095e215ff4475e53",
"content-hash": "5b7bf691a189373a64ba0cd8c9b3e46a",
"packages": [
{
"name": "codeigniter4/framework",
@@ -5224,7 +5224,7 @@
"prefer-stable": false,
"prefer-lowest": false,
"platform": {
"php": "^8.2",
"php": ">=8.2.35 <8.3 || >=8.3.36 <8.4 || >=8.4.27",
"ext-intl": "*"
},
"platform-dev": {},
+3 -3
View File
@@ -24,7 +24,7 @@ const execAsync = promisify(exec);
/**
* Navigation SVG icon mapping for menubar:
* - source: Original SVG filename from 'node_modules/elegant-circles/svg/full-color/'
* - source: Original SVG filename from 'node_modules/elegant-circles/svg/full-color/'
* - renamed: Target filename saved in 'public/images/menubar/'
*/
const MENUBAR_ICONS = [
@@ -70,7 +70,7 @@ const injectOptions = (tag, options = {}) => ({
/**
* Emits Vinyl file objects from multiple streams sequentially.
* Native replacement for the stream-series package using Readable.from and PassThrough buffers.
* Native replacement for the stream-series package using Readable from and PassThrough buffers.
*/
const streamSeries = (...streams) => {
const buffers = streams.map(stream => {
@@ -360,7 +360,7 @@ gulp.task('debug-login-js', function() {
);
});
// Inject production minified jQuery into app/Views/login.php (production mode)
// Inject production-minified jQuery into app/Views/login.php (production mode)
gulp.task('prod-login-js', function() {
const loginProdJs = gulp.src('./public/resources/jquery-*.min.js', { read: false });
+3
View File
@@ -80,5 +80,8 @@
},
"publishConfig": {
"registry": "https://npm.pkg.github.com/"
},
"allowScripts": {
"core-js@3.50.0": true
}
}
+8 -8
View File
@@ -59,7 +59,7 @@ class HomeTest extends CIUnitTestCase
// Verify password was not changed
$employee = model(Employee::class);
$admin = $employee->get_info(1);
$admin = $employee->getInfo(1);
$this->assertTrue(password_verify('pointofsale', $admin->password),
'Password should not have been changed');
}
@@ -89,7 +89,7 @@ class HomeTest extends CIUnitTestCase
// Verify password was changed
$employee = model(Employee::class);
$admin = $employee->get_info(1);
$admin = $employee->getInfo(1);
$this->assertTrue(password_verify('pa$$w0rd', $admin->password),
'Password with 8 chars should be accepted');
@@ -183,7 +183,7 @@ class HomeTest extends CIUnitTestCase
// Verify password works
$employee = model(Employee::class);
$admin = $employee->get_info(1);
$admin = $employee->getInfo(1);
$this->assertTrue(password_verify($specialPassword, $admin->password));
// Restore original password
@@ -223,7 +223,7 @@ class HomeTest extends CIUnitTestCase
// Verify password was NOT changed
$employee = model(Employee::class);
$admin = $employee->get_info(1);
$admin = $employee->getInfo(1);
$this->assertTrue(password_verify('pointofsale', $admin->password),
'Single character password should be rejected (CVE fix)');
}
@@ -334,7 +334,7 @@ class HomeTest extends CIUnitTestCase
// Verify admin password was NOT changed
$employee = model(Employee::class);
$admin = $employee->get_info(1);
$admin = $employee->getInfo(1);
$this->assertTrue(password_verify('pointofsale', $admin->password),
'Admin password should not have been changed by non-admin');
}
@@ -377,7 +377,7 @@ class HomeTest extends CIUnitTestCase
// Verify password was changed
$employee = model(Employee::class);
$user = $employee->get_info($nonAdminId);
$user = $employee->getInfo($nonAdminId);
$this->assertTrue(password_verify('newpassword123', $user->password));
}
@@ -419,7 +419,7 @@ class HomeTest extends CIUnitTestCase
// Verify password was changed
$employee = model(Employee::class);
$user = $employee->get_info($nonAdminId);
$user = $employee->getInfo($nonAdminId);
$this->assertTrue(password_verify('adminset123', $user->password));
}
@@ -491,7 +491,7 @@ class HomeTest extends CIUnitTestCase
// Verify victim's password was NOT changed
$employeeModel = model(Employee::class);
$victim = $employeeModel->get_info($victimId);
$victim = $employeeModel->getInfo($victimId);
$this->assertTrue(password_verify('victimpass123', $victim->password),
'Non-admin should not be able to change another non-admin password');
}
+7 -7
View File
@@ -552,7 +552,7 @@ class ItemsControllerTest extends CIUnitTestCase
$this->assertIsInt((int) $row->item_id);
$this->assertGreaterThan(0, (int) $row->item_id);
$savedItem = $this->item->get_info((int) $row->item_id);
$savedItem = $this->item->getInfo((int) $row->item_id);
$this->assertEquals('CSV Imported Item', $savedItem->name);
$this->assertEquals('Description from CSV', $savedItem->description);
$this->assertEquals('Electronics', $savedItem->category);
@@ -749,7 +749,7 @@ class ItemsControllerTest extends CIUnitTestCase
$this->assertTrue($this->item->save_value($updatedData, $updatedData['item_id']));
$updatedItem = $this->item->get_info($updatedData['item_id']);
$updatedItem = $this->item->getInfo($updatedData['item_id']);
$this->assertEquals('Updated Name', $updatedItem->name);
$this->assertEquals('Updated Category', $updatedItem->category);
$this->assertEquals(15.00, (float)$updatedItem->cost_price);
@@ -939,7 +939,7 @@ class ItemsControllerTest extends CIUnitTestCase
$this->assertTrue($this->item->save_value($itemData));
$savedItem = $this->item->get_info($itemData['item_id']);
$savedItem = $this->item->getInfo($itemData['item_id']);
$this->assertEquals(-1, (int)$savedItem->reorder_level);
}
@@ -978,7 +978,7 @@ class ItemsControllerTest extends CIUnitTestCase
$this->assertTrue($this->item->save_value($itemData));
$savedItem = $this->item->get_info($itemData['item_id']);
$savedItem = $this->item->getInfo($itemData['item_id']);
$this->assertSame(
$case['expected_cost_price'],
@@ -1008,7 +1008,7 @@ class ItemsControllerTest extends CIUnitTestCase
$this->assertTrue($this->item->save_value($itemData));
$savedItem = $this->item->get_info($itemData['item_id']);
$savedItem = $this->item->getInfo($itemData['item_id']);
$this->assertEquals('8471', $savedItem->hsn_code);
}
@@ -1101,7 +1101,7 @@ class ItemsControllerTest extends CIUnitTestCase
$this->assertIsInt($itemData['item_id']);
$this->assertGreaterThan(0, $itemData['item_id']);
$savedItem = $this->item->get_info($itemData['item_id']);
$savedItem = $this->item->getInfo($itemData['item_id']);
$this->assertEquals('Item Without Barcode', $savedItem->name);
}
@@ -1195,7 +1195,7 @@ class ItemsControllerTest extends CIUnitTestCase
];
$this->inventory->insert($inventoryData);
$savedItem = $this->item->get_info($itemData['item_id']);
$savedItem = $this->item->getInfo($itemData['item_id']);
$this->assertEquals('Complete Test Item', $savedItem->name);
$this->assertEquals('Electronics', $savedItem->category);
$this->assertEquals(50.00, (float)$savedItem->cost_price);
+2 -2
View File
@@ -81,7 +81,7 @@ class ItemTest extends CIUnitTestCase
$itemId = $this->createTestItem();
$itemModel = model(Item::class);
$result = $itemModel->get_multiple_info([$itemId], null);
$result = $itemModel->getMultipleInfo([$itemId], null);
$this->assertSame(0, $result->getNumRows());
}
@@ -96,7 +96,7 @@ class ItemTest extends CIUnitTestCase
]);
$itemModel = model(Item::class);
$result = $itemModel->get_multiple_info([$itemId], self::LOCATION_ID);
$result = $itemModel->getMultipleInfo([$itemId], self::LOCATION_ID);
$this->assertSame(1, $result->getNumRows());
}