From d408675370c81591c3786e93bc3b078aba8bb5b5 Mon Sep 17 00:00:00 2001 From: objecttothis Date: Fri, 10 Feb 2023 23:24:05 +0400 Subject: [PATCH] Fixed sale->update() signature --- app/Controllers/Sales.php | 6 +++--- app/Libraries/Sale_lib.php | 9 +++++---- app/Models/Sale.php | 6 +++--- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/app/Controllers/Sales.php b/app/Controllers/Sales.php index 95afb75ff..65f39cc4f 100644 --- a/app/Controllers/Sales.php +++ b/app/Controllers/Sales.php @@ -1471,7 +1471,7 @@ class Sales extends Secure_Controller } } - $payments[] = [ + $sale_data['payments'] = [ 'payment_id' => $payment_id, 'payment_type' => $payment_type, 'payment_amount' => $payment_amount, @@ -1482,7 +1482,7 @@ class Sales extends Secure_Controller } $this->inventory->update('POS '.$sale_id, ['trans_date' => $sale_time]); //TODO: Reflection Exception - if($this->sale->update($sale_id, $sale_data, $payments)) + if($this->sale->update($sale_id, $sale_data)) { echo json_encode (['success' => TRUE, 'message' => lang('Sales.successfully_updated'), 'id' => $sale_id]); } @@ -1707,4 +1707,4 @@ class Sales extends Secure_Controller return NULL; } -} \ No newline at end of file +} diff --git a/app/Libraries/Sale_lib.php b/app/Libraries/Sale_lib.php index 3e8eec954..4e1bf686d 100644 --- a/app/Libraries/Sale_lib.php +++ b/app/Libraries/Sale_lib.php @@ -14,6 +14,7 @@ use App\Models\Sale; use CodeIgniter\Session\Session; use App\Models\Stock_location; use ReflectionException; +use App\Libraries\Tax_lib; /** * Sale library @@ -30,15 +31,13 @@ use ReflectionException; * @property rounding_mode rounding_mode * @property sale sale * @property stock_location stock_location - * - * @property tax_lib tax_lib + * @property Tax_lib tax_lib * @property session session */ class Sale_lib { public function __construct() { - $this->tax_lib = new Tax_lib(); $this->session = Session(); $this->attribute = model('Attribute'); @@ -1424,6 +1423,8 @@ class Sale_lib if(!config('OSPOS')->settings['tax_included']) { $cart = $this->get_cart(); + $this->tax_lib = new \app\Libraries\Tax_lib(); + foreach($this->tax_lib->get_taxes($cart)[0] as $tax) { $total = bcadd($total, $tax['sale_tax_amount']); @@ -1450,4 +1451,4 @@ class Sale_lib return Rounding_mode::round_number($cash_rounding_code, (float)$total, $cash_decimals); } -} \ No newline at end of file +} diff --git a/app/Models/Sale.php b/app/Models/Sale.php index c12b18451..bdb2ed263 100644 --- a/app/Models/Sale.php +++ b/app/Models/Sale.php @@ -537,14 +537,14 @@ class Sale extends Model /** * Update sale */ - public function update($sale_id = NULL, array $sale_data = NULL, array $payments = NULL): bool + public function update($sale_id = NULL, $sale_data = NULL): bool { $builder = $this->db->table('sales'); $builder->where('sale_id', $sale_id); $success = $builder->update($sale_data); //touch payment only if update sale is successful and there is a payments object otherwise the result would be to delete all the payments associated to the sale - if($success && !empty($payments)) + if($success && !empty($sale_data['payments'])) { //Run these queries as a transaction, we want to make sure we do all or nothing $this->db->transStart(); @@ -552,7 +552,7 @@ class Sale extends Model $builder = $this->db->table('sales_payments'); // add new payments - foreach($payments as $payment) + foreach($sale_data['payments'] as $payment) { $payment_id = $payment['payment_id']; $payment_type = $payment['payment_type'];