Añadido configurador

This commit is contained in:
imnavajas
2025-07-25 13:41:40 +02:00
parent 200e45c898
commit e642f0520a
9 changed files with 308 additions and 249 deletions

View File

@ -272,7 +272,7 @@ class ImportadorCatalogo extends BaseResourceController
'gramajeCubierta' => $libro->cubierta_gramaje,
'solapas' => $libro->cubierta_ancho_solapas,
'acabado' => $libro->cubierta_acabado_id,
'cabezada' => 'WHI',
'cabezada' => model('\App\Models\Configuracion\ConfigVariableModel')->getCabezadaDefault(),
'lomoRedondo' => 0
],

View File

@ -460,6 +460,8 @@ class Presupuestoadmin extends \App\Controllers\BaseResourceController
$this->viewData['tipo_impresion_id'] = $presupuestoEntity->tipo_impresion_id; // Cosido tapa blanda JJO
$this->viewData['cabezadas'] = model('\App\Models\Configuracion\ConfigVariableModel')->getCabezadasDisponibles();
$this->viewData = array_merge($this->viewData, $this->getStringsFromTipoImpresion($presupuestoEntity->tipo_impresion_id));
$this->viewData['formAction'] = route_to('updatePresupuestoAdmin', $id);

View File

@ -133,6 +133,7 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController
$this->viewData['lomo_maximo_fresado_cosido'] = model('App\Models\Configuracion\ConfigVariableModel')->getVariable('lomo_maximo_fresado_cosido')->value;
$this->viewData['lomo_minimo_fresado_cosido'] = model('App\Models\Configuracion\ConfigVariableModel')->getVariable('lomo_minimo_fresado_cosido')->value;
$this->viewData['eb'] = 0;
$this->viewData['cabezadas'] = model('\App\Models\Configuracion\ConfigVariableModel')->getCabezadasDisponibles();
$this->viewData['boxTitle'] = lang('Basic.global.addNew') . ' ' . $this->viewData['pageTitle'] . ' ' . lang('Basic.global.addNewSuffix');
@ -178,6 +179,7 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController
$this->viewData['lomo_maximo_fresado_cosido'] = model('App\Models\Configuracion\ConfigVariableModel')->getVariable('lomo_maximo_fresado_cosido')->value;
$this->viewData['lomo_minimo_fresado_cosido'] = model('App\Models\Configuracion\ConfigVariableModel')->getVariable('lomo_minimo_fresado_cosido')->value;
$this->viewData['eb'] = $presupuestoEntity->envio_base;
$this->viewData['cabezadas'] = model('\App\Models\Configuracion\ConfigVariableModel')->getCabezadasDisponibles();
// Si se ha llamado a esta funcion porque se ha duplicado el presupuesto
// se actualiza la bbdd para que sólo ejecute algunas funciones una vez
@ -1103,7 +1105,7 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController
'solapasCubierta' => intval($cubierta['solapas'] ?? 0) == 1 ? intval($cubierta['tamanioSolapas']) : 0,
'acabado' => $cubierta['acabado'] ?? 0,
'lomoRedondo' => $cubierta['lomoRedondo'] ?? 0,
'cabezada' => $cubierta['cabezada'] ?? 'WHI',
'cabezada' => $cubierta['cabezada'] ?? model('\App\Models\Configuracion\ConfigVariableModel')->getCabezadaDefault(),
];
// Sobrecubierta

View File

@ -56,4 +56,40 @@ class ConfigVariableModel extends Model
return $builder->get()->getFirstRow();
}
/**
* Devuelve solo el valor de la variable por nombre
*/
public function getValue(string $name): ?string
{
$row = $this->getVariable($name);
return $row ? $row->value : null;
}
/**
* Devuelve el valor decodificado (JSON) si aplica
*/
public function getDecodedValue(string $name): ?array
{
$value = $this->getValue($name);
$decoded = json_decode($value, true);
return (json_last_error() === JSON_ERROR_NONE && is_array($decoded)) ? $decoded : null;
}
/**
* Devuelve las opciones disponibles de cabezadas (como array clave => langKey)
*/
public function getCabezadasDisponibles(): array
{
return $this->getDecodedValue('cabezadas_disponibles') ?? [];
}
/**
* Devuelve la cabezada por defecto, o 'WHI' si no está definida
*/
public function getCabezadaDefault(): string
{
return $this->getValue('cabezada_default') ?? 'WHI';
}
}

