public function getXoaGia($id_gia, $id_sanpham)
 {
     $model = Gia::find($id_gia);
     Logfileadmin::addData("Xóa", "Giá", $id_gia, "ID Sản Phẩm: {$id_sanpham}\n Giá:{$model->gia}");
     Gia::where('id', '=', $id_gia)->where('id_sanpham', '=', $id_sanpham)->delete();
     return Redirect::to('gia/xem-gia')->with('success', 'Xóa thành công');
 }
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function destroy($id)
 {
     $sanpham = Sanpham::where('id_loai', '=', $id)->count();
     if ($sanpham > 0) {
         return Redirect::to('loais')->with('errorDelete', "Thất bại.Loại này đang tồn tại sản phẩm");
     }
     $model = $this->loai->find($id);
     Logfileadmin::addData("Xóa", "Loại", $model->id, $model->tenloai);
     $this->loai->find($id)->delete();
     return Redirect::route('loais.index');
 }
 public function postSuaSanpham($id)
 {
     $input = Input::all();
     $validation = Validator::make($input, Sanpham::$rulesUpdate);
     if ($validation->passes()) {
         $image = Input::file('hinhanh');
         if (!is_null($image)) {
             // nếu có thay doi hinh anh
             $imageName = $image->getClientOriginalName();
             $nameArray = explode('.', $imageName);
             $imageType = end($nameArray);
             $imageRules = array("jpg", "jpeg", "png");
             if (in_array($imageType, $imageRules)) {
                 //neu dung thi tien hanh insert vao csdl
                 $imageNewName = uniqid(rand(), true);
                 $imageNewName = md5($imageNewName);
                 $imageNewName = substr($imageNewName, 0, 6);
                 $imageNewName .= "." . $imageType;
                 Input::file('hinhanh')->move('uploads', $imageNewName);
                 // upload hinh anh
                 //sau khi upload thi insert vao csdl
                 $sp = Sanpham::find($id);
                 $sp->tensp = Input::get('tensp');
                 $sp->donvitinh = Input::get('donvitinh');
                 $sp->hinhanh = $imageNewName;
                 $sp->chitietsp = Input::get('chitietsp');
                 $sp->khuyenmai = Input::get('khuyenmai');
                 $sp->id_loai = Input::get('id_loai');
                 //luu logfile
                 $info = Sanpham::where('id', '=', $id)->get()->toArray();
                 Logfileadmin::addData("Sửa", "Sản Phẩm", $sp->id, $sp->tensp, $info);
                 //hoan tat update
                 $sp->save();
                 return Redirect::to("sanpham/chitiet-sanpham/{$sp->id}");
             } else {
                 return Redirect::to("sanpham/sua-sanpham/{$id}")->with('errorImage', "Không đúng định dạng hình ảnh");
             }
         } else {
             //nếu không thay doi hinh anh
             $sp = Sanpham::find($id);
             $sp->tensp = Input::get('tensp');
             $sp->donvitinh = Input::get('donvitinh');
             $sp->chitietsp = Input::get('chitietsp');
             $sp->khuyenmai = Input::get('khuyenmai');
             $sp->id_loai = Input::get('id_loai');
             //luu logfile
             $info = Sanpham::where('id', '=', $id)->get()->toArray();
             Logfileadmin::addData("Sửa", "Sản Phẩm", $sp->id, $sp->tensp, $info);
             //hoan tat update
             $sp->save();
             return Redirect::to("sanpham/chitiet-sanpham/{$sp->id}");
         }
     } else {
         return Redirect::to("sanpham/sua-sanpham/{$id}")->withInput()->withErrors($validation)->with('message', 'There were validation errors.');
     }
 }
 public function getXoaHoadon($id)
 {
     Logfileadmin::addData("Xóa", "Hóa đơn nhập", $id, "Hóa đơn nhập");
     $ctns = Chitietnhap::where('id_phieunhap', '=', $id)->get();
     foreach ($ctns as $ctn) {
         $value = "";
         $value = "ID Hóa Đơn Nhập:{$ctn->id_phieunhap}\n" . "ID Sản phẩm:{$ctn->id_sanpham}\n" . "Đơn Giá:{$ctn->dongia}\n" . "Số Lượng:{$ctn->soluong}";
         Logfileadmin::addData("Xóa", "Chi tiết hóa đơn nhập", $ctn->id, $value);
     }
     Chitietnhap::where('id_phieunhap', '=', $id)->delete();
     Phieunhap::where('id', '=', $id)->delete();
     return Redirect::to('nhap/xem-hoadon');
 }
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function destroy($id)
 {
     $model = $this->hang->find($id);
     Logfileadmin::addData("Xóa", "Hãng", $model->id, $model->tenhang);
     $this->hang->find($id)->delete();
     return Redirect::route('hangs.index');
 }
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function destroy($id)
 {
     $model = $this->nguoi_dung->find($id);
     Logfileadmin::addData("Xóa", "Thành Viên", $model->id, "Tên: " . $model->tennd . "\n Tài khoản:" . $model->taikhoan);
     $this->nguoi_dung->find($id)->delete();
     return Redirect::route('nguoi_dungs.index');
 }
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function destroy($id)
 {
     $model = $this->chung_loai->find($id);
     Logfileadmin::addData("Xóa", "Chủng Loại", $model->id, $model->tenchungloai);
     $this->chung_loai->find($id)->delete();
     return Redirect::route('chung_loais.index');
 }