Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function Save($giohang) {
- $check = TRUE;
- $id = "";
- $this->db->trans_begin();
- $data = array(
- "mahd" => $this->mahd,
- "matk" => $this->matk,
- "ngaydat" => $this->ngaydat,
- "sodt" => $this->sodt,
- "tennn" => $this->tennn,
- "diachi" => $this->diachi,
- "mahinhthuctt" => $this->mahinhthuctt,
- "matrangthai" => $this->matrangthai
- );
- $isTrue = $this->db->insert("hoadon", $data);
- if ($isTrue)
- foreach ($giohang as $item) {
- $masp = $item['id'];
- $soluong = $item['qty'];
- $giaban = $item['price'];
- if ($this->SoLuongSPCon($masp) < $soluong) {
- $check = FALSE;
- $id = $masp;
- break;
- } else {
- $sql = "INSERT INTO ct_hoadon(mahd, masp, sl, giaban) values (?,?,?,?)";
- $this->db->query($sql, array("$this->mahd", "$masp", $soluong, $giaban));
- $sql = "update sanpham set soluong=soluong-? where masp=?";
- $this->db->query($sql, array($soluong, "$masp"));
- }
- // echo $this->db->last_query();
- }
- if ($this->db->trans_status() === FALSE || $check == FALSE) {
- $this->db->trans_rollback();
- return array("result" => FALSE, 'masp' => $id);
- } else {
- $this->db->trans_commit();
- return array("result" => TRUE);
- }
- //return $isTrue;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement