public function actionToday()
 {
     $dates = date('Y-m-d');
     $startProducts = array();
     $inProducts = array();
     $outProducts = array();
     $inOutProducts = array();
     $endProducts = array();
     $prodModel = Products::model()->findAll();
     //Приход
     $fakturaProd = Faktura::model()->with('realize.products')->findAll('date(realize_date) = :realize_date', array('realize_date' => $dates));
     foreach ($fakturaProd as $value) {
         foreach ($value->getRelated('realize') as $key => $val) {
             $inProducts[$val->getRelated('products')->product_id] = $inProducts[$val->getRelated('products')->product_id] + $val->count;
         }
     }
     //Расход
     $Depfaktura = DepFaktura::model()->with('realizedProd')->findAll('date(real_date) = :real_date', array(':real_date' => $dates));
     foreach ($Depfaktura as $value) {
         foreach ($value->getRelated('realizedProd') as $val) {
             $outProducts[$val->prod_id] = $outProducts[$val->prod_id] + $val->count;
         }
     }
     $expense = Expense::model()->with('order.products')->findAll('date(order_date) = :dates AND t.kind = :kind', array(':kind' => 1, ':dates' => $dates));
     foreach ($expense as $value) {
         foreach ($value->getRelated('order') as $val) {
             $inOutProducts[$val->just_id] = $inOutProducts[$val->just_id] + $val->count;
         }
     }
     $curProd = Balance::model()->with('products')->findAll('b_date = :dates', array(':dates' => $dates), array('order' => 'products.name'));
     foreach ($curProd as $value) {
         $endProducts[$value->prod_id] = $endProducts[$value->prod_id] + $value->startCount + $inProducts[$value->prod_id] - $outProducts[$value->prod_id] - $inOutProducts[$value->prod_id];
     }
     $this->render('today', array('prodModel' => $prodModel, 'model' => $curProd, 'inProducts' => $inProducts, 'outProducts' => $outProducts, 'inOutProducts' => $inOutProducts, 'endProducts' => $endProducts));
 }
 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));
 }
Beispiel #3
0
 public function realize_prod($dates)
 {
     $sum = 0;
     $model = DepFaktura::model()->with('realizedProd')->findAll('date(real_date) = :real_date', array(':real_date' => $dates));
     foreach ($model as $value) {
         foreach ($value->getRelated('realizedProd') as $val) {
             $sum = $sum + $val->count * $this->getRealized($val->prod_id, $dates);
         }
     }
     return $sum;
 }
Beispiel #4
0
<?php

$cnt = 1;
$expense = new Expense();
$depRealize = new DepFaktura();
$sumCostPrice = 0;
$sumPrice = 0;
$beforeSumCostPrice = 0;
$beforeSumPrice = 0;
$balance = new Balance();
$sumRealized = 0;
$sumInRealized = 0;
$sumInExp = 0;
$startCount = 0;
$endCount = 0;
$curEndCount = 0;
$sumFaktCost = 0;
?>
    <style>
        td,th{
            font-size: 12px;
        }
        .green{
            color: green;
        }
        .red{
            color: red;
        }
        .rait{
            padding: 0 8px!important;
        }
 public function actionMove()
 {
     $dates = date('Y:m:d H:i:s');
     $model = new DepRealize();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['department']) && isset($_POST['departments'])) {
         $transaction = Yii::app()->db->beginTransaction();
         try {
             $messageType = 'warning';
             $message = "There are some errors ";
             $newModel = new DepFaktura();
             $newModel->real_date = $dates;
             $newModel->department_id = $_POST['department'];
             $newModel->fromDepId = $_POST['departments'];
             if ($newModel->save()) {
                 foreach ($_POST['products'] as $key => $val) {
                     if ($val != null) {
                         $realizeModel = new DepRealize();
                         $realizeModel->dep_faktura_id = $newModel->dep_faktura_id;
                         $realizeModel->prod_id = $key;
                         $realizeModel->price = 0;
                         $realizeModel->count = $this->changeToFloat($val);
                         if ($realizeModel->save()) {
                             $messageType = 'success';
                             $message = "<strong>Well done!</strong> You successfully create data ";
                         }
                     }
                 }
                 $transaction->commit();
                 Yii::app()->user->setFlash($messageType, $message);
                 //$this->redirect(array('view','id'=>$model->dep_realize_id));
             }
         } catch (Exception $e) {
             $transaction->rollBack();
             Yii::app()->user->setFlash('error', "{$e->getMessage()}");
             //$this->refresh();
         }
     }
     $this->render('move', array('model' => $model, 'Products' => $Products));
 }