diff --git a/ci4/app/Controllers/Presupuestos/Cosidotapablanda.php b/ci4/app/Controllers/Presupuestos/Cosidotapablanda.php index ff49bedd..5c8abd5f 100644 --- a/ci4/app/Controllers/Presupuestos/Cosidotapablanda.php +++ b/ci4/app/Controllers/Presupuestos/Cosidotapablanda.php @@ -514,12 +514,14 @@ class Cosidotapablanda extends \App\Controllers\GoBaseResourceController if( $uso == 'cubierta' ){ $opciones_papel = array( 'cubierta' => 1, + 'color' => 1, 'rotativa' => 0, ); } else if ( $uso == 'sobrecubierta' ){ $opciones_papel = array( 'sobrecubierta' => 1, + 'color' => 1, 'rotativa' => 0, ); } diff --git a/ci4/app/Controllers/Test.php b/ci4/app/Controllers/Test.php index 758d560e..93c983c9 100644 --- a/ci4/app/Controllers/Test.php +++ b/ci4/app/Controllers/Test.php @@ -16,7 +16,7 @@ class Test extends BaseController public function index() { - $this->testLineasIntPlanaCubierta(); + $this->testLineasCubierta(); } public function testGetPrecioPliegoRotativa() @@ -248,5 +248,97 @@ class Test extends BaseController } } } + + public static function testLineasCubierta() + { + $uso = 'cubierta'; + $tipo = 'color'; + + $datosPedido = (object)array( + 'paginas' => 240, + 'tirada' => 100, + 'merma' => 10, + 'merma_portada' => 10, + 'ancho' => 150, + 'alto' => 210, + 'isCosido' => true, + 'solapas' => false, + ); + + $opciones_papel = array( + 'color' => 1, + 'cubierta' => 1, + ); + + + // Se obtienen los papeles disponibles + $papelimpresionmodel = new \App\Models\Configuracion\PapelImpresionModel(); + $papeles = $papelimpresionmodel->getIdPapelesImpresionForPresupuesto( + papel_generico_id: 3, // Blanco offset + gramaje: 100, + options: $opciones_papel + ); + + echo '
';
+        var_dump($papeles);
+        echo '
'; + + $lineas = array(); + // Para cada papel, se obtienen las maquinas disponibles + foreach ($papeles as $papel) { + + $maquinamodel = new \App\Models\Configuracion\MaquinaModel(); + $maquinas = $maquinamodel->getMaquinaImpresionForPresupuesto( + is_rotativa: 0, + tarifa_tipo: $tipo, + tirada: $datosPedido->tirada + $datosPedido->merma, + papel_impresion_id: $papel->id, + ); + + echo '
';
+            echo '-------------------------------';
+            echo '
'; + + echo '
';
+            var_dump($maquinas);
+            echo '
'; + + // Se recorren las máquinas y se calcula el coste de linea por cada una + foreach ($maquinas as $maquina) { + + echo '
';
+                echo '$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$';
+                echo '
'; + + $tarifamodel = new \App\Models\Configuracion\MaquinasTarifasImpresionModel(); + $tarifa = $tarifamodel->getTarifa($maquina->maquina_id, $uso, $tipo); + + echo '
';
+                var_dump($tarifa);
+                echo '
'; + + if(!is_float($tarifa)){ + continue; + } + $linea = PresupuestoService::getCostesLinea($uso, $datosPedido, $maquina, $papel, $opciones_papel, $tarifa); + $linea['fields']['maquina'] = $maquina->maquina; + $linea['fields']['maquina_id'] = $maquina->maquina_id; + $linea['fields']['papel_impresion'] = $papel->nombre; + $linea['fields']['papel_impresion_id'] = $papel->id; + $linea['fields']['paginas'] = $datosPedido->paginas; + $linea['fields']['gramaje'] = 100; + $linea['fields']['papel_generico_id'] = 3; + $linea['fields']['papel_generico'] = 'Blanco offset'; + + array_push($lineas, $linea); + } + } + + echo '
';
+        var_dump($lineas);
+        echo '
'; + + + } } \ No newline at end of file diff --git a/ci4/app/Services/PresupuestoService.php b/ci4/app/Services/PresupuestoService.php index e428beed..01bf1e81 100644 --- a/ci4/app/Services/PresupuestoService.php +++ b/ci4/app/Services/PresupuestoService.php @@ -90,6 +90,8 @@ class PresupuestoService extends BaseService else if (($cubierta == 1 || $sobrecubierta == 1) && $rotativa == 0) { // precio papel $pliegos_libro = 1.0 / $response['fields']['num_formas']['value']; + // En cubierta y sobrecubierta siempre el mínimo pliego es 1 + $pliegos_libro = $pliegos_libro<1?1:$pliegos_libro; $pliegos_pedido = $pliegos_libro * ($datosPedido->tirada + $datosPedido->merma); $precio_libro = $pliegos_libro * $precio_pliego_impresion; $precio_pedido = $precio_libro * ($datosPedido->tirada + $datosPedido->merma); @@ -104,6 +106,11 @@ class PresupuestoService extends BaseService if ($tarifa) { $precio_click = $tarifa; $precio_click_pedido = $pliegos_pedido * $precio_click; + + // dos caras + if($datosPedido->paginas > 2) { + $precio_click_pedido *= 2.0; + } } } @@ -246,6 +253,14 @@ class PresupuestoService extends BaseService private static function getNumFormasPlana($uso, $maquina, $ancho, $alto, $isCosido) { + // El ancho si es cosido es el doble + if($uso != 'cubierta' && $uso != 'sobrecubierta'){ + $anchoForCalculo = $isCosido ? $ancho * 2 : $ancho; + } + else{ + $anchoForCalculo = $ancho; + } + if($uso == 'cubierta' || $uso == 'sobrecubierta') { if(property_exists($maquina, 'forzar_num_formas_horizontales_cubierta') && property_exists($maquina, 'forzar_num_formas_horizontales_cubierta')){ @@ -253,57 +268,59 @@ class PresupuestoService extends BaseService if($maquina->forzar_num_formas_horizontales_cubierta > 0 && $maquina->forzar_num_formas_horizontales_cubierta > 0){ - $h1 = $maquina->forzar_num_formas_horizontales_cubierta; - $h2 = $maquina->forzar_num_formas_verticales_cubierta; - $num_formas = $h1 * $h2; + $h1_temp = $maquina->forzar_num_formas_horizontales_cubierta; + $h2_temp = $maquina->forzar_num_formas_verticales_cubierta; + //$num_formas = $h1_temp * $h2_temp; } else{ - $num_formas == 0; + $h1_temp == 0; + $h2_temp == 0; } } else{ - $num_formas == 0; + $h1_temp == 0; + $h2_temp == 0; } } + // No es cubierta ni sobrecubierta + else{ + // horizontales + $h1_temp = floor($maquina->ancho_impresion / $anchoForCalculo); + $h2_temp = floor($maquina->ancho_impresion / $alto); + } + + // horizontales + $calles = (new \App\Models\Configuracion\MaquinasCallesModel())->getCallesForMaquina($maquina->maquina_id, $h1_temp); + // Si son mas de 2 formas + if(count($calles)>0) + $h1 = ($h1_temp * $anchoForCalculo + 2 * $calles[0]->externas + ($h1_temp - 1) * $calles[0]->internas < ($maquina->ancho)) ? $h1_temp : $h1_temp - 1; + else + $h1 = $h1_temp; + + $v1 = floor($maquina->alto_impresion / $alto); + $formas_h = $h1 * $v1; //p1 + + + // verticales + $calles = (new \App\Models\Configuracion\MaquinasCallesModel())->getCallesForMaquina($maquina->maquina_id, $h2_temp); + if(count($calles)>0) + $h2 = ($h2_temp * $anchoForCalculo + 2 * $calles[0]->externas + ($h2_temp - 1) * $calles[0]->internas < ($maquina->ancho)) ? $h2_temp : $h2_temp - 1; + else + $h2 = $h2_temp; + $v2 = floor($maquina->alto_impresion / $anchoForCalculo); + $formas_v = $h2 * $v2; //p2 + + + // Se calcula el numero de formas + if($uso != 'cubierta' && $uso != 'sobrecubierta'){ + $num_formas = ($formas_h > $formas_v) ? $formas_h : $formas_v; + $num_formas = $isCosido ? $num_formas * 2 : $num_formas; + } else{ - - if($uso != 'cubierta' && $uso != 'sobrecubierta'){ - $anchoForCalculo = $isCosido ? $ancho * 2 : $ancho; - } - else{ - $anchoForCalculo = $ancho; - } - - - // horizontales - $h1_temp = floor($maquina->ancho_impresion / $anchoForCalculo); - $calles = (new \App\Models\Configuracion\MaquinasCallesModel())->getCallesForMaquina($maquina->maquina_id, $h1_temp); - // Si son mas de 2 formas - if(count($calles)>0) - $h1 = ($h1_temp * $anchoForCalculo + 2 * $calles[0]->externas + ($h1_temp - 1) * $calles[0]->internas < ($maquina->ancho)) ? $h1_temp : $h1_temp - 1; - else - $h1 = $h1_temp; - - $v1 = floor($maquina->alto_impresion / $alto); - $formas_h = $h1 * $v1; //p1 - - // verticales - - $h2_temp = floor($maquina->ancho_impresion / $alto); - $calles = (new \App\Models\Configuracion\MaquinasCallesModel())->getCallesForMaquina($maquina->maquina_id, $h2_temp); - if(count($calles)>0) - $h2 = ($h2_temp * $anchoForCalculo + 2 * $calles[0]->externas + ($h2_temp - 1) * $calles[0]->internas < ($maquina->ancho)) ? $h2_temp : $h2_temp - 1; - else - $h2 = $h2_temp; - $v2 = floor($maquina->alto_impresion / $anchoForCalculo); - $formas_v = $h2 * $v2; //p2 - - $num_formas = ($formas_h > $formas_v) ? $formas_h : $formas_v; - if($uso != 'cubierta' && $uso != 'sobrecubierta'){ - $num_formas = $isCosido ? $num_formas * 2 : $num_formas; - } + $num_formas = $h1*$h2; } + // si no hay formas se devuelve n/a if ($num_formas == 0) { $response['num_formas']['posicion_formas'] = 'n/a'; // not available @@ -319,6 +336,14 @@ class PresupuestoService extends BaseService $response['num_formas']['value'] = $num_formas; } + if($uso == 'cubierta' || $uso == 'sobrecubierta') { + if(property_exists($maquina, 'forzar_num_formas_horizontales_cubierta') && + property_exists($maquina, 'forzar_num_formas_horizontales_cubierta')){ + + $response['num_formas']['num_formas_verticales'] = $h2; + } + } + return $response; } diff --git a/ci4/app/Views/themes/backend/vuexy/form/presupuestos/cosidotapablanda/comparador.js b/ci4/app/Views/themes/backend/vuexy/form/presupuestos/cosidotapablanda/comparador.js index 66f40259..fe91ffb6 100644 --- a/ci4/app/Views/themes/backend/vuexy/form/presupuestos/cosidotapablanda/comparador.js +++ b/ci4/app/Views/themes/backend/vuexy/form/presupuestos/cosidotapablanda/comparador.js @@ -86,39 +86,6 @@ $("#solapas").on("click", function () { } }); -$('#tipoImpresion').on("change", function () { - updatePapelesComparador(); - $('#paginas').change(); - - - if (($('#tipoImpresion').select2('data')[0].id == 'negro' || - $('#tipoImpresion').select2('data')[0].id == 'color')){ - - $('#tableCompIntRotativa').DataTable().clear().draw(); - $('#total_comp_rot').html("0.00"); - - if( $('#tableCompIntPlana').DataTable().rows().count() > 0 && - $('#tableCompIntPlana').DataTable().cell(0, 0).data().includes('hq')) { - - $('#tableCompIntPlana').DataTable().clear().draw(); - $('#total_comp_plana').html("0.00"); - } - - } - else if (($('#tipoImpresion').select2('data')[0].id == 'negrohq' || - $('#tipoImpresion').select2('data')[0].id == 'colorhq')){ - - $('#tableCompIntRotativa').DataTable().clear().draw(); - $('#total_comp_rot').html("0.00"); - - if($('#tableCompIntPlana').DataTable().rows().count() > 0 && - !$('#tableCompIntPlana').DataTable().cell(0, 0).data().includes('hq')) { - - $('#tableCompIntPlana').DataTable().clear().draw(); - $('#total_comp_plana').html("0.00"); - } - } -}); $('#compRetractilado').on("change", function () { @@ -441,6 +408,21 @@ function selectIntRotLineas(){ $('#total_comp_rot').html(value_total.toFixed(2)); } +function selectCubiertaLineas(){ + + $("#tableCompCubierta").DataTable().rows( '.selected' ).deselect(); + + let value_total = 0.00; + + if($("#tableCompCubierta").DataTable().rows().count()>0) { + + $("#tableCompCubierta").DataTable().row( 0 ).nodes().to$().toggleClass( 'selected' ); + value_total = parseFloat($("#tableCompCubierta").DataTable().rows( 0 ).data()[0]['total']) + }; + + + $('#total_comp_cubierta').html(value_total.toFixed(2)); +} function getIDsComparador(is_color, is_hq){ @@ -549,6 +531,7 @@ function fillIntRot(data){ } function fillCubierta(data, is_color, is_hq){ + let sorted = data.lineas.sort( (p1, p2) => ((p1.fields.precio_pedido+p1.fields.precio_click_pedido) < (p2.fields.precio_pedido+p2.fields.precio_click_pedido)) ? -1 : ((p1.fields.precio_pedido+p1.fields.precio_click_pedido) > (p2.fields.precio_pedido+p2.fields.precio_click_pedido)) ? 1 : 0); diff --git a/ci4/app/Views/themes/backend/vuexy/form/presupuestos/cosidotapablanda/viewCosidotapablandaForm.php b/ci4/app/Views/themes/backend/vuexy/form/presupuestos/cosidotapablanda/viewCosidotapablandaForm.php index c1bb21f9..bc04b030 100644 --- a/ci4/app/Views/themes/backend/vuexy/form/presupuestos/cosidotapablanda/viewCosidotapablandaForm.php +++ b/ci4/app/Views/themes/backend/vuexy/form/presupuestos/cosidotapablanda/viewCosidotapablandaForm.php @@ -273,14 +273,10 @@ columns: [ { 'data': 'tipo', 'render': function ( data, type, row, meta ) { - if(data=='bn') - return ''; - else if(data=='bnhq') - return ''; - else if(data=='color') - return ''; - else if(data=='colorhq') - return ''; + if(data=='cubierta') + return ''; + else if(data=='sobrecubierta') + return ''; } }, { 'data': 'paginas' }, @@ -393,6 +389,9 @@ selectIntLineas(); $('#title_int_plana').html('' + ' (' + tableCompIntPlana.rows().count() + ')'); } + else{ + $('#title_int_plana').html(''); + } yeniden(data.); return true; }, @@ -442,6 +441,9 @@ selectIntRotLineas(); $('#title_int_rot').html('' + ' (' + tableCompIntRotativa.rows().count() + ')'); } + else{ + $('#title_int_rot').html(''); + } yeniden(data.); return true; }, @@ -454,7 +456,7 @@ return false; } - + $('.comp_cubierta_items').on('change', function (){ if ($('#compCarasCubierta').select2('data').length > 0 && @@ -491,8 +493,11 @@ console.log(data.lineas); fillCubierta(data); - //selectIntLineas(); - //$('#title_int_plana').html('' + ' (' + tableCompIntPlana.rows().count() + ')'); + selectCubiertaLineas(); + $('#title_cubierta').html('' + ' (' + tableCompCubierta.rows().count() + ')'); + } + else{ + $('#title_cubierta').html(''); } yeniden(data.); return true; @@ -509,6 +514,43 @@ }); + $('#tipoImpresion').on("change", function () { + updatePapelesComparador(); + $('#title_int_rot').html(''); + $('#title_int_plana').html(''); + $('#paginas').change(); + + + if (($('#tipoImpresion').select2('data')[0].id == 'negro' || + $('#tipoImpresion').select2('data')[0].id == 'color')){ + + $('#tableCompIntRotativa').DataTable().clear().draw(); + $('#total_comp_rot').html("0.00"); + + if( $('#tableCompIntPlana').DataTable().rows().count() > 0 && + $('#tableCompIntPlana').DataTable().cell(0, 0).data().includes('hq')) { + + $('#tableCompIntPlana').DataTable().clear().draw(); + $('#total_comp_plana').html("0.00"); + } + + } + else if (($('#tipoImpresion').select2('data')[0].id == 'negrohq' || + $('#tipoImpresion').select2('data')[0].id == 'colorhq')){ + + $('#tableCompIntRotativa').DataTable().clear().draw(); + $('#total_comp_rot').html("0.00"); + + if($('#tableCompIntPlana').DataTable().rows().count() > 0 && + !$('#tableCompIntPlana').DataTable().cell(0, 0).data().includes('hq')) { + + $('#tableCompIntPlana').DataTable().clear().draw(); + $('#total_comp_plana').html("0.00"); + } + } + }); + + function checkComparadorInt(is_color, is_hq) { elementos = getIDsComparador(is_color, is_hq)