예제 #1
0
 public function actionViewStorage()
 {
     $dates = date("Y-m-d");
     $outProduct = array();
     $depOut = array();
     $depIn = array();
     $outStuff = array();
     $prodModel = Products::model()->findAll();
     foreach ($prodModel as $value) {
         $outProduct[$value->product_id] = $outProduct[$value->product_id] + 0;
         $depOut[$value->product_id] = $depOut[$value->product_id] + 0;
     }
     $depId = $_POST['department_id'];
     $departMoveOut = DepFaktura::model()->with('realizedProd')->findAll('date(t.real_date) = :dates AND t.department_id = :depId AND t.fromDepId <> :fromDepId', array(':dates' => $dates, ':depId' => $depId, ':fromDepId' => 0));
     foreach ($departMoveOut as $key => $val) {
         foreach ($val->getRelated('realizedProd') as $value) {
             $depIn[$value->prod_id] = $depIn[$value->prod_id] + $value->count;
         }
     }
     $departMoveIn = DepFaktura::model()->with('realizedProd')->findAll('date(t.real_date) = :dates AND t.fromDepId = :depId', array(':dates' => $dates, ':depId' => $depId));
     foreach ($departMoveIn as $value) {
         foreach ($value->getRelated('realizedProd') as $val) {
             $depOut[$val->prod_id] = $depOut[$val->prod_id] + $val->count;
         }
     }
     $curProd = DepBalance::model()->with('products')->findAll('date(t.b_date) = :dates AND t.department_id = :department_id AND t.type = :type', array(':dates' => $dates, ':department_id' => $depId, ':type' => 1));
     $curStuff = DepBalance::model()->with('stuff')->findAll('date(t.b_date) = :dates AND t.department_id = :department_id AND t.type = :type', array(':dates' => $dates, ':department_id' => $depId, ':type' => 2));
     $dish = new Expense();
     $stuff = new Halfstaff();
     $outProduct = $dish->getDishProd($depId, $dates);
     $outDishStuff = $dish->getDishStuff($depId, $dates);
     $inProducts = array();
     $model = DepFaktura::model()->with('realizedProd')->findAll('date(t.real_date) = :dates AND t.department_id = :depId AND t.fromDepId = :fromDepId', array(':dates' => $dates, ':depId' => $depId, ':fromDepId' => 0));
     foreach ($model as $key => $val) {
         foreach ($val->getRelated('realizedProd') as $value) {
             $inProducts[$value->prod_id] = $inProducts[$value->prod_id] + $value->count;
         }
     }
     $instuff = array();
     $outStuffProd = array();
     $model2 = Inexpense::model()->with('inorder.stuffs.stuffStruct')->findAll('date(t.inexp_date) = :dates AND t.department_id = :depId AND stuffStruct.types = :types AND t.fromDepId = :fromDepId', array(':dates' => $dates, 'depId' => $depId, ':types' => 1, ':fromDepId' => 0));
     foreach ($model2 as $val) {
         foreach ($val->getRelated('inorder') as $value) {
             $instuff[$value->stuff_id] = $instuff[$value->stuff_id] + $value->count;
             foreach ($value->getRelated('stuffs')->getRelated('stuffStruct') as $values) {
                 $outStuffProd[$values->prod_id] = $outStuffProd[$values->prod_id] + $values->amount / $value->getRelated('stuffs')->count * $value->count;
             }
         }
     }
     $model3 = Inexpense::model()->with('inorder.stuffs.stuffStruct.podstuff.podstuffStruct.Struct')->findAll('date(t.inexp_date) = :dates AND t.department_id = :depId AND stuffStruct.types = :types AND t.fromDepId = :fromDepId', array(':dates' => $dates, 'depId' => $depId, ':types' => 2, ':fromDepId' => 0));
     foreach ($model3 as $val) {
         foreach ($val->getRelated('inorder') as $value) {
             $instuff[$value->stuff_id] = $instuff[$value->stuff_id] + $value->count;
             foreach ($value->getRelated('stuffs')->getRelated('stuffStruct') as $values) {
                 $outStuff[$values->prod_id] = $outStuff[$values->prod_id] + $values->amount / $value->getRelated('stuffs')->count * $value->count;
                 foreach ($values->getRelated('podstuff')->getRelated('podstuffStruct') as $vals) {
                     $outStuffProd[$values->prod_id] = $outStuffProd[$values->prod_id] + $vals->amount / $values->getRelated('podstuff')->count * $values->amount / $value->getRelated('stuffs')->count * $value->count;
                 }
             }
         }
     }
     $outStuff = $stuff->sumArray($outDishStuff, $outStuff);
     $inexpense = new Inexpense();
     $depStuffIn = $inexpense->getDepIn($depId, $dates);
     $depStuffOut = $inexpense->getDepOut($depId, $dates);
     $this->renderPartial('viewStorage', array('depOut' => $depOut, 'depIn' => $depIn, 'depStuffOut' => $depStuffOut, 'depStuffIn' => $depStuffIn, 'prodModel' => $prodModel, 'curProd' => $curProd, 'curStuff' => $curStuff, 'inProduct' => $inProducts, 'inStuff' => $instuff, 'outProduct' => $outProduct, 'outStuff' => $outStuff, 'outStuffProd' => $outStuffProd));
 }
