Exemplo n.º 1
0
 /**
  * Creates a new Timesheet model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Timesheet();
     if ($model->load(Yii::$app->request->post())) {
         $model->created_at = time();
         $model->updated_at = time();
         $model->user_id = Yii::$app->user->identity->id;
         if ($model->save()) {
             return $this->redirect(['view', 'id' => $model->id]);
         } else {
             return $this->render('create', ['model' => $model]);
         }
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
Exemplo n.º 2
0
 public function actionCreate2()
 {
     $formatter = Yii::$app->formatter;
     $work = new Work();
     $timesheet = new Timesheet();
     $isUpdated = false;
     $isCreated = false;
     if (Yii::$app->request->post()) {
         $formAttributes = Yii::$app->request->post('createForm');
         $date = $formAttributes['date'];
         $availTimesheet = Timesheet::find()->where(['date' => $date, 'user_id' => Yii::$app->user->identity->id])->one();
         if ($availTimesheet) {
             // timesheet is available
             if ($availTimesheet->status) {
                 Yii::$app->session->setFlash('CreateTimesheetFailed');
                 return $this->render('create');
             }
             $work->timesheet_id = $availTimesheet->id;
             $availTimesheet->updated_at = time();
             if ($availTimesheet->update()) {
                 $isUpdated = true;
             }
         } else {
             $timesheet->created_at = time();
             $timesheet->updated_at = time();
             $timesheet->date = $date;
             $timesheet->user_id = Yii::$app->user->identity->id;
             $timesheet->point = 0;
             $timesheet->director_comment = '';
             $timesheet->status = 0;
             if ($timesheet->save()) {
                 $isCreated = true;
             }
         }
         if ($isUpdated || $isCreated && ($work->timesheet_id = $timesheet->id)) {
             $process = Process::find()->where(['process_name' => $formAttributes['process_name']])->one();
             $team = Team::find()->where(['team_name' => $formAttributes['team_name']])->one();
             $work->process_id = $process->id;
             $work->team_id = $team->id;
             $work->work_time = $formAttributes['work_time'];
             $work->work_name = $formAttributes['work_name'];
             $work->comment = $formAttributes['comment'];
             $work->created_at = time();
             $work->updated_at = time();
             if ($work->save()) {
                 return $this->goBack();
             } else {
                 return $this->render('create');
             }
         }
     }
     return $this->render('create');
 }