public function getThemSanpham($id)
 {
     $sanpham = Sanpham::find($id);
     $temp = array("id_sp" => $sanpham->id, "tensp" => $sanpham->tensp, "quantity" => 1, "gia" => 0);
     $data = Session::get('sanphams');
     if (is_null($data)) {
         $data[$sanpham->id] = $temp;
     } elseif (isset($data[$sanpham->id])) {
         $data[$sanpham->id]["quantity"] += 1;
     } else {
         $data[$sanpham->id] = $temp;
     }
     Session::put('sanphams', $data);
     return Redirect::to('sanpham/xem-sanpham')->with('success', "Đã thêm sản phẩm vào hóa đơn nhập. ");
 }
 public function getChitietGia($id_sanpham)
 {
     $gias = DB::table('gia')->select('gia.id', 'sanpham.tensp', 'gia.ngay', 'gia.gia', 'gia.apdung', 'gia.id_sanpham')->join('sanpham', 'sanpham.id', '=', 'gia.id_sanpham')->where('gia.id_sanpham', '=', $id_sanpham)->orderBy("gia.ngay", 'desc')->paginate(15);
     $sanpham = Sanpham::find($id_sanpham);
     return View::make('gia.show')->with('gias', $gias)->with('sp', $sanpham);
 }
$form = $this->beginWidget('CActiveForm', array('id' => 'chitiethoadon-form', 'enableAjaxValidation' => false));
?>

	<p class="note">Fields with <span class="required">*</span> are required.</p>

	<?php 
echo $form->errorSummary($model);
?>

	<div class="form-group">
		<?php 
echo $form->labelEx($model, 'sanpham_id');
?>
		<?php 
echo $form->dropDownList($model, 'sanpham_id', Sanpham::model()->getSanphamsName());
?>
		<?php 
echo $form->error($model, 'sanpham_id');
?>
	</div>

	<div class="form-group">
		<?php 
echo $form->labelEx($model, 'hoadon_id');
?>
		<?php 
echo $form->dropDownList($model, 'hoadon_id', Hoadon::model()->getHoadonId());
?>
		<?php 
echo $form->error($model, 'hoadon_id');
 /**
  * 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 getChitietSanpham($id)
 {
     $sp = Sanpham::find($id);
     if (is_null($sp)) {
         return Redirect::to('sanpham/xem-sanpham');
     } else {
         return View::make('sanpham.show')->with('v', $sp);
     }
 }
 public function getSanphamName()
 {
     $sanpham = Sanpham::model()->findByPk($this->sanpham_id);
     if ($sanpham) {
         return $sanpham->ten;
     } else {
         return 'Chưa Xác Định';
     }
 }
 /**
  * Returns the data model based on the primary key given in the GET variable.
  * If the data model is not found, an HTTP exception will be raised.
  * @param integer $id the ID of the model to be loaded
  * @return Sanpham the loaded model
  * @throws CHttpException
  */
 public function loadModel($id)
 {
     $model = Sanpham::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }
 public function getThemGiohang($id)
 {
     $sanphams = Sanpham::find($id);
     $sanphams->luotxem += 1;
     $sanphams->save();
     $sanpham = DB::table('giaapdung')->find($id);
     $temp = array("id_sp" => $sanpham->id, "tensp" => $sanpham->tensp, "quantity" => 1, "hinhanh" => $sanpham->hinhanh, "gia" => $sanpham->gia);
     $data = Session::get('giohang');
     if (is_null($data)) {
         $data[$sanpham->id] = $temp;
     } elseif (isset($data[$sanpham->id])) {
         $data[$sanpham->id]["quantity"] += 1;
     } else {
         $data[$sanpham->id] = $temp;
     }
     Session::put('giohang', $data);
     return Redirect::to("/")->with('success', "Đã thêm sản phẩm vào giỏ hàng. ");
 }