Advertisement
Guest User

Untitled

a guest
Dec 22nd, 2014
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.62 KB | None | 0 0
  1.   public function Save($giohang) {
  2.         $check = TRUE;
  3.         $id = "";
  4.         $this->db->trans_begin();
  5.         $data = array(
  6.             "mahd" => $this->mahd,
  7.             "matk" => $this->matk,
  8.             "ngaydat" => $this->ngaydat,
  9.             "sodt" => $this->sodt,
  10.             "tennn" => $this->tennn,
  11.             "diachi" => $this->diachi,
  12.             "mahinhthuctt" => $this->mahinhthuctt,
  13.             "matrangthai" => $this->matrangthai
  14.         );
  15.         $isTrue = $this->db->insert("hoadon", $data);
  16.         if ($isTrue)
  17.             foreach ($giohang as $item) {
  18.                 $masp = $item['id'];
  19.                 $soluong = $item['qty'];
  20.                 $giaban = $item['price'];
  21.  
  22.                 if ($this->SoLuongSPCon($masp) < $soluong) {
  23.                     $check = FALSE;
  24.                     $id = $masp;
  25.                     break;
  26.                 } else {
  27.                     $sql = "INSERT INTO ct_hoadon(mahd, masp, sl, giaban) values (?,?,?,?)";
  28.                     $this->db->query($sql, array("$this->mahd", "$masp", $soluong, $giaban));
  29.                     $sql = "update sanpham set soluong=soluong-? where masp=?";
  30.                     $this->db->query($sql, array($soluong, "$masp"));
  31.                 }
  32.                 // echo $this->db->last_query();
  33.             }
  34.         if ($this->db->trans_status() === FALSE || $check == FALSE) {
  35.             $this->db->trans_rollback();
  36.             return array("result" => FALSE, 'masp' => $id);
  37.         } else {
  38.             $this->db->trans_commit();
  39.             return array("result" => TRUE);
  40.         }
  41.  
  42.  
  43.         //return $isTrue;
  44.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement