/**
  * Создает новую модель Дохода.
  * Если создание прошло успешно - перенаправляет на просмотр.
  *
  * @return void
  */
 public function actionCreate()
 {
     $model = new Inflow();
     if (Yii::app()->getRequest()->getPost('Inflow') !== null) {
         $model->setAttributes(Yii::app()->getRequest()->getPost('Inflow'));
         if ($model->save()) {
             Yii::app()->user->setFlash(yupe\widgets\YFlashMessages::SUCCESS_MESSAGE, Yii::t('BalanceModule.balance', 'Запись добавлена!'));
             $this->redirect((array) Yii::app()->getRequest()->getPost('submit-type', ['update', 'id' => $model->id]));
         }
     }
     $this->render('create', ['model' => $model]);
 }
Esempio n. 2
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();
         }
     }
 }