Esempio n. 1
0
 private function addPaidEmployment()
 {
     if (!$this->ticket_id) {
         return true;
     }
     $this->_ticketModel = SeasonTicket::findOne(['id' => $this->ticket_id]);
     if (!$this->_ticketModel) {
         return true;
     }
     $this->_currentDate = Carbon::createFromFormat('d.m.Y', $this->startdate);
     $this->_endDate = self::getEmploymentEndDate($this->_currentDate, $this->_ticketModel->limit_format, $this->_ticketModel->limit_value);
     $timeTableGroups = Timetable::find()->asArray()->where(['group_id' => $this->groups])->all();
     $cond = 'date >= :startdate AND pay.user_id = :user_id';
     $params = [':user_id' => $this->user_id, ':startdate' => $this->_currentDate->toDateString()];
     $existEmployments = PaidEmployment::find()->select(['date', 'timetable_id', 'group_id' => 'timetable.group_id'])->asArray()->joinWith(['pay', 'timetable'])->where($cond, $params)->andWhere(['timetable.group_id' => $this->groups])->all();
     $existLastEmployment = PaidEmployment::find()->select(['date', 'timetable_id', 'group_id' => 'timetable.group_id'])->asArray()->joinWith(['pay', 'timetable'])->where($cond, $params)->andWhere(['timetable.group_id' => $this->groups])->orderBy('date DESC')->one();
     $this->addInsertArrayTimeLimit($timeTableGroups, $existEmployments, $this->_currentDate, $this->_endDate);
     if ($existLastEmployment) {
         $lastEmploymentDate = Carbon::createFromFormat('Y-m-d', $existLastEmployment['date'])->addDay();
         $this->_endDate = self::getEmploymentEndDate($lastEmploymentDate, $this->_ticketModel->limit_format, $this->_ticketModel->limit_value);
     }
     if ($this->_ticketModel->amount > 0) {
         $this->addInsertArrayAmountLimit($timeTableGroups, $existEmployments, $this->_currentDate, $this->_endDate);
     }
     if (!empty($this->_insertArray)) {
         $command = Yii::$app->db->createCommand()->batchInsert('{{%paid_employment}}', ['date', 'pay_id', 'timetable_id'], $this->_insertArray);
         return is_int($command->execute());
     } else {
         return true;
     }
 }
 /**
  * Finds the SeasonTicket model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return SeasonTicket the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = SeasonTicket::findOne($id)) !== null) {
         return $model;
     } else {
         throw new HttpException(404);
     }
 }