mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
servicios desdoblados en presupuesto admin
This commit is contained in:
@ -36,7 +36,7 @@ class ServiciosAcabado extends BaseResourceController
|
||||
// Breadcrumbs
|
||||
$this->viewData['breadcrumb'] = [
|
||||
['title' => lang("App.menu_tarifas"), 'route' => "javascript:void(0);", 'active' => false],
|
||||
['title' => lang("App.menu_Servicioacabado"), 'route' => site_url('tarifas/acabados'), 'active' => true]
|
||||
['title' => lang("App.menu_servicioAcabado"), 'route' => route_to('serviciosAcabadoList'), 'active' => true]
|
||||
];
|
||||
|
||||
helper("time");
|
||||
@ -61,12 +61,96 @@ class ServiciosAcabado extends BaseResourceController
|
||||
return view(static::$viewPath . 'viewServiciosAcabadoList', $viewData);
|
||||
}
|
||||
|
||||
public function add()
|
||||
{
|
||||
|
||||
checkPermission('tarifa-acabado.create', $this->indexRoute);
|
||||
|
||||
if ($this->request->getPost()) :
|
||||
|
||||
$nullIfEmpty = true; // !(phpversion() >= '8.1');
|
||||
|
||||
$postData = $this->request->getPost();
|
||||
|
||||
$sanitizedData = $this->sanitized($postData, $nullIfEmpty);
|
||||
|
||||
$tarifasSeleccionadas = $postData['tarifasAcabado'] ?? [];
|
||||
unset($postData['tarifasAcabado']);
|
||||
|
||||
$sanitizedData = $this->sanitized($postData, $nullIfEmpty);
|
||||
|
||||
$sanitizedData['user_updated_id'] = auth()->user()->id;
|
||||
|
||||
if ($this->request->getPost('mostrar_en_presupuesto_cliente') == null) {
|
||||
$sanitizedData['mostrar_en_presupuesto'] = false;
|
||||
}
|
||||
|
||||
if ($this->request->getPost('acabado_cubierta') == null) {
|
||||
$sanitizedData['acabado_cubierta'] = false;
|
||||
}
|
||||
|
||||
if ($this->request->getPost('acabado_sobrecubierta') == null) {
|
||||
$sanitizedData['acabado_sobrecubierta'] = false;
|
||||
}
|
||||
|
||||
$noException = true;
|
||||
if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) :
|
||||
|
||||
|
||||
if ($this->canValidate()) :
|
||||
try {
|
||||
$successfulResult = $this->model->skipValidation(true)->save($sanitizedData);
|
||||
} catch (\Exception $e) {
|
||||
$noException = false;
|
||||
$this->dealWithException($e);
|
||||
}
|
||||
else:
|
||||
$this->viewData['errorMessage'] = lang('Basic.global.formErr1', [lang('Basic.global.record')]);
|
||||
$this->session->setFlashdata('formErrors', $this->model->errors());
|
||||
endif;
|
||||
|
||||
$thenRedirect = true; // Change this to false if you want your user to stay on the form after submission
|
||||
endif;
|
||||
if ($noException && $successfulResult) :
|
||||
|
||||
$id = $this->model->db->insertID();
|
||||
|
||||
$message = lang('Basic.global.saveSuccess', [lang('Basic.global.record')]) . '.';
|
||||
|
||||
$modelTable = model("App\Models\Tarifas\Acabados\TarifasAcabadoServiciosAcabadoModel");
|
||||
|
||||
foreach ($tarifasSeleccionadas as $tarifaId) {
|
||||
$modelTable->insert(['servicio_id' => $id, 'tarifa_id' => $tarifaId, 'user_updated_id' => auth()->user()->id]);
|
||||
}
|
||||
|
||||
if ($thenRedirect) :
|
||||
if (!empty($this->indexRoute)) :
|
||||
return redirect()->to(site_url('/serviciosacabado/edit/' . $id))->with('message', $message);
|
||||
else:
|
||||
return $this->redirect2listView('sweet-success', $message);
|
||||
endif;
|
||||
else:
|
||||
$this->session->setFlashData('sweet-success', $message);
|
||||
endif;
|
||||
|
||||
endif; // $noException && $successfulResult
|
||||
|
||||
endif; // ($requestMethod === 'post')
|
||||
|
||||
|
||||
$this->viewData['tarifasSeleccionadas'] = [];
|
||||
$this->viewData['servicio'] = isset($sanitizedData) ? new ServicioAcabadoEntity($sanitizedData) : new ServicioAcabadoEntity();
|
||||
$this->viewData['formAction'] = route_to('createServicioAcabado');
|
||||
$this->viewData['boxTitle'] = lang('Basic.global.addNew') . ' ' . lang('ServicioAcabado.moduleTitle') . ' ' . lang('Basic.global.addNewSuffix');
|
||||
|
||||
|
||||
return $this->displayForm(__METHOD__);
|
||||
}
|
||||
|
||||
|
||||
public function edit($requestedId = null)
|
||||
{
|
||||
|
||||
checkPermission('tarifa-acabado.edit', $this->indexRoute);
|
||||
|
||||
if ($requestedId == null):
|
||||
return $this->redirect2listView();
|
||||
endif;
|
||||
@ -84,6 +168,9 @@ class ServiciosAcabado extends BaseResourceController
|
||||
|
||||
$postData = $this->request->getPost();
|
||||
|
||||
$tarifasSeleccionadas = $postData['tarifasAcabado'] ?? [];
|
||||
unset($postData['tarifasAcabado']);
|
||||
|
||||
$sanitizedData = $this->sanitized($postData, $nullIfEmpty);
|
||||
|
||||
$sanitizedData['user_updated_id'] = auth()->user()->id;
|
||||
@ -113,13 +200,20 @@ class ServiciosAcabado extends BaseResourceController
|
||||
$this->dealWithException($e);
|
||||
}
|
||||
else:
|
||||
$this->viewData['warningMessage'] = lang('Basic.global.formErr1', [mb_strtolower(lang('Tarifaacabado.tarifaacabado'))]);
|
||||
$this->viewData['warningMessage'] = lang('Basic.global.formErr1', [mb_strtolower(lang('ServicioAcabado.servicioacabado'))]);
|
||||
$this->session->setFlashdata('formErrors', $this->model->errors());
|
||||
|
||||
endif;
|
||||
|
||||
$servicio->fill($sanitizedData);
|
||||
|
||||
$modelTable = model("App\Models\Tarifas\Acabados\TarifasAcabadoServiciosAcabadoModel");
|
||||
|
||||
$modelTable->where('servicio_id',$id)->delete();
|
||||
foreach ($tarifasSeleccionadas as $tarifaId) {
|
||||
$modelTable->insert(['servicio_id' => $id, 'tarifa_id' => $tarifaId, 'user_updated_id' => auth()->user()->id]);
|
||||
}
|
||||
|
||||
$thenRedirect = false;
|
||||
endif;
|
||||
|
||||
@ -141,7 +235,8 @@ class ServiciosAcabado extends BaseResourceController
|
||||
endif; // ($requestMethod === 'post')
|
||||
|
||||
$this->viewData['servicio'] = $servicio;
|
||||
$this->viewData['tarifasSeleccionadas'] = [1,2];
|
||||
|
||||
$this->viewData['tarifasSeleccionadas'] = $this->getTarifasSeleccionadasForView($id);
|
||||
|
||||
$this->viewData['formAction'] = route_to('updateServicioAcabado', $id);
|
||||
|
||||
@ -172,6 +267,16 @@ class ServiciosAcabado extends BaseResourceController
|
||||
->toJson(returnAsObject: true);
|
||||
}
|
||||
|
||||
|
||||
public function getTarifasSeleccionadasForView($servicioId){
|
||||
|
||||
$model = model("App\Models\Tarifas\Acabados\TarifasAcabadoServiciosAcabadoModel");
|
||||
$ids = $model->getTarifasForServicio($servicioId);
|
||||
|
||||
return $ids;
|
||||
}
|
||||
|
||||
|
||||
public function getTarifasSeleccionadas()
|
||||
{
|
||||
$model = model("App\Models\Tarifas\Acabados\TarifaAcabadoModel");
|
||||
|
||||
Reference in New Issue
Block a user