Merge branch 'main' into 'mod/autoroute'

terminado añadir usuarios y fechas a pedidos. añadido inaplazable. color en...

See merge request jjimenez/safekat!695
This commit is contained in:
Ignacio Martinez Navajas
2025-04-12 20:18:05 +00:00
46 changed files with 965 additions and 1134 deletions

View File

@ -591,29 +591,31 @@
<button id="convert2template" type="button" class="btn btn-secondary waves-effect waves-light float-start"><?= lang("ClientePrecios.convertir2plantilla")?></button>
</div>
</div>
<div class="table-responsive">
<table id="tableOfPrecios" class="table table-striped table-hover" style="width: 100%;">
<thead>
<tr>
<th>ID</th>
<th><?= lang('ClientePrecios.tipo') ?></th>
<th><?= lang('ClientePrecios.tipo_maquina') ?></th>
<th><?= lang('ClientePrecios.tipo_impresion') ?></th>
<th><?= lang('ClientePrecios.tiempo_min') ?></th>
<th><?= lang('ClientePrecios.tiempo_max') ?></th>
<th class="noFilter"><?= lang('ClientePrecios.precio_hora') ?></th>
<th class="noFilter"><?= lang('ClientePrecios.margen') ?></th>
<th class="noFilter"><?= lang('ClientePrecios.total_precio_hora') ?></th>
<th class="noFilter"><?= lang('ClientePrecios.user_updated_id') ?></th>
<th class="noFilter"><?= lang('ClientePrecios.updated_at') ?></th>
<th class="noFilter noVis">plantilla_id</th>
<th class="text-nowrap noFilter noVis" style="min-width:100px"><?= lang('Basic.global.Action') ?></th>
</tr>
</thead>
<tbody>
</tbody>
</table>
<table id="tableOfPrecios" class="table table-striped table-hover" style="width: 100%;">
<thead>
<tr>
<th>ID</th>
<th><?= lang('ClientePrecios.tipo') ?></th>
<th><?= lang('ClientePrecios.tipo_maquina') ?></th>
<th><?= lang('ClientePrecios.tipo_impresion') ?></th>
<th><?= lang('ClientePrecios.tiempo_min') ?></th>
<th><?= lang('ClientePrecios.tiempo_max') ?></th>
<th class="noFilter"><?= lang('ClientePrecios.precio_hora') ?></th>
<th class="noFilter"><?= lang('ClientePrecios.margen') ?></th>
<th class="noFilter"><?= lang('ClientePrecios.total_precio_hora') ?></th>
<th class="noFilter"><?= lang('ClientePrecios.user_updated_id') ?></th>
<th class="noFilter"><?= lang('ClientePrecios.updated_at') ?></th>
<th class="noFilter noVis">plantilla_id</th>
<th class="text-nowrap noFilter noVis" style="min-width:100px"><?= lang('Basic.global.Action') ?></th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
</div>
@ -637,10 +639,11 @@
<div class="tab-pane fade" id="domicilio-entrega" role="tabpanel">
<?= view("themes/vuexy/form/clientes/cliente/_clienteDireccionesForm") ?>
<table id="tableOfDireccionesEnvio" class="table dt-responsive dataTable" style="width: 100%;">
<thead>
<tr>
<th><?= lang('ClienteDirecciones.alias') ?></th>
<div class="table-responsive">
<table id="tableOfDireccionesEnvio" class="table dt-responsive dataTable" style="width: 100%;">
<thead>
<tr>
<th><?= lang('ClienteDirecciones.alias') ?></th>
<th><?= lang('ClienteDirecciones.att') ?></th>
<th><?= lang('ClienteDirecciones.email') ?></th>
<th><?= lang('ClienteDirecciones.direccion') ?></th>
@ -653,9 +656,10 @@
</tr>
</thead>
<tbody>
</tbody>
</table>
</tbody>
</table>
</div>
</div>
<div class="tab-pane fade" id="presupuestos" role="tabpanel">
@ -787,10 +791,7 @@ $(document).on('click', '.btn-remove', function(e) {
},{
"name": "deleted_at",
"type": "hidden"
},{
"name": "is_deleted",
"type": "hidden"
},
}
]
} );

View File

@ -13,7 +13,7 @@
</div><!--//.card-header -->
<form id="clienteForm" data-cliente="<?=$clienteEntity->id?>"
data-url="<?= auth()->user()->inGroup('cliente-admin') || auth()->user()->inGroup('cliente-editor') ?
'/presupuestos/presupuestocliente/edit/' : '/presupuestoadmin/edit//' ?>"
'/presupuestos/presupuestocliente/edit/' : '/presupuestoadmin/edit/' ?>"
method="post" class="card-body" action="<?= $formAction ?>">
<?= csrf_field() ?>
<div class="card-body">

View File

@ -121,6 +121,7 @@ $('#addNewPedidoImpresion').on('click', function(){
$('#pedidoImpresion').val(null).trigger('change');
// Se actualiza la tabla de lineas de factura
$('#tableOfLineasFactura').DataTable().clearPipeline().draw();
$('#tableOfLineasPagos').DataTable().clearPipeline().draw();
}
});
});

