Exemplo n.º 1
0
 /**
  * Registra cualquier pedido junto con las comidas ordenadas por el usuario
  *
  * @return Response
  */
 public function create()
 {
     // Se recuperan todas las comidas del objeto JSON
     $meals = \Input::get('meals');
     // Creación e inicialización de un Pedido
     $order = new Order();
     if ($order != null) {
         $order->customer_id = \Auth::user()->id;
         $order->meal_number = count($meals);
         $order->total = 100;
         $order->save();
     } else {
         return response()->json(['success' => false, 'error' => "No se pudo crear el pedido debido a problemas en la base de datos"]);
     }
     //Registro de las comidas ordenadas en el pedido
     foreach ($meals as $meal) {
         // Creación e inicializacion de una comida
         $order_detail = new OrderDetail();
         // Se recupera el id del pedido para tenerlo como referencia
         $order_detail->order_id = $order->id;
         $order_detail->meal_id = $meal['id'];
         $order_detail->day = $meal['day'];
         $order_detail->ubication = "Tercera";
         $order_detail->delivery = "14:00";
         $order_detail->save();
     }
     return response()->json(["success" => true, 'msj' => "El pedido se ha creado"]);
 }
Exemplo n.º 2
0
 public function actionView($id)
 {
     $this->checkLogin();
     $this->layout = 'admin';
     $modelOrder = $this->findModel($id);
     $modelOrderDetail = new OrderDetail();
     $orderDetails = $modelOrderDetail->getOrderDetail($modelOrder->id);
     return $this->render('view', ['modelOrder' => $modelOrder, 'orderDetails' => $orderDetails]);
 }
Exemplo n.º 3
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = OrderDetail::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['order_detail_id' => $this->order_detail_id, 'order_id' => $this->order_id, 'product_id' => $this->product_id, 'qty_ordered' => $this->qty_ordered, 'qty_in_stock' => $this->qty_in_stock, 'qty_refunded' => $this->qty_refunded, 'qty_returned' => $this->qty_returned, 'product_group_id' => $this->product_group_id, 'product_group_price' => $this->product_group_price, 'supplier_id' => $this->supplier_id, 'supplier_price' => $this->supplier_price, 'product_price' => $this->product_price, 'date_added' => $this->date_added, 'date_update' => $this->date_update]);
     return $dataProvider;
 }
Exemplo n.º 4
0
 /**
  * @return OrderDetailQuery
  */
 public function getOrderDetails()
 {
     return $this->hasMany(OrderDetail::className(), ['ProductID' => 'ProductID'])->inverseOf('product');
 }
Exemplo n.º 5
0
 public function getOrderDetail($orderId)
 {
     return OrderDetail::find()->where(['orderId' => $orderId])->all();
 }
Exemplo n.º 6
0
 /**
  * @return OrderDetailQuery
  */
 public function getOrderDetails()
 {
     return $this->hasMany(OrderDetail::className(), ['OrderID' => 'OrderID'])->inverseOf('order');
 }
Exemplo n.º 7
0
 /**
  * Finds the OrderDetail model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return OrderDetail the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = OrderDetail::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Exemplo n.º 8
0
 /**
  * Finds the User model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Customers the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function getModelItems($id)
 {
     $model = OrderDetail::find()->where(['orderId' => $id])->all();
     return $model;
     /*if (($model = OrderDetail::find()->where(['orderId' => $id])) !== null) {
           return $model;
       } else {
           throw new NotFoundHttpException('The requested page does not exist.');
       }*/
 }
Exemplo n.º 9
0
 /**
  * @param $id
  * @return bool
  */
 public function deleteItem($id)
 {
     $order_detail = OrderDetail::find($id);
     $order = $order_detail->order;
     $subtotal = $order_detail->subtotal;
     if ($order_detail->delete()) {
         $order->total = $order->total - $subtotal;
         $order->save();
         return true;
     }
     return false;
 }
Exemplo n.º 10
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getOrderDetails()
 {
     return $this->hasMany(OrderDetail::className(), ['orderId' => 'id']);
 }