/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionImport() { $model = new Realize(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['Realize'])) { if (!empty($_FILES)) { $tempFile = $_FILES['Realize']['tmp_name']['fileImport']; $fileTypes = array('xls', 'xlsx'); // File extensions $fileParts = pathinfo($_FILES['Realize']['name']['fileImport']); if (in_array(@$fileParts['extension'], $fileTypes)) { Yii::import('ext.heart.excel.EHeartExcel', true); EHeartExcel::init(); $inputFileType = PHPExcel_IOFactory::identify($tempFile); $objReader = PHPExcel_IOFactory::createReader($inputFileType); $objPHPExcel = $objReader->load($tempFile); $sheetData = $objPHPExcel->getActiveSheet()->toArray(null, true, true, true); $baseRow = 2; $inserted = 0; $read_status = false; while (!empty($sheetData[$baseRow]['A'])) { $read_status = true; //$realize_id= $sheetData[$baseRow]['A']; $faktura_id = $sheetData[$baseRow]['B']; $prod_id = $sheetData[$baseRow]['C']; $price = $sheetData[$baseRow]['D']; $count = $sheetData[$baseRow]['E']; $model2 = new Realize(); //$model2->realize_id= $realize_id; $model2->faktura_id = $faktura_id; $model2->prod_id = $prod_id; $model2->price = $price; $model2->count = $count; try { if ($model2->save()) { $inserted++; } } catch (Exception $e) { Yii::app()->user->setFlash('error', "{$e->getMessage()}"); //$this->refresh(); } $baseRow++; } Yii::app()->user->setFlash('success', $inserted . ' row inserted'); } else { Yii::app()->user->setFlash('warning', 'Wrong file type (xlsx, xls, and ods only)'); } } $this->render('admin', array('model' => $model)); } else { $this->render('admin', array('model' => $model)); } }
public function actionMonthStorage() { $dates = explode('-', $_POST['dates']); $number = cal_days_in_month(CAL_GREGORIAN, $dates[1], $dates[0]); $realized = array(); $expenses = array(); $startCount = array(); $endCount = array(); $curEndCount = array(); $realize = new Realize(); $depRealize = new DepFaktura(); $inexp = new Expense(); $balance = new Balance(); for ($i = 1; $i <= $number; $i++) { $tempDate = $dates[0] . "-" . $dates[1] . "-" . $i; $listDate[$i] = $tempDate; $realized[$tempDate] = $realize->getRealizeSumm($tempDate); $expenses[$tempDate] = $inexp->getInExp($tempDate) + $depRealize->getDepRealizeSumm($tempDate); $tempBalance = $balance->getBalanceSumm($tempDate); $startCount[$tempDate] = $tempBalance[0]; $endCount[$tempDate] = $tempBalance[1]; $curEndCount[$tempDate] = $tempBalance[2]; } $this->renderPartial('monthStorage', array('tempDate' => $listDate, 'realized' => $realized, 'expenses' => $expenses, 'startCount' => $startCount, 'endCount' => $endCount, 'curEndCount' => $curEndCount)); }