trabajando en presupuestos servicios extra

This commit is contained in:
jaimejimenezortega
2024-04-07 21:32:38 +02:00
parent 8eb322aaae
commit 987da56f2a
14 changed files with 5777 additions and 5 deletions

View File

@ -1375,6 +1375,236 @@ async function get_servPreimpresion_tiradasAlternativas(){
}
/****************************************************************************************
* Seccion para los servicios extra
***************************************************************************************/
var tableServiciosExtra = new DataTable('#tableOfServiciosExtra',{
scrollX: true,
searching: false,
paging: false,
info: false,
ordering: false,
responsive: true,
select: false,
language: {
url: "/themes/vuexy/vendor/libs/datatables-sk/plugins/i18n/es-ES.json"
}
});
function init_servicio_extra(){
$('#add_servicio_extra_list').select2({
allowClear: false,
minimumResultsForSearch: -1,
placeholder: window.Presupuestos.servicioextraList
})
window.serviciosextraList.forEach((element) =>{
tableServiciosPreimpresion.row.add([
element.tarifa_extra_id,
element.nombre,
'<input class="update-totales-servicios" id="precio_servicioextra_' + element.tarifa_extra_id +'" value="' + parseFloat(element.precio).toFixed(2) + '"></input>',
'<span style="display: none;" class="update-totales" id="servicioextra_margen_' + element.tarifa_extra_id + '">' + parseFloat(element.margen).toFixed(2) + '</span>',
'<a href="javascript:void(0);"><i class="ti ti-trash ti-sm btn-delete-serv mx-2" data-id="' + element.tarifa_extra_id +'"></i></a>'
]).draw(false)
$('#precio_servicioextra_' + element.tarifa_extra_id).on('change', function(){
updatePresupuesto({
update_lineas: false,
update_servicios: false,
update_envios: false,
update_resumen: true,
update_tiradas_alternativas: true})
})
})
updatePresupuesto({
update_lineas: false,
update_servicios: false,
update_envios: false,
update_resumen: true,
update_tiradas_alternativas: true
})
check_serv_extra_error()
}
function check_serv_extra_error(){
var htmlString = '';
$('#tableOfServiciosExtra tr').each(function(){
if(parseFloat($(this).find('td:eq(2) input').val()) == '0'){
htmlString = `
<div class="alert alert-danger d-flex align-items-baseline" role="alert">
<span class="alert-icon alert-icon-lg text-primary me-2">
<i class="ti ti-ban ti-sm"></i>
</span>
<div class="d-flex flex-column ps-1">
<h5 class="alert-heading mb-2">` +
window.Presupuestos.errores.error_servicios_anadidos +
`</h5>
</div>
</div>`;
}
})
$('#serv-preimpresion-error').html(htmlString)
}
function get_tarifas_extra(tarifa_id = -1){
var datos = {
tarifa_extra_id : tarifa_id,
};
datos = Object.assign(datos, window.token_ajax)
$.ajax({
type: "POST",
url: window.routes_servicios.dataTableOfPresupuestoServiciosExtra,
data: datos,
success: function (data) {
data.values.forEach((row) => {
tableServiciosExtra.row.add([
row.tarifa_id,
row.tarifa_nombre,
'<input class="update-totales-servicios" id="precio_servicioextra_' + row.tarifa_id +'" value="' + parseFloat(row.precio).toFixed(2) + '"></input>',
'<span style="display: none;" class="update-totales" id="servicioextra_margen_' + row.tarifa_id + '">' + parseFloat(row.margen).toFixed(2) + '</span>',
'<a href="javascript:void(0);"><i class="ti ti-trash ti-sm btn-delete-serv mx-2" data-id="' + row.tarifa_id +'"></i></a>'
]).draw(false)
$('#precio_servicioextra_' + row.tarifa_id).on('change', function(){
updatePresupuesto({
update_lineas: false,
update_servicios: false,
update_envios: false,
update_resumen: true,
update_tiradas_alternativas: true})
})
});
if(data.values.lenght > 0){
updatePresupuesto({
update_lineas: false,
update_servicios: false,
update_envios: false,
update_resumen: true,
update_tiradas_alternativas: true
})
}
check_serv_extra_error()
yeniden(data[window.csrf_token]);
return true;
},
error: function(e){
return false;
}
})
return false;
}
$('#insertar_serv_extra').on('click', function(){
const tarifa_text = $('#add_servicio_extra_list').select2('data')[0].text.trim()
if( $('#add_servicio_extra_list').select2('data')[0].text.trim().length > 0){
if($('#tableOfServiciosExtra tr > td:contains(' + tarifa_text + ')').length == 0)
get_tarifas_extra($('#add_servicio_extra_list').select2('data')[0].id);
else{
popErrorAlert(window.Presupuestos.errores.error_servicios_duplicados, 'serv-extra-alert')
}
}
check_serv_extra_error()
})
function get_datos_serviciosextra(){
var datosServiciosExtra = []
if($("#tableOfServiciosExtra").DataTable().rows().count()>0){
$("#tableOfServiciosExtra tr").each(function (index,tr) {
var values = {}
$(this).find("td").each(function (index2) {
switch (index2) {
case 0:
values['tarifa_id'] = $(this).text()
break
case 2:
values['precio'] = $(this).children(":first").val()
break
case 3:
values['margen'] = $(this).text()
break
}
})
if(Object.keys(values).length>0)
datosServiciosExtra.push(values)
})
}
return datosServiciosExtra;
}
async function get_servExtra_tiradasAlternativas(){
const url = window.location.href;
const url_parts = url.split('/');
var id = -1;
if(url_parts[url_parts.length-2] == 'edit'){
id = url_parts[url_parts.length-1];
}
var serviciosExtra ={
coste: 0.0,
margen: 0.0,
}
var json_data = {
datos: get_datos_serviciosextra(),
POD: $('#POD').val()
}
if(json_data.datos.length>0){
json_data = Object.assign(json_data, window.token_ajax);
await fetch(window.location.origin + "/presupuestos/presupuestoserviciosextra/update/" + id , {
method: "POST",
body: JSON.stringify(json_data),
headers: {
"Content-type": "application/json; charset=UTF-8"
}
})
.then(response => response.json())
.then(data => {
//const values = await response.json();
yeniden(data[window.csrf_token]);
data.lines.forEach((line) => {
serviciosExtra.coste += parseFloat(line[0].precio);
serviciosExtra.margen += parseFloat(line[0].precio)*parseFloat(line[0].margen)/100.0;
});
});
}
return serviciosExtra;
}
/****************************************************************************************
* Seccion para "otros"
***************************************************************************************/
async function actualizar_servicios(update_preimpresion=false){
const domain = window.location.origin
@ -1425,6 +1655,11 @@ async function actualizar_servicios(update_preimpresion=false){
datos_json_preimpresion = Object.assign(datos_json_preimpresion, window.token_ajax);
var datos_json_serviciosextra = {
datos: get_datos_serviciosextra(),
}
datos_json_preimpresion = Object.assign(datos_json_preimpresion, window.token_ajax);
fetch(domain + "/presupuestos/presupuestoacabados/update/" + id , {
method: "POST",
body: JSON.stringify(datos_json_acabados),
@ -1507,6 +1742,26 @@ async function actualizar_servicios(update_preimpresion=false){
yeniden(data[window.csrf_token]);
})
}
}).then(function(){
if(update_preimpresion){
fetch(domain + "/presupuestos/presupuestoserviciosextra/update/" + id , {
method: "POST",
body: JSON.stringify(datos_json_serviciosextra),
headers: {
"Content-type": "application/json; charset=UTF-8"
}
})
.then(response => response.json())
.then(data => {
data.lines.forEach((line) => {
$('#precio_serviciosextra_' + line[0].tarifa_id).val(parseFloat(line[0].total).toFixed(2))
$('#serviciosextra_margen_' + line[0].tarifa_id).val(parseFloat(line[0].margen).toFixed(2))
});
check_serv_preimpresion_error();
yeniden(data[window.csrf_token]);
})
}
})
)
)
@ -1531,4 +1786,4 @@ function popAlert(message, alertClass, alertIcon, containerId = 'sk-alert'){
$('#' + containerId).fadeOut("slow");
}, 5000);
});
}
}

