From f2a0d4fb164a84b4d1783be4f156e07f98a4b4a2 Mon Sep 17 00:00:00 2001 From: Jaime Jimenez Date: Tue, 19 Dec 2023 22:43:22 +0100 Subject: [PATCH] finalizado datos envios --- .../Clientes/Clientedirecciones.php | 45 +++- .../Presupuestos/Presupuestodirecciones.php | 60 +++++ .../PresupuestoDireccionesEntity.php | 5 + .../Language/en/PresupuestosDirecciones.php | 3 +- .../Language/es/PresupuestosDirecciones.php | 4 +- .../PresupuestoDireccionesModel.php | 10 +- .../cosidotapablanda/_datosEnvios.php | 229 ++++++++++++++---- .../cosidotapablanda/_datosLibroItems.php | 4 +- .../cosidotapablanda/_datosServiciosItems.php | 15 +- .../_presupuestoDireccionesForm.php | 90 ++++++- .../viewCosidotapablandaForm.php | 3 + 11 files changed, 409 insertions(+), 59 deletions(-) diff --git a/ci4/app/Controllers/Clientes/Clientedirecciones.php b/ci4/app/Controllers/Clientes/Clientedirecciones.php index fe170db6..7ee9a681 100755 --- a/ci4/app/Controllers/Clientes/Clientedirecciones.php +++ b/ci4/app/Controllers/Clientes/Clientedirecciones.php @@ -22,7 +22,50 @@ class Clientedirecciones extends \App\Controllers\GoBaseResourceController protected static $controllerSlug = 'clientedirecciones'; - + public function add(){ + if ($this->request->isAJAX()) { + + $reqData = $this->request->getPost(); + $cliente_id = $reqData['cliente_id'] ?? -1; + $att = $reqData['att'] ?? ""; + $email = $reqData['email'] ?? ""; + $direccion = $reqData['direccion'] ?? ""; + $pais_id = $reqData['paisId'] ?? -1; + $ccaa_id = $reqData['ccaaId'] ?? -1; + $provincia = $reqData['provincia'] ?? ""; + $municipio = $reqData['municipio'] ?? ""; + $cp = $reqData['cp'] ?? ""; + $telefono = $reqData['telefono'] ?? ""; + $alias = $reqData['alias'] ?? ""; + + $data = [ + "cliente_id" => $cliente_id, + "att" => $att, + "email" => $email, + "direccion" => $direccion, + "pais_id" => $pais_id, + "ccaa_id" => $ccaa_id, + "provincia" => $provincia, + "municipio" => $municipio, + "cp" => $cp, + "telefono" => $telefono, + "alias" => $alias, + ]; + $response = $this->model->insert($data); + + $newTokenHash = csrf_hash(); + $csrfTokenName = csrf_token(); + $data_ret = [ + 'data' => $response, + $csrfTokenName => $newTokenHash + ]; + return $this->respond($data_ret); + + } else { + return $this->failUnauthorized('Invalid request', 403); + } + } + public function menuItems() { diff --git a/ci4/app/Controllers/Presupuestos/Presupuestodirecciones.php b/ci4/app/Controllers/Presupuestos/Presupuestodirecciones.php index 5c4e8d90..c27b85fe 100755 --- a/ci4/app/Controllers/Presupuestos/Presupuestodirecciones.php +++ b/ci4/app/Controllers/Presupuestos/Presupuestodirecciones.php @@ -33,6 +33,61 @@ class Presupuestodirecciones extends \App\Controllers\GoBaseResourceController } + public function add(){ + if ($this->request->isAJAX()) { + + $reqData = $this->request->getPost(); + $presupuesto_id = $reqData['presupuesto_id'] ?? -1; + $tarifa_id = $reqData['tarifa_id'] ?? -1; + $cantidad = $reqData['cantidad'] ?? -1; + $peso = $reqData['peso'] ?? -1; + $att = $reqData['att'] ?? ""; + $email = $reqData['email'] ?? ""; + $direccion = $reqData['direccion'] ?? ""; + $pais_id = $reqData['paisId'] ?? -1; + $ccaa_id = $reqData['ccaaId'] ?? -1; + $provincia = $reqData['provincia'] ?? ""; + $municipio = $reqData['municipio'] ?? ""; + $cp = $reqData['cp'] ?? ""; + $telefono = $reqData['telefono'] ?? ""; + $precio = $reqData['precio'] ?? ""; + $margen = $reqData['margen'] ?? ""; + $proveedor = $reqData['proveedor'] ?? ""; + $proveedor_id = $reqData['proveedor_id'] ?? ""; + + $data = [ + "presupuesto_id" => $presupuesto_id, + "tarifa_id" => $tarifa_id, + "cantidad" => $cantidad, + "peso" => $peso, + "att" => $att, + "email" => $email, + "direccion" => $direccion, + "pais_id" => $pais_id, + "ccaa_id" => $ccaa_id, + "provincia" => $provincia, + "municipio" => $municipio, + "cp" => $cp, + "telefono" => $telefono, + "precio" => $precio, + "margen" => $margen, + "proveedor" => $proveedor, + "proveedor_id" => $proveedor_id, + ]; + $response = $this->model->insert($data); + + $newTokenHash = csrf_hash(); + $csrfTokenName = csrf_token(); + $data_ret = [ + 'data' => $response, + $csrfTokenName => $newTokenHash + ]; + return $this->respond($data_ret); + + } else { + return $this->failUnauthorized('Invalid request', 403); + } + } public function datatable() { @@ -73,6 +128,11 @@ class Presupuestodirecciones extends \App\Controllers\GoBaseResourceController $model = model('App\Models\Tarifas\TarifaEnvioModel'); return $this->respond($model->getTarifaEnvio($paisId, $cp, $peso, $tipo_envio)); } + else if($reqData['tipo']=='clear_lineas'){ + + $presupuesto_id = $reqData['presupuesto_id'] ?? 0; + return $this->respond($this->model->where('presupuesto_id', $presupuesto_id)->delete()); + } } else { diff --git a/ci4/app/Entities/Presupuestos/PresupuestoDireccionesEntity.php b/ci4/app/Entities/Presupuestos/PresupuestoDireccionesEntity.php index 33e5386a..3eb3bb77 100755 --- a/ci4/app/Entities/Presupuestos/PresupuestoDireccionesEntity.php +++ b/ci4/app/Entities/Presupuestos/PresupuestoDireccionesEntity.php @@ -7,6 +7,7 @@ class PresupuestoDireccionesEntity extends \CodeIgniter\Entity\Entity { protected $attributes = [ "id" => null, + "tarifa_id" => null, "presupuesto_id" => null, "cantidad" => null, "peso" => null, @@ -20,10 +21,13 @@ class PresupuestoDireccionesEntity extends \CodeIgniter\Entity\Entity "cp" => null, "telefono" => null, "precio" => null, + "proveedor" => null, + "proveedor_id" => null, "margen" => null, ]; protected $casts = [ "presupuesto_id" => "int", + "tarifa_id" => "int", "cantidad" => "int", "peso" => "float", "pais_id" => "int", @@ -31,6 +35,7 @@ class PresupuestoDireccionesEntity extends \CodeIgniter\Entity\Entity "cp" => "int", "precio" => "float", "margen" => "float", + "proveedor_id" => "int", ]; } diff --git a/ci4/app/Language/en/PresupuestosDirecciones.php b/ci4/app/Language/en/PresupuestosDirecciones.php index 28487dbe..2d625fbe 100755 --- a/ci4/app/Language/en/PresupuestosDirecciones.php +++ b/ci4/app/Language/en/PresupuestosDirecciones.php @@ -14,13 +14,14 @@ return [ 'telefono' => 'Phone', 'peso' => 'Weight', 'cantidad' => 'Quantity', + 'proveedor' => 'Supplier', 'precio' => 'Price', 'saveDirection' => 'Save to client addresses', 'validation' => [ 'max_length' => 'Max. length ', 'required' => 'Field required', 'valid_email' => 'The email is not valid', - + 'no_tarifa' => 'There is no rate for the indicated address' ], 'selectPais' => 'Select a country', diff --git a/ci4/app/Language/es/PresupuestosDirecciones.php b/ci4/app/Language/es/PresupuestosDirecciones.php index 740c9a19..475f518e 100755 --- a/ci4/app/Language/es/PresupuestosDirecciones.php +++ b/ci4/app/Language/es/PresupuestosDirecciones.php @@ -16,13 +16,15 @@ return [ 'telefono' => 'Teléfono', 'peso' => 'Peso', 'cantidad' => 'Cantidad', - 'precio' => 'Precio', + 'proveedor' => 'Proveedor', + 'precio' => 'Precio', 'saveDirection' => 'Guardar en direcciones de cliente', 'entregaPieCalle' => 'Entrega a pie de calle', 'validation' => [ 'max_length' => 'Max. valor caracteres alcanzado', 'required' => 'Campo obligatorio', 'valid_email' => 'El email introducido no es válido', + 'no_tarifa' => 'No hay tarifa para la dirección indicada' ], diff --git a/ci4/app/Models/Presupuestos/PresupuestoDireccionesModel.php b/ci4/app/Models/Presupuestos/PresupuestoDireccionesModel.php index 2c89671c..fa1e3eed 100755 --- a/ci4/app/Models/Presupuestos/PresupuestoDireccionesModel.php +++ b/ci4/app/Models/Presupuestos/PresupuestoDireccionesModel.php @@ -23,9 +23,12 @@ class PresupuestoDireccionesModel extends \App\Models\GoBaseModel 6 => "t1.provincia", 7 => "t2.nombre", 8 => "t1.telefono", + 9 => "t1.precio", + 10 => "t1.proveedor", ]; protected $allowedFields = [ + "tarifa_id", "presupuesto_id", "cantidad", "peso", @@ -40,6 +43,8 @@ class PresupuestoDireccionesModel extends \App\Models\GoBaseModel "telefono", 'precio', 'margen', + "proveedor_id", + "proveedor", ]; protected $returnType = "App\Entities\Clientes\ClienteDireccionesEntity"; @@ -60,11 +65,12 @@ class PresupuestoDireccionesModel extends \App\Models\GoBaseModel $builder = $this->db ->table($this->table . " t1") ->select( - "t1.id AS id, t1.presupuesto_id AS presupuesto_id, t1.att AS att, + "t1.id AS id, t1.presupuesto_id AS presupuesto_id, t1.tarifa_id AS tarifa_id, t1.att AS att, t1.email AS email, t1.direccion AS direccion, t1.pais_id AS pais_id, t2.nombre AS pais, t1.ccaa_id AS ccaa_id, t3.nombre AS ccaa_nombre, t1.municipio AS municipio, t1.provincia AS provincia, t1.cp AS cp, t1.telefono AS telefono, - t1.cantidad AS cantidad, t1.precio AS precio, t1.margen AS margen" + t1.peso AS peso, t1.cantidad AS cantidad, t1.precio AS precio, t1.margen AS margen, + t1.proveedor_id AS proveedor_id, t1.proveedor AS proveedor" ); $builder->where('t1.presupuesto_id', $presupuesto_id); diff --git a/ci4/app/Views/themes/backend/vuexy/form/presupuestos/cosidotapablanda/_datosEnvios.php b/ci4/app/Views/themes/backend/vuexy/form/presupuestos/cosidotapablanda/_datosEnvios.php index 8219ce4f..90db7d7f 100755 --- a/ci4/app/Views/themes/backend/vuexy/form/presupuestos/cosidotapablanda/_datosEnvios.php +++ b/ci4/app/Views/themes/backend/vuexy/form/presupuestos/cosidotapablanda/_datosEnvios.php @@ -10,29 +10,34 @@
- - - - - - - - - - - - - - - - - - - - - - -
+
+ + + + + + + + + + + + + + + + + + + + + + + + + +
Tarifa_idProveedor_idMargen
+
@@ -41,7 +46,7 @@
-
+
@@ -57,6 +62,7 @@ section("additionalInlineJs") ?> $('#insertar_direccion').on('click', function(){ + $("#addressForm").attr('action','create') var $newAddDialog = $("#addressForm") var maximaCantidad = parseInt($('#tirada').val()) @@ -65,22 +71,54 @@ $('#insertar_direccion').on('click', function(){ $("#add_cantidad").on('change', function(){ $("#add_cantidad").val(parseInt($("#add_cantidad").val())>maximaCantidad ? maximaCantidad : $("#add_cantidad").val()) }) + + cantidad_total = 0 + tableEnvios.rows().every( function ( rowIdx, tableLoop, rowLoop ) { + var data = this.data(); + cantidad_total += data.cantidad + } ); + $('#add_cantidad').attr('max-value', parseInt($('#tirada').val())-cantidad_total) + $('#add_cantidad').val(parseInt($('#tirada').val())-cantidad_total) $newAddDialog.modal('show') }) -const lastColNr = $('#tableOfDireccionesEnvio').find("tr:first th").length - 1; +const lastColNr_direcciones = $('#tableOfDireccionesEnvio').find("tr:first th").length - 1; const actionBtns_direcciones = function(data) { return ` - - - + `; }; +$(document).on('click', '.delete-add-row', function(e) { + const row = $(this).closest('tr'); + tableEnvios.row( row ) + .remove() + .draw(); + checkInsertar() +}) + +const paisList = ; +const ccaaList = ; + + +$('#recoger_en_taller').change(function(){ + if(this.checked) { + $('#rowTable').css('display', 'none') + $('#rowInsertar').css('display', 'none') + tableEnvios.clear().draw() + } + else{ + $('#rowTable').css('display', 'flex') + $('#rowInsertar').css('display', 'flex') + tableEnvios.columns.adjust(); + } +}) + + var tableEnvios = $('#tableOfDireccionesEnvio').DataTable( { draw:5, - serverSide: true, + serverSide: false, processing: true, autoWidth: true, responsive: true, @@ -90,17 +128,10 @@ var tableEnvios = $('#tableOfDireccionesEnvio').DataTable( { searching: false, paging: false, info: false, + scrollX: true, - ajax : $.fn.dataTable.pipeline( { - url: '', - data: function ( d ) { - d.presupuesto_id = id; - }, - method: 'POST', - headers: {'X-Requested-With': 'XMLHttpRequest'}, - async: true, - }), columns: [ + { 'data': 'tarifa_id' }, { 'data': 'cantidad' }, { 'data': 'peso' }, { 'data': 'att' }, @@ -109,9 +140,21 @@ var tableEnvios = $('#tableOfDireccionesEnvio').DataTable( { { 'data': 'cp' }, { 'data': 'municipio' }, { 'data': 'provincia' }, - { 'data': 'ccaaId' }, - { 'data': 'paisId' }, + { 'data': 'ccaaId' , + render: function(data, type, row, meta) { + var value = ccaaList.find(element => element.id === data); + return value['nombre']; + }, + }, + { 'data': 'paisId' , + render: function(data, type, row, meta) { + var value = paisList.find(element => element.id === data); + return value['nombre']; + }, + }, { 'data': 'telefono' }, + { 'data': 'proveedor'}, + { 'data': 'proveedor_id'}, { 'data': 'precio' }, { 'data': 'margen' }, { @@ -123,14 +166,118 @@ var tableEnvios = $('#tableOfDireccionesEnvio').DataTable( { { orderable: false, searchable: false, - targets: [lastColNr] + targets: [lastColNr_direcciones] }, {"orderData": [ 0], "targets": 0 }, ], + columnDefs: [ + { + target: [0,13,15], + visible: false, + searchable: false + }, + ], language: { url: "//cdn.datatables.net/plug-ins/1.13.4/i18n/i18n ?>.json" }, } ); + + +function checkInsertar(){ + cantidad_total = 0 + tableEnvios.rows().every( function ( rowIdx, tableLoop, rowLoop ) { + var data = this.data(); + cantidad_total += data.cantidad + } ); + if(cantidad_total < parseInt($('#tirada').val())){ + $('#rowInsertar').css('display', 'flex') + } + else{ + $('#rowInsertar').css('display', 'none') + } +} + +function save_datos_envios(){ + $.post( '', + { + tipo: "clear_lineas", + presupuesto_id: id, + : v, + }) + .done(function( data ) { + + tableEnvios.rows().every( function ( rowIdx, tableLoop, rowLoop ) { + var data = this.data(); + $.post( '/presupuestos/presupuestodirecciones/add', + { + presupuesto_id : id, + tarifa_id : data.tarifa_id, + cantidad : data.cantidad, + peso : data.peso, + att : data.att, + email : data.email, + direccion : data.direccion, + paisId : data.paisId, + ccaaId : data.ccaaId, + provincia : data.provincia, + municipio : data.municipio, + cp : data.cp, + telefono : data.telefono, + precio : data.precio, + margen : data.margen, + proveedor : data.proveedor, + proveedor_id : data.proveedor_id, + : v, + }) + }); + + }) + +} + +function load_datos_envios(){ + $.post( '', + { + draw: 1, + columns: 1, + search: { + value: "", + }, + presupuesto_id: id, + : v, + }) + .done(function( data ) { + console.log(data) + data.data.forEach((linea) => { + tableEnvios.row + .add({ + 'tarifa_id': linea.tarifa_id, + 'cantidad': linea.cantidad, + 'peso': linea.peso, + 'att': linea.att, + 'email': linea.email, + 'direccion': linea.direccion, + 'cp': linea.cp, + 'municipio': linea.municipio, + 'provincia': linea.provincia, + 'ccaaId': linea.ccaa_id, + 'paisId': linea.pais_id, + 'telefono': linea.telefono, + 'proveedor': linea.proveedor, + 'proveedor_id': linea.proveedor_id, + 'precio': linea.precio, + 'margen': linea.margen, + 'actionBtns_direcciones': actionBtns_direcciones, + }) + .draw(); + }); + }) +} + + +checkInsertar() +load_datos_envios() + endSection() ?> \ No newline at end of file diff --git a/ci4/app/Views/themes/backend/vuexy/form/presupuestos/cosidotapablanda/_datosLibroItems.php b/ci4/app/Views/themes/backend/vuexy/form/presupuestos/cosidotapablanda/_datosLibroItems.php index 91041959..884a8e28 100755 --- a/ci4/app/Views/themes/backend/vuexy/form/presupuestos/cosidotapablanda/_datosLibroItems.php +++ b/ci4/app/Views/themes/backend/vuexy/form/presupuestos/cosidotapablanda/_datosLibroItems.php @@ -286,12 +286,12 @@ $('#paginas').on("change", function () { document.getElementById('compPaginasColorhq').value = 0; } - update_servicios() + update_servicios(false) }); $('#tirada').on("change", function () { - update_servicios() + update_servicios(false) }) $('#papelFormatoId').select2({ diff --git a/ci4/app/Views/themes/backend/vuexy/form/presupuestos/cosidotapablanda/_datosServiciosItems.php b/ci4/app/Views/themes/backend/vuexy/form/presupuestos/cosidotapablanda/_datosServiciosItems.php index de30b5e6..a569c4ad 100755 --- a/ci4/app/Views/themes/backend/vuexy/form/presupuestos/cosidotapablanda/_datosServiciosItems.php +++ b/ci4/app/Views/themes/backend/vuexy/form/presupuestos/cosidotapablanda/_datosServiciosItems.php @@ -367,7 +367,7 @@ ) } - function update_servicios(){ + function update_servicios(update_preimpresion=false){ const domain = window.location.origin const dimension = getDimensionLibro(); @@ -382,7 +382,8 @@ var datosAcabado = get_datos_acabado() var datosEnc = get_datos_encuadernacion() var datosManipulado = get_datos_manipulado() - var datosPreimpresion = get_datos_preimpresion() + if(update_preimpresion) + var datosPreimpresion = get_datos_preimpresion() fetch(domain + "/presupuestos/presupuestoacabados/update/" + id , { method: "POST", @@ -471,10 +472,12 @@ }) .then(response => response.json()) .then(data => { - data.lines.forEach((line) => { - $('#precio_preimpresion_' + line[0].tarifa_id).val(parseFloat(line[0].total).toFixed(2)) - $('#preimpresion_margen_' + line[0].tarifa_id).val(parseFloat(line[0].margen).toFixed(2)) - }); + if(update_preimpresion){ + data.lines.forEach((line) => { + $('#precio_preimpresion_' + line[0].tarifa_id).val(parseFloat(line[0].total).toFixed(2)) + $('#preimpresion_margen_' + line[0].tarifa_id).val(parseFloat(line[0].margen).toFixed(2)) + }); + } yeniden(data.); }) ) diff --git a/ci4/app/Views/themes/backend/vuexy/form/presupuestos/cosidotapablanda/_presupuestoDireccionesForm.php b/ci4/app/Views/themes/backend/vuexy/form/presupuestos/cosidotapablanda/_presupuestoDireccionesForm.php index 7140cc33..bd309aa0 100755 --- a/ci4/app/Views/themes/backend/vuexy/form/presupuestos/cosidotapablanda/_presupuestoDireccionesForm.php +++ b/ci4/app/Views/themes/backend/vuexy/form/presupuestos/cosidotapablanda/_presupuestoDireccionesForm.php @@ -6,6 +6,7 @@