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 fb069b7d..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); @@ -1860,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, @@ -1879,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); @@ -3625,9 +3641,9 @@ 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')) { + 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"' : ''; 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/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/tarjetaDireccionPresupuesto.js b/httpdocs/assets/js/safekat/components/tarjetaDireccionPresupuesto.js index efa22e3f..96763d04 100644 --- a/httpdocs/assets/js/safekat/components/tarjetaDireccionPresupuesto.js +++ b/httpdocs/assets/js/safekat/components/tarjetaDireccionPresupuesto.js @@ -5,12 +5,13 @@ class tarjetaDireccion { 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; - this.isFerroPrototipo = direccion.isFerroPrototipo; - this.numFerro = this.numFerro || 0; + } @@ -40,7 +41,13 @@ class tarjetaDireccion { var $hr = $('