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 cda2f588..87bcab14 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 @@ -90,6 +90,91 @@ const actionBtns_direcciones = function(data) { `; }; +function updateTablaEnvios(){ + + var peso_total_libro = 0 + tableLineasPresupuesto.rows().every( function ( rowIdx, tableLoop, rowLoop ) { + var rowData = this.data(); + peso_total_libro += parseFloat(rowData.peso) + + }) + + tableEnvios.rows().every( function ( rowIdx, tableLoop, rowLoop ) { + var rowData = this.data(); + const peso_envio = peso_total_libro*parseInt(rowData.cantidad)/1000.0 + + + $.post( '', + { + tipo: "get_tarifa", + peso: peso_envio, + paisId: rowData.paisId, + cp: rowData.cp, + tipo_envio: parseInt(rowData.entregaPieCalle)==1?'palets':'cajas', + : v, + }) + .done(function( data ) { + if(data.length >0){ + + var precios = [] + for (var i = 0; i < data.length; i++) { + if(peso_envio>data[i].peso_max){ + data[i].precio = (data[i].peso_min + (peso_envio-data[i].peso_min)*data[i].precio_adicional).toFixed(2); + } + // si no se calcula linealmente + else{ + m=((data[i].precio_max-data[i].precio_min)/(data[i].peso_max-data[i].peso_min)) + b=data[i].precio_max-m*data[i].peso_max + data[i].precio = (m*peso_envio+b).toFixed(2); + } + data[i].margen = data[i].margen + } + + const tarifa_final = data.reduce((previous, current) => { + return current.precio < previous.precio ? current : previous; + }); + tarifa_final.cantidad=parseInt($('#add_cantidad').val()) + tarifa_final.peso=peso_envio + + + tableEnvios.row(rowIdx) + .data({ + 'tarifa_id': tarifa_final.id, + 'cantidad': rowData.cantidad, + 'peso': tarifa_final.peso.toFixed(3), + 'att': rowData.att, + 'email': rowData.email, + 'direccion': rowData.direccion, + 'cp': rowData.cp, + 'municipio': rowData.municipio, + 'provincia': rowData.provincia, + 'paisId': rowData.paisId, + 'telefono': rowData.telefono, + 'proveedor': tarifa_final.proveedor, + 'proveedor_id': tarifa_final.proveedor_id, + 'precio': tarifa_final.precio, + 'margen': tarifa_final.margen, + 'entregaPieCalle': rowData.entregaPieCalle, + 'actionBtns_direcciones': actionBtns_direcciones, + }) + .draw(); + + + checkInsertar() + updateTotales(false, false, true) + + } + else{ + popErrorAlert('', 'error-tarifa') + } + + }); + }) + + + +} + $(document).on('click', '.delete-add-row', function(e) { const row = $(this).closest('tr'); tableEnvios.row( row ) 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 86d90e7f..8262216d 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 @@ -249,7 +249,11 @@ section("additionalInlineJs") ?> $('#paginas').on("change", function () { - if(url_parts[url_parts.length-2] == 'edit'){ + + const url2 = window.location.href; + const url_parts2 = url2.split('/'); + + if(url_parts2[url_parts2.length-2] == 'edit'){ checkPaginasPresupuesto() updateLineasPresupuesto() @@ -274,9 +278,10 @@ $('#tirada').on("change", function () { calcular_mermas() - const url = window.location.href; - const url_parts = url.split('/'); - if(url_parts[url_parts.length-2] == 'edit'){ + const url2 = window.location.href; + const url_parts2 = url2.split('/'); + + if(url_parts2[url_parts2.length-2] == 'edit'){ update_servicios(false) updateLineasPresupuesto() checkInsertar() diff --git a/ci4/app/Views/themes/backend/vuexy/form/presupuestos/cosidotapablanda/_lineasPresupuestoItems.php b/ci4/app/Views/themes/backend/vuexy/form/presupuestos/cosidotapablanda/_lineasPresupuestoItems.php index e70895d9..4981fc6e 100755 --- a/ci4/app/Views/themes/backend/vuexy/form/presupuestos/cosidotapablanda/_lineasPresupuestoItems.php +++ b/ci4/app/Views/themes/backend/vuexy/form/presupuestos/cosidotapablanda/_lineasPresupuestoItems.php @@ -88,7 +88,7 @@ function format(d) { ''+ ''+ ''+ - '
' + + '
' + '
' + "" + ''+ @@ -151,7 +151,7 @@ function format(d) { ''+ ''+ ''+ - '
' + + '
' + '
' + '' + '
'+ @@ -183,7 +183,7 @@ function format(d) { '' + '' + '
' + - '
' + + '
' + '' + '' + '
' + @@ -202,7 +202,7 @@ function format(d) { ''+ ''+ ''+ - '
' + + '
' + (d.row_id.includes('rot')?'
': '