mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
Merge branch 'dev/presupuesto_cliente_2' into 'main'
Dev/presupuesto cliente 2 See merge request jjimenez/safekat!241
This commit is contained in:
@ -326,6 +326,7 @@ $routes->group('clientes', ['namespace' => 'App\Controllers\Clientes'], function
|
||||
$routes->match(['get', 'post'], 'edit/(:num)', 'Cliente::edit/$1', ['as' => 'clienteEdit']);
|
||||
$routes->get('delete/(:num)', 'Cliente::delete/$1', ['as' => 'clienteDelete']);
|
||||
$routes->post('datatable', 'Cliente::datatable', ['as' => 'clienteDT']);
|
||||
$routes->post('menuitems', 'Cliente::menuItems', ['as' => 'menuItemsOfClientes']);
|
||||
});
|
||||
|
||||
/* Precios */
|
||||
@ -348,7 +349,7 @@ $routes->group('clientes', ['namespace' => 'App\Controllers\Clientes'], function
|
||||
$routes->get('delete/(:num)', 'Cliente::delete/$1', ['as' => 'deleteCliente']);
|
||||
$routes->post('datatable', 'Cliente::datatable', ['as' => 'dataTableOfClientes']);
|
||||
$routes->post('allmenuitems', 'Cliente::allItemsSelect', ['as' => 'select2ItemsOfClientes']);
|
||||
$routes->post('menuitems', 'Cliente::menuItems', ['as' => 'menuItemsOfClientes']);
|
||||
|
||||
});
|
||||
$routes->resource('cliente', ['namespace' => 'App\Controllers\Clientes', 'controller' => 'Cliente', 'except' => 'show,new,create,update']);*/
|
||||
|
||||
@ -540,6 +541,9 @@ $routes->group('presupuestocliente', ['namespace' => 'App\Controllers\Presupuest
|
||||
$routes->post('datatable', 'Cosidotapablanda::datatable', ['as' => 'tablaPresupuestosCliente']);
|
||||
$routes->post('getgramaje', 'Presupuestocliente::getGramaje', ['as' => 'obtenerGramaje']);
|
||||
$routes->post('presupuesto', 'Presupuestocliente::presupuesto', ['as' => 'presupuestoCliente']);
|
||||
$routes->post('getDireccionesCliente', 'Presupuestocliente::getDireccionesCliente', ['as' => 'getDirecciones']);
|
||||
$routes->post('getDatosDireccion', 'Presupuestocliente::getDatosDireccion', ['as' => 'getDatosDireccion']);
|
||||
$routes->post('getNuevaDireccion', 'Presupuestocliente::getNuevaDireccion', ['as' => 'nuevaDireccion']);
|
||||
});
|
||||
$routes->resource('presupuestocliente', ['namespace' => 'App\Controllers\Presupuestos', 'controller' => 'Presupuestocliente', 'except' => 'show,new,create,update']);
|
||||
|
||||
|
||||
@ -100,5 +100,16 @@ class Js_loader extends BaseController
|
||||
return view('themes/vuexy/form/presupuestos/cliente/disenioLibro.js');
|
||||
}
|
||||
|
||||
function presupuestoClienteDirecciones_js()
|
||||
{
|
||||
$this->response->setHeader('Content-Type', 'text/javascript');
|
||||
return view('themes/vuexy/form/presupuestos/cliente/direcciones.js');
|
||||
}
|
||||
|
||||
function presupuestoClienteResumen_js()
|
||||
{
|
||||
$this->response->setHeader('Content-Type', 'text/javascript');
|
||||
return view('themes/vuexy/form/presupuestos/cliente/resumen.js');
|
||||
}
|
||||
}
|
||||
|
||||
@ -17,7 +17,7 @@ use App\Models\Presupuestos\PresupuestoServiciosExtraModel;
|
||||
use App\Services\PresupuestoClienteService;
|
||||
use Exception;
|
||||
|
||||
class Presupuestocliente extends \App\Controllers\GoBaseResourceController
|
||||
class Presupuestocliente extends \App\Controllers\BaseResourceController
|
||||
{
|
||||
protected $modelName = "PresupuestoModel";
|
||||
protected $format = 'json';
|
||||
@ -139,7 +139,6 @@ class Presupuestocliente extends \App\Controllers\GoBaseResourceController
|
||||
// Se obtiene el cliente ID a partir del usuario de la sesion
|
||||
$clienteId = 999; // Fijo hasta desarollar clientes usuarios
|
||||
|
||||
|
||||
$presupuestoEntity = isset($sanitizedData) ? new PresupuestoEntity($sanitizedData) : new PresupuestoEntity();
|
||||
$presupuestoEntity->clienteId = $clienteId;
|
||||
|
||||
@ -164,6 +163,8 @@ class Presupuestocliente extends \App\Controllers\GoBaseResourceController
|
||||
|
||||
$this->viewData['formAction'] = route_to('crearPresupuestoCliente');
|
||||
|
||||
$this->viewData['paisList'] = $this->getPaisListItems();
|
||||
|
||||
$this->viewData['presupuestoEntity'] = $presupuestoEntity;
|
||||
$this->viewData['datosPresupuesto'] = $datosPresupuesto;
|
||||
|
||||
@ -600,15 +601,458 @@ class Presupuestocliente extends \App\Controllers\GoBaseResourceController
|
||||
|
||||
public function presupuesto()
|
||||
{
|
||||
|
||||
|
||||
if ($this->request->isAJAX()) {
|
||||
$reqData = $this->request->getPost();
|
||||
|
||||
$resultado_lineas = $this->getLineasPresupuesto($reqData);
|
||||
$newTokenHash = csrf_hash();
|
||||
$csrfTokenName = csrf_token();
|
||||
|
||||
$error = (object)[
|
||||
'interior' => "",
|
||||
'cubierta' => "",
|
||||
'sobrecubierta' => "",
|
||||
'guardas' => "",
|
||||
'servicios' => "",
|
||||
'serviciosDefecto' => "",
|
||||
];
|
||||
$coste_servicios = 0.0;
|
||||
|
||||
$POD = model('App\Models\Configuracion\ConfiguracionSistemaModel')->getPOD();
|
||||
|
||||
|
||||
return $this->respond($resultado_lineas);
|
||||
$tirada = $reqData['tirada'] ?? 0;
|
||||
$tamanio = $reqData['tamanio'];
|
||||
$tipo_impresion_id = $this->getTipoImpresion($reqData['tipo'], $reqData['tapa']);
|
||||
$precio_u = [];
|
||||
$peso = [];
|
||||
|
||||
for ($t = 0; $t < count($tirada); $t++) {
|
||||
$tirada[$t] = intval($tirada[$t]);
|
||||
|
||||
$paginas_color = intval($reqData['paginasColor']) ?? 0;
|
||||
$is_cosido = (new TipoPresupuestoModel())->get_isCosido($tipo_impresion_id);
|
||||
|
||||
$datosPedido = (object)array(
|
||||
'paginas' => intval($reqData['paginas']) ?? 0,
|
||||
'tirada' => $tirada[$t],
|
||||
'merma' => $tirada[$t] > $POD ? $this->calcular_merma($tirada[$t], $POD) : 0,
|
||||
'ancho' => intval($tamanio['ancho']) ?? 100000,
|
||||
'alto' => intval($tamanio['alto']) ?? 100000,
|
||||
'isCosido' => $is_cosido,
|
||||
);
|
||||
|
||||
$papel_generico = [
|
||||
'id' => $reqData['papelInterior'] ?? 0,
|
||||
'nombre' => $reqData['papelInteriorNombre'] ?? "",
|
||||
];
|
||||
$gramaje = $reqData['gramajeInterior'] ?? 0;
|
||||
$cliente_id = $reqData['clienteId'] ?? -1;
|
||||
$excluirRotativa = $reqData['excluirRotativa'] ?? 0;
|
||||
|
||||
$input_data = array(
|
||||
'uso' => 'interior',
|
||||
'tipo_impresion_id' => $tipo_impresion_id,
|
||||
'datosPedido' => $datosPedido,
|
||||
'papel_generico' => $papel_generico,
|
||||
'gramaje' => $gramaje,
|
||||
'isColor' => intval($reqData['isColor']) ?? 0,
|
||||
'isHq' => intval($reqData['isHq']) ?? 0,
|
||||
'cliente_id' => $cliente_id,
|
||||
'paginas_color' => $paginas_color,
|
||||
'excluirRotativa' => $excluirRotativa,
|
||||
);
|
||||
|
||||
$interior = PresupuestoClienteService::obtenerInterior($input_data);
|
||||
|
||||
$costeInterior = 0.0;
|
||||
$peso_interior = 0.0;
|
||||
foreach ($interior as $linea) {
|
||||
if (count($linea) > 0) {
|
||||
$costeInterior += floatval($linea['total_impresion']);
|
||||
$peso_interior += floatval($linea['peso']);
|
||||
}
|
||||
}
|
||||
|
||||
if ($costeInterior <= 0) {
|
||||
$error->interior = lang('Presupuestos.errores.noInterior');
|
||||
}
|
||||
|
||||
// Si es POD hay que volver a calcular para incluir la merma correcta
|
||||
if ($tirada[$t] <= $POD) {
|
||||
$num_formas = [];
|
||||
foreach ($interior as $linea) {
|
||||
if (count($linea) > 0) {
|
||||
$formas_linea = $is_cosido ? intval($linea['num_formas']['value']) / 2 : intval($linea['num_formas']['value']);
|
||||
array_push($num_formas, $formas_linea);
|
||||
}
|
||||
}
|
||||
$input_data['datosPedido']->merma = $this->calcular_merma($tirada[$t], $POD, $num_formas);
|
||||
|
||||
$interior = PresupuestoClienteService::obtenerInterior($input_data);
|
||||
}
|
||||
|
||||
$costeInterior = 0.0;
|
||||
$peso_interior = 0.0;
|
||||
foreach ($interior as $linea) {
|
||||
if (count($linea) > 0) {
|
||||
$costeInterior += floatval($linea['total_impresion']);
|
||||
$peso_interior += floatval($linea['peso']);
|
||||
}
|
||||
}
|
||||
|
||||
if ($costeInterior <= 0)
|
||||
$error->interior = lang('Presupuestos.errores.noInterior');
|
||||
else
|
||||
$error->interior = "";
|
||||
|
||||
|
||||
// Cubierta
|
||||
$papel_generico = [
|
||||
'id' => $reqData['papelCubierta'] ?? 0,
|
||||
'nombre' => $reqData['papelCubiertaNombre'] ?? "",
|
||||
];
|
||||
$input_data['papel_generico'] = $papel_generico;
|
||||
$input_data['gramaje'] = $reqData['gramajeCubierta'] ?? 0;
|
||||
$input_data['datosPedido']->paginas = intval($reqData['carasCubierta'] ?? 0);
|
||||
$input_data['paginas_color'] = intval($reqData['carasCubierta'] ?? 0);
|
||||
$input_data['datosPedido']->solapas_ancho = intval($reqData['solapasCubierta'] ?? 0);
|
||||
$input_data['datosPedido']->solapas = $input_data['datosPedido']->solapas_ancho > 0 ? 1 : 0;
|
||||
$input_data['datosPedido']->lomo = $this->calcular_lomo($interior, 0);
|
||||
$input_data['isColor'] = 1;
|
||||
$input_data['isHq'] = 1;
|
||||
$input_data['uso'] = 'cubierta';
|
||||
|
||||
$cubierta = PresupuestoClienteService::obtenerCubierta($input_data);
|
||||
$coste_cubierta = 0.0;
|
||||
$peso_cubierta = 0.0;
|
||||
if (count($cubierta) > 0) {
|
||||
$coste_cubierta += floatval($cubierta['total_impresion']);
|
||||
$peso_cubierta += floatval($cubierta['peso']);
|
||||
}
|
||||
if ($coste_cubierta <= 0)
|
||||
$error->cubierta = lang('Presupuestos.errores.noCubiertaSobrecubierta');
|
||||
else
|
||||
$error->cubierta = "";
|
||||
|
||||
$tarifaAcabadoCubierta = intval($reqData['acabadoCubierta'] ?? 0);
|
||||
$acabadoCubierta = [];
|
||||
if ($tarifaAcabadoCubierta > 0) {
|
||||
$model = model('App\Models\Presupuestos\PresupuestoAcabadosModel');
|
||||
$acabadoCubierta = $model->getPrecioTarifa($tarifaAcabadoCubierta, $datosPedido->tirada, $POD);
|
||||
}
|
||||
if (count($acabadoCubierta) > 0) {
|
||||
if ($acabadoCubierta[0]->total <= 0)
|
||||
$error->servicios = lang('Presupuestos.errores.errorPresupuesto');
|
||||
$coste_servicios += floatval($acabadoCubierta[0]->total);
|
||||
}
|
||||
|
||||
// Sobrecubierta
|
||||
$coste_sobrecubierta = 0.0;
|
||||
$peso_sobrecubierta = 0.0;
|
||||
$linea_sobrecubierta = [];
|
||||
$acabadoSobrecubierta = [];
|
||||
$sobreCubierta = $reqData["sobrecubierta"] ?? null;
|
||||
if (!is_null($sobreCubierta)) {
|
||||
|
||||
$papel_generico = [
|
||||
'id' => $sobreCubierta['papel'] ?? 0,
|
||||
'nombre' => $sobreCubierta['papel_nombre'] ?? "",
|
||||
];
|
||||
$input_data['papel_generico'] = $papel_generico;
|
||||
$input_data['gramaje'] = $sobreCubierta['gramaje'] ?? 0;
|
||||
$input_data['datosPedido']->paginas = 4;
|
||||
$input_data['paginas_color'] = 4;
|
||||
$input_data['datosPedido']->solapas_ancho = intval($sobreCubierta['solapas'] ?? 0);
|
||||
$input_data['datosPedido']->solapas = $input_data['datosPedido']->solapas_ancho > 0 ? 1 : 0;
|
||||
$input_data['datosPedido']->lomo = $this->calcular_lomo([$cubierta], $input_data['datosPedido']->lomo);
|
||||
$input_data['isColor'] = 1;
|
||||
$input_data['isHq'] = 1;
|
||||
$input_data['uso'] = 'sobrecubierta';
|
||||
|
||||
$linea_sobrecubierta = PresupuestoClienteService::obtenerSobrecubierta($input_data);
|
||||
|
||||
if (count($linea_sobrecubierta) > 0) {
|
||||
$coste_sobrecubierta += floatval($linea_sobrecubierta['total_impresion']);
|
||||
$peso_sobrecubierta += floatval($linea_sobrecubierta['peso']);
|
||||
}
|
||||
if ($coste_sobrecubierta <= 0)
|
||||
$error->sobrecubierta = lang('Presupuestos.errores.noCubiertaSobrecubierta');
|
||||
else
|
||||
$error->sobrecubierta = "";
|
||||
|
||||
$tarifaAcabadoSobrecubierta = intval(strlen($sobreCubierta['acabado']) == 0 ? 0 : $sobreCubierta['acabado']);
|
||||
$acabadoSobrecubierta = [];
|
||||
if ($tarifaAcabadoSobrecubierta > 0) {
|
||||
$model = model('App\Models\Presupuestos\PresupuestoAcabadosModel');
|
||||
$acabadoSobrecubierta = $model->getPrecioTarifa($tarifaAcabadoSobrecubierta, $datosPedido->tirada, $POD);
|
||||
}
|
||||
if (count($acabadoSobrecubierta) > 0) {
|
||||
if ($acabadoSobrecubierta[0]->total <= 0)
|
||||
$error->servicios = lang('Presupuestos.errores.errorPresupuesto');
|
||||
$coste_servicios += floatval($acabadoSobrecubierta[0]->total);
|
||||
}
|
||||
}
|
||||
|
||||
//Guardas
|
||||
$guardas = [];
|
||||
$peso_guardas = 0.0;
|
||||
$coste_guardas = 0.0;
|
||||
if ($reqData['guardas'] ?? 0 > 0) {
|
||||
|
||||
$guardas = $reqData['guardas'];
|
||||
$papel_generico = [
|
||||
'id' => $guardas['papel'] ?? 0,
|
||||
'nombre' => $guardas['nombre'] ?? "",
|
||||
];
|
||||
$input_data['papel_generico'] = $papel_generico;
|
||||
$input_data['gramaje'] = $guardas['gramaje'] ?? 0;
|
||||
$input_data['datosPedido']->paginas = 8;
|
||||
$input_data['paginas_color'] = 8;
|
||||
$input_data['datosPedido']->paginas_impresion = $guardas['caras'] ?? 0;
|
||||
$input_data['datosPedido']->solapas_ancho = 0;
|
||||
$input_data['datosPedido']->solapas = 0;
|
||||
$input_data['isColor'] = 1;
|
||||
$input_data['isHq'] = 1;
|
||||
$input_data['uso'] = 'guardas';
|
||||
|
||||
// Para el caso de Fresado y Cosido tapa dura, las guardas son un diptico
|
||||
// y hay que imprimirlas como "cosido" (dos hojas pegadas). En el caso de espiral
|
||||
// o wire-o tapa dura, las guardas se imprimen como hojas sueltas
|
||||
if ($tipo_impresion_id == 1 || $tipo_impresion_id == 3) {
|
||||
$input_data['datosPedido']->isCosido = true;
|
||||
} else if ($tipo_impresion_id == 5 || $tipo_impresion_id == 7) {
|
||||
$input_data['datosPedido']->isCosido = false;
|
||||
}
|
||||
|
||||
$guardas = PresupuestoClienteService::obtenerGuardas($input_data);
|
||||
|
||||
if (count($guardas) > 0) {
|
||||
$coste_guardas += floatval($guardas['total_impresion']);
|
||||
$peso_guardas += floatval($guardas['peso']);
|
||||
}
|
||||
if ($coste_guardas <= 0)
|
||||
$error->guardas = lang('Presupuestos.errores.noGuardas');
|
||||
else
|
||||
$error->guardas = "";
|
||||
}
|
||||
|
||||
// Servicios defecto
|
||||
$servDefecto = PresupuestoCLienteService::getServiciosEncuadernacionDefault([
|
||||
'tipo_impresion_id' => $tipo_impresion_id,
|
||||
'tirada' => $datosPedido->tirada,
|
||||
'paginas' => intval($reqData['paginas']) ?? 0,
|
||||
'ancho' => $datosPedido->ancho,
|
||||
'alto' => $datosPedido->alto,
|
||||
'POD' => $POD,
|
||||
'solapas' => intval($reqData['solapasCubierta'] ?? 0) > 0 ? 1 : 0,
|
||||
]);
|
||||
$costeServiciosDefecto = 0.0;
|
||||
foreach ($servDefecto as $servicio) {
|
||||
if ($servicio->total <= 0)
|
||||
$error->serviciosDefecto = lang('Presupuestos.errores.errorPresupuesto');
|
||||
|
||||
$costeServiciosDefecto += floatval($servicio->total);
|
||||
}
|
||||
|
||||
// Servicios
|
||||
$servicios = $reqData['servicios'] ?? [];
|
||||
if ($reqData['guardas'] ?? 0 > 0) {
|
||||
array_push($servicios, 62); // Plegado de guardas
|
||||
}
|
||||
/*
|
||||
'retractilado' => 3,
|
||||
'retractilado5' => 5,
|
||||
'ferro' => 24,
|
||||
'prototipo' => 9,
|
||||
'fajaColor' => 16,
|
||||
'plegadoGuardas' => 62,
|
||||
*/
|
||||
$serviciosAutomaticos = [];
|
||||
|
||||
foreach ($servicios as $servicio) {
|
||||
if (intval($servicio) == 3 || intval($servicio) == 5 || intval($servicio) == 16) {
|
||||
// Servicios acabado
|
||||
$resultado = PresupuestoCLienteService::getServiciosManipulado([
|
||||
'tarifa_id' => $servicio,
|
||||
'tirada' => $datosPedido->tirada,
|
||||
'POD' => $POD,
|
||||
]);
|
||||
array_push($serviciosAutomaticos, $resultado[0]);
|
||||
if ($resultado[0]->total <= 0)
|
||||
$error->servicios = lang('Presupuestos.errores.errorPresupuesto');
|
||||
|
||||
$coste_servicios += floatval($resultado[0]->total);
|
||||
} else if (intval($servicio) == 24 || intval($servicio) == 9) {
|
||||
// Servicios preimpresion
|
||||
$resultado = PresupuestoCLienteService::getServiciosExtra([
|
||||
'tarifa_id' => $servicio,
|
||||
]);
|
||||
array_push($serviciosAutomaticos, $resultado[0]);
|
||||
if ($resultado[0]->precio <= 0)
|
||||
$error->servicios = lang('Presupuestos.errores.errorPresupuesto');
|
||||
|
||||
$coste_servicios += floatval($resultado[0]->precio);
|
||||
} else if (intval($servicio) == 62) {
|
||||
// Servicios manipulado
|
||||
$resultado = PresupuestoCLienteService::getServiciosManipulado([
|
||||
'tarifa_id' => $servicio,
|
||||
'tirada' => $datosPedido->tirada,
|
||||
'POD' => $POD,
|
||||
]);
|
||||
array_push($serviciosAutomaticos, $resultado[0]);
|
||||
if ($resultado[0]->total <= 0)
|
||||
$error->servicios = lang('Presupuestos.errores.errorPresupuesto');
|
||||
|
||||
$coste_servicios += floatval($resultado[0]->total);
|
||||
}
|
||||
}
|
||||
|
||||
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));
|
||||
foreach ($error as $err) {
|
||||
if ($err != "")
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$return_data = [
|
||||
'errors' => $error,
|
||||
'total_lp' => $costeInterior + $coste_cubierta + $coste_sobrecubierta,
|
||||
'acabadoCubierta' => $acabadoCubierta,
|
||||
'acabadoSobrecubierta' => $acabadoSobrecubierta,
|
||||
'total_servicios_defecto' => $costeServiciosDefecto,
|
||||
'total_servicios_automaticos' => $coste_servicios,
|
||||
'tiradas' => $tirada,
|
||||
'precio_u' => $precio_u,
|
||||
'peso' => $peso,
|
||||
|
||||
'interior' => $interior,
|
||||
'cubierta' => $cubierta,
|
||||
'sobrecubierta' => $linea_sobrecubierta,
|
||||
'guardas' => $guardas,
|
||||
'serviciosDefecto' => $servDefecto,
|
||||
'servicios_automaticos' => $serviciosAutomaticos,
|
||||
$csrfTokenName => $newTokenHash
|
||||
];
|
||||
|
||||
|
||||
return $this->respond($return_data);
|
||||
} else {
|
||||
return $this->failUnauthorized('Invalid request', 403);
|
||||
}
|
||||
}
|
||||
|
||||
public function getDireccionesCliente()
|
||||
{
|
||||
if ($this->request->isAJAX()) {
|
||||
|
||||
$newTokenHash = csrf_hash();
|
||||
$csrfTokenName = csrf_token();
|
||||
|
||||
$reqData = $this->request->getPost();
|
||||
$cliente_id = $reqData['id'] ?? 0;
|
||||
$model = model('App\Models\Clientes\ClienteDireccionesModel');
|
||||
$data = $model->getMenuDirecciones($cliente_id);
|
||||
array_unshift($data, ['id' => 0, 'text' => 'Agregar nueva dirección']);
|
||||
|
||||
return $this->respond([
|
||||
'menu' => $data,
|
||||
$csrfTokenName => $newTokenHash
|
||||
]);
|
||||
} else {
|
||||
return $this->failUnauthorized('Invalid request', 403);
|
||||
}
|
||||
}
|
||||
|
||||
public function getDatosDireccion()
|
||||
{
|
||||
|
||||
if ($this->request->isAJAX()) {
|
||||
|
||||
$newTokenHash = csrf_hash();
|
||||
$csrfTokenName = csrf_token();
|
||||
|
||||
$reqData = $this->request->getPost();
|
||||
$direccionId = $reqData['id'] ?? 0;
|
||||
$peso = $reqData['peso'] ?? 0;
|
||||
$unidades = $reqData['unidades'] ?? 0;
|
||||
$model = model('App\Models\Clientes\ClienteDireccionesModel');
|
||||
$data = $model->getDireccion($direccionId);
|
||||
|
||||
$modelTarifaEnvio = model('App\Models\Tarifas\TarifaEnvioModel');
|
||||
$coste = 0;
|
||||
if ($data > 0) {
|
||||
$tarifas_envio = $modelTarifaEnvio->getTarifaEnvio($data[0]->pais_id, $peso, $unidades, 'cajas');
|
||||
for ($i = 0; $i < count($tarifas_envio); $i++) {
|
||||
if ($peso > $tarifas_envio[$i]->peso_max) {
|
||||
$tarifas_envio[$i]->precio = number_format($tarifas_envio[$i]->peso_min + ($peso - $data[$i]->peso_min) * $data[$i]->precio_adicional, 2);
|
||||
}
|
||||
// si no se calcula linealmente
|
||||
else {
|
||||
$m = (($tarifas_envio[$i]->precio_max - $tarifas_envio[$i]->precio_min) / ($tarifas_envio[$i]->peso_max - $tarifas_envio[$i]->peso_min));
|
||||
$b = $tarifas_envio[$i]->precio_max - $m * $tarifas_envio[$i]->peso_max;
|
||||
$tarifas_envio[$i]->precio = number_format($m * $peso + $b, 2);
|
||||
}
|
||||
$tarifas_envio[$i]->margen = $tarifas_envio[$i]->margen;
|
||||
}
|
||||
|
||||
if(count($tarifas_envio) > 1){
|
||||
$tarifa_final = array_reduce($tarifas_envio, function ($previous, $current) {
|
||||
return $current->precio < $previous->precio ? $current : $previous;
|
||||
});
|
||||
$coste = $tarifa_final->precio;
|
||||
}
|
||||
else{
|
||||
$coste = $tarifas_envio[0]->precio;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
$data[0]->coste = $coste;
|
||||
|
||||
return $this->respond([
|
||||
'data' => $data,
|
||||
$csrfTokenName => $newTokenHash
|
||||
]);
|
||||
} else {
|
||||
return $this->failUnauthorized('Invalid request', 403);
|
||||
}
|
||||
}
|
||||
|
||||
public function getNuevaDireccion()
|
||||
{
|
||||
|
||||
if ($this->request->isAJAX()) {
|
||||
|
||||
$newTokenHash = csrf_hash();
|
||||
$csrfTokenName = csrf_token();
|
||||
|
||||
$reqData = $this->request->getPost();
|
||||
|
||||
$data = [
|
||||
'cliente_id' => $reqData['cliente_id'] ?? 0,
|
||||
'alias' => $reqData['alias'] ?? "",
|
||||
'att' => $reqData['att'] ?? "",
|
||||
'email' => $reqData['email'] ?? "",
|
||||
'direccion' => $reqData['direccion'] ?? "",
|
||||
'pais_id' => $reqData['pais_id'] ?? 0,
|
||||
'municipio' => $reqData['municipio'] ?? "",
|
||||
'provincia' => $reqData['provincia'] ?? "",
|
||||
'cp' => $reqData['cp'] ?? "",
|
||||
'telefono' => $reqData['telefono'] ?? ""
|
||||
];
|
||||
|
||||
$model = model('App\Models\Clientes\ClienteDireccionesModel');
|
||||
$id = $model->nuevaDireccion($data);
|
||||
|
||||
$menu = $model->getMenuDirecciones($data['cliente_id']);
|
||||
|
||||
|
||||
return $this->respond([
|
||||
'data' => $menu,
|
||||
$csrfTokenName => $newTokenHash
|
||||
]);
|
||||
} else {
|
||||
return $this->failUnauthorized('Invalid request', 403);
|
||||
}
|
||||
@ -620,270 +1064,8 @@ class Presupuestocliente extends \App\Controllers\GoBaseResourceController
|
||||
* Funciones auxiliares
|
||||
*
|
||||
**********************/
|
||||
protected function getLineasPresupuesto($reqData)
|
||||
protected function calcular_lomo($lineas, $lomo_inicial)
|
||||
{
|
||||
$error =(object)[
|
||||
'interior' => "",
|
||||
'cubierta' => "",
|
||||
'sobrecubierta' => "",
|
||||
'guardas' => "",
|
||||
'servicios' => "",
|
||||
'serviciosDefecto' => "",
|
||||
];
|
||||
$coste_servicios = 0.0;
|
||||
|
||||
$POD = model('App\Models\Configuracion\ConfiguracionSistemaModel')->getPOD();
|
||||
|
||||
|
||||
$tirada = $reqData['tirada'] ?? 0;
|
||||
$tamanio = $reqData['tamanio'];
|
||||
$tipo_impresion_id = $this->getTipoImpresion($reqData['tipo'], $reqData['tapa']);
|
||||
$precio_u = [];
|
||||
|
||||
for($t=0; $t<count($tirada); $t++){
|
||||
$tirada[$t] = intval($tirada[$t]);
|
||||
|
||||
$paginas_color = intval($reqData['paginasColor']) ?? 0;
|
||||
$is_cosido = (new TipoPresupuestoModel())->get_isCosido($tipo_impresion_id);
|
||||
|
||||
$datosPedido = (object)array(
|
||||
'paginas' => intval($reqData['paginas']) ?? 0,
|
||||
'tirada' => $tirada[$t],
|
||||
'merma' => $tirada[$t] > $POD ? $this->calcular_merma($tirada[$t], $POD) : 0,
|
||||
'ancho' => intval($tamanio['ancho']) ?? 100000,
|
||||
'alto' => intval($tamanio['alto']) ?? 100000,
|
||||
'isCosido' => $is_cosido,
|
||||
);
|
||||
|
||||
$papel_generico = [
|
||||
'id' => $reqData['papelInterior'] ?? 0,
|
||||
'nombre' => $reqData['papelInteriorNombre'] ?? "",
|
||||
];
|
||||
$gramaje = $reqData['gramajeInterior'] ?? 0;
|
||||
$cliente_id = $reqData['clienteId'] ?? -1;
|
||||
$excluirRotativa = $reqData['excluirRotativa'] ?? 0;
|
||||
|
||||
$input_data = array(
|
||||
'uso' => 'interior',
|
||||
'tipo_impresion_id' => $tipo_impresion_id,
|
||||
'datosPedido' => $datosPedido,
|
||||
'papel_generico' => $papel_generico,
|
||||
'gramaje' => $gramaje,
|
||||
'isColor' => intval($reqData['isColor']) ?? 0,
|
||||
'isHq' => intval($reqData['isHq']) ?? 0,
|
||||
'cliente_id' => $cliente_id,
|
||||
'paginas_color' => $paginas_color,
|
||||
'excluirRotativa' => $excluirRotativa,
|
||||
);
|
||||
|
||||
$interior = PresupuestoClienteService::obtenerInterior($input_data);
|
||||
|
||||
$costeInterior = 0.0;
|
||||
foreach ($interior as $linea) {
|
||||
if (count($linea) > 0) {
|
||||
$costeInterior += floatval($linea['total_impresion']);
|
||||
}
|
||||
}
|
||||
|
||||
if ($costeInterior <= 0) {
|
||||
$error->interior = lang('Presupuestos.errores.noInterior');
|
||||
}
|
||||
|
||||
// Si es POD hay que volver a calcular para incluir la merma correcta
|
||||
if ($tirada[$t] <= $POD) {
|
||||
$num_formas = [];
|
||||
foreach ($interior as $linea) {
|
||||
if (count($linea) > 0) {
|
||||
$formas_linea = $is_cosido ? intval($linea['num_formas']['value']) / 2 : intval($linea['num_formas']['value']);
|
||||
array_push($num_formas, $formas_linea);
|
||||
}
|
||||
}
|
||||
$input_data['datosPedido']->merma = $this->calcular_merma($tirada[$t], $POD, $num_formas);
|
||||
|
||||
$interior = PresupuestoClienteService::obtenerInterior($input_data);
|
||||
}
|
||||
|
||||
$costeInterior = 0.0;
|
||||
foreach ($interior as $linea) {
|
||||
if (count($linea) > 0) {
|
||||
$costeInterior += floatval($linea['total_impresion']);
|
||||
}
|
||||
}
|
||||
|
||||
if ($costeInterior <= 0)
|
||||
$error->interior = lang('Presupuestos.errores.noInterior');
|
||||
else
|
||||
$error->interior = "";
|
||||
|
||||
|
||||
// Cubierta
|
||||
$papel_generico = [
|
||||
'id' => $reqData['papelCubierta'] ?? 0,
|
||||
'nombre' => $reqData['papelCubiertaNombre'] ?? "",
|
||||
];
|
||||
$input_data['papel_generico'] = $papel_generico;
|
||||
$input_data['gramaje'] = $reqData['gramajeCubierta'] ?? 0;
|
||||
$input_data['datosPedido']->paginas = intval($reqData['carasCubierta'] ?? 0);
|
||||
$input_data['paginas_color'] = intval($reqData['carasCubierta'] ?? 0);
|
||||
$input_data['datosPedido']->solapas_ancho = intval($reqData['solapasCubierta'] ?? 0);
|
||||
$input_data['datosPedido']->solapas = $input_data['datosPedido']->solapas_ancho>0 ? 1 : 0;
|
||||
$input_data['datosPedido']->lomo = $this->calcular_lomo($interior, 0);
|
||||
$input_data['isColor'] = 1;
|
||||
$input_data['isHq'] = 1;
|
||||
$input_data['uso'] = 'cubierta';
|
||||
|
||||
$cubierta = PresupuestoClienteService::obtenerCubierta($input_data);
|
||||
$coste_cubierta = 0.0;
|
||||
if (count($cubierta) > 0) {
|
||||
$coste_cubierta += floatval($cubierta['total_impresion']);
|
||||
}
|
||||
if($coste_cubierta <= 0)
|
||||
$error->cubierta = lang('Presupuestos.errores.noCubiertaSobrecubierta');
|
||||
else
|
||||
$error->cubierta = "";
|
||||
|
||||
$tarifaAcabadoCubierta = intval($reqData['acabadoCubierta'] ?? 0);
|
||||
$acabadoCubierta = [];
|
||||
if($tarifaAcabadoCubierta > 0){
|
||||
$model = model('App\Models\Presupuestos\PresupuestoAcabadosModel');
|
||||
$acabadoCubierta = $model->getPrecioTarifa($tarifaAcabadoCubierta, $datosPedido->tirada, $POD);
|
||||
}
|
||||
if(count($acabadoCubierta) > 0){
|
||||
if($acabadoCubierta[0]->total <= 0 )
|
||||
$error->servicios = lang('Presupuestos.errores.errorPresupuesto');
|
||||
$coste_servicios += floatval($acabadoCubierta[0]->total);
|
||||
}
|
||||
|
||||
// Sobrecubierta
|
||||
$coste_sobrecubierta = 0.0;
|
||||
$linea_sobrecubierta = [];
|
||||
$sobreCubierta = $reqData["sobrecubierta"] ?? null;
|
||||
if(!is_null($sobreCubierta)){
|
||||
|
||||
$papel_generico = [
|
||||
'id' => $sobreCubierta['papel'] ?? 0,
|
||||
'nombre' => $sobreCubierta['papel_nombre'] ?? "",
|
||||
];
|
||||
$input_data['papel_generico'] = $papel_generico;
|
||||
$input_data['gramaje'] = $sobreCubierta['gramaje'] ?? 0;
|
||||
$input_data['datosPedido']->paginas = 4;
|
||||
$input_data['paginas_color'] = 4;
|
||||
$input_data['datosPedido']->solapas_ancho = intval($sobreCubierta['solapas'] ?? 0);
|
||||
$input_data['datosPedido']->solapas = $input_data['datosPedido']->solapas_ancho>0 ? 1 : 0;
|
||||
$input_data['datosPedido']->lomo = $this->calcular_lomo([$cubierta], $input_data['datosPedido']->lomo);
|
||||
$input_data['isColor'] = 1;
|
||||
$input_data['isHq'] = 1;
|
||||
$input_data['uso'] = 'sobrecubierta';
|
||||
|
||||
$linea_sobrecubierta = PresupuestoClienteService::obtenerSobrecubierta($input_data);
|
||||
|
||||
if (count($linea_sobrecubierta) > 0) {
|
||||
$coste_sobrecubierta += floatval($linea_sobrecubierta['total_impresion']);
|
||||
}
|
||||
if($coste_sobrecubierta <= 0)
|
||||
$error->sobrecubierta = lang('Presupuestos.errores.noCubiertaSobrecubierta');
|
||||
else
|
||||
$error->sobrecubierta = "";
|
||||
|
||||
$tarifaAcabadoSobrecubierta = intval(strlen($sobreCubierta['acabado'])==0 ? 0:$sobreCubierta['acabado']);
|
||||
$acabadoSobrecubierta = [];
|
||||
if($tarifaAcabadoSobrecubierta > 0){
|
||||
$model = model('App\Models\Presupuestos\PresupuestoAcabadosModel');
|
||||
$acabadoSobrecubierta = $model->getPrecioTarifa($tarifaAcabadoSobrecubierta, $datosPedido->tirada, $POD);
|
||||
}
|
||||
if(count($acabadoSobrecubierta) > 0){
|
||||
if($acabadoSobrecubierta[0]->total <= 0 )
|
||||
$error->servicios = lang('Presupuestos.errores.errorPresupuesto');
|
||||
$coste_servicios += floatval($acabadoSobrecubierta[0]->total);
|
||||
}
|
||||
}
|
||||
|
||||
//Guardas
|
||||
if($reqData['guardas'] ?? 0 > 0){
|
||||
|
||||
$guardas = $reqData['guardas'];
|
||||
$papel_generico = [
|
||||
'id' => $guardas['papel'] ?? 0,
|
||||
'nombre' => $guardas['nombre'] ?? "",
|
||||
];
|
||||
$input_data['papel_generico'] = $papel_generico;
|
||||
$input_data['gramaje'] = $guardas['gramaje'] ?? 0;
|
||||
$input_data['datosPedido']->paginas = 8;
|
||||
$input_data['paginas_color'] = 8;
|
||||
$input_data['datosPedido']->paginas_impresion = $guardas['caras'] ?? 0;
|
||||
$input_data['datosPedido']->solapas_ancho = 0;
|
||||
$input_data['datosPedido']->solapas = 0;
|
||||
$input_data['isColor'] = 1;
|
||||
$input_data['isHq'] = 1;
|
||||
$input_data['uso'] = 'guardas';
|
||||
|
||||
// Para el caso de Fresado y Cosido tapa dura, las guardas son un diptico
|
||||
// y hay que imprimirlas como "cosido" (dos hojas pegadas). En el caso de espiral
|
||||
// o wire-o tapa dura, las guardas se imprimen como hojas sueltas
|
||||
if ($tipo_impresion_id == 1 || $tipo_impresion_id == 3) {
|
||||
$input_data['datosPedido']->isCosido = true;
|
||||
} else if ($tipo_impresion_id == 5 || $tipo_impresion_id == 7) {
|
||||
$input_data['datosPedido']->isCosido = false;
|
||||
}
|
||||
|
||||
$guardas = PresupuestoClienteService::obtenerGuardas($input_data);
|
||||
$coste_guardas = 0.0;
|
||||
if (count($guardas) > 0) {
|
||||
$coste_guardas += floatval($guardas['total_impresion']);
|
||||
}
|
||||
if($coste_guardas <= 0)
|
||||
$error->guardas = lang('Presupuestos.errores.noGuardas');
|
||||
else
|
||||
$error->guardas = "";
|
||||
}
|
||||
|
||||
// Servicios defecto
|
||||
$servDefecto = PresupuestoCLienteService::getServiciosEncuadernacionDefault([
|
||||
'tipo_impresion_id' => $tipo_impresion_id,
|
||||
'tirada' => $datosPedido->tirada,
|
||||
'paginas' => intval($reqData['paginas']) ?? 0,
|
||||
'ancho' => $datosPedido->ancho,
|
||||
'alto' => $datosPedido->alto,
|
||||
'POD' => $POD,
|
||||
'solapas' => intval($reqData['solapasCubierta'] ?? 0)>0?1:0,
|
||||
]);
|
||||
$costeServiciosDefecto = 0.0;
|
||||
foreach ($servDefecto as $servicio) {
|
||||
if($servicio->total <= 0 )
|
||||
$error->serviciosDefecto = lang('Presupuestos.errores.errorPresupuesto');
|
||||
|
||||
$costeServiciosDefecto += floatval($servicio->total);
|
||||
}
|
||||
|
||||
array_push($precio_u, round(($costeInterior + $coste_cubierta + $coste_sobrecubierta + $costeServiciosDefecto + $coste_servicios)/$tirada[$t], 4));
|
||||
foreach($error as $err){
|
||||
if($err != "")
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if($reqData['guardas'] ?? 0 > 0){
|
||||
}
|
||||
|
||||
return [
|
||||
'errors' => $error,
|
||||
'total_lp' => $costeInterior+$coste_cubierta+$coste_sobrecubierta,
|
||||
'acabadoCubierta' => $acabadoCubierta,
|
||||
'total_servicios_defecto' => $costeServiciosDefecto,
|
||||
'tiradas' => $tirada,
|
||||
'precio_u' => $precio_u,
|
||||
|
||||
'interior' => $interior,
|
||||
'cubierta' => $cubierta,
|
||||
'sobrecubierta' => $linea_sobrecubierta,
|
||||
'guardas' => $guardas,
|
||||
'serviciosDefecto' => $servDefecto,
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
|
||||
protected function calcular_lomo($lineas, $lomo_inicial){
|
||||
$lomo = $lomo_inicial;
|
||||
foreach ($lineas as $linea) {
|
||||
if (count($linea) > 0) {
|
||||
@ -991,4 +1173,13 @@ class Presupuestocliente extends \App\Controllers\GoBaseResourceController
|
||||
endif;
|
||||
return $data;
|
||||
}
|
||||
|
||||
protected function getPaisListItems()
|
||||
{
|
||||
$paisModel = model('App\Models\Configuracion\PaisModel');
|
||||
$onlyActiveOnes = true;
|
||||
$data = $paisModel->getAllForMenu('id, nombre', 'nombre', $onlyActiveOnes);
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
||||
@ -141,6 +141,7 @@ class ClienteDireccionesModel extends \App\Models\BaseModel
|
||||
|
||||
return $builder->get()->getResultObject();
|
||||
}
|
||||
|
||||
|
||||
public function getMenuDirecciones($cliente_id=-1){
|
||||
|
||||
@ -154,4 +155,11 @@ class ClienteDireccionesModel extends \App\Models\BaseModel
|
||||
return $builder->get()->getResultArray();
|
||||
|
||||
}
|
||||
|
||||
public function nuevaDireccion($data)
|
||||
{
|
||||
$builder = $this->db->table($this->table);
|
||||
$builder->insert($data);
|
||||
return $this->db->insertID();
|
||||
}
|
||||
}
|
||||
|
||||
@ -20,11 +20,23 @@ class PresupuestoClienteService extends BaseService
|
||||
$rotativa = PresupuestoClienteService::obtenerPresupuestoClienteInteriorRotativa($data);
|
||||
|
||||
$total_plana = -1;
|
||||
if (count($plana[0]) > 0 || count($plana[1]) > 0) {
|
||||
$total_plana = 0.0;
|
||||
if($data['isColor']){
|
||||
if (count($plana[0]) > 2 && count($plana[1]) > 2) {
|
||||
$total_plana = 0.0;
|
||||
foreach ($plana as $linea) {
|
||||
if (count($linea) > 0)
|
||||
$total_plana += floatval($linea['total_impresion']);
|
||||
}
|
||||
}
|
||||
}
|
||||
else{
|
||||
foreach ($plana as $linea) {
|
||||
if (count($linea) > 0)
|
||||
$total_plana += floatval($linea['total_impresion']);
|
||||
if($linea['tipo_linea'] == 'lp_bn' || $linea['tipo_linea'] == 'lp_bnhq'){
|
||||
$total_plana = 0.0;
|
||||
$total_plana = floatval($linea['total_impresion']);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -331,6 +343,47 @@ class PresupuestoClienteService extends BaseService
|
||||
return $values;
|
||||
}
|
||||
|
||||
public static function getServiciosManipulado($data){
|
||||
|
||||
$tarifa_id = $data['tarifa_id'] ?? -1;
|
||||
$tirada = $data['tirada'] ?? -1;
|
||||
$POD = $data['POD'] ?? -1;
|
||||
|
||||
$model = model('App\Models\Presupuestos\PresupuestoManipuladosModel');
|
||||
$values = $model->getPrecioTarifa($tarifa_id, $tirada, $POD);
|
||||
return $values;
|
||||
}
|
||||
|
||||
public static function getServiciosPreimpresion($data){
|
||||
|
||||
$tarifa_id = $data['tarifa_id'] ?? -1;
|
||||
|
||||
$model = model('App\Models\Presupuestos\PresupuestoPreimpresionesModel');
|
||||
$values = $model->getPrecioTarifa($tarifa_id);
|
||||
return $values;
|
||||
}
|
||||
|
||||
|
||||
public static function getServiciosExtra($data){
|
||||
|
||||
$tarifa_id = $data['tarifa_id'] ?? -1;
|
||||
|
||||
$model = model('App\Models\Presupuestos\PresupuestoServiciosExtraModel');
|
||||
$values = $model->getPrecioTarifa($tarifa_id);
|
||||
return $values;
|
||||
}
|
||||
|
||||
public static function getServiciosAcabados($data){
|
||||
|
||||
$tarifa_id = $data['tarifa_id'] ?? -1;
|
||||
$tirada = $data['tirada'] ?? -1;
|
||||
$POD = $data['POD'] ?? -1;
|
||||
|
||||
$model = model('App\Models\Presupuestos\PresupuestoAcabadosModel');
|
||||
$values = $model->getPrecioTarifa($tarifa_id, $tirada, $POD);
|
||||
return $values;
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtiene las lineas de rotativa en el presupuesto de cliente
|
||||
* Selecciona entre las más económicas
|
||||
|
||||
@ -19,7 +19,7 @@
|
||||
</div><!--//.mb-3 -->
|
||||
<div class="mb-3">
|
||||
<label for="add_email" class="form-label">
|
||||
<?= lang('ClienteDirecciones.email') ?>*
|
||||
<?= lang('ClienteDirecciones.email') ?>
|
||||
</label>
|
||||
<input type="text" id="add_email" tabindex="2" maxLength="100" class="form-control">
|
||||
</div><!--//.mb-3 -->
|
||||
@ -65,7 +65,7 @@
|
||||
<div class="col-md-12 col-lg-6 pl-4 spain-data" style="display: none;">
|
||||
<div class="mb-3">
|
||||
<label for="add_provincia" class="form-label">
|
||||
<?=lang('ClienteDirecciones.provincia') ?>*
|
||||
<?=lang('ClienteDirecciones.provincia') ?>
|
||||
</label>
|
||||
<input type="text" id="add_provincia" tabindex="7" maxLength="100" class="form-control">
|
||||
</div><!--//.mb-3 -->
|
||||
@ -87,7 +87,7 @@
|
||||
<div class="col-md-12 col-lg-6 pl-4">
|
||||
<div class="mb-3">
|
||||
<label for="add_telefono" class="form-label">
|
||||
<?=lang('ClienteDirecciones.telefono') ?>*
|
||||
<?=lang('ClienteDirecciones.telefono') ?>
|
||||
</label>
|
||||
<input type="text" id="add_telefono" tabindex="9" maxLength="100" class="form-control"></input>
|
||||
</div><!--//.mb-3 -->
|
||||
|
||||
@ -0,0 +1,42 @@
|
||||
<div class="col-12 pb-2">
|
||||
|
||||
<div id="containerTiradasEnvios" class="row mb-3">
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
<div class="row mb-3">
|
||||
|
||||
<div class="col-sm-4 mb-3">
|
||||
<label for="direcciones" class="form-label">Mis direcciones</label>
|
||||
<select id="direcciones" name="direcciones" class="form-control select2bs2" style="width: 100%;"></select>
|
||||
</div>
|
||||
<div class="col-sm-2 mb-3">
|
||||
<label for="unidadesEnvio" class="form-label">
|
||||
Unidades
|
||||
</label>
|
||||
<input type="number" class="form-control" id="unidadesEnvio" name="unidadesEnvio" maxLength="8" step="1" class="form-control">
|
||||
</div><!--//.mb-3 -->
|
||||
<div class="col-sm-2 mb-3 mt-auto mb-0">
|
||||
<button id="insertarDireccion" type="button" class="btn btn-secondary waves-effect waves-light">Insertar</button>
|
||||
</div>
|
||||
<div id="errorDirecciones" class="fv-plugins-message-container invalid-feedback" style="display: none;">
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="divDirecciones" class="col-12 pb-2">
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?= $this->section("additionalInlineJs") ?>
|
||||
|
||||
window.routes_direcciones = {
|
||||
direcciones: "<?= route_to('getDirecciones') ?>",
|
||||
getDatos: "<?= route_to('getDatosDireccion') ?>",
|
||||
nuevaDireccion: "<?= route_to('nuevaDireccion') ?>",
|
||||
}
|
||||
<?= $this->endSection() ?>
|
||||
@ -73,6 +73,11 @@
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
|
||||
<div id="errorTiradas" class="fv-plugins-message-container invalid-feedback" style="display: none;">
|
||||
<div>No puede mezclar tiradas mayores de 30 unidades con tiradas menores de 30 unidades</div>
|
||||
</div>
|
||||
|
||||
<div class="col-sm-3 mb-3">
|
||||
<label for="tirada" class="form-label">
|
||||
<?= lang('Presupuestos.tirada') ?> 1
|
||||
@ -392,14 +397,7 @@
|
||||
|
||||
<div class="row sobrecubierta enable-sobrecubierta" style="display: none;">
|
||||
|
||||
<div class="col-sm-3 mb-md-0 mb-2 d-flex align-items-end">
|
||||
<div class="form-check form-switch mb-2">
|
||||
<input class="form-check-input calcular-presupuesto input-sobrecubierta" type="checkbox" id="solapasSobrecubierta" name="solapasSobrecubierta" value="0">
|
||||
<label class="form-check-label" for="solapasSobrecubierta">Solapas sobrecubierta</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="tamanioSolapasSobrecubierta" class="col-sm-3 mb-md-0 mb-2" style="display: none;">
|
||||
<div id="tamanioSolapasSobrecubierta" class="col-sm-3 mb-md-0 mb-2"">
|
||||
<label for="anchoSolapasSobrecubierta" class="form-label">Tamaño</label>
|
||||
<input type="number" id="anchoSolapasSobrecubierta" name="anchoSolapasSobrecubierta" maxLength="8" step="1" class="form-control input-sobrecubierta calcular-presupuesto" value="">
|
||||
</div>
|
||||
|
||||
@ -0,0 +1,49 @@
|
||||
<div class="col-12 pb-2">
|
||||
<div class="row mb-3">
|
||||
<h3>Resumen</h3>
|
||||
<div class="col-sm-6">
|
||||
<h5 class="mb-1">Libro</h5>
|
||||
<p class="mb-0"><small id="tipoLibro">Rústica cosido tapa blanda</small></p>
|
||||
<p class="mb-0"><small id="resumenTamanio">Tamaño: 100x100</small></p>
|
||||
<p class="mb-0"><small id="resumenPaginas">Número de páginas: 200</small></p>
|
||||
<p class="mb-0"><small id="resumenTirada">Tirada: 200</small></p>
|
||||
<p class="mb-0"><small id="resumenPrototipo">Prototipo: NO</small></p>
|
||||
<p class="mb-3"><small id="resumenFerro">Ferro: NO</small></p>
|
||||
|
||||
<h5 class="mb-1">Interior</h5>
|
||||
<p class="mb-0"><small id="tipoImpresion">Impresion: Negro premium</small></p>
|
||||
<p id="pResumenPaginasColor" class="mb-0" style="display:none"><small id="resumenPaginasColor">Páginas a color: 100</small></p>
|
||||
<p class="mb-3"><small id="resumenPapelInterior">Papel: Blanco Offset 70gr/m²</small></p>
|
||||
|
||||
<h5 class="mb-1">Cubierta</h5>
|
||||
<p class="mb-0"><small id="resumenPapelCubierta">Papel: Blanco Offset 70gr/m²</small></p>
|
||||
<p class="mb-0"><small id="resumenCarasCubierta">Impresión: 1 cara</small></p>
|
||||
<p class="mb-0"><small id="resumenSolapasCubierta">Solapas: 25mm</small></p>
|
||||
<p class="mb-3"><small id="resumenAcabadoCubierta">Acabado: Ninguno</small></p>
|
||||
|
||||
<h5 class="mb-1 resumen-sobrecubierta">Sobrecubierta</h5>
|
||||
<p class="mb-0 resumen-sobrecubierta"><small id="resumenPapelSobrecubierta">Papel: Blanco Offset 70gr/m<sup>2</sup></small></p>
|
||||
<p class="mb-0 resumen-sobrecubierta"><small id="resumenSolapasCubierta">Ancho solapas: 25mm</small></p>
|
||||
<p class="mb-3 resumen-sobrecubierta"><small id="resumenAcabadoCubierta">Acabado: Ninguno</small></p>
|
||||
|
||||
<h5 class="mb-1 resumen-guardas">Guardas</h5>
|
||||
<p class="mb-0 resumen-guardas"><small id="resumenGuardasPapel">Papel: Blanco Offset 70gr/m<sup>2</sup></small></p>
|
||||
<p class="mb-3 resumen-guardas"><small id="resumenGuardasCaras">Impresión: 1 cara</small></p>
|
||||
|
||||
<h5 class="mb-1 resumen-extras">Extras</h5>
|
||||
<p class="mb-0 resumen-extras" id="resumenRetractilado1"><small>Retractilado individual</small></p>
|
||||
<p class="mb-0 resumen-extras" id="resumenRetractilado5"><small>Retractilado de 5</small></p>
|
||||
<p class="mb-0 resumen-extras" id="resumenFajaColor"><small>Imprimir faja a color</small></p>
|
||||
</div>
|
||||
|
||||
<div class="col-sm-6">
|
||||
<h4 id="resumenTotal" class="mb-1">Total: 100€</h4>
|
||||
<h6 id="resumenPrecioU" class="mb-0">10.4€/ud</h6>
|
||||
<h6 id="resumenTotalIVA"class="mb-0">Coste impresion (4% IVA): 104€</h6>
|
||||
<h6 id="resumenEnvio" class="mb-1">Envío: 30€</h6>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
@ -57,8 +57,7 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row row-cols-3 d-flex justify-content-center d-flex justify-content-center"
|
||||
style="margin-bottom: 40px;">
|
||||
<div class="row row-cols-3 d-flex justify-content-center d-flex justify-content-center">
|
||||
<div class="col-md-4 mb-6 d-flex justify-content-center">
|
||||
<div>
|
||||
<div style="max-width:200px;max-height:200px;padding-right:0px" id="espiralDiv"
|
||||
@ -77,7 +76,7 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col-md-4 mb-6 d-flex justify-content-center" style="margin-bottom: 40px;">
|
||||
<div class="col-md-4 mb-6 d-flex justify-content-center" >
|
||||
<div>
|
||||
<div style="max-width:200px;max-height:200px;padding-right:0px" id="wireoDiv"
|
||||
class="form-check custom-option-tipo custom-option custom-option-image custom-option-image-radio">
|
||||
|
||||
@ -0,0 +1,303 @@
|
||||
function initDirecciones() {
|
||||
data = {
|
||||
id: $('#clienteId').val()
|
||||
},
|
||||
data = Object.assign(data, window.token_ajax)
|
||||
|
||||
$.ajax({
|
||||
url: window.routes_direcciones.direcciones,
|
||||
type: 'POST',
|
||||
data: data,
|
||||
success: function(response) {
|
||||
$("#direcciones").empty();
|
||||
$.each(response.menu, function(index, value) {
|
||||
$("#direcciones").append('<option value="' + value.id + '">' + value.text + '</option>');
|
||||
});
|
||||
$("#direcciones").val('');
|
||||
},
|
||||
error: function() {
|
||||
$("#direcciones").empty();
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
function initTiradasDirecciones() {
|
||||
const _this = this
|
||||
|
||||
$('#containerTiradasEnvios').empty();
|
||||
|
||||
for (i = 1; i <= 4; i++) {
|
||||
let id = "tiradaPrecio" + i;
|
||||
if ($('#' + id).length > 0) {
|
||||
|
||||
let tirada_id = "ud_tiradaPrecio" + i;
|
||||
let total_id = "tot_tiradaPrecio" + i;
|
||||
let precio_u_id = "pu_tiradaPrecio" + i;
|
||||
let peso = $('#' + id).attr('peso');
|
||||
|
||||
let html = '';
|
||||
html += '<div class="col-sm-3">';
|
||||
html += '<div class="form-check custom-option custom-option-basic custom-option-tiradasDirecciones' + (i==1?' checked':'')+ ' ">';
|
||||
html += '<label class="form-check-label custom-option-content" for="tiradaEnvios' + i + '">';
|
||||
html += '<input name=env_"' + id + '" peso="' + peso + '" class="form-check-input" type="radio" value="" id="env_' + id + '">';
|
||||
html += '<span class="custom-option-header">';
|
||||
html += '<span id="tiradaDireccionesValue' + i + '" class="h6 mb-0">' + $('#' + tirada_id).text().split(' ')[0] + '</span>';
|
||||
html += '<span class="text-muted">' + $('#' + total_id).text() + '</span>';
|
||||
html += '</span>';
|
||||
html += '<span class="custom-option-body">';
|
||||
html += '<small>' + $('#' + precio_u_id).text() + '</small>';
|
||||
html += '</span>';
|
||||
html += '</label>';
|
||||
html += '</div>';
|
||||
html += '</div>';
|
||||
|
||||
$('#containerTiradasEnvios').append(html);
|
||||
|
||||
$('#' + id).hide();
|
||||
}
|
||||
}
|
||||
|
||||
const tiradasDireccionesList = [].slice.call(document.querySelectorAll('.custom-option-tiradasDirecciones .form-check-input'))
|
||||
tiradasDireccionesList.map(function (customOptionEL) {
|
||||
// Update custom options check on page load
|
||||
_this.updateTiradasDireccionesCheck(customOptionEL)
|
||||
|
||||
// Update custom options check on click
|
||||
customOptionEL.addEventListener('click', e => {
|
||||
_this.updateTiradasDireccionesCheck(customOptionEL)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
function updateTiradasDireccionesCheck(el) {
|
||||
if (el.checked) {
|
||||
// If custom option element is radio, remove checked from the siblings (closest `.row`)
|
||||
if (el.type === 'radio') {
|
||||
const customRadioOptionList = [].slice.call(el.closest('.row').querySelectorAll('.custom-option-tiradasDirecciones'))
|
||||
customRadioOptionList.map(function (customRadioOptionEL) {
|
||||
customRadioOptionEL.closest('.custom-option-tiradasDirecciones').classList.remove('checked')
|
||||
})
|
||||
}
|
||||
el.closest('.custom-option-tiradasDirecciones').classList.add('checked')
|
||||
|
||||
} else {
|
||||
el.closest('.custom-option-tiradasDirecciones').classList.remove('checked')
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function obtenerUnidadesEnvio(){
|
||||
|
||||
const elements = $('#divDirecciones').find('.row.mb-3');
|
||||
let total = 0;
|
||||
|
||||
if(elements.length > 0) {
|
||||
for (let index=0; index<elements.length; index++){
|
||||
let unidades_direcciones = parseInt($(elements[index]).find('div label span span').text().split(' ')[0]);
|
||||
total += unidades_direcciones;
|
||||
};
|
||||
}
|
||||
return total;
|
||||
}
|
||||
|
||||
|
||||
$('#insertarDireccion').on('click', function() {
|
||||
|
||||
if( $('#direcciones').val() > 0 ) {
|
||||
|
||||
let unidades = $('#unidadesEnvio').val();
|
||||
if(unidades == '' || isNaN(unidades) || parseInt(unidades) <= 0){
|
||||
return false;
|
||||
}
|
||||
unidades = parseInt(unidades);
|
||||
|
||||
const seleccion = $('.custom-option-tiradasDirecciones.checked');
|
||||
if(seleccion.length == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const element_tirada =($(seleccion[0]).find('label input')[0]);
|
||||
const number = element_tirada.id.match(/\d+$/);
|
||||
if (number.length == 0) {
|
||||
return false;
|
||||
}
|
||||
let tirada = parseInt($('#tiradaDireccionesValue' + number[0]).text());
|
||||
|
||||
let total = obtenerUnidadesEnvio();
|
||||
|
||||
if($('#prototipo').is(':checked')) {
|
||||
tirada += 1;
|
||||
}
|
||||
|
||||
if(total + unidades <= tirada) {
|
||||
|
||||
data = {
|
||||
id: $('#direcciones').val(),
|
||||
peso: $('#env_tiradaPrecio' + number[0]).attr('peso'),
|
||||
unidades: unidades
|
||||
},
|
||||
data = Object.assign(data, window.token_ajax)
|
||||
|
||||
$.ajax({
|
||||
url: window.routes_direcciones.getDatos,
|
||||
type: 'POST',
|
||||
data: data,
|
||||
success: function(response) {
|
||||
if(response.data.length > 0) {
|
||||
let html = '';
|
||||
html += '<div id="envioId' + response.data[0].id + '" p= ' +response.data[0].coste + ' class="row mb-3">';
|
||||
html += '<div class="col-sm-5 form-check custom-option custom-option-basic checked">';
|
||||
html += '<label class="form-check-label custom-option-content" for="customRadioAddress1">';
|
||||
html += '<span class="custom-option-header mb-2">';
|
||||
html += '<h6 class="fw-semibold mb-0">' + response.data[0].att + '</h6>';
|
||||
html += '<span class="badge bg-label-primary">' + unidades + ' unidades</span>';
|
||||
html += '</span>';
|
||||
html += '<span class="custom-option-body">';
|
||||
html += '<small>' + response.data[0].direccion + '</small><br>';
|
||||
html += '<small>' + response.data[0].cp + '</small><br>';
|
||||
html += '<small>' + response.data[0].municipio +', ' + response.data[0].pais + '</small><br>';
|
||||
html += '<small>' + response.data[0].telefono + '</small><br>';
|
||||
html += '<small>' + response.data[0].email + '</small><br>';
|
||||
html += '<hr class="my-2">';
|
||||
html += '<span class="d-flex">';
|
||||
html += '<a class="eliminar-direccion" href="javascript:void(0)">Eliminar</a>';
|
||||
html += '</span>';
|
||||
html += '</span>';
|
||||
html += '</label>';
|
||||
html += '</div>';
|
||||
html += '</div>';
|
||||
|
||||
$('#divDirecciones').append(html);
|
||||
$('#errorDirecciones').hide();
|
||||
}
|
||||
},
|
||||
error: function() {
|
||||
$("#direcciones").empty();
|
||||
},
|
||||
});
|
||||
}
|
||||
else{
|
||||
$('#errorDirecciones').text('El número de unidades supera la tirada seleccionada.');
|
||||
$('#errorDirecciones').show();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
return false;
|
||||
})
|
||||
|
||||
|
||||
|
||||
$(document).on('click', '.eliminar-direccion', function(e) {
|
||||
|
||||
$(this).closest('.row.mb-3').remove();
|
||||
|
||||
const seleccion = $('.custom-option-tiradasDirecciones.checked');
|
||||
if(seleccion.length == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const element_tirada =($(seleccion[0]).find('label input')[0]);
|
||||
const number = element_tirada.id.match(/\d+$/);
|
||||
if (number.length == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
let tirada = parseInt($('#tiradaDireccionesValue' + number[0]).text());
|
||||
|
||||
const elements = $('#divDirecciones').find('.row.mb-3');
|
||||
|
||||
let total = 0;
|
||||
if(elements.length > 0) {
|
||||
for (let index=0; index<elements.length; index++){
|
||||
let unidades_direcciones = parseInt($(elements[index]).find('div label span span').text().split(' ')[0]);
|
||||
total += unidades_direcciones;
|
||||
};
|
||||
}
|
||||
|
||||
if(total <= tirada) {
|
||||
$('#errorDirecciones').hide();
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
|
||||
$('#direcciones').on('change', function() {
|
||||
if( $('#direcciones').val() == 0 ) {
|
||||
$("#addressForm").attr('action','create')
|
||||
|
||||
var $newAddDialog = $("#addressForm")
|
||||
$newAddDialog.modal('show')
|
||||
|
||||
$newAddDialog.on('hidden.bs.modal', function (e) {
|
||||
$('#direcciones').val('');
|
||||
});
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
function saveAdd_callback(){
|
||||
if($('#addressForm').attr('action')=='create'){
|
||||
let data = {
|
||||
cliente_id: $('#clienteId').val(),
|
||||
alias: $('#add_alias').val(),
|
||||
att: $('#add_att').val(),
|
||||
email: $('#add_email').val(),
|
||||
direccion: $('#add_direccion').val(),
|
||||
pais_id: $("#add_pais_id option:selected").val(),
|
||||
municipio: $('#add_municipio').val(),
|
||||
provincia: $('#add_provincia').val(),
|
||||
cp: $('#add_cp').val(),
|
||||
telefono: $('#add_telefono').val(),
|
||||
}
|
||||
console.log(data);
|
||||
data = Object.assign(data, window.token_ajax)
|
||||
|
||||
$.ajax({
|
||||
url: window.routes_direcciones.nuevaDireccion,
|
||||
type: 'POST',
|
||||
data: data,
|
||||
success: function(response) {
|
||||
$("#direcciones").empty();
|
||||
$.each(response.data, function(index, value) {
|
||||
$("#direcciones").append('<option value="' + value.id + '">' + value.text + '</option>');
|
||||
});
|
||||
$("#direcciones").val('');
|
||||
$('#addressForm').modal('hide');
|
||||
},
|
||||
error: function() {
|
||||
$('#addressForm').modal('hide');
|
||||
},
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
function validarEnvio(){
|
||||
|
||||
const seleccion = $('.custom-option-tiradasDirecciones.checked');
|
||||
if(seleccion.length == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const element_tirada =($(seleccion[0]).find('label input')[0]);
|
||||
|
||||
const number = element_tirada.id.match(/\d+$/);
|
||||
if (number.length == 0) {
|
||||
return false;
|
||||
}
|
||||
let tirada = parseInt($('#tiradaDireccionesValue' + number[0]).text());
|
||||
|
||||
let total = obtenerUnidadesEnvio();
|
||||
|
||||
if($('#prototipo').is(':checked')) {
|
||||
tirada += 1;
|
||||
}
|
||||
|
||||
if(total != tirada){
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@ -137,7 +137,6 @@ $('#enableSobrecubierta').on('change', function () {
|
||||
$('#gramajeSobrecubierta').val('').trigger('change');
|
||||
$('#paperSobrecubierta').val('').trigger('change');
|
||||
$('#acabadosSobrecubierta').val('').trigger('change');
|
||||
$('#solapasSobrecubierta').prop('checked', false).trigger('change');
|
||||
$('#tamanioSolapasSobrecubierta').val();
|
||||
$('.enable-sobrecubierta').hide();
|
||||
|
||||
@ -170,7 +169,8 @@ $('.change-tipo-impresion').on('change', function () {
|
||||
//si es color hay que mostrar el numero de paginas a color
|
||||
if (isColor) {
|
||||
$('#pagColorDiv').show();
|
||||
$('#paginasColor').val('0');
|
||||
if($('#paginasColor').val() == '')
|
||||
$('#paginasColor').val('0');
|
||||
}
|
||||
else {
|
||||
$('#pagColorDiv').hide();
|
||||
@ -338,7 +338,7 @@ $('#papelSobrecubierta').on('change', function () {
|
||||
});
|
||||
|
||||
if (valSobrecubierta != undefined)
|
||||
$('#gramajeSobrecubierta option[value=' + valCubierta + ']').prop('selected', true).trigger('change');
|
||||
$('#gramajeSobrecubierta option[value=' + valSobrecubierta + ']').prop('selected', true).trigger('change');
|
||||
else
|
||||
$('#gramajeSobrecubierta').val('').trigger('change');
|
||||
}
|
||||
@ -355,14 +355,6 @@ $('#solapasCubierta').on('change', function () {
|
||||
}
|
||||
});
|
||||
|
||||
$('#solapasSobrecubierta').on('change', function () {
|
||||
if ($(this).is(":checked")) {
|
||||
$('#tamanioSolapasSobrecubierta').show();
|
||||
} else {
|
||||
$('#tamanioSolapasSobrecubierta').hide();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
// Funcion que comprueba que están rellenos todos los datos necesarios para calcular el presupuesto
|
||||
function checkValues() {
|
||||
@ -377,6 +369,14 @@ function checkValues() {
|
||||
const papelFormatoAncho = $('#anchoLibro').val();
|
||||
const clienteId = $('#clienteId').val();
|
||||
|
||||
if (paginas == '' || isNaN(paginas) || parseInt(paginas) <= 0) {
|
||||
return false;
|
||||
}
|
||||
if(parseInt(paginas)%2!=0){
|
||||
$('#paginas').val(parseInt(paginas)+1).trigger('change');
|
||||
return false;
|
||||
}
|
||||
|
||||
if(clienteId == '' || isNaN(clienteId) || parseInt(clienteId) <= 0){
|
||||
return false;
|
||||
}
|
||||
@ -385,10 +385,6 @@ function checkValues() {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (paginas == '' || isNaN(paginas) || parseInt(paginas) <= 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (papelInterior == '' || gramajeInterior == '') {
|
||||
return false;
|
||||
}
|
||||
@ -578,9 +574,31 @@ $('.calcular-presupuesto').on('change', function () {
|
||||
calcularPresupuesto();
|
||||
});
|
||||
|
||||
function comprobarTiradasPOD(){
|
||||
const tiradas = getTiradas();
|
||||
|
||||
//Comprobar que todos los elementos del array tiradas estan por encima de 30 o por debajo
|
||||
const tiradasPOD = tiradas.every(tirada => tirada <= 30);
|
||||
const tiradasNoPOD = tiradas.every(tirada => tirada > 30);
|
||||
if (tiradasPOD == !tiradasNoPOD) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
$('#clienteId').on('select2:change', function () {
|
||||
calcularPresupuesto();
|
||||
});
|
||||
|
||||
|
||||
async function calcularPresupuesto() {
|
||||
|
||||
if(!comprobarTiradasPOD()){
|
||||
$('#errorTiradas').show();
|
||||
return;
|
||||
}
|
||||
$('#errorTiradas').hide();
|
||||
|
||||
// se obtiene la propiedad serv_id de los checkboxes seleccionados de la clase .servicio-extra
|
||||
if (!checkValues()) {
|
||||
return;
|
||||
@ -627,9 +645,8 @@ async function calcularPresupuesto() {
|
||||
gramaje: $('#gramajeSobrecubierta option:selected').text(),
|
||||
acabado: $('#acabadosSobrecubierta').val()
|
||||
}
|
||||
if ($('#solapasSobrecubierta').is(':checked')) {
|
||||
datos.sobrecubierta.solapas = $('#anchoSolapasSobrecubierta').val()
|
||||
}
|
||||
|
||||
datos.sobrecubierta.solapas = $('#anchoSolapasSobrecubierta').val()
|
||||
}
|
||||
}
|
||||
|
||||
@ -644,7 +661,7 @@ async function calcularPresupuesto() {
|
||||
|
||||
datos = Object.assign(datos, window.token_ajax)
|
||||
|
||||
|
||||
$('#divTiradasPrecio').empty();
|
||||
$('#loader').show();
|
||||
|
||||
$.ajax({
|
||||
@ -691,24 +708,36 @@ async function calcularPresupuesto() {
|
||||
|
||||
console.log(response);
|
||||
$('#loader').hide();
|
||||
if(error){
|
||||
$('#precios > tbody').empty();
|
||||
$('#precios').hide();
|
||||
}
|
||||
else{
|
||||
$('#precios > tbody').empty();
|
||||
|
||||
for (i = 0; i < response.tiradas.length; i++) {
|
||||
$('#precios > tbody').append('<tr class="table-light"><td>' + response.tiradas[i] + '</td><td>' + response.precio_u[i] + '€</td></tr>');
|
||||
}
|
||||
$('#precios').show();
|
||||
}
|
||||
|
||||
$('#divTiradasPrecio').empty();
|
||||
|
||||
$('#precios').show();
|
||||
|
||||
for (i = 0; i < response.tiradas.length; i++) {
|
||||
const total = (parseFloat(response.precio_u[i]) * parseInt(response.tiradas[i])).toFixed(2) ;
|
||||
const label = "tiradaPrecio" + parseInt(i+1);
|
||||
|
||||
let html = '';
|
||||
|
||||
|
||||
html += '<div id="' + label + '" peso="' +response.peso[i]+ '" class="list-group" >';
|
||||
html += '<a href="javascript:void(0);" class="list-group-item list-group-item-action">';
|
||||
html += '<div class="li-wrapper d-flex justify-content-start align-items-center" >';
|
||||
html += '<div class="list-content">';
|
||||
html += '<h7 id="ud_' + label + '" class="mb-1">' + (response.tiradas[i] + ' ud.') + '</h7>';
|
||||
html += '<h6 id="tot_' + label + '" class="mb-1">' + ('Total: ' + total + '€') + '</h6>';
|
||||
html += '<h7 id="pu_' + label + '" class="mb-1">' + (response.precio_u[i] + '€/ud') + '</h7>';
|
||||
html += '</div>';
|
||||
html += '</div>'
|
||||
html += '</a>';
|
||||
html += '</div>';
|
||||
|
||||
$('#divTiradasPrecio').append(html);
|
||||
}
|
||||
},
|
||||
error: function (error) {
|
||||
$('#loader').hide();
|
||||
$('#precios > tbody').empty();
|
||||
$('#precios').hide();
|
||||
$('#divTiradasPrecio').empty();
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -208,6 +208,8 @@
|
||||
}
|
||||
}).on('core.form.valid', function () {
|
||||
validationStepper.next();
|
||||
initDirecciones();
|
||||
initTiradasDirecciones();
|
||||
});
|
||||
|
||||
const tirada = $('#tirada');
|
||||
@ -218,7 +220,7 @@
|
||||
FormValidation2.revalidateField('gramajeSobrecubierta');
|
||||
});
|
||||
|
||||
// Deal Usage
|
||||
// Direcciones
|
||||
const FormValidation4 = FormValidation.formValidation(clientePresupuestoWizardFormStep4, {
|
||||
fields: {
|
||||
|
||||
@ -235,7 +237,18 @@
|
||||
submitButton: new FormValidation.plugins.SubmitButton()
|
||||
}
|
||||
}).on('core.form.valid', function () {
|
||||
validationStepper.next();
|
||||
if(validarEnvio()){
|
||||
generarResumen();
|
||||
validationStepper.next();
|
||||
}
|
||||
else{
|
||||
let text = "El número de unidades enviadas no coincie con la tirada seleccionada.";
|
||||
if($('#prototipo').is(':checked')) {
|
||||
text += "<br>(Tenga en cuenta que se ha seleccionado la opción de prototipo)";
|
||||
}
|
||||
$('#errorDirecciones').text(text);
|
||||
$('#errorDirecciones').show();
|
||||
}
|
||||
});
|
||||
|
||||
// Deal Usage
|
||||
@ -300,6 +313,12 @@
|
||||
break;
|
||||
|
||||
case 2:
|
||||
for (let i = 0; i < 4; i++) {
|
||||
let id = "tiradaPrecio" + i;
|
||||
if ($('#' + id).length > 0) {
|
||||
$('#' + id).show();
|
||||
}
|
||||
}
|
||||
validationStepper.previous();
|
||||
break;
|
||||
|
||||
|
||||
122
ci4/app/Views/themes/vuexy/form/presupuestos/cliente/resumen.js
Normal file
122
ci4/app/Views/themes/vuexy/form/presupuestos/cliente/resumen.js
Normal file
@ -0,0 +1,122 @@
|
||||
function generarResumen(){
|
||||
$('#tipoLibro').text($('#tituloDisenioLibro').text() + ' tapa ' + (($('#tapaBlandaInnerDiv').hasClass('checked'))?'blanda':'dura'));
|
||||
$('#resumenTamanio').text('Dimensiones: ' + getDimensionLibro().ancho + 'x' + getDimensionLibro().alto + 'mm');
|
||||
$('#resumenPaginas').text('Páginas: '+ $('#paginas').val() + ' páginas');
|
||||
|
||||
const seleccion = $('.custom-option-tiradasDirecciones.checked');
|
||||
let tirada = 0;
|
||||
if(seleccion.length != 0) {
|
||||
|
||||
const element_tirada =($(seleccion[0]).find('label input')[0]);
|
||||
const number = element_tirada.id.match(/\d+$/);
|
||||
if (number.length != 0) {
|
||||
tirada = parseInt($('#tiradaDireccionesValue' + number[0]).text());
|
||||
}
|
||||
}
|
||||
$('#resumenTirada').text('Tirada: '+ tirada + ' unidades');
|
||||
|
||||
$('#resumenPrototipo').text('Prototipo: ' + (($('#prototipo').is(':checked'))?'Sí':'No'));
|
||||
$('#resumenFerro').text('Ferro: ' + (($('#ferro').is(':checked'))?'Sí':'No'));
|
||||
|
||||
$('#tipoImpresion').text('Impresión: ' +
|
||||
($('#colorNegroDiv').hasClass('checked')?'Negro ':'Color ') +
|
||||
($('#calidadEstandarDiv').hasClass('checked')?'Estándar': 'Premium'));
|
||||
if($('#colorNegroDiv').hasClass('checked')){
|
||||
$('#pResumenPaginasColor').hide();
|
||||
}
|
||||
else{
|
||||
$('#pResumenPaginasColor').show();
|
||||
$('#resumenPaginasColor').text($('#paginasColor').val());
|
||||
}
|
||||
$('#resumenPapelInterior').text($('#papelInterior option:selected').text().trim() + ' ' +
|
||||
$('#gramajeInterior option:selected').text() + 'gr/m²');
|
||||
|
||||
let papelCubierta = $('#papelCubierta option:selected').text().trim() + ' ' +
|
||||
$('#gramajeCubierta option:selected').text();
|
||||
papelCubierta += 'gr/m<sup>2</sup>';
|
||||
$('#resumenPapelCubierta').text(papelCubierta);
|
||||
$('#resumenCarasCubierta').text('Impresión: ' + $('#carasCubierta option:selected').text())
|
||||
$('#resumenAcabadoCubierta').text('Acabado: ' + $('#acabadosCubierta option:selected').text())
|
||||
if ($('#solapasCubierta').is(':checked')) {
|
||||
$('#resumenSolapasCubierta').text('Solapas: ' + $('#anchoSolapasCubierta').val())
|
||||
}
|
||||
else{
|
||||
$('#resumenSolapasCubierta').text('Solapas: No')
|
||||
}
|
||||
|
||||
if ($('.enable-sobrecubierta').is(':visible')) {
|
||||
$(".resumen-sobrecubierta").show();
|
||||
$('#resumenPapelCubierta').text($('#papelSobrecubierta option:selected').text().trim() + ' ' +
|
||||
$('#gramajeSobrecubierta option:selected').text() + 'gr/m²');
|
||||
$('#resumenAcabadoSobrecubierta').text('Acabado: ' + $('#acabadosSobrecubierta option:selected').text())
|
||||
$('#resumenSolapasSobrecubierta').text('Solapas: ' + $('#anchoSolapasSobrecubierta').val())
|
||||
|
||||
}
|
||||
else{
|
||||
$(".resumen-sobrecubierta").hide();
|
||||
}
|
||||
|
||||
if ($('.guardas').is(':visible')) {
|
||||
$(".resumen-guardas").show();
|
||||
$('#resumenGuardasPapel').text($('#papelGuardas option:selected').text().trim() + ' ' + '170gr/m²');
|
||||
$('#resumenGuardasCaras').text('Impresión: ' + $('#impresionGuardas option:selected').text())
|
||||
}
|
||||
else{
|
||||
$(".resumen-guardas").hide();
|
||||
}
|
||||
|
||||
|
||||
if($('#retractilado').is(':checked') || $('#retractilado5').is(':checked') || $('#fajaColor').is(':checked')){
|
||||
|
||||
$('.resumen-extras').show();
|
||||
$('#retractilado').is(':checked')?$('#resumenRetractilado1').show():$('#resumenRetractilado1').hide();
|
||||
$('#retractilado5').is(':checked')?$('#resumenRetractilado5').show():$('#resumenRetractilado5').hide();
|
||||
$('#fajaColor').is(':checked')?$('#resumenFajaColor').show():$('#resumenFajaColor').hide();
|
||||
}
|
||||
else{
|
||||
$('.resumen-extras').hide();
|
||||
}
|
||||
|
||||
for (i = 1; i <= 4; i++) {
|
||||
let id = "tiradaPrecio" + i;
|
||||
if ($('#' + id).length > 0) {
|
||||
|
||||
let tirada_id = "ud_tiradaPrecio" + i;
|
||||
if(parseInt($('#' + tirada_id).text().replace(' ud.', '')) != tirada){
|
||||
continue;
|
||||
}
|
||||
|
||||
let total_id = "tot_tiradaPrecio" + i;
|
||||
let precio_u_id = "pu_tiradaPrecio" + i;
|
||||
|
||||
$('#resumenTotal').text($('#' + total_id).text());
|
||||
$('#resumenPrecioU').text($('#' + precio_u_id).text());
|
||||
let total = parseFloat($('#' + total_id).text().replace('€', '').replace('Total: ', ''));
|
||||
let total_iva = 0.0;
|
||||
if($('#ivaReducido').val() == '1'){
|
||||
total_iva = total * 1.04;
|
||||
}
|
||||
else{
|
||||
total_iva = total * 1.21;
|
||||
}
|
||||
$('#resumenTotalIVA').text('Total (I.V.A. ' + (($('#ivaReducido').val() == '1')?'4':'21') + '%): ' + total_iva.toFixed(2) + '€');
|
||||
const envio = getTotalEnvio();
|
||||
$('#resumenEnvio').text('Envío: ' + envio.toFixed(2) + '€');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function getTotalEnvio(){
|
||||
const elements = $('#divDirecciones').find('.row.mb-3');
|
||||
let total = 0.0;
|
||||
|
||||
if(elements.length > 0) {
|
||||
for (let index=0; index<elements.length; index++){
|
||||
let precio_envio = parseFloat($(elements[index]).attr('p'));
|
||||
total += precio_envio;
|
||||
};
|
||||
}
|
||||
|
||||
return total;
|
||||
}
|
||||
@ -6,6 +6,7 @@
|
||||
|
||||
<?= $this->section("content") ?>
|
||||
|
||||
<?= view("themes/vuexy/form/clientes/cliente/_clienteDireccionesForm") ?>
|
||||
<div class="container-xxl flex-grow-1 container-p-y">
|
||||
<div class="col-12">
|
||||
<h3 class="card-title"><?= $boxTitle ?? $pageTitle ?></h3>
|
||||
@ -62,20 +63,15 @@
|
||||
</div>
|
||||
|
||||
<div id="errorGeneral" class="fv-plugins-message-container invalid-feedback" style="display: none;">
|
||||
<p>Se ha producido un error al calcular el presupuesto. Póngase en contacto con el administrador</p>
|
||||
<p>Se ha producido un error <br>
|
||||
al calcular el presupuesto. <br>
|
||||
Póngase en contacto con el <br>
|
||||
administrador.</p>
|
||||
</div>
|
||||
|
||||
<table id="precios" class="table table-sm" style="display: none;">
|
||||
<caption>Precio/Unidad por tirada</caption>
|
||||
<thead>
|
||||
<tr>
|
||||
<th></th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
</tbody>
|
||||
</table>
|
||||
<div id='divTiradasPrecio'>
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
@ -87,9 +83,8 @@
|
||||
<div id="tipo-libro" class="content active dstepper-block fv-plugins-bootstrap5 fv-plugins-framework">
|
||||
<div class="row g-3">
|
||||
|
||||
|
||||
<?= view("themes/vuexy/form/presupuestos/cliente/_tipoLibroItems") ?>
|
||||
|
||||
|
||||
<div class="col-12 d-flex justify-content-between mt-4">
|
||||
<button class="btn btn-label-secondary btn-prev waves-effect">
|
||||
<i class="ti ti-arrow-left ti-xs me-sm-1 me-0"></i>
|
||||
@ -122,11 +117,11 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Deal Usage -->
|
||||
<!-- Direcciones -->
|
||||
<div id="direcciones-libro" class="content fv-plugins-bootstrap5 fv-plugins-framework">
|
||||
<div class="row g-3">
|
||||
|
||||
|
||||
<?= view("themes/vuexy/form/presupuestos/cliente/_direccionesItems") ?>
|
||||
|
||||
<div class="col-12 d-flex justify-content-between mt-4">
|
||||
<button class="btn btn-label-secondary btn-prev waves-effect">
|
||||
@ -145,15 +140,25 @@
|
||||
<div id="resumen-libro" class="content fv-plugins-bootstrap5 fv-plugins-framework">
|
||||
<div class="row g-3">
|
||||
|
||||
<?= view("themes/vuexy/form/presupuestos/cliente/_resumenItems") ?>
|
||||
|
||||
</div>
|
||||
<div class="col-12 d-flex justify-content-between mt-4">
|
||||
<button class="btn btn-label-secondary btn-prev waves-effect">
|
||||
<i class="ti ti-arrow-left ti-xs me-sm-1 me-0"></i>
|
||||
<span class="align-middle d-sm-inline-block d-none">Anterior</span>
|
||||
</button>
|
||||
<button class="btn btn-success btn-submit btn-next waves-effect waves-light">
|
||||
<span class="align-middle d-sm-inline-block d-none me-sm-1">Submit</span><i class="ti ti-check ti-xs"></i>
|
||||
</button>
|
||||
<div class="col-6 d-flex flex-row">
|
||||
<button class="btn btn-label-secondary btn-prev waves-effect">
|
||||
<i class="ti ti-arrow-left ti-xs me-sm-1 me-0"></i>
|
||||
<span class="align-middle d-sm-inline-block d-none">Anterior</span>
|
||||
</button>
|
||||
</div>
|
||||
<div class="col-6 d-flex flex-row-reverse">
|
||||
<button class="btn btn-primary btn-submit waves-effect waves-light ml-2">
|
||||
<span class="align-middle d-sm-inline-block d-none me-sm-1">Guardar</span>
|
||||
<i class="ti ti-arrow-right ti-xs"></i>
|
||||
</button>
|
||||
<button class="btn btn-success btn-submit btn-next mx-2 waves-effect waves-light">
|
||||
<span class="align-middle d-sm-inline-block d-none me-sm-1">Confirmar</span><i class="ti ti-check ti-xs"></i>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -161,12 +166,8 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
</div><!--//.col -->
|
||||
<div class="pt-4">
|
||||
<input type="submit" class="btn btn-primary float-start me-sm-3 me-1" name="save" id="saveForm" value="<?= lang("Basic.global.Save") ?>" />
|
||||
</div>
|
||||
|
||||
</div><!--//.row -->
|
||||
<?= view("themes/_commonPartialsBs/_modalConfirmDialog") ?>
|
||||
<?= view("themes/_commonPartialsBs/_modalMessageDialog") ?>
|
||||
@ -237,4 +238,6 @@ initDisenioLibro();
|
||||
<script src="<?= site_url('js_loader/presupuestoCliente_js') ?>"></script>
|
||||
<script src="<?= site_url('js_loader/presupuestoClienteTipoLibro_js') ?>"></script>
|
||||
<script src="<?= site_url('js_loader/presupuestoClienteDisenioLibro_js') ?>"></script>
|
||||
<script src="<?= site_url('js_loader/presupuestoClienteDirecciones_js') ?>"></script>
|
||||
<script src="<?= site_url('js_loader/presupuestoClienteResumen_js') ?>"></script>
|
||||
<?= $this->endSection() ?>
|
||||
@ -1268,34 +1268,34 @@ function get_tarifas_preimpresion(tarifa_id = -1){
|
||||
|
||||
function servicioPrototipo(){
|
||||
if($('#prototipo').prop('checked')){
|
||||
$('#add_servicio_preimpresion_list').val(serviciosAutomaticos.prototipo)
|
||||
$('#insertar_serv_preimpresion').click()
|
||||
$('#add_servicio_extra_list').val(serviciosAutomaticos.prototipo)
|
||||
$('#insertar_serv_extra').click()
|
||||
}
|
||||
else{
|
||||
var row_indexes = tableServiciosPreimpresion.rows().eq( 0 ).filter( function (rowIdx) {
|
||||
return tableServiciosPreimpresion.cell( rowIdx, 0 ).data() == serviciosAutomaticos.prototipo ? true : false;
|
||||
var row_indexes = tableServiciosExtra.rows().eq( 0 ).filter( function (rowIdx) {
|
||||
return tableServiciosExtra.cell( rowIdx, 0 ).data() == serviciosAutomaticos.prototipo ? true : false;
|
||||
} );
|
||||
if(row_indexes.length > 0){
|
||||
tableServiciosPreimpresion.row(row_indexes[0]).remove().draw()
|
||||
tableServiciosExtra.row(row_indexes[0]).remove().draw()
|
||||
check_serv_preimpresion_error()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function servicioFerro(){
|
||||
var row_indexes = tableServiciosPreimpresion.rows().eq( 0 ).filter( function (rowIdx) {
|
||||
return tableServiciosPreimpresion.cell( rowIdx, 0 ).data() == serviciosAutomaticos.ferro ? true : false;
|
||||
var row_indexes = tableServiciosExtra.rows().eq( 0 ).filter( function (rowIdx) {
|
||||
return tableServiciosExtra.cell( rowIdx, 0 ).data() == serviciosAutomaticos.ferro ? true : false;
|
||||
} );
|
||||
if($('#ferro').prop('checked')){
|
||||
if(row_indexes.length == 0){
|
||||
$('#add_servicio_preimpresion_list').val(serviciosAutomaticos.ferro)
|
||||
$('#insertar_serv_preimpresion').click()
|
||||
$('#add_servicio_extra_list').val(serviciosAutomaticos.ferro)
|
||||
$('#insertar_serv_extra').click()
|
||||
}
|
||||
}
|
||||
else{
|
||||
if(row_indexes.length > 0){
|
||||
tableServiciosPreimpresion.row(row_indexes[0]).remove().draw()
|
||||
check_serv_preimpresion_error()
|
||||
tableServiciosExtra.row(row_indexes[0]).remove().draw()
|
||||
check_serv_extra_error()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -59,7 +59,7 @@
|
||||
/**
|
||||
* JJO
|
||||
*/
|
||||
|
||||
--->
|
||||
<li class="menu-header small text-uppercase">
|
||||
<span class="menu-header-text">Test JJO</span>
|
||||
</li>
|
||||
@ -69,7 +69,7 @@
|
||||
<div data-i18n="Test">Test</div>
|
||||
</a>
|
||||
</li>
|
||||
--->
|
||||
|
||||
|
||||
|
||||
</ul>
|
||||
|
||||
@ -10,11 +10,10 @@
|
||||
"slack": "https://codeigniterchat.slack.com"
|
||||
},
|
||||
"require": {
|
||||
"php": "^8.1",
|
||||
"php": "^8.2",
|
||||
"codeigniter4/framework": "^4.0",
|
||||
"codeigniter4/shield": "^1.0",
|
||||
"dompdf/dompdf": "^2.0",
|
||||
//"phpoffice/phpspreadsheet": "^1.18"
|
||||
"dompdf/dompdf": "^2.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"fakerphp/faker": "^1.9",
|
||||
|
||||
2711
ci4/composer.lock
generated
Executable file → Normal file
2711
ci4/composer.lock
generated
Executable file → Normal file
File diff suppressed because it is too large
Load Diff
88359
xdebug.log
88359
xdebug.log
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user