Esempio n. 1
0
 /**
  * Lists all Invoice models.
  * @return mixed
  */
 public function actionIndex()
 {
     $model = new Invoice();
     if (Yii::$app->request->post('Invoice')) {
         $file = $model->loadFile('excel');
         if ($file->saveAs(Yii::getAlias('@statics/web/' . $file->name))) {
             $invoices = [];
             $objReader = \PHPExcel_IOFactory::load(Yii::getAlias('@statics/web/' . $file->name));
             foreach ($objReader->getActiveSheet()->getRowIterator() as $key => $row) {
                 $activeSheet = $objReader->getActiveSheet();
                 $invoiceModel = Invoice::getByOrderNumber($activeSheet->getCellByColumnAndRow(13, $key)) ?: Invoice::getByRefNumber(0, $row);
                 if ($key !== 1 && $invoiceModel && !array_key_exists($invoiceModel->id, $invoices)) {
                     $invoices[$invoiceModel->id] = $invoiceModel->id;
                     $invoiceModel->setAttributes(['card_organization' => $activeSheet->getCellByColumnAndRow(2, $key)->getValue(), 'card_number' => $activeSheet->getCellByColumnAndRow(3, $key)->getValue(), 'card_holder' => $activeSheet->getCellByColumnAndRow(4, $key)->getValue(), 'base_status' => (int) $activeSheet->getCellByColumnAndRow(9, $key)->getValue(), 'amount' => (string) $activeSheet->getCellByColumnAndRow(6, $key)->getValue(), 'date_of_receipt' => strtotime($activeSheet->getCellByColumnAndRow(8, $key)->getValue()), 'transaction_type' => $activeSheet->getCellByColumnAndRow(11, $key)->getValue(), 'job_id' => $activeSheet->getCellByColumnAndRow(13, $key)->getValue()]);
                     $invoiceModel->save();
                 }
             }
             unset($objReader);
             unlink(Yii::getAlias('@statics/web/' . $file->name));
         }
     }
     $searchModel = new InvoiceSearch();
     $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
     return $this->render('index', ['model' => $model, 'searchModel' => $searchModel, 'dataProvider' => $dataProvider]);
 }