add inventory changes

This commit is contained in:
Roland Schneider 2016-03-23 08:15:37 +01:00
parent 7db129de92
commit e7b16f20ce
15 changed files with 413 additions and 62 deletions

View File

@ -0,0 +1,31 @@
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace backend\assets;
use yii\web\AssetBundle;
/**
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
*/
class InventoryItemIndexAsset extends AssetBundle
{
public $basePath = '@webroot';
public $baseUrl = '@web';
public $css = [
];
public $js = [
'js/app.js',
'js/inventory.item.index.js',
];
public $depends = [
'backend\assets\AppAsset',
'yii\jui\JuiAsset',
'common\assets\TypeAheadAsset',
];
}

View File

@ -86,13 +86,13 @@ class InventoryController extends Controller
$model->id_user = \Yii::$app->user->id; $model->id_user = \Yii::$app->user->id;
if ($model->load(Yii::$app->request->post()) && $model->save()) { 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 { } else {
}
return $this->render('create', [ return $this->render('create', [
'model' => $model, 'model' => $model,
]); ]);
} }
}
/** /**
* Updates an existing Inventory model. * Updates an existing Inventory model.

View File

@ -10,6 +10,8 @@ use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter; use yii\filters\VerbFilter;
use backend\models\InventoryItemForm; use backend\models\InventoryItemForm;
use common\models\Inventory; use common\models\Inventory;
use yii\helpers\Url;
use common\models\Product;
/** /**
* InventoryItemController implements the CRUD actions for InventoryItem model. * InventoryItemController implements the CRUD actions for InventoryItem model.
@ -43,13 +45,94 @@ class InventoryItemController extends Controller
$searchModel = new InventoryItemSearch(['inventory' => $inventory]); $searchModel = new InventoryItemSearch(['inventory' => $inventory]);
$dataProvider = $searchModel->search(Yii::$app->request->queryParams); $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', [ return $this->render('index', [
'model' => $inventory, 'model' => $inventory,
'searchModel' => $searchModel, 'searchModel' => $searchModel,
'dataProvider' => $dataProvider, '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 clients 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. * Displays a single InventoryItem model.
* @param integer $id * @param integer $id
@ -93,12 +176,21 @@ class InventoryItemController extends Controller
public function actionUpdate($id) public function actionUpdate($id)
{ {
$model = $this->findModel($id); $model = $this->findModel($id);
$inventory = Inventory::findOne($model->id_inventory);
if ($model->load(Yii::$app->request->post()) && $model->save()) { if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->id_inventory_item]);
$prev = Url::previous("inventory-item-index");
if ( isset($prev)){
return $this->redirect($prev);
}else{
return $this->redirect([ 'index', 'id' => $inventory->id_inventory ]);
}
} else { } else {
return $this->render('update', [ return $this->render('update', [
'model' => $model, 'model' => $model,
'inventory' => $inventory,
]); ]);
} }
} }

View File

@ -89,7 +89,6 @@ class InventoryItemForm extends Model{
} }
public function save(){ public function save(){
if ( $this->validate()) {
$this->loadLastInventory(); $this->loadLastInventory();
@ -129,8 +128,7 @@ class InventoryItemForm extends Model{
return true; return true;
} }
return false;
}
protected function loadProductIn(){ protected function loadProductIn(){
$query = new Query(); $query = new Query();

View File

@ -20,7 +20,10 @@ use common\models\Inventory;
class InventoryItemSearch extends InventoryItem class InventoryItemSearch extends InventoryItem
{ {
public $inventory; public $inventory;
public $output;
public $item_name;
public $item_type;
public $item_id;
/** /**
* @inheritdoc * @inheritdoc
*/ */
@ -28,6 +31,10 @@ class InventoryItemSearch extends InventoryItem
{ {
return [ return [
[['id_inventory_item', 'id_inventory', 'count_in', 'count_sold', 'count', 'type', 'id_product', 'id_inventory_group', 'id_user'], 'integer'], [['id_inventory_item', 'id_inventory', 'count_in', 'count_sold', 'count', 'type', 'id_product', 'id_inventory_group', 'id_user'], 'integer'],
['output', 'string'],
['item_name', 'string'],
['item_type', 'string'],
['item_id', 'integer'],
]; ];
} }
@ -50,6 +57,7 @@ class InventoryItemSearch extends InventoryItem
public function search($params) public function search($params)
{ {
$query = new Query(); $query = new Query();
$query->select([ $query->select([
'inventory_item.id_inventory_item as item_id_inventory_item', 'inventory_item.id_inventory_item as item_id_inventory_item',
'inventory_item.created_at as item_created_at', 'inventory_item.created_at as item_created_at',
@ -65,6 +73,7 @@ class InventoryItemSearch extends InventoryItem
'inventory_prev.name as inventory_prev_name', '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('(inventory_item.count - ( inventory_item.count_prev + inventory_item.count_in - inventory_item.count_sold )) as item_difference'),
]); ]);
$query->from(InventoryItem::tableName()); $query->from(InventoryItem::tableName());
@ -78,9 +87,19 @@ class InventoryItemSearch extends InventoryItem
$query->andWhere( ['inventory_item.id_inventory' => $this->inventory->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( $dataProvider = new ActiveDataProvider(
['query' => $query , ['query' => $query ,
'pagination' => ( empty($this->output) ? [] : false ),
'sort' => [ 'sort' => [
'defaultOrder' => ['item_name' => SORT_ASC],
'attributes' => Helper::mkYiiSortItems([ 'attributes' => Helper::mkYiiSortItems([
['item_created_at', 'item_created_at'], ['item_created_at', 'item_created_at'],
['item_name', 'item_name'], ['item_name', 'item_name'],
@ -100,22 +119,16 @@ class InventoryItemSearch extends InventoryItem
] ]
] ]
); );
$this->load($params);
if (!$this->validate()) {
// uncomment the following line if you do not want to return any records when validation fails if ( !empty($this->item_type) && is_numeric($this->item_id) ){
// $query->where('0=1'); if ( $this->item_type == 'product'){
return $dataProvider; $query->andFilterWhere(['product.id_product' => $this->item_id]);
}else if ( $this->item_type == 'group' ){
$query->andFilterWhere(['inventory_group.id_inventory_group' => $this->item_id]);
}
} }
$query->andFilterWhere([
'inventory_item.id_inventory_item' => $this->id_inventory_item,
'inventory_item.type' => $this->type,
'inventory_item.id_product' => $this->id_product,
'inventory_item.id_inventory_group' => $this->id_inventory_group,
'inventory_item.id_user' => $this->id_user,
'inventory_item.created_at' => $this->created_at,
]);
return $dataProvider; return $dataProvider;
} }

View File

@ -12,8 +12,6 @@ use yii\widgets\ActiveForm;
<?php $form = ActiveForm::begin(); ?> <?php $form = ActiveForm::begin(); ?>
<?= $form->field($model, 'name')->textInput(['autocomplete' => 'off']) ?>
<?= $form->field($model, 'id_product')->hiddenInput()->label(false) ?>
<?= $form->field($model, 'type')->hiddenInput()->label(false) ?> <?= $form->field($model, 'type')->hiddenInput()->label(false) ?>
<?= $form->field($model, 'count')->textInput() ?> <?= $form->field($model, 'count')->textInput() ?>

View File

@ -11,36 +11,22 @@ use yii\widgets\ActiveForm;
<div class="inventory-item-search"> <div class="inventory-item-search">
<?php $form = ActiveForm::begin([ <?php $form = ActiveForm::begin([
'action' => ['index'], 'action' => ['index','id' => $model->inventory->id_inventory],
'method' => 'get', 'method' => 'get',
]); ?> ]); ?>
<?= $form->field($model, 'id_inventory_item') ?> <?= $form->field($model, 'item_type')->hiddenInput()->label(false) ?>
<?= $form->field($model, 'item_id')->hiddenInput()->label(false) ?>
<?= $form->field($model, 'id_inventory') ?> <div class="row">
<div class="col-md-4">
<?= $form->field($model, 'count_in') ?> <?= $form->field($model, 'item_name')->label("Termék/Termék csoport neve") ?>
</div>
<?= $form->field($model, 'count_sold') ?> </div>
<?= $form->field($model, 'count') ?>
<?php // echo $form->field($model, 'type') ?>
<?php // echo $form->field($model, 'id_product') ?>
<?php // echo $form->field($model, 'id_inventory_group') ?>
<?php // echo $form->field($model, 'id_user') ?>
<?php // echo $form->field($model, 'created_at') ?>
<?php // echo $form->field($model, 'updated_at') ?>
<div class="form-group"> <div class="form-group">
<?= Html::submitButton(Yii::t('common/inventory-item', 'Search'), ['class' => 'btn btn-primary']) ?> <?= Html::submitButton(Yii::t('common/inventory-item', 'Keresés'), ['class' => 'btn btn-primary']) ?>
<?= Html::resetButton(Yii::t('common/inventory-item', 'Reset'), ['class' => 'btn btn-default']) ?>
</div> </div>
<?php ActiveForm::end(); ?> <?php ActiveForm::end(); ?>

View File

@ -4,6 +4,7 @@ use yii\helpers\Html;
use yii\grid\GridView; use yii\grid\GridView;
use yii\widgets\DetailView; use yii\widgets\DetailView;
use yii\helpers\Url; use yii\helpers\Url;
use backend\assets\InventoryItemIndexAsset;
/* @var $this yii\web\View */ /* @var $this yii\web\View */
/* @var $searchModel backend\models\InventoryItemSearch */ /* @var $searchModel backend\models\InventoryItemSearch */
@ -11,6 +12,15 @@ use yii\helpers\Url;
$this->title = Yii::t('common/inventory-item', 'Leltár részletei'); $this->title = Yii::t('common/inventory-item', 'Leltár részletei');
$this->params['breadcrumbs'][] = $this->title; $this->params['breadcrumbs'][] = $this->title;
InventoryItemIndexAsset::register($this);
$options = [];
$options['products'] = $productOptions;
$this->registerJs('inventoryItemIndex.init( '. json_encode($options) .' );');
?> ?>
<div class="inventory-item-index"> <div class="inventory-item-index">
@ -23,17 +33,17 @@ $this->params['breadcrumbs'][] = $this->title;
'name', 'name',
['attribute'=>'id_user', ['attribute'=>'id_user',
'value'=>$model->userName 'value'=>$model->userName
],
['attribute'=>'id_account',
'value'=>$model->accountName
], ],
'created_at:datetime', 'created_at:datetime',
], ],
]) ?> ]) ?>
<?php // echo $this->render('_search', ['model' => $searchModel]); ?> <?php echo $this->render('_search', ['model' => $searchModel]); ?>
<p>
<?= Html::a(Yii::t('common/inventory', 'Új termék felvétele a leltárba'), ['inventory-item/create','id' =>$model->id_inventory], ['class' => 'btn btn-success']) ?>
</p>
<p> <p>
Magyarázat: Magyarázat:
@ -59,6 +69,10 @@ $this->params['breadcrumbs'][] = $this->title;
</ul> </ul>
</p> </p>
<p>
<?php echo Html::a("XLS letöltése", Url::current(['InventoryItemSearch[output]' =>'xls']),['class' =>'btn btn-primary'])?>
</p>
<?php <?php
echo GridView::widget( [ echo GridView::widget( [
'dataProvider' => $dataProvider, 'dataProvider' => $dataProvider,
@ -114,16 +128,14 @@ $this->params['breadcrumbs'][] = $this->title;
], ],
['class' => 'yii\grid\ActionColumn', ['class' => 'yii\grid\ActionColumn',
'template' => '{delete}', 'template' => '{update}',
'urlCreator' => function ($action, $model, $key, $index){ 'urlCreator' => function ($action, $model, $key, $index){
return Url::to(['inventory-item/delete', 'id' => $model['item_id_inventory_item' ] ]) ; return Url::to(['inventory-item/update', 'id' => $model['item_id_inventory_item' ] ]) ;
}, },
'buttons' =>[ 'buttons' =>[
'delete' =>function ($url, $model, $key) { 'update' =>function ($url, $model, $key) {
return Html::a('Törlés', $url,['class' => 'btn btn-xs btn-danger', return Html::a('Módosítás', $url,['class' => 'btn btn-xs btn-success',
'data' => [ 'data' => [
'confirm' => Yii::t('common/inventory-item', 'Biztosan törlöd ezt az elemet?'),
'method' => 'post',
], ],
]) ; ]) ;
} }

View File

@ -1,13 +1,12 @@
<?php <?php
use yii\helpers\Html; use yii\helpers\Html;
use yii\widgets\DetailView;
/* @var $this yii\web\View */ /* @var $this yii\web\View */
/* @var $model common\models\InventoryItem */ /* @var $model common\models\InventoryItem */
$this->title = Yii::t('common/inventory-item', 'Update {modelClass}: ', [ $this->title = Yii::t('common/inventory-item', 'Leltár termék');
'modelClass' => 'Inventory Item',
]) . ' ' . $model->id_inventory_item;
$this->params['breadcrumbs'][] = ['label' => Yii::t('common/inventory-item', 'Inventory Items'), 'url' => ['index']]; $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'][] = ['label' => $model->id_inventory_item, 'url' => ['view', 'id' => $model->id_inventory_item]];
$this->params['breadcrumbs'][] = Yii::t('common/inventory-item', 'Update'); $this->params['breadcrumbs'][] = Yii::t('common/inventory-item', 'Update');
@ -16,6 +15,37 @@ $this->params['breadcrumbs'][] = Yii::t('common/inventory-item', 'Update');
<h1><?= Html::encode($this->title) ?></h1> <h1><?= Html::encode($this->title) ?></h1>
<h2>Leltár</h2>
<?= DetailView::widget([
'model' => $inventory,
'attributes' => [
'id_inventory',
'name',
['attribute'=>'id_user',
'value'=>$inventory->userName
],
['attribute'=>'id_account',
'value'=>$inventory->accountName
],
'created_at:datetime',
],
]) ?>
<h2>Termék</h2>
<?= DetailView::widget([
'model' => $model,
'attributes' => [
[
'value' => $model->name,
'label' =>"Név"
],
],
]) ?>
<?= $this->render('_form', [ <?= $this->render('_form', [
'model' => $model, 'model' => $model,
]) ?> ]) ?>

View File

@ -2,18 +2,27 @@
use yii\helpers\Html; use yii\helpers\Html;
use yii\widgets\ActiveForm; use yii\widgets\ActiveForm;
use common\models\Account;
use common\components\Helper;
use frontend\components\HtmlHelper;
/* @var $this yii\web\View */ /* @var $this yii\web\View */
/* @var $model common\models\Inventory */ /* @var $model common\models\Inventory */
/* @var $form yii\widgets\ActiveForm */ /* @var $form yii\widgets\ActiveForm */
?> ?>
<?php
$accounts = ['' =>'Mind'] + HtmlHelper::mkAccountOptions( Account::readAccounts() );
?>
<div class="inventory-form"> <div class="inventory-form">
<?php $form = ActiveForm::begin(); ?> <?php $form = ActiveForm::begin(); ?>
<div class="form-group"> <div class="form-group">
<?php echo $form->field($model, "id_account")->dropDownList($accounts)?>
<?php echo $form->field($model, "name")->textInput()?> <?php echo $form->field($model, "name")->textInput()?>
<?= Html::submitButton($model->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']) ?> <?= Html::submitButton($model->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']) ?>
</div> </div>

View File

@ -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);
}
}
}

View File

@ -5,12 +5,16 @@ namespace common\models;
use Yii; use Yii;
use common\components\UserAwareBehavior; use common\components\UserAwareBehavior;
use yii\helpers\ArrayHelper; use yii\helpers\ArrayHelper;
use yii\db\Query;
use backend\models\InventoryItemForm;
use common\components\AccountAwareBehavior;
/** /**
* This is the model class for table "inventory". * This is the model class for table "inventory".
* *
* @property integer $id_inventory * @property integer $id_inventory
* @property integer $id_user * @property integer $id_user
* @property integer $id_account
* @property string $name * @property string $name
* @property string $created_at * @property string $created_at
* @property string $updated_at * @property string $updated_at
@ -27,13 +31,15 @@ class Inventory extends \common\models\BaseFitnessActiveRecord
return 'inventory'; return 'inventory';
} }
/** /**
* @inheritdoc * @inheritdoc
*/ */
public function rules() public function rules()
{ {
return [ return [
[['name'], 'string'] [['name'], 'string'],
[['id_account'], 'integer'],
]; ];
} }
@ -46,6 +52,7 @@ class Inventory extends \common\models\BaseFitnessActiveRecord
'id_inventory' => Yii::t('common/inventory', 'Leltár azonosító'), 'id_inventory' => Yii::t('common/inventory', 'Leltár azonosító'),
'name' => Yii::t('common/inventory', 'Megnevezés'), 'name' => Yii::t('common/inventory', 'Megnevezés'),
'id_user' => Yii::t('common/inventory', 'Felhasználó'), 'id_user' => Yii::t('common/inventory', 'Felhasználó'),
'id_account' => Yii::t('common/inventory', 'Kassza'),
'created_at' => Yii::t('common/inventory', 'Létrehozás'), 'created_at' => Yii::t('common/inventory', 'Létrehozás'),
'updated_at' => Yii::t('common/inventory', 'Módosítás'), 'updated_at' => Yii::t('common/inventory', 'Módosítás'),
]; ];
@ -59,7 +66,47 @@ class Inventory extends \common\models\BaseFitnessActiveRecord
return ArrayHelper::merge( [ return ArrayHelper::merge( [
[ [
'class' => UserAwareBehavior::className(), 'class' => UserAwareBehavior::className(),
],
[
'class' => AccountAwareBehavior::className()
] ]
], parent::behaviors()); ], parent::behaviors());
} }
public function afterSave($insert, $changedAttributes){
if ( $insert ){
$query = Product::find();
if ( isset($this->id_account) && !is_numeric($this->id_account)){
$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();
foreach ($products as $product){
$form = new InventoryItemForm(
[
'inventory' => $this,
'id_product' => $product->id_product,
'product' => $product,
'type' => 'product'
]
);
$form->save();
}
}
}
} }

