diff --git a/backend/assets/InventoryItemUpdateAsset.php b/backend/assets/InventoryItemUpdateAsset.php new file mode 100644 index 0000000..792649b --- /dev/null +++ b/backend/assets/InventoryItemUpdateAsset.php @@ -0,0 +1,31 @@ + + * @since 2.0 + */ +class InventoryItemUpdateAsset extends AssetBundle +{ + public $basePath = '@webroot'; + public $baseUrl = '@web'; + public $css = [ + ]; + public $js = [ + 'js/app.js', + 'js/inventory,item.update.js', + ]; + public $depends = [ + 'backend\assets\AppAsset', + 'yii\jui\JuiAsset', + 'common\assets\TypeAheadAsset', + ]; +} diff --git a/backend/controllers/InventoryController.php b/backend/controllers/InventoryController.php index 4b9712e..8167db5 100644 --- a/backend/controllers/InventoryController.php +++ b/backend/controllers/InventoryController.php @@ -2,15 +2,14 @@ namespace backend\controllers; -use Yii; +use /** @noinspection PhpMethodOrClassCallIsNotCaseSensitiveInspection */ + Yii; use common\models\Inventory; use backend\models\InventorySearch; use yii\web\Controller; use yii\web\NotFoundHttpException; use yii\filters\VerbFilter; use common\models\User; -use yii\db\Query; -use backend\models\InventoryItemSearch; use common\models\InventoryItem; use common\components\Helper; diff --git a/backend/controllers/InventoryItemController.php b/backend/controllers/InventoryItemController.php index 627898a..75eba2e 100644 --- a/backend/controllers/InventoryItemController.php +++ b/backend/controllers/InventoryItemController.php @@ -2,9 +2,12 @@ namespace backend\controllers; -use Yii; +use /** @noinspection PhpMethodOrClassCallIsNotCaseSensitiveInspection */ + Yii; use common\models\InventoryItem; use backend\models\InventoryItemSearch; +use yii\base\Exception; +use yii\db\Query; use yii\web\Controller; use yii\web\NotFoundHttpException; use yii\filters\VerbFilter; @@ -33,107 +36,113 @@ class InventoryItemController extends Controller /** * Lists all InventoryItem models. + * @param $id * @return mixed + * @throws NotFoundHttpException */ public function actionIndex($id) { - $inventory = Inventory::findOne($id); - - if ( !isset($inventory)){ - throw new NotFoundHttpException("Leltár nem található"); - } - - $searchModel = new InventoryItemSearch(['inventory' => $inventory]); - $dataProvider = $searchModel->search(Yii::$app->request->queryParams); - - $productOptions = Product::buildProductAndInventoryGroupList(); - - if ($searchModel->output == 'xls') { - $this->downloadIndexXls($dataProvider); - }else{ - Url::remember(Url::current(),"inventory-item-index"); + $inventory = Inventory::findOne($id); + + if (!isset($inventory)) { + throw new NotFoundHttpException("Leltár nem található"); } - + $searchModel = new InventoryItemSearch(['inventory' => $inventory]); + $dataProvider = $searchModel->search(Yii::$app->request->queryParams); + + $productOptions = Product::buildProductAndInventoryGroupList(); + + if ($searchModel->output == 'xls') { + $this->downloadIndexXls($dataProvider); + } else { + Url::remember(Url::current(), "inventory-item-index"); + } + + return $this->render('index', [ - 'model' => $inventory, + 'model' => $inventory, 'searchModel' => $searchModel, 'dataProvider' => $dataProvider, - 'productOptions' =>$productOptions + 'productOptions' => $productOptions ]); } - - protected function downloadIndexXls($dataProvider){ - - - $defs = [['item_created_at', 'Létrehozva'], - ['item_name', 'Termék/Termék csoport'], - ['user_username', 'Felhasználó'], - ['item_count_prev', 'Előző leltár (db)'], - ['item_count_sold', 'Eladott mennyiség (db)'], - ['item_count_in', 'Beszerzett mennyiség (db)'], - ['item_count', 'Leltározott mennyiség (db)'], - ['item_difference', 'Különbség (db)'], - ['item_count_system', 'Rendszer szerinti mennyiség (db)'], - ]; - $cols = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P']; - - $models = $dataProvider->getModels (); - $objPHPExcel = new \PHPExcel (); - - $sheet = $objPHPExcel->setActiveSheetIndex ( 0 ); - /** - * Termék azonosító Termék neve Termék szám Termék vonalkód Termék raktáron Termék eladva - */ - $row = 1; - $col = 0; - foreach ( $defs as $def ) { - $sheet->setCellValue ( $cols [$col] . $row, $def [1] ); - $col ++; - } - - foreach ( $models as $model ) { - $row ++; - $col = 0; - foreach ( $defs as $def ) { - $sheet->setCellValue ( $cols [$col] . $row, $model[$def [0]] ); - $col ++; - } - } - - $styleArray = array ( - 'font' => array ( - 'bold' => true - ) - ); - // 'color' => array('rgb' => 'FF0000'), - // 'size' => 15, - // 'name' => 'Verdana' - - - - foreach ( range ( 'A', 'I' ) as $columnID ) { - $sheet->getColumnDimension ( $columnID )->setAutoSize ( true ); - $sheet->getStyle ( $columnID . '1' )->applyFromArray ( $styleArray ); - } - - // Redirect output to a client’s web browser (Excel5) - header ( 'Content-Type: application/vnd.ms-excel' ); - header ( 'Content-Disposition: attachment;filename="leltar.xls"' ); - header ( 'Cache-Control: max-age=0' ); - // If you're serving to IE 9, then the following may be needed - header ( 'Cache-Control: max-age=1' ); - // If you're serving to IE over SSL, then the following may be needed - header ( 'Expires: Mon, 26 Jul 1997 05:00:00 GMT' ); // Date in the past - header ( 'Last-Modified: ' . gmdate ( 'D, d M Y H:i:s' ) . ' GMT' ); // always modified - header ( 'Cache-Control: cache, must-revalidate' ); // HTTP/1.1 - header ( 'Pragma: public' ); // HTTP/1.0 - $objWriter = \PHPExcel_IOFactory::createWriter ( $objPHPExcel, 'Excel5' ); - $objWriter->save ( 'php://output' ); - exit (); + + /** + * @param $dataProvider + */ + protected function downloadIndexXls($dataProvider) + { + $defs = [['item_created_at', 'Létrehozva'], + ['item_name', 'Termék/Termék csoport'], + ['user_username', 'Felhasználó'], + ['item_count_prev', 'Előző leltár (db)'], + ['item_count_sold', 'Eladott mennyiség (db)'], + ['item_count_in', 'Beszerzett mennyiség (db)'], + ['item_count', 'Leltározott mennyiség (db)'], + ['item_difference', 'Különbség (db)'], + ['item_count_system', 'Rendszer szerinti mennyiség (db)'], + ]; + $cols = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P']; + + /** @noinspection PhpUndefinedMethodInspection */ + $models = $dataProvider->getModels(); + /** @noinspection PhpUndefinedClassInspection */ + $objPHPExcel = new \PHPExcel (); + + $sheet = $objPHPExcel->setActiveSheetIndex(0); + /** + * Termék azonosító Termék neve Termék szám Termék vonalkód Termék raktáron Termék eladva + */ + $row = 1; + $col = 0; + foreach ($defs as $def) { + $sheet->setCellValue($cols [$col] . $row, $def [1]); + $col++; + } + + foreach ($models as $model) { + $row++; + $col = 0; + foreach ($defs as $def) { + $sheet->setCellValue($cols [$col] . $row, $model[$def [0]]); + $col++; + } + } + + $styleArray = array( + 'font' => array( + 'bold' => true + ) + ); + // 'color' => array('rgb' => 'FF0000'), + // 'size' => 15, + // 'name' => 'Verdana' + + + foreach (range('A', 'I') as $columnID) { + $sheet->getColumnDimension($columnID)->setAutoSize(true); + $sheet->getStyle($columnID . '1')->applyFromArray($styleArray); + } + + // Redirect output to a client’s web browser (Excel5) + header('Content-Type: application/vnd.ms-excel'); + header('Content-Disposition: attachment;filename="leltar.xls"'); + header('Cache-Control: max-age=0'); + // If you're serving to IE 9, then the following may be needed + header('Cache-Control: max-age=1'); + // If you're serving to IE over SSL, then the following may be needed + header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past + header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); // always modified + header('Cache-Control: cache, must-revalidate'); // HTTP/1.1 + header('Pragma: public'); // HTTP/1.0 + /** @noinspection PhpUndefinedClassInspection */ + $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5'); + $objWriter->save('php://output'); + exit (); } - + /** * Displays a single InventoryItem model. * @param integer $id @@ -149,16 +158,18 @@ class InventoryItemController extends Controller /** * Creates a new InventoryItem model. * If creation is successful, the browser will be redirected to the 'view' page. + * @param Integer $id the item id * @return mixed + * @throws \Exception */ public function actionCreate($id) { $model = new InventoryItemForm([ - 'id_inventory' => $id + 'id_inventory' => $id ]); $model->read(); - + if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['inventory-item/index', 'id' => $model->inventory->id_inventory]); } else { @@ -173,38 +184,142 @@ class InventoryItemController extends Controller * If update is successful, the browser will be redirected to the 'view' page. * @param integer $id * @return mixed + * @throws NotAcceptableHttpException + * @throws NotFoundHttpException */ public function actionUpdate($id) { $model = $this->findModel($id); $inventory = Inventory::findOne($model->id_inventory); - - if ( !$inventory->isOpen()){ - throw new NotAcceptableHttpException("A leltár elem nem található"); + + if (!$inventory->isOpen()) { + throw new NotAcceptableHttpException("A leltár elem nem található"); } - + if ($model->load(Yii::$app->request->post()) && $model->validate()) { - - $model->recalculateTotalPriceBrutto(); - - $model->save(false); - - $prev = Url::previous("inventory-item-index"); - - if ( isset($prev)){ - return $this->redirect($prev); - }else{ - return $this->redirect([ 'index', 'id' => $inventory->id_inventory ]); - } - + + $model->recalculateTotalPriceBrutto(); + + $model->save(false); + + $prev = Url::previous("inventory-item-index"); + + if (isset($prev)) { + return $this->redirect($prev); + } else { + return $this->redirect(['index', 'id' => $inventory->id_inventory]); + } + } else { return $this->render('update', [ 'model' => $model, - 'inventory' => $inventory, + 'inventory' => $inventory, ]); } } + /** + * @param integer $id the inventory item id + * @return string + * @throws Exception + * @throws NotAcceptableHttpException + * @throws NotFoundHttpException + */ + public function actionUpdateItem($idInventory = null,$id = null) + { + + if ( !isset($idInventory ) && !isset($id)){ + \Yii::error("Neither inventory id nor inventory item id"); + } + + if ( isset($id)){ + $model = $this->findModel($id); + $inventory = Inventory::findOne($model->id_inventory); + }else{ + $inventory = Inventory::findOne($idInventory); + $model = new InventoryItem(); + } + + if (!$inventory->isOpen()) { + throw new NotAcceptableHttpException("A leltár elem nem található"); + } + + + if (Yii::$app->request->getIsAjax()) { + $arr = [ + 'id_inventory_item' => $model->id_inventory_item, + 'productName' => $model->productName, + 'count' => $model->count, + 'type' => $model->type + ]; + + return json_encode($arr); + } else { + if (Yii::$app->request->isPost && $model->isNewRecord ){ + \Yii::error("Failed to save inventory-item: post , but no item id"); + throw new Exception("Hiba történt mentés közben"); + } + + if ($model->load(Yii::$app->request->post()) && $model->validate()) { + + $model->recalculateTotalPriceBrutto(); + + if ( $model->save(false) ){ + \Yii::$app->session->setFlash('success', "Mennyiség elmentve: " . $model->productName . ' - ' .$model->count . ' db'); + }else{ + \Yii::error("Nem sikerült elmenteni a leltár element."); + throw new Exception("Nem sikerült elmenteni a leltár element"); + } + + if ( isset($_POST['_next'])){ + return $this->redirect(['update-item', 'idInventory' => $inventory->id_inventory]); + }else{ + return $this->redirect(['index', 'id' => $inventory->id_inventory]); + } + + } + + + $query = new Query(); + $query->select([ + 'product.id_product as product_id_product', + 'product.name as product_name', + 'account.name as account_name', + 'product_category.name as product_category_name', + 'inventory_item.id_inventory_item as inventory_item_id_inventory_item', + ]); + $query->from(['product']); + + $query + ->innerJoin("product_category", "product_category.id_product_category = product.id_product_category") + ->innerJoin("account", "product.id_account = account.id_account") + ->innerJoin("inventory_item", "inventory_item.id_product = product.id_product") + ->andWhere(["inventory_item.id_inventory" => $inventory->id_inventory])->all(); + $productsRaw = $query->all(); + + + $products = []; + foreach ($productsRaw as $product ){ + $arr = []; + $arr['id_inventory_item'] = $product['inventory_item_id_inventory_item']; + $arr['id_product'] = $product['product_id_product']; + $arr['name'] = $product['product_name'] ."( ". $product['account_name'].")"; + $arr['product_name'] = $product['account_name'] ; + $products[] = $arr; + } + + + + return $this->render("update_item", [ + 'model' => $model, + 'inventory' => $inventory, + 'products' => $products + ]); + } + + } + + /** * Deletes an existing InventoryItem model. * If deletion is successful, the browser will be redirected to the 'index' page. diff --git a/backend/controllers/UgiroController.php b/backend/controllers/UgiroController.php index dcc9d44..61035da 100644 --- a/backend/controllers/UgiroController.php +++ b/backend/controllers/UgiroController.php @@ -373,14 +373,17 @@ class UgiroController extends Controller { * @return mixed */ public function actionDelete($id) { + $this->findModel ( $id )->delete (); return $this->redirect ( [ 'index' ] ); + } public function actionDetsta() { $ugiro = Ugiro::findOne ( 31 ); + $model = new DetStatProcessor ( [ 'koteg' => $ugiro ] ); diff --git a/backend/views/inventory-item/_form.php b/backend/views/inventory-item/_form.php index e804144..74eb942 100644 --- a/backend/views/inventory-item/_form.php +++ b/backend/views/inventory-item/_form.php @@ -7,19 +7,15 @@ use yii\widgets\ActiveForm; /* @var $model common\models\InventoryItem */ /* @var $form yii\widgets\ActiveForm */ ?> - -
+ Magyarázat: +
+ 'xls']), ['class' => 'btn btn-primary']) ?> +
+ 'item_name', + 'label' => 'Név', + + ], + [ + 'attribute' => 'inventory_prev_name', + 'label' => 'Utolsó leltár' + ], + [ + 'attribute' => 'item_count_system', + 'label' => 'Rendszer szerinti mennyiség (db)', + 'contentOptions' => ['class' => 'numeric'] + + ], + [ + 'attribute' => 'item_count', + 'label' => 'Leltározott mennyiség (db)', + 'contentOptions' => ['class' => 'numeric'] + + ], + [ + 'attribute' => 'item_count_prev', + 'label' => 'Előzö leltár (db)', + 'contentOptions' => ['class' => 'numeric'] + + ], + [ + 'attribute' => 'item_count_in', + 'label' => 'Beszerzett mennyiség (db)', + 'contentOptions' => ['class' => 'numeric'] + + ], + [ + 'attribute' => 'item_count_sold', + 'label' => 'Eladott mennyiség (db)', + 'contentOptions' => ['class' => 'numeric'] + + ], + [ + 'attribute' => 'item_difference', + 'label' => 'Különbség (db)', + 'contentOptions' => ['class' => 'numeric'] + + ], + [ + 'attribute' => 'item_price_brutto', + 'label' => 'Eladási ár (Ft)', + 'contentOptions' => ['class' => 'numeric'] + ], + [ + 'attribute' => 'item_total_price_brutto', + 'label' => 'Összeg (Ft)', + 'contentOptions' => ['class' => 'numeric'] + ], - -- Magyarázat: -
- 'xls']),['class' =>'btn btn-primary'])?> -
- - 'item_name', - 'label' => 'Név', - - ], - [ - 'attribute' => 'inventory_prev_name', - 'label' => 'Utolsó leltár' - ], - [ - 'attribute' => 'item_count_system', - 'label' => 'Rendszer szerinti mennyiség (db)', - 'contentOptions' => ['class' => 'numeric'] - - ], - [ - 'attribute' => 'item_count', - 'label' => 'Leltározott mennyiség (db)', - 'contentOptions' => ['class' => 'numeric'] - - ], - [ - 'attribute' => 'item_count_prev', - 'label' => 'Előzö leltár (db)', - 'contentOptions' => ['class' => 'numeric'] - - ], - [ - 'attribute' => 'item_count_in', - 'label' => 'Beszerzett mennyiség (db)', - 'contentOptions' => ['class' => 'numeric'] - - ], - [ - 'attribute' => 'item_count_sold', - 'label' => 'Eladott mennyiség (db)', - 'contentOptions' => ['class' => 'numeric'] - - ], - [ - 'attribute' => 'item_difference', - 'label' => 'Különbség (db)', - 'contentOptions' => ['class' => 'numeric'] - - ], - [ - 'attribute' => 'item_price_brutto', - 'label' => 'Eladási ár (Ft)', - 'contentOptions' => ['class' => 'numeric'] - ], - [ - 'attribute' => 'item_total_price_brutto', - 'label' => 'Összeg (Ft)', - 'contentOptions' => ['class' => 'numeric'] - ], - - - ]; - - if ( $model->isOpen() ){ - - $columns[] = ['class' => 'yii\grid\ActionColumn', - 'template' => '{update}', - 'urlCreator' => function ($action, $model, $key, $index){ - return Url::to(['inventory-item/update', 'id' => $model['item_id_inventory_item' ] ]) ; - }, - 'buttons' =>[ - 'update' =>function ($url, $model, $key) { - return Html::a('Módosítás', $url,['class' => 'btn btn-xs btn-success', - 'data' => [ - ], - ]) ; - } - ] - - ] ; - } - - - - echo GridView::widget( [ - 'dataProvider' => $dataProvider, - 'columns' => $columns - - ]); - ?> + echo GridView::widget([ + 'dataProvider' => $dataProvider, + 'columns' => $columns + ]); + ?>| Név |
|---|