diff --git a/ci4/app/Config/RBAC/permissionMatrix.php b/ci4/app/Config/RBAC/permissionMatrix.php index 63f2d991..c876a2b2 100644 --- a/ci4/app/Config/RBAC/permissionMatrix.php +++ b/ci4/app/Config/RBAC/permissionMatrix.php @@ -45,11 +45,16 @@ const SK_PERMISSION_MATRIX = [ "tarifa-encuadernacion.edit", "tarifa-encuadernacion.delete", "tarifa-encuadernacion.menu", + "tarifa-extra.create", + "tarifa-extra.edit", + "tarifa-extra.delete", + "tarifa-extra.menu", "tarifa-envio.create", "tarifa-envio.edit", "tarifa-envio.delete", "tarifa-envio.menu", "servicio-acabado.create", + "servicio-acabado.edit", "servicio-acabado.delete", "servicio-acabado.menu", "proveedores.create", @@ -222,10 +227,18 @@ const SK_PERMISSION_MATRIX = [ "tarifa-encuadernacion.edit", "tarifa-encuadernacion.delete", "tarifa-encuadernacion.menu", + "tarifa-extra.create", + "tarifa-extra.edit", + "tarifa-extra.delete", + "tarifa-extra.menu", "tarifa-envio.create", "tarifa-envio.edit", "tarifa-envio.delete", "tarifa-envio.menu", + "servicio-acabado.create", + "servicio-acabado.edit", + "servicio-acabado.delete", + "servicio-acabado.menu", "proveedores.create", "proveedores.edit", "proveedores.delete", diff --git a/ci4/app/Controllers/API/ImprimelibrosApi.php b/ci4/app/Controllers/API/ImprimelibrosApi.php index dbd7b783..aeff2713 100644 --- a/ci4/app/Controllers/API/ImprimelibrosApi.php +++ b/ci4/app/Controllers/API/ImprimelibrosApi.php @@ -57,10 +57,10 @@ class ImprimelibrosApi extends ResourceController 'precios' => $response['precio_u'] ] ]; - } else { + }else{ $response = [ 'status' => 400, - 'error' => $response + 'error' => $response ]; } @@ -75,42 +75,23 @@ class ImprimelibrosApi extends ResourceController // Access the entire POST data $post_data = $this->request->getJSON(true); + //return $this->respond(var_dump($post_data)); + // Instancia de presupuesto cliente $presupuestocliente = new Presupuestocliente(); - try { - $response = $presupuestocliente->guardar($post_data); + $response = $presupuestocliente->guardar($post_data); - // DEBUG LINE - //return $this->respond($response); + return $this->respond($response); - if (!isset($response['sk_id'])) { - return $this->respond([ - 'status' => 400, - 'error' => 'Missing sk_id', - 'message' => 'El identificador sk_id es requerido pero no se recibió.' - ], 400); - } - - $response = [ - 'status' => 200, - 'error' => null, - 'data' => [ - 'sk_id' => $response['sk_id'], - 'sk_url' => $response['sk_url'] ?? null - ] - ]; - - return $this->respond($response); - - } catch (\Exception $e) { - - return $this->respond([ - 'status' => 500, - 'error' => 'Server error', - 'message' => 'Error inesperado durante el procesado' - ]); - - } + $response = [ + 'status' => 200, + 'error' => null, + 'data' => [ + 'tiradas' => $response['tiradas'], + 'precios' => $response['precio_u'] + ] + ]; + return $this->respond($response); } diff --git a/ci4/app/Controllers/Presupuestos/Presupuestocliente.php b/ci4/app/Controllers/Presupuestos/Presupuestocliente.php index 04d599c2..f45d7bb8 100755 --- a/ci4/app/Controllers/Presupuestos/Presupuestocliente.php +++ b/ci4/app/Controllers/Presupuestos/Presupuestocliente.php @@ -181,6 +181,8 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController $this->viewData['state'] = intval($presupuestoEntity->estado_id); $this->viewData['boxTitle'] = lang('Basic.global.edit2') . ' ' . $this->viewData['pageTitle'] . ' ' . lang('Basic.global.edit3'); + $this->viewData['serviciosExtra'] = $this->getServiciosExtra(); + return $this->displayForm(__METHOD__, $id); } // end function edit(...) @@ -1243,6 +1245,37 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController $borrar_antes = true; } + $servicio_ferro = (object) [ + 'nombre' => 'ferro', + 'id' => model('App\Models\Configuracion\ConfigVariableModel')->getVariable('id_servicio_ferro')->value + ]; + + $servicio_ferro_digital = (object) [ + 'nombre' => 'ferro_digital', + 'id' => model('App\Models\Configuracion\ConfigVariableModel')->getVariable('id_servicio_ferro_digital')->value + ]; + $servicio_prototipo = (object) [ + 'nombre' => 'prototipo', + 'id' => model('App\Models\Configuracion\ConfigVariableModel')->getVariable('id_servicio_prototipo')->value + ]; + + + if(isset($resultado_presupuesto['values']['servicios_extra'])) + { + foreach ($resultado_presupuesto['values']['servicios_extra'] as $servicio) { + if($servicio->tarifa_id == $servicio_ferro->id){ + $ferro = 1; + } + else if($servicio->tarifa_id == $servicio_ferro_digital->id){ + $ferroDigital = 1; + } + else if($servicio->tarifa_id == $servicio_prototipo->id){ + $prototipo = 1; + } + } + } + + $datos_presupuesto['prototipo'] = $prototipo; $datos_presupuesto['ferro'] = $ferro; $datos_presupuesto['ferro_digital'] = $ferroDigital; @@ -1354,14 +1387,7 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController foreach ($resultado_presupuesto['values']['serviciosDefecto']['manipulado'] as $servicio) { $this->guardarServicio($id, $servicio, 'manipulado'); } - $servicio_ferro = (object) [ - 'nombre' => 'ferro', - 'id' => model('App\Models\Configuracion\ConfigVariableModel')->getVariable('id_servicio_ferro')->value - ]; - $servicio_prototipo = (object) [ - 'nombre' => 'prototipo', - 'id' => model('App\Models\Configuracion\ConfigVariableModel')->getVariable('id_servicio_prototipo')->value - ]; + $servicio_retractilado = (object) [ 'nombre' => 'retractilado', 'id' => model('App\Models\Configuracion\ConfigVariableModel')->getVariable('id_servicio_retractilado')->value @@ -1399,6 +1425,11 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController 'id' => model('App\Models\Configuracion\ConfigVariableModel')->getVariable('id_servicio_plegado_exceso_solapas_faja')->value ]; + // Funcionalidad servicios extra + foreach ($resultado_presupuesto['values']['servicios_extra'] as $servicio) { + $this->guardarServicio($id, $servicio, 'extra'); + } + foreach ($resultado_presupuesto['values']['servicios_automaticos'] as $servicio) { if ($servicio->tarifa_id == $servicio_retractilado->id || $servicio->tarifa_id == $servicio_retractilado5->id) { // Servicios acabado @@ -1501,6 +1532,10 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController $data['datosGenerales']['retractilado'] = $presupuesto->retractilado; $data['datosGenerales']['retractilado5'] = $presupuesto->retractilado5; + $modelServiciosExtra = new PresupuestoServiciosExtraModel(); + $data['datosGenerales']['serviciosExtra'] = $modelServiciosExtra + ->where('presupuesto_id', $id)->findColumn('tarifa_extra_id'); + $datos_papel = $this->obtenerDatosPapel($presupuesto->id); if (array_key_exists('interior', $datos_papel)) { $data['interior'] = $datos_papel['interior']; @@ -1783,11 +1818,15 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController $data = [ 'presupuesto_id' => $presupuestoId, - 'tarifa_extra_id' => $servicio->tarifa_id, + 'tarifa_extra_id' => intval($servicio->tarifa_id), 'precio' => round($servicio->precio, 2), - 'margen' => $servicio->margen, + 'margen' => floatval($servicio->margen), ]; - $model->insert($data); + $errors = null; + + if (!$model->insert($data)) { + $errors = $model->errors(); + } } else if ($tipo == 'acabado') { $model = new PresupuestoAcabadosModel(); @@ -2637,13 +2676,13 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController if ($datos_entrada['servicios'] !== []) { - if ($datos_entrada['servicios']['retractilado']) // acabado + if (isset($datos_entrada['servicios']['retractilado']) && $datos_entrada['servicios']['retractilado']) // acabado array_push($servicios, $servicio_retractilado); - if ($datos_entrada['servicios']['retractilado5']) // acabado + if (isset($datos_entrada['servicios']['retractilado5']) && $datos_entrada['servicios']['retractilado5']) // acabado array_push($servicios, $servicio_retractilado5); - if ($datos_entrada['servicios']['prototipo']) // extra + if (isset($datos_entrada['servicios']['prototipo']) && $datos_entrada['servicios']['prototipo']) // extra array_push($servicios, $servicio_prototipo); - if ($datos_entrada['servicios']['ferro']) // extra + if (isset($datos_entrada['servicios']['ferro']) && $datos_entrada['servicios']['ferro']) // extra array_push($servicios, $servicio_ferro); if ($solapasCubierta > 0) array_push($servicios, $servicio_solapas_cubierta); @@ -2758,6 +2797,46 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController } } + $serviciosExtra = []; + // funcionalidad para los servicios extra añadidos por el usuario + if($datos_entrada['servicios'] !== [] && isset($datos_entrada['servicios']['serviciosExtra']) && + $datos_entrada['servicios']['serviciosExtra'] !== []){ + + foreach($datos_entrada['servicios']['serviciosExtra'] as $servicio){ + $resultado = PresupuestoCLienteService::getServiciosExtra([ + 'tarifa_id' => intval($servicio), + ]); + + if ($resultado[0]->precio <= 0) { + + $errorModel = new ErrorPresupuesto(); + $errorModel->insertError( + $datos_entrada['id'], + auth()->user()->id, + 'No se puede obtener servicio con id ' . ((string) $servicio), + $input_data + ); + $return_data = [ + 'errors' => (object) ([ + 'status' => 1 + ]), + ]; + return $return_data; + } + + array_push($serviciosExtra, $resultado[0]); + + $coste_servicios += round(floatval($resultado[0]->precio), 2); + if ($extra_info) { + $totalServicios += round(floatval($resultado[0]->precio), 2); + $base = round(floatval($resultado[0]->precio / (1 + $resultado[0]->margen / 100.0)), 2); + $base = round(floatval($base / $datosPedido->tirada), 2) * $datosPedido->tirada; + $margenServicios += round(floatval($resultado[0]->precio - $base), 2); + } + } + + } + // Plegado de solapas grandes if (intval($solapasCubierta) > 0 && intval($cubierta['dimension_desarrollo']['ancho']) > 630) { // Servicios manipulado @@ -2925,6 +3004,7 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController $return_data['values']['serviciosDefecto']['encuadernacion'] = $servDefectoEnc; $return_data['values']['serviciosDefecto']['manipulado'] = $servDefectoMan; $return_data['values']['servicios_automaticos'] = $serviciosAutomaticos; + $return_data['values']['servicios_extra'] = $serviciosExtra; } } @@ -3434,4 +3514,22 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController return [$paginasNegro, $paginasColor]; } + + private function getServiciosExtra(){ + + $servicios = []; + + $model = model('App\Models\Tarifas\TarifaextraModel'); + $data = $model->where('deleted_at', null)->where('mostrar_en_presupuesto_cliente', 1)->findAll(); + + foreach ($data as $servicio) { + $id = "service_extra_" . $servicio->id; + array_push($servicios, + "id}\" data-tarifa-tipo=\"extra\" data-tarifa-nombre=\"{$servicio->nombre}\"> + "); + } + + return $servicios; + } } diff --git a/ci4/app/Models/Presupuestos/PresupuestoServiciosExtraModel.php b/ci4/app/Models/Presupuestos/PresupuestoServiciosExtraModel.php index 1adccc74..d5a3dcd2 100755 --- a/ci4/app/Models/Presupuestos/PresupuestoServiciosExtraModel.php +++ b/ci4/app/Models/Presupuestos/PresupuestoServiciosExtraModel.php @@ -21,6 +21,8 @@ class PresupuestoServiciosExtraModel extends \App\Models\BaseModel protected $allowedFields = ["presupuesto_id", "tarifa_extra_id", "precio", "margen"]; protected $returnType = "App\Entities\Presupuestos\PresupuestoServiciosExtraEntity"; + protected $primaryKey = 'id'; + protected $useTimestamps = true; protected $useSoftDeletes = false; @@ -30,14 +32,14 @@ class PresupuestoServiciosExtraModel extends \App\Models\BaseModel public static $labelField = "nombre"; protected $validationRules = [ - "precio_total" => [ + "precio" => [ "label" => "Presupuestos.precioTotal", "rules" => "decimal|required", ], ]; protected $validationMessages = [ - "precio_total" => [ + "precio" => [ "decimal" => "Presupuestos.validation.decimal", "requerido" => "Presupuestos.validation.decimal", ], @@ -49,7 +51,7 @@ class PresupuestoServiciosExtraModel extends \App\Models\BaseModel $modelTarifa = model('App\Models\Tarifas\TarifaextraModel'); $tarifa_value = $modelTarifa->getTarifaPresupuestoExtra($tarifa_extra_id); if (count($tarifa_value)>0) { - + $ret_array = []; foreach($tarifa_value as $tarifa){ $result_data = $this->calcularTarifa($tarifa); @@ -74,7 +76,7 @@ class PresupuestoServiciosExtraModel extends \App\Models\BaseModel 'precio' => 0, 'margen' => 0, ]; - return $ret_array; + return $ret_array; } return []; } @@ -82,8 +84,8 @@ class PresupuestoServiciosExtraModel extends \App\Models\BaseModel private function calcularTarifa($tarifa){ $precio = floatval($tarifa->precio); - $precio = $precio * (1+ floatval($tarifa->margen)/100.0); - $margen = $tarifa->margen; + $precio = $precio * (1+ floatval($tarifa->margen)/100.0); + $margen = $tarifa->margen; return [$precio, $margen]; } @@ -110,15 +112,15 @@ class PresupuestoServiciosExtraModel extends \App\Models\BaseModel public function updateTarifas($presupuesto_id, $tarifas){ foreach($tarifas as $tarifa){ - + $builder = $this->db ->table($this->table . " t1"); $builder->select("id"); - $builder->where('presupuesto_id', $presupuesto_id); - $builder->where('tarifa_extra_id', $tarifa->tarifa_id); + $builder->where('presupuesto_id', $presupuesto_id); + $builder->where('tarifa_extra_id', $tarifa->tarifa_id); $result = $builder->get()->getResultObject(); if(count($result)>0){ - + $this->db ->table($this->table . " t1") ->where('presupuesto_id', $presupuesto_id) @@ -126,7 +128,7 @@ class PresupuestoServiciosExtraModel extends \App\Models\BaseModel ->set('precio', $tarifa->precio) ->set('margen', $tarifa->margen) ->update(); - + } else{ 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 5b15cddd..eef7b00a 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 @@ -268,37 +268,31 @@

