diff --git a/ci4/app/Config/Routes.php b/ci4/app/Config/Routes.php index 471136c8..bd702019 100755 --- a/ci4/app/Config/Routes.php +++ b/ci4/app/Config/Routes.php @@ -319,6 +319,7 @@ $routes->group('clienteusuarios', ['namespace' => 'App\Controllers\Clientes'], f $routes->group('misdirecciones', ['namespace' => 'App\Controllers\Clientes'], function ($routes) { $routes->get('', 'Clientedirecciones::index', ['as' => 'clientedireccionesIndex']); $routes->get('get/(:num)', 'Clientedirecciones::get/$1', ['as' => 'get']); + $routes->get('getId', 'Clientedirecciones::getDireccionIdFromData'); $routes->get('getDireccionPresupuesto/(:num)', 'Clientedirecciones::getDireccionPresupuesto/$1', ['as' => 'getDireccionPresupuesto']); $routes->post('add', 'Clientedirecciones::add', ['as' => 'newClientedirecciones']); $routes->get('getSelect2', 'Clientedirecciones::getSelect2', ['as' => 'listaClientedirecciones']); diff --git a/ci4/app/Controllers/Clientes/Clientedirecciones.php b/ci4/app/Controllers/Clientes/Clientedirecciones.php index 2979bd10..5efbee06 100755 --- a/ci4/app/Controllers/Clientes/Clientedirecciones.php +++ b/ci4/app/Controllers/Clientes/Clientedirecciones.php @@ -215,13 +215,13 @@ class Clientedirecciones extends \App\Controllers\BaseResourceController { try { $resourceData = $this->model->getDireccion($id); - $response = (object)[ + $response = (object) [ 'error' => false, 'data' => $resourceData ]; return $this->respond($response); } catch (\Exception $e) { - $response = (object)[ + $response = (object) [ 'error' => true, 'message' => $e->getMessage() ]; @@ -229,22 +229,61 @@ class Clientedirecciones extends \App\Controllers\BaseResourceController } } + public function getDireccionIdFromData() + { + $data = $this->request->getGet('data') ?? []; + $cliente_id = $this->request->getGet('cliente_id') ?? -1; + $att = $data['att'] ?? ""; + $direccion = $data['direccion'] ?? ""; + $cp = $data['cp'] ?? ""; + $municipio = $data['municipio'] ?? ""; + $provincia = $data['provincia'] ?? ""; + $pais_id = $data['pais_id'] ?? -1; + $email = $data['email'] ?? ""; + $telefono = $data['telefono'] ?? ""; + try { + $model = model('App\Models\Clientes\ClienteDireccionesModel'); + $id = $model->select('id') + ->where('att', $att) + ->where('direccion', $direccion) + ->where('cp', $cp) + ->where('municipio', $municipio) + ->where('provincia', $provincia) + ->where('pais_id', $pais_id) + ->where('email', $email) + ->where('telefono', $telefono) + ->where('cliente_id', $cliente_id) + ->get() + ->getResultObject(); + + if (count($id) > 0) { + $id = $id[0]->id; + } else { + $id = null; + } + return $id; + + } catch (\Exception $e) { + throw new \RuntimeException($e->getMessage()); + } + } + public function getDireccionPresupuesto($id) { try { $model = model('App\Models\Presupuestos\PresupuestoDireccionesModel'); $resourceData = $model->getDireccion($id); - if(count($resourceData) > 0){ + if (count($resourceData) > 0) { $resourceData[0]->direccionId = $id; } - - $response = (object)[ + + $response = (object) [ 'error' => false, 'data' => $resourceData ]; return $this->respond($response); } catch (\Exception $e) { - $response = (object)[ + $response = (object) [ 'error' => true, 'message' => $e->getMessage() ]; @@ -400,11 +439,11 @@ class Clientedirecciones extends \App\Controllers\BaseResourceController protected function getComunidadAutonomaListItems($selId = null) { $data = ['' => lang('Basic.global.pleaseSelectA', [mb_strtolower(lang('ComunidadesAutonomas.comunidadAutonoma'))])]; - if (!is_null($selId)) : + if (!is_null($selId)): $comunidadAutonomaModel = model('App\Models\Configuracion\ComunidadAutonomaModel'); $selOption = $comunidadAutonomaModel->where('id', $selId)->findColumn('nombre'); - if (!empty($selOption)) : + if (!empty($selOption)): $data[$selId] = $selOption[0]; endif; endif; @@ -414,11 +453,11 @@ class Clientedirecciones extends \App\Controllers\BaseResourceController protected function getProvinciaListItems($selId = null) { $data = ['' => lang('Basic.global.pleaseSelectA', [mb_strtolower(lang('Provincias.provincia'))])]; - if (!empty($selId)) : + if (!empty($selId)): $provinciaModel = model('App\Models\Configuracion\ProvinciaModel'); $selOption = $provinciaModel->where('id', $selId)->findColumn('nombre'); - if (!empty($selOption)) : + if (!empty($selOption)): $data[$selId] = $selOption[0]; endif; endif; diff --git a/ci4/app/Controllers/Presupuestos/Presupuestocliente.php b/ci4/app/Controllers/Presupuestos/Presupuestocliente.php index a06f93a9..60c3c251 100755 --- a/ci4/app/Controllers/Presupuestos/Presupuestocliente.php +++ b/ci4/app/Controllers/Presupuestos/Presupuestocliente.php @@ -1065,6 +1065,9 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController $direcciones = $reqData['direcciones'] ?? []; + $direccionesFP1 = $reqData['direccionesFP1'] ?? []; + $direccionesFP2 = $reqData['direccionesFP2'] ?? []; + if ($tipo != "") $tipo_impresion_id = $this->getTipoImpresion($tipo, $cubierta['tipoCubierta']); else @@ -1557,6 +1560,14 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController } } + if (count($direccionesFP1) > 0) { + $this->guardarLineaEnvio($id, $direccionesFP1, $peso_libro, true); + + } + if (count($direccionesFP2) > 0) { + $this->guardarLineaEnvio($id, $direccionesFP2, $peso_libro, true); + } + if ($confirmar) { $model_presupuesto->confirmarPresupuesto($id); PresupuestoService::crearPedido($id); @@ -1585,7 +1596,6 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController $modelPapelFormato = new PapelFormatoModel(); $modelCliente = new ClienteModel(); - $presupuesto = $this->model->find($id); $data = []; if ($presupuesto) { @@ -1695,7 +1705,7 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController if (intval($presupuesto->recoger_en_taller) == 1) { $data['direcciones']['entrega_taller'] = 1; } else { - $data['direcciones'] = $this->obtenerDireccionesEnvio($id, $presupuesto->cliente_id); + $data['direcciones'] = $this->obtenerDireccionesEnvio($id); } if (intval($presupuesto->estado_id) == 2) { @@ -1861,12 +1871,13 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController } - protected function guardarLineaEnvio($presupuestoId, $direccion, $peso_libro) + protected function guardarLineaEnvio($presupuestoId, $direccion, $peso_libro, $coste_cero = false) { $unidades = intval($direccion['unidades']); $peso_envio = $peso_libro * $unidades / 1000.0; + $data = $this->getCosteEnvio( $direccion['direccion'], $peso_libro, @@ -1880,7 +1891,11 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController $data->presupuesto_id = $presupuestoId; $data->tarifa_id = $data->id; unset($data->id); - $data->precio = $data->coste; + if($coste_cero) { + $data->coste = 0; + } else { + $data->precio = $data->coste; + } unset($data->coste); $data->entregaPieCalle = ($direccion['entregaPalets'] == 'false' || $direccion['entregaPalets'] == 0) ? 0 : 1; unset($data->tipo); @@ -3398,39 +3413,22 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController } } - protected function obtenerDireccionesEnvio($id, $cliente_id) + protected function obtenerDireccionesEnvio($id) { $model = model('App\Models\Presupuestos\PresupuestoDireccionesModel'); - $model_direcciones = model('App\Models\Clientes\ClienteDireccionesModel'); - $direcciones = $model->where('presupuesto_id', $id)->asArray()->findAll(); + $direcciones = $model->where('presupuesto_id', $id) + ->where('is_ferro_prototipo', 0)->asArray()->findAll(); return $direcciones; + } - $result = []; - $temp = []; - for ($i = 0; $i < count($direcciones); $i++) { - $direccion_id = $model_direcciones->getIdForPresupuestoCliente( - $cliente_id, - $direcciones[$i]->att, - $direcciones[$i]->email, - $direcciones[$i]->direccion, - $direcciones[$i]->cp, - $direcciones[$i]->pais_id, - $direcciones[$i]->telefono - ); - if (count($direccion_id) > 0) { - $temp = $direcciones[$i]->toArray(); - array_push($result, [ - 'id' => $temp['id'], - 'unidades' => $temp['cantidad'], - 'palets' => $temp['entregaPieCalle'], - ]); - } - } - if (count($result) > 0) - return $result; - else - return []; + protected function obtenerDireccionesEnvioFerro($id) + { + $model = model('App\Models\Presupuestos\PresupuestoDireccionesModel'); + $direcciones = $model->where('presupuesto_id', $id) + ->where('is_ferro_prototipo', 0)->asArray()->findAll(); + + return $direcciones; } protected function obtenerDatosPapel($presupuesto_id) @@ -3643,10 +3641,18 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController foreach ($data as $servicio) { $id = "service_extra_" . $servicio->id; + + $tarifa_excluyente = false; + if (str_contains(strtolower($servicio->nombre), 'ferro') || str_contains(strtolower($servicio->nombre), 'prototipo')) { + $tarifa_excluyente = true; + } + $atributo_excluyente = $tarifa_excluyente ? 'data-tarifa-extra-excluyente="1"' : ''; + array_push( $servicios, "id}\" data-tarifa-tipo=\"extra\" data-tarifa-nombre=\"{$servicio->nombre}\"> + name=\"{$id}\" value=\"1\" data-tarifa-id=\"{$servicio->id}\" data-tarifa-tipo=\"extra\" data-tarifa-nombre=\"{$servicio->nombre}\" + {$atributo_excluyente}> " ); } diff --git a/ci4/app/Database/Migrations/2025-06-27-113000_DireccionesFerroPrototipo.php b/ci4/app/Database/Migrations/2025-06-27-113000_DireccionesFerroPrototipo.php new file mode 100644 index 00000000..de982a31 --- /dev/null +++ b/ci4/app/Database/Migrations/2025-06-27-113000_DireccionesFerroPrototipo.php @@ -0,0 +1,30 @@ +forge->addColumn('presupuesto_direcciones', [ + 'num_ferro_prototipo' => [ + 'type' => 'INT', + 'constraint' => 3, + 'null' => false, + 'default' => '0', + 'description' => 'numero de ferro/prototipo', + ], + ]); + + } + + public function down() + { + $this->db->table('presupuesto_direcciones')->whereIn('name', [ + 'num_ferro_prototipo', + 'lomo_maximo_wireo' + ])->delete(); + } +} diff --git a/ci4/app/Entities/Presupuestos/PresupuestoDireccionesEntity.php b/ci4/app/Entities/Presupuestos/PresupuestoDireccionesEntity.php index 11538041..5bde9014 100755 --- a/ci4/app/Entities/Presupuestos/PresupuestoDireccionesEntity.php +++ b/ci4/app/Entities/Presupuestos/PresupuestoDireccionesEntity.php @@ -26,6 +26,7 @@ class PresupuestoDireccionesEntity extends \CodeIgniter\Entity\Entity "margen" => null, "entregaPieCalle" => null, "is_ferro_prototipo" => null, + "num_ferro_prototipo" => null, ]; protected $casts = [ "presupuesto_id" => "int", @@ -40,6 +41,7 @@ class PresupuestoDireccionesEntity extends \CodeIgniter\Entity\Entity "proveedor_id" => "int", "entregaPieCalle" => "int", "is_ferro_prototipo" => "int", + "num_ferro_prototipo" => "int", ]; } diff --git a/ci4/app/Language/en/Presupuestos.php b/ci4/app/Language/en/Presupuestos.php index 4823c372..f465f2ef 100755 --- a/ci4/app/Language/en/Presupuestos.php +++ b/ci4/app/Language/en/Presupuestos.php @@ -42,8 +42,8 @@ return [ 'papelFormatoAncho' => 'Width', 'papelFormatoAlto' => 'Height', 'cosido' => 'Sewn', - 'ferro' => 'Ferro', - 'ferroDigital' => 'Digital Ferro', + 'ferro' => 'Blueline proof', + 'ferroDigital' => 'Digital Blueline proof', 'prototipo' => 'Prototype', 'imagenesBnInterior' => 'B/W pictures inside', 'recogerEnTaller' => 'Pick up in workshop', diff --git a/ci4/app/Language/es/Presupuestos.php b/ci4/app/Language/es/Presupuestos.php index c5d50698..dae270ef 100755 --- a/ci4/app/Language/es/Presupuestos.php +++ b/ci4/app/Language/es/Presupuestos.php @@ -396,8 +396,7 @@ return [ 'paginasColor' => 'El número de páginas a color debe ser un número entero mayor o igual que 0.', 'paginasNegro' => 'El número de páginas en negro debe ser un número entero mayor o igual que 0.', 'paginas' => 'El total de páginas tiene que ser mayor que 0.', - 'paginas_pares' => 'El número de páginas debe ser par.', - 'tipo_libro' => 'Seleccione el tipo de libro que desea para el presupuesto.', + 'tipo_libro' => 'Seleccione el tipo de encuadernación que desea para el presupuesto.', 'decimal' => 'El campo {field} debe contener un número decimal.', 'integer' => 'El campo {field} debe contener un número entero.', 'requerido' => 'El campo {field} es obligatorio.', diff --git a/ci4/app/Language/es/PresupuestosDirecciones.php b/ci4/app/Language/es/PresupuestosDirecciones.php index fbb1be1b..16205e78 100755 --- a/ci4/app/Language/es/PresupuestosDirecciones.php +++ b/ci4/app/Language/es/PresupuestosDirecciones.php @@ -21,6 +21,8 @@ return [ 'costePrecio' => 'Coste/Precio', 'saveDirection' => 'Guardar en direcciones de cliente', 'entregaPieCalle' => 'Entrega a pie de calle (enviado en palets)', + 'sameAddPrincipal' => 'Usar la dirección principal del presupuesto', + 'sameAddFP1' => 'Usar la dirección del ferro/prototipo 1', 'validation' => [ 'ejemplares_envio' => 'El número de ejemplares enviados no coincide con la tirada', 'max_length' => 'Max. valor caracteres alcanzado', diff --git a/ci4/app/Models/Presupuestos/PresupuestoDireccionesModel.php b/ci4/app/Models/Presupuestos/PresupuestoDireccionesModel.php index 15f63294..7a269872 100755 --- a/ci4/app/Models/Presupuestos/PresupuestoDireccionesModel.php +++ b/ci4/app/Models/Presupuestos/PresupuestoDireccionesModel.php @@ -45,7 +45,8 @@ class PresupuestoDireccionesModel extends \App\Models\BaseModel "proveedor_id", "proveedor", "entregaPieCalle", - "is_ferro_prototipo" + "is_ferro_prototipo", + "num_ferro_prototipo" ]; protected $returnType = "App\Entities\Presupuestos\PresupuestoDireccionesEntity"; diff --git a/ci4/app/Views/themes/vuexy/form/presupuestos/cliente/items/_datosGenerales.php b/ci4/app/Views/themes/vuexy/form/presupuestos/cliente/items/_datosGenerales.php index 01febb89..53de120a 100755 --- a/ci4/app/Views/themes/vuexy/form/presupuestos/cliente/items/_datosGenerales.php +++ b/ci4/app/Views/themes/vuexy/form/presupuestos/cliente/items/_datosGenerales.php @@ -283,12 +283,12 @@
- +
- +
@@ -300,7 +300,7 @@
- +
diff --git a/ci4/app/Views/themes/vuexy/form/presupuestos/cliente/items/_direcciones.php b/ci4/app/Views/themes/vuexy/form/presupuestos/cliente/items/_direcciones.php index 3dc42fdc..516f6767 100755 --- a/ci4/app/Views/themes/vuexy/form/presupuestos/cliente/items/_direcciones.php +++ b/ci4/app/Views/themes/vuexy/form/presupuestos/cliente/items/_direcciones.php @@ -62,7 +62,91 @@ -
+
+ +
+
+ +
+
+

Dirección de envío ferro/prototipo

+
+ + +
+ +
+ + +
+ +
+ +
+
+ + +
+
+
+ + +
+
+
+ +
+ +
+
+ +
+
+

Dirección de envío ferro/prototipo 2

+
+ +
+
+ + +
+ +
+ +
+
+ +
+
+
+ + +
+
+
+ +
+
+
+ + +
+
+
+ +
diff --git a/ci4/app/Views/themes/vuexy/form/presupuestos/cliente/items/_disenioCubierta.php b/ci4/app/Views/themes/vuexy/form/presupuestos/cliente/items/_disenioCubierta.php index 30729a8a..4f62b196 100755 --- a/ci4/app/Views/themes/vuexy/form/presupuestos/cliente/items/_disenioCubierta.php +++ b/ci4/app/Views/themes/vuexy/form/presupuestos/cliente/items/_disenioCubierta.php @@ -200,7 +200,7 @@
-
@@ -211,7 +211,7 @@ -
@@ -251,7 +251,7 @@
-
@@ -262,7 +262,7 @@ -
diff --git a/httpdocs/assets/js/safekat/components/ajax.js b/httpdocs/assets/js/safekat/components/ajax.js index 9e8be0bc..8a92c701 100644 --- a/httpdocs/assets/js/safekat/components/ajax.js +++ b/httpdocs/assets/js/safekat/components/ajax.js @@ -1,24 +1,24 @@ -class Ajax{ - constructor(url, data, headers, success, error, type='default'){ - this.url = url; - this.data = data; - this.headers = headers; - this.success = success; - this.error = error; - this.type = type; - this.jqXHR = null; - } - post(){ - (this.type == 'default') ? this.ajax('POST'): this.ajaxForm('POST'); +class Ajax { + constructor(url, data, headers, success, error, type = 'default') { + this.url = url; + this.data = data; + this.headers = headers; + this.success = success; + this.error = error; + this.type = type; + this.jqXHR = null; } - get(){ + post() { + (this.type == 'default') ? this.ajax('POST') : this.ajaxForm('POST'); + } + get() { this.ajax('GET'); } - put(){ - (this.type == 'default') ? this.ajax('PUT'): this.ajaxForm('PUT'); + put() { + (this.type == 'default') ? this.ajax('PUT') : this.ajaxForm('PUT'); } - delete(){ - (this.type == 'default') ? this.ajax('DELETE'): this.ajaxForm('DELETE'); + delete() { + (this.type == 'default') ? this.ajax('DELETE') : this.ajaxForm('DELETE'); } abort() { if (this.jqXHR) { @@ -26,31 +26,31 @@ class Ajax{ this.jqXHR = null; // Limpiamos la referencia a la petición } } - setData(data){ + setData(data) { this.data = data; } - ajax(method){ + ajax(method) { if (this.jqXHR) { this.jqXHR.abort(); } this.jqXHR = $.ajax({ - url : this.url, - type : method, + url: this.url, + type: method, data: this.data, headers: this.headers, success: this.success, error: this.error }) } - ajaxForm(method){ + ajaxForm(method) { if (this.jqXHR) { this.jqXHR.abort(); } this.jqXHR = $.ajax({ - url : this.url, - type : method, + url: this.url, + type: method, data: this.data, processData: false, contentType: false, @@ -59,6 +59,28 @@ class Ajax{ error: this.error }) } + getPromise() { + if (this.jqXHR) { + this.jqXHR.abort(); + } + + return new Promise((resolve, reject) => { + this.jqXHR = $.ajax({ + url: this.url, + type: 'GET', + data: this.data, + headers: this.headers, + success: (response) => { + if (this.success) this.success(response); + resolve(response); + }, + error: (xhr) => { + if (this.error) this.error(xhr); + reject(xhr); + } + }); + }); + } } export default Ajax \ No newline at end of file diff --git a/httpdocs/assets/js/safekat/components/configVariableDatatable.js b/httpdocs/assets/js/safekat/components/configVariableDatatable.js index ade81e35..c1534967 100644 --- a/httpdocs/assets/js/safekat/components/configVariableDatatable.js +++ b/httpdocs/assets/js/safekat/components/configVariableDatatable.js @@ -17,9 +17,10 @@ class ConfigVariableDatatable init(){ this.datatable = this.datatableItem.DataTable({ processing: true, - dom: 'Brtip', + dom: 'Blrtip', serverSide: true, - + lengthMenu: [ 25, 50, 100, 200 ], + pageLength: 50, language: { url: "/themes/vuexy/vendor/libs/datatables-sk/plugins/i18n/es-ES.json" }, diff --git a/httpdocs/assets/js/safekat/components/tarjetaDireccionPresupuesto.js b/httpdocs/assets/js/safekat/components/tarjetaDireccionPresupuesto.js index 7c555773..96763d04 100644 --- a/httpdocs/assets/js/safekat/components/tarjetaDireccionPresupuesto.js +++ b/httpdocs/assets/js/safekat/components/tarjetaDireccionPresupuesto.js @@ -1,14 +1,17 @@ class tarjetaDireccion { - constructor(container, id, direccion) { + constructor(container, id, direccion, isFerroPrototipo = false, numFerro = 0) { this.container = container; this.id = id; this.direccionId = direccion.id; + this.direccion = direccion; + this.isFerroPrototipo = isFerroPrototipo; + this.numFerro = numFerro || 0; this.card = this.#generateHTML(id, direccion); this.deleteBtn = this.card.find('.direccion-eliminar'); this.editBtn = this.card.find('.direccion-editar'); - this.direccion = direccion; + } @@ -38,7 +41,13 @@ class tarjetaDireccion { var $hr = $('
', { class: 'my-2' }); var $eliminar = $('', { class: 'ms-auto direccion-eliminar', href: 'javascript:void(0)', text: 'Eliminar' }); var $editar = $('', { class: 'me-auto direccion-editar', href: 'javascript:void(0)', text: 'Editar' }); - var $eliminarContainer = $('', { class: 'd-flex w-100 position-relative' }).append($editar, $eliminar); + var $eliminarContainer = ''; + if(!this.isFerroPrototipo) { + $eliminarContainer = $('', { class: 'd-flex w-100 position-relative' }).append($editar, $eliminar); + } + else{ + $eliminarContainer = $('', { class: 'd-flex w-100 position-relative' }).append($eliminar); + } // Construir la estructura del HTML $header.append($name, $unidades); @@ -109,6 +118,13 @@ class tarjetaDireccion { entregaPalets: this.getEntregaPalets() }; } + + getIsFerroPrototipo() { + return this.isFerroPrototipo; + } + getNumFerro() { + return this.numFerro; + } } export default tarjetaDireccion; \ No newline at end of file diff --git a/httpdocs/assets/js/safekat/pages/presupuestoAdmin/sections/comparador.js b/httpdocs/assets/js/safekat/pages/presupuestoAdmin/sections/comparador.js index e8def6b4..8e95d906 100644 --- a/httpdocs/assets/js/safekat/pages/presupuestoAdmin/sections/comparador.js +++ b/httpdocs/assets/js/safekat/pages/presupuestoAdmin/sections/comparador.js @@ -365,6 +365,7 @@ class Comparador { popErrorAlert(window.language.Presupuestos.errores.error_sobrecubierta_sin_solapas, 'divAlarmasComparador') }*/ $('#solapas_sobrecubierta').prop('checked', true); + $('#solapas_sobrecubierta').trigger('change'); $('#div_solapas_ancho_sobrecubierta').removeClass('d-none'); $('#solapas_ancho_sobrecubierta').val(60); $('#compPapelSobrecubierta').prop('disabled', false); @@ -373,6 +374,8 @@ class Comparador { else { this.papelSobrecubierta.setVal(0); this.gramajeSobrecubierta.setVal(0); + $('#solapas_sobrecubierta').prop('checked', false); + $('#solapas_sobrecubierta').trigger('change') $('#compPapelSobrecubierta').prop('disabled', true); $('#compGramajeSobrecubierta').prop('disabled', true); @@ -387,6 +390,7 @@ class Comparador { popErrorAlert(window.language.Presupuestos.errores.error_faja_sin_solapas, 'divAlarmasComparador'); } $('#faja').prop('checked', true); + $('#faja').trigger('change'); $('.faja-div').removeClass('d-none'); $('#compPapelFaja').prop('disabled', false); $('#compGramajeFaja').prop('disabled', false); @@ -394,6 +398,8 @@ class Comparador { else { this.papelFaja.setVal(0); this.gramajeFaja.setVal(0); + $('#faja').prop('checked', false); + $('#faja').trigger('change'); $('#compPapelFaja').prop('disabled', true); $('#compGramajeFaja').prop('disabled', true); } diff --git a/httpdocs/assets/js/safekat/pages/presupuestoCliente/datosGenerales.js b/httpdocs/assets/js/safekat/pages/presupuestoCliente/datosGenerales.js index fee7ab5d..07254345 100644 --- a/httpdocs/assets/js/safekat/pages/presupuestoCliente/datosGenerales.js +++ b/httpdocs/assets/js/safekat/pages/presupuestoCliente/datosGenerales.js @@ -103,9 +103,44 @@ class DatosGenerales { this.pagColorConsecutivas.on('change', this.#handPaginasConsecutivas.bind(this)); this.papelDiferente.on('change', this.#handlePapelDiferente.bind(this)); + // check ferro y prototipo + this.domItem.on('change', 'input[type="checkbox"][data-tarifa-extra-excluyente="1"]', (e) => { + if (!this.cargando) { + const current = $(e.target); + + if (current.is(':checked')) { + this.domItem.find('input[type="checkbox"][data-tarifa-extra-excluyente="1"]') + .not(current) + .prop('checked', false); + + if ((current.data('tarifa-nombre')?.toString().toLowerCase() || '').includes('2')) { + $('#direccionesFerroPrototipo2').removeClass('d-none'); + } + $('#direccionesFerroPrototipo').removeClass('d-none'); + } + else { + if (this.domItem.find('input[type="checkbox"][data-tarifa-extra-excluyente="1"]').prop('checked').length === 0) { + + $('#direccionesFerroPrototipo').addClass('d-none'); + $('#divDireccionesFerroPrototipo').empty(); + $('#direccionesFerroPrototipo2').addClass('d-none'); + $('#divDireccionesFerroPrototipo2').empty(); + } + } + } + }); + + + $('.tirada-presupuesto').on('change', () => { - - self.validate(false); + + if (this.validateTiradas()) { + this.removeError(window.translations["validation"].tirada_integer_greatherThan_0); + this.removeError(window.translations["validation"].tirada_pod_nopod); + } + else { + this.addErrors(); + } let tiradas = self.getTiradas(); if (!Array.isArray(tiradas)) { tiradas = [tiradas]; @@ -120,7 +155,24 @@ class DatosGenerales { this.anchoPersonalizado.on("change", this.#checkValue.bind(this)); this.altoPersonalizado.on("change", this.#checkValue.bind(this)); - this.titulo.on('change', () => { $(".titulo").html(this.titulo.val()); }); + this.titulo.on('change', () => { + $(".titulo").html(this.titulo.val()); + if (this.validateTitulo()) { + this.removeError(window.translations["validation"].titulo_requerido); + } + else { + this.addErrors(); + } + }); + + this.cliente.item.on('change', () => { + if (this.validateCliente()) { + this.removeError(window.translations["validation"].cliente); + } + else { + this.addErrors(); + } + }); this.retractilado.on('change', this.#eventRetractilado.bind(this)); this.retractilado5.on('change', this.#eventRetractilado.bind(this)); @@ -132,60 +184,114 @@ class DatosGenerales { this.errores = []; // Titulo - if (this.titulo.val().trim() === '') { - this.errores.push(window.translations["validation"].titulo_requerido); - this.titulo.addClass('is-invalid'); - } else { - this.titulo.removeClass('is-invalid'); - } + this.validateTitulo(); // Cliente - if ($(this.excluirRotativa).prop('hidden')) { - if ($('#clienteId').val() === null || $('#clienteId').val().length === 0) { - this.errores.push(window.translations["validation"].cliente); - $('#clienteId').addClass('is-invalid'); - } else { - $('#clienteId').removeClass('is-invalid'); - } - } else { - if (this.cliente.getVal() <= 0) { - this.errores.push(window.translations["validation"].cliente); - this.cliente.item.addClass('is-invalid'); - } else { - this.cliente.item.removeClass('is-invalid'); - } - } + this.validateCliente(); // Tirada - let tiradas = this.getTiradas(); - if (tiradas.length === 0 || tiradas.some(tirada => - !Number.isInteger(tirada) || - parseInt(tirada) <= 0 || - tirada == "")) { - - this.errores.push(window.translations["validation"].tirada_integer_greatherThan_0); - this.tirada1.addClass('is-invalid'); - - } else { - this.tirada1.removeClass('is-invalid'); - // Comprobar tiradas POD - const noPOD = tiradas.some(tirada => parseInt(tirada) > 30); - const siPOD = tiradas.some(tirada => parseInt(tirada) <= 30); - if (noPOD && siPOD) { - this.errores.push(window.translations["validation"].tirada_pod_nopod); - this.tirada1.addClass('is-invalid'); - } - else { - this.tirada1.removeClass('is-invalid'); - } - } + this.validateTiradas(); // formato libro + this.validateFormatoLibro(); + + // Paginas + this.validatePaginas(); + + // Tipo de libro + this.validateTipoLibro(); + + this.addErrors(); + + if (this.errores.length > 0) { + + return false; + } + else { + if (goToNext) + this.validatorStepper.next(); + else + return true; + } + } + + validateTipoLibro() { + + let noError = true; + + if ($('.tipo-libro.selected').length > 0) { + if ($('#cosido').hasClass('selected') || $('#grapado').hasClass('selected')) { + const value = parseInt($("#paginas").val()); + if (value % 4 != 0) { + if (parseInt(this.paginas.val()) % 4 != 0) { + this.errores.push(window.translations["validation"].paginas_multiplo_4); + this.paginas.addClass('is-invalid'); + noError = false; + } else { + this.paginas.removeClass('is-invalid'); + } + } + } + this.domItem.find('#divTipoLibro').removeClass('is-invalid'); + } else { + this.errores.push(window.translations["validation"].tipo_libro); + this.domItem.find('#divTipoLibro').addClass('is-invalid'); + noError = false; + } + + return noError; + } + + validatePaginas() { + + let noError = true; + + if (this.paginasColor.val() == '' || isNaN(this.paginasColor.val()) || parseInt(this.paginasColor.val()) < 0) { + this.errores.push(window.translations["validation"].paginasColor); + this.paginasColor.addClass('is-invalid'); + noError = false; + } + else if (parseInt(this.paginasColor.val()) % 2 != 0) { + this.errores.push(window.translations["validation"].paginas_pares); + this.paginasColor.addClass('is-invalid'); + noError = false; + } + else { + this.paginasColor.removeClass('is-invalid'); + } + if (this.paginasNegro.val() == '' || isNaN(this.paginasNegro.val()) || parseInt(this.paginasNegro.val()) < 0) { + this.errores.push(window.translations["validation"].paginasNegro); + this.paginasNegro.addClass('is-invalid'); + noError = false; + } + else if (parseInt(this.paginasNegro.val()) % 2 != 0) { + this.errores.push(window.translations["validation"].paginas_pares); + this.paginasNegro.addClass('is-invalid'); + noError = false; + } + else { + this.paginasNegro.removeClass('is-invalid'); + } + if (this.paginas.val() == '' || isNaN(this.paginas.val()) || parseInt(this.paginas.val()) <= 0) { + this.errores.push(window.translations["validation"].paginas); + this.paginas.addClass('is-invalid'); + noError = false; + } else { + this.paginas.removeClass('is-invalid'); + } + + return noError; + } + + validateFormatoLibro() { + + let noError = true; if (this.checkFormatoPersonalizado.is(':checked')) { if (this.anchoPersonalizado.val().length === 0 || isNaN(this.anchoPersonalizado.val()) || parseFloat(this.anchoPersonalizado.val()) <= 0) { this.errores.push(window.translations["validation"].papelFormatoAncho); this.anchoPersonalizado.addClass('is-invalid'); + noError = false; } else { this.anchoPersonalizado.removeClass('is-invalid'); } @@ -193,6 +299,7 @@ class DatosGenerales { parseFloat(this.altoPersonalizado.val()) <= 0) { this.errores.push(window.translations["validation"].papelFormatoAlto); this.altoPersonalizado.addClass('is-invalid'); + noError = false; } else { this.altoPersonalizado.removeClass('is-invalid'); } @@ -204,78 +311,73 @@ class DatosGenerales { } else { this.errores.push(window.translations["validation"].papelFormato); this.papelFormatoId.addClass('is-invalid'); + noError = false; } } + return noError; + } - // Paginas - if (this.paginasColor.val() == '' || isNaN(this.paginasColor.val()) || parseInt(this.paginasColor.val()) < 0) { - this.errores.push(window.translations["validation"].paginasColor); - this.paginasColor.addClass('is-invalid'); - } - else if (parseInt(this.paginasColor.val()) % 2 != 0) { - this.errores.push(window.translations["validation"].paginas_pares); - this.paginasColor.addClass('is-invalid'); - } - else { - this.paginasColor.removeClass('is-invalid'); - } - if (this.paginasNegro.val() == '' || isNaN(this.paginasNegro.val()) || parseInt(this.paginasNegro.val()) < 0) { - this.errores.push(window.translations["validation"].paginasNegro); - this.paginasNegro.addClass('is-invalid'); - } - else if (parseInt(this.paginasNegro.val()) % 2 != 0) { - this.errores.push(window.translations["validation"].paginas_pares); - this.paginasNegro.addClass('is-invalid'); - } - else { - this.paginasNegro.removeClass('is-invalid'); - } - if (this.paginas.val() == '' || isNaN(this.paginas.val()) || parseInt(this.paginas.val()) <= 0) { - this.errores.push(window.translations["validation"].paginas); - this.paginas.addClass('is-invalid'); - } else { - this.paginas.removeClass('is-invalid'); - } + validateTiradas() { - // Tipo de libro - if ($('.tipo-libro.selected').length > 0) { - if ($('#cosido').hasClass('selected') || $('#grapado').hasClass('selected')) { - const value = parseInt($("#paginas").val()); - if (value % 4 != 0) { - if (parseInt(this.paginas.val()) % 4 != 0) { - this.errores.push(window.translations["validation"].paginas_multiplo_4); - this.paginas.addClass('is-invalid'); - } else { - this.paginas.removeClass('is-invalid'); - } - } - } - this.domItem.find('#divTipoLibro').removeClass('is-invalid'); - } else { - this.errores.push(window.translations["validation"].tipo_libro); - this.domItem.find('#divTipoLibro').addClass('is-invalid'); - } + let tiradas = this.getTiradas(); + if (tiradas.length === 0 || tiradas.some(tirada => + !Number.isInteger(tirada) || + parseInt(tirada) <= 0 || + tirada == "")) { - const skAlert = document.getElementById('sk-alert'); - skAlert.innerHTML = ''; - const uniqueErrors = [...new Set(this.errores)]; - - if (uniqueErrors.length > 0) { - const message = window.translations["validation"].fix_errors + - `
    - ${uniqueErrors.map(err => `
  • ${err}
  • `).join('')} -
`; - popErrorAlert(message, 'sk-alert', false); - this.errores = []; + this.errores.push(window.translations["validation"].tirada_integer_greatherThan_0); + this.tirada1.addClass('is-invalid'); return false; - } - else { - document.getElementById('sk-alert').innerHTML = ''; - this.errores = []; - if (goToNext) - this.validatorStepper.next(); - else + + } else { + this.tirada1.removeClass('is-invalid'); + // Comprobar tiradas POD + const noPOD = tiradas.some(tirada => parseInt(tirada) > 30); + const siPOD = tiradas.some(tirada => parseInt(tirada) <= 30); + if (noPOD && siPOD) { + this.errores.push(window.translations["validation"].tirada_pod_nopod); + this.tirada1.addClass('is-invalid'); + return false; + } + else { + this.tirada1.removeClass('is-invalid'); return true; + } + } + } + + validateCliente() { + + if ($(this.excluirRotativa).prop('hidden')) { + if ($('#clienteId').val() === null || $('#clienteId').val().length === 0) { + this.errores.push(window.translations["validation"].cliente); + $('#clienteId').addClass('is-invalid'); + return false; + } else { + $('#clienteId').removeClass('is-invalid'); + return true; + } + } else { + if (this.cliente.getVal() <= 0) { + this.errores.push(window.translations["validation"].cliente); + this.cliente.item.addClass('is-invalid'); + return false; + } else { + this.cliente.item.removeClass('is-invalid'); + return true; + } + } + } + + validateTitulo() { + + if (this.titulo.val().trim() === '') { + this.errores.push(window.translations["validation"].titulo_requerido); + this.titulo.addClass('is-invalid'); + return false; + } else { + this.titulo.removeClass('is-invalid'); + return true; } } @@ -570,8 +672,11 @@ class DatosGenerales { this.formatoEstandar.removeClass('d-none'); this.formatoPersonalizado.addClass('d-none'); } - const alto = this.getDimensionLibro().alto; - $('#altoFaja').closest('.config-faja').find('.form-text').text('Entre 50 y ' + alto + ' mm'); + const dimensionLibro = this.getDimensionLibro(); + if (dimensionLibro && dimensionLibro.alto) { + + $('#altoFaja').closest('.config-faja').find('.form-text').text('Entre 50 y ' + dimensionLibro.alto + ' mm'); + } } #checkValue(event) { @@ -579,6 +684,13 @@ class DatosGenerales { if (target.value < target.min) { target.value = target.min; } + if (this.validateFormatoLibro()) { + this.removeError(window.translations["validation"].papelFormatoAncho); + this.removeError(window.translations["validation"].papelFormatoAlto); + } + else { + this.addErrors(); + } } #eventRetractilado(event) { @@ -597,6 +709,7 @@ class DatosGenerales { #handleTipolibro(event) { + // Accede al ID del elemento que disparó el evento const element = $(event.target); @@ -631,7 +744,7 @@ class DatosGenerales { $('#addSobrecubierta').prop('checked', false).trigger('change'); $(".sobrecubierta-items").addClass('d-none'); - if (this.grapado.hasClass('selected')){ + if (this.grapado.hasClass('selected')) { $("#tapaBlanda").addClass('selected'); $("#tapaBlanda").removeClass('d-none'); @@ -647,7 +760,13 @@ class DatosGenerales { } } - this.validate(false); + if (this.validateTipoLibro()) { + this.removeError(window.translations["validation"].tipo_libro); + this.removeError(window.translations["validation"].paginas_multiplo_4); + } + else { + this.addErrors(); + } // Para recalcular el presupuesto $('#paginas').trigger('change'); @@ -692,7 +811,7 @@ class DatosGenerales { this.domItem.find('#grapado').show(); } - if( totalPaginas < 20){ + if (totalPaginas < 20) { this.domItem.find('#espiral').removeClass('selected'); this.domItem.find('#espiral').find('.image-presupuesto').removeClass('selected'); this.domItem.find('#espiral').hide(); @@ -740,6 +859,15 @@ class DatosGenerales { } $('.calcular-lomo').trigger('change'); + if (this.validatePaginas()) { + this.removeError(window.translations["validation"].paginas); + this.removeError(window.translations["validation"].paginasColor); + this.removeError(window.translations["validation"].paginasNegro); + this.removeError(window.translations["validation"].paginas_pares); + } + else { + this.addErrors(); + } } @@ -829,6 +957,38 @@ class DatosGenerales { return servicios; } + removeError(error) { + const hasError = this.errores.filter(err => err === error).length > 0; + if (hasError) { + // remove the item from this.errores + this.errores = this.errores.filter(err => err !== error); + } + if (this.errores.length == 0) { + document.getElementById('sk-alert').innerHTML = ''; + } + else { + document.getElementById('sk-alert').innerHTML = document.getElementById('sk-alert').innerHTML + .replace(`
  • ${error}
  • `, '').replace(error, ''); + } + } + + addErrors() { + + const skAlert = document.getElementById('sk-alert'); + skAlert.innerHTML = ''; + this.errores = [...new Set(this.errores)]; + + if (this.errores.length > 0) { + const message = window.translations["validation"].fix_errors + + `
      + ${this.errores.map(err => `
    • ${err}
    • `).join('')} +
    `; + popErrorAlert(message, 'sk-alert', false); + } + else { + skAlert.innerHTML = ''; + } + } } diff --git a/httpdocs/assets/js/safekat/pages/presupuestoCliente/direcciones.js b/httpdocs/assets/js/safekat/pages/presupuestoCliente/direcciones.js index 9720cd8c..ca4a2d74 100644 --- a/httpdocs/assets/js/safekat/pages/presupuestoCliente/direcciones.js +++ b/httpdocs/assets/js/safekat/pages/presupuestoCliente/direcciones.js @@ -22,13 +22,21 @@ class Direcciones { this.entregaPieCallero = this.domItem.find('#entregaPieCalle'); this.direccionesCliente = new ClassSelect($("#direcciones"), '/misdirecciones/getSelect2'); + this.direccionesClienteFP1 = new ClassSelect($("#direccionesFP1"), '/misdirecciones/getSelect2'); + this.direccionesClienteFP2 = new ClassSelect($("#direccionesFP2"), '/misdirecciones/getSelect2'); this.divDirecciones = $(this.domItem.find('#divDirecciones')); this.divTiradas = this.domItem.find('#containerTiradasEnvios'); + this.sameAddPrincipalFP1 = this.domItem.find('#sameAddPrincipalFP1'); + this.sameAddPrincipalFP2 = this.domItem.find('#sameAddPrincipalFP2'); + this.sameAddFP1 = this.domItem.find('#sameAddFP1'); + this.checksTiradasEnvio = $('.check-tirada-envio'); this.direcciones = []; + this.direccionesFP1 = []; + this.direccionesFP2 = []; this.tiradaSeleccionada = null; @@ -57,9 +65,18 @@ class Direcciones { this.direccionesCliente.init(); + this.direccionesClienteFP1.init(); + this.direccionesClienteFP2.init(); this.btnAdd.on('click', this.#insertDireccion.bind(this)); this.btnNew.on('click', this.#nuevaDireccion.bind(this)); + $('#insertarDireccionFP1').on('click', () => { + this.#insertDireccionFP(1); + }); + $('#insertarDireccionFP2').on('click', () => { + this.#insertDireccionFP(2); + }); + // evento para actualizar el selector de tiradas $(document).on('update-tiradas-envios', (event, data) => { self.divTiradas.empty(); @@ -80,9 +97,14 @@ class Direcciones { self.divTiradas.trigger('change'); } }); + + this.sameAddPrincipalFP1.on('change', this.#handleSameAddPrincipalFP1.bind(this)); + this.sameAddPrincipalFP2.on('change', this.#handleSameAddPrincipalFP2.bind(this)); + this.sameAddFP1.on('change', this.#handleSameAddFP1.bind(this)); } + cargarDatos(datos, datosGenerales) { self = this; @@ -150,29 +172,6 @@ class Direcciones { tarjeta.card.find('.direccion-eliminar').on('click', this.#deleteDireccion.bind(self)); this.divDirecciones.append(tarjeta.card); this.direcciones.push(tarjeta); - - /*let peticion = new Ajax('/misdirecciones/getDireccionPresupuesto/' + id, {}, {}, - (response) => { - let divId = "dirEnvio-1"; - let direccionesActuales = this.divDirecciones.find('.direccion-cliente'); - if (direccionesActuales.length > 0) { - // the the lass item - let last = direccionesActuales[direccionesActuales.length - 1]; - divId = "dirEnvio-" + (parseInt(last.id.split('-')[1]) + 1); - } - let tarjeta = new tarjetaDireccion(this.divDirecciones, divId, response.data[0]); - tarjeta.setUnidades(unidades); - tarjeta.setEntregaPalets(entregaPalets); - tarjeta.card.find('.direccion-editar').on('click', this.#editUnits.bind(self)); - tarjeta.card.find('.direccion-eliminar').on('click', this.#deleteDireccion.bind(self)); - this.divDirecciones.append(tarjeta.card); - this.direcciones.push(tarjeta); - }, - () => { - console.error('Error getting address'); - }); - - peticion.get();*/ } } } catch (e) { @@ -223,72 +222,6 @@ class Direcciones { } } - initValidation() { - - const stepper = this.validatorStepper; - - this.formValidation = FormValidation.formValidation(this.wizardStep, { - fields: { - div_error_envios: { - validators: { - callback: { - callback: () => { - - - div.find('.fv-plugins-message-container').remove(); - - if ($('.check-tirada-envio:checked').length > 0) { - let unidades = parseInt($($('.check-tirada-envio:checked')[0]).attr('tirada')); - let total_envio = 0; - // se recorre el array this.direcciones - this.direcciones.forEach(direccion => { - total_envio += parseInt(direccion.getUnidades()); - }); - if (total_envio <= unidades) { - return true; - } - } - - div.append(` -
    -
    - El total de unidades enviadas no puede ser mayor que la tirada seleccionada -
    -
    - `); - return false; - }, - } - - } - } - }, - plugins: { - trigger: new FormValidation.plugins.Trigger(), - bootstrap5: new FormValidation.plugins.Bootstrap5({ - // Use this for enabling/changing valid/invalid class - // eleInvalidClass: '', - eleValidClass: '', - rowSelector: function (field, ele) { - // field is the field name - // ele is the field element - switch (field) { - case 'div_error_envios': - return '.col-sm-10'; - default: - return '.col-sm-3'; - } - } - }), - autoFocus: new FormValidation.plugins.AutoFocus(), - submitButton: new FormValidation.plugins.SubmitButton() - } - }).on('core.form.valid', () => { - if (this.allowNext) - stepper.next(); - }); - } - insertTirada(tirada) { @@ -408,47 +341,116 @@ class Direcciones { return; } } + this.#addTarjetaDireccion(this.divDirecciones, this.direcciones, divId, id, unidades, entregaPalets); - $('#loader').modal('show'); - let peticion = new Ajax('/misdirecciones/get/' + id, {}, {}, - (response) => { - - if (this.direcciones.length == 0) { - $('#loader').modal('hide'); - if (entregaPalets) { - this.calcularPresupuesto = true; - } - } - else { - this.calcularPresupuesto = true; - } - let tarjeta = new tarjetaDireccion(this.divDirecciones, divId, response.data[0]); - tarjeta.setUnidades(unidades); - tarjeta.setEntregaPalets(entregaPalets); - tarjeta.card.find('.direccion-editar').on('click', this.#editUnits.bind(self)); - tarjeta.card.find('.direccion-eliminar').on('click', this.#deleteDireccion.bind(self)); - this.divDirecciones.append(tarjeta.card); - this.direcciones.push(tarjeta); - self.divDirecciones.trigger('change'); - - }, - () => { - console.error('Error getting address'); - $('#loader').modal('hide'); - }); - - peticion.get(); } catch (e) { console.error(e); $('#loader').modal('hide'); } } + #insertDireccionFP(num_ferroPrototipo) { + + self = this; + + try { + + let id = 0; + if( num_ferroPrototipo === 1) { + id = this.direccionesClienteFP1.getVal(); + } + if( num_ferroPrototipo === 2) { + id = this.direccionesClienteFP2.getVal(); + } + let unidades = 1; + + if (id == null || id <= 0 || id == undefined) + return; + + let divId = "dirEnvio-FP-" + num_ferroPrototipo; + let containerId = num_ferroPrototipo === 1 ? "#divDireccionesFerroPrototipo" : "#divDireccionesFerroPrototipo2"; + let arrayName = num_ferroPrototipo === 1 ? this.direccionesFP1 : this.direccionesFP2; + + this.#addTarjetaDireccion( + $(containerId), + arrayName, + divId, + id, + 1, false, true, num_ferroPrototipo); + + $('.div-direcciones-fp' + num_ferroPrototipo).addClass('d-none'); + + } catch (e) { + console.error(e); + $('#loader').modal('hide'); + } + } + + async #addTarjetaDireccion(container, addArray, divId, data, unidades, entregaPalets = false, isFerroPrototipo = false, numFerroPrototipo = 0) { + const self = this; + + let id = data; + + try { + if (typeof data === 'object') { + const ajaxGetId = new Ajax('/misdirecciones/getId', { + data: data, + cliente_id: $("#clienteId").select2('data')[0].id + }, {}, null, null); + const response = await ajaxGetId.getPromise(); + id = response; + } + + $('#loader').modal('show'); + + const ajaxGetDireccion = new Ajax('/misdirecciones/get/' + id, {}, {}, null, null); + const response = await ajaxGetDireccion.getPromise(); + + if (this.direcciones.length === 0) { + $('#loader').modal('hide'); + if (entregaPalets) { + this.calcularPresupuesto = true; + } + } else { + this.calcularPresupuesto = true; + } + + const tarjeta = new tarjetaDireccion(container, divId, response.data[0], isFerroPrototipo, numFerroPrototipo); + tarjeta.setUnidades(unidades); + tarjeta.setEntregaPalets(entregaPalets); + + if (!isFerroPrototipo) { + tarjeta.card.find('.direccion-eliminar').on('click', this.#deleteDireccion.bind(self)); + tarjeta.card.find('.direccion-editar').on('click', this.#editUnits.bind(self)); + } + else { + tarjeta.card.find('.direccion-eliminar').on('click', (event) => { + this.#deleteDireccionFP(event, numFerroPrototipo); + $('.div-direcciones-fp' + numFerroPrototipo).removeClass('d-none'); + }); + } + container.append(tarjeta.card); + addArray.push(tarjeta); + container.trigger('change'); + + } catch (err) { + console.error('Error en petición Ajax:', err); + $('#loader').modal('hide'); + } + } + + + + handleChangeCliente() { this.direccionesCliente.setParams({ 'cliente_id': $("#clienteId").select2('data')[0].id }) this.direccionesCliente.empty(); + this.direccionesClienteFP1.setParams({ 'cliente_id': $("#clienteId").select2('data')[0].id }) + this.direccionesClienteFP1.empty(); + this.direccionesClienteFP2.setParams({ 'cliente_id': $("#clienteId").select2('data')[0].id }) + this.direccionesClienteFP2.empty(); this.domItem.find('.direccion-cliente').remove(); this.direcciones = []; @@ -500,6 +502,124 @@ class Direcciones { this.divDirecciones.trigger('change'); } + #deleteDireccionFP(event, num_ferroPrototipo = 1) { + + let tarjeta = event.currentTarget.closest('.direccion-cliente'); + + this.calcularPresupuesto = true; + + if (num_ferroPrototipo === 1) { + this.direccionesFP1 = []; + this.sameAddPrincipalFP1.prop('checked', false); + $('#divDireccionesFerroPrototipo1').trigger('change'); + } + if (num_ferroPrototipo === 2) { + this.direccionesFP2 = []; + this.sameAddPrincipalFP2.prop('checked', false); + this.sameAddFP1.prop('checked', false); + $('#divDireccionesFerroPrototipo2').trigger('change'); + } + + tarjeta.remove(); + } + + #handleSameAddPrincipalFP1() { + + if (this.sameAddPrincipalFP1.is(':checked')) { + $('.div-direcciones-fp1').addClass('d-none'); + $('#divDireccionesFerroPrototipo').empty(); + if (this.direcciones.length > 0) { + // get first element + let data = this.direcciones[0].getDireccion(); + + this.direccionesFP1 = []; + this.#addTarjetaDireccion( + $("#divDireccionesFerroPrototipo"), + this.direccionesFP1, + 'dirEnvio-FP-1', + data, + 1, false, true, 1); + $('#divDireccionesFerroPrototipo').removeClass('d-none'); + } + else { + // mostrar alerta de que no hay direcciones + } + + } + else { + $('.div-direcciones-fp1').removeClass('d-none'); + $('#divDireccionesFerroPrototipo').removeClass('d-none'); + $('#divDireccionesFerroPrototipo').empty(); + } + } + + #handleSameAddPrincipalFP2() { + + if (this.sameAddPrincipalFP2.is(':checked')) { + if(this.sameAddFP1.is(':checked')) { + this.sameAddFP1.prop('checked', false); + } + $('.div-direcciones-fp2').addClass('d-none'); + $('#divDireccionesFerroPrototipo2').empty(); + if (this.direcciones.length > 0) { + + let data = this.direcciones[0].getDireccion(); + this.direccionesFP2 = []; + this.#addTarjetaDireccion( + $("#divDireccionesFerroPrototipo2"), + this.direccionesFP2, + 'dirEnvio-FP-2', + data, + 1, false, true, 2); + $('#divDireccionesFerroPrototipo2').removeClass('d-none'); + } + else { + // mostrar alerta de que no hay direcciones + } + + } + else { + $('.div-direcciones-fp2').removeClass('d-none'); + $('#divDireccionesFerroPrototipo2').removeClass('d-none'); + $('#divDireccionesFerroPrototipo2').empty(); + } + } + + #handleSameAddFP1() { + + if (this.sameAddFP1.is(':checked')) { + if(this.sameAddPrincipalFP2.is(':checked')) { + this.sameAddPrincipalFP2.prop('checked', false); + } + $('.div-direcciones-fp2').addClass('d-none'); + $('#divDireccionesFerroPrototipo2').empty(); + if (this.direccionesFP1.length > 0) { + + let data = this.direccionesFP1[0].getDireccion(); + + this.direccionesFP1 = []; + this.#addTarjetaDireccion( + $("#divDireccionesFerroPrototipo2"), + this.direccionesFP2, + 'dirEnvio-FP-2', + data, + 1, false, true, 2); + + $('#divDireccionesFerroPrototipo2').removeClass('d-none'); + } + else { + // mostrar alerta de que no hay direcciones + } + + } + else { + $('.div-direcciones-fp2').removeClass('d-none'); + $('#divDireccionesFerroPrototipo2').removeClass('d-none'); + $('#divDireccionesFerroPrototipo2').empty(); + } + } + + getSelectedTirada() { if ($('.check-tirada-envio:checked').length > 0) return parseInt($($('.check-tirada-envio:checked')[0]).attr('tirada')); diff --git a/httpdocs/assets/js/safekat/pages/presupuestoCliente/disenioCubierta.js b/httpdocs/assets/js/safekat/pages/presupuestoCliente/disenioCubierta.js index 63da86b8..da6df22b 100644 --- a/httpdocs/assets/js/safekat/pages/presupuestoCliente/disenioCubierta.js +++ b/httpdocs/assets/js/safekat/pages/presupuestoCliente/disenioCubierta.js @@ -1,5 +1,4 @@ -import { getToken } from '../../common/common.js'; -import { capitalizeFirstLetter } from '../../common/common.js'; +import { capitalizeFirstLetter, getToken } from '../../common/common.js'; import Ajax from '../../components/ajax.js'; import ClassSelect from '../../components/select2.js'; @@ -265,6 +264,8 @@ class DisenioCubierta { this.presupuestoConfirmado = false; this.papelForResumen = ""; this.gramajeForResumen = ""; + + this.errores = []; } @@ -286,6 +287,15 @@ class DisenioCubierta { this.papelFaja.init(); this.gramajeFaja.init(); + this.acabadoCubierta.onChange(() => { + if (this.acabadoCubierta.getVal() > 0) { + $('#alert-cubierta-sin-acabado').addClass('d-none'); + } + else { + $('#alert-cubierta-sin-acabado').removeClass('d-none'); + } + }); + $('#papelEspecialCubiertaSel').on("change", this.#handlePapelCubiertaEspecial.bind(this)); // Eventos @@ -299,18 +309,54 @@ class DisenioCubierta { this.carasCubierta.on('change', this.#handleCarasCubierta.bind(this)); this.sobrecubierta.on('change', () => { - this.sobrecubierta.is(":checked") ? this.configuracionSobrecubierta.removeClass("d-none") : this.configuracionSobrecubierta.addClass("d-none") + + if (this.sobrecubierta.is(":checked")) { + + this.configuracionSobrecubierta.removeClass("d-none"); + if (this.papelSobrecubierta.getVal() && this.gramajeSobrecubierta.getVal()) { + $('#tirada').trigger('change'); // recalcular presupuesto + } + } + else { + this.configuracionSobrecubierta.addClass("d-none"); + $('#tirada').trigger('change'); // recalcular presupuesto + } } ); this.faja.on('change', () => { - this.faja.is(":checked") ? this.configuracionFaja.removeClass("d-none") : this.configuracionFaja.addClass("d-none"); + + if(this.faja.is(":checked")) { + this.configuracionFaja.removeClass("d-none"); + if (this.papelFaja.getVal() && this.gramajeFaja.getVal()) { + $('#tirada').trigger('change'); // recalcular presupuesto + } + } + else{ + this.configuracionFaja.addClass("d-none"); + $('#tirada').trigger('change'); // recalcular presupuesto + } const div = $('#divExtras'); // Selecciona el div div.find('.fv-plugins-message-container').remove(); }); - this.papelFaja.item.on('change', () => { this.gramajeFaja.empty(); }); + this.papelSobrecubierta.item.on('change', () => { + this.gramajeSobrecubierta.item.find('option').remove(); + this.gramajeSobrecubierta.item.val(null); + this.gramajeSobrecubierta.item.trigger('select2:clear'); + }); - this.papelGuardas.item.on('change', () => { this.gramajeGuardas.empty(); }); + this.papelFaja.item.on('change', () => { + this.gramajeFaja.item.find('option').remove(); + this.gramajeFaja.item.val(null); + this.gramajeFaja.item.trigger('select2:clear'); + }); + + this.papelGuardas.item.on('change', () => { + this.gramajeGuardas.item.find('option').remove(); + this.gramajeGuardas.item.val(null); + this.gramajeGuardas.item.trigger('select2:clear'); + + }); // Observadores this.observer.observe(this.tapaBlanda[0], { attributes: true }); @@ -318,6 +364,18 @@ class DisenioCubierta { this.observer.observe(this.tapaDuraLomoRedondo[0], { attributes: true }); this.observer.observe(this.conSolapas[0], { attributes: true }); this.observer.observe(this.sinSolapas[0], { attributes: true }); + + this.papelGuardas.onChange(() => { + if (self.validateTapaDuraOptions()) { + self.removeError(window.translations["validation"].papel_guardas) + } + }); + + this.gramajeGuardas.onChange(() => { + if (self.validateTapaDuraOptions()) { + self.removeError(window.translations["validation"].gramaje_guardas) + } + }); } @@ -394,106 +452,46 @@ class DisenioCubierta { validate(goToNext = true) { - let errores = []; + this.errores = []; let continueCheck = true; // diseño cubierta - $('#divTipoCubierta').removeClass('is-invalid'); - if ($('.tipo-cubierta.selected').length == 0) { - $('#divTipoCubierta').addClass('is-invalid'); - errores.push(window.translations["validation"].tipo_cubierta); - continueCheck = false; - } + continueCheck = this.validateDisenioCubierta(); // solapas cubierta - $('#divSolapasCubierta').removeClass('is-invalid'); - if (!$('#divSolapasCubierta').hasClass("d-none") && $('.solapas-cubierta.selected').length == 0 && continueCheck) { - $('#divSolapasCubierta').addClass('is-invalid'); - errores.push(window.translations["validation"].opcion_solapas); - } + this.validateSolapasCubierta(continueCheck); // opciones tapa dura y lomo redondo - $('#papelGuardas').removeClass('is-invalid'); - $('#gramajeGuardas').removeClass('is-invalid'); - if (!$('#divConfigTapaDura').hasClass('d-none') && continueCheck) { - if ($('#papelGuardas').select2('data').length == 0) { - $('#papelGuardas').addClass('is-invalid'); - errores.push(window.translations["validation"].papel_guardas); - } - if ($('#gramajeGuardas').select2('data').length == 0) { - $('#gramajeGuardas').addClass('is-invalid'); - errores.push(window.translations["validation"].gramaje_guardas); - } - } + this.validateTapaDuraOptions(continueCheck); // papel - $('#divPapelCubierta').removeClass('is-invalid'); - if ($('.custom-selector-papel-cubierta input[type="radio"]:checked').length == 0 && continueCheck) { - - $('#divPapelCubierta').addClass('is-invalid'); - errores.push(window.translations["validation"].papel_cubierta); - continueCheck = false; - } - else if (!$('#divPapelEspecialCubierta').hasClass("d-none")) { - if ($('#papelEspecialCubiertaSel').select2('data').length == 0 && continueCheck) { - $('#divPapelEspecialCubierta').addClass('is-invalid'); - errores.push(window.translations["validation"].papel_cubierta_especial); - continueCheck = false; - } - } + continueCheck = this.validatePapelCubierta(continueCheck); // gramaje - $('#divGramajeCubierta').removeClass('is-invalid'); - if ($('.custom-selector-gramaje-cubierta input[type="radio"]:checked').length == 0 && continueCheck) { - $('#divGramajeCubierta').addClass('is-invalid'); - errores.push(window.translations["validation"].gramaje_cubierta); - } + this.validateGramajeCubierta(continueCheck); // sobrecubierta - $('#papelSobrecubierta').removeClass('is-invalid'); - $('#gramajeSobrecubierta').removeClass('is-invalid'); - if ($("#addSobrecubierta").prop("checked") == true) { - if ($('#papelSobrecubierta').select2('data').length == 0) { - $('#papelSobrecubierta').addClass('is-invalid'); - errores.push(window.translations["validation"].papel_sobrecubierta); - } - if ($('#gramajeSobrecubierta').select2('data').length == 0) { - $('#gramajeSobrecubierta').addClass('is-invalid'); - errores.push(window.translations["validation"].gramaje_sobrecubierta); - } - } + this.validateSobrecubierta(); // faja - $('#papelFaja').removeClass('is-invalid'); - $('#gramajeFaja').removeClass('is-invalid'); - if ($("#addFaja").prop("checked") == true) { - if ($('#papelFaja').select2('data').length == 0) { - $('#papelFaja').addClass('is-invalid'); - errores.push(window.translations["validation"].papel_faja); - } - if ($('#gramajeFaja').select2('data').length == 0) { - $('#gramajeFaja').addClass('is-invalid'); - errores.push(window.translations["validation"].gramaje_faja); - } - } + this.validateFaja(); const skAlert = document.getElementById('sk-alert'); skAlert.innerHTML = ''; - const uniqueErrors = [...new Set(errores)]; + this.errores = [...new Set(this.errores)]; - if (uniqueErrors.length > 0) { + if (this.errores.length > 0) { const message = window.translations["validation"].fix_errors + `
      - ${uniqueErrors.map(err => `
    • ${err}
    • `).join('')} + ${this.errores.map(err => `
    • ${err}
    • `).join('')}
    `; popErrorAlert(message, 'sk-alert', false); - errores = []; return false; } else { document.getElementById('sk-alert').innerHTML = ''; - errores = []; + this.errores = []; if (goToNext) this.validatorStepper.next(); else @@ -502,6 +500,123 @@ class DisenioCubierta { } + validateDisenioCubierta() { + + $('#divTipoCubierta').removeClass('is-invalid'); + if ($('.tipo-cubierta.selected').length == 0) { + $('#divTipoCubierta').addClass('is-invalid'); + this.errores.push(window.translations["validation"].tipo_cubierta); + return false; + } + return true; + } + + validateSolapasCubierta(continueCheck = true) { + + $('#divSolapasCubierta').removeClass('is-invalid'); + if (!$('#divSolapasCubierta').hasClass("d-none") && $('.solapas-cubierta.selected').length == 0) { + $('#divSolapasCubierta').addClass('is-invalid'); + this.errores.push(window.translations["validation"].opcion_solapas); + return false; + } + return true; + } + + + validateTapaDuraOptions(continueCheck = true) { + + $('#papelGuardas').removeClass('is-invalid'); + $('#gramajeGuardas').removeClass('is-invalid'); + if (!continueCheck) + return false; + if (!$('#divConfigTapaDura').hasClass('d-none') && continueCheck) { + if ($('#papelGuardas').select2('data').length == 0) { + $('#papelGuardas').addClass('is-invalid'); + this.errores.push(window.translations["validation"].papel_guardas); + return false; + } + if ($('#gramajeGuardas').select2('data').length == 0) { + $('#gramajeGuardas').addClass('is-invalid'); + this.errores.push(window.translations["validation"].gramaje_guardas); + return false; + } + } + return true; + } + + validatePapelCubierta(continueCheck = true) { + + $('#divPapelCubierta').removeClass('is-invalid'); + $('#divPapelEspecialCubierta').removeClass('is-invalid'); + if (!continueCheck) + return false; + if ($('.custom-selector-papel-cubierta input[type="radio"]:checked').length == 0 && continueCheck) { + + $('#divPapelCubierta').addClass('is-invalid'); + this.errores.push(window.translations["validation"].papel_cubierta); + return false; + } + else if (!$('#divPapelEspecialCubierta').hasClass("d-none")) { + if ($('#papelEspecialCubiertaSel').select2('data').length == 0 && continueCheck) { + $('#divPapelEspecialCubierta').addClass('is-invalid'); + this.errores.push(window.translations["validation"].papel_cubierta_especial); + return false; + } + } + return true; + } + + validateGramajeCubierta(continueCheck = true) { + + $('#divGramajeCubierta').removeClass('is-invalid'); + if ($('.custom-selector-gramaje-cubierta input[type="radio"]:checked').length == 0 && continueCheck) { + $('#divGramajeCubierta').addClass('is-invalid'); + this.errores.push(window.translations["validation"].gramaje_cubierta); + return false; + } + return true; + } + + validateSobrecubierta() { + + let noError = true; + $('#papelSobrecubierta').removeClass('is-invalid'); + $('#gramajeSobrecubierta').removeClass('is-invalid'); + if ($("#addSobrecubierta").prop("checked") == true) { + if ($('#papelSobrecubierta').select2('data').length == 0) { + $('#papelSobrecubierta').addClass('is-invalid'); + this.errores.push(window.translations["validation"].papel_sobrecubierta); + noError = false; + } + if ($('#gramajeSobrecubierta').select2('data').length == 0) { + $('#gramajeSobrecubierta').addClass('is-invalid'); + this.errores.push(window.translations["validation"].gramaje_sobrecubierta); + noError = false; + } + } + return noError; + } + + validateFaja() { + + let noError = true; + $('#papelFaja').removeClass('is-invalid'); + $('#gramajeFaja').removeClass('is-invalid'); + if ($("#addFaja").prop("checked") == true) { + if ($('#papelFaja').select2('data').length == 0) { + $('#papelFaja').addClass('is-invalid'); + this.errores.push(window.translations["validation"].papel_faja); + noError = false; + } + if ($('#gramajeFaja').select2('data').length == 0) { + $('#gramajeFaja').addClass('is-invalid'); + this.errores.push(window.translations["validation"].gramaje_faja); + noError = false; + } + } + return noError; + } + getLomoCubierta() { const lomoRedondo = this.tapaDuraLomoRedondo.hasClass("selected"); @@ -809,6 +924,10 @@ class DisenioCubierta { } element.trigger('change'); + + if (this.validateDisenioCubierta()) { + this.removeError(window.translations["validation"].tipo_cubierta); + } } @@ -830,6 +949,10 @@ class DisenioCubierta { element.closest('.image-presupuesto').toggleClass('selected'); element.trigger('change'); + + if (this.validateSolapasCubierta()) { + this.removeError(window.translations["validation"].opcion_solapas); + } } @@ -902,6 +1025,11 @@ class DisenioCubierta { this.papelCubierta = this.papelEspecial.getVal(); const tapa_dura = this.tapaBlanda.hasClass("selected") ? 0 : 1; + if (this.validatePapelCubierta()) { + this.removeError(window.translations["validation"].papel_cubierta); + this.removeError(window.translations["validation"].papel_cubierta_especial); + } + new Ajax('/configuracion/papelesgenericos/getpapelcliente', { [this.csrf_token]: this.csrf_hash, @@ -916,6 +1044,7 @@ class DisenioCubierta { tirada: this.presupuestoCliente.datosGenerales.getTiradas()[0], }, {}, + this.fillGramajes.bind(context), (response) => { console.log(response); } ).get(); @@ -925,8 +1054,13 @@ class DisenioCubierta { fillPapeles(response) { + const self = this; + this.divPapelCubierta.empty(); this.divGramajeCubierta.empty(); + this.divPapelCubierta.removeClass('is-invalid'); + this.divGramajeCubierta.removeClass('is-invalid'); + this.divPapelEspecial.removeClass('is-invalid'); if (response.papeles.length > 0) { this.textoPapelCubierta.removeClass('d-none'); @@ -953,7 +1087,11 @@ class DisenioCubierta { text: papel.nombre }); - radioButton.on('click', this.#handleGramajeCubierta.bind(this)); + radioButton.on('click', () => { + self.removeError(window.translations["validation"].papel_cubierta); + self.removeError(window.translations["validation"].papel_cubierta_especial); + this.#handleGramajeCubierta(); + }); container.append(radioButton).append(label); $('#divPapelCubierta').append(container); @@ -1092,6 +1230,10 @@ class DisenioCubierta { const element = $(event.target); const gramaje = element[0].id; + /*if(this.validateGramajeCubierta()) { + this.removeError(window.translations["validation"].gramaje_cubierta); + }*/ + this.presupuestoCliente.checkForm(event); }); @@ -1162,6 +1304,21 @@ class DisenioCubierta { else if ($('#' + id).val() > max) $('#' + id).val(max); } + + removeError(error) { + const hasError = this.errores.filter(err => err === error).length > 0; + if (hasError) { + // remove the item from this.errores + this.errores = this.errores.filter(err => err !== error); + } + if (this.errores.length == 0) { + document.getElementById('sk-alert').innerHTML = ''; + } + else { + document.getElementById('sk-alert').innerHTML = document.getElementById('sk-alert').innerHTML. + replace(error, ''); + } + } } diff --git a/httpdocs/assets/js/safekat/pages/presupuestoCliente/disenioInterior.js b/httpdocs/assets/js/safekat/pages/presupuestoCliente/disenioInterior.js index 5e69213c..1cb00768 100644 --- a/httpdocs/assets/js/safekat/pages/presupuestoCliente/disenioInterior.js +++ b/httpdocs/assets/js/safekat/pages/presupuestoCliente/disenioInterior.js @@ -93,6 +93,8 @@ class DisenioInterior { this.gramajeNegroForResumen = ""; this.papelColorForResumen = ""; this.gramajeColorForResumen = ""; + + this.errores = []; } @@ -377,72 +379,36 @@ class DisenioInterior { validate(goToNext = true) { - let errores = []; - - let continueCheck = true; + this.errores = []; // impresion interior - if ($('.disenio-interior.selected').length > 0) { - $('#divImpresionInterior').removeClass('is-invalid'); - } - else { - errores.push(window.translations["validation"].disenio_interior); - $('#divImpresionInterior').addClass('is-invalid'); - continueCheck = false; - } + let continueCheck = this.validateDisenioInterior(); // papel interior if (continueCheck) { - const papelSeleccionado = $('.custom-selector-papel input[type="radio"]:checked'); - if (papelSeleccionado.length > 0) { - if (!$('#divPapelEspecialInterior').hasClass("d-none")) { - if ($('#papelEspecialInterior').select2('data').length == 0) { - $('#divPapelInterior').addClass('is-invalid'); - errores.push(window.translations["validation"].papel_interior_especial); - continueCheck = false; - } - else { - $('#divPapelInterior').removeClass('is-invalid'); - } - } - else { - $('#divPapelInterior').removeClass('is-invalid'); - } - } else { - $('#divPapelInterior').addClass('is-invalid'); - errores.push(window.translations["validation"].papel_interior); - continueCheck = false; - } + continueCheck = this.validatePapelInterior(); } // gramaje interior if (continueCheck) { - const gramajeSeleccionado = $('.custom-selector-gramaje input[type="radio"]:checked'); - if (gramajeSeleccionado.length > 0) { - $('#divGramajeInterior').removeClass('is-invalid'); - } - else { - $('#divGramajeInterior').addClass('is-invalid'); - errores.push(window.translations["validation"].gramaje_interior); - } + this.validateGramajeInterior(); } const skAlert = document.getElementById('sk-alert'); skAlert.innerHTML = ''; - const uniqueErrors = [...new Set(errores)]; + this.errores = [...new Set(this.errores)]; - if (uniqueErrors.length > 0) { + if (this.errores.length > 0) { const message = window.translations["validation"].fix_errors + `
      - ${uniqueErrors.map(err => `
    • ${err}
    • `).join('')} + ${this.errores.map(err => `
    • ${err}
    • `).join('')}
    `; popErrorAlert(message, 'sk-alert', false); - errores = []; return false; } else { document.getElementById('sk-alert').innerHTML = ''; - errores = []; + this.errores = []; if (goToNext) this.validatorStepper.next(); else @@ -450,6 +416,58 @@ class DisenioInterior { } } + validateDisenioInterior() { + + if ($('.disenio-interior.selected').length > 0) { + $('#divImpresionInterior').removeClass('is-invalid'); + return true; + } + else { + this.errores.push(window.translations["validation"].disenio_interior); + $('#divImpresionInterior').addClass('is-invalid'); + return false; + } + } + + validatePapelInterior() { + + const papelSeleccionado = $('.custom-selector-papel input[type="radio"]:checked'); + if (papelSeleccionado.length > 0) { + if (!$('#divPapelEspecialInterior').hasClass("d-none")) { + if ($('#papelEspecialInterior').select2('data').length == 0) { + $('#divPapelInterior').addClass('is-invalid'); + this.errores.push(window.translations["validation"].papel_interior_especial); + return false; + } + else { + $('#divPapelInterior').removeClass('is-invalid'); + return true; + } + } + else { + $('#divPapelInterior').removeClass('is-invalid'); + return true; + } + } else { + $('#divPapelInterior').addClass('is-invalid'); + this.errores.push(window.translations["validation"].papel_interior); + return false; + } + } + + validateGramajeInterior() { + const gramajeSeleccionado = $('.custom-selector-gramaje input[type="radio"]:checked'); + if (gramajeSeleccionado.length > 0) { + $('#divGramajeInterior').removeClass('is-invalid'); + return true; + } + else { + $('#divGramajeInterior').addClass('is-invalid'); + this.errores.push(window.translations["validation"].gramaje_interior); + return false; + } + } + getTipoImpresion() { @@ -730,6 +748,21 @@ class DisenioInterior { else this.updatePapeles(); } + + if (this.validateDisenioInterior()) { + const hasError = this.errores.filter(err => err === window.translations["validation"].disenio_interior).length > 0; + if (hasError) { + // remove the item from this.errores + this.errores = this.errores.filter(err => err !== window.translations["validation"].disenio_interior); + } + if (this.errores.length == 0) { + document.getElementById('sk-alert').innerHTML = ''; + } + else { + document.getElementById('sk-alert').innerHTML = document.getElementById('sk-alert').innerHTML. + replace(window.translations["validation"].disenio_interior, ''); + } + } } @@ -780,8 +813,23 @@ class DisenioInterior { (response) => { console.log(response); } ).get(); } - if (!this.cargando) + if (!this.cargando) { this.gramaje = null; + if (this.validatePapelInterior()) { + const hasError = this.errores.filter(err => err === window.translations["validation"].papel_interior).length > 0; + if (hasError) { + // remove the item from this.errores + this.errores = this.errores.filter(err => err !== window.translations["validation"].papel_interior); + } + if (this.errores.length == 0) { + document.getElementById('sk-alert').innerHTML = ''; + } + else { + document.getElementById('sk-alert').innerHTML = document.getElementById('sk-alert').innerHTML. + replace(window.translations["validation"].papel_interior, ''); + } + } + } else { this.cargando = false; } @@ -938,9 +986,24 @@ class DisenioInterior { const element = $(event.target); const gramaje = element[0].id; - this.presupuestoCliente.calcularSolapas(event); - this.presupuestoCliente.checkLomoInterior(event); - this.presupuestoCliente.checkForm(event); + if (this.validateGramajeInterior()) { + const hasError = this.errores.filter(err => err === window.translations["validation"].gramaje_interior).length > 0; + if (hasError) { + // remove the item from this.errores + this.errores = this.errores.filter(err => err !== window.translations["validation"].gramaje_interior); + } + if (this.errores.length == 0) { + document.getElementById('sk-alert').innerHTML = ''; + } + else { + document.getElementById('sk-alert').innerHTML = document.getElementById('sk-alert').innerHTML. + replace(window.translations["validation"].gramaje_interior, ''); + } + + this.presupuestoCliente.calcularSolapas(event); + this.presupuestoCliente.checkLomoInterior(event); + this.presupuestoCliente.checkForm(event); + }; }); diff --git a/httpdocs/assets/js/safekat/pages/presupuestoCliente/presupuestoCliente.js b/httpdocs/assets/js/safekat/pages/presupuestoCliente/presupuestoCliente.js index 21daec53..46768cdc 100644 --- a/httpdocs/assets/js/safekat/pages/presupuestoCliente/presupuestoCliente.js +++ b/httpdocs/assets/js/safekat/pages/presupuestoCliente/presupuestoCliente.js @@ -86,6 +86,8 @@ class PresupuestoCliente { if (this.datosGenerales.excluirRotativa.length == 0) { this.direcciones.direccionesCliente.setParams({ 'cliente_id': $("#clienteId").val() }) + this.direcciones.direccionesClienteFP1.setParams({ 'cliente_id': $("#clienteId").val() }) + this.direcciones.direccionesClienteFP2.setParams({ 'cliente_id': $("#clienteId").val() }) } @@ -791,6 +793,19 @@ class PresupuestoCliente { }; } } + + if( this.direcciones.direccionesFP1.length > 0) { + this.datos.direccionesFP1 = this.direcciones.direccionesFP1.map((direccion) => { + return direccion.getFormData(); + }); + } + + if( this.direcciones.direccionesFP2.length > 0) { + this.datos.direccionesFP2 = this.direcciones.direccionesFP2.map((direccion) => { + return direccion.getFormData(); + }); + } + if (save) { this.datos.datosCabecera = { titulo: this.datosGenerales.titulo.val(),