public function actionStruct() { $id = $_POST['type_id']; $mType = $_POST['mType']; $products = new Products(); $stuff = new Halfstaff(); $dish = new Dishes(); $prodList = $products->getUseProdList(); $stuffList = $stuff->getUseStuffList(); $dishList = $dish->getUseDishList(); $dishModel = Menu::model()->with('dish')->findAll('t.type_id = :typeId AND mType = :mType', array(':typeId' => $id, ':mType' => $mType)); $prodModel = Menu::model()->with('products')->findAll('t.type_id = :typeId AND mType = :mType', array(':typeId' => $id, ':mType' => $mType)); $stuffModel = Menu::model()->with('halfstuff')->findAll('t.type_id = :typeId AND mType = :mType', array(':typeId' => $id, ':mType' => $mType)); $listDep = CHtml::listData(Department::model()->findAll(), 'department_id', 'name'); $this->renderPartial('struct', array('id' => $id, 'mType' => $mType, 'listDep' => $listDep, 'dishModel' => $dishModel, 'prodModel' => $prodModel, 'stuffModel' => $stuffModel, 'prodList' => $prodList, 'stuffList' => $stuffList, 'dishList' => $dishList)); }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $products = new Products(); $provider = new Provider(); $prodList = $products->getUseProdList(); $provList = $provider->getProvList(); $model = new Realize(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['provider'])) { $fakturaId = $this->beforeSave($_POST['provider']); $currentDate = date('Y-m-d'); //echo $fakturaId; $transaction = Yii::app()->db->beginTransaction(); try { $messageType = 'warning'; $message = "There are some errors " . count($_POST['product_id']); if ($_POST['product_id']) { for ($i = 0; $i < count($_POST['product_id']); $i++) { $models = new Realize(); $models->faktura_id = $fakturaId; $models->prod_id = $_POST['product_id'][$i]; $models->price = $_POST['price'][$i]; $models->count = $this->changeToFloat($_POST['count'][$i]); if ($models->save()) { $messageType = 'success'; $message = "<strong>Well done!</strong> You successfully create data "; } } } Yii::app()->user->setFlash($messageType, $message); $transaction->commit(); $this->redirect(array('dishes/checkMargin')); } catch (Exception $e) { $transaction->rollBack(); Yii::app()->user->setFlash('error', "{$e->getMessage()}"); //$this->refresh(); } } $this->render('create', array('model' => $model, 'prodList' => $prodList, 'provList' => $provList)); }
/** * Updates a particular model. * If update is successful, the browser will be redirected to the 'view' page. * @param integer $id the ID of the model to be updated */ public function actionUpdate($id) { $chosenStuff = array(); $prod_id = CHtml::listData(HalfstuffStructure::model()->findAll(array("condition" => "halfstuff_id = {$id} AND types = 1")), 'halfstruct_id', 'prod_id'); $stuff_id = CHtml::listData(HalfstuffStructure::model()->findAll(array("condition" => "halfstuff_id = {$id} AND types = 2")), 'halfstruct_id', 'prod_id'); $chosenProduct = Products::model()->with('stuffStruct')->findAllByPk($prod_id, 'stuffStruct.halfstuff_id = :halfstuff_id AND stuffStruct.types = :types', array(':halfstuff_id' => $id, ':types' => 1)); foreach ($stuff_id as $key => $value) { $chosenStuff[$key] = HalfstuffStructure::model()->with('stuff')->findAllByPk($key, 't.halfstuff_id = :halfstuff_id AND types = :types', array(':halfstuff_id' => $id, ':types' => 2)); } $model = $this->loadModel($id); $products = new Products(); $prodList = $products->getUseProdList(); $stuffList = $model->getUseStuffList(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['Halfstaff'])) { $messageType = 'warning'; $message = "There are some errors "; $transaction = Yii::app()->db->beginTransaction(); try { $_POST['Halfstaff']['count'] = $this->changeToFloat($_POST['Halfstaff']['count']); if ($_POST['Halfstaff']['count'] == '' or $_POST['Halfstaff']['count'] == 0) { $_POST['Halfstaff']['count'] = 1; } $model->attributes = $_POST['Halfstaff']; $messageType = 'success'; $message = "<strong>Well done!</strong> You successfully update data "; if ($model->save()) { HalfstuffStructure::model()->deleteAll('halfstuff_id=:halfstuff_id', array(':halfstuff_id' => $id)); if ($_POST['product_id'] != null) { $count = 0; $prodMes = "prod>"; for ($i = 0; $i < count($_POST['product_id']); $i++) { $ss = $this->changeToFloat($_POST['prod'][$i]); $struct = new HalfstuffStructure(); $struct->halfstuff_id = $id; $struct->prod_id = $_POST['product_id'][$i]; $struct->amount = $ss; $struct->types = 1; if ($struct->save()) { $messageType = 'success'; $prodMes .= $struct->prod_id . ":" . $struct->amount . ","; $message = "<strong>Well done!</strong> Your successfully create data "; } $count++; } } if ($_POST['stuff_id'] != null) { $count = 0; $stuffMes = "stuff>"; for ($i = 0; $i < count($_POST['stuff_id']); $i++) { $ss = $this->changeToFloat($_POST['stuff'][$i]); $struct = new HalfstuffStructure(); $struct->halfstuff_id = $model->halfstuff_id; $struct->prod_id = $_POST['stuff_id'][$i]; $struct->amount = $ss; $struct->types = 2; if ($struct->save()) { $stuffMes .= $struct->prod_id . ":" . $struct->amount . ","; } $count++; } } $this->logs('update', 'halfstaff', $model->halfstuff_id, $model->name . "->" . $prodMes . "=>" . $stuffMes); $transaction->commit(); Yii::app()->user->setFlash($messageType, $message); $this->redirect(array('view', 'id' => $model->halfstuff_id)); } } catch (Exception $e) { $transaction->rollBack(); Yii::app()->user->setFlash('error', "{$e->getMessage()}"); // $this->refresh(); } $model->attributes = $_POST['Halfstaff']; if ($model->save()) { } $this->redirect(array('view', 'id' => $model->halfstuff_id)); } $this->render('update', array('model' => $model, 'chosenProduct' => $chosenProduct, 'chosenStuff' => $chosenStuff, 'prodList' => $prodList, 'stuffList' => $stuffList)); }
public function actionRefreshAdd() { $prod = new Products(); $prodList = $prod->getUseProdList(); $stuff = new Halfstaff(); $stuffList = $stuff->getUseStuffList(); $this->renderPartial('refreshAdd', array('stuffList' => $stuffList, 'prodList' => $prodList, 'form' => $_POST['form'])); }
public function actionRequest() { $products = new Products(); $provider = new Provider(); $prodList = $products->getUseProdList(); $provList = $provider->getProvList(); $depId = Department::model()->findAll(); $dates = date('Y-m-d H:i:s'); $command = Yii::app()->db->createCommand(); $expense = new Expense(); if (isset($_POST['request'])) { $command->insert('request', array('req_date' => $dates, 'provider_id' => $_POST['provider'])); $lastId = Yii::app()->db->lastInsertID; foreach ($_POST['request'] as $key => $val) { foreach ($val as $keys => $value) { $count = $expense->changeToFloat($value['count']); $command->insert('request_prod', array('request_id' => $lastId, 'prod_id' => $keys, 'depId' => $key, 'count' => $count)); } } $this->redirect(array('view', 'id' => $lastId)); } $this->render('request', array('depId' => $depId, 'prodList' => $prodList, 'provList' => $provList)); }