/var/www/vhosts/nabawater/backend/controllers
Edit: /var/www/vhosts/nabawater/backend/controllers/DeliveryChargeSettingsController.php (4556B)
search(Yii::$app->request->queryParams);
return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
]);
}
/**
* Displays a single DeliveryChargeSetting model.
* @param integer $id
* @return mixed
* @throws NotFoundHttpException if the model cannot be found
* @ Title("View")
*/
public function actionView($id)
{
return $this->render('view', [
'model' => $this->findModel($id),
]);
}
/**
* Creates a new DeliveryChargeSetting model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
* @Title("Create")
*/
public function actionCreate()
{
$model = new DeliveryChargeSetting();
$model->setScenario($model::SCENARIO_CREATE);
if ($model->load(Yii::$app->request->post())) {
if($model->validate() && $model->save()) {
return $this->redirect(['index']);
}
}
return $this->render('create', [
'model' => $model,
]);
}
/**
* Updates an existing DeliveryChargeSetting model.
* If update is successful, the browser will be redirected to the 'view' page.
* @param integer $id
* @return mixed
* @throws NotFoundHttpException if the model cannot be found
* @Title("Update")
*/
public function actionUpdate($id)
{
$model = $this->findModel($id);
$model->setScenario($model::SCENARIO_UPDATE);
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['index']);
}
return $this->render('update', [
'model' => $model,
]);
}
/**
* Deletes an existing DeliveryChargeSetting model.
* If deletion is successful, the browser will be redirected to the 'index' page.
* @param integer $id
* @return mixed
* @throws NotFoundHttpException if the model cannot be found
* @Title("Delete")
*/
public function actionDelete($id)
{
$this->findModel($id)->delete();
return $this->redirect(['index']);
}
/**
* Finds the DeliveryChargeSetting model based on its primary key value.
* If the model is not found, a 404 HTTP exception will be thrown.
* @param integer $id
* @return DeliveryChargeSetting the loaded model
* @throws NotFoundHttpException if the model cannot be found
*/
protected function findModel($id)
{
if (($model = DeliveryChargeSetting::findOne($id)) !== null) {
return $model;
}
throw new NotFoundHttpException('The requested page does not exist.');
}
/**
*
* @return Json
*/
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 = DeliveryChargeSetting::findOne(['delivery_charge_id' => $post['key']]);
if ($model === null) {
$result['msg'] = 'Invalid Request';
goto skip;
}
$model->amount = $post['value'];
if($model->amount > 10000000){
$result['msg'] = 'Sorry, maximum allowed amount is 10000000';
goto skip;
}
$model->save(false);
$result['status'] = STATUS_SUCCESS;
$result['msg'] = 'Amount Updated Successfully';
skip:
return $this->asJson($result);
}
}