/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionImport() { $model = new DepRealize(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['DepRealize'])) { if (!empty($_FILES)) { $tempFile = $_FILES['DepRealize']['tmp_name']['fileImport']; $fileTypes = array('xls', 'xlsx'); // File extensions $fileParts = pathinfo($_FILES['DepRealize']['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; //$dep_realize_id= $sheetData[$baseRow]['A']; $dep_faktura_id = $sheetData[$baseRow]['B']; $prod_id = $sheetData[$baseRow]['C']; $price = $sheetData[$baseRow]['D']; $count = $sheetData[$baseRow]['E']; $model2 = new DepRealize(); //$model2->dep_realize_id= $dep_realize_id; $model2->dep_faktura_id = $dep_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)); } }
<?php $count = 1; $realize = new DepRealize(); $summ = 0; ?> <table class="table table-bordered" id="dataTable"> <thead> <tr> <th></th> <th>Название продукта</th> <th>Количество</th> <th>Отдел</th> <th>Цена</th> <th>Сумма</th> </tr> </thead> <tbody> <?php foreach ($model as $value) { foreach ($value->getRelated('realizedProd') as $val) { ?> <tr> <td><?php echo $count; ?> </td> <td><?php echo $val->getRelated('product')->name; ?> </td>
<?php $count = 1; $realize = new DepRealize(); $summ = 0; $products = new Products(); ?> <table class="table table-bordered" id="dataTable"> <thead> <tr> <th></th> <th>Название продукта</th> <th>Количество</th> <th>Цена</th> <th>Сумма</th> </tr> </thead> <tbody> <?php foreach ($outProduct as $key => $val) { ?> <tr> <td><?php echo $count; ?> </td> <td><?php echo $products->getName($key); ?> </td> <td><?php