viewData['pageTitle'] = lang('Festivos.moduleTitle'); $this->viewData['usingSweetAlert'] = true; $this->model = model($this->modelName); $this->validation = service("validation"); parent::initController($request, $response, $logger); } public function index() { checkPermission('festivos.menu'); return view($this->viewPath . $this->indexRoute); } public function store_festivo_date() { checkPermission('festivos.edit'); $bodyData = $this->request->getPost(); $date = $bodyData['date']; $count = $this->model->where('date',$date)->countAllResults(); if ($count) { $status = $this->model->where('date', $date)->delete(purge: true); return $this->response->setJSON([ "message" => lang("App.user_alert_delete"), "status" => $status, ]); } else { $status = $this->model->insert($bodyData); if ($status) { $festivoEntity = $this->model->find($status); return $this->response->setJSON([ "message" => lang("App.global_alert_save_success"), "status" => $status, "data" => $festivoEntity ]); } else { return $this->response->setJSON([ "message" => lang("App.global_alert_save_error"), "errors" => $this->model->errors(), "status" => true ])->setStatusCode(400); } } } public function delete_festivo_date($id) { $status = $this->model->delete($id, true); if ($status) { return $this->response->setJSON([ "message" => lang("App.user_alert_delete"), "status" => $status, ]); } else { return $this->response->setJSON([ "message" => lang("App.global_alert_save_error"), "errors" => $this->model->errors(), "status" => true ])->setStatusCode(400); } } public function find_all() { $festivos = $this->model->findAll(); return $this->response->setJSON([ "message" => lang("App.global_alert_fetch_success"), "status" => true, "data" => $festivos ]); } }