From 1d3c47647673efc789eb9976ceaf55613e165029 Mon Sep 17 00:00:00 2001 From: Roland Schneider Date: Mon, 7 Mar 2016 20:54:32 +0100 Subject: [PATCH] work on inventory --- backend/assets/InventoryItemCreateAsset.php | 31 ++ backend/components/AdminMenuStructure.php | 1 + backend/controllers/InventoryController.php | 122 ++++++++ .../controllers/InventoryItemController.php | 126 ++++++++ backend/models/InventoryItemForm.php | 268 ++++++++++++++++++ backend/models/InventoryItemSearch.php | 75 +++++ backend/models/InventorySearch.php | 67 +++++ backend/views/inventory-item/_form.php | 27 ++ backend/views/inventory-item/_search.php | 49 ++++ backend/views/inventory-item/create.php | 33 +++ backend/views/inventory-item/index.php | 45 +++ backend/views/inventory-item/update.php | 23 ++ backend/views/inventory-item/view.php | 46 +++ backend/views/inventory/_form.php | 22 ++ backend/views/inventory/_search.php | 33 +++ backend/views/inventory/create.php | 21 ++ backend/views/inventory/index.php | 36 +++ backend/views/inventory/update.php | 23 ++ backend/views/inventory/view.php | 36 +++ backend/web/js/inventory.item.create.js | 59 ++++ common/models/Inventory.php | 60 ++++ common/models/InventoryItem.php | 65 +++++ .../m160306_130115_add_inventory_item.php | 58 ++++ ...__column_id_inventory_prev__count_prev.php | 31 ++ 24 files changed, 1357 insertions(+) create mode 100644 backend/assets/InventoryItemCreateAsset.php create mode 100644 backend/controllers/InventoryController.php create mode 100644 backend/controllers/InventoryItemController.php create mode 100644 backend/models/InventoryItemForm.php create mode 100644 backend/models/InventoryItemSearch.php create mode 100644 backend/models/InventorySearch.php create mode 100644 backend/views/inventory-item/_form.php create mode 100644 backend/views/inventory-item/_search.php create mode 100644 backend/views/inventory-item/create.php create mode 100644 backend/views/inventory-item/index.php create mode 100644 backend/views/inventory-item/update.php create mode 100644 backend/views/inventory-item/view.php create mode 100644 backend/views/inventory/_form.php create mode 100644 backend/views/inventory/_search.php create mode 100644 backend/views/inventory/create.php create mode 100644 backend/views/inventory/index.php create mode 100644 backend/views/inventory/update.php create mode 100644 backend/views/inventory/view.php create mode 100644 backend/web/js/inventory.item.create.js create mode 100644 common/models/Inventory.php create mode 100644 common/models/InventoryItem.php create mode 100644 console/migrations/m160306_130115_add_inventory_item.php create mode 100644 console/migrations/m160307_174038_alter__tablle__inventory_item__add__column_id_inventory_prev__count_prev.php diff --git a/backend/assets/InventoryItemCreateAsset.php b/backend/assets/InventoryItemCreateAsset.php new file mode 100644 index 0000000..7390ed1 --- /dev/null +++ b/backend/assets/InventoryItemCreateAsset.php @@ -0,0 +1,31 @@ + + * @since 2.0 + */ +class InventoryItemCreateAsset extends AssetBundle +{ + public $basePath = '@webroot'; + public $baseUrl = '@web'; + public $css = [ + ]; + public $js = [ + 'js/app.js', + 'js/inventory.item.create.js', + ]; + public $depends = [ + 'backend\assets\AppAsset', + 'yii\jui\JuiAsset', + 'common\assets\TypeAheadAsset', + ]; +} diff --git a/backend/components/AdminMenuStructure.php b/backend/components/AdminMenuStructure.php index 87910b8..bf08e95 100644 --- a/backend/components/AdminMenuStructure.php +++ b/backend/components/AdminMenuStructure.php @@ -91,6 +91,7 @@ class AdminMenuStructure{ $items[] = ['label' => 'Termékek', 'url' => ['/product/index'] ]; $items[] = ['label' => 'Beszerzések', 'url' => ['/procurement/index'] ]; $items[] = ['label' => 'Leltár csoport', 'url' => ['/inventory-group/index'] ]; + $items[] = ['label' => 'Leltár', 'url' => ['/inventory/index'] ]; $items[] = ['label' => 'Részletes eladások', 'url' => ['/transfer/sale' ,'TransferSaleSearch[start]' =>$todayDatetime,'TransferSaleSearch[end]' => $tomorrowDatetime ] ]; $items[] = ['label' => 'Termék összesítő', 'url' => ['/product/statistics' ,'ProductStatisticsSearch[start]' =>$todayDatetime,'ProductStatisticsSearch[end]' => $tomorrowDatetime ] ]; $this->menuItems[] = ['label' => 'Termékek', 'url' => $this->emptyUrl, diff --git a/backend/controllers/InventoryController.php b/backend/controllers/InventoryController.php new file mode 100644 index 0000000..6a11a94 --- /dev/null +++ b/backend/controllers/InventoryController.php @@ -0,0 +1,122 @@ + [ + '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, + ]); + } + + /** + * Displays a single Inventory model. + * @param integer $id + * @return mixed + */ + public function actionView($id) + { + return $this->render('view', [ + 'model' => $this->findModel($id), + ]); + } + + /** + * 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(); + + $model->id_user = \Yii::$app->user->id; + if ($model->load(Yii::$app->request->post()) && $model->save()) { + return $this->redirect(['view', 'id' => $model->id_inventory]); + } else { + return $this->render('create', [ + 'model' => $model, + ]); + } + } + + /** + * 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. + * 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/backend/controllers/InventoryItemController.php b/backend/controllers/InventoryItemController.php new file mode 100644 index 0000000..bf679c0 --- /dev/null +++ b/backend/controllers/InventoryItemController.php @@ -0,0 +1,126 @@ + [ + 'class' => VerbFilter::className(), + 'actions' => [ + 'delete' => ['post'], + ], + ], + ]; + } + + /** + * Lists all InventoryItem models. + * @return mixed + */ + public function actionIndex() + { + $searchModel = new InventoryItemSearch(); + $dataProvider = $searchModel->search(Yii::$app->request->queryParams); + + return $this->render('index', [ + 'searchModel' => $searchModel, + 'dataProvider' => $dataProvider, + ]); + } + + /** + * 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(['view', 'id' => $model->id_inventory_item]); + } 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); + + if ($model->load(Yii::$app->request->post()) && $model->save()) { + return $this->redirect(['view', 'id' => $model->id_inventory_item]); + } else { + return $this->render('update', [ + 'model' => $model, + ]); + } + } + + /** + * 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) + { + $this->findModel($id)->delete(); + + return $this->redirect(['index']); + } + + /** + * 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/backend/models/InventoryItemForm.php b/backend/models/InventoryItemForm.php new file mode 100644 index 0000000..87372d6 --- /dev/null +++ b/backend/models/InventoryItemForm.php @@ -0,0 +1,268 @@ + false, 'skipOnError' => false], + ['id_product','validateId','skipOnEmpty' => false, 'skipOnError' => false] + + ]; + } + + public function validateType($attribute,$params){ + if ( array_search($this->type, ['product','group']) === false ){ + \Yii::error("Típus nem megfelelő: " . $this->type); + $this->addError("name","Nincs termék vagy termék csoport kiválasztva"); + } + } + + public function validateId($attribute,$params){ + if ( !$this->hasErrors('type')){ + if ( $this->type == 'group'){ + $this->inventoryGroup = InventoryGroup::findOne($this->id_product); + if ( !isset($this->inventoryGroup)){ + \Yii::error("Termék csoport nem található"); + $this->addError("name","Nincs termék vagy termék csoport kiválasztva"); + } + }else{ + $this->product = Product::findOne($this->id_product); + if ( !isset($this->product )){ + \Yii::error("Termék nem található"); + $this->addError("name","Nincs termék vagy termék csoport kiválasztva"); + } + } + } + } + + public function save(){ + if ( $this->validate()) { + + $this->loadLastInventoryItem(); + $this->loadProductIn(); + $this->loadProductSold(); + $this->loadProductStock(); + + $item = new InventoryItem(); + $item->count_in = $this->product_in; + $item->count_sold = $this->product_out; + $item->count = $this->product_stock; + + if ( isset( $this->lastInventoryItem ) ){ + $item->id_inventory_item_prev = $this->lastInventoryItem->id_inventory_item; + $item->count_prev = $this->lastInventoryItem->count; + }else{ + $item->count_prev = 0; + } + + $item->id_user = \Yii::$app->user->id; + + if ( $this->type == 'product'){ + $item->id_product = $this->product->id_product; + }else{ + $item->id_inventory_group = $this->inventoryGroup->id_inventory_group; + } + + if ( !$item->save() ){ + throw new \Exception("Nem sikerült a leltár végrehajtása"); + } + + + } + return false; + } + + protected function loadProductIn(){ + $query = new Query(); + $query->select(['sum(procurement.count) as total_in']); + $query->from(Procurement::tableName()); + $query->innerJoin(Product::tableName(),"product.id_product = procurement.id_product"); + + if ( isset($this->lastInventoryItem ) ){ + $query->andWhere([ '>', 'procurement.created_at' ,$this->lastInventoryItem->created_at]); + } + + if ( $this->type == 'product') { + $query->andWhere(['product.id_product' => $this->product->id_product]); + }else{ + $query->andWhere(['product.id_inventory_group' => $this->inventoryGroup->id_inventory_group]); + } + + $this->product_in = $query->scalar(); + + } + + protected function loadProductSold(){ + + $query = new Query(); + $query->select(['sum(transfer.count) as total_sold']); + $query->from(Transfer::tableName()); + $query->innerJoin(Product::tableName(),"product.id_product = transfer.id_object and transfer.type = " .Transfer::TYPE_PRODUCT); + $query->andWhere(['in', 'transfer.status' ,[Transfer::STATUS_PAID ,Transfer::STATUS_NOT_PAID ] ]); + $query->andWhere(['transfer.type' => Transfer::TYPE_PRODUCT]); + + if ( $this->type == 'product') { + $query->andWhere(['product.id_product' => $this->product->id_product]); + }else{ + $query->andWhere(['product.id_inventory_group' => $this->inventoryGroup->id_inventory_group]); + } + + $this->product_out = $query->scalar(); + } + + protected function loadProductStock(){ + + $query = new Query(); + $query->select(['sum(product.stock) as total_stock']); + $query->from(Product::tableName()); + + if ( $this->type == 'product') { + $query->andWhere(['product.id_product' => $this->product->id_product]); + }else{ + $query->andWhere(['product.id_inventory_group' => $this->inventoryGroup->id_inventory_group]); + } + + $this->product_stock = $query->scalar(); + } + + + + + public function addProductItem(){ + + } + + public function addGroupItem(){ + + } + + /** + * Load previous inventory item, if exists + * */ + protected function loadLastInventoryItem( ){ + if ( isset( $this->lastInventory ) ){ + $query = InventoryItem::find(); + $query->andWhere(['id_inventory' => $this->lastInventory->id_inventory]); + + if ( $this->type == 'product'){ + $query->andWhere(['id_product' => $this->product->id_product]); + }else{ + $query->andWhere(['id_inventory_group' => $this->inventoryGroup->id_inventory_group]); + } + + $this->lastInventoryItem = $query->one(); + } + } + + public function read(){ + $this->loadInventory(); + $this->loadLastInventory(); + + $this->loadProducts(); + $this->loadInventoryGroups(); + + $this->buildProductList(); + + } + + public function loadInventory(){ + $this->inventory = Inventory::findOne($this->id_inventory); + if ( !isset( $this->inventory) ){ + throw new Exception("Nem található a leltár objektum"); + } + } + public function loadLastInventory(){ + $query = Inventory::find(); + $query->andWhere('<', 'inventory.created_at' , $this->inventory->created_at); + $query->orderBy(['created_at' => SORT_DESC ]); + //$this->lastInventory = + $query->limit(1)->all(); + } + + public function loadProducts(){ + $query = Product::find(); + $query->andWhere("id_inventory_group is null"); + $query->andWhere(['status' => Product::STATUS_ACTIVE]); + $this->products = $query->all(); + } + + public function loadInventoryGroups(){ + $query = InventoryGroup::find(); + $query->andWhere(['status' => Product::STATUS_ACTIVE]); + $this->inventoryGroups = $query->all(); + } + + public function buildProductList(){ + $this->productOptions = []; + + foreach ($this->products as $product ){ + $this->productOptions[]= [ 'type' =>'product', 'id' => $product->id_product ,'name' => $product->name . " (Termék/" .$product->productCategoryName ."/" . $product->accountName .")" ]; + + } + + foreach ($this->inventoryGroups as $inventoryGroup ){ + $this->productOptions[] = ['type' =>'group', 'id' =>$inventoryGroup->id_inventory_group ,'name' =>$inventoryGroup->name ."/Termékcsoport" ]; + + } + + } + + public function attributeLabels() + { + return [ + 'count' => 'Mennyiség' + ]; + } + + +} \ No newline at end of file diff --git a/backend/models/InventoryItemSearch.php b/backend/models/InventoryItemSearch.php new file mode 100644 index 0000000..ba44f59 --- /dev/null +++ b/backend/models/InventoryItemSearch.php @@ -0,0 +1,75 @@ + $query, + ]); + + $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_item' => $this->id_inventory_item, + 'id_inventory' => $this->id_inventory, + 'count_in' => $this->count_in, + 'count_sold' => $this->count_sold, + 'count' => $this->count, + 'type' => $this->type, + 'id_product' => $this->id_product, + 'id_inventory_group' => $this->id_inventory_group, + 'id_user' => $this->id_user, + 'last_inventroy_at' => $this->last_inventroy_at, + 'created_at' => $this->created_at, + 'updated_at' => $this->updated_at, + ]); + + return $dataProvider; + } +} diff --git a/backend/models/InventorySearch.php b/backend/models/InventorySearch.php new file mode 100644 index 0000000..81ff763 --- /dev/null +++ b/backend/models/InventorySearch.php @@ -0,0 +1,67 @@ + $query, + ]); + + $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/backend/views/inventory-item/_form.php b/backend/views/inventory-item/_form.php new file mode 100644 index 0000000..0343c8d --- /dev/null +++ b/backend/views/inventory-item/_form.php @@ -0,0 +1,27 @@ + + +
+ + + + field($model, 'name')->textInput(['autocomplete' => 'off']) ?> + field($model, 'id_product')->hiddenInput()->label(false) ?> + field($model, 'type')->hiddenInput()->label(false) ?> + field($model, 'count')->textInput() ?> + + +
+ 'btn btn-success' ]) ?> +
+ + + +
diff --git a/backend/views/inventory-item/_search.php b/backend/views/inventory-item/_search.php new file mode 100644 index 0000000..6b31263 --- /dev/null +++ b/backend/views/inventory-item/_search.php @@ -0,0 +1,49 @@ + + + diff --git a/backend/views/inventory-item/create.php b/backend/views/inventory-item/create.php new file mode 100644 index 0000000..16056d1 --- /dev/null +++ b/backend/views/inventory-item/create.php @@ -0,0 +1,33 @@ +title = Yii::t('common/inventory-item', 'Új leltár elem'); +$this->params['breadcrumbs'][] = ['label' => 'Leltár' , 'url' => ['inventory/view', 'id' => $model->inventory->id_inventory]]; +$this->params['breadcrumbs'][] = $this->title; + +InventoryItemCreateAsset::register($this); + + +$options = []; +$options['products'] = $model->productOptions; +$options['url_product_find'] = Url::toRoute(['product/find']); + +$this->registerJs('inventoryItemCreate.init( '. json_encode($options) .' );'); + +?> +
+ +

title) ?>

+ + render('_form', [ + 'model' => $model, + ]) ?> + +
diff --git a/backend/views/inventory-item/index.php b/backend/views/inventory-item/index.php new file mode 100644 index 0000000..fb55dad --- /dev/null +++ b/backend/views/inventory-item/index.php @@ -0,0 +1,45 @@ +title = Yii::t('common/inventory-item', 'Inventory Items'); +$this->params['breadcrumbs'][] = $this->title; +?> +
+ +

title) ?>

+ render('_search', ['model' => $searchModel]); ?> + +

+ 'btn btn-success']) ?> +

+ + $dataProvider, + 'filterModel' => $searchModel, + 'columns' => [ + ['class' => 'yii\grid\SerialColumn'], + + 'id_inventory_item', + 'id_inventory', + 'count_in', + 'count_sold', + 'count', + // 'type', + // 'id_product', + // 'id_inventory_group', + // 'id_user', + // 'last_inventroy_at', + // 'created_at', + // 'updated_at', + + ['class' => 'yii\grid\ActionColumn'], + ], + ]); ?> + +
diff --git a/backend/views/inventory-item/update.php b/backend/views/inventory-item/update.php new file mode 100644 index 0000000..cba8142 --- /dev/null +++ b/backend/views/inventory-item/update.php @@ -0,0 +1,23 @@ +title = Yii::t('common/inventory-item', 'Update {modelClass}: ', [ + 'modelClass' => 'Inventory Item', +]) . ' ' . $model->id_inventory_item; +$this->params['breadcrumbs'][] = ['label' => Yii::t('common/inventory-item', 'Inventory Items'), 'url' => ['index']]; +$this->params['breadcrumbs'][] = ['label' => $model->id_inventory_item, 'url' => ['view', 'id' => $model->id_inventory_item]]; +$this->params['breadcrumbs'][] = Yii::t('common/inventory-item', 'Update'); +?> +
+ +

title) ?>

+ + render('_form', [ + 'model' => $model, + ]) ?> + +
diff --git a/backend/views/inventory-item/view.php b/backend/views/inventory-item/view.php new file mode 100644 index 0000000..917f066 --- /dev/null +++ b/backend/views/inventory-item/view.php @@ -0,0 +1,46 @@ +title = $model->id_inventory_item; +$this->params['breadcrumbs'][] = ['label' => Yii::t('common/inventory-item', 'Inventory Items'), 'url' => ['index']]; +$this->params['breadcrumbs'][] = $this->title; +?> +
+ +

title) ?>

+ +

+ $model->id_inventory_item], ['class' => 'btn btn-primary']) ?> + $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', + ], + ]) ?> +

+ + $model, + 'attributes' => [ + 'id_inventory_item', + 'id_inventory', + 'count_in', + 'count_sold', + 'count', + 'type', + 'id_product', + 'id_inventory_group', + 'id_user', + 'last_inventroy_at', + 'created_at', + 'updated_at', + ], + ]) ?> + +
diff --git a/backend/views/inventory/_form.php b/backend/views/inventory/_form.php new file mode 100644 index 0000000..0b494ff --- /dev/null +++ b/backend/views/inventory/_form.php @@ -0,0 +1,22 @@ + + +
+ + + + +
+ isNewRecord ? Yii::t('common/inventory', 'Létrehoz') : Yii::t('common/inventory', 'Módosít'), [ 'name'=>'Inventory[submit]' ,'class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?> +
+ + + +
diff --git a/backend/views/inventory/_search.php b/backend/views/inventory/_search.php new file mode 100644 index 0000000..48ba4bc --- /dev/null +++ b/backend/views/inventory/_search.php @@ -0,0 +1,33 @@ + + + diff --git a/backend/views/inventory/create.php b/backend/views/inventory/create.php new file mode 100644 index 0000000..0bb57b8 --- /dev/null +++ b/backend/views/inventory/create.php @@ -0,0 +1,21 @@ +title = Yii::t('common/inventory', 'Új leltár'); +$this->params['breadcrumbs'][] = ['label' => Yii::t('common/inventory', 'Leltár lista'), 'url' => ['index']]; +$this->params['breadcrumbs'][] = $this->title; +?> +
+ +

title) ?>

+ + render('_form', [ + 'model' => $model, + ]) ?> + +
diff --git a/backend/views/inventory/index.php b/backend/views/inventory/index.php new file mode 100644 index 0000000..497e02b --- /dev/null +++ b/backend/views/inventory/index.php @@ -0,0 +1,36 @@ +title = Yii::t('common/inventory', 'Leltár lista'); +$this->params['breadcrumbs'][] = $this->title; +?> +
+ +

title) ?>

+ render('_search', ['model' => $searchModel]); ?> + +

+ 'btn btn-success']) ?> +

+ + $dataProvider, + 'columns' => [ + + 'id_inventory', + 'id_user', + 'created_at:datetime', + + ['class' => 'yii\grid\ActionColumn', + 'template' => '{view}' + ], + ], + ]); ?> + +
diff --git a/backend/views/inventory/update.php b/backend/views/inventory/update.php new file mode 100644 index 0000000..218789b --- /dev/null +++ b/backend/views/inventory/update.php @@ -0,0 +1,23 @@ +title = Yii::t('common/inventory', 'Update {modelClass}: ', [ + 'modelClass' => 'Inventory', +]) . ' ' . $model->id_inventory; +$this->params['breadcrumbs'][] = ['label' => Yii::t('common/inventory', 'Inventories'), 'url' => ['index']]; +$this->params['breadcrumbs'][] = ['label' => $model->id_inventory, 'url' => ['view', 'id' => $model->id_inventory]]; +$this->params['breadcrumbs'][] = Yii::t('common/inventory', 'Update'); +?> +
+ +

title) ?>

+ + render('_form', [ + 'model' => $model, + ]) ?> + +
diff --git a/backend/views/inventory/view.php b/backend/views/inventory/view.php new file mode 100644 index 0000000..aa005bf --- /dev/null +++ b/backend/views/inventory/view.php @@ -0,0 +1,36 @@ +title = $model->id_inventory; +$this->params['breadcrumbs'][] = ['label' => Yii::t('common/inventory', 'Leltár lista'), 'url' => ['index']]; +$this->params['breadcrumbs'][] = "Leltár"; +?> +
+ +

+ + + $model, + 'attributes' => [ + 'id_inventory', + ['attribute'=>'id_user', + 'value'=>$model->userName + ], + 'created_at:datetime', + ], + ]) ?> + + + +
+ +

+ $model->id_inventory], ['class' => 'btn btn-success']) ?> +

+ diff --git a/backend/web/js/inventory.item.create.js b/backend/web/js/inventory.item.create.js new file mode 100644 index 0000000..3565db0 --- /dev/null +++ b/backend/web/js/inventory.item.create.js @@ -0,0 +1,59 @@ + + +var inventoryItemCreate = { + + defaults : { + products: [], + selector_type : '#inventoryitemform-type', + selector_name : '#inventoryitemform-name', + selector_id : '#inventoryitemform-id_product', + }, + product: null, + init: function(o){ + this.defaults = $.extend( this.defaults, o ); + console.info(this.defaults.products); + 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 diff --git a/common/models/Inventory.php b/common/models/Inventory.php new file mode 100644 index 0000000..aaf14a0 --- /dev/null +++ b/common/models/Inventory.php @@ -0,0 +1,60 @@ + Yii::t('common/inventory', 'Leltár azonosító'), + 'id_user' => Yii::t('common/inventory', 'Felhasználó'), + 'created_at' => Yii::t('common/inventory', 'Létrehozás'), + 'updated_at' => Yii::t('common/inventory', 'Módosítás'), + ]; + } + + /** + * @inheritdoc + */ + public function behaviors() + { + return ArrayHelper::merge( [ + [ + 'class' => UserAwareBehavior::className(), + ] + ], parent::behaviors()); + } +} diff --git a/common/models/InventoryItem.php b/common/models/InventoryItem.php new file mode 100644 index 0000000..ab1ab53 --- /dev/null +++ b/common/models/InventoryItem.php @@ -0,0 +1,65 @@ + Yii::t('common/inventory_item', 'Id Inventory Item'), + 'id_inventory' => Yii::t('common/inventory_item', 'Id Inventory'), + 'count_in' => Yii::t('common/inventory_item', 'Count In'), + 'count_sold' => Yii::t('common/inventory_item', 'Count Sold'), + 'count' => Yii::t('common/inventory_item', 'Count'), + 'type' => Yii::t('common/inventory_item', 'Type'), + 'id_product' => Yii::t('common/inventory_item', 'Id Product'), + 'id_inventory_group' => Yii::t('common/inventory_item', 'Id Inventory Group'), + 'id_user' => Yii::t('common/inventory_item', 'Id User'), + 'last_inventroy_at' => Yii::t('common/inventory_item', 'Last Inventroy At'), + 'created_at' => Yii::t('common/inventory_item', 'Created At'), + 'updated_at' => Yii::t('common/inventory_item', 'Updated At'), + ]; + } + +} diff --git a/console/migrations/m160306_130115_add_inventory_item.php b/console/migrations/m160306_130115_add_inventory_item.php new file mode 100644 index 0000000..a37a2eb --- /dev/null +++ b/console/migrations/m160306_130115_add_inventory_item.php @@ -0,0 +1,58 @@ +db->driverName === 'mysql') { + // http://stackoverflow.com/questions/766809/whats-the-difference-between-utf8-general-ci-and-utf8-unicode-ci + $tableOptions = 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB'; + } + + + $this->createTable('{{%inventory}}', [ + 'id_inventory' => $this->primaryKey(), + 'id_user' => $this->integer(11), + 'created_at' => $this->dateTime()->notNull(), + 'updated_at' => $this->dateTime()->notNull(), + ], $tableOptions); + + $this->createTable('{{%inventory_item}}', [ + 'id_inventory_item' => $this->primaryKey(), + 'id_inventory' => $this->integer(11), + 'count_in' => $this->integer(11), + 'count_sold' => $this->integer(11), + 'count' => $this->integer(11), + 'type' => $this->integer(11), + 'id_product' => $this->integer(11), + 'id_inventory_group' => $this->integer(11), + 'id_user' => $this->integer(11), + 'last_inventroy_at' => $this->dateTime(), + 'created_at' => $this->dateTime()->notNull(), + 'updated_at' => $this->dateTime()->notNull(), + ], $tableOptions); + + } + + public function down() + { + echo "m160306_130115_add_inventory_item cannot be reverted.\n"; + + return false; + } + + /* + // Use safeUp/safeDown to run migration code within a transaction + public function safeUp() + { + } + + public function safeDown() + { + } + */ +} diff --git a/console/migrations/m160307_174038_alter__tablle__inventory_item__add__column_id_inventory_prev__count_prev.php b/console/migrations/m160307_174038_alter__tablle__inventory_item__add__column_id_inventory_prev__count_prev.php new file mode 100644 index 0000000..bb5dbe5 --- /dev/null +++ b/console/migrations/m160307_174038_alter__tablle__inventory_item__add__column_id_inventory_prev__count_prev.php @@ -0,0 +1,31 @@ +addColumn("inventory_item", "id_inventory_item_prev", "int"); + $this->addColumn("inventory_item", "count_prev", "int"); + $this->dropColumn("inventory_item", 'last_inventroy_at'); + } + + public function down() + { + echo "m160307_174038_alter__tablle__inventory_item__add__column_id_inventory_prev__count_prev cannot be reverted.\n"; + + return false; + } + + /* + // Use safeUp/safeDown to run migration code within a transaction + public function safeUp() + { + } + + public function safeDown() + { + } + */ +}