/** * @param $attribute * @param $params * Kiem tra gio xin trong don co phep khong */ public function hoursAllow($attribute, $params) { //Neu manager or hrm ko ok thi ko can kiem tra nua. // if($this->manager_ok != 1 || $this->hrm_ok != 1) // return true; $reason = ReasonApplication::findOne($this->reason); //thoi gian cho phep cua kieu nghi phep do tinh trong 1 lan nghi phep if (isset($reason->time_allow) && $reason->type == 1 && $this->hours_off > $reason->time_allow) { $this->addError($attribute, "The maximum time to leave is " . $reason->time_allow . "h"); } //thoi gian cho phep cua kieu nghi phep do tinh trong 1 nam nghi phep //nghi trong truong hop khong co giay to if (isset($reason->time_allow) && $reason->type == 12) { $hours = Yii::$app->db->createCommand("SELECT SUM(hours_off) AS hours FROM `application` WHERE (`user_id`=" . $this->user_id . ") AND (`manager_ok`=1) AND (`hrm_ok`=1) AND (`reason`=3) AND year(from_date) = " . date('Y', strtotime($this->from_date)))->queryOne(); if ($hours['hours'] == '') { $hours['hours'] = 0; } if ($reason->time_allow < (int) $hours['hours'] + $this->hours_off) { $this->addError($attribute, "The maximum time to leave is " . $reason->time_allow . "h. You leave " . $hours['hours'] . "h."); } } //thoi gian nghi phep hang nam. if ($this->reason == 13) { $hours = Yii::$app->db->createCommand("SELECT SUM(hours_off) AS hours FROM `application` WHERE (`user_id`=" . $this->user_id . ") AND (`manager_ok`=1) AND (`hrm_ok`=1) AND (`reason`=13) AND year(from_date) = " . date('Y', strtotime($this->from_date)))->queryOne(); $userYear = UserDate::findOne(['user_id' => $this->user_id, 'year' => date('Y', strtotime($this->from_date))]); if ($hours['hours'] == '') { $hours['hours'] = 0; } if ($userYear === null) { $this->addError($attribute, "You don't set time leave in " . date('Y', strtotime($this->from_date)) . ". Please contact to human resource manager"); return; } if ($hours['hours'] + $this->hours_off > $userYear->entitlement) { $this->addError($attribute, "The maximum time to leave is " . $userYear->entitlement . "h in " . $userYear->year . " . You leave " . $hours['hours'] . "h."); } } //Nghi bu tru vao thoi gian lam them. //11: nghi bu cho gio lam them //12: lam them gio //14: chuyen gio lam them thanh tien if ($this->reason == 11 || $this->reason == 14) { $timeover = Yii::$app->db->createCommand("SELECT SUM(hours_off) AS hours FROM `application` WHERE (`user_id`=" . $this->user_id . ") AND (`manager_ok`=1) AND (`hrm_ok`=1) AND (`reason`=12)")->queryOne(); $timeLeave = Yii::$app->db->createCommand("SELECT SUM(hours_off) AS hours FROM `application` WHERE (`user_id`=" . $this->user_id . ") AND (`manager_ok`=1) AND (`hrm_ok`=1) AND (`reason`=11)")->queryOne(); $timeMoney = Yii::$app->db->createCommand("SELECT SUM(hours_off) AS hours FROM `application` WHERE (`user_id`=" . $this->user_id . ") AND (`manager_ok`=1) AND (`hrm_ok`=1) AND (`reason`=14)")->queryOne(); if ($timeover['hours'] == '') { $timeover['hours'] = 0; } if ($timeLeave['hours'] == '') { $timeLeave['hours'] = 0; } if ($timeMoney['hours'] == '') { $timeMoney['hours'] = 0; } if ($timeover['hours'] - $timeLeave['hours'] - $timeMoney['hours'] - $this->hours_off < 0) { $this->addError($attribute, "The overtime remaining is " . ($timeover['hours'] - $timeLeave['hours'] - $timeMoney['hours']) . "h. "); } } }
/** * Finds the UserDate model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return UserDate the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = UserDate::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }