/var/www/vhosts/nabawater/backend/controllers
Edit: /var/www/vhosts/nabawater/backend/controllers/StockController.php (2067B)
render('_stock',
[
'searchModel' => $searchModel,
'dataProvider' => $searchModel->search(Yii::$app->request->queryParams),
'categoryName' => $categoryName,
'vendorName' => $vendorName,
'cuisineName' => $cuisineName
]
);
}
/**
*
* @return string
*
* @Title("Update Stock")
*/
public function actionUpdateAmount()
{
$result = ['status' => STATUS_FAIL, 'msg' => ''];
$params = ['key', 'value'];
$post = Yii::$app->getRequest()->post();
foreach ($params as $param) {
if (!array_key_exists($param, $post)) {
$result['msg'] = 'Required Param Missing';
goto skip;
}
}
$model = Item::findOne(['item_key' => $post['key']]);
if ($model === null) {
$result['msg'] = 'Invalid Request';
goto skip;
}
$model->quantity = $post['value'];
if($model->quantity > 10000000){
$result['msg'] = 'Sorry, maximum quantity is 10000000';
goto skip;
}
$model->save(false);
$result['status'] = STATUS_SUCCESS;
$result['msg'] = 'Quantity Updated Successfully';
skip:
return $this->asJson($result);
}
}