/** * Creates a new MedicalCertificate model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new MedicalCertificate(); if ($model->load(Yii::$app->request->post())) { //send email before saving in DB //get student info $student_id = $model->student_id; $student = Student::findOne($student_id); //get student's program $program = Program::findOne($student->program_id); //get Clinic that produce the Medical Certificate $clinic = Clinic::findOne($model->clinic_id); //get authorizer info $auth = Authorizer::findOne($model->au_id); $staff = Staff::findOne($auth->staff_id); $value = Yii::$app->mail->compose()->setFrom(array('*****@*****.**' => 'imaprog'))->setTo('*****@*****.**')->setSubject('Medical Certificate')->setHtmlBody(' Serial Number: ' . $model->mc_serial . ' Student Name: ' . $student->student_name . ' Student Matrix: ' . $student->student_matrix . ' Student Faculty: ' . $program->program_name . ' Problem/Diesease: ' . $model->mc_problem . ' Valid From: ' . $model->mc_startdate . ' Till: ' . $model->mc_enddate . ' Appointmet On: ' . $model->mc_appdate . ' Produced By: ' . $clinic->clinic_name . ' Authorize By: ' . $staff->staff_name)->send(); //save into DB $model->save(); //return to view, then proceed with sending email to the lecturers, NotifyEmailController.php return $this->redirect(['view', 'id' => $model->mc_id]); } else { return $this->renderAjax('create', ['model' => $model]); } }
/** * Creates a new NotifyEmail model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new NotifyEmail(); if ($model->load(Yii::$app->request->post())) { //recepients info $rcpt = Staff::findOne($model->staff_id); $mc = MedicalCertificate::findOne($model->mc_id); $student = Student::findOne($mc->student_id); //get student's program $program = Program::findOne($student->program_id); //get Clinic that produce the Medical Certificate $clinic = Clinic::findOne($mc->clinic_id); //get authorizer info $auth = Authorizer::findOne($mc->au_id); $staff = Staff::findOne($auth->staff_id); //upload the attachment $model->attachment = UploadedFile::getInstance($model, 'attachment'); if ($model->attachment) { $time = time(); $model->attachment->saveAs('attachments/' . $time . '.' . $model->attachment->extension); $model->attachment = 'attachments/' . $time . '.' . $model->attachment->extension; } if ($model->attachment) { //send email with attachment $value = Yii::$app->mail->compose()->setFrom(array('*****@*****.**' => 'imaprog'))->setTo('*****@*****.**')->setSubject('Medical Certificate')->setHtmlBody(' Dear ' . $rcpt->staff_name . ' Your Student Has a Medical Certificate, Serial Number: ' . $mc->mc_serial . ' Student Name: ' . $student->student_name . ' Student Matrix: ' . $student->student_matrix . ' Student Faculty: ' . $program->program_name . ' Problem/Diesease: ' . $mc->mc_problem . ' Valid From: ' . $mc->mc_startdate . ' Till: ' . $mc->mc_enddate . ' Appointmet On: ' . $mc->mc_appdate . ' Produced By: ' . $clinic->clinic_name . ' Authorize By: ' . $staff->staff_name)->attach($model->attachment)->send(); } else { //send email without attachment $value = Yii::$app->mail->compose()->setFrom(array('*****@*****.**' => 'imaprog'))->setTo('*****@*****.**')->setSubject('Medical Certificate')->setHtmlBody(' Dear ' . $rcpt->staff_name . ' Your Student Has a Medical Certificate, Serial Number: ' . $mc->mc_serial . ' Student Name: ' . $student->student_name . ' Student Matrix: ' . $student->student_matrix . ' Student Faculty: ' . $program->program_name . ' Problem/Diesease: ' . $mc->mc_problem . ' Valid From: ' . $mc->mc_startdate . ' Till: ' . $mc->mc_enddate . ' Appointmet On: ' . $mc->mc_appdate . ' Produced By: ' . $clinic->clinic_name . ' Authorize By: ' . $staff->staff_name)->send(); } $model->save(); return $this->redirect(['view', 'id' => $model->ne_id]); } else { return $this->render('create', ['model' => $model]); } }
public function deleteQrcode($channelId, $qrcodeId) { //can not delete staff qrcode,if the qrcode is deleted,i can not update the template of qrcode when staff update his username $staffInfo = Staff::findOne(['qrcodeId' => $qrcodeId]); if (!empty($staffInfo)) { throw new InvalidParameterException(Yii::t('channel', 'delete_staff_qrcode_fail')); } //delete store qrcode Store::deleteStoreQrcode($channelId, $qrcodeId); }
public function actionView($id) { $id = new MongoId($id); $store = Store::findByPk($id); if (empty($store)) { throw new BadRequestHttpException(Yii::t('common', 'data_error')); } $location = $store->getStoreLocation(); $result = $store->toArray(); $result['location'] = $location; $accountId = $this->getAccountId(); $result['storeGoods'] = StoreGoods::getTotal($id, $accountId); $result['staff'] = Staff::getTotal($id, $accountId); return $result; }
/** * get qrcodeId name:struct array(qrcodeId=>value) * @param $qrcodeIds,array */ public static function getQrcodeName($qrcodeIds) { $data = []; //promotion qrcode only check in store and staff if (!empty($qrcodeIds)) { $where = Store::createStoreChannelCondition($qrcodeIds); $storeInfos = Store::findAll($where); $storeIds = []; if (!empty($storeInfos)) { $model = new Store(); $channels = $model->storeChannels; foreach ($storeInfos as $storeInfo) { foreach ($channels as $channel) { if (!empty($channel = $storeInfo->{$channel})) { $storeIds[] = $channel['qrcodeId']; $data[$channel['qrcodeId']] = $storeInfo->name; } } } } //get staff qrcode $staffIds = array_values(array_diff($qrcodeIds, $storeIds)); $where = ['qrcodeId' => ['$in' => $staffIds]]; $staffInfos = Staff::findAll($where); if (!empty($staffIds)) { foreach ($staffInfos as $staffInfo) { $name = ''; if (!empty($staffInfo->name)) { $name = $staffInfo->name; } $data[$staffInfo->qrcodeId] = '店员' . $name . '二维码'; } } } return $data; }
public function getStaff() { return $this->hasMany(Staff::className(), ['dept_id' => 'dept_id']); }
public function getStaff() { return $this->hasOne(Staff::className(), ['staff_id' => 'staff_id']); }
/* @var $model backend\models\NotifyEmail */ /* @var $form yii\widgets\ActiveForm */ ?> <div class="notify-email-form"> <?php $form = ActiveForm::begin(['options' => ['enctype' => 'multipart/form-data']]); ?> <?php echo $form->field($model, 'mc_id')->hiddenInput()->label(false); ?> <?php echo $form->field($model, 'staff_id')->widget(Select2::classname(), ['data' => ArrayHelper::map(Staff::find()->all(), 'staff_id', 'staff_name', 'department.dept_name'), 'language' => 'en', 'options' => ['placeholder' => 'Insert Staff Name', 'id' => 'staffId'], 'pluginOptions' => ['allowClear' => true]])->label('Staff Name'); ?> <?php echo $form->field($model, 'staff_email')->textInput(['maxlength' => true]); ?> <?php echo $form->field($model, 'attachment')->fileInput(['maxlength' => true]); ?> <div class="form-group"> <?php echo Html::submitButton($model->isNewRecord ? 'Create' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']); ?> </div>
/** * Finds the Staff model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Staff the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Staff::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
public function actionDelete($id) { //delete staff info and delete staff qrcode $id = new MongoId($id); $staff = Staff::findByPk($id); if (!empty($staff->qrcodeId)) { Yii::$app->weConnect->deleteQrcode($staff->channel['channelId'], $staff->qrcodeId); } Staff::deleteAll(['_id' => $id]); }