Fixed sale->update() signature

This commit is contained in:
objecttothis
2023-02-10 23:24:05 +04:00
committed by Steve Ireland
parent bc8c3fd2c3
commit d408675370
3 changed files with 11 additions and 10 deletions

View File

@@ -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;
}
}
}

View File

@@ -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);
}
}
}

View File

@@ -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'];