From ae5d23f77d0a69f73b2e24921fb53544a83a7e4f Mon Sep 17 00:00:00 2001 From: FrancescoUK Date: Thu, 21 Apr 2016 19:25:06 +0100 Subject: [PATCH] Make the payment type change a unique transaction in the model (#314) --- application/models/Sale.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/application/models/Sale.php b/application/models/Sale.php index 70482f3a8..f4a73ed98 100644 --- a/application/models/Sale.php +++ b/application/models/Sale.php @@ -248,6 +248,9 @@ class Sale extends CI_Model // 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)) { + //Run these queries as a transaction, we want to make sure we do all or nothing + $this->db->trans_start(); + // first delete all payments $this->db->delete('sales_payments', array('sale_id'=>$sale_id)); @@ -262,6 +265,10 @@ class Sale extends CI_Model $success = $this->db->insert('sales_payments', $sales_payments_data); } + + $this->db->trans_complete(); + + $success = $this->db->trans_status(); } return $success;