コード例 #1
0
 public function actionApplicationOfType($id, $user_id = 0)
 {
     $model = new Application();
     $model->type = $id;
     $reason = array();
     if ($id == 0) {
         //Don xin nghi phep (co tru phep va khong tru phep)
         $reason = ReasonApplication::find()->where(['type_id' => -2])->orWhere(['type_id' => 0])->orderBy(['name' => SORT_ASC])->all();
     } else {
         if ($id == -1) {
             //Don xin nghi bu
             $reason = ReasonApplication::find()->where(['type_id' => -1])->orderBy(['name' => SORT_ASC])->all();
         } else {
             if ($id == 1) {
                 //Don xin lam bu
                 $reason = ReasonApplication::find()->where(['type_id' => 1])->orderBy(['name' => SORT_ASC])->all();
             } else {
                 if ($id == -11) {
                     //Don xin chuyen gio overtime thanh tien
                     $reason = ReasonApplication::find()->where(['type_id' => -11])->orderBy(['name' => SORT_ASC])->all();
                 } else {
                     throw new NotFoundHttpException("This type of application does not exist");
                 }
             }
         }
     }
     if ($model->load(Yii::$app->request->post())) {
         //neu la don xin chuyen thoi gian lam them qua tien thi gan manager = 1;
         $r = ReasonApplication::findOne($model->reason);
         if ($r->type_id == -11) {
             $model->manager_ok = 1;
             $model->manager_readed = 1;
         }
         $model->user_id = Yii::$app->user->id;
         //Thiet lap trong truong hop hrm lam don xin nghi
         if (Yii::$app->user->can('hrm')) {
             $model->hrm_readed = 1;
             $model->hrm_ok = 1;
         }
         //Thiet lap trong truong hop hrm lam don chuyen gio them thanh tien cho nhan vien
         if ($id == -11) {
             $model->to_date = $model->from_date;
             $model->user_id = $user_id;
         }
         $from_date_temp = $model->from_date;
         $model->from_date = date('Y-m-d', strtotime(str_replace('/', '-', $model->from_date)));
         $to_date_tem = $model->to_date;
         $model->to_date = date('Y-m-d', strtotime(str_replace('/', '-', $model->to_date)));
         $model->date_create = date('Y-m-d H:i:s');
         //Kiem tra gio co hop phep ko? va luu lai
         if ($model->validate(['hours_off']) && $model->save()) {
             //Truong hop la nhan vien xin nghi, lam bu, nghi bu
             //Gui thu cho manager cua no
             if (Yii::$app->user->can('staff') && $id != -11) {
                 // Gui mail bao cho manager biet co dua xin nghi.
                 $link = Html::a('Click me!', Yii::$app->urlManager->createAbsoluteUrl(['application/check-application', 'id' => $model->id]));
                 $reason = ReasonApplication::findOne(['id' => $model->reason]);
                 $user_info = UserInfo::findOne(['user_id' => $model->user_id]);
                 $user_manager = UserInfo::findOne(['user_id' => $user_info->manager]);
                 $body = $this->renderPartial('email_request', ['model' => $model, 'reason' => $reason, 'link' => $link, 'user_info' => $user_info, 'user_manager' => $user_manager]);
                 if ($user_manager !== null && $this->sendMail($user_manager->email, $user_info->email, $user_info->full_name, $reason->name, $body)) {
                     //if($user_manager !== null && $this->sendMail("*****@*****.**","*****@*****.**",$user_info->full_name,$reason->name,$str)){
                     Yii::$app->session->setFlash('success', 'Your message has been sent to the manager !');
                 } else {
                     Yii::$app->session->setFlash('error', 'Unable to send a letter to the manager. Please call the manager. Manager\'s phone: .' . $user_manager->phone);
                 }
             }
             //Truong hop la don xin chuyen thoi gian thanh tien.
             if ($id == -11) {
             }
             //Truong hop manager xin nghi viec.
             if (Yii::$app->user->can('manager') && $id != -11) {
             }
             return $this->redirect(['view', 'id' => $model->id]);
         }
         $model->from_date = $from_date_temp;
         $model->to_date = $to_date_tem;
     }
     if ($id == -11) {
         return $this->render('application-time-to-money', ['model' => $model, 'reason' => $reason]);
     }
     return $this->render('application-of-type', ['model' => $model, 'reason' => $reason]);
 }
コード例 #2
0
 /**
  * Show thong tin user
  */
 public function actionShowInformationUser($id)
 {
     if (UserInfo::findOne($id) !== null) {
         $this->redirect(['view', 'id' => $id]);
     } else {
         $this->redirect(['create']);
     }
 }
コード例 #3
0
 public function actionListDateOff()
 {
     $idStaff = Yii::$app->request->post('idOfStaff');
     $query = UserDate::find();
     $query = UserDate::find();
     $query->select('user_info.*,id, year, entitlement, entitlement - (SELECT SUM(hours_off) AS hours FROM `application` WHERE manager_ok = 1 AND hrm_ok = 1 AND application.user_id = user_info.user_id AND reason = 13 AND YEAR(from_date) = user_date.`year`) AS balance');
     $query->joinWith(['user']);
     $query->where(['user_date.user_id' => $idStaff]);
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $user = UserInfo::findOne(['user_id' => $idStaff]);
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     return $this->renderAjax('list-date-off', ['dataProvider' => $dataProvider, 'user' => $user]);
 }