mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
Merge branch 'fix/use_tiradas_alternativas' into 'main'
corregidas direfencias en totales presupuestos. tiradas alternativas ok.... See merge request jjimenez/safekat!516
This commit is contained in:
@ -72,6 +72,7 @@ $routes->group('tarifas', ['namespace' => 'App\Controllers\Tarifas'], function (
|
||||
$routes->group('acabados', ['namespace' => 'App\Controllers\Tarifas\Acabados'], function ($routes) {
|
||||
|
||||
$routes->get('', 'TarifaAcabados::index', ['as' => 'tarifaAcabadoList']);
|
||||
$routes->get('gettarifas', 'TarifaAcabados::getSelect2');
|
||||
$routes->match(['get', 'post'], 'add', 'TarifaAcabados::add', ['as' => 'tarifaAcabadoAdd']);
|
||||
$routes->match(['get', 'post'], 'edit/(:num)', 'TarifaAcabados::edit/$1', ['as' => 'tarifaAcabadoEdit']);
|
||||
$routes->get('delete/(:num)', 'TarifaAcabados::delete/$1', ['as' => 'tarifaAcabadoDelete']);
|
||||
@ -275,7 +276,7 @@ $routes->group('papelesimpresion', ['namespace' => 'App\Controllers\Configuracio
|
||||
$routes->post('datatable', 'Papelesimpresion::datatable', ['as' => 'dataTableOfPapelesImpresion']);
|
||||
$routes->post('allmenuitems', 'Papelesimpresion::allItemsSelect', ['as' => 'select2ItemsOfPapelesImpresion']);
|
||||
$routes->post('menuitems', 'Papelesimpresion::menuItems', ['as' => 'menuItemsOfPapelesImpresion']);
|
||||
$routes->post('duplicate/(:num)','Papelesimpresion::duplicate/$1',['as' => 'duplicatePapelImpresion']);
|
||||
$routes->post('duplicate/(:num)', 'Papelesimpresion::duplicate/$1', ['as' => 'duplicatePapelImpresion']);
|
||||
});
|
||||
$routes->resource('papelesimpresion', ['namespace' => 'App\Controllers\Configuracion', 'controller' => 'Papelesimpresion', 'except' => 'show,new,create,update']);
|
||||
|
||||
@ -308,7 +309,7 @@ $routes->group('maquinas', ['namespace' => 'App\Controllers\Configuracion'], fun
|
||||
$routes->post('datatable', 'Maquinas::datatable', ['as' => 'dataTableOfMaquinas']);
|
||||
$routes->post('allmenuitems', 'Maquinas::allItemsSelect', ['as' => 'select2ItemsOfMaquinas']);
|
||||
$routes->post('menuitems', 'Maquinas::menuItems', ['as' => 'menuItemsOfMaquinas']);
|
||||
$routes->post('duplicate/(:num)', 'Maquinas::duplicate/$1',['as' => 'duplicateMaquina']);
|
||||
$routes->post('duplicate/(:num)', 'Maquinas::duplicate/$1', ['as' => 'duplicateMaquina']);
|
||||
|
||||
$routes->get('select', 'Maquinas::select', ['as' => 'selectMaquinas']);
|
||||
});
|
||||
|
||||
@ -1244,7 +1244,7 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController
|
||||
$resultado_presupuesto['info']['merma'] = $this->calcular_merma($selected_tirada, $POD);
|
||||
|
||||
$datos_presupuesto['faja'] = $faja;
|
||||
|
||||
|
||||
$id = $model_presupuesto->insertarPresupuestoCliente(
|
||||
$id,
|
||||
$selected_tirada,
|
||||
@ -1722,8 +1722,8 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController
|
||||
'tarifa_encuadernado_id' => $servicio->tarifa_id,
|
||||
'proveedor_id' => $servicio->proveedor_id,
|
||||
'tiempo' => $servicio->tiempo,
|
||||
'precio_total' => $servicio->total,
|
||||
'precio_unidad' => $servicio->precio_unidad,
|
||||
'precio_total' => round($servicio->total, 2),
|
||||
'precio_unidad' => round($servicio->precio_unidad, 2),
|
||||
'margen' => $servicio->margen,
|
||||
];
|
||||
|
||||
@ -1739,7 +1739,7 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController
|
||||
$data = [
|
||||
'presupuesto_id' => $presupuestoId,
|
||||
'tarifa_extra_id' => $servicio->tarifa_id,
|
||||
'precio' => $servicio->precio,
|
||||
'precio' => round($servicio->precio, 2),
|
||||
'margen' => $servicio->margen,
|
||||
];
|
||||
$model->insert($data);
|
||||
@ -1764,8 +1764,8 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController
|
||||
$data = [
|
||||
'presupuesto_id' => $presupuestoId,
|
||||
'tarifa_manipulado_id' => $servicio->tarifa_id,
|
||||
'precio_total' => $servicio->total,
|
||||
'precio_unidad' => $servicio->precio_unidad,
|
||||
'precio_total' => round($servicio->total, 2),
|
||||
'precio_unidad' => round($servicio->precio_unidad, 2),
|
||||
'margen' => $servicio->margen,
|
||||
];
|
||||
$model->insert($data);
|
||||
@ -1792,7 +1792,7 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController
|
||||
$margen = 0;
|
||||
|
||||
|
||||
$peso_envio = round(floatval(floatval($peso) * floatval($unidades) / 1000.0)); // peso libro * unidades y se pasa a kilogramos
|
||||
$peso_envio = round(floatval(floatval($peso) * floatval($unidades) / 1000.0), 3); // peso libro * unidades y se pasa a kilogramos
|
||||
$tarifas_envio = $modelTarifaEnvio->getTarifaEnvio($pais_id, $cp, $peso_envio, $entregaPieCalle ? 'palets' : 'cajas');
|
||||
for ($i = 0; $i < count($tarifas_envio); $i++) {
|
||||
if ($peso_envio > $tarifas_envio[$i]->peso_max || floatval($tarifas_envio[$i]->precio_max) == 0) {
|
||||
@ -1961,7 +1961,7 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController
|
||||
$peso_interior = 0.0;
|
||||
foreach ($interior as $linea) {
|
||||
if (count($linea) > 0) {
|
||||
$costeInterior += floatval($linea['total_impresion']);
|
||||
$costeInterior += round(floatval($linea['total_impresion']), 2);
|
||||
$peso_interior += floatval($linea['peso']);
|
||||
$lomo += floatval($linea['mano']);
|
||||
$info['lomo_interior'] += floatval($linea['mano']);
|
||||
@ -2021,7 +2021,7 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController
|
||||
}
|
||||
foreach ($interior as $linea) {
|
||||
if (count($linea) > 0) {
|
||||
$costeInterior += floatval($linea['total_impresion']);
|
||||
$costeInterior += round(floatval($linea['total_impresion']), 2);
|
||||
$peso_interior += floatval($linea['peso']);
|
||||
$lomo += floatval($linea['mano']);
|
||||
if ($extra_info) {
|
||||
@ -2073,7 +2073,7 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController
|
||||
$coste_cubierta = 0.0;
|
||||
$peso_cubierta = 0.0;
|
||||
if (count($cubierta) > 0) {
|
||||
$coste_cubierta += floatval($cubierta['total_impresion']);
|
||||
$coste_cubierta += round(floatval($cubierta['total_impresion']), 2);
|
||||
$peso_cubierta += floatval($cubierta['peso']);
|
||||
$lomo += floatval($cubierta['mano']);
|
||||
if ($extra_info) {
|
||||
@ -2130,7 +2130,13 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController
|
||||
];
|
||||
return $return_data;
|
||||
}
|
||||
$coste_servicios += floatval($acabadoCubierta[0]->total);
|
||||
$coste_servicios += round(floatval($acabadoCubierta[0]->total), 2);
|
||||
if ($extra_info) {
|
||||
$totalServicios += round(floatval($acabadoCubierta[0]->total), 2);
|
||||
$base = round(floatval($acabadoCubierta[0]->total / (1 + $acabadoCubierta[0]->margen / 100.0)), 2);
|
||||
$base = round(floatval($base / $datosPedido->tirada) , 2)* $datosPedido->tirada;
|
||||
$margenServicios += round(floatval($acabadoCubierta[0]->total - $base), 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -2157,7 +2163,7 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController
|
||||
$linea_sobrecubierta = PresupuestoClienteService::obtenerSobrecubierta($input_data);
|
||||
|
||||
if (count($linea_sobrecubierta) > 0) {
|
||||
$coste_sobrecubierta += floatval($linea_sobrecubierta['total_impresion']);
|
||||
$coste_sobrecubierta += round(floatval($linea_sobrecubierta['total_impresion']), 2);
|
||||
$peso_sobrecubierta += floatval($linea_sobrecubierta['peso']);
|
||||
if ($extra_info) {
|
||||
|
||||
@ -2215,7 +2221,13 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController
|
||||
return $return_data;
|
||||
}
|
||||
|
||||
$coste_servicios += floatval($acabadoSobrecubierta[0]->total);
|
||||
$coste_servicios += round(floatval($acabadoSobrecubierta[0]->total), 2);
|
||||
if ($extra_info) {
|
||||
$totalServicios += round(floatval($acabadoSobrecubierta[0]->total), 2);
|
||||
$base = round(floatval($acabadoSobrecubierta[0]->total / (1 + $acabadoSobrecubierta[0]->margen / 100.0)), 2);
|
||||
$base = round(floatval($base / $datosPedido->tirada) , 2)* $datosPedido->tirada;
|
||||
$margenServicios += round(floatval($acabadoSobrecubierta[0]->total - $base), 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -2251,7 +2263,7 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController
|
||||
$guardas = PresupuestoClienteService::obtenerGuardas($input_data);
|
||||
|
||||
if (count($guardas) > 0) {
|
||||
$coste_guardas += floatval($guardas['total_impresion']);
|
||||
$coste_guardas += round(floatval($guardas['total_impresion']), 2);
|
||||
$peso_guardas += floatval($guardas['peso']);
|
||||
if ($extra_info) {
|
||||
|
||||
@ -2305,7 +2317,7 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController
|
||||
|
||||
if (count($linea_faja) > 0) {
|
||||
$linea_faja['tipo_linea'] = 'lp_faja';
|
||||
$coste_faja += floatval($linea_faja['total_impresion']);
|
||||
$coste_faja += round(floatval($linea_faja['total_impresion']), 2);
|
||||
$peso_faja += floatval($linea_faja['peso']);
|
||||
if ($extra_info) {
|
||||
|
||||
@ -2335,7 +2347,7 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController
|
||||
];
|
||||
return $return_data;
|
||||
}
|
||||
|
||||
|
||||
// Acabado faja
|
||||
if (intval($faja['acabado']) != 0) {
|
||||
|
||||
@ -2362,7 +2374,13 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController
|
||||
return $return_data;
|
||||
}
|
||||
|
||||
$coste_servicios += floatval($acabadoFaja[0]->total);
|
||||
$coste_servicios += round(floatval($acabadoFaja[0]->total), 2);
|
||||
if ($extra_info) {
|
||||
$totalServicios += round(floatval($acabadoFaja[0]->total), 2);
|
||||
$base = round(floatval($acabadoFaja[0]->total / (1 + $acabadoFaja[0]->margen / 100.0)), 2);
|
||||
$base = round(floatval($base / $datosPedido->tirada) , 2)* $datosPedido->tirada;
|
||||
$margenServicios += round(floatval($acabadoFaja[0]->total - $base), 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -2410,10 +2428,12 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController
|
||||
}
|
||||
|
||||
|
||||
$costeServiciosDefecto += floatval($servicio->total);
|
||||
$costeServiciosDefecto += round(floatval($servicio->total), 2);
|
||||
if ($extra_info) {
|
||||
$totalServicios += floatval($servicio->total);
|
||||
$margenServicios += floatval($servicio->total) * floatval($servicio->margen) / 100.0;
|
||||
$totalServicios += round(floatval($servicio->total), 2);
|
||||
$base = round(floatval($servicio->total / (1 + $servicio->margen / 100.0)), 2);
|
||||
$base = round(floatval($base / $datosPedido->tirada), 2)*$datosPedido->tirada;
|
||||
$margenServicios += round(floatval($servicio->total -$base), 2);
|
||||
}
|
||||
}
|
||||
|
||||
@ -2445,10 +2465,12 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController
|
||||
}
|
||||
|
||||
|
||||
$costeServiciosDefecto += floatval($servicio->total);
|
||||
$costeServiciosDefecto += round(floatval($servicio->total), 2);
|
||||
if ($extra_info) {
|
||||
$totalServicios += floatval($servicio->total);
|
||||
$margenServicios += floatval($servicio->total) * floatval($servicio->margen) / 100.0;
|
||||
$totalServicios += round(floatval($servicio->total), 2);
|
||||
$base = round(floatval($servicio->total / (1 + $servicio->margen / 100.0)), 2);
|
||||
$base = round(floatval($base / $datosPedido->tirada), 2)*$datosPedido->tirada;
|
||||
$margenServicios += round(floatval($servicio->total -$base), 2);
|
||||
}
|
||||
}
|
||||
|
||||
@ -2528,7 +2550,7 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController
|
||||
array_push($servicios, $servicio_solapas_cubierta);
|
||||
if (!is_null($sobreCubierta) && $sobreCubierta) // Si hay sobrecubierta, siempre con solapas
|
||||
array_push($servicios, $servicio_solapas_sobrecubierta);
|
||||
if(!is_null($faja) && $faja && $faja != false) // Si hay faja, siempre con solapas
|
||||
if (!is_null($faja) && $faja && $faja != false) // Si hay faja, siempre con solapas
|
||||
array_push($servicios, $servicio_solapas_faja);
|
||||
|
||||
|
||||
@ -2560,10 +2582,12 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController
|
||||
return $return_data;
|
||||
}
|
||||
|
||||
$coste_servicios += floatval($resultado[0]->total);
|
||||
$coste_servicios += round(floatval($resultado[0]->total), 2);
|
||||
if ($extra_info) {
|
||||
$totalServicios += floatval($resultado[0]->total);
|
||||
$margenServicios += floatval($resultado[0]->total) * floatval($resultado[0]->margen) / 100.0;
|
||||
$totalServicios += round(floatval($resultado[0]->total), 2);
|
||||
$base = round(floatval($resultado[0]->total / (1 + $resultado[0]->margen / 100.0)), 2);
|
||||
$base = round(floatval($base / $datosPedido->tirada) , 2)* $datosPedido->tirada;
|
||||
$margenServicios += round(floatval($resultado[0]->total - $base), 2);
|
||||
}
|
||||
} else if ($servicio->nombre == "ferro" || $servicio->nombre == "prototipo") {
|
||||
// Extra
|
||||
@ -2590,10 +2614,12 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController
|
||||
|
||||
array_push($serviciosAutomaticos, $resultado[0]);
|
||||
|
||||
$coste_servicios += floatval($resultado[0]->precio);
|
||||
$coste_servicios += round(floatval($resultado[0]->precio), 2);
|
||||
if ($extra_info) {
|
||||
$totalServicios += floatval($resultado[0]->precio);
|
||||
$margenServicios += floatval($resultado[0]->precio) * floatval($resultado[0]->margen) / 100.0;
|
||||
$totalServicios += round(floatval($resultado[0]->precio), 2);
|
||||
$base = round(floatval($resultado[0]->total / (1 + $resultado[0]->margen / 100.0)), 2);
|
||||
$base = round(floatval($base / $datosPedido->tirada) , 2)* $datosPedido->tirada;
|
||||
$margenServicios += round(floatval($resultado[0]->total - $base), 2);
|
||||
}
|
||||
} else if ($servicio->nombre == 'solapas_cubierta' || $servicio->nombre == 'solapas_sobrecubierta' || $servicio->nombre == 'solapas_faja') {
|
||||
// Servicios manipulado
|
||||
@ -2622,10 +2648,12 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController
|
||||
array_push($serviciosAutomaticos, $resultado[0]);
|
||||
}
|
||||
|
||||
$coste_servicios += floatval($resultado[0]->total);
|
||||
$coste_servicios += round(floatval($resultado[0]->total), 2);
|
||||
if ($extra_info) {
|
||||
$totalServicios += floatval($resultado[0]->total);
|
||||
$margenServicios += floatval($resultado[0]->total) * floatval($resultado[0]->margen) / 100.0;
|
||||
$totalServicios += round(floatval($resultado[0]->total), 2);
|
||||
$base = round(floatval($resultado[0]->total / (1 + $resultado[0]->margen / 100.0)), 2);
|
||||
$base = round(floatval($base / $datosPedido->tirada) , 2)* $datosPedido->tirada;
|
||||
$margenServicios += round(floatval($resultado[0]->total - $base), 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -2658,10 +2686,12 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController
|
||||
array_push($serviciosAutomaticos, $resultado[0]);
|
||||
}
|
||||
|
||||
$coste_servicios += floatval($resultado[0]->total);
|
||||
$coste_servicios += round(floatval($resultado[0]->total), 2);
|
||||
if ($extra_info) {
|
||||
$totalServicios += floatval($resultado[0]->total);
|
||||
$margenServicios += floatval($resultado[0]->total) * floatval($resultado[0]->margen) / 100.0;
|
||||
$totalServicios += round(floatval($resultado[0]->total), 2);
|
||||
$base = round(floatval($resultado[0]->total / (1 + $resultado[0]->margen / 100.0)), 2);
|
||||
$base = round(floatval($base / $datosPedido->tirada) , 2)* $datosPedido->tirada;
|
||||
$margenServicios += round(floatval($resultado[0]->total - $base), 2);
|
||||
}
|
||||
}
|
||||
|
||||
@ -2693,20 +2723,68 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController
|
||||
array_push($serviciosAutomaticos, $resultado[0]);
|
||||
}
|
||||
|
||||
$coste_servicios += floatval($resultado[0]->total);
|
||||
$coste_servicios += round(floatval($resultado[0]->total), 2);
|
||||
if ($extra_info) {
|
||||
$totalServicios += floatval($resultado[0]->total);
|
||||
$margenServicios += floatval($resultado[0]->total) * floatval($resultado[0]->margen) / 100.0;
|
||||
$totalServicios += round(floatval($resultado[0]->total), 2);
|
||||
$base = round(floatval($resultado[0]->total / (1 + $resultado[0]->margen / 100.0)), 2);
|
||||
$base = round(floatval($base / $datosPedido->tirada) , 2)* $datosPedido->tirada;
|
||||
$margenServicios += round(floatval($resultado[0]->total - $base), 2);
|
||||
}
|
||||
}
|
||||
|
||||
array_push($precio_u, round(($costeInterior + $coste_cubierta + $coste_sobrecubierta + $costeServiciosDefecto + $coste_servicios) / $tirada[$t], 4));
|
||||
array_push($peso, round($peso_interior + $peso_cubierta + $peso_sobrecubierta + $peso_guardas, 2));
|
||||
if (is_array($faja) && ($faja['solapas'] > 0 && intval($linea_faja['dimension_desarrollo']['ancho']) > 630)) {
|
||||
|
||||
// Servicios manipulado
|
||||
$resultado = PresupuestoCLienteService::getServiciosManipulado([
|
||||
'tarifa_id' => intval($servicio_solapas_grandes_faja->id),
|
||||
'tirada' => $datosPedido->tirada,
|
||||
'POD' => $POD,
|
||||
]);
|
||||
|
||||
if ($resultado[0]->total <= 0) {
|
||||
|
||||
$errorModel = new ErrorPresupuesto();
|
||||
$errorModel->insertError(
|
||||
$datos_entrada['id'],
|
||||
auth()->user()->id,
|
||||
'No se puede obtener servicio de manupulado ' . ((string) $servicio->nombre),
|
||||
$input_data
|
||||
);
|
||||
$return_data = [
|
||||
'errors' => (object) ([
|
||||
'status' => 1
|
||||
]),
|
||||
];
|
||||
return $return_data;
|
||||
} else {
|
||||
array_push($serviciosAutomaticos, $resultado[0]);
|
||||
}
|
||||
|
||||
$coste_servicios += round(floatval($resultado[0]->total), 2);
|
||||
if ($extra_info) {
|
||||
$totalServicios += round(floatval($resultado[0]->total), 2);
|
||||
$base = round(floatval($resultado[0]->total / (1 + $resultado[0]->margen / 100.0)), 2);
|
||||
$base = round(floatval($base / $datosPedido->tirada) , 2)* $datosPedido->tirada;
|
||||
$margenServicios += round(floatval($resultado[0]->total - $base), 2);
|
||||
}
|
||||
}
|
||||
|
||||
$total_por_tirada = $costeInterior +
|
||||
$coste_cubierta +
|
||||
$coste_sobrecubierta +
|
||||
$coste_guardas +
|
||||
$coste_faja +
|
||||
$costeServiciosDefecto + $coste_servicios;
|
||||
array_push(
|
||||
$precio_u,
|
||||
round(($total_por_tirada) / $tirada[$t], 4)
|
||||
);
|
||||
array_push($peso, round($peso_interior + $peso_cubierta + $peso_sobrecubierta + $peso_guardas + $peso_faja, 2));
|
||||
|
||||
if ($extra_info) {
|
||||
$totalServicios -= $margenServicios;
|
||||
if (($margenServicios + $totalServicios) > 0) {
|
||||
$porcentajeMargenServicios = $margenServicios / ($margenServicios + $totalServicios) * 100;
|
||||
$porcentajeMargenServicios = $margenServicios / ($totalServicios) * 100;
|
||||
} else {
|
||||
$porcentajeMargenServicios = 0;
|
||||
}
|
||||
@ -2782,25 +2860,25 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController
|
||||
{
|
||||
if (count($linea) == 0)
|
||||
return;
|
||||
$totalPapel += $linea['precio_pedido'];
|
||||
$margenPapel += $linea['margen_papel_pedido'];
|
||||
$sumForFactor += $linea['precio_pedido'];
|
||||
$sumForFactor -= $linea['precio_pedido'];
|
||||
$totalPapel += round($linea['precio_pedido'], 2);
|
||||
$margenPapel += round($linea['margen_papel_pedido'], 2);
|
||||
$sumForFactor += round($linea['precio_pedido'], 2);
|
||||
$sumForFactor -= round($linea['precio_pedido'], 2);
|
||||
|
||||
$totalImpresion += $linea['precio_impresion_horas'];
|
||||
$totalImpresion += $linea['precio_click_pedido'];
|
||||
$sumForFactor += $linea['precio_click_pedido'];
|
||||
$totalImpresion += round($linea['precio_impresion_horas'], 2);
|
||||
$totalImpresion += round($linea['precio_click_pedido'], 2);
|
||||
$sumForFactor += round($linea['precio_click_pedido'], 2);
|
||||
|
||||
if ($linea['tipo_maquina'] == 'inkjet') {
|
||||
$totalImpresion += $linea['precio_tinta'];
|
||||
$totalImpresion += round($linea['precio_tinta'], 2);
|
||||
if (array_key_exists('total_corte', $linea)) {
|
||||
$totalImpresion += $linea['total_corte'];
|
||||
$sumForFactor += $linea['total_corte'];
|
||||
$totalImpresion += round($linea['total_corte'], 2);
|
||||
$sumForFactor += round($linea['total_corte'], 2);
|
||||
}
|
||||
}
|
||||
$margenImpresion += $linea['margen_impresion_horas'];
|
||||
$margenImpresion += $linea['margen_click_pedido'];
|
||||
$sumForFactor -= $linea['margen_click_pedido'];
|
||||
$margenImpresion += round($linea['margen_impresion_horas'], 2);
|
||||
$margenImpresion += round($linea['margen_click_pedido'], 2);
|
||||
$sumForFactor -= round($linea['margen_click_pedido'], 2);
|
||||
}
|
||||
|
||||
protected function calcular_lomo($lineas, $lomo_inicial)
|
||||
|
||||
@ -115,7 +115,7 @@ class Presupuestomanipulados extends \App\Controllers\BaseResourceController
|
||||
|
||||
if (count($datos_tarifas) > 0) {
|
||||
foreach ($datos_tarifas as $tarifa) {
|
||||
$values = $model->getPrecioTarifa($tarifa, $tirada, $POD);
|
||||
$values = $model->getPrecioTarifa($tarifa['tarifa_manipulado_id'], $tirada, $POD);
|
||||
$values[0]->cubierta = $tarifa['cubierta'] ?? 0;
|
||||
$values[0]->sobrecubierta = $tarifa['sobrecubierta'] ?? 0;
|
||||
array_push($result, $values[0]);
|
||||
|
||||
@ -86,6 +86,21 @@ class Presupuestopreimpresiones extends \App\Controllers\BaseResourceController
|
||||
return $this->respond($data);
|
||||
}
|
||||
|
||||
public function getServiciosPreimpresion($datos_tarifas)
|
||||
{
|
||||
$result = [];
|
||||
$model = model('App\Models\Presupuestos\Presupuestopreimpresiones');
|
||||
|
||||
if (count($datos_tarifas) > 0) {
|
||||
foreach ($datos_tarifas as $tarifa) {
|
||||
$values = $model->getPrecioTarifa($tarifa);
|
||||
array_push($result, $values[0]);
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
public function datatable()
|
||||
{
|
||||
if ($this->request->isAJAX()) {
|
||||
|
||||
@ -86,6 +86,20 @@ class Presupuestoserviciosextra extends \App\Controllers\BaseResourceController
|
||||
return $this->respond($data);
|
||||
}
|
||||
|
||||
public function getServiciosExtra($datos_tarifas)
|
||||
{
|
||||
$result = [];
|
||||
$model = model('App\Models\Presupuestos\PresupuestoServiciosExtraModel');
|
||||
|
||||
if (count($datos_tarifas) > 0) {
|
||||
foreach ($datos_tarifas as $tarifa) {
|
||||
$values = $model->getPrecioTarifa($tarifa);
|
||||
array_push($result, $values[0]);
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function datatable()
|
||||
{
|
||||
if ($this->request->isAJAX()) {
|
||||
|
||||
@ -88,6 +88,8 @@ class Presupuestotiradasalternativas extends \App\Controllers\BaseResourceContro
|
||||
$json_data_acabados = $reqData['json_acabados'] ?? null;
|
||||
$json_data_encuadernacion = $reqData['json_encuadernaciones'] ?? null;
|
||||
$json_data_manipulado = $reqData['json_manipulado'] ?? null;
|
||||
$json_data_preimpresion = $reqData['json_preimpresion'] ?? null;
|
||||
$json_data_extra = $reqData['json_extra'] ?? null;
|
||||
$cliente_id = $reqData['cliente_id'] ?? 0;
|
||||
|
||||
$faja_alto = $reqData['faja_alto'] ?? 0;
|
||||
@ -95,6 +97,8 @@ class Presupuestotiradasalternativas extends \App\Controllers\BaseResourceContro
|
||||
|
||||
$tipo_impresion_id = $reqData['tipo_impresion_id'] ?? 4;
|
||||
|
||||
$tirada = $reqData['tirada'] ?? 0;
|
||||
|
||||
$values = [];
|
||||
|
||||
if ($json_data) {
|
||||
@ -126,7 +130,9 @@ class Presupuestotiradasalternativas extends \App\Controllers\BaseResourceContro
|
||||
} else if ($linea['row_id'] == 'lp_sobrecubierta' || $linea['row_id'] == 'lp_cubierta' || $linea['row_id'] == 'lp_faja') {
|
||||
$datosPedido->solapas = $reqData['solapas_cubierta'];
|
||||
if ($linea['row_id'] == 'lp_faja') {
|
||||
$datosPedido->solapas = $solapas_faja;
|
||||
$datosPedido->solapas = 1;
|
||||
$datosPedido->alto = $faja_alto;
|
||||
|
||||
} else if ($linea['row_id'] == 'lp_sobrecubierta') {
|
||||
$datosPedido->solapas = $reqData['solapas_sobrecubierta'];
|
||||
}
|
||||
@ -252,10 +258,6 @@ class Presupuestotiradasalternativas extends \App\Controllers\BaseResourceContro
|
||||
$datosLinea['gramaje'] = $linea['gramaje'] ?? 0;
|
||||
|
||||
if ($linea['row_id'] != 'lp_rot_bn' && $linea['row_id'] != 'lp_rot_color') {
|
||||
$data = $datosLinea;
|
||||
if($uso=='faja'){
|
||||
$data['datosPedido']->alto = $faja_alto;
|
||||
}
|
||||
$linea_coste = PresupuestoService::getLineaPresupuestoPlana($datosLinea);
|
||||
} else {
|
||||
$linea_coste = PresupuestoService::getLineaPresupuestoRotativa($datosLinea);
|
||||
@ -311,10 +313,10 @@ class Presupuestotiradasalternativas extends \App\Controllers\BaseResourceContro
|
||||
$result = $acabados->getServiciosAcabados($json_data_acabados, $reqData['tirada'], $POD);
|
||||
if (count($result) > 0) {
|
||||
foreach ($result as $servicio) {
|
||||
$coste = round($servicio->total / (1 + $servicio->margen / 100), 2);
|
||||
$margen = round($servicio->total - $coste, 2);
|
||||
$servicios->coste += $coste;
|
||||
$servicios->margen += $margen;
|
||||
$servicios->coste += round(floatval($servicio->total), 2);
|
||||
$base = round(floatval($servicio->total / (1 + $servicio->margen / 100.0)), 2);
|
||||
$base = round(floatval($base / $datosPedido->tirada) , 2)* $datosPedido->tirada;
|
||||
$servicios->margen += round(floatval($servicio->total - $base), 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -329,10 +331,10 @@ class Presupuestotiradasalternativas extends \App\Controllers\BaseResourceContro
|
||||
$result = $encuadernacion->getServiciosEncuadernacion($json_data_encuadernacion, $reqData['tirada'], $reqData['paginas'], $reqData['ancho'], $reqData['alto'], $POD);
|
||||
if (count($result) > 0) {
|
||||
foreach ($result as $servicio) {
|
||||
$coste = round($servicio->total / (1 + $servicio->margen / 100), 2);
|
||||
$margen = round($servicio->total - $coste, 2);
|
||||
$servicios->coste += $coste;
|
||||
$servicios->margen += $margen;
|
||||
$servicios->coste += round(floatval($servicio->total), 2);
|
||||
$base = round(floatval($servicio->total / (1 + $servicio->margen / 100.0)), 2);
|
||||
$base = round(floatval($base / $datosPedido->tirada) , 2)* $datosPedido->tirada;
|
||||
$servicios->margen += round(floatval($servicio->total - $base), 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -346,10 +348,44 @@ class Presupuestotiradasalternativas extends \App\Controllers\BaseResourceContro
|
||||
$result = $manipulados->getServiciosManipulado($json_data_manipulado, $reqData['tirada'], $POD);
|
||||
if (count($result) > 0) {
|
||||
foreach ($result as $servicio) {
|
||||
$coste = round($servicio->total / (1 + $servicio->margen / 100), 2);
|
||||
$margen = round($servicio->total - $coste, 2);
|
||||
$servicios->coste += $coste;
|
||||
$servicios->margen += $margen;
|
||||
$servicios->coste += round(floatval($servicio->total), 2);
|
||||
$base = round(floatval($servicio->total / (1 + $servicio->margen / 100.0)), 2);
|
||||
$base = round(floatval($base / $datosPedido->tirada) , 2)* $datosPedido->tirada;
|
||||
$servicios->margen += round(floatval($servicio->total - $base), 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if($json_data_preimpresion){
|
||||
$json_data_preimpresion = json_decode($json_data_preimpresion, true);
|
||||
if (count($json_data_preimpresion) > 0) {
|
||||
$preimpresion = new Presupuestopreimpresiones();
|
||||
$POD = (new \App\Models\Configuracion\ConfigVariableModel())->getVariable('POD')->value;
|
||||
$result = $preimpresion->getServiciosPreimpresion($json_data_preimpresion);
|
||||
if (count($result) > 0) {
|
||||
foreach ($result as $servicio) {
|
||||
$servicios->coste += round(floatval($servicio->total), 2);
|
||||
$base = round(floatval($servicio->total / (1 + $servicio->margen / 100.0)), 2);
|
||||
$base = round(floatval($base / $datosPedido->tirada) , 2)* $datosPedido->tirada;
|
||||
$servicios->margen += round(floatval($servicio->total - $base), 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if($json_data_extra){
|
||||
$json_data_extra = json_decode($json_data_extra, true);
|
||||
if (count($json_data_extra) > 0) {
|
||||
$extra = new Presupuestoserviciosextra();
|
||||
$POD = (new \App\Models\Configuracion\ConfigVariableModel())->getVariable('POD')->value;
|
||||
$result = $extra->getServiciosExtra($json_data_extra, $reqData['tirada'], $POD);
|
||||
if (count($result) > 0) {
|
||||
foreach ($result as $servicio) {
|
||||
$servicios->coste += round(floatval($servicio->total), 2);
|
||||
$base = round(floatval($servicio->total / (1 + $servicio->margen / 100.0)), 2);
|
||||
$base = round(floatval($base / $datosPedido->tirada) , 2)* $datosPedido->tirada;
|
||||
$servicios->margen += round(floatval($servicio->total - $base), 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -26,13 +26,13 @@ class Test extends BaseController
|
||||
|
||||
public function index()
|
||||
{
|
||||
$model = model("\App\Models\Clientes\ClientePreciosModel");
|
||||
/*$model = model("\App\Models\Clientes\ClientePreciosModel");
|
||||
$model->debug_all_clientes_to_defecto();
|
||||
echo '<pre>';
|
||||
echo 'OK';
|
||||
echo '</pre>';
|
||||
echo '</pre>';*/
|
||||
|
||||
//xdebug_info();
|
||||
xdebug_info();
|
||||
|
||||
|
||||
|
||||
|
||||
@ -15,6 +15,8 @@ class PresupuestoAcabadosEntity extends \CodeIgniter\Entity\Entity
|
||||
"tarifa_acabado_id" => null,
|
||||
"proveedor_id" => null,
|
||||
"precio_unidad" => null,
|
||||
"importe_minimo" => null,
|
||||
"importe_fijo" => null,
|
||||
"precio_total" => null,
|
||||
"margen" => null,
|
||||
"cubierta" => null,
|
||||
@ -28,7 +30,8 @@ class PresupuestoAcabadosEntity extends \CodeIgniter\Entity\Entity
|
||||
"tarifa_acabado_id" => "int",
|
||||
"proveedor_id" => "int",
|
||||
"precio_unidad" => "float",
|
||||
"precio_total" => "float",
|
||||
"importe_minimo" => "float",
|
||||
"importe_fijo" => "float",
|
||||
"margen" => "float",
|
||||
"cubierta" => "int",
|
||||
"sobrecubierta" => "int",
|
||||
|
||||
@ -22,7 +22,7 @@ class PresupuestoAcabadosModel extends \App\Models\BaseModel
|
||||
3 => "t1.precio_total"
|
||||
];
|
||||
|
||||
protected $allowedFields = ["presupuesto_id", "tarifa_acabado_id", "proveedor_id", "nombre", "precio_total", "precio_unidad", "margen", "cubierta", "sobrecubierta", "faja"];
|
||||
protected $allowedFields = ["presupuesto_id", "tarifa_acabado_id", "proveedor_id", "nombre", "precio_total", "importe_fijo", "importe_minimo", "precio_unidad", "margen", "cubierta", "sobrecubierta", "faja"];
|
||||
protected $returnType = "App\Entities\Presupuestos\PresupuestoAcabadosEntity";
|
||||
|
||||
protected $useTimestamps = true;
|
||||
@ -48,55 +48,58 @@ class PresupuestoAcabadosModel extends \App\Models\BaseModel
|
||||
];
|
||||
|
||||
|
||||
public function getProveedoresForSelector($tarifa_acabado_id, $tirada){
|
||||
public function getProveedoresForSelector($tarifa_acabado_id, $tirada)
|
||||
{
|
||||
|
||||
$proveedores = [];
|
||||
$modelTarifa = model('App\Models\Tarifas\Acabados\TarifaAcabadoModel');
|
||||
|
||||
|
||||
$tarifa_value = $modelTarifa->getTarifaPresupuestoAcabado($tarifa_acabado_id, $tirada);
|
||||
|
||||
if (count($tarifa_value)>0) {
|
||||
foreach($tarifa_value as $tarifa)
|
||||
array_push($proveedores,
|
||||
(object)[
|
||||
'id'=> $tarifa->proveedor_id,
|
||||
'text'=> $tarifa->proveedor_nombre,
|
||||
]);
|
||||
|
||||
if (count($tarifa_value) > 0) {
|
||||
foreach ($tarifa_value as $tarifa)
|
||||
array_push(
|
||||
$proveedores,
|
||||
(object) [
|
||||
'id' => $tarifa->proveedor_id,
|
||||
'text' => $tarifa->proveedor_nombre,
|
||||
]
|
||||
);
|
||||
}
|
||||
return $proveedores;
|
||||
}
|
||||
|
||||
public function getPrecioTarifa($tarifa_acabado_id, $tirada, $proveedor_id, $POD){
|
||||
public function getPrecioTarifa($tarifa_acabado_id, $tirada, $proveedor_id, $POD)
|
||||
{
|
||||
|
||||
$modelTarifa = model('App\Models\Tarifas\Acabados\TarifaAcabadoModel');
|
||||
$tarifa_value = $modelTarifa->getTarifaPresupuestoAcabado($tarifa_acabado_id, $tirada, $proveedor_id);
|
||||
if (count($tarifa_value)>0) {
|
||||
|
||||
if (count($tarifa_value) > 0) {
|
||||
|
||||
$ret_array = [];
|
||||
foreach ($tarifa_value as $tarifa) {
|
||||
$result_data = $this->calcularTarifa($tarifa, $tirada, $POD<$tirada?false:true);
|
||||
array_push($ret_array, (object)[
|
||||
'tarifa_id'=> $tarifa->tarifa_acabado_id,
|
||||
'tarifa_nombre'=> $tarifa->tarifa_acabado_nombre,
|
||||
'nombre'=> $tarifa->tarifa_acabado_nombre,
|
||||
'precio_unidad'=> round($result_data[0], 2),
|
||||
'total'=> round($result_data[1], 2),
|
||||
'precio_total'=> round($result_data[1], 2),
|
||||
'margen'=> $result_data[2],
|
||||
$result_data = $this->calcularTarifa($tarifa, $tirada, $POD < $tirada ? false : true);
|
||||
array_push($ret_array, (object) [
|
||||
'tarifa_id' => $tarifa->tarifa_acabado_id,
|
||||
'tarifa_nombre' => $tarifa->tarifa_acabado_nombre,
|
||||
'nombre' => $tarifa->tarifa_acabado_nombre,
|
||||
'precio_unidad' => round($result_data[0], 2),
|
||||
'total' => round($result_data[1], 2),
|
||||
'precio_total' => round($result_data[1], 2),
|
||||
'margen' => $result_data[2],
|
||||
'proveedor' => $tarifa->proveedor_nombre,
|
||||
'proveedor_id' => $tarifa->proveedor_id,
|
||||
]);
|
||||
}
|
||||
usort($ret_array, function($a, $b) {
|
||||
usort($ret_array, function ($a, $b) {
|
||||
return $a->precio_total <=> $b->precio_total;
|
||||
});
|
||||
return $ret_array;
|
||||
}
|
||||
else{
|
||||
$ret_array[] = (object)[
|
||||
'tarifa_id'=> $tarifa_acabado_id,
|
||||
'tarifa_nombre'=> $modelTarifa->getNombreTarifaAcabado($tarifa_acabado_id)[0]->nombre,
|
||||
'nombre'=> $modelTarifa->getNombreTarifaAcabado($tarifa_acabado_id)[0]->nombre,
|
||||
} else {
|
||||
$ret_array[] = (object) [
|
||||
'tarifa_id' => $tarifa_acabado_id,
|
||||
'tarifa_nombre' => $modelTarifa->getNombreTarifaAcabado($tarifa_acabado_id)[0]->nombre,
|
||||
'nombre' => $modelTarifa->getNombreTarifaAcabado($tarifa_acabado_id)[0]->nombre,
|
||||
'precio_unidad' => 0,
|
||||
'total' => 0,
|
||||
'precio_total' => 0,
|
||||
@ -104,13 +107,14 @@ class PresupuestoAcabadosModel extends \App\Models\BaseModel
|
||||
'proveedor' => '',
|
||||
'proveedor_id' => 0,
|
||||
];
|
||||
return $ret_array;
|
||||
return $ret_array;
|
||||
}
|
||||
return [];
|
||||
}
|
||||
|
||||
|
||||
public function deleteAllServicios($presupuesto_id){
|
||||
|
||||
public function deleteAllServicios($presupuesto_id)
|
||||
{
|
||||
|
||||
$this->db
|
||||
->table($this->table . " t1")
|
||||
@ -118,25 +122,28 @@ class PresupuestoAcabadosModel extends \App\Models\BaseModel
|
||||
->delete();
|
||||
}
|
||||
|
||||
public function deleteServiciosNotInArray($presupuesto_id, $tarifas){
|
||||
public function deleteServiciosNotInArray($presupuesto_id, $tarifas)
|
||||
{
|
||||
|
||||
$builder = $this->db
|
||||
->table($this->table . " t1");
|
||||
->table($this->table . " t1");
|
||||
$builder->select("*");
|
||||
$builder->where('presupuesto_id', $presupuesto_id);
|
||||
$builder->where('presupuesto_id', $presupuesto_id);
|
||||
$results = $builder->get()->getResultObject();
|
||||
|
||||
$ids_for_delete = [];
|
||||
foreach($results as $result){
|
||||
$found = false;
|
||||
foreach($tarifas as $tarifa){
|
||||
if($tarifa->tarifa_id == $result->tarifa_acabado_id &&
|
||||
$tarifa->cubierta == $result->cubierta &&
|
||||
$tarifa->sobrecubierta == $result->sobrecubierta &&
|
||||
$tarifa->faja == $result->faja)
|
||||
foreach ($results as $result) {
|
||||
$found = false;
|
||||
foreach ($tarifas as $tarifa) {
|
||||
if (
|
||||
$tarifa->tarifa_id == $result->tarifa_acabado_id &&
|
||||
$tarifa->cubierta == $result->cubierta &&
|
||||
$tarifa->sobrecubierta == $result->sobrecubierta &&
|
||||
$tarifa->faja == $result->faja
|
||||
)
|
||||
$found = true;
|
||||
}
|
||||
if(!$found){
|
||||
if (!$found) {
|
||||
array_push($ids_for_delete, $result->id);
|
||||
}
|
||||
}
|
||||
@ -144,28 +151,29 @@ class PresupuestoAcabadosModel extends \App\Models\BaseModel
|
||||
$builder = $this->db
|
||||
->table($this->table . " t1");
|
||||
$builder->where('presupuesto_id', $presupuesto_id);
|
||||
foreach($ids_for_delete as $id){
|
||||
foreach ($ids_for_delete as $id) {
|
||||
$builder->orWhere('id', $id);
|
||||
}
|
||||
$builder->delete();
|
||||
}
|
||||
|
||||
public function updateTarifas($presupuesto_id, $tarifas){
|
||||
public function updateTarifas($presupuesto_id, $tarifas)
|
||||
{
|
||||
|
||||
foreach($tarifas as $tarifa){
|
||||
|
||||
$proveedor = $tarifa->proveedor_id=='undefined'?'NULL':$tarifa->proveedor_id;
|
||||
foreach ($tarifas as $tarifa) {
|
||||
|
||||
$proveedor = $tarifa->proveedor_id == 'undefined' ? 'NULL' : $tarifa->proveedor_id;
|
||||
|
||||
$builder = $this->db
|
||||
->table($this->table . " t1");
|
||||
$builder->select("id");
|
||||
$builder->where('presupuesto_id', $presupuesto_id);
|
||||
$builder->where('tarifa_acabado_id', $tarifa->tarifa_id);
|
||||
$builder->where('cubierta', $tarifa->cubierta);
|
||||
$builder->where('sobrecubierta', $tarifa->sobrecubierta);
|
||||
$builder->where('faja', $tarifa->faja);
|
||||
$builder->where('presupuesto_id', $presupuesto_id);
|
||||
$builder->where('tarifa_acabado_id', $tarifa->tarifa_id);
|
||||
$builder->where('cubierta', $tarifa->cubierta);
|
||||
$builder->where('sobrecubierta', $tarifa->sobrecubierta);
|
||||
$builder->where('faja', $tarifa->faja);
|
||||
$result = $builder->get()->getResultObject();
|
||||
if(count($result)>0){
|
||||
if (count($result) > 0) {
|
||||
$this->db
|
||||
->table($this->table . " t1")
|
||||
->where('presupuesto_id', $presupuesto_id)
|
||||
@ -178,10 +186,9 @@ class PresupuestoAcabadosModel extends \App\Models\BaseModel
|
||||
->set('sobrecubierta', $tarifa->sobrecubierta)
|
||||
->set('faja', $tarifa->faja)
|
||||
->update();
|
||||
|
||||
|
||||
}
|
||||
else{
|
||||
|
||||
} else {
|
||||
$this->db
|
||||
->table($this->table . " t1")
|
||||
->set('presupuesto_id', $presupuesto_id)
|
||||
@ -290,27 +297,28 @@ class PresupuestoAcabadosModel extends \App\Models\BaseModel
|
||||
return $builder;
|
||||
}
|
||||
|
||||
private function calcularTarifa($tarifa, $tirada, $is_POD=false){
|
||||
private function calcularTarifa($tarifa, $tirada, $is_POD = false)
|
||||
{
|
||||
|
||||
$precio_unidad = floatval($tarifa->precio_min) - (floatval($tarifa->precio_min) - floatval($tarifa->precio_max))/($tarifa->tirada_max - $tarifa->tirada_min) * ($tirada - $tarifa->tirada_min);
|
||||
$precio_unidad = floatval($tarifa->precio_min) - (floatval($tarifa->precio_min) - floatval($tarifa->precio_max)) / ($tarifa->tirada_max - $tarifa->tirada_min) * ($tirada - $tarifa->tirada_min);
|
||||
if ($tirada > $tarifa->tirada_max)
|
||||
$precio_unidad = $tarifa->precio_max;
|
||||
$precio_unidad = $precio_unidad* (1+ floatval($tarifa->margen)/100.0);
|
||||
|
||||
$precio_unidad = $precio_unidad * (1 + floatval($tarifa->margen) / 100.0);
|
||||
|
||||
if (!$is_POD) {
|
||||
$precio_unidad += floatval($tarifa->tarifa_importe_fijo)/floatval($tirada);
|
||||
}
|
||||
|
||||
$total = $precio_unidad * $tirada;
|
||||
$margen = floatval($tarifa->margen);
|
||||
|
||||
if($tarifa->tarifa_precio_min > $total){
|
||||
$total = $total-($total * $margen/100.0);
|
||||
if ($tarifa->tarifa_precio_min > $total) {
|
||||
$total = $total - ($total * $margen / 100.0);
|
||||
$margen = round(100.0 * (floatval($tarifa->tarifa_precio_min) - $total) / floatval($tarifa->tarifa_precio_min), 0);
|
||||
$total = floatval($tarifa->tarifa_precio_min);
|
||||
$precio_unidad = round(floatval($total / $tirada), 2);
|
||||
}
|
||||
|
||||
if (!$is_POD){
|
||||
$total += floatval($tarifa->tarifa_importe_fijo);
|
||||
}
|
||||
|
||||
return [$precio_unidad, $total, $margen];
|
||||
}
|
||||
|
||||
|
||||
@ -48,63 +48,65 @@ class PresupuestoEncuadernacionesModel extends \App\Models\BaseModel
|
||||
|
||||
|
||||
|
||||
public function initPresupuesto($tipo_presupuesto, $solapas, $tirada, $paginas, $ancho, $alto, $POD, $paginasCuadernillo = 32){
|
||||
|
||||
public function initPresupuesto($tipo_presupuesto, $solapas, $tirada, $paginas, $ancho, $alto, $POD, $paginasCuadernillo = 32)
|
||||
{
|
||||
|
||||
$model = model('App\Models\Presupuestos\TipoPresupuestoServiciosDefectoModel');
|
||||
$tarifas_procesar = $model->get_tarifas($tipo_presupuesto, $solapas, "encuadernacion");
|
||||
|
||||
$tarifas_procesar = $model->get_tarifas($tipo_presupuesto, $solapas, "encuadernacion");
|
||||
|
||||
$modelTarifa = model('App\Models\Tarifas\TarifaEncuadernacionModel');
|
||||
$tarifas = [];
|
||||
|
||||
foreach($tarifas_procesar as $tarifa){
|
||||
foreach ($tarifas_procesar as $tarifa) {
|
||||
|
||||
if($modelTarifa->isTarifaPorHoras($tarifa['tarifa_id'])){
|
||||
if ($modelTarifa->isTarifaPorHoras($tarifa['tarifa_id'])) {
|
||||
|
||||
if($tarifa['tarifa_id'] == 2 || $tarifa['tarifa_id'] == 14){ // Rústica cosido hilo vegetal y Rústica cosido hilo vegetal solapas
|
||||
if ($tarifa['tarifa_id'] == 2 || $tarifa['tarifa_id'] == 14) { // Rústica cosido hilo vegetal y Rústica cosido hilo vegetal solapas
|
||||
$tiempo = $this->calcularTiempoCosido(16, $paginas, $tirada, $paginasCuadernillo); // ID fija. Cambiar cuando se metan maquinas de corte. Velocidad en minutos
|
||||
}
|
||||
else{
|
||||
} else {
|
||||
$tiempo = $this->calcularTiempo(16, $paginas, $tirada); // ID fija. Cambiar cuando se metan maquinas de corte. Velocidad en minutos
|
||||
}
|
||||
|
||||
|
||||
$tarifa_value = $modelTarifa->getTarifaPresupuestoEncuadernacionHoras($tarifa['tarifa_id'], $tiempo, $tirada);
|
||||
if (count($tarifa_value)>0) {
|
||||
if (count($tarifa_value) > 0) {
|
||||
|
||||
$result_array = [];
|
||||
foreach($tarifa_value as $tarifa_proveedor){
|
||||
$precio_total = floatval(1.0* $tarifa_proveedor->precio_hora* $tiempo) * (1+$tarifa_value[0]->margen/100.0);
|
||||
if ($tirada>=$POD){
|
||||
$precio_total += floatval($tarifa_proveedor->tarifa_importe_fijo);
|
||||
}
|
||||
foreach ($tarifa_value as $tarifa_proveedor) {
|
||||
$precio_total = floatval(1.0 * $tarifa_proveedor->precio_hora * $tiempo) * (1 + $tarifa_value[0]->margen / 100.0);
|
||||
if ($tirada >= $POD) {
|
||||
$precio_total += floatval($tarifa_proveedor->tarifa_importe_fijo);
|
||||
}
|
||||
|
||||
$result_data[0] = round(floatval($precio_total / $tirada), 2); // Precio/unidad
|
||||
$result_data[1] = round($result_data[0] * $tirada, 2);
|
||||
$result_data[2] = $tarifa_proveedor->margen; // margen
|
||||
|
||||
$result_data[0] = floatval($precio_total / $tirada); // Precio/unidad
|
||||
$result_data[1] = $precio_total;
|
||||
$result_data[2] = $tarifa_proveedor->margen ; // margen
|
||||
|
||||
$datos = [
|
||||
'tarifa_id'=> $tarifa['tarifa_id'],
|
||||
'tarifa_nombre'=> $tarifa_proveedor->tarifa_enc_nombre,
|
||||
'nombre'=> $tarifa_proveedor->tarifa_enc_nombre,
|
||||
'precio_unidad'=> $result_data[0],
|
||||
'tarifa_id' => $tarifa['tarifa_id'],
|
||||
'tarifa_nombre' => $tarifa_proveedor->tarifa_enc_nombre,
|
||||
'nombre' => $tarifa_proveedor->tarifa_enc_nombre,
|
||||
'precio_unidad' => $result_data[0],
|
||||
'tiempo' => $tiempo,
|
||||
'total'=> $result_data[1],
|
||||
'precio_total'=> $result_data[1],
|
||||
'total' => $result_data[1],
|
||||
'precio_total' => $result_data[1],
|
||||
'margen' => $result_data[2],
|
||||
'proveedor' => $tarifa_proveedor->proveedor_nombre,
|
||||
'proveedor_id' => $tarifa_proveedor->proveedor_id,
|
||||
];
|
||||
|
||||
if($tarifa['tarifa_id'] == 2 || $tarifa['tarifa_id'] == 14){
|
||||
if ($tarifa['tarifa_id'] == 2 || $tarifa['tarifa_id'] == 14) {
|
||||
$datos['paginas_por_cuadernillo'] = $paginasCuadernillo;
|
||||
}
|
||||
|
||||
array_push($result_array,
|
||||
(object)$datos);
|
||||
array_push(
|
||||
$result_array,
|
||||
(object) $datos
|
||||
);
|
||||
}
|
||||
|
||||
usort($result_array, function($a, $b) {
|
||||
|
||||
if ($a->total == $b->total) {
|
||||
usort($result_array, function ($a, $b) {
|
||||
|
||||
if ($a->total == $b->total) {
|
||||
return 0;
|
||||
}
|
||||
return ($a->total < $b->total) ? -1 : 1;
|
||||
@ -113,66 +115,67 @@ class PresupuestoEncuadernacionesModel extends \App\Models\BaseModel
|
||||
array_push($tarifas, $result_array[0]);
|
||||
|
||||
|
||||
} else {
|
||||
array_push(
|
||||
$tarifas,
|
||||
(object) [
|
||||
'tarifa_id' => $tarifa['tarifa_id'],
|
||||
'tarifa_nombre' => $tarifa['tarifa_nombre'],
|
||||
'nombre' => $tarifa['tarifa_nombre'],
|
||||
'proveedor' => lang('Presupuestos.no_disponible'),
|
||||
'precio_unidad' => 0,
|
||||
'tiempo' => null,
|
||||
'total' => 0,
|
||||
'precio_total' => 0,
|
||||
'margen' => 0,
|
||||
]
|
||||
);
|
||||
}
|
||||
else{
|
||||
array_push($tarifas,
|
||||
(object)[
|
||||
'tarifa_id'=> $tarifa['tarifa_id'],
|
||||
'tarifa_nombre'=> $tarifa['tarifa_nombre'],
|
||||
'nombre'=> $tarifa['tarifa_nombre'],
|
||||
'proveedor' => lang('Presupuestos.no_disponible'),
|
||||
'precio_unidad'=> 0,
|
||||
'tiempo' => null,
|
||||
'total'=> 0,
|
||||
'precio_total'=> 0,
|
||||
'margen' => 0,
|
||||
]);
|
||||
}
|
||||
}
|
||||
else{
|
||||
} else {
|
||||
$tarifa_value = $modelTarifa->getTarifaPresupuestoEncuadernacion($tarifa['tarifa_id'], $paginas, $tirada, $ancho, $alto);
|
||||
if (count($tarifa_value)>0) {
|
||||
if (count($tarifa_value) > 0) {
|
||||
|
||||
$result_array = [];
|
||||
foreach($tarifa_value as $tarifa_proveedor){
|
||||
$result_data = $this->calcularTarifa($tarifa_proveedor, $paginas, $tirada, $POD<$tirada?false:true);
|
||||
array_push($result_array, (object)[
|
||||
'tarifa_id'=> $tarifa_proveedor->tarifa_enc_id,
|
||||
'tarifa_nombre'=> $tarifa_proveedor->tarifa_enc_nombre,
|
||||
'nombre'=> $tarifa_proveedor->tarifa_enc_nombre,
|
||||
'precio_unidad'=> $result_data[0],
|
||||
foreach ($tarifa_value as $tarifa_proveedor) {
|
||||
$result_data = $this->calcularTarifa($tarifa_proveedor, $paginas, $tirada, $POD < $tirada ? false : true);
|
||||
array_push($result_array, (object) [
|
||||
'tarifa_id' => $tarifa_proveedor->tarifa_enc_id,
|
||||
'tarifa_nombre' => $tarifa_proveedor->tarifa_enc_nombre,
|
||||
'nombre' => $tarifa_proveedor->tarifa_enc_nombre,
|
||||
'precio_unidad' => $result_data[0],
|
||||
'tiempo' => null,
|
||||
'total'=> $result_data[1],
|
||||
'precio_total'=> $result_data[1],
|
||||
'margen'=> $result_data[2],
|
||||
'total' => $result_data[1],
|
||||
'precio_total' => $result_data[1],
|
||||
'margen' => $result_data[2],
|
||||
'proveedor' => $tarifa_proveedor->proveedor_nombre,
|
||||
'proveedor_id' => $tarifa_proveedor->proveedor_id,
|
||||
]);
|
||||
}
|
||||
|
||||
usort($result_array, function($a, $b) {
|
||||
|
||||
if ($a->total == $b->total) {
|
||||
usort($result_array, function ($a, $b) {
|
||||
|
||||
if ($a->total == $b->total) {
|
||||
return 0;
|
||||
}
|
||||
return ($a->total < $b->total) ? -1 : 1;
|
||||
});
|
||||
|
||||
array_push($tarifas, $result_array[0]);
|
||||
}
|
||||
else{
|
||||
array_push($tarifas,
|
||||
(object)[
|
||||
'tarifa_id'=> $tarifa['tarifa_id'] ,
|
||||
'tarifa_nombre'=> $tarifa['tarifa_nombre'],
|
||||
'nombre'=> $tarifa['tarifa_nombre'],
|
||||
} else {
|
||||
array_push(
|
||||
$tarifas,
|
||||
(object) [
|
||||
'tarifa_id' => $tarifa['tarifa_id'],
|
||||
'tarifa_nombre' => $tarifa['tarifa_nombre'],
|
||||
'nombre' => $tarifa['tarifa_nombre'],
|
||||
'proveedor' => lang('Presupuestos.no_disponible'),
|
||||
'precio_unidad'=> 0,
|
||||
'precio_unidad' => 0,
|
||||
'tiempo' => null,
|
||||
'total'=> 0,
|
||||
'precio_total'=> 0,
|
||||
'total' => 0,
|
||||
'precio_total' => 0,
|
||||
'margen' => 0,
|
||||
]);
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -181,202 +184,211 @@ class PresupuestoEncuadernacionesModel extends \App\Models\BaseModel
|
||||
}
|
||||
|
||||
|
||||
public function getProveedoresForSelector($tarifa_encuadernacion_id, $paginas, $tirada, $ancho, $alto, $paginasCuadernillo = 32){
|
||||
public function getProveedoresForSelector($tarifa_encuadernacion_id, $paginas, $tirada, $ancho, $alto, $paginasCuadernillo = 32)
|
||||
{
|
||||
|
||||
$proveedores = [];
|
||||
$modelTarifa = model('App\Models\Tarifas\TarifaEncuadernacionModel');
|
||||
|
||||
if($modelTarifa->isTarifaPorHoras($tarifa_encuadernacion_id)){
|
||||
|
||||
if ($modelTarifa->isTarifaPorHoras($tarifa_encuadernacion_id)) {
|
||||
$tiempo = $this->calcularTiempoCosido(16, $paginas, $tirada, $paginasCuadernillo); // ID fija. Cambiar cuando se metan maquinas de corte. Velocidad en minutos
|
||||
$tarifa_value = $modelTarifa->getTarifaPresupuestoEncuadernacionHoras($tarifa_encuadernacion_id, $tiempo, $tirada);
|
||||
}
|
||||
else{
|
||||
} else {
|
||||
$tiempo = $this->calcularTiempo(16, $paginas, $tirada); // ID fija. Cambiar cuando se metan maquinas de corte. Velocidad en minutos
|
||||
$tarifa_value = $modelTarifa->getTarifaPresupuestoEncuadernacion($tarifa_encuadernacion_id, $paginas, $tirada, $ancho, $alto);
|
||||
}
|
||||
if (count($tarifa_value)>0) {
|
||||
foreach($tarifa_value as $tarifa)
|
||||
array_push($proveedores,
|
||||
(object)[
|
||||
'id'=> $tarifa->proveedor_id,
|
||||
'text'=> $tarifa->proveedor_nombre,
|
||||
]);
|
||||
if (count($tarifa_value) > 0) {
|
||||
foreach ($tarifa_value as $tarifa)
|
||||
array_push(
|
||||
$proveedores,
|
||||
(object) [
|
||||
'id' => $tarifa->proveedor_id,
|
||||
'text' => $tarifa->proveedor_nombre,
|
||||
]
|
||||
);
|
||||
}
|
||||
return $proveedores;
|
||||
}
|
||||
|
||||
public function getPrecioTarifa($tarifa_encuadernacion_id, $paginas, $tirada, $ancho, $alto, $proveedor_id, $POD){
|
||||
public function getPrecioTarifa($tarifa_encuadernacion_id, $paginas, $tirada, $ancho, $alto, $proveedor_id, $POD)
|
||||
{
|
||||
|
||||
$modelTarifa = model('App\Models\Tarifas\TarifaEncuadernacionModel');
|
||||
if($proveedor_id != -1){
|
||||
if ($proveedor_id != -1) {
|
||||
$tarifa_value = $modelTarifa->getTarifaPresupuestoEncuadernacion($tarifa_encuadernacion_id, $paginas, $tirada, $ancho, $alto, $proveedor_id);
|
||||
}
|
||||
else{
|
||||
} else {
|
||||
$tarifa_value = $modelTarifa->getTarifaPresupuestoEncuadernacion($tarifa_encuadernacion_id, $paginas, $tirada, $ancho, $alto);
|
||||
}
|
||||
if (count($tarifa_value)>0) {
|
||||
if (count($tarifa_value) > 0) {
|
||||
|
||||
$ret_array = [];
|
||||
foreach($tarifa_value as $tarifa){
|
||||
foreach ($tarifa_value as $tarifa) {
|
||||
|
||||
$result_data = $this->calcularTarifa($tarifa, $paginas, $tirada, $POD<$tirada?false:true);
|
||||
array_push($ret_array, (object)[
|
||||
'tarifa_id'=> $tarifa->tarifa_enc_id,
|
||||
'tarifa_nombre'=> $tarifa->tarifa_enc_nombre,
|
||||
'nombre'=> $tarifa->tarifa_enc_nombre,
|
||||
'precio_unidad'=> $result_data[0],
|
||||
$result_data = $this->calcularTarifa($tarifa, $paginas, $tirada, $POD < $tirada ? false : true);
|
||||
array_push($ret_array, (object) [
|
||||
'tarifa_id' => $tarifa->tarifa_enc_id,
|
||||
'tarifa_nombre' => $tarifa->tarifa_enc_nombre,
|
||||
'nombre' => $tarifa->tarifa_enc_nombre,
|
||||
'precio_unidad' => $result_data[0],
|
||||
'tiempo' => null,
|
||||
'total'=> $result_data[1],
|
||||
'precio_total'=> $result_data[1],
|
||||
'margen'=> $result_data[2],
|
||||
'total' => $result_data[1],
|
||||
'precio_total' => $result_data[1],
|
||||
'margen' => $result_data[2],
|
||||
'proveedor' => $tarifa->proveedor_nombre,
|
||||
'proveedor_id' => $tarifa->proveedor_id,
|
||||
]);
|
||||
}
|
||||
|
||||
usort($ret_array, function($a, $b) {
|
||||
|
||||
if ($a->total == $b->total) {
|
||||
|
||||
usort($ret_array, function ($a, $b) {
|
||||
|
||||
if ($a->total == $b->total) {
|
||||
return 0;
|
||||
}
|
||||
return ($a->total < $b->total) ? -1 : 1;
|
||||
});
|
||||
return $ret_array;
|
||||
}
|
||||
else{
|
||||
$ret_array[] = (object)[
|
||||
'tarifa_id'=> $tarifa_encuadernacion_id,
|
||||
'tarifa_nombre'=> $modelTarifa->getNombreTarifaEncuadernacion($tarifa_encuadernacion_id)[0]->nombre,
|
||||
'nombre'=> $modelTarifa->getNombreTarifaEncuadernacion($tarifa_encuadernacion_id)[0]->nombre,
|
||||
} else {
|
||||
$ret_array[] = (object) [
|
||||
'tarifa_id' => $tarifa_encuadernacion_id,
|
||||
'tarifa_nombre' => $modelTarifa->getNombreTarifaEncuadernacion($tarifa_encuadernacion_id)[0]->nombre,
|
||||
'nombre' => $modelTarifa->getNombreTarifaEncuadernacion($tarifa_encuadernacion_id)[0]->nombre,
|
||||
'proveedor' => lang('Presupuestos.no_disponible'),
|
||||
'precio_unidad'=> 0,
|
||||
'precio_unidad' => 0,
|
||||
'tiempo' => null,
|
||||
'total'=> 0,
|
||||
'precio_total'=> 0,
|
||||
'margen'=> 0,
|
||||
'total' => 0,
|
||||
'precio_total' => 0,
|
||||
'margen' => 0,
|
||||
];
|
||||
return $ret_array;
|
||||
return $ret_array;
|
||||
}
|
||||
return [];
|
||||
}
|
||||
|
||||
public function getPrecioTarifaHoras($tarifa_encuadernacion_id, $paginas, $tirada, $proveedor_id, $POD, $paginas_cuadernillo = 32){
|
||||
|
||||
public function getPrecioTarifaHoras($tarifa_encuadernacion_id, $paginas, $tirada, $proveedor_id, $POD, $paginas_cuadernillo = 32)
|
||||
{
|
||||
|
||||
$modelTarifa = model('App\Models\Tarifas\TarifaEncuadernacionModel');
|
||||
|
||||
if($tarifa_encuadernacion_id == 2 || $tarifa_encuadernacion_id == 14){ // Rústica cosido hilo vegetal y Rústica cosido hilo vegetal solapas
|
||||
|
||||
if ($tarifa_encuadernacion_id == 2 || $tarifa_encuadernacion_id == 14) { // Rústica cosido hilo vegetal y Rústica cosido hilo vegetal solapas
|
||||
$tiempo = $this->calcularTiempoCosido(16, $paginas, $tirada, $paginas_cuadernillo); // ID fija. Cambiar cuando se metan maquinas de corte. Velocidad en minutos
|
||||
}
|
||||
else{
|
||||
} else {
|
||||
$tiempo = $this->calcularTiempo(16, $paginas, $tirada); // ID fija. Cambiar cuando se metan maquinas de corte. Velocidad en minutos
|
||||
}
|
||||
|
||||
|
||||
$tarifa_value = $modelTarifa->getTarifaPresupuestoEncuadernacionHoras($tarifa_encuadernacion_id, $tiempo, $tirada, $proveedor_id);
|
||||
if (count($tarifa_value)>0) {
|
||||
|
||||
if (count($tarifa_value) > 0) {
|
||||
|
||||
$ret_array = [];
|
||||
foreach($tarifa_value as $tarifa_proveedor){
|
||||
$precio_total = floatval(1.0* $tarifa_proveedor->precio_hora* $tiempo) * (1+$tarifa_value[0]->margen/100.0);
|
||||
if ($tirada>=$POD){
|
||||
$precio_total += floatval($tarifa_proveedor->tarifa_importe_fijo);
|
||||
foreach ($tarifa_value as $tarifa_proveedor) {
|
||||
$precio_total = floatval(1.0 * $tarifa_proveedor->precio_hora * $tiempo) * (1 + $tarifa_value[0]->margen / 100.0);
|
||||
if ($tirada >= $POD) {
|
||||
$precio_total += floatval($tarifa_proveedor->tarifa_importe_fijo);
|
||||
}
|
||||
|
||||
|
||||
$tarifa_precio_min = floatval($tarifa_proveedor->tarifa_precio_min);
|
||||
|
||||
if($tarifa_precio_min > $precio_total){
|
||||
$total = $total-($total * $margen/100.0);
|
||||
$margen = round(100.0 * (floatval($$tarifa_precio_min) - $total) / floatval($$tarifa_precio_min), 0);
|
||||
$total = floatval($$tarifa_precio_min);
|
||||
if ($tarifa_precio_min > $precio_total) {
|
||||
$precio_total = $precio_total - ($precio_total * $margen / 100.0);
|
||||
$margen = round(100.0 * (floatval($tarifa_precio_min) - $precio_total) / floatval($tarifa_precio_min), 0);
|
||||
$precio_total = floatval($tarifa_precio_min);
|
||||
}
|
||||
|
||||
$result_data[0] = floatval($precio_total / $tirada); // Precio/unidad
|
||||
$result_data[1] = $precio_total;
|
||||
$result_data[2] = $tarifa_proveedor->margen ; // margen
|
||||
$precio_total = round($precio_total, 2);
|
||||
|
||||
|
||||
array_push($ret_array,
|
||||
(object)[
|
||||
'tarifa_id'=> $tarifa_proveedor->tarifa_enc_id,
|
||||
'tarifa_nombre'=> $tarifa_proveedor->tarifa_enc_nombre,
|
||||
'nombre'=> $tarifa_proveedor->tarifa_enc_nombre,
|
||||
'precio_unidad'=> $result_data[0],
|
||||
'tiempo' => $tiempo,
|
||||
'paginas_por_cuadernillo' => $paginas_cuadernillo,
|
||||
'precio_total'=> $result_data[1],
|
||||
'total'=> $result_data[1],
|
||||
'margen' => $result_data[2],
|
||||
'proveedor' => $tarifa_proveedor->proveedor_nombre,
|
||||
'proveedor_id' => $tarifa_proveedor->proveedor_id,
|
||||
]);
|
||||
$result_data[0] = round(floatval($precio_total / $tirada), 2); // Precio/unidad
|
||||
$result_data[1] = round($result_data[0] * $tirada, 2);
|
||||
$result_data[2] = $tarifa_proveedor->margen; // margen
|
||||
|
||||
|
||||
array_push(
|
||||
$ret_array,
|
||||
(object) [
|
||||
'tarifa_id' => $tarifa_proveedor->tarifa_enc_id,
|
||||
'tarifa_nombre' => $tarifa_proveedor->tarifa_enc_nombre,
|
||||
'nombre' => $tarifa_proveedor->tarifa_enc_nombre,
|
||||
'precio_unidad' => $result_data[0],
|
||||
'tiempo' => $tiempo,
|
||||
'paginas_por_cuadernillo' => $paginas_cuadernillo,
|
||||
'precio_total' => $result_data[1],
|
||||
'total' => $result_data[1],
|
||||
'margen' => $result_data[2],
|
||||
'proveedor' => $tarifa_proveedor->proveedor_nombre,
|
||||
'proveedor_id' => $tarifa_proveedor->proveedor_id,
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
usort($ret_array, function($a, $b) {
|
||||
usort($ret_array, function ($a, $b) {
|
||||
|
||||
if ($a->total == $b->total) {
|
||||
if ($a->total == $b->total) {
|
||||
return 0;
|
||||
}
|
||||
return ($a->total < $b->total) ? -1 : 1;
|
||||
});
|
||||
|
||||
return $ret_array;
|
||||
}
|
||||
else{
|
||||
$ret_array[] = (object)[
|
||||
'tarifa_id'=> $tarifa_encuadernacion_id,
|
||||
'tarifa_nombre'=> $modelTarifa->getNombreTarifaEncuadernacion($tarifa_encuadernacion_id)[0]->nombre,
|
||||
'nombre'=> $modelTarifa->getNombreTarifaEncuadernacion($tarifa_encuadernacion_id)[0]->nombre,
|
||||
} else {
|
||||
$ret_array[] = (object) [
|
||||
'tarifa_id' => $tarifa_encuadernacion_id,
|
||||
'tarifa_nombre' => $modelTarifa->getNombreTarifaEncuadernacion($tarifa_encuadernacion_id)[0]->nombre,
|
||||
'nombre' => $modelTarifa->getNombreTarifaEncuadernacion($tarifa_encuadernacion_id)[0]->nombre,
|
||||
'proveedor' => lang('Presupuestos.no_disponible'),
|
||||
'precio_unidad'=> 0,
|
||||
'precio_unidad' => 0,
|
||||
'tiempo' => null,
|
||||
'paginas_por_cuadernillo' => null,
|
||||
'total'=> 0,
|
||||
'precio_total'=> 0,
|
||||
'total' => 0,
|
||||
'precio_total' => 0,
|
||||
'margen' => 0,
|
||||
];
|
||||
return $ret_array;
|
||||
return $ret_array;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private function calcularTarifa($tarifa, $paginas, $ejemplares, $is_POD=false){
|
||||
private function calcularTarifa($tarifa, $paginas, $ejemplares, $is_POD = false)
|
||||
{
|
||||
|
||||
$precio_unidad = floatval($tarifa->precio_max) - (floatval($tarifa->precio_max) - floatval($tarifa->precio_min))/($tarifa->paginas_max - $tarifa->paginas_min) * ($paginas - $tarifa->paginas_min);
|
||||
$precio_unidad = floatval($tarifa->precio_max) - (floatval($tarifa->precio_max) - floatval($tarifa->precio_min)) / ($tarifa->paginas_max - $tarifa->paginas_min) * ($paginas - $tarifa->paginas_min);
|
||||
if ($paginas > $tarifa->paginas_max)
|
||||
$precio_unidad = $tarifa->precio_max;
|
||||
$precio_unidad = $precio_unidad* (1+ floatval($tarifa->margen)/100.0);
|
||||
|
||||
$precio_unidad = $precio_unidad * (1 + floatval($tarifa->margen) / 100.0);
|
||||
|
||||
if (!$is_POD) {
|
||||
$precio_unidad += floatval($tarifa->tarifa_importe_fijo) / floatval($ejemplares);
|
||||
}
|
||||
|
||||
$precio_unidad = round($precio_unidad, 2);
|
||||
|
||||
$total = $precio_unidad * $ejemplares;
|
||||
$margen = floatval($tarifa->margen);
|
||||
$tarifa_precio_min = floatval($tarifa->tarifa_precio_min);
|
||||
|
||||
if($tarifa_precio_min > $total){
|
||||
$total = $total-($total * $margen/100.0);
|
||||
if ($tarifa_precio_min > $total) {
|
||||
$total = $total - ($total * $margen / 100.0);
|
||||
$margen = round(100.0 * (floatval($tarifa_precio_min) - $total) / floatval($tarifa_precio_min), 0);
|
||||
$total = floatval($tarifa_precio_min);
|
||||
$precio_unidad = round(floatval($total / $ejemplares), 2);
|
||||
}
|
||||
|
||||
if (!$is_POD){
|
||||
$total += floatval($tarifa->tarifa_importe_fijo);
|
||||
}
|
||||
|
||||
return [$precio_unidad, $total, $margen];
|
||||
}
|
||||
|
||||
|
||||
public function getIdFromTarifa($tarifa_id){
|
||||
|
||||
public function getIdFromTarifa($tarifa_id)
|
||||
{
|
||||
|
||||
$builder = $this->db
|
||||
->table($this->table . " t1")
|
||||
->select(
|
||||
"t1.id AS id"
|
||||
);
|
||||
->table($this->table . " t1")
|
||||
->select(
|
||||
"t1.id AS id"
|
||||
);
|
||||
$builder->where('t1.tarifa_encuadernado_id', $tarifa_id);
|
||||
return $builder;
|
||||
}
|
||||
|
||||
|
||||
public function deleteAllServicios($presupuesto_id){
|
||||
public function deleteAllServicios($presupuesto_id)
|
||||
{
|
||||
|
||||
$this->db
|
||||
->table($this->table . " t1")
|
||||
@ -384,30 +396,32 @@ class PresupuestoEncuadernacionesModel extends \App\Models\BaseModel
|
||||
->delete();
|
||||
}
|
||||
|
||||
public function deleteServiciosNotInArray($presupuesto_id, $tarifas_id){
|
||||
public function deleteServiciosNotInArray($presupuesto_id, $tarifas_id)
|
||||
{
|
||||
|
||||
$builder = $this->db
|
||||
->table($this->table . " t1");
|
||||
$builder->where('presupuesto_id', $presupuesto_id);
|
||||
foreach($tarifas_id as $id){
|
||||
foreach ($tarifas_id as $id) {
|
||||
$builder->where('tarifa_encuadernado_id !=', $id);
|
||||
}
|
||||
$builder->delete();
|
||||
}
|
||||
|
||||
public function updateTarifas($presupuesto_id, $tarifas){
|
||||
public function updateTarifas($presupuesto_id, $tarifas)
|
||||
{
|
||||
|
||||
foreach($tarifas as $tarifa){
|
||||
|
||||
$proveedor = $tarifa->proveedor_id=='undefined'?'NULL':$tarifa->proveedor_id;
|
||||
foreach ($tarifas as $tarifa) {
|
||||
|
||||
$proveedor = $tarifa->proveedor_id == 'undefined' ? 'NULL' : $tarifa->proveedor_id;
|
||||
$builder = $this->db
|
||||
->table($this->table . " t1");
|
||||
$builder->select("id");
|
||||
$builder->where('presupuesto_id', $presupuesto_id);
|
||||
$builder->where('tarifa_encuadernado_id', $tarifa->tarifa_id);
|
||||
$builder->where('presupuesto_id', $presupuesto_id);
|
||||
$builder->where('tarifa_encuadernado_id', $tarifa->tarifa_id);
|
||||
$result = $builder->get()->getResultObject();
|
||||
$paginas_cuadernillo = $tarifa->paginas_por_cuadernillo??null;
|
||||
if(count($result)>0){
|
||||
$paginas_cuadernillo = $tarifa->paginas_por_cuadernillo ?? null;
|
||||
if (count($result) > 0) {
|
||||
$this->db
|
||||
->table($this->table . " t1")
|
||||
->where('presupuesto_id', $presupuesto_id)
|
||||
@ -419,10 +433,9 @@ class PresupuestoEncuadernacionesModel extends \App\Models\BaseModel
|
||||
->set('margen', $tarifa->margen)
|
||||
->set('paginas_por_cuadernillo', $paginas_cuadernillo)
|
||||
->update();
|
||||
|
||||
|
||||
}
|
||||
else{
|
||||
|
||||
} else {
|
||||
$this->db
|
||||
->table($this->table . " t1")
|
||||
->set('presupuesto_id', $presupuesto_id)
|
||||
@ -461,21 +474,23 @@ class PresupuestoEncuadernacionesModel extends \App\Models\BaseModel
|
||||
return $builder;
|
||||
}
|
||||
|
||||
private function calcularTiempo($maquina_id, $paginas, $tirada){
|
||||
private function calcularTiempo($maquina_id, $paginas, $tirada)
|
||||
{
|
||||
|
||||
$maquinaModel = model("App\Models\Configuracion\MaquinaModel");
|
||||
$cuadernillos_libro = $paginas/4;
|
||||
$cuadernillos_pedido = $cuadernillos_libro*$tirada;
|
||||
$velocidad = $maquinaModel->getVelocidad($maquina_id);
|
||||
return round($cuadernillos_pedido/($velocidad*60.0), 2);
|
||||
$cuadernillos_libro = $paginas / 4;
|
||||
$cuadernillos_pedido = $cuadernillos_libro * $tirada;
|
||||
$velocidad = $maquinaModel->getVelocidad($maquina_id);
|
||||
return round($cuadernillos_pedido / ($velocidad * 60.0), 2);
|
||||
}
|
||||
|
||||
private function calcularTiempoCosido($maquina_id, $paginas, $tirada, $cuadernillos_por_pagina = 32){
|
||||
|
||||
private function calcularTiempoCosido($maquina_id, $paginas, $tirada, $cuadernillos_por_pagina = 32)
|
||||
{
|
||||
|
||||
$maquinaModel = model("App\Models\Configuracion\MaquinaModel");
|
||||
$velocidad = $maquinaModel->getVelocidad($maquina_id); // cuadernillos por minuto
|
||||
$cuadernillos_libro = ceil($paginas/intval($cuadernillos_por_pagina));
|
||||
$cuadernillos_pedido = $cuadernillos_libro*$tirada;
|
||||
return round($cuadernillos_pedido/($velocidad*60.0), 2); // tiempo en segundos
|
||||
$cuadernillos_libro = ceil($paginas / intval($cuadernillos_por_pagina));
|
||||
$cuadernillos_pedido = $cuadernillos_libro * $tirada;
|
||||
return round($cuadernillos_pedido / ($velocidad * 60.0), 2); // tiempo en segundos
|
||||
}
|
||||
}
|
||||
|
||||
@ -45,81 +45,82 @@ class PresupuestoManipuladosModel extends \App\Models\BaseModel
|
||||
];
|
||||
|
||||
|
||||
public function getPrecioTarifa($tarifa_manipulado_id, $tirada, $POD){
|
||||
public function getPrecioTarifa($tarifa_manipulado_id, $tirada, $POD)
|
||||
{
|
||||
|
||||
$modelTarifa = model('App\Models\Tarifas\TarifaManipuladoModel');
|
||||
$tarifa_value = $modelTarifa->getTarifaPresupuestoManipulado($tarifa_manipulado_id, $tirada);
|
||||
if (count($tarifa_value)>0) {
|
||||
if (count($tarifa_value) > 0) {
|
||||
$ret_array = [];
|
||||
foreach($tarifa_value as $tarifa){
|
||||
$result_data = $this->calcularTarifa($tarifa, $tirada, $POD<$tirada?false:true);
|
||||
array_push($ret_array, (object)[
|
||||
'tarifa_id'=> $tarifa->tarifa_manipulado_id,
|
||||
'tarifa_nombre'=> $tarifa->tarifa_manipulado_nombre,
|
||||
'nombre'=> $tarifa->tarifa_manipulado_nombre,
|
||||
'precio_unidad'=> $result_data[0],
|
||||
'total'=> $result_data[1],
|
||||
'precio_total'=> $result_data[1],
|
||||
foreach ($tarifa_value as $tarifa) {
|
||||
$result_data = $this->calcularTarifa($tarifa, $tirada, $POD < $tirada ? false : true);
|
||||
array_push($ret_array, (object) [
|
||||
'tarifa_id' => $tarifa->tarifa_manipulado_id,
|
||||
'tarifa_nombre' => $tarifa->tarifa_manipulado_nombre,
|
||||
'nombre' => $tarifa->tarifa_manipulado_nombre,
|
||||
'precio_unidad' => $result_data[0],
|
||||
'total' => $result_data[1],
|
||||
'precio_total' => $result_data[1],
|
||||
'margen' => $result_data[2],
|
||||
]);
|
||||
}
|
||||
|
||||
usort($ret_array, function($a, $b) {
|
||||
usort($ret_array, function ($a, $b) {
|
||||
return $a->precio_total <=> $b->precio_total;
|
||||
});
|
||||
|
||||
|
||||
return $ret_array;
|
||||
}
|
||||
else{
|
||||
if(is_array($tarifa_manipulado_id)){
|
||||
$ret_array[] = (object)[
|
||||
'tarifa_id'=> $tarifa_manipulado_id['id'],
|
||||
'tarifa_nombre'=> $tarifa_manipulado_id['nombre'],
|
||||
'nombre'=> $tarifa_manipulado_id['nombre'],
|
||||
} else {
|
||||
if (is_array($tarifa_manipulado_id)) {
|
||||
$ret_array[] = (object) [
|
||||
'tarifa_id' => $tarifa_manipulado_id['id'],
|
||||
'tarifa_nombre' => $tarifa_manipulado_id['nombre'],
|
||||
'nombre' => $tarifa_manipulado_id['nombre'],
|
||||
'precio_unidad' => 0,
|
||||
'total'=> 0,
|
||||
'total' => 0,
|
||||
'margen' => 0,
|
||||
];
|
||||
}
|
||||
else{
|
||||
$ret_array[] = (object)[
|
||||
'tarifa_id'=> $tarifa_manipulado_id,
|
||||
'tarifa_nombre'=> $modelTarifa->getNombreTarifaManipulado($tarifa_manipulado_id)[0]->nombre,
|
||||
'nombre'=> $modelTarifa->getNombreTarifaManipulado($tarifa_manipulado_id)[0]->nombre,
|
||||
];
|
||||
} else {
|
||||
$ret_array[] = (object) [
|
||||
'tarifa_id' => $tarifa_manipulado_id,
|
||||
'tarifa_nombre' => $modelTarifa->getNombreTarifaManipulado($tarifa_manipulado_id)[0]->nombre,
|
||||
'nombre' => $modelTarifa->getNombreTarifaManipulado($tarifa_manipulado_id)[0]->nombre,
|
||||
'precio_unidad' => 0,
|
||||
'total'=> 0,
|
||||
'total' => 0,
|
||||
'margen' => 0,
|
||||
];
|
||||
}
|
||||
return $ret_array;
|
||||
return $ret_array;
|
||||
}
|
||||
}
|
||||
|
||||
private function calcularTarifa($tarifa, $tirada, $is_POD=false){
|
||||
private function calcularTarifa($tarifa, $tirada, $is_POD = false)
|
||||
{
|
||||
|
||||
$precio_unidad = floatval($tarifa->precio_min) - (floatval($tarifa->precio_min) - floatval($tarifa->precio_max))/($tarifa->tirada_max - $tarifa->tirada_min) * ($tirada - $tarifa->tirada_min);
|
||||
$precio_unidad = floatval($tarifa->precio_min) - (floatval($tarifa->precio_min) - floatval($tarifa->precio_max)) / ($tarifa->tirada_max - $tarifa->tirada_min) * ($tirada - $tarifa->tirada_min);
|
||||
if ($tirada > $tarifa->tirada_max)
|
||||
$precio_unidad = $tarifa->precio_max;
|
||||
$precio_unidad = $precio_unidad* (1+ floatval($tarifa->margen)/100.0);
|
||||
|
||||
$precio_unidad = $precio_unidad * (1 + floatval($tarifa->margen) / 100.0);
|
||||
|
||||
if (!$is_POD) {
|
||||
$precio_unidad += floatval($tarifa->tarifa_importe_fijo)/floatval($tirada);
|
||||
}
|
||||
|
||||
$total = $precio_unidad * $tirada;
|
||||
$margen = floatval($tarifa->margen);
|
||||
|
||||
if($tarifa->tarifa_precio_min > $total){
|
||||
$total = $total-($total * $margen/100.0);
|
||||
if ($tarifa->tarifa_precio_min > $total) {
|
||||
$total = $total - ($total * $margen / 100.0);
|
||||
$margen = round(100.0 * (floatval($tarifa->tarifa_precio_min) - $total) / floatval($tarifa->tarifa_precio_min), 0);
|
||||
$total = floatval($tarifa->tarifa_precio_min);
|
||||
$precio_unidad = round(floatval($total / $tirada), 2);
|
||||
}
|
||||
|
||||
if (!$is_POD){
|
||||
$total += floatval($tarifa->tarifa_importe_fijo);
|
||||
}
|
||||
|
||||
return [$precio_unidad, $total, $margen];
|
||||
}
|
||||
|
||||
public function deleteAllServicios($presupuesto_id){
|
||||
public function deleteAllServicios($presupuesto_id)
|
||||
{
|
||||
|
||||
$this->db
|
||||
->table($this->table . " t1")
|
||||
@ -127,28 +128,30 @@ class PresupuestoManipuladosModel extends \App\Models\BaseModel
|
||||
->delete();
|
||||
}
|
||||
|
||||
public function deleteServiciosNotInArray($presupuesto_id, $tarifas_id){
|
||||
public function deleteServiciosNotInArray($presupuesto_id, $tarifas_id)
|
||||
{
|
||||
|
||||
$builder = $this->db
|
||||
->table($this->table . " t1");
|
||||
$builder->where('presupuesto_id', $presupuesto_id);
|
||||
foreach($tarifas_id as $id){
|
||||
foreach ($tarifas_id as $id) {
|
||||
$builder->where('tarifa_manipulado_id !=', $id);
|
||||
}
|
||||
$builder->delete();
|
||||
}
|
||||
|
||||
public function updateTarifas($presupuesto_id, $tarifas){
|
||||
public function updateTarifas($presupuesto_id, $tarifas)
|
||||
{
|
||||
|
||||
foreach ($tarifas as $tarifa) {
|
||||
|
||||
foreach($tarifas as $tarifa){
|
||||
|
||||
$builder = $this->db
|
||||
->table($this->table . " t1");
|
||||
$builder->select("id");
|
||||
$builder->where('presupuesto_id', $presupuesto_id);
|
||||
$builder->where('tarifa_manipulado_id', $tarifa->tarifa_id);
|
||||
$builder->where('presupuesto_id', $presupuesto_id);
|
||||
$builder->where('tarifa_manipulado_id', $tarifa->tarifa_id);
|
||||
$result = $builder->get()->getResultObject();
|
||||
if(count($result)>0){
|
||||
if (count($result) > 0) {
|
||||
$this->db
|
||||
->table($this->table . " t1")
|
||||
->where('presupuesto_id', $presupuesto_id)
|
||||
@ -157,10 +160,9 @@ class PresupuestoManipuladosModel extends \App\Models\BaseModel
|
||||
->set('precio_total', $tarifa->precio_total)
|
||||
->set('margen', $tarifa->margen)
|
||||
->update();
|
||||
|
||||
|
||||
}
|
||||
else{
|
||||
|
||||
} else {
|
||||
$this->db
|
||||
->table($this->table . " t1")
|
||||
->set('presupuesto_id', $presupuesto_id)
|
||||
@ -174,43 +176,45 @@ class PresupuestoManipuladosModel extends \App\Models\BaseModel
|
||||
}
|
||||
|
||||
|
||||
public function initPresupuesto($tipo_presupuesto, $solapas, $tirada, $POD){
|
||||
|
||||
public function initPresupuesto($tipo_presupuesto, $solapas, $tirada, $POD)
|
||||
{
|
||||
|
||||
$model = model('App\Models\Presupuestos\TipoPresupuestoServiciosDefectoModel');
|
||||
$tarifas_procesar = $model->get_tarifas($tipo_presupuesto, $solapas, "manipulado");
|
||||
|
||||
$tarifas_procesar = $model->get_tarifas($tipo_presupuesto, $solapas, "manipulado");
|
||||
|
||||
$modelTarifa = model('App\Models\Tarifas\TarifaManipuladoModel');
|
||||
$tarifas = [];
|
||||
|
||||
|
||||
foreach($tarifas_procesar as $tarifa){
|
||||
foreach ($tarifas_procesar as $tarifa) {
|
||||
|
||||
$tarifa_value = $modelTarifa->getTarifaPresupuestoManipulado($tarifa['tarifa_id'], $tirada);
|
||||
if (count($tarifa_value)>0) {
|
||||
$result_data = $this->calcularTarifa($tarifa_value[0], $tirada, $POD<$tirada?false:true);
|
||||
array_push($tarifas, (object)[
|
||||
'tarifa_id'=> $tarifa_value[0]->tarifa_manipulado_id,
|
||||
'tarifa_nombre'=> $tarifa_value[0]->tarifa_manipulado_nombre,
|
||||
'nombre'=> $tarifa_value[0]->tarifa_manipulado_nombre,
|
||||
'precio_unidad'=> $result_data[0],
|
||||
'total'=> $result_data[1],
|
||||
'precio_total'=> $result_data[1],
|
||||
'margen'=> $result_data[2],
|
||||
if (count($tarifa_value) > 0) {
|
||||
$result_data = $this->calcularTarifa($tarifa_value[0], $tirada, $POD < $tirada ? false : true);
|
||||
array_push($tarifas, (object) [
|
||||
'tarifa_id' => $tarifa_value[0]->tarifa_manipulado_id,
|
||||
'tarifa_nombre' => $tarifa_value[0]->tarifa_manipulado_nombre,
|
||||
'nombre' => $tarifa_value[0]->tarifa_manipulado_nombre,
|
||||
'precio_unidad' => $result_data[0],
|
||||
'total' => $result_data[1],
|
||||
'precio_total' => $result_data[1],
|
||||
'margen' => $result_data[2],
|
||||
]);
|
||||
}
|
||||
else{
|
||||
array_push($tarifas,
|
||||
(object)[
|
||||
'tarifa_id'=> $tarifa['tarifa_id'] ,
|
||||
'tarifa_nombre'=> $tarifa['tarifa_nombre'],
|
||||
'nombre'=> $tarifa['tarifa_nombre'],
|
||||
} else {
|
||||
array_push(
|
||||
$tarifas,
|
||||
(object) [
|
||||
'tarifa_id' => $tarifa['tarifa_id'],
|
||||
'tarifa_nombre' => $tarifa['tarifa_nombre'],
|
||||
'nombre' => $tarifa['tarifa_nombre'],
|
||||
'precio_unidad' => 0,
|
||||
'total'=> 0,
|
||||
'precio_total'=> 0,
|
||||
'total' => 0,
|
||||
'precio_total' => 0,
|
||||
'margen' => 0,
|
||||
]);
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
return $tarifas;
|
||||
|
||||
@ -980,7 +980,7 @@ class PresupuestoService extends BaseService
|
||||
//'color' => 1,
|
||||
'rotativa' => 0,
|
||||
);
|
||||
} else if ($uso == 'sobrecubierta') {
|
||||
} else if ($uso == 'sobrecubierta' || $uso == 'faja') {
|
||||
$opciones_papel = array(
|
||||
'sobrecubierta' => 1,
|
||||
//'color' => 1,
|
||||
@ -1826,7 +1826,7 @@ class PresupuestoService extends BaseService
|
||||
}
|
||||
}
|
||||
|
||||
if ($uso == 'cubierta' || $uso == 'sobrecubierta') {
|
||||
if ($uso == 'cubierta' || $uso == 'sobrecubierta' || $uso == 'faja') {
|
||||
|
||||
$linea['fields']['dimension_desarrollo']['ancho'] = $datosPedido->anchoExteriores;
|
||||
$linea['fields']['dimension_desarrollo']['alto'] = $datosPedido->altoExteriores;
|
||||
|
||||
@ -114,7 +114,7 @@
|
||||
<?= lang('Presupuestos.solapasAnchoCubierta') ?>*
|
||||
</label>
|
||||
<input type="number" id="solapas_ancho" name="solapas_ancho" placeholder="0"
|
||||
maxLength="8" step="1" class="form-control solapas_cubierta" value="">
|
||||
maxLength="8" step="1" min=60 class="form-control solapas_cubierta" value="60">
|
||||
<div class="form-text">
|
||||
Entre 60 y 120 mm
|
||||
</div>
|
||||
|
||||
@ -370,8 +370,7 @@ id = -1;
|
||||
searching: false,
|
||||
paging: true,
|
||||
info: false,
|
||||
dom: '<"mt-4"><"float-end"B><"float-start"l>
|
||||
<t><"mt-4 mb-3"p>',
|
||||
dom: '<"mt-4"><"float-end"B><"float-start"l><t><"mt-4 mb-3"p>',
|
||||
ajax : $.fn.dataTable.pipeline( {
|
||||
url: '<?= route_to('dataTableOfTarifaEncuadernacionLineasHoras') ?>',
|
||||
data: function ( d ) {
|
||||
@ -570,8 +569,7 @@ id = -1;
|
||||
searching: false,
|
||||
paging: true,
|
||||
info: false,
|
||||
dom: '<"mt-4"><"float-end"B><"float-start"l>
|
||||
<t><"mt-4 mb-3"p>',
|
||||
dom: '<"mt-4"><"float-end"B><"float-start"l><t><"mt-4 mb-3"p>',
|
||||
ajax : $.fn.dataTable.pipeline( {
|
||||
url: '<?= route_to('dataTableOfTarifaEncuadernacionLineas') ?>',
|
||||
data: function ( d ) {
|
||||
@ -776,8 +774,7 @@ id = -1;
|
||||
paging: true,
|
||||
select: true,
|
||||
info: false,
|
||||
dom: '<"mt-4"><"float-end"B><"float-start"l>
|
||||
<t><"mt-4 mb-3"p>',
|
||||
dom: '<"mt-4"><"float-end"B><"float-start"l><t><"mt-4 mb-3"p>',
|
||||
ajax : $.fn.dataTable.pipeline( {
|
||||
url: '<?= route_to('dataTableOfTarifaEncuadernacionTiradas') ?>',
|
||||
data: {
|
||||
|
||||
@ -29,12 +29,15 @@ class PresupuestoAdminEdit {
|
||||
|
||||
this.tipoTapa = $('.card-title').text().toLowerCase().includes('dura') ? 'dura' : 'blanda';
|
||||
|
||||
this.cargandoPresupuesto = false;
|
||||
|
||||
this.datosGenerales = new DatosGenerales(this.domItem.find('#accordionDatosPresupuestoTip'));
|
||||
this.datosLibro = new DatosLibro(this.domItem.find('#accordionDatosLibroTip'),
|
||||
()=>{return this.cargandoPresupuesto},
|
||||
{
|
||||
checkPaginasPresupuesto: this.checkPaginasPresupuesto,
|
||||
getDimensionLibro: this.getDimensionLibro,
|
||||
calcularSolapas: this.calcularSolapas.bind(this)
|
||||
calcularSolapas: this.calcularSolapas.bind(this),
|
||||
});
|
||||
this.comparador = new Comparador(this.domItem.find('#accordionDatosPresupuestoClienteTip'),
|
||||
{
|
||||
@ -56,9 +59,7 @@ class PresupuestoAdminEdit {
|
||||
this.guardar = $('#saveForm');
|
||||
|
||||
this.calcularPresupuesto = false;
|
||||
this.cargandoPresupuesto = false;
|
||||
|
||||
|
||||
|
||||
this.configUploadDropzone = {
|
||||
domElement: '#dropzone-presupuesto-admin-files',
|
||||
nameId: "presupuesto_id",
|
||||
|
||||
@ -370,8 +370,6 @@ class Comparador {
|
||||
}
|
||||
$('#faja').prop('checked', true);
|
||||
$('.faja-div').removeClass('d-none');
|
||||
$('#faja_solapas_ancho').val(60);
|
||||
$('#faja_alto').val(50);
|
||||
$('#compPapelFaja').prop('disabled', false);
|
||||
$('#compGramajeFaja').prop('disabled', false);
|
||||
}
|
||||
|
||||
@ -3,7 +3,7 @@ import { getToken } from '../../../common/common.js';
|
||||
|
||||
class DatosLibro {
|
||||
|
||||
constructor(domItem, functions = {}) {
|
||||
constructor(domItem, cargando, functions = {}) {
|
||||
|
||||
this.domItem = domItem;
|
||||
|
||||
@ -70,7 +70,7 @@ class DatosLibro {
|
||||
this.fajaSolapasAncho = this.domItem.find('#faja_solapas_ancho');
|
||||
this.div_faja = this.domItem.find('.faja-div');
|
||||
|
||||
this.cargando = false;
|
||||
this.cargando = cargando;
|
||||
|
||||
}
|
||||
|
||||
@ -182,6 +182,9 @@ class DatosLibro {
|
||||
|
||||
checkMinMaxInput(event) {
|
||||
|
||||
if(this.cargando)
|
||||
return;
|
||||
|
||||
const el = event.target;
|
||||
if (el.value != "") {
|
||||
if (parseInt(el.value) < parseInt(el.min)) {
|
||||
@ -380,7 +383,8 @@ class DatosLibro {
|
||||
|
||||
|
||||
// para que se actualice el comparador
|
||||
$('#compSobrecubierta').trigger('change');
|
||||
if($('#compGramajeSobrecubierta').select2('data').length > 0)
|
||||
$('#compGramajeSobrecubierta').trigger('change');
|
||||
|
||||
if(this.cargando)
|
||||
return;
|
||||
@ -569,8 +573,6 @@ class DatosLibro {
|
||||
|
||||
cargarDatos(datos) {
|
||||
|
||||
this.cargando = true;
|
||||
|
||||
this.paginas.val(datos.paginas);
|
||||
this.tirada.val(datos.tirada);
|
||||
this.calcular_mermas();
|
||||
@ -646,8 +648,6 @@ class DatosLibro {
|
||||
this.ferro.prop('checked', datos.ferro);
|
||||
this.ferroDigital.prop('checked', datos.ferroDigital);
|
||||
this.marcapaginas.prop('checked', datos.marcapaginas);
|
||||
|
||||
this.cargando = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -79,6 +79,8 @@ class Resumen {
|
||||
|
||||
async updateTotales(event, data = {}) {
|
||||
|
||||
const self = this;
|
||||
|
||||
let updateLP = data.updateLP || true;
|
||||
let updateServicios = data.updateServicios || true;
|
||||
let updateEnvio = data.updateEnvio || true;
|
||||
@ -89,8 +91,8 @@ class Resumen {
|
||||
let totalImpresionforMargen = 0;
|
||||
let margenImpresion = 0;
|
||||
|
||||
let totalServicios = 0;
|
||||
let margenServicios = 0;
|
||||
let totalServicios = parseFloat(0);
|
||||
let margenServicios = parseFloat(0);
|
||||
|
||||
let totalEnvios = 0;
|
||||
let margenEnvios = 0;
|
||||
@ -116,28 +118,25 @@ class Resumen {
|
||||
|
||||
}
|
||||
if (rowData.check_impresion_total) {
|
||||
//totalImpresion += parseFloat($('#' + rowData.row_id + '_precioImpresion').val())
|
||||
margenPorHoras += parseFloat($('#' + rowData.row_id + '_precioImpresion').val())
|
||||
|
||||
totalImpresion += parseFloat($('#' + rowData.row_id + '_precioImpresion').val())
|
||||
margenPorHoras += parseFloat($('#' + rowData.row_id + '_margenImpresion').val())
|
||||
totalImpresion += parseFloat($('#' + rowData.row_id + '_totalClicks').val())
|
||||
margenImpresion += parseFloat($('#' + rowData.row_id + '_margenClicks').val())
|
||||
|
||||
sumForFactor += parseFloat($('#' + rowData.row_id + '_totalClicks').val())
|
||||
|
||||
if (rowData.maquinaTipo == 'inkjet') {
|
||||
totalImpresion += parseFloat(rowData.totalTinta)
|
||||
totalImpresion += parseFloat(rowData.totalCorte)
|
||||
|
||||
totalImpresion += parseFloat(rowData.totalCorte)?? 0;
|
||||
sumForFactor += (parseFloat(rowData.totalTinta) + parseFloat(rowData.totalCorte))
|
||||
}
|
||||
//margenImpresion += parseFloat($('#' + rowData.row_id + '_margenImpresion').val())
|
||||
//margenPorHoras += parseFloat($('#' + rowData.row_id + '_margenImpresion').val())
|
||||
margenImpresion += parseFloat($('#' + rowData.row_id + '_margenClicks').val())
|
||||
|
||||
|
||||
|
||||
sumForFactor -= parseFloat($('#' + rowData.row_id + '_margenClicks').val())
|
||||
|
||||
if (!isNaN(parseFloat($('#' + rowData.row_id + 'lp_bn_totalTinta').val()))) {
|
||||
totalImpresion += parseFloat($('#' + rowData.row_id + 'lp_bn_totalTinta').val())
|
||||
sumForFactor += parseFloat($('#' + rowData.row_id + 'lp_bn_totalTinta').val())
|
||||
if (!isNaN(parseFloat($('#' + rowData.row_id + '_totalTinta').val()))) {
|
||||
totalImpresion += parseFloat($('#' + rowData.row_id + '_totalTinta').val())
|
||||
sumForFactor += parseFloat($('#' + rowData.row_id + '_totalTinta').val())
|
||||
}
|
||||
}
|
||||
})
|
||||
@ -177,53 +176,56 @@ class Resumen {
|
||||
if (typeof $("#tableOfServiciosEncuadernacion").DataTable() !== 'undefined' && $("#tableOfServiciosEncuadernacion").DataTable().rows().count() > 0) {
|
||||
$('#tableOfServiciosEncuadernacion').DataTable().rows().every(function (rowIdx, tableLoop, rowLoop) {
|
||||
let rowData = this.data();
|
||||
let total_servicio = parseFloat(rowData.precio_total);
|
||||
let total_servicio = self.roundToTwoDecimals(parseFloat(rowData.precio_total));
|
||||
let margen_servicio = parseFloat(rowData.margen);
|
||||
totalServicios += total_servicio
|
||||
let base = total_servicio / (1 + margen_servicio / 100.0);
|
||||
margenServicios = total_servicio - base;
|
||||
let base = self.roundToTwoDecimals(total_servicio / (1 + margen_servicio / 100.0));
|
||||
base = self.roundToTwoDecimals(base / parseInt($('#tirada').val()))*parseInt($('#tirada').val());
|
||||
margenServicios += self.roundToTwoDecimals(parseFloat(total_servicio - base));
|
||||
});
|
||||
}
|
||||
|
||||
if (typeof $("#tableOfServiciosAcabado").DataTable() !== 'undefined' && $("#tableOfServiciosAcabado").DataTable().rows().count() > 0) {
|
||||
$('#tableOfServiciosAcabado').DataTable().rows().every(function (rowIdx, tableLoop, rowLoop) {
|
||||
let rowData = this.data();
|
||||
let total_servicio = parseFloat(rowData.precio_total);
|
||||
let total_servicio = self.roundToTwoDecimals(parseFloat(rowData.precio_total));
|
||||
let margen_servicio = parseFloat(rowData.margen);
|
||||
totalServicios += total_servicio
|
||||
let base = total_servicio / (1 + margen_servicio / 100.0);
|
||||
margenServicios = total_servicio - base;
|
||||
let base = self.roundToTwoDecimals(total_servicio / (1 + margen_servicio / 100.0));
|
||||
base = self.roundToTwoDecimals(base / parseInt($('#tirada').val()))*parseInt($('#tirada').val());
|
||||
margenServicios += self.roundToTwoDecimals(parseFloat(total_servicio - base));
|
||||
});
|
||||
}
|
||||
|
||||
if (typeof $("#tableOfServiciosPreimpresion").DataTable() !== 'undefined' && $("#tableOfServiciosPreimpresion").DataTable().rows().count() > 0) {
|
||||
$('#tableOfServiciosPreimpresion').DataTable().rows().every(function (rowIdx, tableLoop, rowLoop) {
|
||||
let rowData = this.data();
|
||||
let total_servicio = parseFloat(rowData.precio);
|
||||
let coste_servicio = parseFloat(rowData.coste);
|
||||
let total_servicio = self.roundToTwoDecimals(parseFloat(rowData.precio));
|
||||
let coste_servicio = self.roundToTwoDecimals(parseFloat(rowData.coste));
|
||||
totalServicios += total_servicio
|
||||
margenServicios = total_servicio - coste_servicio;
|
||||
margenServicios += total_servicio - coste_servicio;
|
||||
});
|
||||
}
|
||||
|
||||
if (typeof $("#tableOfServiciosExtra").DataTable() !== 'undefined' && $("#tableOfServiciosExtra").DataTable().rows().count() > 0) {
|
||||
$('#tableOfServiciosExtra').DataTable().rows().every(function (rowIdx, tableLoop, rowLoop) {
|
||||
let rowData = this.data();
|
||||
let total_servicio = parseFloat(rowData.precio);
|
||||
let coste_servicio = parseFloat(rowData.coste);
|
||||
let total_servicio = self.roundToTwoDecimals(parseFloat(rowData.precio));
|
||||
let coste_servicio = self.roundToTwoDecimals(parseFloat(rowData.coste));
|
||||
totalServicios += total_servicio
|
||||
margenServicios = total_servicio - coste_servicio;
|
||||
margenServicios += total_servicio - coste_servicio;
|
||||
});
|
||||
}
|
||||
|
||||
if (typeof $("#tableOfServiciosManipulado").DataTable() !== 'undefined' && $("#tableOfServiciosManipulado").DataTable().rows().count() > 0) {
|
||||
$('#tableOfServiciosManipulado').DataTable().rows().every(function (rowIdx, tableLoop, rowLoop) {
|
||||
let rowData = this.data();
|
||||
let total_servicio = parseFloat(rowData.precio_total);
|
||||
let total_servicio = self.roundToTwoDecimals(parseFloat(rowData.precio_total));
|
||||
let margen_servicio = parseFloat(rowData.margen);
|
||||
totalServicios += total_servicio
|
||||
let base = total_servicio / (1 + margen_servicio / 100.0);
|
||||
margenServicios = total_servicio - base;
|
||||
let base = self.roundToTwoDecimals(total_servicio / (1 + margen_servicio / 100.0));
|
||||
base = self.roundToTwoDecimals(base / parseInt($('#tirada').val()))*parseInt($('#tirada').val());
|
||||
margenServicios += self.roundToTwoDecimals(parseFloat(total_servicio - base));
|
||||
});
|
||||
}
|
||||
|
||||
@ -346,6 +348,10 @@ class Resumen {
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
roundToTwoDecimals(num) {
|
||||
return parseFloat(num.toFixed(2));
|
||||
}
|
||||
}
|
||||
|
||||
export default Resumen;
|
||||
@ -96,8 +96,9 @@ class TiradasAlernativas {
|
||||
|
||||
self.table.row(row).remove().draw();
|
||||
|
||||
$(document).trigger('update-envios', { tirada_inicial: $('#tirada').val(), tirada: data.tirada });
|
||||
$('#tirada').val(data.tirada).trigger('change');
|
||||
|
||||
$(document).trigger('update-envios', { tirada_inicial: $('#tirada').val(), tirada: data.tirada });
|
||||
});
|
||||
|
||||
$(document).on('update-tiradas-alternativas', async function () {
|
||||
@ -181,6 +182,8 @@ class TiradasAlernativas {
|
||||
json_acabados: this.generate_json_servicios('acabados'),
|
||||
json_encuadernaciones: this.generate_json_servicios('encuadernaciones'),
|
||||
json_manipulado: this.generate_json_servicios('manipulado'),
|
||||
json_presimpresion: this.generate_json_servicios('presimpresion'),
|
||||
json_extra: this.generate_json_servicios('extra'),
|
||||
json_envios: envios,
|
||||
ancho: dimension.ancho,
|
||||
alto: dimension.alto,
|
||||
|
||||
Reference in New Issue
Block a user