From 1863db9ab48204d38e4e80e86d275d62d7b4c45a Mon Sep 17 00:00:00 2001 From: Steve Ireland Date: Sat, 25 Mar 2023 10:37:56 -0400 Subject: [PATCH] Bulk Model changes. --- app/Models/Cashup.php | 4 ++-- app/Models/Employee.php | 4 ++-- app/Models/Item.php | 6 +++--- app/Models/Sale.php | 14 +++++++------- app/Models/Stock_location.php | 2 +- app/Models/Supplier.php | 2 +- app/Models/Tax.php | 2 +- app/Models/Tax_category.php | 4 ++-- app/Models/Tax_code.php | 2 +- app/Models/Tax_jurisdiction.php | 4 ++-- app/Models/Tokens/Token_customer.php | 2 +- 11 files changed, 23 insertions(+), 23 deletions(-) diff --git a/app/Models/Cashup.php b/app/Models/Cashup.php index 54cdb8e4d..e503b6384 100644 --- a/app/Models/Cashup.php +++ b/app/Models/Cashup.php @@ -215,9 +215,9 @@ class Cashup extends Model /** * Inserts or updates a cashup */ - public function save_value(array &$cash_up_data, $cashup_id = FALSE): bool + public function save_value(array &$cash_up_data, $cashup_id = NEW_ITEM): bool { - if(!$cashup_id == -1 || !$this->exists($cashup_id)) //TODO: Replace -1 with constant + if(!$cashup_id == NEW_ITEM || !$this->exists($cashup_id)) { $builder = $this->db->table('cash_up'); if($builder->insert($cash_up_data)) diff --git a/app/Models/Employee.php b/app/Models/Employee.php index 1e7efddb8..3de3afaf7 100644 --- a/app/Models/Employee.php +++ b/app/Models/Employee.php @@ -95,13 +95,13 @@ class Employee extends Person } //Get empty base parent object, as $employee_id is NOT an employee - $person_obj = parent::get_info(-1); //TODO: Replace -1 with a constant + $person_obj = parent::get_info(NEW_ITEM); //Get all the fields from employee table //append those fields to base parent object, we have a complete empty object foreach($this->db->getFieldNames('employees') as $field) { - $person_obj->$field = ''; + $person_obj->$field = null; } return $person_obj; diff --git a/app/Models/Item.php b/app/Models/Item.php index 55d307d3d..3b3764c82 100644 --- a/app/Models/Item.php +++ b/app/Models/Item.php @@ -280,11 +280,11 @@ class Item extends Model /** * Returns all the items */ - public function get_all(int $stock_location_id = -1, int $rows = 0, int $limit_from = 0): ResultInterface //TODO: Replace -1 with a constant + public function get_all(int $stock_location_id = NEW_ENTRY, int $rows = 0, int $limit_from = 0): ResultInterface { $builder = $this->db->table('items'); - if($stock_location_id > -1) //TODO: Replace -1 with a constant + if($stock_location_id > -1) { $builder->join('item_quantities', 'item_quantities.item_id = items.item_id'); $builder->where('location_id', $stock_location_id); @@ -438,7 +438,7 @@ class Item extends Model if($builder->insert($item_data)) { $item_data['item_id'] = $this->db->insertID(); - if($item_data['low_sell_item_id'] == -1) //TODO: Replace -1 with a constant... === ? + if($item_data['low_sell_item_id'] == NEW_ENTRY) { $builder = $this->db->table('items'); $builder->where('item_id', $item_data['item_id']); diff --git a/app/Models/Sale.php b/app/Models/Sale.php index 9b823ac2b..f1c240c28 100644 --- a/app/Models/Sale.php +++ b/app/Models/Sale.php @@ -592,7 +592,7 @@ class Sale extends Model $cash_adjustment = $payment['cash_adjustment']; $employee_id = $payment['employee_id']; - if($payment_id == -1 && $payment_amount != 0) + if($payment_id == NEW_ENTRY && $payment_amount != 0) { // Add a new payment transaction $sales_payments_data = [ @@ -605,7 +605,7 @@ class Sale extends Model ]; $success = $builder->insert($sales_payments_data); } - elseif($payment_id != -1) + elseif($payment_id != NEW_ENTRY) { if($payment_amount != 0) { @@ -651,7 +651,7 @@ class Sale extends Model $item = model(Item::class); $item_quantity = model(Item_quantity::class); - if($sale_id != -1) + if($sale_id != NEW_ENTRY) { $this->clear_suspended_sale_detail($sale_id); } @@ -681,7 +681,7 @@ class Sale extends Model $builder = $this->db->table('sales'); - if($sale_id == -1) //TODO: I think we have a constant for this and the -1 needs to be replaced with the constant in constants.php... something like NEW_SALE + if($sale_id == NEW_ENTRY) { $builder->insert($sales_data); $sale_id = $this->db->insertID(); @@ -795,7 +795,7 @@ class Sale extends Model $attribute->copy_attribute_links($item_data['item_id'], 'sale_id', $sale_id); } - if($customer_id == -1 || $customer->taxable) //TODO: Need a NEW_CUSTOMER constant in constants.php instead of -1 + if($customer_id == NEW_ENTRY || $customer->taxable) { $this->save_sales_tax($sale_id, $sales_taxes[0]); $this->save_sales_items_taxes($sale_id, $sales_taxes[1]); @@ -1341,7 +1341,7 @@ class Sale extends Model */ public function get_all_suspended(int $customer_id = NULL): array { - if($customer_id == -1) //TODO: This should be converted to a global constant and stored in constants.php + if($customer_id == NEW_ENTRY) { $query = $this->db->query("SELECT sale_id, case when sale_type = '".SALE_TYPE_QUOTE."' THEN quote_number WHEN sale_type = '".SALE_TYPE_WORK_ORDER."' THEN work_order_number else sale_id end as doc_id, sale_id as suspended_sale_id, sale_status, sale_time, dinner_table_id, customer_id, employee_id, comment FROM " . $this->db->prefixTable('sales') . ' where sale_status = ' . SUSPENDED); @@ -1360,7 +1360,7 @@ class Sale extends Model */ public function get_dinner_table(int $sale_id) //TODO: this is returning NULL or the table_id. We can keep it this way but multiple return types can't be declared until PHP 8.x { - if($sale_id == -1) + if($sale_id == NEW_ENTRY) { return NULL; } diff --git a/app/Models/Stock_location.php b/app/Models/Stock_location.php index 3a4a7f5b3..e665c7221 100644 --- a/app/Models/Stock_location.php +++ b/app/Models/Stock_location.php @@ -31,7 +31,7 @@ class Stock_location extends Model $this->session = session(); } - public function exists(int $location_id = -1): bool //TODO: Replace -1 with a constant + public function exists(int $location_id = NEW_ENTRY): bool { $builder = $this->db->table('stock_locations'); $builder->where('location_id', $location_id); diff --git a/app/Models/Supplier.php b/app/Models/Supplier.php index af1d1907d..0eb560338 100644 --- a/app/Models/Supplier.php +++ b/app/Models/Supplier.php @@ -81,7 +81,7 @@ class Supplier extends Person else { //Get empty base parent object, as $supplier_id is NOT a supplier - $person_obj = parent::get_info(-1); //TODO: need to replace with a constant instead of -1 + $person_obj = parent::get_info(NEW_ENTRY); //Get all the fields from supplier table //append those fields to base parent object, we have a complete empty object diff --git a/app/Models/Tax.php b/app/Models/Tax.php index 4402dc851..95d6e737c 100644 --- a/app/Models/Tax.php +++ b/app/Models/Tax.php @@ -163,7 +163,7 @@ class Tax extends Model /** Inserts or updates a tax_rates entry */ - public function save_value(array &$tax_rate_data, int $tax_rate_id = -1): bool //TODO: the default value for $tax_rate_id should be made a constant and replaced here. + public function save_value(array &$tax_rate_data, int $tax_rate_id = NEW_ENTRY): bool { $builder = $this->db->table('tax_rates'); if(!$this->exists($tax_rate_id)) diff --git a/app/Models/Tax_category.php b/app/Models/Tax_category.php index 16373f84c..61d2c6d32 100644 --- a/app/Models/Tax_category.php +++ b/app/Models/Tax_category.php @@ -150,7 +150,7 @@ class Tax_category extends Model $this->save_value($tax_category_data, $value['tax_category_id']); - if($value['tax_category_id'] == -1) //TODO: -1 should be converted into a constant for code readability. Perhaps NO_TAX_CATEGORY? + if($value['tax_category_id'] == NEW_ENTRY) { $not_to_delete[] = $tax_category_data['tax_category_id']; } @@ -270,7 +270,7 @@ class Tax_category extends Model { return [ '0' => [ - 'tax_category_id' => -1, //TODO: This should probably be a Constant instead of -1 + 'tax_category_id' => NEW_ENTRY, 'tax_category' => '', 'tax_group_sequence' => '', 'deleted' => '' diff --git a/app/Models/Tax_code.php b/app/Models/Tax_code.php index fffed6eb9..03e748420 100644 --- a/app/Models/Tax_code.php +++ b/app/Models/Tax_code.php @@ -313,7 +313,7 @@ class Tax_code extends Model { return [ '0' => [ - 'tax_code_id' => -1, + 'tax_code_id' => NEW_ENTRY, 'tax_code' => '', 'tax_code_name' => '', 'city' => '', diff --git a/app/Models/Tax_jurisdiction.php b/app/Models/Tax_jurisdiction.php index e33c43ffe..5bc4cd8ba 100644 --- a/app/Models/Tax_jurisdiction.php +++ b/app/Models/Tax_jurisdiction.php @@ -155,7 +155,7 @@ class Tax_jurisdiction extends Model $this->save_value($tax_jurisdiction_data, $value['jurisdiction_id']); - if($value['jurisdiction_id'] == -1) //TODO: replace -1 with a constant. Also === ?. Also replace this with ternary notation. + if($value['jurisdiction_id'] == NEW_ENTRY) { $not_to_delete[] = $tax_jurisdiction_data['jurisdiction_id']; } @@ -256,7 +256,7 @@ class Tax_jurisdiction extends Model { return [ '0' => [ - 'jurisdiction_id' => -1, //TODO: Replace -1 with a constant + 'jurisdiction_id' => NEW_ENTRY, 'jurisdiction_name' => '', 'tax_group' => '', 'tax_type' => '1', diff --git a/app/Models/Tokens/Token_customer.php b/app/Models/Tokens/Token_customer.php index 2475e2b05..83575e831 100644 --- a/app/Models/Tokens/Token_customer.php +++ b/app/Models/Tokens/Token_customer.php @@ -34,7 +34,7 @@ class Token_customer extends Token { //substitute customer info $customer_id = $this->sale_lib->get_customer(); - if($customer_id != -1 && empty($this->customer_info)) //TODO: Replace -1 with a Constant + if($customer_id != NEW_ITEM && empty($this->customer_info)) { $customer = model(Customer::class); $customer_info = $customer->get_info($customer_id);