예제 #2
0
 public function endDepBalance($dates)
 {
     $stuff = new Halfstaff();
     //Количественный расчет по отделам
     $department = Department::model()->findAll();
     foreach ($department as $v) {
         $depId = $v->department_id;
         $depIn = array();
         $depOut = array();
         $inProduct = array();
         $instuff = array();
         $endProduct = array();
         $endStuff = array();
         $outProduct = array();
         $outStuff = array();
         $outStuffProd = array();
         $prodModel = Products::model()->findAll();
         foreach ($prodModel as $value) {
             $outProduct[$value->product_id] = 0;
         }
         //расход продуктов в другой отдел
         $departMoveOut = DepFaktura::model()->with('realizedProd')->findAll('date(t.real_date) = :dates AND t.department_id != :depId AND t.fromDepId = :fromDepId', array(':dates' => $dates, ':depId' => $depId, ':fromDepId' => $depId));
         foreach ($departMoveOut as $key => $val) {
             foreach ($val->getRelated('realizedProd') as $value) {
                 $depOut[$value->prod_id] = $depOut[$value->prod_id] + $value->count;
             }
         }
         //приход продуктов из других отделов
         $departMoveIn = DepFaktura::model()->with('realizedProd')->findAll('date(t.real_date) = :dates AND t.department_id = :depId AND t.fromDepId != :fromDepId ', array(':dates' => $dates, ':depId' => $depId, ':fromDepId' => 0));
         foreach ($departMoveIn as $value) {
             foreach ($value->getRelated('realizedProd') as $val) {
                 $depIn[$val->prod_id] = $depIn[$val->prod_id] + $val->count;
             }
         }
         $dish = new Expense();
         $outProduct = $dish->getDishProd($depId, $dates);
         $outDishStuff = $dish->getDishStuff($depId, $dates);
         $model = DepFaktura::model()->with('realizedProd')->findAll('date(t.real_date) = :dates AND t.department_id = :depId AND t.fromDepId = :fromDepId', array(':dates' => $dates, ':depId' => $depId, ':fromDepId' => 0));
         foreach ($model as $key => $val) {
             foreach ($val->getRelated('realizedProd') as $value) {
                 $inProduct[$value->prod_id] = $inProduct[$value->prod_id] + $value->count;
             }
         }
         //Приход загатовок в отдел и расход их продуктов
         $models2 = Inexpense::model()->with('inorder.stuffs.stuffStruct')->findAll('date(t.inexp_date) = :dates AND t.department_id = :depId AND stuffStruct.types = :types AND t.fromDepId = :fromDepId', array(':dates' => $dates, 'depId' => $depId, ':types' => 1, ':fromDepId' => 0));
         foreach ($models2 as $val) {
             foreach ($val->getRelated('inorder') as $value) {
                 $instuff[$value->stuff_id] = $instuff[$value->stuff_id] + $value->count;
                 foreach ($value->getRelated('stuffs')->getRelated('stuffStruct') as $values) {
                     $outStuffProd[$values->prod_id] = $outStuffProd[$values->prod_id] + $values->amount / $value->getRelated('stuffs')->count * $value->count;
                 }
             }
         }
         //Приход и расход загатовок в отдел, расход их продуктов
         $model3 = Inexpense::model()->with('inorder.stuffs.stuffStruct.podstuff.podstuffStruct.Struct')->findAll('date(t.inexp_date) = :dates AND t.department_id = :depId AND stuffStruct.types = :types AND t.fromDepId = :fromDepId', array(':dates' => $dates, 'depId' => $depId, ':types' => 2, ':fromDepId' => 0));
         foreach ($model3 as $val) {
             foreach ($val->getRelated('inorder') as $value) {
                 $instuff[$value->stuff_id] = $instuff[$value->stuff_id] + $value->count;
                 foreach ($value->getRelated('stuffs')->getRelated('stuffStruct') as $values) {
                     $outStuff[$values->prod_id] = $outStuff[$values->prod_id] + $values->amount / $value->getRelated('stuffs')->count * $value->count;
                     foreach ($values->getRelated('podstuff')->getRelated('podstuffStruct') as $vals) {
                         $outStuffProd[$values->prod_id] = $outStuffProd[$values->prod_id] + $vals->amount / $values->getRelated('podstuff')->count * $values->amount / $value->getRelated('stuffs')->count * $value->count;
                     }
                 }
             }
         }
         $outStuff = $stuff->sumArray($outDishStuff, $outStuff);
         $inexpense = new Inexpense();
         $depStuffIn = $inexpense->getDepIn($depId, $dates);
         $depStuffOut = $inexpense->getDepOut($depId, $dates);
         $curProd = DepBalance::model()->with('products')->findAll('t.b_date = :dates AND t.department_id = :depId AND t.type = :type', array(':dates' => $dates, ':depId' => $depId, ':type' => 1));
         foreach ($curProd as $value) {
             //echo 'id -> '.$value->prod_id.' '.$value->getRelated('products')->name.'|| Начальный =>'.$value->startCount.'|| Приход =>'.$inProduct[$value->prod_id].'|| Расход =>'.$outProduct[$value->prod_id].'|| перемещ in =>'.$depIn[$value->prod_id].'|| перемещ out =>'.$depOut[$value->prod_id]."<br />";
             $endProduct[$value->prod_id] = +($value->startCount + $inProduct[$value->prod_id] - $outProduct[$value->prod_id] - $outStuffProd[$value->prod_id] + $depIn[$value->prod_id] - $depOut[$value->prod_id]);
             $Models = DepBalance::model()->find('prod_id = :prod_id AND department_id = :depId AND b_date = :dates AND t.type = :type', array(':prod_id' => $value->prod_id, ':depId' => $v->department_id, ':dates' => $dates, ':type' => 1));
             $Models->endCount = $endProduct[$value->prod_id];
             $Models->update(array('endCount'));
         }
         $curStuff = DepBalance::model()->findAll('t.b_date = :dates AND t.department_id = :depId AND t.type = :type', array(':dates' => $dates, ':depId' => $depId, ':type' => 2));
         foreach ($curStuff as $value) {
             $endStuff[$value->prod_id] = $value->startCount + $instuff[$value->prod_id] + $depStuffIn[$value->prod_id] - $outStuff[$value->prod_id] - $depStuffOut[$value->prod_id];
             $Models = DepBalance::model()->find('prod_id = :prod_id AND department_id = :depId AND b_date = :dates AND t.type = :type', array(':prod_id' => $value->prod_id, ':depId' => $v->department_id, ':dates' => $dates, ':type' => 2));
             $Models->endCount = $endStuff[$value->prod_id];
             $Models->update(array('endCount'));
         }
     }
     //конец
 }
