surat/frontend/modules/administrator/controllers/HospitalImportServiceCharge...

179 lines
5.4 KiB
PHP
Raw Normal View History

2026-02-16 07:32:27 +00:00
<?php
namespace frontend\modules\administrator\controllers;
use Yii;
use common\models\HospitalImportServiceCharge;
use frontend\modules\administrator\models\HospitalImportServiceChargeSearch;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
/**
* HospitalImportServiceChargeController implements the CRUD actions for HospitalImportServiceCharge model.
*/
class HospitalImportServiceChargeController extends Controller
{
/**
* {@inheritdoc}
*/
public function behaviors()
{
return [
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'delete' => ['POST'],
],
],
];
}
/**
* Lists all HospitalImportServiceCharge models.
* @return mixed
*/
public function actionIndex()
{
$searchModel = new HospitalImportServiceChargeSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
]);
}
/**
* Displays a single HospitalImportServiceCharge model.
* @param integer $id
* @return mixed
* @throws NotFoundHttpException if the model cannot be found
*/
public function actionView($id)
{
return $this->render('view', [
'model' => $this->findModel($id),
]);
}
/**
* Creates a new HospitalImportServiceCharge model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
$model = new HospitalImportServiceCharge();
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->id]);
}
return $this->render('create', [
'model' => $model,
]);
}
/**
* Updates an existing HospitalImportServiceCharge 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
*/
public function actionUpdate($id)
{
$model = $this->findModel($id);
2026-02-17 07:53:03 +00:00
if ($model->load(Yii::$app->request->post())) {
if ($model->save()) {
Yii::$app->pathology->setLog(
'Update',
'แก้ไข Hospital Import Service Charge: ' . $model->id_case,
Yii::$app->user->getId(),
HospitalImportServiceCharge::tableName()
);
Yii::$app->session->setFlash(
'success',
'บันทึกการแก้ไข Hospital Import Service Charge ของ Case: ' . $model->id_case . ' เรียบร้อยแล้ว'
);
return $this->redirect(['view', 'id' => $model->id]);
} else {
Yii::$app->session->setFlash(
'error',
'ไม่สามารถบันทึกข้อมูลได้ กรุณาตรวจสอบข้อมูลอีกครั้ง'
);
}
2026-02-16 07:32:27 +00:00
}
return $this->render('update', [
'model' => $model,
]);
}
/**
* Deletes an existing HospitalImportServiceCharge 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
*/
/*public function actionDelete($id)
{
$this->findModel($id)->delete();
return $this->redirect(['index']);
}*/
public function actionDelete($id)
{
$model = $this->findModel($id);
2026-02-17 07:53:03 +00:00
// เก็บ req_no ไว้ก่อนลบ
$req_no = $model->req_no;
2026-02-16 07:32:27 +00:00
2026-02-17 07:53:03 +00:00
if ($model->delete()) {
2026-02-16 07:32:27 +00:00
2026-02-17 07:53:03 +00:00
Yii::$app->pathology->setLog(
'Delete',
'ลบรายการตรวจ: ' . $req_no,
Yii::$app->user->getId(),
HospitalImportServiceCharge::tableName()
);
Yii::$app->session->setFlash(
'success',
'ลบรายการตรวจของ Request Number: ' . $req_no . ' เรียบร้อยแล้ว'
);
} else {
Yii::$app->session->setFlash(
'error',
'ไม่สามารถลบข้อมูลได้ อาจมีข้อมูลที่เกี่ยวข้องอยู่ในระบบ'
);
}
2026-02-16 07:32:27 +00:00
return $this->redirect(['index']);
}
/**
* Finds the HospitalImportServiceCharge model based on its primary key value.
* If the model is not found, a 404 HTTP exception will be thrown.
* @param integer $id
* @return HospitalImportServiceCharge the loaded model
* @throws NotFoundHttpException if the model cannot be found
*/
protected function findModel($id)
{
if (($model = HospitalImportServiceCharge::findOne($id)) !== null) {
return $model;
}
throw new NotFoundHttpException('The requested page does not exist.');
}
2026-02-17 07:53:03 +00:00
}