diff --git a/ci4/app/Config/Routes.php b/ci4/app/Config/Routes.php index 443012e3..1448159a 100644 --- a/ci4/app/Config/Routes.php +++ b/ci4/app/Config/Routes.php @@ -572,7 +572,6 @@ $routes->group('presupuestocliente', ['namespace' => 'App\Controllers\Presupuest $routes->post('getgramaje', 'Presupuestocliente::getGramaje', ['as' => 'obtenerGramaje']); $routes->post('presupuesto', 'Presupuestocliente::presupuesto', ['as' => 'presupuestoCliente']); $routes->post('getDireccionesCliente', 'Presupuestocliente::getDireccionesCliente', ['as' => 'getDirecciones']); - $routes->post('getDatosDireccion', 'Presupuestocliente::getDatosDireccion', ['as' => 'getDatosDireccion']); $routes->post('getNuevaDireccion', 'Presupuestocliente::getNuevaDireccion', ['as' => 'nuevaDireccion']); $routes->post('guardarPresupuesto', 'Presupuestocliente::guardarPresupuesto', ['as' => 'guardarPresupuesto']); $routes->post('duplicarPresupuesto', 'Presupuestocliente::duplicarPresupuesto', ['as' => 'duplicarPresupuesto']); diff --git a/ci4/app/Controllers/Presupuestos/Presupuestocliente.php b/ci4/app/Controllers/Presupuestos/Presupuestocliente.php index 4026fcfb..c10c843b 100755 --- a/ci4/app/Controllers/Presupuestos/Presupuestocliente.php +++ b/ci4/app/Controllers/Presupuestos/Presupuestocliente.php @@ -332,13 +332,15 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController $excluirRotativa = $reqData['excluirRotativa'] ?? 0; $ivaReducido = $reqData['ivaReducido'] ?? 0; + $direcciones = $reqData['direcciones'] ?? []; + $tipo_impresion_id = $this->getTipoImpresion($tipo, $cubierta['tipoCubierta']); // Interior $interior = [ 'papel_generico' => $modelPapelGenerico->getIdFromCode($interior['papelInterior']), 'gramaje' => intval($interior['gramajeInterior']), - 'excluirRotativa' => $excluirRotativa == "false" ? false: true, + 'excluirRotativa' => $excluirRotativa == "false" ? false : true, 'paginas' => $paginas, 'paginas_color' => $paginas_color, ]; @@ -361,8 +363,7 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController 'solapas' => intval($sobrecubierta['solapas'] ?? 0), 'acabados' => $sobrecubierta['plastificado'] ?? 0, ]; - } - else + } else $sobrecubierta = false; // Guardas @@ -372,8 +373,7 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController 'gramaje' => intval($guardas['gramaje']), 'caras' => intval($guardas['guardasImpresas']), ]; - } - else + } else $datos_guardas = false; $datos_presupuesto = array( @@ -389,10 +389,38 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController 'cubierta' => $cubierta, 'sobrecubierta' => $sobrecubierta, 'datos_guardas' => $datos_guardas, + + 'servicios' => $reqData['servicios'] ?? [], ); $return_data = $this->calcular_presupuesto($datos_presupuesto, 0, false); //TRUE FOR DEBUG + if(count($direcciones) > 1){ + + for ($i=0; $igetCosteEnvio( + $direccion['id'], + $return_data['peso'][$i], + $direccion['unidades'], + $direccion['enPallets'] == 'true'?1:0)[0]->coste; + } + $return_data['precio_u'][$i] = round(floatval($return_data['precio_u'][$i]) + $coste_envio, 4); + } + } + else{ + + for ($i=0; $igetCosteEnvio(null, $return_data['peso'][$i], $tirada[$i], false)[0]->coste; + $return_data['precio_u'][$i] = round(floatval($return_data['precio_u'][$i]) + $coste_envio, 4); + } + + + } + return $this->respond($return_data); } catch (Exception $e) { return $this->failServerError($e->getMessage()); @@ -424,30 +452,7 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController } } - public function getDatosDireccion() - { - - if ($this->request->isAJAX()) { - - $newTokenHash = csrf_hash(); - $csrfTokenName = csrf_token(); - - $reqData = $this->request->getPost(); - $direccionId = $reqData['id'] ?? 0; - $peso = $reqData['peso'] ?? 0; - $unidades = $reqData['unidades'] ?? 0; - $entregaPieCalle = $reqData['entregaPieCalle'] ?? 0; - - $data = $this->calcular_coste_envio($direccionId, $peso, $unidades, $entregaPieCalle); - - return $this->respond([ - 'data' => $data, - $csrfTokenName => $newTokenHash - ]); - } else { - return $this->failUnauthorized('Invalid request', 403); - } - } + public function getNuevaDireccion() { @@ -1026,11 +1031,21 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController } - protected function calcular_coste_envio($direccionId, $peso, $unidades, $entregaPieCalle) + protected function getCosteEnvio($direccionId = null, $peso, $unidades, $entregaPieCalle) { - $model = model('App\Models\Clientes\ClienteDireccionesModel'); - $data = $model->getDireccion($direccionId); + if($direccionId != null){ + $model = model('App\Models\Clientes\ClienteDireccionesModel'); + $data = $model->getDireccion($direccionId); + } + else{ + $data = []; + array_push($data, (object)[ + 'pais_id' => 1, // espaƱa + 'cp' => 18000, // envio nacional + ]); + } + $modelTarifaEnvio = model('App\Models\Tarifas\TarifaEnvioModel'); $coste = 0; @@ -1105,6 +1120,7 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController $gramajeCubierta = $datos_entrada['cubierta']['gramajeCubierta']; $carasCubierta = $datos_entrada['cubierta']['carasCubierta']; $solapasCubierta = $datos_entrada['cubierta']['solapasCubierta']; + $acabadosCubierta = $datos_entrada['cubierta']['acabadosCubierta'] ?? []; // Sobrecubierta $sobreCubierta = $datos_entrada["sobrecubierta"] ?? null; @@ -1291,18 +1307,22 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController else $error->cubierta = ""; - $tarifaAcabadoCubierta = intval($datos_entrada['acabadoCubierta'] ?? 0); + // Acabados Cubierta + $tarifaAcabadoCubierta = $this->obtenerTarifasAcabado($acabadosCubierta); $acabadoCubierta = []; - if ($tarifaAcabadoCubierta > 0) { + foreach ($tarifaAcabadoCubierta as $tarifa) { + $model = model('App\Models\Presupuestos\PresupuestoAcabadosModel'); - $acabadoCubierta = $model->getPrecioTarifa($tarifaAcabadoCubierta, $datosPedido->tirada, -1, $POD); - } - if (count($acabadoCubierta) > 0) { - if ($acabadoCubierta[0]->total <= 0) - $error->servicios = lang('Presupuestos.errores.errorPresupuesto'); - $coste_servicios += floatval($acabadoCubierta[0]->total); + $acabadoCubierta = $model->getPrecioTarifa($tarifa, $datosPedido->tirada, -1, $POD); + + if (count($acabadoCubierta) > 0) { + if ($acabadoCubierta[0]->total <= 0) + $error->servicios = lang('Presupuestos.errores.errorPresupuesto'); + $coste_servicios += floatval($acabadoCubierta[0]->total); + } } + // Sobrecubierta $coste_sobrecubierta = 0.0; $peso_sobrecubierta = 0.0; @@ -1316,7 +1336,7 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController $input_data['datosPedido']->paginas = 4; $input_data['paginas_color'] = 4; $input_data['datosPedido']->solapas_ancho = intval($sobreCubierta['solapas'] ?? 0); - $input_data['datosPedido']->solapas = $input_data['datosPedido']->solapas_ancho > 0 ? 1 : 0; + $input_data['datosPedido']->solapas = $sobreCubierta['solapas'] > 0 ? 1 : 0; $input_data['datosPedido']->lomo = $this->calcular_lomo([$cubierta], $input_data['datosPedido']->lomo); $input_data['isColor'] = 1; $input_data['isHq'] = 1; @@ -1346,17 +1366,18 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController $lomo_sobrecubierta = $lomo + floatval($linea_sobrecubierta['mano']); - ////////////////////////////////////JJJO - $tarifaAcabadoSobrecubierta = intval(strlen($sobreCubierta['acabados']) == 0 ? 0 : $sobreCubierta['acabados']); + $tarifaAcabadoSobrecubierta = $this->obtenerTarifasAcabado(['plastificado' => $sobreCubierta['acabados']]); $acabadoSobrecubierta = []; - if ($tarifaAcabadoSobrecubierta > 0) { + foreach ($tarifaAcabadoSobrecubierta as $tarifa) { + $model = model('App\Models\Presupuestos\PresupuestoAcabadosModel'); - $acabadoSobrecubierta = $model->getPrecioTarifa($tarifaAcabadoSobrecubierta, $datosPedido->tirada, $POD); - } - if (count($acabadoSobrecubierta) > 0) { - if ($acabadoSobrecubierta[0]->total <= 0) - $error->servicios = lang('Presupuestos.errores.errorPresupuesto'); - $coste_servicios += floatval($acabadoSobrecubierta[0]->total); + $acabadoSobrecubierta = $model->getPrecioTarifa($tarifa, $datosPedido->tirada, -1, $POD); + + if (count($acabadoSobrecubierta) > 0) { + if ($acabadoSobrecubierta[0]->total <= 0) + $error->servicios = lang('Presupuestos.errores.errorPresupuesto'); + $coste_servicios += floatval($acabadoSobrecubierta[0]->total); + } } } @@ -1460,16 +1481,16 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController /* 'retractilado' => 3, - 'retractilado5' => 5, - 'ferro' => 24, 'prototipo' => 9, - 'fajaColor' => 16, - 'plegadoGuardas' => 62, */ $serviciosAutomaticos = []; - + $servicios = []; + if ($datos_entrada['cubierta']['acabadosCubierta']['retractilado'] === 'true') + array_push($servicios, 3); + if ($datos_entrada['servicios']['prototipo']) + array_push($servicios, 9); foreach ($servicios as $servicio) { - if (intval($servicio) == 3 || intval($servicio) == 5 || intval($servicio) == 16) { + if (intval($servicio) == 3) { // Servicios acabado $resultado = PresupuestoCLienteService::getServiciosAcabados([ 'tarifa_id' => $servicio, @@ -1485,22 +1506,7 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController $totalServicios += floatval($resultado[0]->total); $margenServicios += floatval($resultado[0]->total) * floatval($resultado[0]->margen) / 100.0; } - } else if (intval($servicio) == 24) { - // Servicios preimpresion (Ferro) - $resultado = PresupuestoCLienteService::getServiciosPreimpresion([ - 'tarifa_id' => $servicio, - ]); - array_push($serviciosAutomaticos, $resultado[0]); - if ($resultado[0]->precio <= 0) - $error->servicios = lang('Presupuestos.errores.errorPresupuesto'); - - $coste_servicios += floatval($resultado[0]->precio); - if ($extra_info) { - $totalServicios += floatval($resultado[0]->precio); - $margenServicios += floatval($resultado[0]->precio) * floatval($resultado[0]->margen) / 100.0; - } - } - if (intval($servicio) == 9) { + } else if (intval($servicio) == 9) { // Servicios preimpresion $resultado = PresupuestoCLienteService::getServiciosExtra([ 'tarifa_id' => $servicio, @@ -1514,22 +1520,6 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController $totalServicios += floatval($resultado[0]->precio); $margenServicios += floatval($resultado[0]->precio) * floatval($resultado[0]->margen) / 100.0; } - } else if (intval($servicio) == 62) { - // Servicios manipulado - $resultado = PresupuestoCLienteService::getServiciosManipulado([ - 'tarifa_id' => $servicio, - 'tirada' => $tirada[$t], - 'POD' => $POD, - ]); - array_push($serviciosAutomaticos, $resultado[0]); - if ($resultado[0]->total <= 0) - $error->servicios = lang('Presupuestos.errores.errorPresupuesto'); - - $coste_servicios += floatval($resultado[0]->total); - if ($extra_info) { - $totalServicios += floatval($resultado[0]->total); - $margenServicios += floatval($resultado[0]->total) * floatval($resultado[0]->margen) / 100.0; - } } } @@ -2020,4 +2010,69 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController } return 32; // valor por defecto } + + protected function obtenerTarifasAcabado($acabados) + { + $tarifas = []; + + + foreach ($acabados as $acabado => $value) { + + if ($acabado == 'plastificado') { + + if ($value !== 'NONE') { + + switch ($value) { + case 'BRIL': + array_push($tarifas, 1); + break; + case 'MATE': + array_push($tarifas, 2); + break; + case 'ANTI': + array_push($tarifas, 28); + break; + case 'SAND': + array_push($tarifas, 94); + break; + default: + break; + } + } + } else if ($acabado == 'barniz') { + if ($value !== 'NONE') { + switch ($value) { + case 'R2D': + array_push($tarifas, 102); + break; + case 'R3D': + array_push($tarifas, 8); + break; + default: + break; + } + } + } else if ($acabado == 'estampado') { + if ($value !== 'NONE') { + switch ($value) { + case 'GOLD': + array_push($tarifas, 103); + break; + case 'SILV': + array_push($tarifas, 104); + break; + case 'COPP': + array_push($tarifas, 105); + break; + case 'BRON': + array_push($tarifas, 106); + break; + default: + break; + } + } + } + } + return $tarifas; + } } 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 8236f00e..2ad9ea33 100644 --- a/ci4/app/Views/themes/vuexy/form/presupuestos/cliente/items/_datosGenerales.php +++ b/ci4/app/Views/themes/vuexy/form/presupuestos/cliente/items/_datosGenerales.php @@ -201,11 +201,11 @@ -
+

Servicios extra

-
+
@@ -217,7 +217,7 @@

Otros

-
+
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 b5000969..087f56fa 100644 --- a/ci4/app/Views/themes/vuexy/form/presupuestos/cliente/items/_disenioCubierta.php +++ b/ci4/app/Views/themes/vuexy/form/presupuestos/cliente/items/_disenioCubierta.php @@ -352,7 +352,7 @@
-
+
diff --git a/httpdocs/assets/js/safekat/pages/presupuestoCliente/direcciones.js b/httpdocs/assets/js/safekat/pages/presupuestoCliente/direcciones.js index 3180de71..6c0dba87 100644 --- a/httpdocs/assets/js/safekat/pages/presupuestoCliente/direcciones.js +++ b/httpdocs/assets/js/safekat/pages/presupuestoCliente/direcciones.js @@ -67,6 +67,18 @@ class Direcciones { }); } + + getDirecciones(){ + + let direcciones = this.divDirecciones.find('.direccion-cliente') + if(direcciones.length > 0){ + direcciones.forEach(element => { + + }); + } + } + + #insertDireccion() { self = this; @@ -76,7 +88,7 @@ class Direcciones { let id = this.direccionesCliente.getValue(); let unidades = this.unidadesAdd.val(); let entregaPalets = this.entregaPieCallero.is(':checked'); - let dirId = "dirEnvio-1"; + let dirId = "dirEnvio-" + id; let direccionesActuales = this.divDirecciones.find('.direccion-cliente'); if (direccionesActuales.length > 0) { // the the lass item @@ -99,7 +111,7 @@ class Direcciones { 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({ "id": dirId, "unidades": unidades, "enPallets": entregaPalets, "direccion": response.data[0] }); + this.direcciones.push({ "id": id, "unidades": unidades, "enPallets": entregaPalets}); self.divDirecciones.trigger('change'); $('#loader').hide(); }, diff --git a/httpdocs/assets/js/safekat/pages/presupuestoCliente/presupuestoCliente.js b/httpdocs/assets/js/safekat/pages/presupuestoCliente/presupuestoCliente.js index 74ec6c0c..9b6b17bf 100644 --- a/httpdocs/assets/js/safekat/pages/presupuestoCliente/presupuestoCliente.js +++ b/httpdocs/assets/js/safekat/pages/presupuestoCliente/presupuestoCliente.js @@ -27,11 +27,13 @@ class PresupuestoCliente { this.disenioCubierta = new DisenioCubierta($("#cubierta-libro"), this.clientePresupuestoWizard, this.validationStepper); this.direcciones = new Direcciones($("#direcciones-libro"), this.clientePresupuestoWizard, this.validationStepper); + this.divTiradasPrecios = $("#divTiradasPrecio"); + this.datos = {}; this.ajax_calcular = new Ajax('/presupuestocliente/calcular', {}, this.datos, - this.#procesarPresupuesto, - () => { $('#loader').hide(); console.log("Error") }); + this.#procesarPresupuesto.bind(this), + () => { $('#loader').hide(); }); } @@ -54,12 +56,12 @@ class PresupuestoCliente { this.disenioCubierta.init(); this.direcciones.init(); - this.RELLENAR_PRESUPUESTO(); + //this.RELLENAR_PRESUPUESTO(); } - checkForm() { + checkForm(event) { this.#getDatos(); @@ -154,8 +156,24 @@ class PresupuestoCliente { #procesarPresupuesto(response) { $('#loader').hide(); - console.log("Success"); - console.log(response); + // checj if response.tiradas exists and is not empty + if (response.tiradas && response.tiradas.length) { + + this.divTiradasPrecios.empty(); + + for (let i = 0; i < response.tiradas.length; i++) { + new tarjetaTiradasPrecio( + this.divTiradasPrecios, + ('precio-tiradas-' + response.tiradas[i]), + response.tiradas[i], + (parseFloat(response.precio_u[i])*parseInt(response.tiradas[i])).toFixed(2), + response.precio_u[i] + ); + + } + } + // DEBUG + //console.log(response); } @@ -228,7 +246,7 @@ class PresupuestoCliente { excluirRotativa: this.datosGenerales.excluirRotativa.is(':checked'), ivaReducido: this.datosGenerales.ivaReducido.find('option:selected').val(), servicios: { - 'prototipo' : this.datosGenerales.servicios.prototipo.is(':checked'), + 'prototipo' : this.datosGenerales.prototipo.is(':checked'), }, }; @@ -248,6 +266,10 @@ class PresupuestoCliente { else{ this.datos.cubierta.solapas = false; } + + if(this.direcciones.direcciones.length > 0){ + this.datos.direcciones = this.direcciones.direcciones; + } } diff --git a/httpdocs/assets/js/safekat/pages/presupuestoCliente/tarjetaTiradasPrecio.js b/httpdocs/assets/js/safekat/pages/presupuestoCliente/tarjetaTiradasPrecio.js index 6792b1da..6c34dce8 100644 --- a/httpdocs/assets/js/safekat/pages/presupuestoCliente/tarjetaTiradasPrecio.js +++ b/httpdocs/assets/js/safekat/pages/presupuestoCliente/tarjetaTiradasPrecio.js @@ -15,12 +15,12 @@ class tarjetaTiradasPrecio { let $html = $('