View File

@ -66,6 +66,18 @@
<?= lang("Presupuestos.servicioManipulado") ?>
</button>
</li>
<li class="nav-item">
<button
type="button"
class="nav-link"
role="tab"
data-bs-toggle="tab"
data-bs-target="#servicios-extra"
aria-controls="servicios-extra"
aria-selected="false">
<?= lang("Presupuestos.servicioExtra") ?>
</button>
</li>
</ul>
<div class="tab-content border border-container">
<div class="tab-pane fade show active" id="servicios-acabado" role="tabpanel">
@ -221,6 +233,42 @@
</div>
<div class="tab-pane fade" id="servicios-extra" role="tabpanel">
<div id="serv-extra-alert">
</div>
<div id="serv-extra-error">
</div>
<table id="tableOfServiciosExtra" class="table table-striped table-hover tiradas-alternativas update-resumen-presupuesto" style="width: 100%;">
<thead>
<tr>
<th><?= lang('Presupuestos.id') ?></th>
<th><?= lang('Tarifaextra.tarifaextra') ?></th>
<th><?= lang('Presupuestos.precio') ?></th>
<th></th>
<th class="text-nowrap"><?= lang('Basic.global.Action') ?></th>
</tr>
</thead>
<tbody>
</tbody>
</table>
<div class="row mb-3 px-4">
<div class="col-md-12 col-lg-4 py-4">
<select id="add_servicio_extra_list" class="select2bs2" style="width: 100%;">
<option></option>
<?php foreach ($serviciosExtra as $item) : ?>
<option value="<?= $item->value ?>" >
<?= $item->label ?>
</option>
<?php endforeach; ?>
</select>
</div>
<div class="col-md-12 col-lg-4 px-2 py-4">
<button id="insertar_serv_extra" type="button" class="btn btn-secondary waves-effect waves-light float-start tiradas-alternativas"><?= lang("Presupuestos.insertar")?></button>
</div>
</div>
</div>
</div>
</div>
</div> <!-- //.accordion-body -->
@ -243,12 +291,15 @@
window.serviciospreimpresionList = <?php echo json_encode($serviciosPreimpresionList); ?>;
window.serviciosextraList = <?php echo json_encode($serviciosExtraList); ?>;
window.routes_servicios = {
dataTableOfPresupuestoAcabados: "<?=route_to('dataTableOfPresupuestoAcabados') ?>",
dataTableOfPresupuestoPreimpresion: "<?=route_to('dataTableOfPresupuestoPreimpresiones') ?>",
dataTableOfPresupuestoEncuadernaciones: "<?=route_to('dataTableOfPresupuestoEncuadernaciones') ?>",
dataTableOfPresupuestoManipulados: "<?=route_to('dataTableOfPresupuestoManipulados') ?>",
menuItemsOfPresupuestoEncuadernaciones: '<?= route_to("menuItemsOfPresupuestoEncuadernaciones") ?>',
dataTableOfPresupuestoServiciosExtra: "<?=route_to('dataTableOfPresupuestoServiciosExtra') ?>",
}
init_servicio_acabado()
@ -258,5 +309,7 @@
init_servicio_manipulado()
init_servicio_preimpresion()
init_servicio_extra()
<?= $this->endSection() ?>

