public function actionAjaxProdExp() { $from = $_POST['from']; $to = $_POST['to']; $product_id = $_POST['prod']; $dishPorce = array(); $dishName = array(); $stuffPorce = array(); $stuffName = array(); $dishOrders = array(); $stuffOrders = array(); $model = Dishes::model()->with('dishStruct')->findAll('dishStruct.prod_id = :prod', array(':prod' => $product_id)); foreach ($model as $value) { foreach ($value->getRelated('dishStruct') as $val) { $dishPorce[$value->dish_id] = $val->amount / $value->count; $dishName[$value->dish_id] = $value->name; } } $model5 = Dishes::model()->with('halfstuff.Struct.stuffStruct')->findAll('stuffStruct.prod_id = :prod AND stuffStruct.types = :types', array(':prod' => $product_id, ':types' => 1)); foreach ($model5 as $value) { foreach ($value->getRelated('halfstuff') as $val) { foreach ($val->getRelated('Struct')->getRelated('stuffStruct') as $vals) { $dishPorce[$value->dish_id] = $dishPorce[$value->dish_id] + $vals->amount / $val->getRelated('Struct')->count * $val->amount / $value->count; $dishName[$value->dish_id] = $value->name; } } } $model3 = Halfstaff::model()->with('stuffStruct')->findAll('stuffStruct.prod_id = :prod AND stuffStruct.types = :types', array(':prod' => $product_id, ':types' => 1)); foreach ($model3 as $value) { foreach ($value->getRelated('stuffStruct') as $val) { $stuffPorce[$value->halfstuff_id] = $val->amount / $value->count; $stuffName[$value->halfstuff_id] = $value->name; } } $model2 = Expense::model()->with('order')->findAll('date(order_date) BETWEEN :from AND :to AND type = :types', array(':from' => $from, ':to' => $to, ':types' => 1)); foreach ($model2 as $value) { foreach ($value->getRelated('order') as $val) { $dishOrders[$val->just_id] = $dishOrders[$val->just_id] + $val->count; } } $model4 = Expense::model()->with('order')->findAll('date(order_date) BETWEEN :from AND :to AND type = :types', array(':from' => $from, ':to' => $to, ':types' => 2)); foreach ($model4 as $value) { foreach ($value->getRelated('order') as $val) { $stuffOrders[$val->just_id] = $stuffOrders[$val->just_id] + $val->count; } } $prodCount = array(); $prodSumm = array(); $model6 = Faktura::model()->with('realize')->findAll('date(realize_date) BETWEEN :from AND :to', array(':from' => $from, ':to' => $to)); foreach ($model6 as $value) { foreach ($value->getRelated('realize') as $val) { $prodCount[$val->prod_id] = $prodCount[$val->prod_id] + $val->count; $prodSumm[$val->prod_id] = $prodSumm[$val->prod_id] + $val->count * $val->price; } } $this->renderPartial('ajaxProdExp', array('dishPorce' => $dishPorce, 'dishName' => $dishName, 'stuffPorce' => $stuffPorce, 'stuffName' => $stuffName, 'dishOrder' => $dishOrders, 'stuffOrder' => $stuffOrders, 'realizeCount' => $prodCount[$product_id])); }
public function actionProdRelList($id) { $model = Dishes::model()->with('products')->findAll('products.product_id = :prodId', array(':prodId' => $id)); $model2 = Halfstaff::model()->with('products')->findAll('products.product_id = :prodId', array(':prodId' => $id)); $this->renderPartial('prodRelList', array('model' => $model, 'model2' => $model2)); }
public function actionDepForm() { $depId = $_POST['depId']; $model = new Products(); $products = $model->getProdName($depId); $models = new Halfstaff(); $products = $products + $models->getStuffProdName($depId); $model2 = Dishes::model()->with('stuff.products')->findAll('t.department_id = :depId', array(':depId' => $depId)); if (!empty($model2)) { foreach ($model2 as $value) { foreach ($value->getRelated('stuff') as $values) { foreach ($values->getRelated('products') as $val) { $products[$val->product_id] = $val->name; } } } } $stuffs = $models->getStuffName($depId); $curProdModel = DepStorage::model()->with('product.measure')->findAll('t.department_id = :depId AND t.type = :type', array('depId' => $depId, ':type' => 1)); $curStuffModel = DepStorage::model()->with('stuff.halfstuffType')->findAll('t.department_id = :depId AND t.type = :type', array('depId' => $depId, ':type' => 2)); $this->renderPartial('depForm', array('curProdModel' => $curProdModel, 'curStuffModel' => $curStuffModel, 'products' => $products, 'stuffs' => $stuffs)); }
public function getStuff($id) { $result = array(); $result2 = array(); $model = Dishes::model()->with('halfstuff')->findByPk($id); foreach ($model->getRelated('halfstuff') as $val) { $result[$val->halfstuff_id] = $result[$val->halfstuff_id] + $val->amount; //$result = $stuff->sumArray($result,$result2); } return $result; }
public function getStuffProdName($depId) { $models = Dishes::model()->with('stuff')->findAll('t.department_id = :depId', array(':depId' => $depId)); $stuff = ''; if (!empty($models)) { foreach ($models as $values) { foreach ($values->getRelated('stuff') as $value) { $stuff .= $this->getProdId($value->halfstuff_id); } } } $model = Halfstaff::model()->findAll('t.department_id = :depId', array(':depId' => $depId)); foreach ($model as $value) { $stuff .= $this->getProdId($value->halfstuff_id); } $temp = explode(':', $stuff); $result = array(); foreach ($temp as $val) { $model = Products::model()->findByPk($val); if (!empty($model)) { $result[$model->product_id] = $model->name; } } return $result; }
<?php $form = $this->beginWidget('bootstrap.widgets.TbActiveForm', array('id' => 'inexpense-form', 'enableAjaxValidation' => false)); ?> <?php echo $form->errorSummary($model); ?> <?php echo $form->dropDownList($model, 'department_id', CHtml::listData(Department::model()->findAll(), 'department_id', 'name'), array('empty' => '--Выберите отдел--', 'class' => 'span3')); ?> <?php echo CHtml::dropDownList('stuff', '', CHtml::listData(Dishes::model()->findAll(), 'dish_id', 'name'), array('empty' => '--Выберите блюда--', 'class' => 'span3')); ?> <script src="<?php echo Yii::app()->request->baseUrl; ?> /js/jquery.table2excel.js" type="text/javascript"></script> <div id="data"> <table id="structList" class="table table-striped table-hover "> <thead> <tr> <th style="text-align:center;">Название продукта</th> <th style="text-align:center;">Количество</th> <th style="text-align:center;">Удалить</th> </tr> </thead>
public function actionListDish() { $depId = $_POST['depId']; $dishList = Dishes::model()->findAll('t.department_id = :depId', array(':depId' => $depId)); $this->renderPartial('listDish', array('model' => $dishList)); }
/** * 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 Dishes the loaded model * @throws CHttpException */ public function loadModel($id) { $model = Dishes::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }
/** * 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) { $model = $this->loadModel($id); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['dish']) or isset($_POST['stuff']) or isset($_POST['product'])) { $transaction = Yii::app()->db->beginTransaction(); try { $messageType = 'warning'; $message = "There are some errors "; foreach ($_POST as $keys => $value) { $message = "<strong>"; if ($keys == 'dish') { foreach ($value['id'] as $key => $val) { $newModel = new Menu(); $newModel->just_id = $val; $newModel->type = 1; $newModel->type_id = $value['type'][$key]; if ($newModel->save()) { $messageType = 'success'; } Dishes::model()->updateByPk($val, array('price' => $value['price'][$key])); $message .= "Блюда"; } } /*if($keys == 'stuff'){ foreach($value['id'] as $key => $val){ echo $value['price'][$key]."<br />"; $newModel = new Menu; $newModel->just_id = $val; $newModel->type = 2; if($newModel->save()) $messageType = 'success'; Halfstaff::model()->updateByPk($val,array('price'=>$value['price'][$key])); $message .= ", Полуфабрикаты"; } }*/ if ($keys == 'product') { foreach ($value['id'] as $key => $val) { $newModel = new Menu(); $newModel->just_id = $val; $newModel->type = 3; $newModel->type_id = $value['type'][$key]; if ($newModel->save()) { $messageType = 'success'; } Products::model()->updateByPk($val, array('price' => $value['price'][$key])); $message .= ", Продукты "; } } } $message .= "Успешно добавлены</strong>"; $transaction->commit(); Yii::app()->user->setFlash($messageType, $message); //$uploadFile=CUploadedFile::getInstance($model,'filename'); /*if($model->save()){ $messageType = 'success'; $message = "<strong>Well done!</strong> You successfully create data "; /* $model2 = Menu::model()->findByPk($model->menu_id); if(!empty($uploadFile)) { $extUploadFile = substr($uploadFile, strrpos($uploadFile, '.')+1); if(!empty($uploadFile)) { if($uploadFile->saveAs(Yii::app()->basePath.DIRECTORY_SEPARATOR.'files'.DIRECTORY_SEPARATOR.'menu'.DIRECTORY_SEPARATOR.$model2->menu_id.DIRECTORY_SEPARATOR.$model2->menu_id.'.'.$extUploadFile)){ $model2->filename=$model2->menu_id.'.'.$extUploadFile; $model2->save(); $message .= 'and file uploded'; } else{ $messageType = 'warning'; $message .= 'but file not uploded'; } } } $transaction->commit(); Yii::app()->user->setFlash($messageType, $message); $this->redirect(array('view','id'=>$model->menu_id)); } */ } catch (Exception $e) { $transaction->rollBack(); Yii::app()->user->setFlash('error', "{$e->getMessage()}"); //$this->refresh(); } } $this->render('update', array('model' => $model)); }
public function addDish($id, $depId) { //Корневые продукты блюда выбранного отдела $dishProducts = Dishes::model()->with('products')->findByPk($id, 't.department_id = :depId', array(':depId' => $depId)); if (!empty($dishProducts)) { foreach ($dishProducts->getRelated('products') as $val) { $this->addProd($val->product_id, $depId); } } //Корневые полуфабрикаты блюда выбранного отдела $DishStuff = Dishes::model()->with('stuff')->findByPk($id, 't.department_id = :depId', array(':depId' => $depId)); if (!empty($DishStuff)) { foreach ($DishStuff->getRelated('stuff') as $val) { $this->addStuff($val->halfstuff_id, $depId); } } }