Exemple #1
0
 public function actionCompany()
 {
     $company = Company::find()->one();
     if (empty($company)) {
         $company = new Company();
         $company->vat = 0;
         $company->logo = '';
     }
     $post = Yii::$app->request->post();
     if (!empty($post)) {
         if (!empty($_FILES['Company']['name']['logo'])) {
             $tmp_name = $_FILES['Company']['tmp_name']['logo'];
             $name = $_FILES['Company']['name']['logo'];
             if (file_exists('upload/' . $name)) {
                 unlink('upload' . $name);
             }
             if (move_uploaded_file($tmp_name, 'upload/' . $name)) {
                 $company->logo = $name;
             }
         }
         $company->name = $post['Company']['name'];
         $company->tax_code = $post['Company']['tax_code'];
         $company->tel = $post['Company']['tel'];
         $company->website = $post['Company']['website'];
         $company->address = $post['Company']['address'];
         $company->vat = $post['Company']['vat'];
         if ($company->save()) {
             $session = new Session();
             $session->setFlash('message', 'บันทึกรายการแล้ว');
             return $this->redirect(['company']);
         }
     }
     return $this->render('//config/company', ['company' => $company]);
 }
 public function actionDelete($id)
 {
     Category::findOne($id)->delete();
     $session = new Session();
     $session->open();
     $session->setFlash('message', 'Deleted.');
     return $this->redirect(['index']);
 }
 /**
  * Creates a new Saleorderinvoice model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $searchModel = \backend\models\Saleorderinvoiceline::find()->where(['invid' => 0]);
     $model = new Saleorderinvoice();
     if ($model->load(Yii::$app->request->post())) {
         $chkcount = Saleorderinvoice::find()->where(['invoiceno' => $_POST['Saleorderinvoice']['invoiceno']])->count();
         if ($chkcount > 0) {
             //                print_r($model->errors);
             //                echo 'Not save';
             $session = new Session();
             $session->open();
             $session->setFlash('modelerror', 'เลขที่ Invoice ซ้ำ');
             return $this->render('create', ['model' => $model, 'saleline' => $searchModel, 'rowcount' => 0, 'saleincluded' => null, 'saleincludedcount' => 0]);
         }
         $saledate = $_POST['Saleorderinvoice']['invoicedate'];
         $model->invoicedate = date('d/M/Y H:i:s', strtotime($saledate));
         // $model->createby =$session['username'];
         if ($model->save()) {
             $uploaded = UploadedFile::getInstance($model, 'upfile');
             $result = 0;
             if (!empty($uploaded)) {
                 $upfiles = time() . "." . $uploaded->getExtension();
                 $uploaded->saveAs('../../uploads/' . $upfiles);
                 $handle = fopen('../../uploads/' . $upfiles, 'r');
                 $n = 0;
                 while (($fileop = fgetcsv($handle, 1000, ",")) !== false) {
                     if ($n < 1) {
                         $n++;
                         continue;
                     }
                     $model2 = new \backend\models\Saleorderinvoiceline();
                     $model2->invid = $model->recid;
                     $model2->invline = $fileop[0];
                     $model2->partno = $fileop[1];
                     $model2->description = iconv("TIS-620", "UTF-8", $fileop[2]);
                     $model2->quantity = $fileop[3];
                     $model2->unitprice = $fileop[4];
                     $model2->totalamount = $fileop[5];
                     $model2->unit = 1;
                     if ($model2->save()) {
                         $result++;
                     }
                 }
                 fclose($handle);
                 if ($result > 0) {
                     $session = new \yii\web\Session();
                     $session->open();
                     $session->setFlash('msgsuccess', 'บันทึกรายการเรียบร้อย');
                     return $this->redirect(['update', 'id' => $model->recid]);
                 }
             }
         } else {
         }
     }
     return $this->render('create', ['model' => $model, 'saleline' => $searchModel, 'rowcount' => 0, 'saleincluded' => null, 'saleincludedcount' => 0]);
 }
 public function actionDelete($id)
 {
     $productImage = BookImage::findOne($id);
     $product = $productImage->book;
     $image_url = $productImage->url;
     if ($productImage->delete()) {
         $session = new Session();
         $session->open();
         $session->setFlash('message', 'Data Deleted.');
         unlink('../uploads/' . $image_url);
         return $this->redirect(['index', 'book_id' => $product->id]);
     }
 }
 public function actionShowjob($type)
 {
     $session = new Session();
     $session->open();
     if ($type == 1) {
         $session->setFlash('msg', "แจ้งปัญหาข้อมูลและโปรแกรมคอมพิวเตอร์");
     }
     if ($type == 2) {
         $session->setFlash('msg', "ร้องขอผู้ใช้งาน");
     }
     if ($type == 3) {
         $session->setFlash('msg', "ร้องขอรายงาน");
     }
     if ($type == 4) {
         $session->setFlash('msg', "ร้องขออุปกรณ์คอมพิวเตอร์");
     }
     if ($type == 5) {
         $session->setFlash('msg', "แจ้งปัญหากล้องวงจรปิด");
     }
     if ($type == 6) {
         $session->setFlash('msg', "แจ้งปัญหาโทรศัพท์");
     }
     if ($type == 7) {
         $session->setFlash('msg', "ร้องขอกู้ข้อมูล");
     }
     $searchModel = new AdashboardSearch();
     $dataProvider = $searchModel->search($type);
     $dataProvider->pagination->pageSize = 10;
     //
     //        return $this->render('index', [
     //            'searchModel' => $searchModel,
     //            'dataProvider' => $dataProvider,
     //        ]);
     $session = new Session();
     $session->open();
     $countJob = Adashboard::find()->count();
     $countProgramActive = Adashboard::find()->where(['jobstatus' => 1, 'jobtype' => 1])->count();
     $countUserActive = Adashboard::find()->where(['jobstatus' => 1, 'jobtype' => 2])->count();
     $countReportActive = Adashboard::find()->where(['jobstatus' => 1, 'jobtype' => 3])->count();
     $countDeviceActive = Adashboard::find()->where(['jobstatus' => 1, 'jobtype' => 4])->count();
     $countCameraActive = Adashboard::find()->where(['jobstatus' => 1, 'jobtype' => 5])->count();
     $countPhoneActive = Adashboard::find()->where(['jobstatus' => 1, 'jobtype' => 6])->count();
     $countRestoreActive = Adashboard::find()->where(['jobstatus' => 1, 'jobtype' => 7])->count();
     $totalCount = Adashboard::find()->count();
     $pages = new Pagination(['totalCount' => $totalCount, 'pageSize' => 10]);
     $model = Adashboard::find()->offset($pages->offset)->limit($pages->limit)->all();
     return $this->render('index', ['model' => $model, 'searchModel' => $searchModel, 'dataProvider' => $dataProvider, 'programactive' => $countProgramActive, 'useractive' => $countUserActive, 'reportactive' => $countReportActive, 'deviceactive' => $countDeviceActive, 'cameraactive' => $countCameraActive, 'phoneactive' => $countPhoneActive, 'restoreactive' => $countRestoreActive, 'alljob' => $countJob, 'pages' => $pages]);
 }
 public function actionLogin()
 {
     $Tb_Users = new Tb_Users();
     $post = Yii::$app->request->post();
     $session = new Session();
     if (!empty($post)) {
         $user = Tb_Users::find()->where(['usr' => $post['Tb_Users']['usr'], 'pwd' => $post['Tb_Users']['pwd']])->one();
         if (!empty($user)) {
             $session['usr'] = $user->usr;
             $session['active_menu'] = "";
             return $this->redirect('index.php?r=site/index');
         } else {
             $session->setFlash('message', 'Username หรือ Password ไม่ถูกต้อง');
         }
     }
     $login_read = new Tb_Users();
     return $this->render('//site/login', ['login' => $login_read]);
 }
 public function actionIndex()
 {
     $company = Company::find()->orderBy('id')->one();
     if (!empty($_POST)) {
         if (!empty($_FILES['Company'])) {
             // remove old logo
             if (!empty($company->logo)) {
                 $old_img = $company->logo;
                 unlink('../uploads/' . $old_img);
             }
             // upload new logo
             $img = $_FILES['Company']['name']['logo'];
             $ext = end(explode(".", $img));
             $name = microtime();
             $name = str_replace(' ', '', $name);
             $name = str_replace('.', '', $name);
             $name = $name . '.' . $ext;
             $tmp = $_FILES['Company']['tmp_name']['logo'];
             $company->logo = $name;
             move_uploaded_file($tmp, '../uploads/' . $name);
         }
         $company->name = $_POST['Company']['name'];
         $company->web_title = $_POST['Company']['web_title'];
         $company->tel = $_POST['Company']['tel'];
         $company->email = $_POST['Company']['email'];
         $company->fax = $_POST['Company']['fax'];
         $company->website = $_POST['Company']['website'];
         $company->facebook = $_POST['Company']['facebook'];
         $company->line_id = $_POST['Company']['line_id'];
         $company->address = $_POST['Company']['address'];
         $company->tax_code = $_POST['Company']['tax_code'];
         $company->payment = $_POST['Company']['payment'];
         $company->about = $_POST['Company']['about'];
         if ($company->save()) {
             $session = new Session();
             $session->open();
             $session->setFlash('message', 'Data Saved.');
             return $this->redirect(['index']);
         }
     }
     return $this->render('//Company/Index', ['company' => $company]);
 }
Exemple #8
0
 public function actionSignin()
 {
     if (!empty($_POST)) {
         $count = \common\models\Dbusers::find()->where(['username' => $_POST['Mylogin']['username'], 'password' => $_POST['Mylogin']['password']])->count();
         $query = \common\models\Dbusers::find()->where(['username' => $_POST['Mylogin']['username'], 'password' => $_POST['Mylogin']['password']])->one();
         if ($count <= 0) {
             $this->layout = 'mylayout';
             $userlogin = new \backend\models\Mylogin();
             $session = new Session();
             $session->open();
             $session->setFlash('msg', 'Username or password incorect');
             return $this->render('index', ['model' => $userlogin]);
         } else {
             $userlogin = new \backend\models\Mylogin();
             $session = new Session();
             $session->open();
             $session['userid'] = $query->recid;
             $session['username'] = $query->fname;
             return $this->redirect(['/saleorder/index']);
         }
     }
 }
 /**
  * [actionForgot description]
  * @return [type] [description]
  */
 public function actionForgot()
 {
     $model = new ForgotForm();
     $session = new Session();
     if ($model->load(Yii::$app->request->post()) && $model->validate()) {
         $getEmail = $model->email;
         $getIdentity = User::find()->where(['email' => $getEmail])->one();
         $getToken = rand(0, 99999);
         $getTime = date("H:i:s");
         $calcToken = md5($getToken . $getTime);
         $getIdentity->token = $calcToken;
         $getEmail = "*****@*****.**";
         $emailAdmin = "*****@*****.**";
         $senderName = "Jobocracy";
         $senderName = '=?UTF-8?B?' . base64_encode($senderName) . '?=';
         $subject = "Reset Password";
         $subject = '=?UTF-8?B?' . base64_encode($subject) . '?=';
         $message = 'You have successfully reset your password<br>
                    <a href="localhost/application/basic/web/index.php?r=site/ver-token&token=' . $calcToken . '">Click Here to Reset Your Password</a>';
         $headers = "From: {$senderName} <{$emailAdmin}>\r\n" . "Reply To: {$emailAdmin}\r\n" . "MIME-Version: 1.0\r\n" . "Content-type: text/html; charset=UTF-8";
         $getIdentity->save();
         $session->setFlash('forgot', 'A link to reset your password
             has been sent to your email address.');
         mail($getEmail, $subject, $message, $headers);
         return $this->render('forgot', ['session' => $session]);
     }
     return $this->render('forgot', ['model' => $model, 'session' => $session]);
 }
 public function actionProfile()
 {
     $session = new Session();
     $session->open();
     $id = $session->get('member_id');
     $member = Member::findOne($id);
     if (!empty($_POST)) {
         $member->name = $_POST['Member']['name'];
         $member->username = $_POST['Member']['username'];
         $member->password = $_POST['Member']['password'];
         if ($member->save()) {
             $session->setFlash('message', 'Update member info success.');
             return $this->redirect(['profile']);
         }
     }
     return $this->render('//Frontend/Profile', ['member' => $member]);
 }
 public function actionUpdate($id)
 {
     $session = new Session();
     $session->open();
     $totalCount = Saleorderline::find()->where(['saleid' => $id])->count();
     $pages = new Pagination(['totalCount' => $totalCount, 'pageSize' => 20]);
     $searchModel = Saleorderline::find()->where(['saleid' => $id])->orderBy('recid')->offset($pages->offset)->limit($pages->limit)->all();
     $model = $this->findModel($id);
     if ($model->load(Yii::$app->request->post())) {
         $saledate = $_POST['Saleorder']['saledate'];
         $shipdate = $_POST['Saleorder']['shipdate'];
         $model->saledate = date('d/M/Y H:i:s', strtotime($saledate));
         $model->shipdate = date('d/M/Y H:i:s', strtotime($shipdate));
         //         $model->shipfrom = $_POST['Saleorder']['shipfrom'];
         $model->shipto = isset($session['shipto']) ? $session['shipto'] : '';
         $model->saleman = isset($session['salecode']) ? $session['salecode'] : NULL;
         $model->createby = $session['userid'];
         if ($model->save()) {
             $uploaded = UploadedFile::getInstance($model, 'upfile');
             $result = 0;
             if (!empty($uploaded)) {
                 //                    print_r($uploaded);
                 //                    return;
                 $deldetail = Saleorderline::deleteAll('saleid = :saleid', [':saleid' => $id]);
                 $upfiles = time() . "." . $uploaded->getExtension();
                 $uploaded->saveAs('../../uploads/' . $upfiles);
                 //                    // $uploaded->saveAs();
                 //                  //  move_uploaded_file($uploaded, '../../uploads/' . $upfiles);
                 //
                 $handle = fopen('../../uploads/' . $upfiles, 'r');
                 //                  $handle = fopen($uploaded, 'r');
                 $n = 0;
                 setlocale(LC_ALL, 'en_US.UTF-8');
                 while (($fileop = fgetcsv($handle, 1000, ",")) !== false) {
                     if ($n < 1) {
                         $n++;
                         continue;
                     }
                     $model2 = new \backend\models\Saleorderline();
                     $model2->saleid = $model->recid;
                     $model2->saleline = $fileop[0];
                     $model2->partno = $fileop[1];
                     $model2->custorderno = iconv("TIS-620", "UTF-8", $fileop[2]);
                     $model2->customername = iconv("TIS-620", "UTF-8", $fileop[3]);
                     $model2->quantity = $fileop[4];
                     $model2->unitprice = $fileop[5];
                     $model2->totalamount = $fileop[6];
                     $model2->unit = 1;
                     //                         $model2->partno=$fileop[7];
                     //  echo $name."<BR />";
                     // $age = $fileop[1];
                     //$location = $fileop[2];
                     //print_r($fileop);exit();
                     //                        $sql = "INSERT INTO details(name, age, location) VALUES ('$name', '$age', '$location')";
                     //                        $query = Yii::$app->db->createCommand($sql)->execute();
                     if ($model2->save()) {
                         $result++;
                     }
                 }
                 fclose($handle);
                 unlink('../../uploads/' . $upfiles);
                 if ($result > 0) {
                     $session = new \yii\web\Session();
                     $session->open();
                     $session->setFlash('msgsuccess', 'บันทึกรายการเรียบร้อย');
                     return $this->redirect(['update', 'id' => $model->recid]);
                 }
             }
         }
     } else {
         return $this->render('update', ['model' => $model, 'saleline' => $searchModel, 'pages' => $pages, 'rowcount' => $totalCount]);
     }
     return $this->render('update', ['model' => $model, 'saleline' => $searchModel, 'pages' => $pages, 'rowcount' => $totalCount]);
 }
 public function actionUpdate($id)
 {
     $totalCount = \backend\models\Saleorderinvoiceline::find()->where(['invid' => $id])->count();
     $saleincluded = \backend\models\Invoicerefsale::find()->where(['invid' => $id])->all();
     $saleincludedcount = \backend\models\Invoicerefsale::find()->where(['invid' => $id])->count();
     $pages = new Pagination(['totalCount' => $totalCount, 'pageSize' => 20]);
     $searchModel = \backend\models\Saleorderinvoiceline::find()->where(['invid' => $id])->orderBy('recid')->offset($pages->offset)->limit($pages->limit)->all();
     $model = $this->findModel($id);
     if ($model->load(Yii::$app->request->post())) {
         $saledate = $_POST['Saleorderinvoice']['invoicedate'];
         $model->invoicedate = date('d/M/Y H:i:s', strtotime($saledate));
         if ($model->save()) {
             $uploaded = UploadedFile::getInstance($model, 'upfile');
             $result = 0;
             if (!empty($uploaded)) {
                 $upfiles = time() . "." . $uploaded->getExtension();
                 $uploaded->saveAs('../../uploads/' . $upfiles);
                 $handle = fopen('../../uploads/' . $upfiles, 'r');
                 $n = 0;
                 while (($fileop = fgetcsv($handle, 1000, ",")) !== false) {
                     if ($n < 1) {
                         $n++;
                         continue;
                     }
                     $model2 = new \backend\models\Saleorderinvoiceline();
                     $model2->invid = $model->recid;
                     $model2->invline = $fileop[0];
                     $model2->partno = $fileop[1];
                     $model2->description = $fileop[2];
                     $model2->quantity = $fileop[3];
                     $model2->unitprice = $fileop[4];
                     $model2->totalamount = $fileop[5];
                     $model2->unit = 1;
                     if ($model2->save()) {
                         $result++;
                     }
                 }
                 fclose($handle);
                 if ($result > 0) {
                     $session = new \yii\web\Session();
                     $session->open();
                     $session->setFlash('msgsuccess', 'บันทึกรายการเรียบร้อย');
                     return $this->redirect(['update', 'id' => $model->recid]);
                 }
             }
         } else {
         }
     } else {
         return $this->render('update', ['model' => $model, 'saleline' => $searchModel, 'pages' => $pages, 'rowcount' => $totalCount, 'saleincluded' => $saleincluded, 'saleincludedcount' => $saleincludedcount]);
     }
     return $this->render('update', ['model' => $model, 'saleline' => $searchModel, 'pages' => $pages, 'rowcount' => $totalCount, 'saleincluded' => $saleincluded, 'saleincludedcount' => $saleincludedcount]);
 }
 public function actionCreate()
 {
     $session = new Session();
     $session->open();
     //        Yii::$app->params['uploadPath'] = realpath(Yii::$app->basePath) . '\\uploads\\';
     $searchModel = Saleorderline::find()->where(['saleid' => 0]);
     $model = new Saleorder();
     if ($model->load(Yii::$app->request->post())) {
         $chkcount = Saleorder::find()->where(['saleno' => $_POST['Saleorder']['saleno']])->count();
         if ($chkcount > 0) {
             //                print_r($model->errors);
             //                echo 'Not save';
             $session = new Session();
             $session->open();
             $session->setFlash('modelerror', 'เลขที่ SO ซ้ำ');
             return $this->render('create', ['model' => $model, 'saleline' => $searchModel, 'rowcount' => 0]);
         }
         $saledate = $_POST['Saleorder']['saledate'];
         $shipdate = $_POST['Saleorder']['shipdate'];
         $model->saledate = date('d/M/Y H:i:s', strtotime($saledate));
         $model->shipdate = date('d/M/Y H:i:s', strtotime($shipdate));
         //            $model->shipfrom = $_POST['Saleorder']['shipfrom'];
         $model->shipto = isset($session['shipto']) ? $session['shipto'] : '';
         $model->saleman = isset($session['salecode']) ? $session['salecode'] : NULL;
         $model->createby = $session['userid'];
         // $model->saleman = $_POST['saleman'];
         //echo $session['salecode'];
         // return;
         if ($model->save()) {
             $uploaded = UploadedFile::getInstance($model, 'upfile');
             $result = 0;
             if (!empty($uploaded)) {
                 $upfiles = time() . "." . $uploaded->getExtension();
                 if ($uploaded->saveAs('../../uploads/' . $upfiles)) {
                     $handle = fopen('../../uploads/' . $upfiles, 'r');
                 }
                 //            $uploaded->saveAs(Yii::$app->params['uploadPath'].$upfiles);
                 //
                 //                $handle = fopen(Yii::$app->params['uploadPath'].$upfiles, 'r');
                 $n = 0;
                 $nonepartcount = 0;
                 setlocale(LC_ALL, 'en_US.UTF-8');
                 while (($fileop = fgetcsv($handle, 1000, ",")) !== false) {
                     if ($n < 1) {
                         $n++;
                         continue;
                     }
                     if ($this->Validpart($fileop[1]) <= 0) {
                         $nonepartcount += 1;
                         $nonepart = new \backend\models\Nonepartnumber();
                         $nonepart->partno = $fileop[1];
                         $nonepart->description = iconv("TIS-620", "UTF-8", $fileop[2]);
                         $nonepart->salerefid = $model->recid;
                         $nonepart->createdate = date('Y-m-d H:i:s');
                         $nonepart->save();
                         //                            $nonepart->partno = '12';
                         //                            $nonepart->description = 'xxxx';
                         //                            $nonepart->salerefid = $model->recid;
                         //                            $nonepart->createdate = date('Y-m-d H:i:s');
                         //                            $nonepart->save();
                     }
                     $model2 = new \backend\models\Saleorderline();
                     $model2->saleid = $model->recid;
                     $model2->saleline = $fileop[0];
                     $model2->partno = $fileop[1];
                     $model2->custorderno = iconv("TIS-620", "UTF-8", $fileop[2]);
                     $model2->customername = iconv("TIS-620", "UTF-8", $fileop[3]);
                     $model2->quantity = $fileop[4];
                     $model2->unitprice = $fileop[5];
                     $model2->totalamount = $fileop[6];
                     $model2->unit = 1;
                     //                         $model2->partno=$fileop[7];
                     //  echo $name."<BR />";
                     // $age = $fileop[1];
                     //$location = $fileop[2];
                     //print_r($fileop);exit();
                     //                        $sql = "INSERT INTO details(name, age, location) VALUES ('$name', '$age', '$location')";
                     //                        $query = Yii::$app->db->createCommand($sql)->execute();
                     //                      iconv("TIS-620", "UTF-8", $fileop[2]);
                     //   return;
                     if ($model2->save()) {
                         $result++;
                     }
                 }
                 if ($nonepartcount > 0) {
                     $result = 0;
                     Saleorderline::deleteAll(['saleid' => $model->recid]);
                     //Saleorder::deleteAll(['recid'=>$model->recid]);
                     //  echo "OKKK";
                     //  return;
                 }
                 fclose($handle);
                 unlink('../../uploads/' . $upfiles);
                 if ($result > 0) {
                     $session = new \yii\web\Session();
                     $session->open();
                     $session->setFlash('msgsuccess', 'บันทึกรายการเรียบร้อย');
                     return $this->redirect(['update', 'id' => $model->recid]);
                 } else {
                     $session = new \yii\web\Session();
                     $session->open();
                     $session->setFlash('msgerror', 'บันทึกรายการไม่สำเร็จ พบข้อผิดพลาดขณะอัพโหลดข้อมูล');
                     return $this->redirect(['update', 'id' => $model->recid]);
                 }
             }
         }
     } else {
         return $this->render('create', ['model' => $model, 'saleline' => $searchModel, 'rowcount' => 0]);
     }
 }
 public function actionMultidelete()
 {
     if (\yii::$app->request->isAjax) {
         $pk = \yii::$app->request->post('pk');
         foreach ($pk as $data) {
             $this->findModel($data)->delete();
         }
     }
     $session = new Session();
     $session->open();
     $session->setFlash('msg', 'ทำรายการเรียบร้อย');
     return $this->redirect(['index']);
 }
 public function actionApproveprocess()
 {
     $session = new Session();
     $session->open();
     if (\Yii::$app->request->post()) {
         $count = User::find()->where(['username' => $_POST['Jobapprove']['username']])->count();
         $uid = User::find()->where(['username' => $_POST['Jobapprove']['username']])->all();
         $isuser = User::findOne(['username' => $_POST['Jobapprove']['username']]);
         $ispwd = $isuser->validatePassword($_POST['Jobapprove']['password']);
         if ($count <= 0 || $ispwd == false) {
             $session = new Session();
             $session->open();
             $session->setFlash('msg', 'คุณไม่มีสิทธิอนุมัติใบสั่งงานนี้');
             $model = new Jobapprove();
             $pagename = "reqdevice";
             //  return $this->render('approvefail');
             return $this->render('index', ['model' => $model]);
         }
         foreach ($uid as $value) {
             $roleid = $value->roleid;
         }
         $depid = \backend\Models\Assignroledetail::findAll(['roleid' => $roleid]);
         $approve = false;
         $res = 0;
         foreach ($depid as $did) {
             foreach ($session['recid'] as $idd) {
                 $model2 = Jobs::findOne($idd);
                 $userdep = User::findOne(['id' => $model2->requestby]);
                 if ($userdep->departmentid == $did->departmentid) {
                     $model2->jobstatus = 2;
                     if ($model2->save()) {
                         $res = 1;
                     }
                 }
             }
         }
         if ($res == 1) {
             $session = new Session();
             $session->open();
             $session->setFlash('msg', 'อนุมัติใบสั่งงานเรียบร้อย');
             unset($session['recid']);
             if ($session['module'] == 'device') {
                 unset($session['module']);
                 unset($session['department']);
                 return $this->redirect(['reqdevice/index']);
             } else {
                 if ($session['module'] == 'report') {
                     unset($session['module']);
                     unset($session['department']);
                     return $this->redirect(['reqreport/index']);
                 } else {
                     if ($session['module'] == 'user') {
                         unset($session['module']);
                         unset($session['department']);
                         return $this->redirect(['requser/index']);
                     }
                 }
             }
         } else {
             $session = new Session();
             $session->open();
             $session->setFlash('msg', 'คุณไม่มีสิทธิอนุมัติใบสั่งงานนี้');
             $model = new Jobapprove();
             $pagename = "reqdevice";
             //    return $this->render('approvefail');
             return $this->render('index', ['model' => $model]);
         }
         // echo var_dump($ispwd);return;
     }
     //        else {
     //            $session = new Session();
     //            $session->open();
     //            $session->setFlash('msg', 'คุณไม่มีสิทธิอนุมัติใบสั่งงานนี้');
     //            $model = new Jobapprove();
     //            $pagename = "reqdevice";
     //            //    return $this->render('approvefail');
     //            return $this->render('index', ['model' => $model]);
     //        }
 }
Exemple #16
0
 /**
  * Add a Error Flash Notification
  *
  * @param string  $message
  * @param string  $fontawesomeIcon
  */
 public function notifyError($message, $fontawesomeIcon = 'fa-times')
 {
     $this->session->setFlash('error', ['type' => 'danger', 'duration' => 10000, 'icon' => 'fa ' . $fontawesomeIcon, 'message' => $message]);
 }
 public function actionDelete($id)
 {
     $product = Book::findOne($id);
     if (!empty($product)) {
         if (!empty($product->img)) {
             unlink('../uploads/' . $product->img);
         }
         $product->delete();
         $session = new Session();
         $session->open();
         $session->setFlash('message', 'Data Deleted.');
         return $this->redirect(['index']);
     }
 }