/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = UserInfo::find()->from(UserInfo::tableName() . ' t')->joinWith(['userinfo' => function ($q) { $q->from(UserInfo::tableName() . ' parent'); }]); if (Yii::$app->user->can('manager')) { $query->where(array('t.manager' => Yii::$app->user->id)); } if (Yii::$app->user->can('hrm')) { $query->leftJoin('auth_assignment', 't.user_id = auth_assignment.user_id'); $query->where('auth_assignment.item_name <> "admin" '); } $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(['user_id' => $this->user_id, 'manager' => $this->manager]); $query->andFilterWhere(['like', 't.first_name', $this->first_name])->andFilterWhere(['like', 't.last_name', $this->last_name])->andFilterWhere(['like', 't.full_name', $this->full_name])->andFilterWhere(['like', 't.phone', $this->phone])->andFilterWhere(['like', 't.email', $this->email])->andFilterWhere(['like', 't.position', $this->position]); return $dataProvider; }
/** * Show thong tin user */ public function actionShowInformationUser($id) { if (UserInfo::findOne($id) !== null) { $this->redirect(['view', 'id' => $id]); } else { $this->redirect(['create']); } }
/** * @return \yii\db\ActiveQuery */ public function getUser() { return $this->hasOne(UserInfo::className(), ['user_id' => 'user_id']); }
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]); }
use yii\helpers\Html; use yii\widgets\ActiveForm; use backend\models\UserInfo; use yii\helpers\ArrayHelper; /* @var $this yii\web\View */ /* @var $model backend\models\UserDate */ /* @var $form yii\widgets\ActiveForm */ ?> <div class="user-date-form"> <?php $form = ActiveForm::begin(); ?> <?php echo $form->field($model, 'user_id')->dropDownList(ArrayHelper::map(UserInfo::find()->all(), 'user_id', 'full_name'), array('prompt' => '--Select a employee--')); ?> <?php echo $form->field($model, 'year')->dropDownList(array_combine(range(date('Y'), date('Y') + 10), range(date('Y'), date('Y') + 10))); ?> <?php echo $form->field($model, 'entitlement')->textInput(); ?> <div class="form-group"> <?php echo Html::submitButton($model->isNewRecord ? 'Create' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']); ?> </div>
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]); }