[ 'class' => VerbFilter::className(), 'actions' => [ 'delete' => ['POST'], ], ], ]; } /** * @return void * @throws \Throwable * @throws \yii\db\StaleObjectException */ public function actionFinanceServiceChargeDelete() { $p = Yii::$app->request->post(); $finance = FinanceServiceCharge::findOne(['id_case' => $p['id_case'], 'id' => $p['from_id']]); if (!$finance) { // || !$surgical echo 'error'; } else { $finance->delete(); echo 'success'; } } /** * Lists all FinanceServiceCharge models. * @return mixed */ public function actionIndex() { $searchModel = new FinanceServiceChargeSearch(); $dataProvider = $searchModel->search(Yii::$app->request->queryParams); return $this->render('index', [ 'searchModel' => $searchModel, 'dataProvider' => $dataProvider, ]); } /** * Displays a single FinanceServiceCharge 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), ]); } /** * Updates an existing CaseSurgical 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); if ($model->load(Yii::$app->request->post())) { if ($model->save()) { Yii::$app->pathology->setLog( 'Update', 'แก้ไข ID Case และ Status: ' . $model->id_case, Yii::$app->user->getId(), FinanceServiceCharge::tableName() ); Yii::$app->session->setFlash( 'success', 'บันทึกการแก้ไขข้อมูลค่าบริการของ Case: ' . $model->id_case . ' เรียบร้อยแล้ว' ); return $this->redirect(['view', 'id' => $model->id]); } else { Yii::$app->session->setFlash( 'error', 'ไม่สามารถบันทึกข้อมูลได้ กรุณาตรวจสอบความถูกต้องอีกครั้ง' ); } } return $this->render('update', [ 'model' => $model, ]); } /** * Deletes an existing FinanceServiceCharge 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) { $model = $this->findModel($id); // เก็บ id_case ไว้ก่อนลบ (กันค่า null หลัง delete) $id_case = $model->id_case; try { if ($model->delete()) { // ถ้าต้องการเรียก API หลังลบ // Yii::$app->pathology->financeApiSendByCase($id_case); Yii::$app->pathology->setLog( 'Delete', 'ลบ Finance Service Charge: ' . $id_case, Yii::$app->user->getId(), FinanceServiceCharge::tableName() ); Yii::$app->session->setFlash( 'success', 'ลบข้อมูล Finance Service Charge ของ Case: ' . $id_case . ' เรียบร้อยแล้ว' ); } else { Yii::$app->session->setFlash( 'error', 'ไม่สามารถลบข้อมูลได้' ); } } catch (\Throwable $e) { Yii::$app->session->setFlash( 'error', 'ไม่สามารถลบข้อมูลได้ อาจมีข้อมูลที่เกี่ยวข้องอยู่ในระบบ' ); } return $this->redirect(['index']); } /** * Finds the FinanceServiceCharge model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return FinanceServiceCharge the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = FinanceServiceCharge::findOne($id)) !== null) { return $model; } throw new NotFoundHttpException('The requested page does not exist.'); } }