View File

@ -6,6 +6,7 @@ use Yii;
use yii\helpers\ArrayHelper; use yii\helpers\ArrayHelper;
use common\components\UserAwareBehavior; use common\components\UserAwareBehavior;
use common\components\Helper; use common\components\Helper;
use common\components\ProductAwareBehavior;
/** /**
* This is the model class for table "inventory_item". * This is the model class for table "inventory_item".
@ -45,6 +46,8 @@ class InventoryItem extends BaseFitnessActiveRecord
public function rules() public function rules()
{ {
return [ return [
[['count'],'integer'] ,
[['count'],'required'] ,
]; ];
} }
@ -58,7 +61,7 @@ class InventoryItem extends BaseFitnessActiveRecord
'id_inventory' => Yii::t('common/inventory_item', 'Id Inventory'), 'id_inventory' => Yii::t('common/inventory_item', 'Id Inventory'),
'count_in' => Yii::t('common/inventory_item', 'Count In'), 'count_in' => Yii::t('common/inventory_item', 'Count In'),
'count_sold' => Yii::t('common/inventory_item', 'Count Sold'), 'count_sold' => Yii::t('common/inventory_item', 'Count Sold'),
'count' => Yii::t('common/inventory_item', 'Count'), 'count' => Yii::t('common/inventory_item', 'Leltározott mennyiség'),
'type' => Yii::t('common/inventory_item', 'Type'), 'type' => Yii::t('common/inventory_item', 'Type'),
'id_product' => Yii::t('common/inventory_item', 'Id Product'), 'id_product' => Yii::t('common/inventory_item', 'Id Product'),
'id_inventory_group' => Yii::t('common/inventory_item', 'Id Inventory Group'), 'id_inventory_group' => Yii::t('common/inventory_item', 'Id Inventory Group'),
@ -72,6 +75,9 @@ class InventoryItem extends BaseFitnessActiveRecord
return ArrayHelper::merge( [ return ArrayHelper::merge( [
[ [
'class' => UserAwareBehavior::className(), 'class' => UserAwareBehavior::className(),
],
[
'class' => ProductAwareBehavior::className(),
] ]
], parent::behaviors()); ], parent::behaviors());
} }
@ -133,4 +139,13 @@ class InventoryItem extends BaseFitnessActiveRecord
} }
public function afterSave($insert, $changedAttributes){
if ( !$insert ){
$product = $this->product;
$product->stock = $this->count;
$product->save(false);
}
}
} }

View File

@ -264,4 +264,36 @@ class Product extends \common\models\BaseFitnessActiveRecord {
$product->stock = $product->stock - $count; $product->stock = $product->stock - $count;
} }
public static function readProductsNotPartOfInventoryGroup( $id_account = null ){
$query = Product::find();
$query->andWhere("id_inventory_group is null");
$query->andWhere(['status' => Product::STATUS_ACTIVE]);
return $query->all();
}
public static function readInventoryGroups(){
$query = InventoryGroup::find();
$query->andWhere(['status' => Product::STATUS_ACTIVE]);
return $query->all();
}
public static function buildProductAndInventoryGroupList($id_account = null){
$productOptions = [];
$products = Product::readProductsNotPartOfInventoryGroup($id_account);
$inventoryGroups = Product::readInventoryGroups();
foreach ($products as $product ){
$productOptions[]= [ 'type' =>'product', 'id' => $product->id_product ,'name' => $product->name . " (Termék/" .$product->productCategoryName ."/" . $product->accountName .")" ];
}
foreach ($inventoryGroups as $inventoryGroup ){
$productOptions[] = ['type' =>'group', 'id' =>$inventoryGroup->id_inventory_group ,'name' =>$inventoryGroup->name ."/Termékcsoport" ];
}
return $productOptions;
}
} }

View File

@ -0,0 +1,30 @@
<?php
use yii\db\Schema;
use yii\db\Migration;
class m160321_082725_alter__inventory__add__column__id_account extends Migration
{
public function up()
{
$this->addColumn("inventory", "id_account", "int");
}
public function down()
{
echo "m160321_082725_alter__inventory__add__column__id_account cannot be reverted.\n";
return false;
}
/*
// Use safeUp/safeDown to run migration code within a transaction
public function safeUp()
{
}
public function safeDown()
{
}
*/
}