View File

@ -15,7 +15,7 @@
<?= view('themes/_commonPartialsBs/_alertBoxes'); ?>
<table id="tableConfigVariables" class="table table-striped table-hover" style="width: 100%;">
<table id="tableConfigVariables" class="table table-striped table-hover table-responsive" style="width: 100%; word-break: break-word;">
<thead>
<tr>
<th><?= lang('ConfigVariables.datatable.columns.name') ?></th>
@ -55,11 +55,13 @@
<div class="row g-4">
<div class="col-12 mb-0">
<label for="value" class="form-label"><?= lang('ConfigVariables.form.value') ?></label>
<input type="number" min=0 id="value" class="form-control">
<div id="value-wrapper">
</div>
</div>
<div class="col-12 mb-0">
<label for="description" class="form-label"><?= lang('ConfigVariables.form.description') ?></label>
<textarea type="text" rows="4" cols="10" id="description" class="form-control"></textarea>
<textarea type="text" rows="4" cols="10" id="description" class="form-control"></textarea>
</div>
</div>
</div>
@ -75,4 +77,13 @@
<?= $this->endSection() ?>
<?= $this->section("additionalExternalJs") ?>
<script type="module" src="<?= versioned_asset('assets/js/safekat/pages/configuracion/variables.js') ?>"></script>
<script>
// Pasamos las opciones al frontend desde PHP
window.CABEZADAS_OPCIONES = <?= json_encode([
'WHI' => lang('Presupuestos.blanca'),
'GRE' => lang('Presupuestos.verde'),
'BLUE' => lang('Presupuestos.azul'),
'REDYEL' => lang('Presupuestos.rojaAmarilla'),
]) ?>;
</script>
<?= $this->endSection() ?>

View File

