public function actionIndex() { $searchModel = new UdashboardSearch(); $dataProvider = $searchModel->search(Yii::$app->request->queryParams); $countSaleorder = \backend\models\Saleorder::find()->count(); $countInvoice = \backend\models\Saleorderinvoice::find()->count(); return $this->render('index', ['searchModel' => $searchModel, 'dataProvider' => $dataProvider, 'salecount' => $countSaleorder, 'invoicecount' => $countInvoice]); }
public function actionIndex() { $searchModel = new UdashboardSearch(); $dataProvider = $searchModel->search(Yii::$app->request->queryParams); $countSaleorder = \backend\models\Saleorder::find()->count(); $countInvoice = \backend\models\Saleorderinvoice::find()->count(); $lastSale = \backend\models\Saleorder::find()->orderBy('createdate DESC')->limit(10)->all(); $lastInv = \backend\models\Saleorderinvoice::find()->orderBy('createdate DESC')->limit(10)->all(); return $this->render('index', ['searchModel' => $searchModel, 'dataProvider' => $dataProvider, 'salecount' => $countSaleorder, 'invoicecount' => $countInvoice, 'lastsale' => $lastSale, 'lastinv' => $lastInv]); }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Saleorder::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } // $query->andFilterWhere([ // 'recid' => $this->recid, // 'saledate' => $this->saledate, // 'shipdate' => $this->shipdate, // 'currencyrate' => $this->currencyrate, // 'createdate' => $this->createdate, // ]); $query->orFilterWhere(['like', 'saleno', $this->globalSearch])->orFilterWhere(['like', 'customer', $this->globalSearch])->orFilterWhere(['like', 'saleman', $this->globalSearch])->orFilterWhere(['like', 'refno', $this->globalSearch])->orFilterWhere(['like', 'description', $this->globalSearch])->orFilterWhere(['like', 'shipfrom', $this->globalSearch])->orFilterWhere(['like', 'shipto', $this->globalSearch])->orFilterWhere(['like', 'paymentterm', $this->globalSearch])->orFilterWhere(['like', 'currency', $this->globalSearch]); return $dataProvider; }
public function actionIndex() { $count = Saleorder::find()->count(); $model = Saleorder::find()->all(); return $this->renderAjax('index', ['model' => $model, 'rowcount' => $count]); }
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]); } }