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