public function actionShow() { $date = explode('-', $_GET['daterange']); $branch = $_GET['branch']; $d1 = date('Y-m-d', strtotime($date[0])); $d2 = date('Y-m-d', strtotime($date[1])); $inflow = []; $outflow = []; $totalArr = []; // Формирование моделей $criteria = new CDbCriteria(); if ($branch == "all") { $criteria->condition = 'date =:date1'; } else { $criteria->condition = 'date =:date1 AND branch_id=:br'; } $arr = []; $in = 0; $out = 0; $totalIn = 0; $totalOut = 0; $total = 0; while ($d1 <= $d2) { if ($branch == "all") { $criteria->params = [":date1" => $d1]; } else { $criteria->params = [":date1" => $d1, 'br' => $branch]; } $inflowArr = Inflow::model()->findAll($criteria); if ($inflowArr) { foreach ($inflowArr as $value) { array_push($inflow, $value); $in += $value->price; $totalIn += $in; } } $outflowArr = Outflow::model()->findAll($criteria); if ($outflowArr) { foreach ($outflowArr as $value) { array_push($outflow, $value); $out += (int) $value->price; $totalOut += $out; } } if ($inflowArr || $outflowArr) { $arr['date'] = $d1; $arr['inflow'] = $in; $arr['outflow'] = $out; $total += $in - $out; $arr['total'] = $total; array_push($totalArr, $arr); } $d1 = date('Y-m-d', strtotime("+1 day", strtotime($d1))); $in = 0; $out = 0; } //$this->render('search', array('inflow' => $inflow, 'outflow' => $outflow, 'totalflow' => $totalArr)); $this->actionPrint($inflow, $outflow, $totalArr, $totalIn, $totalOut); }
public function actionChange($id) { if (Yii::app()->request->isAjaxRequest) { $model = \Schedule::model()->findByPk($id); if ($model->is_active == 1) { $price = $model->position->form->price / $model->position->form->number; $model->is_active = 0; $model->update(); $outflow = new Outflow(); $outflow->price = $price; $outflow->based = "Отмена урока от " . $model->start_time; $outflow->note = $model->id; $outflow->branch_id = $model->position->listner->branch_id; $outflow->date = date('Y-m-d'); $outflow->receiver = 'admin'; $outflow->save(); } elseif ($model->is_active == 0) { $model->is_active = 1; $model->update(); $outflow = Outflow::model()->find("note='{$id}'"); $outflow->delete(); } echo CJSON::encode($model->is_active); } else { throw new CHttpException(404, Yii::t('ListnerModule.listner', 'Запрошенная страница не найдена.')); } }
/** * Возвращает модель по указанному идентификатору * Если модель не будет найдена - возникнет HTTP-исключение. * * @param integer идентификатор нужной модели * * @return void */ public function loadModel($id) { $model = Outflow::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, Yii::t('BalanceModule.balance', 'Запрошенная страница не найдена.')); } return $model; }