예제 #3
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionImport()
 {
     $model = new Inexpense();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Inexpense'])) {
         if (!empty($_FILES)) {
             $tempFile = $_FILES['Inexpense']['tmp_name']['fileImport'];
             $fileTypes = array('xls', 'xlsx');
             // File extensions
             $fileParts = pathinfo($_FILES['Inexpense']['name']['fileImport']);
             if (in_array(@$fileParts['extension'], $fileTypes)) {
                 Yii::import('ext.heart.excel.EHeartExcel', true);
                 EHeartExcel::init();
                 $inputFileType = PHPExcel_IOFactory::identify($tempFile);
                 $objReader = PHPExcel_IOFactory::createReader($inputFileType);
                 $objPHPExcel = $objReader->load($tempFile);
                 $sheetData = $objPHPExcel->getActiveSheet()->toArray(null, true, true, true);
                 $baseRow = 2;
                 $inserted = 0;
                 $read_status = false;
                 while (!empty($sheetData[$baseRow]['A'])) {
                     $read_status = true;
                     //$inexpense_id=  $sheetData[$baseRow]['A'];
                     $inexp_date = $sheetData[$baseRow]['B'];
                     $department_id = $sheetData[$baseRow]['C'];
                     $model2 = new Inexpense();
                     //$model2->inexpense_id=  $inexpense_id;
                     $model2->inexp_date = $inexp_date;
                     $model2->department_id = $department_id;
                     try {
                         if ($model2->save()) {
                             $inserted++;
                         }
                     } catch (Exception $e) {
                         Yii::app()->user->setFlash('error', "{$e->getMessage()}");
                         //$this->refresh();
                     }
                     $baseRow++;
                 }
                 Yii::app()->user->setFlash('success', $inserted . ' row inserted');
             } else {
                 Yii::app()->user->setFlash('warning', 'Wrong file type (xlsx, xls, and ods only)');
             }
         }
         $this->render('admin', array('model' => $model));
     } else {
         $this->render('admin', array('model' => $model));
     }
 }