From 3a43f90ef97e09915951d1ba234815ea29e414e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaime=20Jim=C3=A9nez?= Date: Wed, 13 Dec 2023 15:33:56 +0100 Subject: [PATCH] trabajando en resumen --- .../PresupuestoEncuadernacionesEntity.php | 2 + .../PresupuestoEncuadernacionesModel.php | 37 +++++++++++---- .../cosidotapablanda/_datosServiciosItems.php | 17 +++++-- .../_lineasPresupuestoItems.php | 4 +- .../_resumenPresupuestoItems.php | 45 +++++++++++++++++-- 5 files changed, 87 insertions(+), 18 deletions(-) diff --git a/ci4/app/Entities/Presupuestos/PresupuestoEncuadernacionesEntity.php b/ci4/app/Entities/Presupuestos/PresupuestoEncuadernacionesEntity.php index e1ce106d..9716d26d 100755 --- a/ci4/app/Entities/Presupuestos/PresupuestoEncuadernacionesEntity.php +++ b/ci4/app/Entities/Presupuestos/PresupuestoEncuadernacionesEntity.php @@ -11,6 +11,7 @@ class PresupuestoEncuadernacionesEntity extends \CodeIgniter\Entity\Entity "tarifa_encuadernado_id" => null, "precio_unidad" => null, "precio_total" => null, + "margen" => null, "created_at" => null, "updated_at" => null, ]; @@ -19,5 +20,6 @@ class PresupuestoEncuadernacionesEntity extends \CodeIgniter\Entity\Entity "tarifa_encuadernado_id" => "int", "precio_unidad" => "float", "precio_total" => "float", + "margen" => "float", ]; } diff --git a/ci4/app/Models/Presupuestos/PresupuestoEncuadernacionesModel.php b/ci4/app/Models/Presupuestos/PresupuestoEncuadernacionesModel.php index 9b75d5ab..a2e0b46c 100755 --- a/ci4/app/Models/Presupuestos/PresupuestoEncuadernacionesModel.php +++ b/ci4/app/Models/Presupuestos/PresupuestoEncuadernacionesModel.php @@ -21,7 +21,7 @@ class PresupuestoEncuadernacionesModel extends \App\Models\GoBaseModel 4 => "t1.precio_total" ]; - protected $allowedFields = ["presupuesto_id", "tarifa_encuadernado_id", "nombre", "precio_total", "precio_unidad"]; + protected $allowedFields = ["presupuesto_id", "tarifa_encuadernado_id", "nombre", "precio_total", "precio_unidad", "margen"]; protected $returnType = "App\Entities\Presupuestos\PresupuestoEncuadernacionesEntity"; protected $useTimestamps = true; @@ -66,17 +66,22 @@ class PresupuestoEncuadernacionesModel extends \App\Models\GoBaseModel $tarifa_value = $modelTarifa->getTarifaPresupuestoEncuadernacionHoras($tarifa['tarifa_id'], $tiempo, $tirada); if (count($tarifa_value)>0) { - $result_data[0] = floatval(1.0* $tarifa_value[0]->precio_hora* $tiempo / $tirada); - $result_data[1] = floatval(1.0* $tarifa_value[0]->precio_hora* $tiempo) ; + $precio_total = floatval(1.0* $tarifa_value[0]->precio_hora* $tiempo) * (1+$tarifa_value[0]->margen/100.0); if (!$POD){ - $result_data[1] += floatval($tarifa_value[0]->tarifa_importe_fijo); + $precio_total += floatval($tarifa_value[0]->tarifa_importe_fijo); } + + $result_data[0] = floatval($precio_total / $tirada); // Precio/unidad + $result_data[1] = $precio_total; + $result_data[2] = $precio_total * ($tarifa_value[0]->margen/100.0) ; // margen + array_push($tarifas, (object)[ 'tarifa_id'=> $tarifa['tarifa_id'], 'tarifa_nombre'=> $tarifa_value[0]->tarifa_enc_nombre, 'precio_unidad'=> $result_data[0], 'total'=> $result_data[1], + 'margen' => $result_data[2], 'proveedor' => $tarifa_value[0]->proveedor_nombre, 'proveedor_id' => $tarifa_value[0]->proveedor_id, ]); @@ -89,6 +94,7 @@ class PresupuestoEncuadernacionesModel extends \App\Models\GoBaseModel 'proveedor' => lang('Presupuestos.no_disponible'), 'precio_unidad'=> 0, 'total'=> 0, + 'margen' => 0, ]); } } @@ -102,6 +108,7 @@ class PresupuestoEncuadernacionesModel extends \App\Models\GoBaseModel 'tarifa_nombre'=> $tarifa_value[0]->tarifa_enc_nombre, 'precio_unidad'=> $result_data[0], 'total'=> $result_data[1], + 'margen'=> $result_data[2], 'proveedor' => $tarifa_value[0]->proveedor_nombre, 'proveedor_id' => $tarifa_value[0]->proveedor_id, ]); @@ -114,6 +121,7 @@ class PresupuestoEncuadernacionesModel extends \App\Models\GoBaseModel 'proveedor' => lang('Presupuestos.no_disponible'), 'precio_unidad'=> 0, 'total'=> 0, + 'margen' => 0, ]); } } @@ -162,6 +170,7 @@ class PresupuestoEncuadernacionesModel extends \App\Models\GoBaseModel 'tarifa_nombre'=> $tarifa_value[0]->tarifa_enc_nombre, 'precio_unidad'=> $result_data[0], 'total'=> $result_data[1], + 'margen'=> $result_data[2], 'proveedor' => $tarifa_value[0]->proveedor_nombre, 'proveedor_id' => $tarifa_value[0]->proveedor_id, ]; @@ -174,6 +183,7 @@ class PresupuestoEncuadernacionesModel extends \App\Models\GoBaseModel 'proveedor' => lang('Presupuestos.no_disponible'), 'precio_unidad'=> 0, 'total'=> 0, + 'marge'=> 0, ]; return $ret_array; } @@ -189,16 +199,21 @@ class PresupuestoEncuadernacionesModel extends \App\Models\GoBaseModel $tarifa_value = $modelTarifa->getTarifaPresupuestoEncuadernacionHoras($tarifa_encuadernacion_id, $tiempo, $tirada, $proveedor_id); if (count($tarifa_value)>0) { - $result_data[0] = floatval(1.0* $tarifa_value[0]->precio_hora* $tiempo / $tirada); - $result_data[1] = floatval(1.0* $tarifa_value[0]->precio_hora* $tiempo) ; + $precio_total = floatval(1.0* $tarifa_value[0]->precio_hora* $tiempo) * (1+$tarifa_value[0]->margen/100.0); if (!$POD){ - $result_data[1] += floatval($tarifa_value[0]->tarifa_importe_fijo); + $precio_total += floatval($tarifa_value[0]->tarifa_importe_fijo); } + + $result_data[0] = floatval($precio_total / $tirada); // Precio/unidad + $result_data[1] = $precio_total; + $result_data[2] = $precio_total * ($tarifa_value[0]->margen/100.0) ; // margen + $ret_array[] = (object)[ 'tarifa_id'=> $tarifa_encuadernacion_id, 'tarifa_nombre'=> $tarifa_value[0]->tarifa_enc_nombre, 'precio_unidad'=> $result_data[0], 'total'=> $result_data[1], + 'margen' => $result_data[2], 'proveedor' => $tarifa_value[0]->proveedor_nombre, 'proveedor_id' => $tarifa_value[0]->proveedor_id, ]; @@ -211,6 +226,7 @@ class PresupuestoEncuadernacionesModel extends \App\Models\GoBaseModel 'proveedor' => lang('Presupuestos.no_disponible'), 'precio_unidad'=> 0, 'total'=> 0, + 'margen' => 0, ]; return $ret_array; } @@ -226,12 +242,13 @@ class PresupuestoEncuadernacionesModel extends \App\Models\GoBaseModel $precio_unidad = $precio_unidad* (1+ floatval($tarifa->margen)/100.0); $total = $precio_unidad * $paginas; + $margen = $total * (floatval($tarifa->margen)/100.0); if (!$is_POD){ $total += floatval($tarifa->tarifa_importe_fijo); } - return [$precio_unidad, $total]; + return [$precio_unidad, $total, $margen]; } @@ -285,6 +302,7 @@ class PresupuestoEncuadernacionesModel extends \App\Models\GoBaseModel ->set('proveedor_id', $proveedor, false) ->set('precio_unidad', $tarifa->precio_unidad) ->set('precio_total', $tarifa->precio_total) + ->set('margen', $tarifa->margen) ->update(); @@ -297,6 +315,7 @@ class PresupuestoEncuadernacionesModel extends \App\Models\GoBaseModel ->set('proveedor_id', $proveedor, false) ->set('precio_unidad', $tarifa->precio_unidad) ->set('precio_total', $tarifa->precio_total) + ->set('margen', $tarifa->margen) ->insert(); } } @@ -315,7 +334,7 @@ class PresupuestoEncuadernacionesModel extends \App\Models\GoBaseModel ->table($this->table . " t1") ->select( "t1.id AS id, t1.tarifa_encuadernado_id AS tarifa_encuadernado_id, t1.precio_unidad AS precio_unidad, - t1.precio_total AS precio_total, t2.nombre AS nombre, t1.proveedor_id AS proveedor_id, t3.nombre AS proveedor" + t1.precio_total AS precio_total, t1.margen AS margen, t2.nombre AS nombre, t1.proveedor_id AS proveedor_id, t3.nombre AS proveedor" ); $builder->where('t1.presupuesto_id', $presupuesto_id); 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 3c36f85d..82cee6d3 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 @@ -154,6 +154,7 @@ + @@ -624,6 +625,10 @@ language: { url: "//cdn.datatables.net/plug-ins/1.13.4/i18n/i18n ?>.json" }, + columnDefs: [{ + target: 5, + visible: false + }] }); @@ -651,7 +656,8 @@ '' + '', '' + parseFloat(element.precio_unidad).toFixed(2) + '', - '', + '', + '' + parseFloat(element.margen).toFixed(2) + '', '' ]).draw(false) @@ -725,6 +731,7 @@ $('#precio_unidad_encuadernado_' + datos.tarifa_encuadernacion_id).text(parseFloat(data.values[0].precio_unidad).toFixed(2)) $('#precio_total_encuadernado_' + datos.tarifa_encuadernacion_id).val(parseFloat(data.values[0].total).toFixed(2)) + $('#margen_' + datos.tarifa_encuadernacion_id).val(parseFloat(data.values[0].margen).toFixed(2)) yeniden(data.); return true; }, @@ -798,7 +805,8 @@ '' + '', '' + parseFloat(row.precio_unidad).toFixed(2) + '', - '', + '', + '' + parseFloat(row.margen).toFixed(2) + '', '' ]).draw(false) @@ -890,6 +898,9 @@ case 4: values['precio_total'] = $(this).children(":first").val() break + case 5: + values['margen'] = $(this).text() + break } }) if(Object.keys(values).length>0) @@ -939,7 +950,7 @@ element.tarifa_manipulado_id, element.nombre, '' + parseFloat(element.precio_unidad).toFixed(2) + '', - '', + '', '' ]).draw(false) 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 af97215a..ff740623 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 @@ -2698,12 +2698,12 @@ var tableLineasPresupuesto = new DataTable('#tableLineasPresupuesto',{ language: { url: "//cdn.datatables.net/plug-ins/1.13.4/i18n/i18n ?>.json" }, - /*columnDefs: [ + columnDefs: [ { target: 12, visible: false } - ]*/ + ] }); diff --git a/ci4/app/Views/themes/backend/vuexy/form/presupuestos/cosidotapablanda/_resumenPresupuestoItems.php b/ci4/app/Views/themes/backend/vuexy/form/presupuestos/cosidotapablanda/_resumenPresupuestoItems.php index d793ba60..d117abd4 100755 --- a/ci4/app/Views/themes/backend/vuexy/form/presupuestos/cosidotapablanda/_resumenPresupuestoItems.php +++ b/ci4/app/Views/themes/backend/vuexy/form/presupuestos/cosidotapablanda/_resumenPresupuestoItems.php @@ -30,9 +30,9 @@
NaN €
Coste servicios
-
NaN €
+
NaN €
Margen servicios
-
NaN €
+
NaN €
Costes
NaN €
@@ -83,8 +83,20 @@ $(".update-totales").on("change", updateTotales) function updateTotales(){ totalPapel = 0 margenPapel = 0 + totalImpresion = 0 - $('#tableLineasPresupuesto tbody tr:visible ').each(function(){ + + totalServicios = 0 + margenServicios = 0 + + tableLineasPresupuesto.rows({filter: 'applied'}).every( function ( rowIdx, tableLoop, rowLoop ) { + + /*totalServicios += parseFloat(tableServiciosEnc.cell(rowIdx, 4).node().lastChild.value) + margenServicios += parseFloat(tableServiciosEnc.cell(rowIdx, 5).node().lastChild.innerText) +*/ + }); + + /*$('#tableLineasPresupuesto tbody tr:visible ').each(function(){ if($('#' + this.id + '_checkPapel').prop('checked')){ totalPapel += parseFloat($('#' + this.id + '_totalPapelPedido').val()) margenPapel += parseFloat($('#' + this.id + '_margenPapelPedido').val()) @@ -92,12 +104,37 @@ function updateTotales(){ if($('#' + this.id + '_checkClicks').prop('checked')){ totalImpresion += parseFloat($('#' + this.id + '_totalClicks').val()) } - }) + })*/ + $('#totalCostePapel').text(totalPapel.toFixed(2) + '€') $('#margenPapel').text(margenPapel.toFixed(2) + '€') + $('#totalCosteImpresion').text(totalImpresion.toFixed(2) + '€') $('#margenImpresion').text((totalImpresion*$('#margenImpresionValue').val()/100.0).toFixed(2) + '€') + + tableServiciosEnc.rows().every( function ( rowIdx, tableLoop, rowLoop ) { + + totalServicios += parseFloat(tableServiciosEnc.cell(rowIdx, 4).node().lastChild.value) + margenServicios += parseFloat(tableServiciosEnc.cell(rowIdx, 5).node().lastChild.innerText) + + }); + + /*$('#tableOfServiciosEncuadernacion tbody tr').each(function(){ + console.log(this) + var currentRow = $(this).closest("tr"); + var data = $('#myTable').DataTable().row(currentRow).data(); + console.log(data) + //margenServicios += parseFloat(this.text()) + })*/ + /*$('#tableOfServiciosEncuadernacion tbody tr td:nth-child(4)').each(function(){ + totalServicios += parseFloat(this.text()) + })*/ + totalServicios -= margenServicios; + $('#totalServicios').text(totalServicios.toFixed(2) + '€') + $('#margenServicios').text(margenServicios.toFixed(2) + '€') + } endSection() ?> +