diff --git a/backend/controllers/InventoryController.php b/backend/controllers/InventoryController.php index 7fba9f3..308384f 100644 --- a/backend/controllers/InventoryController.php +++ b/backend/controllers/InventoryController.php @@ -8,13 +8,7 @@ use backend\models\InventorySearch; use yii\web\Controller; use yii\web\NotFoundHttpException; use yii\filters\VerbFilter; -use common\models\InventoryItem; -use yii\data\ActiveDataProvider; -use common\components\Helper; use common\models\User; -use common\models\Product; -use common\models\InventoryGroup; -use yii\db\Expression; use yii\db\Query; use backend\models\InventoryItemSearch; @@ -50,27 +44,7 @@ class InventoryController extends Controller ]); } - /** - * Displays a single Inventory model. - * @param integer $id - * @return mixed - */ - public function actionView($id) - { - $inventory = $this->findModel($id); - - $searchModel = new InventoryItemSearch(['inventory' => $inventory]); - $dataProvider = $searchModel->search(Yii::$app->request->queryParams); - - - $query = new Query(); - - return $this->render('view', [ - 'model' => $inventory, - 'dataProvider' => $dataProvider - ]); - } - + /** * Creates a new Inventory model. * If creation is successful, the browser will be redirected to the 'view' page. @@ -86,7 +60,7 @@ class InventoryController extends Controller $model->id_user = \Yii::$app->user->id; if ($model->load(Yii::$app->request->post()) && $model->save()) { -// return $this->redirect(['view', 'id' => $model->id_inventory]); + return $this->redirect(['view', 'id' => $model->id_inventory]); } else { } return $this->render('create', [ @@ -94,37 +68,7 @@ class InventoryController extends Controller ]); } - /** - * Updates an existing Inventory model. - * If update is successful, the browser will be redirected to the 'view' page. - * @param integer $id - * @return mixed - */ - public function actionUpdate($id) - { - $model = $this->findModel($id); - - if ($model->load(Yii::$app->request->post()) && $model->save()) { - return $this->redirect(['view', 'id' => $model->id_inventory]); - } else { - return $this->render('update', [ - 'model' => $model, - ]); - } - } - - /** - * Deletes an existing Inventory model. - * If deletion is successful, the browser will be redirected to the 'index' page. - * @param integer $id - * @return mixed - */ - public function actionDelete($id) - { - $this->findModel($id)->delete(); - - return $this->redirect(['index']); - } + /** * Finds the Inventory model based on its primary key value. diff --git a/backend/models/InventoryItemForm.php b/backend/models/InventoryItemForm.php index 59f92cd..6e53108 100644 --- a/backend/models/InventoryItemForm.php +++ b/backend/models/InventoryItemForm.php @@ -108,10 +108,14 @@ class InventoryItemForm extends Model{ if ( isset( $this->last_inventory_item ) ){ $item->id_inventory_item_prev = $this->last_inventory_item->id_inventory_item; $item->count_prev = $this->last_inventory_item->count; + if ( !isset($item->count_prev)){ + $item->count_prev = 0; + } }else{ $item->count_prev = 0; } + $item->id_user = \Yii::$app->user->id; if ( $this->type == 'product'){ @@ -121,7 +125,7 @@ class InventoryItemForm extends Model{ } $item->id_inventory = $this->inventory->id_inventory; - if ( !$item->save() ){ + if ( !$item->save(false) ){ throw new \Exception("Nem sikerült a leltár végrehajtása"); } $this->inventory_item = $item; @@ -132,7 +136,7 @@ class InventoryItemForm extends Model{ protected function loadProductIn(){ $query = new Query(); - $query->select(['sum(procurement.count) as total_in']); + $query->select(['coalesce(sum(procurement.count),0) as total_in']); $query->from(Procurement::tableName()); $query->innerJoin(Product::tableName(),"product.id_product = procurement.id_product"); @@ -153,7 +157,7 @@ class InventoryItemForm extends Model{ protected function loadProductSold(){ $query = new Query(); - $query->select(['sum(transfer.count) as total_sold']); + $query->select(['coalesce(sum(transfer.count),0) as total_sold']); $query->from(Transfer::tableName()); $query->innerJoin(Sale::tableName(),"sale.id_sale = transfer.id_object and transfer.type = " .Transfer::TYPE_PRODUCT); $query->innerJoin(Product::tableName(),"product.id_product = sale.id_product "); @@ -172,7 +176,7 @@ class InventoryItemForm extends Model{ protected function loadProductStock(){ $query = new Query(); - $query->select(['sum(product.stock) as total_stock']); + $query->select(['coalesce(sum(product.stock),0) as total_stock']); $query->from(Product::tableName()); if ( $this->type == 'product') { diff --git a/backend/models/InventoryItemSearch.php b/backend/models/InventoryItemSearch.php index 31d45ec..b49fb49 100644 --- a/backend/models/InventoryItemSearch.php +++ b/backend/models/InventoryItemSearch.php @@ -71,7 +71,7 @@ class InventoryItemSearch extends InventoryItem 'inventory.created_at as inventory_created_at', 'inventory_prev.id_inventory as inventory_prev_id_inventory', 'inventory_prev.name as inventory_prev_name', - new Expression('(inventory_item.count - ( inventory_item.count_prev + inventory_item.count_in - inventory_item.count_sold )) as item_difference'), + new Expression('(coalesce(inventory_item.count,0) - ( coalesce(inventory_item.count_prev,0) + coalesce(inventory_item.count_in,0) - coalesce(inventory_item.count_sold,0) )) as item_difference'), ]); $query->from(InventoryItem::tableName()); diff --git a/backend/models/InventorySearch.php b/backend/models/InventorySearch.php index 81ff763..baa9964 100644 --- a/backend/models/InventorySearch.php +++ b/backend/models/InventorySearch.php @@ -45,6 +45,9 @@ class InventorySearch extends Inventory $dataProvider = new ActiveDataProvider([ 'query' => $query, + 'sort' => [ + 'defaultOrder' => ['created_at' => SORT_DESC] + ] ]); $this->load($params); diff --git a/backend/views/inventory-item/index.php b/backend/views/inventory-item/index.php index 5cabbe3..614f907 100644 --- a/backend/views/inventory-item/index.php +++ b/backend/views/inventory-item/index.php @@ -128,7 +128,7 @@ $this->registerJs('inventoryItemIndex.init( '. json_encode($options) .' );'); ], ['class' => 'yii\grid\ActionColumn', - 'template' => '{update}', + 'template' => '', 'urlCreator' => function ($action, $model, $key, $index){ return Url::to(['inventory-item/update', 'id' => $model['item_id_inventory_item' ] ]) ; }, diff --git a/backend/views/inventory/index.php b/backend/views/inventory/index.php index 566635a..75dfff2 100644 --- a/backend/views/inventory/index.php +++ b/backend/views/inventory/index.php @@ -17,7 +17,7 @@ $this->params['breadcrumbs'][] = $this->title; render('_search', ['model' => $searchModel]); ?>
- = Html::a(Yii::t('common/inventory', 'Új leltár'), ['create'], ['class' => 'btn btn-success']) ?> + 'btn btn-success']) ?>
= GridView::widget([ diff --git a/common/models/Inventory.php b/common/models/Inventory.php index 3d915fc..c809adf 100644 --- a/common/models/Inventory.php +++ b/common/models/Inventory.php @@ -78,7 +78,7 @@ class Inventory extends \common\models\BaseFitnessActiveRecord if ( $insert ){ $query = Product::find(); - if ( isset($this->id_account) && !is_numeric($this->id_account)){ + if ( isset($this->id_account) && is_numeric($this->id_account)){ $query->andWhere(['id_account' => $this->id_account]); } @@ -102,6 +102,18 @@ class Inventory extends \common\models\BaseFitnessActiveRecord $form->save(); } + foreach ($inventoryGroups as $group){ + $form = new InventoryItemForm( + [ + 'inventory' => $this, + 'id_product' => $group->id_inventory_group, + 'inventoryGroup' => $group, + 'type' => 'group' + ] + ); + $form->save(); + } + } diff --git a/common/models/InventoryItem.php b/common/models/InventoryItem.php index 7aa113f..34c961c 100644 --- a/common/models/InventoryItem.php +++ b/common/models/InventoryItem.php @@ -142,9 +142,14 @@ class InventoryItem extends BaseFitnessActiveRecord public function afterSave($insert, $changedAttributes){ if ( !$insert ){ - $product = $this->product; - $product->stock = $this->count; - $product->save(false); + if ( $this->type == 'product'){ + $product = $this->product; + $product->stock = $this->count; + if ( !$product->save(false) ){ + \Yii::error("Failed to save product stock"); + throw new \Exception("A leltár elem mentése nem sikerült"); + } + } } } diff --git a/frontend/assets/InventoryItemIndexAsset.php b/frontend/assets/InventoryItemIndexAsset.php new file mode 100644 index 0000000..31599cb --- /dev/null +++ b/frontend/assets/InventoryItemIndexAsset.php @@ -0,0 +1,30 @@ + + * @since 2.0 + */ +class InventoryItemIndexAsset extends AssetBundle +{ + public $basePath = '@webroot'; + public $baseUrl = '@web'; + public $css = [ + ]; + public $js = [ + 'js/inventory.item.index.js', + ]; + public $depends = [ + 'frontend\assets\AppAsset', + 'yii\jui\JuiAsset', + 'common\assets\TypeAheadAsset', + ]; +} diff --git a/frontend/components/FrontendMenuStructure.php b/frontend/components/FrontendMenuStructure.php index d5ebc01..1c69b35 100644 --- a/frontend/components/FrontendMenuStructure.php +++ b/frontend/components/FrontendMenuStructure.php @@ -88,7 +88,8 @@ class FrontendMenuStructure{ // } $items[] = ['label' => Yii::t('frontend/card','Vendégek'), 'url' => [ '/card/index' ] ]; - $items[] = ['label' => Yii::t('frontend/card','Leltár'), 'url' => [ '/product/inventory' ] ]; +// $items[] = ['label' => Yii::t('frontend/card','Leltár'), 'url' => [ '/product/inventory' ] ]; + $items[] = ['label' => Yii::t('frontend/card','Leltár'), 'url' => [ '/inventory/index' ] ]; $this->menuItems[] = ['label' => Yii::t('frontend/account', 'Account'), diff --git a/frontend/controllers/InventoryController.php b/frontend/controllers/InventoryController.php new file mode 100644 index 0000000..c2b9c64 --- /dev/null +++ b/frontend/controllers/InventoryController.php @@ -0,0 +1,86 @@ + [ + 'class' => VerbFilter::className(), + 'actions' => [ + 'delete' => ['post'], + ], + ], + ]; + } + + /** + * Lists all Inventory models. + * @return mixed + */ + public function actionIndex() + { + $searchModel = new InventorySearch(); + $dataProvider = $searchModel->search(Yii::$app->request->queryParams); + + return $this->render('index', [ + 'searchModel' => $searchModel, + 'dataProvider' => $dataProvider, + ]); + } + + + /** + * Creates a new Inventory model. + * If creation is successful, the browser will be redirected to the 'view' page. + * @return mixed + */ + public function actionCreate() + { + $model = new Inventory(); + $user = User::findOne(\Yii::$app->user->id); + + + $model->name = 'Leltár_'.date('Ymd_His') .'_' . $user->username; + + $model->id_user = \Yii::$app->user->id; + if ($model->load(Yii::$app->request->post()) && $model->save()) { + return $this->redirect(['inventory-item/index', 'id' => $model->id_inventory]); + } else { + } + return $this->render('create', [ + 'model' => $model, + ]); + } + + + + /** + * Finds the Inventory model based on its primary key value. + * If the model is not found, a 404 HTTP exception will be thrown. + * @param integer $id + * @return Inventory the loaded model + * @throws NotFoundHttpException if the model cannot be found + */ + protected function findModel($id) + { + if (($model = Inventory::findOne($id)) !== null) { + return $model; + } else { + throw new NotFoundHttpException('The requested page does not exist.'); + } + } +} diff --git a/frontend/controllers/InventoryItemController.php b/frontend/controllers/InventoryItemController.php new file mode 100644 index 0000000..86287ad --- /dev/null +++ b/frontend/controllers/InventoryItemController.php @@ -0,0 +1,228 @@ + [ + 'class' => VerbFilter::className(), + 'actions' => [ + 'delete' => ['post'], + ], + ], + ]; + } + + /** + * Lists all InventoryItem models. + * @return mixed + */ + 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"); + } + + + return $this->render('index', [ + 'model' => $inventory, + 'searchModel' => $searchModel, + 'dataProvider' => $dataProvider, + '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 (); + } + + /** + * Displays a single InventoryItem model. + * @param integer $id + * @return mixed + */ + public function actionView($id) + { + return $this->render('view', [ + 'model' => $this->findModel($id), + ]); + } + + /** + * Creates a new InventoryItem model. + * If creation is successful, the browser will be redirected to the 'view' page. + * @return mixed + */ + public function actionCreate($id) + { + $model = new InventoryItemForm([ + '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 { + return $this->render('create', [ + 'model' => $model, + ]); + } + } + + /** + * Updates an existing InventoryItem model. + * If update is successful, the browser will be redirected to the 'view' page. + * @param integer $id + * @return mixed + */ + public function actionUpdate($id) + { + $model = $this->findModel($id); + $inventory = Inventory::findOne($model->id_inventory); + + if ($model->load(Yii::$app->request->post()) && $model->save()) { + + $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, + ]); + } + } + + /** + * Deletes an existing InventoryItem model. + * If deletion is successful, the browser will be redirected to the 'index' page. + * @param integer $id + * @return mixed + */ + public function actionDelete($id) + { + $item = $this->findModel($id); + $id_inventory = $item->id_inventory; + $item->delete(); + + return $this->redirect(['index', 'id' => $id_inventory]); + } + + /** + * Finds the InventoryItem model based on its primary key value. + * If the model is not found, a 404 HTTP exception will be thrown. + * @param integer $id + * @return InventoryItem the loaded model + * @throws NotFoundHttpException if the model cannot be found + */ + protected function findModel($id) + { + if (($model = InventoryItem::findOne($id)) !== null) { + return $model; + } else { + throw new NotFoundHttpException('The requested page does not exist.'); + } + } +} diff --git a/frontend/models/InventoryItemSearch.php b/frontend/models/InventoryItemSearch.php new file mode 100644 index 0000000..2b32c03 --- /dev/null +++ b/frontend/models/InventoryItemSearch.php @@ -0,0 +1,135 @@ +select([ + 'inventory_item.id_inventory_item as item_id_inventory_item', + 'inventory_item.created_at as item_created_at', + new Expression('case when inventory_item.id_product is null then inventory_group.name else product.name end as item_name'), + 'user.username as user_username', + 'coalesce(inventory_item.count_prev ,0)as item_count_prev', + 'coalesce(inventory_item.count_in,0) as item_count_in', + 'coalesce(inventory_item.count_sold,0) as item_count_sold', + 'coalesce(inventory_item.count,0) as item_count', + 'coalesce(inventory_item.count_system,0) as item_count_system', + 'inventory.created_at as inventory_created_at', + 'inventory_prev.id_inventory as inventory_prev_id_inventory', + 'inventory_prev.name as inventory_prev_name', + new Expression('(coalesce(inventory_item.count,0) - ( coalesce(inventory_item.count_prev,0) + coalesce(inventory_item.count_in,0) - coalesce(inventory_item.count_sold,0) )) as item_difference'), + ]); + + $query->from(InventoryItem::tableName()); + + + $query->innerJoin(User::tableName(), "user.id = inventory_item.id_user"); + $query->leftJoin(Product::tableName(), "product.id_product = inventory_item.id_product"); + $query->leftJoin(InventoryGroup::tableName(), "inventory_group.id_inventory_group = inventory_item.id_inventory_group"); + $query->leftJoin(Inventory::tableName(), "inventory.id_inventory = inventory_item.id_inventory"); + + $query->leftJoin( "inventory_item as item_prev", "item_prev.id_inventory_item = inventory_item.id_inventory_item_prev" ); + $query->leftJoin( "inventory as inventory_prev", "inventory_prev.id_inventory = item_prev.id_inventory" ); + + $query->andWhere( ['inventory_item.id_inventory' => $this->inventory->id_inventory] ); + + $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; + } + + $dataProvider = new ActiveDataProvider( + ['query' => $query , + 'pagination' => ( empty($this->output) ? [] : false ), + 'sort' => [ + 'defaultOrder' => ['item_name' => SORT_ASC], + 'attributes' => Helper::mkYiiSortItems([ + ['item_created_at', 'item_created_at'], + ['item_name', 'item_name'], + ['user_username', 'user_username'], + ['item_count_prev', 'item_count_prev'], + ['item_count_sold', 'item_count_sold'], + ['item_count_in', 'item_count_in'], + ['item_count', 'item_count'], + ['item_count', 'item_count'], + ['item_difference', 'item_difference'], + ['item_count_system', 'item_count_system'], + ['inventory.id_inventory', 'inventory_id_inventory'], + ['inventory.name', 'inventory_name'], + ['inventory_prev_name', 'inventory_prev_name'], + ]) + , + ] + ] + ); + + + if ( !empty($this->item_type) && is_numeric($this->item_id) ){ + if ( $this->item_type == 'product'){ + $query->andFilterWhere(['product.id_product' => $this->item_id]); + }else if ( $this->item_type == 'group' ){ + $query->andFilterWhere(['inventory_group.id_inventory_group' => $this->item_id]); + } + } + + + return $dataProvider; + } +} diff --git a/frontend/models/InventorySearch.php b/frontend/models/InventorySearch.php new file mode 100644 index 0000000..c2052ff --- /dev/null +++ b/frontend/models/InventorySearch.php @@ -0,0 +1,70 @@ + $query, + 'sort' =>[ + 'defaultOrder' => [ 'created_at' => SORT_DESC ] + ] + ]); + + $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([ + 'id_inventory' => $this->id_inventory, + 'id_user' => $this->id_user, + 'created_at' => $this->created_at, + 'updated_at' => $this->updated_at, + ]); + + return $dataProvider; + } +} diff --git a/frontend/views/inventory-item/_form.php b/frontend/views/inventory-item/_form.php new file mode 100644 index 0000000..e804144 --- /dev/null +++ b/frontend/views/inventory-item/_form.php @@ -0,0 +1,25 @@ + + ++ Magyarázat: +
+ 'xls']),['class' =>'btn btn-primary'])?> +
+ + $dataProvider, + 'columns' =>[ + [ + 'attribute' => 'item_name', + 'label' => 'Név', + + ], + [ + 'attribute' => 'item_count_system', + 'label' => 'Rendszer szerinti mennyiség (db)', + + ], + + + [ + 'attribute' => 'item_count', + 'label' => 'Leltározott mennyiség (db)', + + ], + [ + 'attribute' => 'item_count_prev', + 'label' => 'Előzö leltár (db)' + + ], + [ + 'attribute' => 'item_count_in', + 'label' => 'Beszerzett mennyiség (db)' + + ], + [ + 'attribute' => 'item_count_sold', + 'label' => 'Eladott mennyiség (db)', + + ], + + + [ + 'attribute' => 'item_difference', + 'label' => 'Különbség (db)', + + ], + ['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' => [ + ], + ]) ; + } + ] + + ] + ] + + ]); + ?> + ++ = Html::a(Yii::t('common/inventory-item', 'Update'), ['update', 'id' => $model->id_inventory_item], ['class' => 'btn btn-primary']) ?> + = Html::a(Yii::t('common/inventory-item', 'Delete'), ['delete', 'id' => $model->id_inventory_item], [ + 'class' => 'btn btn-danger', + 'data' => [ + 'confirm' => Yii::t('common/inventory-item', 'Are you sure you want to delete this item?'), + 'method' => 'post', + ], + ]) ?> +
+ + = DetailView::widget([ + 'model' => $model, + 'attributes' => [ + 'id_inventory_item', + 'id_inventory', + 'count_in', + 'count_sold', + 'count', + 'type', + 'id_product', + 'id_inventory_group', + 'id_user', + 'created_at', + 'updated_at', + ], + ]) ?> + ++ = Html::a(Yii::t('common/inventory', 'Új leltár'), ['create'], ['class' => 'btn btn-success']) ?> +
+ + = GridView::widget([ + 'dataProvider' => $dataProvider, + 'columns' => [ + + 'id_inventory', + 'name', + [ 'attribute' => 'id_user', "value" =>"userName" ], + 'created_at:datetime', + + ['class' => 'yii\grid\ActionColumn', + 'template' => '{view}', + 'urlCreator' => function( $action, $model, $key, $index ){ + if ( $action == 'view' ){ + return Url::to(['inventory-item/index' , 'id'=> $model->id_inventory]); + } + }, + 'buttons' =>[ + 'view' =>function ($url, $model, $key) { + return Html::a('Részletek', $url,['class' => 'btn btn-xs btn-primary', + ]) ; + } + ] + + ], + ], + ]); ?> + ++ = Html::a(Yii::t('common/inventory', 'Új termék'), ['inventory-item/create','id' =>$model->id_inventory], ['class' => 'btn btn-success']) ?> +
+ + $dataProvider, + 'columns' =>[ + [ + 'attribute' => 'item_created_at', + 'label' => 'Létrehozva', + 'format' => 'datetime' + ], + [ + 'attribute' => 'item_name', + 'label' => 'Név', + + ], + [ + 'attribute' => 'user_username', + 'label' => 'Felhasználó', + + ], + [ + 'attribute' => 'item_count_prev', + 'label' => 'Előzö leltár (db)' + + ], + [ + 'attribute' => 'item_count_in', + 'label' => 'Beszerzett mennyiség (db)' + + ], + [ + 'attribute' => 'item_count_sold', + 'label' => 'Eladott mennyiség (db)', + + ], + [ + 'attribute' => 'item_count', + 'label' => 'Leltározott mennyiség (db)', + + ], + [ + 'attribute' => 'item_difference', + 'label' => 'Különbség (db)', + + ], + ] + + ]); + ?> + diff --git a/frontend/web/js/inventory.item.index.js b/frontend/web/js/inventory.item.index.js new file mode 100644 index 0000000..a025c96 --- /dev/null +++ b/frontend/web/js/inventory.item.index.js @@ -0,0 +1,58 @@ + + +var inventoryItemIndex = { + + defaults : { + products: [], + selector_type : '#inventoryitemsearch-item_type', + selector_name : '#inventoryitemsearch-item_name', + selector_id : '#inventoryitemsearch-item_id', + }, + product: null, + init: function(o){ + this.defaults = $.extend( this.defaults, o ); + this.initAutocomplete(); + + }, + + initAutocomplete : function (){ + var self = this; + + var $input = $(self.defaults.selector_name); + $input.typeahead({source : self.defaults.products, + autoSelect: true, + items: 20, + minLength: 3, + }); + $input.change(function() { + var current = $input.typeahead("getActive"); + $("#filter_text").val(''); + if (current) { + // Some item from your model is active! + if (current.name == $input.val()) { + self.product = current; + } else { + self.product = null; + } + } else { + self.product = null; + } + self.productChange(); + }); + }, + productChange: function( ){ + this.clearProductData(); + this.setProductData(); + }, + clearProductData: function(){ + $(this.defaults.selector_type).val(''); + $(this.defaults.selector_id).val(''); + }, + setProductData: function(){ + if ( this.product ){ + $(this.defaults.selector_type).val( this.product.type); + $(this.defaults.selector_id ).val( this.product.id); + } + + } +} \ No newline at end of file