@ -222,46 +222,39 @@
</div>
<?php if ($tipo_impresion_id == 1 || $tipo_impresion_id == 3): ?>
<div class="col-md-12 col-lg-2 px-4">
</div>
<div class="col-md-12 col-lg-2 px-4">
</div>
<div class="col-md-12 col-lg-2 px-4">
<label id="label_compLomoRedondo" for="compLomoRedondo" class="form-label">
<?= lang('Presupuestos.lomoRedondo') ?>*
</label>
<select id="compLomoRedondo" name="lomo_redondo" service-id="<?= $serviciosAutomaticos['lomo_redondo'] ?>"
class="form-control select2bs2 comp_cubierta_items" style="width: 100%;">
<option value="0">
<p>
<?= lang('Presupuestos.no') ?>
</p>
</option>
<option value="1">
<p>
<?= lang('Presupuestos.si') ?>
</p>
</option>
</select>
</div>
<div class="col-md-12 col-lg-2 px-4">
<label for="cabezada" class="form-label">
<?= lang('Presupuestos.cabezada') ?>
</label>
<select class="form-select select2bs2" id="cabezada" name="cabezada">
<option value="WHI">
<?= lang('Presupuestos.blanca') ?>
</option>
<option value="GRE">
<?= lang('Presupuestos.verde') ?>
</option>
<option value="BLUE">
<?= lang('Presupuestos.azul') ?>
</option>
<option value="REDYEL">
<?= lang('Presupuestos.rojaAmarilla') ?>
</option>
</select>
</div>
<div class="col-md-12 col-lg-2 px-4">
<label id="label_compLomoRedondo" for="compLomoRedondo" class="form-label">
<?= lang('Presupuestos.lomoRedondo') ?>*
</label>
<select id="compLomoRedondo" name="lomo_redondo" service-id="<?= $serviciosAutomaticos['lomo_redondo'] ?>"
class="form-control select2bs2 comp_cubierta_items" style="width: 100%;">
<option value="0">
<p>
<?= lang('Presupuestos.no') ?>
</p>
</option>
<option value="1">
<p>
<?= lang('Presupuestos.si') ?>
</p>
</option>
</select>
</div>
<div class="col-md-12 col-lg-2 px-4">
<label for="cabezada" class="form-label">
<?= lang('Presupuestos.cabezada') ?>
</label>
<select class="form-select" name="cabezada" id="cabezada">
<?php foreach ($cabezadas as $key => $langKey): ?>
<option value="<?= esc($key) ?>">
<?= lang($langKey) ?>
</option>
<?php endforeach; ?>
</select>
</div>
<?php endif; ?>
<div>
<hr class="my-1">
@ -269,83 +262,83 @@
</div>
<?php if ($tipo_impresion_id != 5 && $tipo_impresion_id != 6 && $tipo_impresion_id != 7 && $tipo_impresion_id != 8 && $tipo_impresion_id != 21): ?>
<div class="row">
<div class="col-md-12 col-lg-2 px-4">
<p>
<?= lang('PapelImpresion.sobrecubierta') ?>
</p>
<div class="row">
<div class="col-md-12 col-lg-2 px-4">
<p>
<?= lang('PapelImpresion.sobrecubierta') ?>
</p>
</div>
<div class="col-md-12 col-lg-2 px-4">
<select id="compSobrecubierta" name="comp_sobrecubierta"
class="form-control select2bs2 comp_sobrecubierta_items" style="width: 100%;">
<option value="0">
<?= lang('Presupuestos.no') ?>
</option>
<option value="1">
<?= lang('Presupuestos.si') ?>
</option>
</select>
</div>
<div class="col-md-12 col-lg-6 px-4">
<select disabled id="compPapelSobrecubierta" name="comp_papel_sobrecubierta"
class="form-control select2bs2 comp_sobrecubierta_items" style="width: 100%;">
</select>
</div>
<div class="col-md-12 col-lg-2 px-4">
<select disabled id="compGramajeSobrecubierta" name="comp_gramaje_sobrecubierta"
class="form-control select2bs2 comp_sobrecubierta_items" style="width: 100%;">
</select>
</div>
<div>
<hr class="my-1">
</div>
</div>
<div class="col-md-12 col-lg-2 px-4">
<select id="compSobrecubierta" name="comp_sobrecubierta"
class="form-control select2bs2 comp_sobrecubierta_items" style="width: 100%;">
<option value="0">
<?= lang('Presupuestos.no') ?>
</option>
<option value="1">
<?= lang('Presupuestos.si') ?>
</option>
</select>
</div>
<div class="col-md-12 col-lg-6 px-4">
<select disabled id="compPapelSobrecubierta" name="comp_papel_sobrecubierta"
class="form-control select2bs2 comp_sobrecubierta_items" style="width: 100%;">
</select>
</div>
<div class="col-md-12 col-lg-2 px-4">
<select disabled id="compGramajeSobrecubierta" name="comp_gramaje_sobrecubierta"
class="form-control select2bs2 comp_sobrecubierta_items" style="width: 100%;">
</select>
</div>
<div>
<hr class="my-1">
</div>
</div>
<?php endif; ?>
<?php if ($tipo_impresion_id == 1 || $tipo_impresion_id == 3 || $tipo_impresion_id == 5 || $tipo_impresion_id == 7): ?>
<div class="row">
<div class="col-md-12 col-lg-2 px-4">
<p>
<?= lang('PapelImpresion.guardas') ?>
</p>
</div>
<div class="col-md-12 col-lg-2 px-4">
<select id="compCarasGuardas" name="comp_paginas_guardas"
class="form-control select2bs2 comp_guardas_items" style="width: 100%;">
<option value="0">
<p>
<?= lang('Presupuestos.sinImpresion') ?>
</p>
</option>
<option value="4">
<p>
<?= lang('Presupuestos.unaCara') ?>
</p>
</option>
<option value="8">
<?php if ($tipo_impresion_id != 5 && $tipo_impresion_id != 6 && $tipo_impresion_id != 7 && $tipo_impresion_id != 8): ?>
<p>
<?= lang('Presupuestos.dosCaras') ?>
</p>
<?php endif ?>
</option>
</select>
</div>
<div class="col-md-12 col-lg-6 px-4">
<select id="compPapelGuardas" name="comp_papel_guardas"
class="form-control select2bs2 comp_guardas_items" style="width: 100%;">
</select>
</div>
<div class="col-md-12 col-lg-2 px-4">
<select id="compGramajeGuardas" name="comp_gramaje_guardas"
class="form-control select2bs2 comp_guardas_items" style="width: 100%;">
</select>
</div>
<div class="row">
<div class="col-md-12 col-lg-2 px-4">
<p>
<?= lang('PapelImpresion.guardas') ?>
</p>
</div>
<div class="col-md-12 col-lg-2 px-4">
<select id="compCarasGuardas" name="comp_paginas_guardas"
class="form-control select2bs2 comp_guardas_items" style="width: 100%;">
<option value="0">
<p>
<?= lang('Presupuestos.sinImpresion') ?>
</p>
</option>
<option value="4">
<p>
<?= lang('Presupuestos.unaCara') ?>
</p>
</option>
<option value="8">
<?php if ($tipo_impresion_id != 5 && $tipo_impresion_id != 6 && $tipo_impresion_id != 7 && $tipo_impresion_id != 8): ?>
<p>
<?= lang('Presupuestos.dosCaras') ?>
</p>
<?php endif ?>
</option>
</select>
</div>
<div class="col-md-12 col-lg-6 px-4">
<select id="compPapelGuardas" name="comp_papel_guardas"
class="form-control select2bs2 comp_guardas_items" style="width: 100%;">
</select>
</div>
<div class="col-md-12 col-lg-2 px-4">
<select id="compGramajeGuardas" name="comp_gramaje_guardas"
class="form-control select2bs2 comp_guardas_items" style="width: 100%;">
</select>
</div>
<div>
<hr class="my-1">
<div>
<hr class="my-1">
</div>
</div>
</div>
<?php endif; ?>
<div class="row">
@ -733,102 +726,102 @@
<!----------------------------------------------------------------------------->
<?php if ($tipo_impresion_id == 1 || $tipo_impresion_id == 3 || $tipo_impresion_id == 5 || $tipo_impresion_id == 7): ?>
<div class="accordion mt-3" id="accordionCompGuardas">
<div class="card accordion-item active">
<h2 class="accordion-header" id="headingOne">
<button id="accordion-button-int-guardas" type="button" class="accordion-button"
data-bs-toggle="collapse" data-bs-target="#accordionCompGuardasTip"
aria-expanded="false" aria-controls="accordionCompGuardasTip">
<h6 id="title_guardas">
<?= lang("Presupuestos.Guardas") ?>
</h6>
</button>
</h2>
<div class="accordion mt-3" id="accordionCompGuardas">
<div class="card accordion-item active">
<h2 class="accordion-header" id="headingOne">
<button id="accordion-button-int-guardas" type="button" class="accordion-button"
data-bs-toggle="collapse" data-bs-target="#accordionCompGuardasTip"
aria-expanded="false" aria-controls="accordionCompGuardasTip">
<h6 id="title_guardas">
<?= lang("Presupuestos.Guardas") ?>
</h6>
</button>
</h2>
<div id="accordionCompGuardasTip" class="accordion-collapse collapse"
data-bs-parent="#accordionCompGuardasTip">
<div class="accordion-body">
<div id="accordionCompGuardasTip" class="accordion-collapse collapse"
data-bs-parent="#accordionCompGuardasTip">
<div class="accordion-body">
<table id="tableCompGuardas" class="comparator-table table dt-responsive dataTable"
style="width: 100%;">
<thead>
<tr>
<th style="padding-right: 0.75em;">
<?= lang('Presupuestos.tipo') ?>
</th>
<th style="padding-right: 0.75em;">
<?= lang('Presupuestos.paginas') ?>
</th>
<th style="padding-right: 0.75em;">
<?= lang('Presupuestos.papel') ?>
</th>
<th style="padding-right: 0.75em;">
<?= lang('Presupuestos.gramaje') ?>
</th>
<th style="padding-right: 0.75em;">
<?= lang('Presupuestos.marca') ?>
</th>
<th style="padding-right: 0.75em;">
<?= lang('Presupuestos.maquina') ?>
</th>
<th style="padding-right: 0.75em;">
<?= lang('Presupuestos.numeroPliegos') ?>
</th>
<th style="padding-right: 0.75em; max-width:80px">
<?= lang('Presupuestos.pliegosPedido') ?>
</th>
<th style="padding-right: 0.75em; max-width:80px">
<?= lang('Presupuestos.precioPliego') ?>
</th>
<th style="padding-right: 0.75em;">
<?= lang('Presupuestos.libro') ?>
</th>
<th style="padding-right: 0.75em; max-width:80px">
<?= lang('Presupuestos.totalPapelPedido') ?>
</th>
<th style="padding-right: 0.75em;">
<?= lang('Presupuestos.lomo') ?>
</th>
<th style="padding-right: 0.75em;">
<?= lang('Presupuestos.peso') ?>
</th>
<th style="padding-right: 0.75em; max-width:80px">
<?= lang('Presupuestos.horas') ?>
</th>
<th style="padding-right: 0.75em; max-width:80px">
<?= lang('Presupuestos.precioImpresion') ?>
</th>
<th style="padding-right: 0.75em;">
<?= lang('Presupuestos.total') ?>
</th>
</tr>
</thead>
<tbody>
</tbody>
<tfoot>
<tr>
<td class="dt-result dt-result-text" colspan="14">
<?= lang('Presupuestos.total') ?>
<?= lang("Presupuestos.Guardas") ?>:
</td>
<td id="total_comp_guardas" class="dt-result dt-result-value" colspan="2">
0.00 </td>
</tr>
</tfoot>
</table>
<table id="tableCompGuardas" class="comparator-table table dt-responsive dataTable"
style="width: 100%;">
<thead>
<tr>
<th style="padding-right: 0.75em;">
<?= lang('Presupuestos.tipo') ?>
</th>
<th style="padding-right: 0.75em;">
<?= lang('Presupuestos.paginas') ?>
</th>
<th style="padding-right: 0.75em;">
<?= lang('Presupuestos.papel') ?>
</th>
<th style="padding-right: 0.75em;">
<?= lang('Presupuestos.gramaje') ?>
</th>
<th style="padding-right: 0.75em;">
<?= lang('Presupuestos.marca') ?>
</th>
<th style="padding-right: 0.75em;">
<?= lang('Presupuestos.maquina') ?>
</th>
<th style="padding-right: 0.75em;">
<?= lang('Presupuestos.numeroPliegos') ?>
</th>
<th style="padding-right: 0.75em; max-width:80px">
<?= lang('Presupuestos.pliegosPedido') ?>
</th>
<th style="padding-right: 0.75em; max-width:80px">
<?= lang('Presupuestos.precioPliego') ?>
</th>
<th style="padding-right: 0.75em;">
<?= lang('Presupuestos.libro') ?>
</th>
<th style="padding-right: 0.75em; max-width:80px">
<?= lang('Presupuestos.totalPapelPedido') ?>
</th>
<th style="padding-right: 0.75em;">
<?= lang('Presupuestos.lomo') ?>
</th>
<th style="padding-right: 0.75em;">
<?= lang('Presupuestos.peso') ?>
</th>
<th style="padding-right: 0.75em; max-width:80px">
<?= lang('Presupuestos.horas') ?>
</th>
<th style="padding-right: 0.75em; max-width:80px">
<?= lang('Presupuestos.precioImpresion') ?>
</th>
<th style="padding-right: 0.75em;">
<?= lang('Presupuestos.total') ?>
</th>
</tr>
</thead>
<tbody>
</tbody>
<tfoot>
<tr>
<td class="dt-result dt-result-text" colspan="14">
<?= lang('Presupuestos.total') ?>
<?= lang("Presupuestos.Guardas") ?>:
</td>
<td id="total_comp_guardas" class="dt-result dt-result-value" colspan="2">
0.00 </td>
</tr>
</tfoot>
</table>
<div>
<button type="button" name="insertarGuardasBtn" id="insertarGuardasBtn"
class="btn btn-primary float-end me-sm-3 me-1 mb-3 insertarLinea d-none">
<?= lang('Presupuestos.insertarLinea') . ' ' . strtoupper(lang('Presupuestos.Guardas')) ?>
</button>
<div>
<button type="button" name="insertarGuardasBtn" id="insertarGuardasBtn"
class="btn btn-primary float-end me-sm-3 me-1 mb-3 insertarLinea d-none">
<?= lang('Presupuestos.insertarLinea') . ' ' . strtoupper(lang('Presupuestos.Guardas')) ?>
</button>
</div>
</div>
</div>
</div>
</div>
</div>
<?php endif; ?>
<div class="accordion mt-3" id="accordionCompFaja">

View File

@ -136,10 +136,11 @@
<?= lang('Presupuestos.cabezada') ?>
</label>
<select class="form-select select2bs2" id="cabezada" name="cabezada">
<option value="WHI"><?= lang('Presupuestos.blanca') ?></option>
<option value="GRE"><?= lang('Presupuestos.verde') ?></option>
<option value="BLUE"><?= lang('Presupuestos.azul') ?></option>
<option value="REDYEL"><?= lang('Presupuestos.rojaAmarilla') ?></option>
<?php foreach ($cabezadas as $key => $langKey): ?>
<option value="<?= esc($key) ?>">
<?= lang($langKey) ?>
</option>
<?php endforeach; ?>
</select>
</div>