View File

@ -0,0 +1,93 @@
<div class="row">
<div class="col-md-12 col-lg-12 px-4">
<div class="mb-3">
<label for="nombre" class="form-label">
<?= lang('Tarifaextra.nombre') ?>*
</label>
<input
type="text"
id="nombre"
name="nombre"
required
maxLength="255"
class="form-control"
value="<?= old('nombre', $tarifaextraEntity->nombre) ?>"
>
</div><!--//.mb-3 -->
<div class="mb-3">
<label for="precio" class="form-label">
<?= lang('Tarifaextra.precio') ?>*
</label>
<input
type="number"
id="precio"
name="precio"
required
maxLength="31"
step="0.01"
class="form-control"
value="<?= old('precio', $tarifaextraEntity->precio) ?>"
>
</div><!--//.mb-3 -->
<div class="mb-3">
<label for="precio_min" class="form-label">
<?= lang('Tarifaextra.precioMin') ?>*
</label>
<input
type="text"
id="precio_min"
name="precio_min"
required
class="form-control"
value="<?= old('precio_min', $tarifaextraEntity->precio_min) ?>"
>
</div><!--//.mb-3 -->
<div class="mb-3">
<label for="importe_fijo" class="form-label">
<?= lang('Tarifaextra.importeFijo') ?>*
</label>
<input
type="text"
id="importe_fijo"
name="importe_fijo"
required
class="form-control"
value="<?= old('importe_fijo', $tarifaextraEntity->importe_fijo) ?>"
>
</div><!--//.mb-3 -->
<div class="mb-3">
<label for="margen" class="form-label">
<?= lang('Tarifaextra.margen') ?>*
</label>
<input
type="text"
id="margen"
name="margen"
required
class="form-control"
value="<?= old('margen', $tarifaextraEntity->margen) ?>"
>
</div><!--//.mb-3 -->
<div class="mb-3">
<div class="form-check form-check-inline">
<input type="checkbox"
id="mostrar_en_presupuesto"
name="mostrar_en_presupuesto"
value="1"
class="form-check-input"<?= $tarifaextraEntity->mostrar_en_presupuesto == true ? 'checked' : ''; ?>
>
<label for="mostrar_en_presupuesto" class="form-check-label">
<?= lang('Tarifaextra.mostrar_en_presupuesto') ?>
</label>
</div>
</div>
</div><!--//.col -->
</div><!-- //.row -->