View File

@ -20,7 +20,6 @@
<th ></th>
<th style="width: 10%;"><?= lang('Facturas.unidades') ?></th>
<th ><?= lang('Facturas.concepto') ?></th>
<th style="width: 10%;"><?= lang('Facturas.precioUnidad') ?></th>
<th style="width: 10%;"><?= lang('Facturas.iva') ?></th>
<th style="width: 10%;"><?= lang('Facturas.subtotal') ?></th>
<th></th>
@ -31,26 +30,26 @@
</tbody>
<tfoot>
<tr>
<td colspan="9" style="text-align:right">Subtotal:</td>
<td id="subtotal-sum"></td>
<td colspan="8" style="text-align:right">Subtotal:</td>
<td class="autonumeric text-end" id="subtotal-sum"></td>
<td></td>
<td></td>
</tr>
<tr>
<td colspan="9" style="text-align:right">I.V.A.:</td>
<td id="total-iva-sum"></td>
<td colspan="8" style="text-align:right">I.V.A.:</td>
<td class="autonumeric text-end" id="total-iva-sum"></td>
<td></td>
<td></td>
</tr>
<tr>
<td colspan="9" style="text-align:right">Total:</td>
<td id="total-sum"></td>
<td colspan="8" style="text-align:right">Total:</td>
<td class="autonumeric text-end" id="total-sum"></td>
<td></td>
<td></td>
</tr>
<tr>
<td <?= ($facturaEntity->serie_id == 7 || $facturaEntity->serie_id == 9)? "style='display:none;'":"" ?> colspan="9" style="text-align:right">Pendiente de pago:</td>
<td <?= ($facturaEntity->serie_id == 7 || $facturaEntity->serie_id == 9)? "style='display:none;'":"" ?> id="pendiente-pago"></td>
<td <?= ($facturaEntity->serie_id == 7 || $facturaEntity->serie_id == 9)? "style='display:none;'":"" ?> colspan="8" style="text-align:right">Pendiente de pago:</td>
<td class="autonumeric text-end" <?= ($facturaEntity->serie_id == 7 || $facturaEntity->serie_id == 9)? "style='display:none;'":"" ?> id="pendiente-pago"></td>
<td></td>
<td></td>
</tr>
@ -79,55 +78,85 @@
<?=$this->section('additionalInlineJs') ?>
const actionBtns = function(data) {
// se comprueba si data es null
<?php if($facturaEntity->estado != 'borrador') :?>
if (data.pedido_id != null) {
return `
<div class="text-right py-0 align-middle">
<div class="row">
<button type="button" class="btn btn-sm btn-primary btn-view_pedido" data-id="${data.pedido_id}">Ver pedido</button>
</div>
</div>
`;
}
else
{
return ``;
}
<?php if ($facturaEntity->estado != 'borrador') : ?>
if (data.pedido_id != null) {
return `
<div class="text-right py-0 align-middle">
<div class="row">
<button type="button" class="btn btn-sm btn-primary btn-view_pedido" data-id="${data.pedido_id}">Ver pedido</button>
</div>
</div>
`;
} else {
return ``;
}
<?php else: ?>
if (data.pedido_id === null) {
return `
<td class="text-right py-0 align-middle">
<div class="row mb-2">
<div class="btn-group btn-group-sm">
<a href="javascript:void(0);"><i class="ti ti-trash ti-sm btn-delete mx-2" data-id="${data.id}"></i></a>
<span class="edit"><a href="javascript:void(0);"><i class="ti ti-pencil ti-sm btn-edit mx-2" data-id="${data.id}"></i></a></span>
<span class="cancel"></span>
if (data.pedido_id === null) {
return `
<div class="text-right py-0 align-middle">
<div class="row mb-2">
<div class="btn-group btn-group-sm">
<a href="javascript:void(0);"><i class="ti ti-trash ti-sm btn-delete mx-2" data-id="${data.id}"></i></a>
<span class="edit"><a href="javascript:void(0);"><i class="ti ti-pencil ti-sm btn-edit mx-2" data-id="${data.id}"></i></a></span>
<span class="cancel"></span>
</div>
</div>
</div>
</div>
</td>`;
}
else{
return `
<div class="text-right py-0 align-middle">
<div class="row mb-2 align-middle">
<div class="btn-group btn-group-sm">
<a href="javascript:void(0);"><i class="ti ti-trash ti-sm btn-delete mx-2" data-id="${data.id}"></i></a>
<span class="edit"><a href="javascript:void(0);"><i class="ti ti-pencil ti-sm btn-edit mx-2" data-id="${data.id}"></i></a></span>
<span class="cancel"></span>
`;
} else {
return `
<div class="text-right py-0 align-middle">
<div class="row mb-2 align-middle">
<div class="btn-group btn-group-sm">
<a href="javascript:void(0);"><i class="ti ti-trash ti-sm btn-delete mx-2" data-id="${data.id}"></i></a>
<span class="edit"><a href="javascript:void(0);"><i class="ti ti-pencil ti-sm btn-edit mx-2" data-id="${data.id}"></i></a></span>
<span class="cancel"></span>
</div>
</div>
<div class="row">
<button type="button" class="btn btn-sm btn-primary btn-view_pedido" data-id="${data.pedido_id}">Ver pedido</button>
</div>
</div>
</div>
<div class="row">
<button type="button" class="btn btn-sm btn-primary btn-view_pedido" data-id="${data.pedido_id}">Ver pedido</button>
</div>
</div>
`;
}
`;
}
<?php endif; ?>
};
const autoNumericSubtotal = new AutoNumeric('#subtotal-sum', 0, {
decimalPlaces: 2,
digitGroupSeparator: ',',
decimalCharacter: '.',
unformatOnSubmit: true,
decimalPlacesShownOnFocus: 2,
decimalPlacesShownOnBlur: 2,
});
const autoNumericIVA = new AutoNumeric('#total-iva-sum', 0, {
decimalPlaces: 2,
digitGroupSeparator: ',',
decimalCharacter: '.',
unformatOnSubmit: true,
decimalPlacesShownOnFocus: 2,
decimalPlacesShownOnBlur: 2,
});
const autoNumericTotal = new AutoNumeric('#total-sum', 0, {
decimalPlaces: 2,
digitGroupSeparator: ',',
decimalCharacter: '.',
unformatOnSubmit: true,
decimalPlacesShownOnFocus: 2,
decimalPlacesShownOnBlur: 2,
});
const autoNumericPendientePago = new AutoNumeric('#pendiente-pago', 0, {
decimalPlaces: 2,
digitGroupSeparator: ',',
decimalCharacter: '.',
unformatOnSubmit: true,
decimalPlacesShownOnFocus: 2,
decimalPlacesShownOnBlur: 2,
});
var editor_lineas = new $.fn.dataTable.Editor( {
ajax: {
@ -153,14 +182,6 @@ var editor_lineas = new $.fn.dataTable.Editor( {
rows: 5,
style: "height: 120px;"
}
}, {
name: "precio_unidad",
attr: {
type: "text",
name : "precio_unidad",
class :"autonumeric",
style: "min-width: 65px;"
}
}, {
name: "iva",
attr: {
@ -187,56 +208,52 @@ var editor_lineas = new $.fn.dataTable.Editor( {
var old_cantidad = 0;
editor_lineas.on('open', (event) => {
$("input.autonumeric").each(function () {
let autoNumericInstance = AutoNumeric.getAutoNumericElement(this)
if (autoNumericInstance) {
autoNumericInstance.remove()
$("input.autonumeric").each(function () {
let autoNumericInstance = AutoNumeric.getAutoNumericElement(this)
if (autoNumericInstance) {
autoNumericInstance.remove()
}
new AutoNumeric(this, {
decimalCharacter: ",",
digitGroupSeparator: ".",
allowDecimalPadding : 'floats',
decimalPlaces: 2,
unformatOnSubmit: true,
});
})
}
new AutoNumeric(this, {
decimalCharacter: ",",
digitGroupSeparator: ".",
allowDecimalPadding : 'floats',
decimalPlaces: 2,
unformatOnSubmit: true,
});
})
editor_lineas.on('preSubmit', (e, d, type) => {
if (d.data) {
Object.keys(d.data).forEach(function (key) {
// Find all elements with class .autonumeric
$("input.autonumeric").each(function () {
let autoNumericInstance = AutoNumeric.getAutoNumericElement(this)
if (autoNumericInstance) {
// Get raw value and update the corresponding field
let rawValue = autoNumericInstance.getNumericString();
d.data[key][this.name] = rawValue; // Ensure the correct name attribute is used
}
});
});
})
editor_lineas.on('preSubmit', (e, d, type) => {
if (d.data) {
if ( type === 'create'){
d.data[0]['factura_id'] = <?= $facturaEntity->id ?>;
d.data[0]['old_cantidad'] = null;
}
else if(type === 'edit' ) {
for (v in d.data){
d.data[v]['factura_id'] = <?= $facturaEntity->id ?>;
d.data[v]['old_cantidad'] = old_cantidad;
}
})
}
Object.keys(d.data).forEach(function (key) {
// Find all elements with class .autonumeric
$("input.autonumeric").each(function () {
let autoNumericInstance = AutoNumeric.getAutoNumericElement(this)
if (autoNumericInstance) {
// Get raw value and update the corresponding field
let rawValue = autoNumericInstance.getNumericString();
d.data[key][this.name] = rawValue; // Ensure the correct name attribute is used
}
});
});
}
})
editor_lineas.on( 'preEdit', function ( e, json, data, id ) {
old_cantidad = data.cantidad;
});
editor_lineas.on( 'preSubmit', function ( e, d, type ) {
if ( type === 'create'){
d.data[0]['factura_id'] = <?= $facturaEntity->id ?>;
d.data[0]['old_cantidad'] = null;
}
else if(type === 'edit' ) {
for (v in d.data){
d.data[v]['factura_id'] = <?= $facturaEntity->id ?>;
d.data[v]['old_cantidad'] = old_cantidad;
}
}
});
editor_lineas.on( 'postSubmit', function ( e, json, data, action ) {
@ -310,7 +327,7 @@ var tableLineas = $('#tableOfLineasFactura').DataTable({
<div class="row mt-2">
<div style="margin-top: auto;" class="col-md-12 col-lg-2 px-4">
<label for="total-aceptado_-${meta.row}">Total aceptado</label>
<input readonly style="max-width: 110px;" type="text" id="total-aceptado_${meta.row}" value="${row.total_aceptado}">
<input readonly class="autonumeric-datatable-lineas" style="max-width: 110px;" type="text" id="total-aceptado_${meta.row}" value="${row.total_aceptado}">
</div>
`;
@ -366,11 +383,10 @@ var tableLineas = $('#tableOfLineasFactura').DataTable({
}
}
},
{data: "precio_unidad",render : (d) => `<span class="autonumeric">${d}</span>`},
{data: "iva",render : (d) => `<span class="autonumeric">${d}</span>`},
{data: "base",render : (d) => `<span class="autonumeric">${d}</span>`},
{data: "total_iva",render : (d) => `<span class="autonumeric">${d}</span>`},
{data: "total",render : (d) => `<span class="autonumeric">${d}</span>`},
{data: "iva", className: "text-end", render : (d) => `<span class="autonumeric-facturas text-end">${d}</span>`},
{data: "base", className: "text-end", render : (d) => `<span class="autonumeric-facturas text-end">${d}</span>`},
{data: "total_iva", className: "text-end",render : (d) => `<span class="autonumeric-facturas text-end">${d}</span>`},
{data: "total", className: "text-end", render : (d) => `<span class="autonumeric-facturas text-end">${d}</span>`},
],
order: [[1, "asc"]],
dom: 't',
@ -391,94 +407,85 @@ var tableLineas = $('#tableOfLineasFactura').DataTable({
},
{
visible: false,
targets: [1, 2, 3, 4, 10, 11]
targets: [1, 2, 3, 4, 9, 10]
}
],
drawCallback: function() {
$(this.api().table().container()).find('table').css('width', '100%');
this.api().columns.adjust();
$('.autonumeric-datatable-lineas').each(function() {
if (!$(this).data('autoNumeric')) {
new AutoNumeric(this, {
decimalPlaces: 2,
digitGroupSeparator: '.',
decimalCharacter: ',',
unformatOnSubmit: true
});
}
});
$("span.autonumeric-facturas").each(function () {
let autoNumericInstance = AutoNumeric.getAutoNumericElement(this)
if(autoNumericInstance){
autoNumericInstance.remove()
}
new AutoNumeric(this, {
digitGroupSeparator: ".",
decimalCharacter: ",",
allowDecimalPadding : 'floats',
decimalPlaces: 2,
unformatOnSubmit: true,
decimalPlacesShownOnFocus: 2,
decimalPlacesShownOnBlur: 2,
allowDecimalPadding: true,
});
});
},
footerCallback: function (row, data, start, end, display) {
updateFooterLineas(this.api());
const table = this.api();
const totalSubtotal = table.column(8).data().reduce((a, b) => parseFloat(a) + parseFloat(b), 0);
const totalIVA = table.column(9).data().reduce((a, b) => parseFloat(a) + parseFloat(b), 0);
const totalTotal = table.column(10).data().reduce((a, b) => parseFloat(a) + parseFloat(b), 0);
autoNumericSubtotal.set(totalSubtotal);
autoNumericIVA.set(totalIVA);
autoNumericTotal.set(totalTotal);
var total_pagos = autoNumericTotalCobrado.getNumber();
var pendientePago = totalTotal - total_pagos;
if (isNaN(pendientePago)) pendientePago = 0;
autoNumericPendientePago.set(pendientePago);
$.ajax({
url: '<?= route_to('updateFacturaTotales', $facturaEntity->id) ?>',
method: 'POST',
data: {
base: totalSubtotal,
total: totalTotal,
total_pagos: total_pagos,
pendiente: pendientePago,
<?= csrf_token() ?? "token" ?> : <?= csrf_token() ?>v
}
}).done(function (data) {
if (data.estado_pago === 'pagada') {
$('#estado_pago_text').text('<?= lang('Facturas.pagada') ?>').css('color', 'green');
} else {
$('#estado_pago_text').text('<?= lang('Facturas.pendiente') ?>').css('color', 'red');
}
}).fail(function (jqXHR) {
popErrorAlert(jqXHR.responseJSON.messages.error);
});
}
});
function updateFooterLineas(table){
// Remove the formatting to get integer data for summation
var intVal = function (i) {
return typeof i === 'string' ?
i.replace(/[\$,]/g, '')*1 :
typeof i === 'number' ?
i : 0;
};
// Total over all pages
var totalSubtotal = table
.column(9)
.data()
.reduce(function (a, b) {
return intVal(a) + intVal(b);
}, 0);
var totalIVA = table
.column(10)
.data()
.reduce(function (a, b) {
return intVal(a) + intVal(b);
}, 0);
var totalTotal = table
.column(11)
.data()
.reduce(function (a, b) {
return intVal(a) + intVal(b);
}, 0);
// Update footer
$('#subtotal-sum').html(totalSubtotal.toFixed(2));
$('#total-iva-sum').html(totalIVA.toFixed(2));
$('#total-sum').html(totalTotal.toFixed(2));
// Assuming pendiente de pago is totalTotal - totalIVA for this example
<?php if($facturaEntity->estado == 'borrador') :?>
var pendientePago = totalTotal ;
var total_pagos = 0;
<?php else: ?>
var total_pagos = parseFloat($('#totalCobrado-sum').html()).toFixed(2);
var pendientePago = totalTotal - total_pagos;
<?php endif; ?>
if(isNaN(pendientePago)){
pendientePago = 0;
}
$('#pendiente-pago').html(pendientePago.toFixed(2));
$.ajax({
url: '<?= route_to('updateFacturaTotales', $facturaEntity->id) ?>',
method: 'POST',
data: {
base: totalSubtotal,
total: totalTotal,
total_pagos: total_pagos,
pendiente: pendientePago,
<?= csrf_token() ?? "token" ?> : <?= csrf_token() ?>v
}
}).done((data, textStatus, jqXHR) => {
if(data.estado_pago == 'pagada'){
$('#estado_pago_text').text('<?= lang('Facturas.pagada') ?>');
$('#estado_pago_text').css('color', 'green');
}
else{
$('#estado_pago_text').text('<?= lang('Facturas.pendiente') ?>');
$('#estado_pago_text').css('color', 'red');
}
}).fail((jqXHR, textStatus, errorThrown) => {
popErrorAlert(jqXHR.responseJSON.messages.error)
})
}
// Delete row
$(document).on('click', '.btn-delete', function(e) {
@ -510,6 +517,8 @@ function deleteConfirmedLinea(params){
<?= csrf_token() ?? "token" ?> : <?= csrf_token() ?>v
}
}).done((data, textStatus, jqXHR) => {
tablelineas.clearPipeline().footerCallback().draw();
$('#tableOfLineasPagos').DataTable().clearPipeline().footerCallback().draw();
}).fail((jqXHR, textStatus, errorThrown) => {
popErrorAlert(jqXHR.responseJSON.messages.error)
@ -577,7 +586,6 @@ $(document).on('click', '.btn-excedentes', function(e) {
pedido_id: pedido_id,
pedido_linea_impresion_id: pedido_linea_impresion_id,
pedido_linea_maquetacion_id: pedido_linea_maquetacion_id,
precio_unidad: row_data.precio_unidad,
descripcion: row_data.descripcion,
iva: row_data.iva,
descuento: row_data.descuento_tirada_flexible,

View File

@ -22,12 +22,12 @@
<tbody></tbody>
<tfoot>
<tr>
<td colspan="6" style="text-align:right">Total cobrado:</td>
<td><span id="totalCobrado-sum" class="autonumeric"></span></td>
<td colspan="6" class="text-end">Total cobrado:</td>
<td class="text-end"><span id="totalCobrado-sum" class="autonumeric text-end"></span></td>
</tr>
<tr>
<td colspan="6" style="text-align:right">Total pendiente:</td>
<td><span id="pendienteCobro-sum" class="autonumeric"></span></td>
<td colspan="6" class="text-end">Total pendiente:</td>
<td class="text-end"><span id="pendienteCobro-sum" class="autonumeric text-end"></span></td>
</tr>
</tfoot>
</table>
@ -73,7 +73,7 @@ const actionBtns_pagos = function(data) {
<?php endif; ?>
}
var editor_pagos = new $.fn.dataTable.Editor( {
const editor_pagos = new $.fn.dataTable.Editor( {
ajax: {
url: "<?= route_to('editorOfPagosFacturas') ?>",
headers: {
@ -99,8 +99,10 @@ var editor_pagos = new $.fn.dataTable.Editor( {
{
name: "total",
attr: {
style: "min-width: 65px;"
}
style: "min-width: 65px;",
class :"autonumeric",
name: 'total'
},
},
{
name: "fecha_pago_at",
@ -132,17 +134,48 @@ var editor_pagos = new $.fn.dataTable.Editor( {
]
});
editor_pagos.on('open',(event)=>{
$("input.autonumeric").each(function () {
let autoNumericInstance = AutoNumeric.getAutoNumericElement(this)
if(autoNumericInstance){
autoNumericInstance.remove()
}
new AutoNumeric(this, {
digitGroupSeparator: ".",
decimalCharacter: ",",
allowDecimalPadding : 'floats',
decimalPlaces: 2,
unformatOnSubmit: true,
decimalPlacesShownOnFocus: 2,
decimalPlacesShownOnBlur: 2,
});
})
})
editor_pagos.on( 'preSubmit', function ( e, d, type ) {
if ( type === 'create'){
d.data[0]['factura_id'] = <?= $facturaEntity->id ?>;
}
else if(type === 'edit' ) {
for (v in d.data){
d.data[v]['factura_id'] = <?= $facturaEntity->id ?>;
if (d.data) {
if ( type === 'create'){
d.data[0]['factura_id'] = <?= $facturaEntity->id ?>;
}
else if(type === 'edit' ) {
for (v in d.data){
d.data[v]['factura_id'] = <?= $facturaEntity->id ?>;
}
}
Object.keys(d.data).forEach(function (key) {
// Find all elements with class .autonumeric
$("input.autonumeric").each(function () {
let autoNumericInstance = AutoNumeric.getAutoNumericElement(this)
if (autoNumericInstance) {
// Get raw value and update the corresponding field
let rawValue = autoNumericInstance.getNumericString();
d.data[key][this.name] = rawValue; // Ensure the correct name attribute is used
}
});
});
}
});
@ -152,8 +185,26 @@ editor_pagos.on( 'postSubmit', function ( e, json, data, action ) {
yeniden(json.<?= csrf_token() ?>);
tablePagos.clearPipeline();
tablePagos.draw();
updateFooterLineas(tableLineas);
});
const autoNumericTotalCobrado = new AutoNumeric('#totalCobrado-sum', 0, {
decimalPlaces: 2,
digitGroupSeparator: ',',
decimalCharacter: '.',
unformatOnSubmit: true,
decimalPlacesShownOnFocus: 2,
decimalPlacesShownOnBlur: 2,
});
const autoNumericPendienteCobro = new AutoNumeric('#pendienteCobro-sum', 0, {
decimalPlaces: 2,
digitGroupSeparator: ',',
decimalCharacter: '.',
unformatOnSubmit: true,
decimalPlacesShownOnFocus: 2,
decimalPlacesShownOnBlur: 2,
});
var tablePagos = $('#tableOfLineasPagos').DataTable({
processing: true,
@ -193,7 +244,11 @@ var tablePagos = $('#tableOfLineasPagos').DataTable({
return data!='0000-00-00 00:00:00' ? moment(data).format('DD/MM/YYYY') : '';
}
},
{data: "total"},
{
data: "total",
className: "text-end",
render : (d) => `<span class="autonumeric-pagos text-end">${d}</span>`
},
],
order: [[1, "asc"]],
dom: 't',
@ -226,14 +281,27 @@ var tablePagos = $('#tableOfLineasPagos').DataTable({
},
],
drawCallback: function (settings) {
$("span.autonumeric-pagos").each(function () {
let autoNumericInstance = AutoNumeric.getAutoNumericElement(this)
if(autoNumericInstance){
autoNumericInstance.remove()
}
new AutoNumeric(this, {
digitGroupSeparator: ".",
decimalCharacter: ",",
allowDecimalPadding : 'floats',
decimalPlaces: 2,
unformatOnSubmit: true,
decimalPlacesShownOnFocus: 2,
decimalPlacesShownOnBlur: 2,
allowDecimalPadding: true,
});
});
},
footerCallback: function (row, data, start, end, display) {
var api = this.api();
var intVal = function (i) {
// Convertir a número o devolver 0 si no es válido
return typeof i === 'string' ? i.replace(/[\$,]/g, '')*1 : typeof i === 'number' ? i : 0;
};
var filas = [];
api.rows().every(function() {
var data = this.data();
@ -243,7 +311,7 @@ var tablePagos = $('#tableOfLineasPagos').DataTable({
});
var totalPagos = filas
.reduce(function(a, data) {
return a + intVal(data['total']); // Aquí asumimos que la columna 6 está en el índice 5
return parseFloat(a) + parseFloat(data['total']);
}, 0);
var filas = [];
@ -255,12 +323,12 @@ var tablePagos = $('#tableOfLineasPagos').DataTable({
});
var totalPendiente = filas
.reduce(function(a, data) {
return a + intVal(data['total']); // Aquí asumimos que la columna 6 está en el índice 5
return parseFloat(a) + parseFloat(data['total']);
}, 0);
// Update footer
$('#totalCobrado-sum').html(totalPagos.toFixed(2));
$('#pendienteCobro-sum').html(totalPendiente.toFixed(2));
autoNumericTotalCobrado.set(totalPagos);
autoNumericPendienteCobro.set(totalPendiente);
// call footerCallback of the other table
if (typeof tableLineas !== 'undefined') {
@ -269,71 +337,32 @@ var tablePagos = $('#tableOfLineasPagos').DataTable({
}
});
function updateFooterLineas(table){
// Remove the formatting to get integer data for summation
var intVal = function (i) {
return typeof i === 'string' ?
i.replace(/[\$,]/g, '')*1 :
typeof i === 'number' ?
i : 0;
};
// Total over all pages
var totalSubtotal = table
.column(9)
.data()
.reduce(function (a, b) {
return intVal(a) + intVal(b);
}, 0);
var totalIVA = table
.column(10)
.data()
.reduce(function (a, b) {
return intVal(a) + intVal(b);
}, 0);
var totalTotal = table
.column(11)
.data()
.reduce(function (a, b) {
return intVal(a) + intVal(b);
}, 0);
// Update footer
$('#subtotal-sum').html(totalSubtotal.toFixed(2));
$('#total-iva-sum').html(totalIVA.toFixed(2));
$('#total-sum').html(totalTotal.toFixed(2));
// Assuming pendiente de pago is totalTotal - totalIVA for this example
<?php if($facturaEntity->estado == 'borrador') :?>
var pendientePago = totalTotal ;
var total_pagos = 0;
<?php else: ?>
var total_pagos = parseFloat($('#totalCobrado-sum').html()).toFixed(2);
var pendientePago = totalTotal - total_pagos;
<?php endif; ?>
var total_pagos = autoNumericTotalCobrado.getNumber();
var pendientePago = autoNumericTotal.getNumber() - total_pagos;
// Se comprueba si pendientePago es un numero o NAN
if(isNaN(pendientePago)){
pendientePago = 0;
}
$('#pendiente-pago').html(pendientePago.toFixed(2));
autoNumericPendientePago.set(pendientePago);
$.ajax({
url: '<?= route_to('updateFacturaTotales', $facturaEntity->id) ?>',
method: 'POST',
data: {
base: totalSubtotal,
total: totalTotal,
base: autoNumericSubtotal.getNumber(),
total: autoNumericTotal.getNumber(),
total_pagos: total_pagos,
pendiente: pendientePago
}
}).done((data, textStatus, jqXHR) => {
if($('#pendiente-pago').html() == '0.00'){
if(autoNumericPendientePago.getNumber() == 0){
$('#addPagoRow').hide();
} else {
$('#validarFactura').show();
$('#addPagoRow').show();
}
if(data.estado_pago == 'pagada'){
$('#estado_pago_text').text('<?= lang('Facturas.pagada') ?>');

View File

@ -22,7 +22,7 @@
<?php endif; ?>
<?= view("themes/vuexy/form/facturas/_facturaLineasItems") ?>
<?php if($facturaEntity->estado !='borrador' && (strpos($facturaEntity->numero, "REC ") !== 0) ) : ?>
<?php if((strpos($facturaEntity->numero, "REC ") !== 0) ) : ?>
<?= view("themes/vuexy/form/facturas/_pagosFacturasItems") ?>
<?php endif; ?>
<?php if($facturaEntity->estado !='borrador' && (strpos($facturaEntity->numero, "REC ") === 0) ) : ?>
@ -38,6 +38,9 @@
name="validarFactura"
value="<?= lang("Facturas.validarFactura") ?>"
/>
<?php endif; ?>
<?php if($facturaEntity->showDeleteButton == true && $facturaEntity->estado !='validada') : ?>
<input type="button"
class="btn btn-danger float-start me-sm-3 me-1"
id="borrarFactura"

View File

@ -86,7 +86,7 @@
<label for="total_precio" class="form-label">
<?= lang('Pedidos.total_precio') ?>
</label>
<input readonly id="total_precio" name="total_precio" tabindex="1" maxLength="11" class="form-control" value="<?= old('total_precio', $pedidoEntity->total_precio) ?>" >
<input readonly id="total_precio" name="total_precio" tabindex="1" maxLength="11" class="form-control autonumeric" value="<?= old('total_precio', $pedidoEntity->total_precio) ?>" >
</div>
</div><!--//.mb-3 -->
@ -100,6 +100,7 @@
</div><!--//.mb-3 -->
</div>
</div> <!--//accordion-body -->
</div> <!--//accordionFechasTip-->
</div> <!--//card-->
@ -121,7 +122,8 @@
<label for="fecha_entrega_real" class="fecha-pedido form-label">
<?= lang('Pedidos.fecha_entrega_real') ?>
</label>
<input type="text" value="" id="fecha_entrega_real" name="fecha_entrega_real" tabindex="1" maxLength="11" class="form-control" value="<?= old('fecha_entrega_real', $pedidoEntity->fecha_entrega_real) ?>" >
<input type="text" value="" id="fecha_entrega_real" name="fecha_entrega_real" tabindex="1" maxLength="11" class="form-control inaplazable-date" value="<?= old('fecha_entrega_real', $pedidoEntity->fecha_entrega_real) ?>" >
<div id="fecha_entrega_real_change_user" class="form-text"><?= $pedidoEntity->fecha_entrega_real_change_user?></div>
</div>
</div>
<div class="col-md-12 col-lg-3 px-4">
@ -129,7 +131,8 @@
<label for="fecha_impresion" class="form-label">
<?= lang('Pedidos.fecha_impresion') ?>
</label>
<input type="text" id="fecha_impresion" name="fecha_impresion" tabindex="1" maxLength="11" class="fecha-pedido form-control" value="<?= old('fecha_impresion', $pedidoEntity->fecha_impresion) ?>" >
<input type="text" id="fecha_impresion" name="fecha_impresion" tabindex="1" maxLength="11" class="fecha-pedido form-control inaplazable-date" value="<?= old('fecha_impresion', $pedidoEntity->fecha_impresion) ?>" >
<div id="fecha_impresion_change_user" class="form-text"><?= $pedidoEntity->fecha_impresion_change_user?></div>
</div>
</div>
<div class="col-md-12 col-lg-3 px-4">
@ -137,7 +140,8 @@
<label for="fecha_encuadernado" class="form-label">
<?= lang('Pedidos.fecha_encuadernado') ?>
</label>
<input type="text" id="fecha_encuadernado" name="fecha_encuadernado" tabindex="1" maxLength="11" class="fecha-pedido form-control" value="<?= old('fecha_encuadernado', $pedidoEntity->fecha_encuadernado) ?>" >
<input type="text" id="fecha_encuadernado" name="fecha_encuadernado" tabindex="1" maxLength="11" class="fecha-pedido form-control inaplazable-date" value="<?= old('fecha_encuadernado', $pedidoEntity->fecha_encuadernado) ?>" >
<div id="fecha_encuadernado_change_user" class="form-text"><?= $pedidoEntity->fecha_encuadernado_change_user?></div>
</div>
</div>
<div class="col-md-12 col-lg-3 px-4">
@ -145,10 +149,25 @@
<label for="fecha_entrega_externo" class="form-label">
<?= lang('Pedidos.fecha_entrega_externo') ?>
</label>
<input type="text" id="fecha_entrega_externo" name="fecha_entrega_externo" tabindex="1" maxLength="11" class="fecha-pedido form-control" value="<?= old('fecha_entrega_externo', $pedidoEntity->fecha_entrega_externo) ?>" >
<input type="text" id="fecha_entrega_externo" name="fecha_entrega_externo" tabindex="1" maxLength="11" class="fecha-pedido form-control inaplazable-date" value="<?= old('fecha_entrega_externo', $pedidoEntity->fecha_entrega_externo) ?>" >
<div id="fecha_entrega_externo_change_user" class="form-text"><?= $pedidoEntity->fecha_entrega_externo_change_user?></div>
</div>
</div>
</div>
<div class="row">
<label class="switch switch-danger switch-lg mt-1">
<input type="checkbox" class="switch-input ot-preview" id="inaplazable" name="inaplazable" <?=$pedidoEntity->inaplazable?"checked":""?> />
<span class="switch-toggle-slider">
<span class="switch-on">
<i class="ti ti-alert-triangle"></i>
</span>
<span class="switch-off">
<i class="ti ti-x"></i>
</span>
</span>
<span class="switch-label fw-large">Inaplazable</span>
</label>
</div>
</div>
</div> <!--//accordionFechasTip-->
</div> <!--//card-->
@ -183,6 +202,24 @@
<?=$this->section('additionalInlineJs') ?>
document.getElementById('inaplazable').addEventListener('change', () => {
updateDate('inaplazable', $('#inaplazable').prop('checked') ? 1 : 0);
});
if(<?= $pedidoEntity->inaplazable?1:0 ?>){
$('.inaplazable-date').addClass('text-danger fw-bold');
}
const autonumericTotalPrecio = new AutoNumeric('#total_precio', {
decimalPlaces: 2,
digitGroupSeparator: '.',
decimalCharacter: ',',
allowDecimalPadding: true,
unformatOnSubmit: true,
});
$("#fecha_entrega_real").flatpickr({
defaultDate: <?= $pedidoEntity->fecha_entrega_real_text ? "'".$pedidoEntity->fecha_entrega_real_text."'" : 'null' ?>,
dateFormat: "d/m/Y",
@ -321,10 +358,21 @@ function updateDate(elementId, dateStr) {
data = {
<?= csrf_token() ?? "token" ?>: <?= csrf_token() ?>v,
};
var parts = dateStr.split('/');
var newFormat = parts[2] + '-' + parts[1] + '-' + parts[0]; // Asume dateStr en formato d/m/Y.
data[elementId] = newFormat;
if(elementId == 'inaplazable'){
data[elementId] = dateStr;
if(dateStr == 1){
$('.inaplazable-date').addClass('text-danger fw-bold');
}
else{
$('.inaplazable-date').removeClass('text-danger fw-bold');
}
}else{
var parts = dateStr.split('/');
var newFormat = parts[2] + '-' + parts[1] + '-' + parts[0]; // Asume dateStr en formato d/m/Y.
data[elementId] = newFormat;
}
var url = '<?= route_to('actualizarPedido', ':id') ?>';
url = url.replace(':id', id );
@ -336,11 +384,16 @@ function updateDate(elementId, dateStr) {
success: function(response){
if('error' in response){
if(response.error == 0){
for (const [key, value] of Object.entries(response)) {
if (key.endsWith('_change_user')) {
$("#" + key).html(value);
}
}
}
}
}
});
}
<?=$this->endSection() ?>

File diff suppressed because one or more lines are too long