Servicios extra

-
-
-
- - -
-
- - -
-
- - -
-
- - -
-
+
+
+
-
+
+ + +
+ +
+ + +
+ + +
+
diff --git a/ci4/app/Views/themes/vuexy/form/presupuestos/cliente/viewPresupuestoclienteForm.php b/ci4/app/Views/themes/vuexy/form/presupuestos/cliente/viewPresupuestoclienteForm.php index 4e6d56e5..7118c132 100644 --- a/ci4/app/Views/themes/vuexy/form/presupuestos/cliente/viewPresupuestoclienteForm.php +++ b/ci4/app/Views/themes/vuexy/form/presupuestos/cliente/viewPresupuestoclienteForm.php @@ -183,35 +183,8 @@
Servicios extra
-
-
    -
  • - Prototipo
  • -
-
    -
  • - Ferro
  • -
-
    -
  • - Ferro digital
  • -
-
    -
  • - Marcapáginas
  • -
-
    -
  • - Retractilado
  • -
-
    -
  • - Retractilado de 5
  • -
+
+
diff --git a/httpdocs/assets/js/safekat/pages/presupuestoCliente/datosGenerales.js b/httpdocs/assets/js/safekat/pages/presupuestoCliente/datosGenerales.js index 3dcac622..23736d72 100644 --- a/httpdocs/assets/js/safekat/pages/presupuestoCliente/datosGenerales.js +++ b/httpdocs/assets/js/safekat/pages/presupuestoCliente/datosGenerales.js @@ -165,7 +165,7 @@ class DatosGenerales { if (value4.length > 0 && Number.isInteger(parseInt(value4)) && parseInt(value4) > 0) { tiradas.push(value4); } - // comprobar si hay valores > 30 + // comprobar si hay valores > 30 const noPOD = (tiradas.some(tirada => parseInt(tirada) > 30)); const siPOD = (tiradas.some(tirada => parseInt(tirada) <= 30)); if (noPOD && siPOD) { @@ -362,7 +362,7 @@ class DatosGenerales { `); return false; } - + }, } } @@ -478,7 +478,7 @@ class DatosGenerales { // servicios extra menu_off = true; - if(this.prototipo.is(':checked')){ + /*if(this.prototipo.is(':checked')){ this.rl_prototipo.removeClass("d-none"); menu_off = false; } @@ -493,7 +493,7 @@ class DatosGenerales { else{ this.rl_ferro.addClass('d-none'); } - + if(this.ferroDigital.is(':checked')){ this.rl_ferroDigital.removeClass("d-none"); menu_off = false; @@ -501,29 +501,67 @@ class DatosGenerales { else{ this.rl_ferroDigital.addClass('d-none'); } +*/ + $('#rl-servicios-extra-items').empty(); if(this.marcapaginas.is(':checked')){ - this.rl_marcapaginas.removeClass("d-none"); + let $ul = $('
    ', { + class: 'list-group list-group-timeline' + }); + + let $li = $('
  • ', { + class: 'list-group-item list-group-timeline-primary texto-resumen-lateral', + text: 'Marcapáginas' + }); + + $ul.append($li); + $('#rl-servicios-extra-items').append($ul); menu_off = false; } - else{ - this.rl_marcapaginas.addClass('d-none'); - } if(this.retractilado.is(':checked')){ - this.rl_retractilado.removeClass("d-none"); + let $ul = $('
      ', { + class: 'list-group list-group-timeline' + }); + + let $li = $('
    • ', { + class: 'list-group-item list-group-timeline-primary texto-resumen-lateral', + text: 'Retractilado' + }); + + $ul.append($li); + $('#rl-servicios-extra-items').append($ul); menu_off = false; } - else{ - this.rl_retractilado.addClass('d-none'); - } if(this.retractilado5.is(':checked')){ - this.rl_retractilado5.removeClass("d-none"); + let $ul = $('
        ', { + class: 'list-group list-group-timeline' + }); + + let $li = $('
      • ', { + class: 'list-group-item list-group-timeline-primary texto-resumen-lateral', + text: 'Retractilado de 5' + }); + + $ul.append($li); + $('#rl-servicios-extra-items').append($ul); menu_off = false; } - else{ - this.rl_retractilado5.addClass('d-none'); + + const serviciosExtra = $('input[type="checkbox"][data-tarifa-tipo="extra"]:checked'); + for(let i=0; i', { + class: 'list-group list-group-timeline' + }); + + let $li = $('
      • ', { + class: 'list-group-item list-group-timeline-primary texto-resumen-lateral', + text: '' + $(serviciosExtra[i]).data('tarifa-nombre') + }); + + $ul.append($li); + $('#rl-servicios-extra-items').append($ul); } if(!menu_off){ @@ -603,9 +641,23 @@ class DatosGenerales { } } - this.prototipo.prop('checked', datos.prototipo); - this.ferro.prop('checked', datos.ferro); - this.ferroDigital.prop('checked', datos.ferroDigital); + + if(datos.serviciosExtra){ + + let serviciosExtra = $('input[type="checkbox"][data-tarifa-tipo="extra"]'); + + $(serviciosExtra).each(function() { + let tarifaId = $(this).data('tarifa-id') + ""; + + if (datos.serviciosExtra.includes(tarifaId)) { + $(this).prop('checked', true); + } + }); + } + + //this.prototipo.prop('checked', datos.prototipo); + //this.ferro.prop('checked', datos.ferro); + //this.ferroDigital.prop('checked', datos.ferroDigital); this.marcapaginas.prop('checked', datos.marcapaginas); this.retractilado.prop('checked', datos.retractilado); this.retractilado5.prop('checked', datos.retractilado5); @@ -805,7 +857,7 @@ class DatosGenerales { this.pagColorConsecutivas.prop('checked', false); if(lastLayoutColor && !this.cargando){ - + $('#divPapelInterior').empty(); $('#divGramajeInterior').empty(); $('#negroEstandar').trigger('click'); @@ -820,7 +872,7 @@ class DatosGenerales { this.divPosPaginasColor.removeClass('d-none'); if(!lastLayoutColor && !this.cargando){ - + $('#divPapelInterior').empty(); $('#divGramajeInterior').empty(); $('#colorEstandar').trigger('click'); @@ -836,7 +888,7 @@ class DatosGenerales { const divTipoLibro = $('#divTipoLibro'); // Selecciona el div divTipoLibro.find('.fv-plugins-message-container').remove(); - + if ($('#cosido').hasClass('selected') || $('#grapado').hasClass('selected')) { const value = parseInt($("#paginas").val()); if (value % 4 != 0) { @@ -920,6 +972,26 @@ class DatosGenerales { } } + getServiciosExtra() { + + let serviciosExtra = $('input[type="checkbox"][data-tarifa-tipo="extra"]:checked'); + + if (serviciosExtra.length === 0) { + return []; + } + + let servicios = []; + + $(serviciosExtra).each(function() { + let tarifaId = $(this).data('tarifa-id'); + if (tarifaId) { + servicios.push(tarifaId); + } + }); + + return servicios; + } + } diff --git a/httpdocs/assets/js/safekat/pages/presupuestoCliente/presupuestoCliente.js b/httpdocs/assets/js/safekat/pages/presupuestoCliente/presupuestoCliente.js index d303deca..8965dea4 100644 --- a/httpdocs/assets/js/safekat/pages/presupuestoCliente/presupuestoCliente.js +++ b/httpdocs/assets/js/safekat/pages/presupuestoCliente/presupuestoCliente.js @@ -632,7 +632,7 @@ class PresupuestoCliente { } } - } + } this.lc.val(parseFloat(response.info.lomo_cubierta).toFixed(2)); this.lsc.val(parseFloat(response.info.lomo_sobrecubierta).toFixed(2)); @@ -773,12 +773,13 @@ class PresupuestoCliente { this.datos.excluirRotativa = this.datosGenerales.excluirRotativa.is(':checked') ? 1 : 0; this.datos.ivaReducido = this.datosGenerales.ivaReducido.find('option:selected').val(); this.datos.servicios = { - 'prototipo': this.datosGenerales.prototipo.is(':checked') ? 1 : 0, - 'ferro': this.datosGenerales.ferro.is(':checked') ? 1 : 0, - 'ferroDigital': this.datosGenerales.ferroDigital.is(':checked') ? 1 : 0, + //'prototipo': this.datosGenerales.prototipo.is(':checked') ? 1 : 0, + //'ferro': this.datosGenerales.ferro.is(':checked') ? 1 : 0, + //'ferroDigital': this.datosGenerales.ferroDigital.is(':checked') ? 1 : 0, 'marcapaginas': this.datosGenerales.marcapaginas.is(':checked') ? 1 : 0, 'retractilado': this.datosGenerales.retractilado.is(':checked') ? 1 : 0, 'retractilado5': this.datosGenerales.retractilado5.is(':checked') ? 1 : 0, + 'serviciosExtra': this.datosGenerales.getServiciosExtra(), }; let lomoRedondo = 0;