View File

@ -0,0 +1,30 @@
<?= $this->include("themes/_commonPartialsBs/select2bs5") ?>
<?= $this->include("themes/_commonPartialsBs/sweetalert") ?>
<?= $this->extend('themes/backend/vuexy/main/defaultlayout') ?>
<?= $this->section("content") ?>
<div class="row">
<div class="col-12">
<div class="card card-info">
<div class="card-header">
<h3 class="card-title"><?= $boxTitle ?? $pageTitle ?></h3>
</div><!--//.card-header -->
<form id="tarifaextraForm" method="post" class="card-body" action="<?= $formAction ?>">
<?= csrf_field() ?>
<?= view("themes/_commonPartialsBs/_alertBoxes") ?>
<?= !empty($validation->getErrors()) ? $validation->listErrors("bootstrap_style") : "" ?>
<?= view("themes/backend/vuexy/form/tarifas/extra/_tarifaextraFormItems") ?>
<div class="pt-4">
<input
type="submit"
class="btn btn-primary float-start me-sm-3 me-1"
name="save"
value="<?= lang("Basic.global.Save") ?>"
/>
<?= anchor(route_to("tarifaextraList"), lang("Basic.global.Cancel"), ["class" => "btn btn-secondary"]) ?>
</div><!-- /.card-footer -->
</form>
</div><!-- //.card -->
</div><!--//.col -->
</div><!--//.row -->
<?= $this->endSection() ?>

View File

