From 1d87de6f7d36d102733a3d0199459f8b03a70773 Mon Sep 17 00:00:00 2001 From: objecttothis Date: Fri, 3 Mar 2023 17:44:37 +0400 Subject: [PATCH] Sales MVC - Added todo to Stock_location.php - make library function return nullable - Added missing model instantiation - Commented out Sale model instantiation in library because it's causing infinite loop - Changed function name prepending get and post required by CI4 autorouting --- app/Controllers/Sales.php | 13 ++++++++----- app/Libraries/Sale_lib.php | 10 +++++----- app/Models/Sale.php | 2 +- app/Models/Stock_location.php | 2 +- 4 files changed, 15 insertions(+), 12 deletions(-) diff --git a/app/Controllers/Sales.php b/app/Controllers/Sales.php index 3d0d8548d..a70977aa0 100644 --- a/app/Controllers/Sales.php +++ b/app/Controllers/Sales.php @@ -56,6 +56,9 @@ class Sales extends Secure_Controller $this->tax_lib = new Tax_lib(); $this->token_lib = new Token_lib(); $this->config = config('OSPOS')->settings; + + $this->customer = model('Customer'); + $this->sale = model('Sale'); $this->stock_location = model('Stock_location'); } @@ -65,7 +68,7 @@ class Sales extends Secure_Controller $this->_reload(); //TODO: Hungarian Notation } - public function manage(): void + public function getManage(): void { $person_id = $this->session->get('person_id'); @@ -169,9 +172,9 @@ class Sales extends Secure_Controller echo json_encode($suggestions); } - public function select_customer(): void + public function postSelect_customer(): void { - $customer_id = $this->request->getPost('customer', FILTER_SANITIZE_NUMBER_INT); + $customer_id = (int)$this->request->getPost('customer', FILTER_SANITIZE_NUMBER_INT); if($this->customer->exists($customer_id)) { $this->sale_lib->set_customer($customer_id); @@ -188,7 +191,7 @@ class Sales extends Secure_Controller $this->_reload(); } - public function change_mode(): void + public function postChange_mode(): void { $mode = $this->request->getPost('mode', FILTER_SANITIZE_STRING); $this->sale_lib->set_mode($mode); @@ -451,7 +454,7 @@ class Sales extends Secure_Controller $this->_reload(); //TODO: Hungarian notation } - public function add(): void + public function postAdd(): void { $data = []; diff --git a/app/Libraries/Sale_lib.php b/app/Libraries/Sale_lib.php index d2a6102f5..eeb9d94ab 100644 --- a/app/Libraries/Sale_lib.php +++ b/app/Libraries/Sale_lib.php @@ -48,7 +48,7 @@ class Sale_lib $this->item_quantity = model('Item_quantity'); $this->item_taxes = model('Item_taxes'); $this->rounding_mode = model('enums/Rounding_mode'); - $this->sale = model('Sale'); +// $this->sale = model('Sale'); //TODO: This is causing an infinite loop because the constructor calls the sale library $this->stock_location = model('Stock_location'); $this->config = config('OSPOS')->settings; } @@ -219,17 +219,17 @@ class Sale_lib $this->session->remove('sales_comment'); } - public function get_invoice_number(): string + public function get_invoice_number(): ?string { return $this->session->get('sales_invoice_number'); } - public function get_quote_number(): string + public function get_quote_number(): ?string { return $this->session->get('sales_quote_number'); } - public function get_work_order_number(): string + public function get_work_order_number(): ?string { return $this->session->get('sales_work_order_number'); } @@ -759,7 +759,7 @@ class Sale_lib $this->session->set('payment_type', $payment_type); } - public function get_payment_type(): string + public function get_payment_type(): ?string { return $this->session->get('payment_type'); } diff --git a/app/Models/Sale.php b/app/Models/Sale.php index 18008ba1d..9d86158b1 100644 --- a/app/Models/Sale.php +++ b/app/Models/Sale.php @@ -46,7 +46,7 @@ class Sale extends Model { parent::__construct(); -// $this->sale_lib = new Sale_lib(); //TODO: This is causing an infinite loop because the sale lib is invoking the sale model and the model invokes the sale_lib + $this->sale_lib = new Sale_lib(); } /** diff --git a/app/Models/Stock_location.php b/app/Models/Stock_location.php index 67d3c7ce7..3a4a7f5b3 100644 --- a/app/Models/Stock_location.php +++ b/app/Models/Stock_location.php @@ -107,7 +107,7 @@ class Stock_location extends Model $builder->where('deleted', 0); $builder->limit(1); - return $builder->get()->getRow()->location_id; + return $builder->get()->getRow()->location_id; //TODO: this is puking. Trying to get property 'location_id' of non-object } public function get_location_name(int $location_id): string