fast inventory item edit

This commit is contained in:
2016-08-08 18:46:58 +02:00
parent e79187c50e
commit c5bfae9ec1
5 changed files with 74 additions and 53 deletions

View File

@@ -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,