@ -0,0 +1,120 @@
<?=$this->include('themes/_commonPartialsBs/datatables') ?>
<?=$this->extend('themes/backend/vuexy/main/defaultlayout') ?>
<?=$this->section('content'); ?>
<div class="row">
<div class="col-md-12">
<div class="card card-info">
<div class="card-header">
<h3 class="card-title"><?=lang('Tarifaextra.tarifaextraList') ?></h3>
<?=anchor(route_to('newTarifaextra'), lang('Basic.global.addNew').' '.lang('Tarifaextra.tarifaextra'), ['class'=>'btn btn-primary float-end']); ?>
</div><!--//.card-header -->
<div class="card-body">
<?= view('themes/_commonPartialsBs/_alertBoxes'); ?>
<table id="tableOfTarifasextra" class="table table-striped table-hover using-exportable-data-table" style="width: 100%;">
<thead>
<tr>
<th><?= lang('Tarifaextra.nombre') ?></th>
<th><?= lang('Tarifaextra.precio') ?></th>
<th><?= lang('Tarifaextra.precioMin') ?></th>
<th><?= lang('Tarifaextra.importeFijo') ?></th>
<th><?= lang('Tarifaextra.margen') ?></th>
<th><?= lang('Tarifaextra.mostrar_en_presupuesto') ?></th>
<th class="text-nowrap"><?= lang('Basic.global.Action') ?></th>
</tr>
</thead>
<tbody>
<?php foreach ($tarifaextraList as $item ) : ?>
<tr>
<td class="align-middle">
<?= empty($item->nombre) || strlen($item->nombre) < 51 ? esc($item->nombre) : character_limiter(esc($item->nombre), 50) ?>
</td>
<td class="align-middle">
<?= esc($item->precio) ?>
</td>
<td class="align-middle">
<?= esc($item->precio_min) ?>
</td>
<td class="align-middle">
<?= esc($item->importe_fijo) ?>
</td>
<td class="align-middle">
<?= esc($item->margen) ?>
</td>
<td class="align-middle">
<?= esc($item->mostrar_en_presupuesto)==1?'<i class="ti ti-check"></i>':"" ?>
</td>
<td class="align-middle text-center text-nowrap">
<?=anchor(route_to('editTarifaextra', $item->id), "<i class='ti ti-pencil ti-sm mx-2'></i>", ['class'=>'text-body', 'data-id'=>$item->id,]); ?>
<?=anchor('#confirm2delete', "<i class='ti ti-trash ti-sm mx-2'></i>", ['class'=>'text-body', 'data-href'=>route_to('deleteTarifaextra', $item->id), 'data-bs-toggle'=>'modal', 'data-bs-target'=>'#confirm2delete']); ?>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div><!--//.card-body -->
<div class="card-footer">
</div><!--//.card-footer -->
</div><!--//.card -->
</div><!--//.col -->
</div><!--//.row -->
<?=$this->endSection() ?>
<?=$this->section('css') ?>
<link rel="stylesheet" href="<?= site_url("/themes/vuexy/vendor/libs/datatables-sk/plugins/buttons/buttons.bootstrap5.min.css") ?>">
<?=$this->endSection() ?>
<?= $this->section('additionalExternalJs') ?>
<script src="<?= site_url("/themes/vuexy/vendor/libs/datatables-sk/plugins/buttons/dataTables.buttons.min.js") ?>"></script>
<script src="<?= site_url("/themes/vuexy/vendor/libs/datatables-sk/plugins/buttons/buttons.bootstrap5.min.js") ?>"></script>
<script src="<?= site_url("/themes/vuexy/vendor/libs/datatables-sk/plugins/buttons/buttons.html5.min.js") ?>"></script>
<script src="<?= site_url("/themes/vuexy/vendor/libs/datatables-sk/plugins/buttons/buttons.print.min.js") ?>"></script>
<script src="<?= site_url("/themes/vuexy/vendor/libs/datatables-sk/plugins/jszip/jszip.min.js") ?>"></script>
<script src="<?= site_url("/themes/vuexy/vendor/libs/datatables-sk/plugins/pdfmake/pdfmake.min.js") ?>" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script src="<?= site_url("/themes/vuexy/vendor/libs/datatables-sk/plugins/pdfmake/vfs_fonts.js") ?>"></script>
<?=$this->endSection() ?>
<?=$this->section('additionalInlineJs') ?>
const lastColNr2 = $(".using-exportable-data-table").find("tr:first th").length - 1;
theTable = $('.using-exportable-data-table').DataTable({
"responsive": true,
"paging": true,
"lengthMenu": [ 5, 10, 25, 50, 75, 100, 250, 500, 1000, 2500 ],
"pageLength": 50,
"lengthChange": true,
"searching": true,
"ordering": true,
"info": true,
"dom": 'lfBrtip', // 'lfBrtip', // you can try different layout combinations by uncommenting one or the other
// "dom": '<"top"lf><"clear">rt<"bottom"ipB><"clear">', // remember to comment this line if you uncomment the above
"buttons": [
'copy', 'csv', 'excel', 'print', {
extend: 'pdfHtml5',
orientation: 'landscape',
pageSize: 'A4'
}
],
"autoWidth": true,
"scrollX": true,
"stateSave": true,
"language": {
url: "/themes/vuexy/vendor/libs/datatables-sk/plugins/i18n/es-ES.json"
},
"columnDefs": [
{
orderable: false,
searchable: false,
targets: [lastColNr2]
}
]
});
<?=$this->endSection() ?>