/var/www/vhosts/nabawater/backend/controllers
Edit: /var/www/vhosts/nabawater/backend/controllers/TaxController.php (4568B)
render('index',
[
'searchModel' => $searchModel,
'dataProvider' => $searchModel->search(Yii::$app->request->queryParams)
]
);
}
/**
*
* @return string
*
* @Title("Create")
*/
public function actionCreate()
{
$model = new Tax();
$modelLang = new TaxLang();
$modelCountry = new Country();
$post = Yii::$app->getRequest()->post();
if ($model->load($post) && $modelLang->load($post)) {
$model->save();
$modelLang->tax_id = $model->getPrimaryKey();
$modelLang->language_code = Yii::$app->language;
$modelLang->save();
Com::successFlash('Created Successfully');
return $this->redirect(['index']);
}
return $this->render('create', [
'model' => $model,
'modelLang' => $modelLang,
'modelCountry' => $modelCountry
]);
}
/**
*
* @param type $id
* @return string
*
* @Title("Update")
*/
public function actionUpdate($id)
{
$model = $this->findModel($id);
$modelCountry = new Country();
$modelLang = TaxLang::find()
->select([
'tax_name',
])
->where(['tax_id' => $model->getPrimaryKey()])
->one();
$post = Yii::$app->getRequest()->post();
if ($model->load($post) && $model->validate()) {
$model->save();
$modelLang = TaxLang::findOne(['tax_id' => $model->getPrimaryKey()]);
$modelLang->language_code = Yii::$app->language;
$modelLang->load($post);
$modelLang->save();
Com::successFlash('Updated Successfully');
return $this->redirect(['index']);
}
return $this->render('update', [
'model' => $model,
'modelLang' => $modelLang,
'modelCountry' => $modelCountry
]);
}
/**
*
* @return string
* @param type $id
*
* @Title("Delete")
*/
public function actionDelete($id)
{
$model = $this->findModel($id);
if ($model === null) {
Com::failureFlash('Unable to find the Tax Record');
return $this->redirect(['index']);
}
$model->status = Tax::DELETE;
$model->save();
Com::successFlash('Deleted Successfully');
return $this->redirect(['index']);
}
/**
*
* @param type $id
* @return $model
* @throws NotFoundHttpException
*/
protected function findModel($id)
{
if (($model = Tax::findOne(['tax_key' => $id])) !== null) {
return $model;
} else {
throw new NotFoundHttpException('The requested page does not exist.');
}
}
/**
* @return string
* @throws \yii\base\InvalidParamException
*
* @Title("Tax Status")
*/
public function actionChangeStatus()
{
$params = ['key', 'status'];
$post = Yii::$app->getRequest()->post();
$result = ['status' => STATUS_FAIL, 'msg' => ''];
foreach ($params as $param) {
if (!array_key_exists($param, $post)) {
$result['msg'] = 'Required param missing';
goto skip;
}
}
$model = Tax::findOne(['tax_key' => $post['key']]);
if ($model === null) {
$result['msg'] = 'Unable to find the Tax Record';
goto skip;
}
$model->status = $post['status'];
$model->save(false);
$result['msg'] = 'Tax Record deactivated successfully';
if ((int)$model->status === $model::ACTIVE) {
$result['msg'] = 'Tax Record activated successfully';
}
$result['status'] = STATUS_SUCCESS;
skip:
return $this->asJson($result);
}
}