예제 #1
0
 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]));
 }
예제 #2
0
 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));
 }
예제 #3
0
<?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'));
?>
 &nbsp;  &nbsp; 
<?php 
echo CHtml::dropDownList('stuff', '', CHtml::listData(Halfstaff::model()->findAll(), 'halfstuff_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></th>
                <th style="text-align:center;">Удалить</th>
            </tr>
예제 #4
0
 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;
 }
예제 #5
0
 /**
  * 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 Halfstaff the loaded model
  * @throws CHttpException
  */
 public function loadModel($id)
 {
     $model = Halfstaff::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }
예제 #6
0
 public function actionCount()
 {
     $prodVal = $_POST['prodVal'];
     $stuffId = $_POST['stuffId'];
     $prodId = $_POST['prodId'];
     $result = 0;
     $model = Halfstaff::model()->with('stuffStruct.Struct.measure')->findByPk($stuffId);
     foreach ($model->getRelated('stuffStruct') as $val) {
         if ($val->prod_id == $prodId) {
             $result = $prodVal * $model->count / $val->amount;
         }
     }
     echo $result;
 }
예제 #7
0
 public function actionStructSave($id)
 {
     $struct = new DishStructure();
     $halfStruct = new DishStructure2();
     $prod_id = CHtml::listData(DishStructure::model()->findAll(array("condition" => "dish_id = {$id}")), 'struct_id', 'prod_id');
     $stuff_id = CHtml::listData(DishStructure2::model()->findAll(array("condition" => "dish_id = {$id}")), 'struct2_id', 'halfstuff_id');
     $this->chosenProduct = CHtml::listData(Products::model()->findAllByPk($prod_id), 'product_id', 'name');
     $this->chosenHalfstuff = CHtml::listData(Halfstaff::model()->findAllByPk($stuff_id), 'halfstuff_id', 'name');
     if ($_POST) {
         $transaction = Yii::app()->db->beginTransaction();
         try {
             if ($_POST['prod']) {
                 foreach ($_POST['prod'] as $key => $val) {
                     $tempStruct = DishStructure::model()->updateAll(array('amount' => $val), 'dish_id = :dish_id AND prod_id = :prod_id', array(':dish_id' => $id, ':prod_id' => $key));
                 }
             }
             if ($_POST['half']) {
                 foreach ($_POST['half'] as $key => $val) {
                     $tempStruct = DishStructure2::model()->updateAll(array('amount' => $val), 'dish_id = :dish_id AND halfstuff_id = :halfstuff_id', array(':dish_id' => $id, ':halfstuff_id' => $key));
                 }
             }
             $transaction->commit();
             Yii::app()->user->setFlash($messageType, $message);
             $this->redirect(array('index'));
         } catch (exception $ex) {
             $transaction->rollBack();
             Yii::app()->user->setFlash('error', "{$e->getMessage()}");
         }
     }
     $this->render('structSave', array());
 }
예제 #8
0
 public function addStuff($id, $depId)
 {
     if ($this->checkStuff($id, $depId) != true) {
         $max_date = DepBalance::model()->find(array('select' => 'MAX(b_date) as b_date'));
         $model = new DepBalance();
         $model->b_date = $max_date->b_date;
         $model->prod_id = $id;
         $model->startCount = 0;
         $model->endCount = 0;
         $model->department_id = $depId;
         $model->type = 2;
         $model->save();
         //Список полуфабрикатов и их продуктов
         $dishStruct = Halfstaff::model()->with('stuffStruct.Struct')->findByPk($id, 'stuffStruct.types = :types', array(':types' => 1));
         if (!empty($dishStruct)) {
             foreach ($dishStruct->getRelated('stuffStruct') as $val) {
                 $this->addProd($val->getRelated('Struct')->product_id, $depId);
             }
         }
         //Список подполуфабрикатов и их продуктов
         $stuffStructs = Halfstaff::model()->with('stuffStruct.podstuff.podstuffStruct.Struct')->findByPk($id, 'stuffStruct.types = :types', array(':types' => 2));
         if (!empty($stuffStructs)) {
             foreach ($stuffStructs->getRelated('stuffStruct') as $val) {
                 $this->addStuff($val->prod_id, $depId);
                 foreach ($val->getRelated('podstuff')->getRelated('podstuffStruct') as $vals) {
                     $this->addProd($vals->prod_id, $depId);
                 }
             }
         }
     }
 }
예제 #9
0
 public function addStuff($id, $depId)
 {
     if ($this->checkStuff($id, $depId) != true) {
         $max_date = DepBalance::model()->find(array('select' => 'MAX(b_date) as b_date'));
         $model = new DepBalance();
         $model->b_date = $max_date->b_date;
         $model->prod_id = $id;
         $model->startCount = 0;
         $model->endCount = 0;
         $model->department_id = $depId;
         $model->type = 2;
         $model->save();
     }
     //Список полуфабрикатов и их продуктов
     //$dishStruct = Halfstaff::model()->with('stuffStruct.Struct')->findByPk($id,'stuffStruct.types = :types',array(':types'=>1));
     $model = Halfstaff::model()->with('stuffStruct')->findByPk($id);
     $prod = '';
     foreach ($model->getRelated('stuffStruct') as $val) {
         if ($val->types == 2) {
             $this->addStuff($val->prod_id, $depId);
         } else {
             $this->addProd($val->prod_id, $depId);
         }
     }
     return $prod;
 }