I Want To insert data in transaction table and at the same time update customer table in codeigniter

by ┘ĆEng Mohamed Abd Elalem   Last Updated September 23, 2018 01:06 AM

(codeigniter) I Want To insert data in transaction table and at the same time update customer table . I want to Add value of ChangeDue in transation table To value now_debt in Customer Table

Function in transaction Model

public function add($_iN, $_iC, $desc, $q, $qs, $_up, $_tp, $change_due, 
$cn) {
$data = ['itemName' => $_iN, 'itemCode' => $_iC, 'description' => $desc,
'quantity' => $q, 'quantitys' => $qs, 'unitPrice' => $_up, 
'totalPrice' => $_tp,'changeDue' => $change_due,'cust_id'=>$cn];
     $this->db->insert('transactions', $data);
     $this->db->set('customer.now_debt', 'customer.now_debt' + $change_due);
     $this->db->where('customer_id', $cn);
     $this->db->join('transactions', 'transactions.cust_id = 
     customer.customer_id');
    $this->db->update('customer');
    if ($this->db->affected_rows()) {
        return $this->db->insert_id();
    }
    else {
        return FALSE;
    }
}


Related Questions



cant connect to postgresql from codeigniter

Updated June 28, 2018 11:06 AM


Updates with many rows and lock escalation

Updated November 07, 2018 16:06 PM

Scrambling PII data in CLOB columns

Updated September 11, 2018 07:06 AM