fast inventory item edit
This commit is contained in:
parent
e79187c50e
commit
c5bfae9ec1
@ -74,8 +74,6 @@ class InventoryItemController extends Controller
|
||||
*/
|
||||
protected function downloadIndexXls($dataProvider)
|
||||
{
|
||||
|
||||
|
||||
$defs = [['item_created_at', 'Létrehozva'],
|
||||
['item_name', 'Termék/Termék csoport'],
|
||||
['user_username', 'Felhasználó'],
|
||||
@ -227,11 +225,24 @@ class InventoryItemController extends Controller
|
||||
* @throws NotAcceptableHttpException
|
||||
* @throws NotFoundHttpException
|
||||
*/
|
||||
public function actionUpdateItem($id)
|
||||
public function actionUpdateItem($idInventory = null,$id = null)
|
||||
{
|
||||
|
||||
$model = $this->findModel($id);
|
||||
$inventory = Inventory::findOne($model->id_inventory);
|
||||
if ( !isset($idInventory ) && !isset($id)){
|
||||
\Yii::error("Neither inventory id nor inventory item id");
|
||||
}
|
||||
|
||||
if ( isset($id)){
|
||||
$model = $this->findModel($id);
|
||||
$inventory = Inventory::findOne($model->id_inventory);
|
||||
}else{
|
||||
$inventory = Inventory::findOne($idInventory);
|
||||
$model = new InventoryItem();
|
||||
}
|
||||
|
||||
if (!$inventory->isOpen()) {
|
||||
throw new NotAcceptableHttpException("A leltár elem nem található");
|
||||
}
|
||||
|
||||
|
||||
if (Yii::$app->request->getIsAjax()) {
|
||||
@ -244,6 +255,10 @@ class InventoryItemController extends Controller
|
||||
|
||||
return json_encode($arr);
|
||||
} else {
|
||||
if (Yii::$app->request->isPost && $model->isNewRecord ){
|
||||
\Yii::error("Failed to save inventory-item: post , but no item id");
|
||||
throw new Exception("Hiba történt mentés közben");
|
||||
}
|
||||
|
||||
if ($model->load(Yii::$app->request->post()) && $model->validate()) {
|
||||
|
||||
@ -256,7 +271,11 @@ class InventoryItemController extends Controller
|
||||
throw new Exception("Nem sikerült elmenteni a leltár element");
|
||||
}
|
||||
|
||||
return $this->redirect(['update-item', 'id' => $model->id_inventory_item]);
|
||||
if ( isset($_POST['_next'])){
|
||||
return $this->redirect(['update-item', 'idInventory' => $inventory->id_inventory]);
|
||||
}else{
|
||||
return $this->redirect(['index', 'id' => $inventory->id_inventory]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -275,7 +294,7 @@ class InventoryItemController extends Controller
|
||||
->innerJoin("product_category", "product_category.id_product_category = product.id_product_category")
|
||||
->innerJoin("account", "product.id_account = account.id_account")
|
||||
->innerJoin("inventory_item", "inventory_item.id_product = product.id_product")
|
||||
->andWhere(["inventory_item.id_inventory" => $model->id_inventory])->all();
|
||||
->andWhere(["inventory_item.id_inventory" => $inventory->id_inventory])->all();
|
||||
$productsRaw = $query->all();
|
||||
|
||||
|
||||
@ -289,9 +308,7 @@ class InventoryItemController extends Controller
|
||||
$products[] = $arr;
|
||||
}
|
||||
|
||||
if (!$inventory->isOpen()) {
|
||||
throw new NotAcceptableHttpException("A leltár elem nem található");
|
||||
}
|
||||
|
||||
|
||||
return $this->render("update_item", [
|
||||
'model' => $model,
|
||||
|
||||
@ -7,19 +7,15 @@ use yii\widgets\ActiveForm;
|
||||
/* @var $model common\models\InventoryItem */
|
||||
/* @var $form yii\widgets\ActiveForm */
|
||||
?>
|
||||
|
||||
<div id="inventory-form" class="inventory-item-form">
|
||||
|
||||
<?php $form = ActiveForm::begin( ); ?>
|
||||
|
||||
<?= $form->field($model, 'type')->hiddenInput()->label(false) ?>
|
||||
<?= $form->field($model, 'count')->textInput() ?>
|
||||
|
||||
|
||||
<div class="form-group">
|
||||
<?= Html::submitButton( Yii::t('common/inventory-item', 'Mentés/Következő')
|
||||
, ['class' => 'btn btn-success',
|
||||
'name'=> '_next' ]) ?>
|
||||
<?= Html::submitButton( Yii::t('common/inventory-item', 'Mentés') , ['class' => 'btn btn-success' ]) ?>
|
||||
</div>
|
||||
|
||||
<?php ActiveForm::end(); ?>
|
||||
|
||||
</div>
|
||||
|
||||
@ -175,17 +175,20 @@ $this->registerJs('inventoryItemIndex.init( '. json_encode($options) .' );');
|
||||
],
|
||||
]) ;
|
||||
}
|
||||
]
|
||||
|
||||
],
|
||||
'urlCreator' => function($action, $model, $key, $index){
|
||||
$result = "";
|
||||
if ( $action == 'update'){
|
||||
$result = Url::toRoute( [ 'update-item' ,'id' => $model['item_id_inventory_item']]);
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
] ;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
echo GridView::widget( [
|
||||
'dataProvider' => $dataProvider,
|
||||
'columns' => $columns
|
||||
|
||||
]);
|
||||
?>
|
||||
|
||||
|
||||
@ -7,9 +7,8 @@ use yii\widgets\DetailView;
|
||||
/* @var $model common\models\InventoryItem */
|
||||
|
||||
$this->title = Yii::t('common/inventory-item', 'Leltár termék');
|
||||
$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');
|
||||
$this->params['breadcrumbs'][] = ['label' => Yii::t('common/inventory-item', 'Leltár termék'), 'url' => ['inventory-item/index','id' => $inventory->id_inventory]];
|
||||
$this->params['breadcrumbs'][] = Yii::t('common/inventory-item', 'Leltár mennyiség');
|
||||
|
||||
\backend\assets\InventoryItemUpdateAsset::register($this);
|
||||
|
||||
@ -41,6 +40,9 @@ $this->registerJs('FitnessAdmin.InventoryItem.Update.init( '. json_encode( $opti
|
||||
],
|
||||
]) ?>
|
||||
|
||||
<?php echo Html::a("Ugrás a leltárhoz",['inventory-item/index','id'=> $inventory->id_inventory ], ['class' => 'btn btn-primary']) ?>
|
||||
|
||||
<h2>Termék keresése a leltárban</h2>
|
||||
<?php $form = \yii\widgets\ActiveForm::begin(); ?>
|
||||
|
||||
<?php echo Html::textInput("product_autocomplete","",['class' => 'form-control', 'id' => 'product_autocomplete','autocomplete' => 'off']) ?>
|
||||
@ -48,16 +50,15 @@ $this->registerJs('FitnessAdmin.InventoryItem.Update.init( '. json_encode( $opti
|
||||
|
||||
<?php \yii\widgets\ActiveForm::end(); ?>
|
||||
|
||||
<h2>Termék</h2>
|
||||
<table class="table table-striped table-bordered detail-view">
|
||||
<tbody><tr><th>Név</th><td id="inventory_product_name"> <?php echo Html::getAttributeValue($model, 'name') ?> </td></tr></tbody>
|
||||
</table>
|
||||
|
||||
|
||||
|
||||
<?= $this->render('_form', [
|
||||
'model' => $model,
|
||||
]) ?>
|
||||
<div id="inventory-product">
|
||||
<h2>Termék</h2>
|
||||
<table class="table table-striped table-bordered detail-view">
|
||||
<tbody><tr><th>Név</th><td id="inventory_product_name"> <?php echo Html::getAttributeValue($model, 'name') ?> </td></tr></tbody>
|
||||
</table>
|
||||
<?= $this->render('_form', [
|
||||
'model' => $model,
|
||||
]) ?>
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
@ -18,10 +18,10 @@ FitnessAdmin.InventoryItem.Update = new function(){
|
||||
INVENTORY_PRODUCT_NAME: '#inventory_product_name',
|
||||
INVENTORYITEM_TYPE: '#inventoryitem-type',
|
||||
INVENTORYITEM_COUNT: '#inventoryitem-count',
|
||||
INVENTORY_FORM: '#inventory-form'
|
||||
INVENTORY_FORM: '#inventory-product'
|
||||
};
|
||||
|
||||
var product = null;
|
||||
var inventoryItem = null;
|
||||
|
||||
this.init = function (options) {
|
||||
defaults = $.extend(defaults,options);
|
||||
@ -37,6 +37,8 @@ FitnessAdmin.InventoryItem.Update = new function(){
|
||||
$(defaults.selector_product).val(p.name);
|
||||
}
|
||||
}
|
||||
}else{
|
||||
$(_SELECTORS.INVENTORY_FORM).hide();
|
||||
}
|
||||
$(defaults.selector_product).focus().select();
|
||||
};
|
||||
@ -65,12 +67,12 @@ FitnessAdmin.InventoryItem.Update = new function(){
|
||||
} else {
|
||||
// This means it is only a partial match, you can either add a new item
|
||||
// or take the active if you don't want new items
|
||||
product = null;
|
||||
inventoryItem = null;
|
||||
renderForm();
|
||||
}
|
||||
} else {
|
||||
// Nothing is active so it is a new value (or maybe empty value)
|
||||
product = null;
|
||||
inventoryItem = null;
|
||||
renderForm();
|
||||
}
|
||||
});
|
||||
@ -78,7 +80,7 @@ FitnessAdmin.InventoryItem.Update = new function(){
|
||||
|
||||
var selectInventoryItem = function (data) {
|
||||
console.info('data',data);
|
||||
product = data;
|
||||
inventoryItem = data;
|
||||
};
|
||||
|
||||
var _findProduct = function (id){
|
||||
@ -97,26 +99,28 @@ FitnessAdmin.InventoryItem.Update = new function(){
|
||||
};
|
||||
|
||||
function renderForm( ) {
|
||||
console.info( "render",product);
|
||||
console.info( "render",inventoryItem);
|
||||
var name = "",type = "",count = "";
|
||||
if ( product){
|
||||
name = product.productName;
|
||||
type = product.type;
|
||||
if ( product.count ){
|
||||
count = product.count;
|
||||
if ( inventoryItem){
|
||||
name = inventoryItem.productName;
|
||||
type = inventoryItem.type;
|
||||
if ( inventoryItem.count != null ){
|
||||
count = inventoryItem.count;
|
||||
}
|
||||
}
|
||||
$(_SELECTORS.INVENTORY_PRODUCT_NAME).html(name);
|
||||
$(_SELECTORS.INVENTORYITEM_TYPE).html(type);
|
||||
$(_SELECTORS.INVENTORYITEM_COUNT).html(count);
|
||||
$(_SELECTORS.INVENTORYITEM_TYPE).val(type);
|
||||
$(_SELECTORS.INVENTORYITEM_COUNT).val(count);
|
||||
|
||||
var formContainer = $(_SELECTORS.INVENTORY_FORM);
|
||||
var form = $(_SELECTORS.INVENTORY_FORM).find('form');
|
||||
|
||||
if ( product == null ){
|
||||
form.hide();
|
||||
if ( inventoryItem == null ){
|
||||
formContainer.hide();
|
||||
}else {
|
||||
form.show();
|
||||
form.attr('action', defaults.url_save +"&id="+product.id_inventory_item);
|
||||
formContainer.show();
|
||||
form.attr('action', defaults.url_save +"&id="+inventoryItem.id_inventory_item);
|
||||
$(_SELECTORS.INVENTORYITEM_COUNT).focus().select();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user