Example #1
0
 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]);
 }
 /**
  * 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]);
 }
Example #3
0
 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 = Saleorderinvoice::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,
     //            'invoicedate' => $this->invoicedate,
     //            'invcurrency' => $this->invcurrency,
     //            'invcurrencyrate' => $this->invcurrencyrate,
     //            'customerid' => $this->customerid,
     //            'createdate' => $this->createdate,
     //        ]);
     $query->orFilterWhere(['like', 'invoiceno', $this->globalSearch]);
     return $dataProvider;
 }