terminado edit

This commit is contained in:
Jaime Jiménez
2023-11-14 12:58:24 +01:00
parent e12913c2a0
commit 149e9f64eb
9 changed files with 415 additions and 257 deletions

View File

@ -14,7 +14,7 @@ use App\Services\PresupuestoService;
use App\Models\Configuracion\PapelImpresionModel;
use App\Models\Configuracion\MaquinaModel;
use App\Models\Configuracion\MaquinasTarifasImpresionModel;
use Exception;
class Cosidotapablanda extends \App\Controllers\GoBaseResourceController
{
@ -153,150 +153,107 @@ class Cosidotapablanda extends \App\Controllers\GoBaseResourceController
public function edit($requestedId = null)
{
// JJO
$session = session();
// JJO
$session = session();
if ($requestedId == null) :
return $this->redirect2listView();
endif;
$id = filter_var($requestedId, FILTER_SANITIZE_URL);
$presupuestoEntity = $this->model->find($id);
if ($presupuestoEntity == false) :
$message = lang('Basic.global.notFoundWithIdErr', [mb_strtolower(lang('Presupuestos.presupuesto')), $id]);
return $this->redirect2listView('sweet-error', $message);
endif;
$requestMethod = $this->request->getMethod();
if ($requestMethod === 'post') :
$nullIfEmpty = true; // !(phpversion() >= '8.1');
$postData = $this->request->getPost();
$sanitizedData = $this->sanitized($postData, $nullIfEmpty);
if ($this->request->getPost('recoger_en_taller') == null) {
$sanitizedData['recoger_en_taller'] = false;
}
if ($this->request->getPost('ferro') == null) {
$sanitizedData['ferro'] = false;
}
if ($this->request->getPost('ferro_digital') == null) {
$sanitizedData['ferro_digital'] = false;
}
if ($this->request->getPost('marcapaginas') == null) {
$sanitizedData['marcapaginas'] = false;
}
if ($this->request->getPost('papel_formato_personalizado') == null) {
$sanitizedData['papel_formato_personalizado'] = false;
}
if ($this->request->getPost('solapas') == null) {
$sanitizedData['solapas'] = false;
}
if ($this->request->getPost('cosido') == null) {
$sanitizedData['cosido'] = false;
}
if ($this->request->getPost('cubiertas') == null) {
$sanitizedData['cubiertas'] = false;
}
if ($this->request->getPost('imagenes_bn_interior') == null) {
$sanitizedData['imagenes_bn_interior'] = false;
}
if ($this->request->getPost('en_produccion') == null) {
$sanitizedData['en_produccion'] = false;
}
if ($this->request->getPost('en_espera') == null) {
$sanitizedData['en_espera'] = false;
}
if ($this->request->getPost('modo_comparador') == null) {
$sanitizedData['modo_comparador'] = false;
}
if ($this->request->getPost('paginas_negro_hq') == null) {
$sanitizedData['paginas_negro_hq'] = false;
}
if ($this->request->getPost('paginas_negro_check_papel_total') == null) {
$sanitizedData['paginas_negro_check_papel_total'] = false;
}
if ($this->request->getPost('paginas_negro_check_impresion_total') == null) {
$sanitizedData['paginas_negro_check_impresion_total'] = false;
}
if ($this->request->getPost('paginas_color_check_papel_total') == null) {
$sanitizedData['paginas_color_check_papel_total'] = false;
}
if ($this->request->getPost('paginas_color_check_impresion_total') == null) {
$sanitizedData['paginas_color_check_impresion_total'] = false;
}
if ($this->request->getPost('paginas_portada_check_papel_total') == null) {
$sanitizedData['paginas_portada_check_papel_total'] = false;
}
if ($this->request->getPost('paginas_portada_check_impresion_total') == null) {
$sanitizedData['paginas_portada_check_impresion_total'] = false;
}
if ($this->request->getPost('paginas_cubierta_papel_impresion_id') == null) {
$sanitizedData['paginas_cubierta_papel_impresion_id'] = false;
}
if ($this->request->getPost('paginas_cubierta_check_papel_total') == null) {
$sanitizedData['paginas_cubierta_check_papel_total'] = false;
}
if ($this->request->getPost('paginas_cubierta_check_impresion_total') == null) {
$sanitizedData['paginas_cubierta_check_impresion_total'] = false;
}
if ($this->request->getPost('isDig') == null) {
$sanitizedData['isDig'] = false;
}
if ($this->request->getPost('envios_recoge_cliente') == null) {
$sanitizedData['envios_recoge_cliente'] = false;
}
if ($this->request->getPost('fecha_entrega_real_aviso') == null) {
$sanitizedData['fecha_entrega_real_aviso'] = false;
}
// JJO
$sanitizedData['user_updated_id'] = $session->id_user;
$noException = true;
if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) :
if ($this->canValidate()) :
try {
$successfulResult = $this->model->skipValidation(true)->update($id, $sanitizedData);
} catch (\Exception $e) {
$noException = false;
$this->dealWithException($e);
}
else :
$this->viewData['warningMessage'] = lang('Basic.global.formErr1', [mb_strtolower(lang('Presupuestos.presupuesto'))]);
$this->session->setFlashdata('formErrors', $this->model->errors());
endif;
$presupuestoEntity->fill($sanitizedData);
$thenRedirect = true;
if ($requestedId == null) :
return $this->redirect2listView();
endif;
if ($noException && $successfulResult) :
$id = $presupuestoEntity->id ?? $id;
$message = lang('Basic.global.updateSuccess', [mb_strtolower(lang('Presupuestos.presupuesto'))]) . '.';
$message .= anchor("admin/presupuestos/{$id}/edit", lang('Basic.global.continueEditing') . '?');
$message = ucfirst(str_replace("'", "\'", $message));
$id = filter_var($requestedId, FILTER_SANITIZE_URL);
$presupuestoEntity = $this->model->find($id);
if ($thenRedirect) :
if (!empty($this->indexRoute)) :
return redirect()->to(route_to($this->indexRoute))->with('sweet-success', $message);
if ($presupuestoEntity == false) :
$message = lang('Basic.global.notFoundWithIdErr', [mb_strtolower(lang('Presupuestos.presupuesto')), $id]);
return $this->redirect2listView('sweet-error', $message);
endif;
$requestMethod = $this->request->getMethod();
if ($requestMethod === 'post') :
$nullIfEmpty = true; // !(phpversion() >= '8.1');
$postData = $this->request->getPost();
$postData['updated_at'] = gmdate('Y-m-d H:m:s', time());
$sanitizedData = $this->sanitized($postData, $nullIfEmpty);
// JJO
$sanitizedData['user_updated_id'] = $session->id_user;
$noException = true;
if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) :
if ($this->canValidate()) :
try {
$successfulResult = $this->model->skipValidation(true)->update($id, $sanitizedData);
} catch (\Exception $e) {
$noException = false;
$this->dealWithException($e);
}
else :
return $this->redirect2listView('sweet-success', $message);
endif;
else :
$this->session->setFlashData('sweet-success', $message);
endif;
$this->viewData['warningMessage'] = lang('Basic.global.formErr1', [mb_strtolower(lang('Presupuestos.presupuesto'))]);
$this->session->setFlashdata('formErrors', $this->model->errors());
endif;
$presupuestoEntity->fill($sanitizedData);
$thenRedirect = false;
endif;
if ($noException && $successfulResult) :
$id = $presupuestoEntity->id ?? $id;
$message = lang('Basic.global.updateSuccess', [mb_strtolower(lang('Presupuestos.presupuesto'))]) . '.';
// $message .= anchor("admin/presupuestos/{$id}/edit", lang('Basic.global.continueEditing') . '?');
//$message = ucfirst(str_replace("'", "\'", $message));
if ($thenRedirect) :
if (!empty($this->indexRoute)) :
return redirect()->to(route_to($this->indexRoute))->with('sweet-success', $message);
else :
if ($this->request->isAJAX()) {
$newTokenHash = csrf_hash();
$csrfTokenName = csrf_token();
$data = [
'mensaje' => $message,
$csrfTokenName => $newTokenHash
];
return $this->respond($data);
}
else{
return $this->redirect2listView('sweet-success', $message);
}
endif;
else :
if ($this->request->isAJAX()) {
$newTokenHash = csrf_hash();
$csrfTokenName = csrf_token();
$data = [
'mensaje' => $message,
$csrfTokenName => $newTokenHash
];
return $this->respond($data);
}
else{
$this->session->setFlashData('sweet-success', $message);
}
endif;
endif; // $noException && $successfulResult
endif; // ($requestMethod === 'post')
endif; // $noException && $successfulResult
endif; // ($requestMethod === 'post')
$this->viewData['presupuestoEntity'] = $presupuestoEntity;
if(!is_null($presupuestoEntity->comparador_json_data))
$this->viewData['comp_data'] = json_decode($presupuestoEntity->comparador_json_data);
else
$this->viewData['comp_data'] = "";
$this->viewData['clienteList'] = $this->getClienteListItems($presupuestoEntity->cliente_id ?? null);
$this->viewData['paisList'] = $this->getPaisListItems();
@ -326,7 +283,7 @@ class Cosidotapablanda extends \App\Controllers\GoBaseResourceController
$this->viewData['formAction'] = route_to('updateCosidotapablanda', $id);
$this->viewData['boxTitle'] = lang('Basic.global.edit2') . ' ' . lang('Presupuestos.moduleTitle') . ' ' . lang('Basic.global.edit3');
$this->viewData['boxTitle'] = lang('Basic.global.edit2') . ' ' . lang('Presupuestos.moduleTitleCosidoTB') . ' ' . lang('Basic.global.edit3');
return $this->displayForm(__METHOD__, $id);
@ -603,6 +560,8 @@ class Cosidotapablanda extends \App\Controllers\GoBaseResourceController
continue;
}
$linea = PresupuestoService::getCostesLinea($uso, $datosPedido, $maquina, $papel, $opciones_papel, $tarifa);
if(array_key_exists('error', $linea))
continue;
$linea['fields']['tarifa_impresion_id'] = $tarifaId;
$linea['fields']['maquina'] = $maquina->maquina;
$linea['fields']['maquina_id'] = $maquina->maquina_id;