public function actionRealizedProd() { $from = $_POST['from']; $to = $_POST['to']; $prodCount = array(); $prodSumm = array(); $model = Faktura::model()->with('realize')->findAll('date(realize_date) BETWEEN :from AND :to', array(':from' => $from, ':to' => $to)); foreach ($model 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; } } $prodModel = Products::model()->findAll(array('order' => 'name')); $this->renderPartial('realizedProd', array('prodSumm' => $prodSumm, 'prodCount' => $prodCount, 'prodModel' => $prodModel)); }
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 actionAjaxAllProd() { $halfstuff = new Halfstaff(); $from = $_POST['from']; $to = $_POST['to']; $allOutProd = array(); $products = array(); $prodCount = array(); $prodSumm = array(); $outProdSumm = array(); for ($i = 0; $i <= date('j', strtotime($to)) - date('j', strtotime($from)); $i++) { $dish = new Expense(); $outProduct = array(); $model = Expense::model()->with('order.dish.dishStruct')->findAll('date(t.order_date) = :dates', array(':dates' => date('Y-m-d', strtotime($from) + $i * 3600 * 24))); foreach ($model as $value) { foreach ($value->getRelated('order') as $val) { $curDish[$val->getRelated('dish')->dish_id] = $val->getRelated('dish')->name; $dishCount[$val->getRelated('dish')->dish_id] = $dishCount[$val->getRelated('dish')->dish_id] + $val->count; foreach ($val->getRelated('dish')->getRelated('dishStruct') as $vals) { $products[$vals->prod_id] = $products[$vals->prod_id] + $vals->amount / $val->getRelated('dish')->count * $val->count; } } } $model2 = Expense::model()->with('order.dish.halfstuff')->findAll('date(t.order_date) = :dates', array(':dates' => date('Y-m-d', strtotime($from) + $i * 3600 * 24))); foreach ($model2 as $value) { foreach ($value->getRelated('order') as $val) { $curDish[$val->getRelated('dish')->dish_id] = $val->getRelated('dish')->name; foreach ($val->getRelated('dish')->getRelated('halfstuff') as $vals) { $stuff[$val->getRelated('dish')->dish_id][$vals->halfstuff_id] = $stuff[$val->getRelated('dish')->dish_id][$vals->halfstuff_id] + $vals->amount / $val->getRelated('dish')->count * $val->count; } } } $model3 = Expense::model()->with('order.halfstuff.stuffStruct')->findAll('date(t.order_date) = :dates', array(':dates' => date('Y-m-d', strtotime($from) + $i * 3600 * 24))); foreach ($model3 as $value) { foreach ($value->getRelated('order') as $val) { $curStuff[$val->getRelated('halfstuff')->halfstuff_id] = $val->getRelated('halfstuff')->name; $stuffCount[$val->getRelated('halfstuff')->halfstuff_id] = $dishCount[$val->getRelated('halfstuff')->halfstuff_id] + $val->count; foreach ($val->getRelated('halfstuff')->getRelated('stuffStruct') as $vals) { if ($vals->types == 1) { $products[$vals->prod_id] = $products[$vals->prod_id] + $vals->amount / $val->getRelated('halfstuff')->count * $val->count; } elseif ($vals->types) { $stuff[$val->getRelated('halfstuff')->halfstuff_id][$vals->prod_id] = $stuff[$val->getRelated('halfstuff')->halfstuff_id][$vals->prod_id] + $vals->amount / $val->getRelated('halfstuff')->count * $val->count; } } } } $model6 = Faktura::model()->with('realize')->findAll('date(realize_date) = :dates', array(':dates' => date('Y-m-d', strtotime($from) + $i * 3600 * 24))); 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; $outProdSumm[$val->prod_id] = $outProdSumm[$val->prod_id] + $products[$val->prod_id] * $val->price; } } /*foreach (Department::model()->findAll() as $val) { //echo date('Y-m-d',strtotime($from)+($i*3600*24))."<br>"; $outProduct = $halfstuff->sumArray($outProduct,$dish->getDishProd($val->department_id, date('Y-m-d',strtotime($from)+($i*3600*24)))); //$outDishStuff = $dish->getDishStuff($depId,$dates); } $allOutProd = $halfstuff->sumArray($allOutProd,$outProduct);*/ } $prodModel = Products::model()->findAll(array('order' => 'name')); $this->renderPartial('ajaxAllProd', array('prodCount' => $prodCount, 'prodSumm' => $prodSumm, 'prodModel' => $prodModel, 'products' => $products, 'outProdSumm' => $outProdSumm)); }
public function getRealized($id, $dates) { $dates = date('Y-m-d H:i:s', strtotime($dates) + 86400); $model = Faktura::model()->with('realize')->find(array('condition' => 't.realize_date < "' . $dates . '"' . ' AND realize.prod_id=' . $id, 'order' => 't.realize_date DESC')); if (!empty($model)) { foreach ($model->getRelated('realize') as $val) { $price = $val->price; } } else { $price = 0; } return $price; }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionTodayStorage() { $dates = date('Y:m:d'); $depId = $_POST['depId']; $Products = array(); /*$model = DepBalance::model()->with('products')->findAll('t.department_id = :depId AND t.type = :type',array(':depId'=>$depId,'type'=>1)); foreach ($model as $val) { $products[$val->prod_id] = $val->getRelated('products')->name; }*/ //$model = new Products(); //$products = $model->getProdName($depId); $storageModel = Storage::model()->findAll(); $balanceModel = Balance::model()->with('products')->findAll('b_date = :b_date', array(':b_date' => $dates)); if (!empty($balanceModel)) { foreach ($balanceModel as $val) { $products[$val->prod_id] = $val->getRelated('products')->name; $Products[$val->prod_id] = $Products[$val->prod_id] + $val->startCount; } } else { foreach ($storageModel as $val) { $Products[$val->prod_id] = $Products[$val->prod_id] + $val->curCount; } } $realizedProd = Faktura::model()->with('realize.products')->findAll('date(realize_date) = :realize_date', array('realize_date' => $dates)); foreach ($realizedProd as $value) { foreach ($value->getRelated('realize') as $val) { $Products[$val->prod_id] = $Products[$val->prod_id] + $val->count; } } $realizeStorageProd = DepFaktura::model()->with('realizedProd')->findAll('date(real_date) = :real_date AND fromDepId = :fromDepId', array(':real_date' => $dates, ':fromDepId' => 0)); foreach ($realizeStorageProd as $value) { foreach ($value->getRelated('realizedProd') as $val) { $Products[$val->prod_id] = $Products[$val->prod_id] - $val->count; } } $expBalance = Yii::app()->db->createCommand()->select('ord.just_id,ord.count')->from('expense ex')->join('orders ord', 'ord.expense_id = ex.expense_id')->where('date(ex.order_date) = :dates AND ex.kind = :kind ', array(':dates' => $dates, ':kind' => 1))->queryAll(); foreach ($expBalance as $val) { $Products[$val['just_id']] = $Products[$val['just_id']] - $val['count']; } $this->renderPartial('todayStorage', array('Products' => $Products, 'products' => $products, 'depId' => $depId)); }
/** * 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 Faktura the loaded model * @throws CHttpException */ public function loadModel($id) { $model = Faktura::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }