diff --git a/backend/components/AdminMenuStructure.php b/backend/components/AdminMenuStructure.php index 1b2576b..df3b8e2 100644 --- a/backend/components/AdminMenuStructure.php +++ b/backend/components/AdminMenuStructure.php @@ -96,6 +96,7 @@ class AdminMenuStructure{ $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 ] ]; + $items[] = ['label' => 'Leltár pillanat képek', 'url' => ['/inventory/daily' ] ]; $this->menuItems[] = ['label' => 'Termékek', 'url' => $this->emptyUrl, 'items' => $items ]; diff --git a/backend/components/InventoryManager.php b/backend/components/InventoryManager.php new file mode 100644 index 0000000..317990e --- /dev/null +++ b/backend/components/InventoryManager.php @@ -0,0 +1,22 @@ +status = Inventory::$STATUS_CLOSED; + $model->type = Inventory::$TYPE_DAILY; + $model->name = 'Automatikus Napi '.date('Ymd_His') ; + $model->save(false); + return $model; + } + +} +?> \ No newline at end of file diff --git a/backend/controllers/InventoryController.php b/backend/controllers/InventoryController.php index 8167db5..1734337 100644 --- a/backend/controllers/InventoryController.php +++ b/backend/controllers/InventoryController.php @@ -2,6 +2,8 @@ namespace backend\controllers; +use backend\components\InventoryManager; +use backend\models\InventorySearchAuto; use /** @noinspection PhpMethodOrClassCallIsNotCaseSensitiveInspection */ Yii; use common\models\Inventory; @@ -45,6 +47,34 @@ class InventoryController extends Controller ]); } + /** + * Lists all Inventory models. + * @return mixed + */ + public function actionDaily() + { + $searchModel = new InventorySearchAuto(); + $dataProvider = $searchModel->search(Yii::$app->request->queryParams); + + return $this->render('daily', [ + 'searchModel' => $searchModel, + 'dataProvider' => $dataProvider, + ]); + } + + + /** + * Creates a new Inventory model with type daily. + * If creation is successful, the browser will be redirected to the 'view' page. + * @return mixed + */ + public function actionCreateDaily() + { + $inventoryManager = new InventoryManager(); + $model = $inventoryManager->generateDaily(); + return $this->redirect(['inventory-item/index', 'id' => $model->id_inventory]); + } + /** * Creates a new Inventory model. @@ -56,7 +86,8 @@ class InventoryController extends Controller $model = new Inventory(); $user = User::findOne(\Yii::$app->user->id); - $model->status = Inventory::$STATUS_OPEN; + $model->status = Inventory::$STATUS_OPEN; + $model->type = Inventory::$TYPE_MANUAL; $model->name = 'Leltár_'.date('Ymd_His') .'_' . $user->username; diff --git a/backend/models/InventoryItemForm.php b/backend/models/InventoryItemForm.php index ab34f93..5c28c6d 100644 --- a/backend/models/InventoryItemForm.php +++ b/backend/models/InventoryItemForm.php @@ -19,6 +19,9 @@ use common\models\Sale; /** * ContactForm is the model behind the contact form. * @property \Yii\web\UploadedFile $file + * @property \common\models\Inventory $inventory + * @property \common\models\Inventory $last_inventory + * @property number $id_inventory */ class InventoryItemForm extends Model{ @@ -102,10 +105,17 @@ class InventoryItemForm extends Model{ $item = new InventoryItem(); $item->count_in = $this->product_in; $item->count_sold = $this->product_out; - $item->count = $this->count; $item->count_system = $this->product_stock; - - + + + if ( isset($this->inventory )){ + if ( $this->inventory->type == Inventory::$TYPE_DAILY){ + $item->count = $this->product_stock; + }else{ + $item->count = $this->count; + } + } + 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; @@ -116,9 +126,11 @@ class InventoryItemForm extends Model{ $item->count_prev = 0; } - - $item->id_user = \Yii::$app->user->id; - + + if ( isset(\Yii::$app->user )){ + $item->id_user = \Yii::$app->user->id; + } + if ( $this->type == 'product'){ $item->price_brutto = $this->product->sale_price; $item->type = InventoryItem::$TYPE_PRODUCT; @@ -201,17 +213,7 @@ class InventoryItemForm extends Model{ $this->product_stock = $query->scalar(); } - - - - public function addProductItem(){ - - } - - public function addGroupItem(){ - - } - + /** * Load previous inventory item, if exists * */ @@ -259,6 +261,7 @@ class InventoryItemForm extends Model{ } $query->andWhere(['<', 'inventory.created_at' , $this->inventory->created_at]); + $query->andWhere(['=', 'inventory.type' , $this->inventory->type]); $query->orderBy(['created_at' => SORT_DESC ]); $this->last_inventory =$query->limit(1)->one(); } diff --git a/backend/models/InventoryItemSearch.php b/backend/models/InventoryItemSearch.php index 54bc7d9..5479344 100644 --- a/backend/models/InventoryItemSearch.php +++ b/backend/models/InventoryItemSearch.php @@ -80,7 +80,7 @@ class InventoryItemSearch extends InventoryItem $query->from(InventoryItem::tableName()); - $query->innerJoin(User::tableName(), "user.id = inventory_item.id_user"); + $query->leftJoin(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"); diff --git a/backend/models/InventorySearch.php b/backend/models/InventorySearch.php index baa9964..ff81d4b 100644 --- a/backend/models/InventorySearch.php +++ b/backend/models/InventorySearch.php @@ -42,11 +42,12 @@ class InventorySearch extends Inventory public function search($params) { $query = Inventory::find(); + $query->andWhere(['=','type',Inventory::$TYPE_MANUAL]); $dataProvider = new ActiveDataProvider([ 'query' => $query, 'sort' => [ - 'defaultOrder' => ['created_at' => SORT_DESC] + 'defaultOrder' => ['created_at' => SORT_DESC] ] ]); @@ -65,6 +66,7 @@ class InventorySearch extends Inventory 'updated_at' => $this->updated_at, ]); + return $dataProvider; } } diff --git a/backend/models/InventorySearchAuto.php b/backend/models/InventorySearchAuto.php new file mode 100644 index 0000000..e2a46fa --- /dev/null +++ b/backend/models/InventorySearchAuto.php @@ -0,0 +1,72 @@ +andWhere(['=','type',Inventory::$TYPE_DAILY]); + + $dataProvider = new ActiveDataProvider([ + 'query' => $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/backend/views/inventory-item/index.php b/backend/views/inventory-item/index.php index 52378c2..6e53cee 100644 --- a/backend/views/inventory-item/index.php +++ b/backend/views/inventory-item/index.php @@ -12,6 +12,12 @@ use backend\assets\InventoryItemIndexAsset; /* @var $model \common\models\Inventory */ $this->title = Yii::t('common/inventory-item', 'Leltár részletei'); +if ( $model->type == \common\models\Inventory::$TYPE_DAILY){ + $this->params['breadcrumbs'][] = ['label' => Yii::t('common/inventory', 'Leltár pillanat képek'), 'url' => ['inventory/daily']]; +}else{ + $this->params['breadcrumbs'][] = ['label' => Yii::t('common/inventory', 'Leltár lista'), 'url' => ['inventory/index']]; +} + $this->params['breadcrumbs'][] = $this->title; diff --git a/backend/views/inventory/daily.php b/backend/views/inventory/daily.php new file mode 100644 index 0000000..3656f90 --- /dev/null +++ b/backend/views/inventory/daily.php @@ -0,0 +1,50 @@ +title = Yii::t('common/inventory', 'Leltár pillanat képek'); +$this->params['breadcrumbs'][] = $this->title; +?> +
+ +

title) ?>

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

+ 'POST','class' => 'btn btn-success']) ?> +

+ + $dataProvider, + 'columns' => [ + + 'id_inventory', + 'name', +// [ 'attribute' => 'id_user', "value" =>"userName" ], + 'created_at:datetime', +// [ 'attribute' => 'status', "value" =>"statusHuman" ], + + ['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', + ]) ; + } + ] + + ], + ], + ]); ?> + +
diff --git a/common/models/Inventory.php b/common/models/Inventory.php index 9a18b1d..aea60ec 100644 --- a/common/models/Inventory.php +++ b/common/models/Inventory.php @@ -5,7 +5,6 @@ namespace common\models; use Yii; use common\components\UserAwareBehavior; use yii\helpers\ArrayHelper; -use yii\db\Query; use backend\models\InventoryItemForm; use common\components\AccountAwareBehavior; use common\components\Helper; @@ -17,6 +16,7 @@ use common\components\Helper; * @property integer $id_user * @property integer $id_account * @property integer $status + * @property integer $type * @property string $name * @property string $created_at * @property string $updated_at @@ -28,7 +28,10 @@ class Inventory extends \common\models\BaseFitnessActiveRecord public static $STATUS_OPEN = 10; public static $STATUS_CLOSED = 20; - + + public static $TYPE_MANUAL = 1; + public static $TYPE_DAILY = 2; + /** * @inheritdoc @@ -84,10 +87,10 @@ class Inventory extends \common\models\BaseFitnessActiveRecord [ 'class' => UserAwareBehavior::className(), ], - [ - 'class' => AccountAwareBehavior::className() - - ] + [ + 'class' => AccountAwareBehavior::className() + + ] ], parent::behaviors()); } @@ -99,11 +102,8 @@ class Inventory extends \common\models\BaseFitnessActiveRecord $query->andWhere(['id_account' => $this->id_account]); } -// $query->andWhere("product.id_inventory_group is null"); $products = $query->all(); - - //echo "Products found: " . count($products); - + $inventoryGroups = InventoryGroup::find()->all(); @@ -130,9 +130,6 @@ class Inventory extends \common\models\BaseFitnessActiveRecord ); $form->save(); } - - - } } diff --git a/console/controllers/InventoryConsoleController.php b/console/controllers/InventoryConsoleController.php index 3981fdb..0a62774 100644 --- a/console/controllers/InventoryConsoleController.php +++ b/console/controllers/InventoryConsoleController.php @@ -1,6 +1,7 @@ generateDaily(); + } + + } diff --git a/console/migrations/m170324_064243_alter_table_inventory_add_column_type.php b/console/migrations/m170324_064243_alter_table_inventory_add_column_type.php new file mode 100644 index 0000000..f10c33e --- /dev/null +++ b/console/migrations/m170324_064243_alter_table_inventory_add_column_type.php @@ -0,0 +1,30 @@ +addColumn("inventory", "type", "int default 1"); + } + + public function down() + { + echo "m170324_064243_alter_table_inventory_add_column_type 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/cutler_daily.sh b/cutler_daily.sh index 0ca5ac1..35fb74d 100644 --- a/cutler_daily.sh +++ b/cutler_daily.sh @@ -8,4 +8,5 @@ php /var/www/html/cutler/yii ticket/index php /var/www/html/cutler/yii ticket/daily -php /var/www/html/cutler/yii doorlog/delete-old \ No newline at end of file +php /var/www/html/cutler/yii doorlog/delete-old +php /var/www/html/cutler/yii inventory-console/create