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);
 }
 /**
  * Возвращает модель по указанному идентификатору
  * Если модель не будет найдена - возникнет HTTP-исключение.
  *
  * @param integer идентификатор нужной модели
  *
  * @return void
  */
 public function loadModel($id)
 {
     $model = Inflow::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, Yii::t('BalanceModule.balance', 'Запрошенная страница не найдена.'));
     }
     return $model;
 }
Exemplo n.º 3
0
 protected function afterSave()
 {
     parent::afterSave();
     if ($this->isNewRecord && $this->is_test == 0) {
         //Формирование расписания пользователя
         if ($this->isNewRecord && $this->group == "on") {
             $group = new Group();
             $group->code = $this->listner->branch->group_counter + 1;
             $group->name = $group->name = $group->code . ' | ' . date('Y-m-d', strtotime("+2 week"));
             $group->time = $this->time;
             $group->lvl = $this->lvl;
             $group->note = $this->note;
             $group->teacher_id = $this->teacher_id;
             $group->number = $this->form->number;
             $group->hui = $this->hui;
             $group->branch_id = $this->listner->branch_id;
             $group->subject_id = $this->subject_id;
             $group->parent_id = $this->id;
             if ($this->parent_group) {
                 $group->parent_group = $this->parent_group;
                 if ($group->prev->first_parent_group) {
                     $group->first_parent_group = $group->prev->first_parent_group;
                 } else {
                     $group->first_parent_group = $group->prev->id;
                 }
             }
             $group->is_active = 1;
             $group->save();
             if ($this->form->type->id == 4) {
                 $this->listner->branch->individual_counter += 1;
             } else {
                 $this->listner->branch->group_counter += 1;
             }
             $this->listner->branch->save();
         }
         if ($this->form->type->id == 3) {
             $time = explode(',', $this->time);
             $tCount = count($time);
             $j = 0;
             $k = 0;
             for ($i = 0; $i < $this->form->number; $i++) {
                 if ($j == $tCount) {
                     $j = 0;
                     $k++;
                 }
                 $schedule = new Schedule();
                 //if($this->form->type->id == 3 || $this->form->type->id == 4)
                 //$schedule->position_id = $this->id;
                 //                    else{
                 //                        $schedule->position_id = $this->id;
                 $schedule->position_id = $this->id;
                 $schedule->number = $i + 1;
                 $schedule->teacher_id = $this->teacher_id;
                 $schedule->start_time = str_replace(" ", "T", date('Y-m-d H:i:s', strtotime("+" . $k . "week", strtotime($time[$j]))));
                 if ($this->hui == "on") {
                     $pizda = 30;
                 } else {
                     $pizda = 0;
                 }
                 $schedule->end_time = str_replace(" ", "T", date('Y-m-d H:i:s', strtotime("+" . $k . "week 1 hours " . $pizda . " minutes", strtotime($time[$j]))));
                 $schedule->room_id = $this->findRoom($schedule->start_time, $this->listner->branch_id, 1);
                 $schedule->save();
                 $j++;
             }
             if ($this->form->type->id == 3) {
                 $this->listner->branch->individual_counter += 1;
                 $this->listner->branch->save();
             }
         }
         //Формирование прихода
         $inflow = new Inflow();
         $inflow->subject_id = $this->subject_id;
         $inflow->receiver = $this->teacher->user->fullName;
         $inflow->form_id = $this->form_id;
         if ($this->is_old == "on") {
             $inflow->price = $this->form->old_price;
         } else {
             $inflow->price = $this->form->price;
         }
         $inflow->based = $this->code;
         $inflow->comment = $this->note;
         $inflow->date = $this->start_date;
         $inflow->branch_id = $this->listner->branch_id;
         $inflow->save();
         //Изменение статуса
         if ($this->listner->status != 1) {
             $this->listner->status = 1;
             $this->listner->save();
         }
     }
 }