Пример #1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = ReasonApplication::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'type_id' => $this->type_id, 'time_allow' => $this->time_allow, 'type' => $this->type]);
     $query->andFilterWhere(['like', 'name', $this->name]);
     return $dataProvider;
 }
Пример #2
0
                if ($model->hrm_readed == -1) {
                    return ['class' => 'no-read'];
                } else {
                    return ['class' => 'danger'];
                }
            }
        }
    }
    if (Yii::$app->user->can('hrm') && $model->hrm_readed == -1) {
        return ['class' => 'no-read'];
    }
}, 'columns' => [['class' => 'yii\\grid\\SerialColumn'], ['attribute' => 'full_name', 'value' => 'user.full_name'], array('attribute' => 'from_date', 'filter' => DatePicker::widget(['model' => $dataProvider, 'name' => 'from_date', 'value' => Yii::$app->request->get('from_date'), 'attribute' => 'from_date', 'size' => 'ms', 'template' => '{addon}{input}', 'clientOptions' => ['autoclose' => true, 'format' => 'yyyy-mm-dd']]), 'value' => function ($model) {
    return Yii::$app->formatter->asDate($model->from_date);
}, 'contentOptions' => array('style' => 'width: 170px;')), array('attribute' => 'to_date', 'filter' => DatePicker::widget(['model' => $dataProvider, 'name' => 'to_date', 'value' => Yii::$app->request->get('to_date'), 'attribute' => 'to_date', 'size' => 'ms', 'template' => '{addon}{input}', 'clientOptions' => ['autoclose' => true, 'format' => 'yyyy-mm-dd']]), 'value' => function ($model) {
    return Yii::$app->formatter->asDate($model->from_date);
}, 'contentOptions' => array('style' => 'width: 170px;')), 'from_hour', 'to_hour', array('attribute' => 'hours_off', 'filter' => false), ['attribute' => 'reason', 'filter' => ArrayHelper::map(\backend\models\ReasonApplication::find()->all(), 'id', 'name'), 'value' => 'reasonApplication.name'], ['attribute' => 'manager_ok', 'format' => 'raw', 'filter' => array('1' => 'Accept', '0' => 'Refuse', '-1' => 'Waiting'), 'value' => function ($model) {
    if ($model->manager_ok == 1) {
        $status = '<span style="color: #008000; font-size: 12px;"> Accept</span>';
    } else {
        if ($model->manager_ok == 0) {
            $status = '<span style="color: #008000; font-size: 12px;"> Refuse</span>';
        } else {
            $status = '<span style="color: #cccccc; font-size: 12px;"> Waiting</span>';
        }
    }
    //return Html::checkbox("manager_ok[]",false,array('disabled'=>true)).$status;
    return $status;
}], ['attribute' => 'hrm_ok', 'format' => 'raw', 'filter' => array('1' => 'Accept', '0' => 'Refuse', '-1' => 'Waiting'), 'value' => function ($model) {
    if ($model->hrm_ok == 1) {
        $status = '<span style="color: #008000; font-size: 12px;"> Accept</span>';
    } else {
Пример #3
0
 public function getReasonApplication()
 {
     return $this->hasOne(ReasonApplication::className(), ['id' => 'reason']);
 }
Пример #4
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]);
 }
 /**
  * Finds the ReasonApplication model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return ReasonApplication the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = ReasonApplication::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }