mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
terminado
This commit is contained in:
@ -31,25 +31,25 @@
|
||||
<tfoot>
|
||||
<tr>
|
||||
<td colspan="8" style="text-align:right">Subtotal:</td>
|
||||
<td id="subtotal-sum"></td>
|
||||
<td class="autonumeric" id="subtotal-sum"></td>
|
||||
<td></td>
|
||||
<td></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="8" style="text-align:right">I.V.A.:</td>
|
||||
<td id="total-iva-sum"></td>
|
||||
<td class="autonumeric" id="total-iva-sum"></td>
|
||||
<td></td>
|
||||
<td></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="8" style="text-align:right">Total:</td>
|
||||
<td id="total-sum"></td>
|
||||
<td class="autonumeric" id="total-sum"></td>
|
||||
<td></td>
|
||||
<td></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td <?= ($facturaEntity->serie_id == 7 || $facturaEntity->serie_id == 9)? "style='display:none;'":"" ?> colspan="8" 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 class="autonumeric" <?= ($facturaEntity->serie_id == 7 || $facturaEntity->serie_id == 9)? "style='display:none;'":"" ?> id="pendiente-pago"></td>
|
||||
<td></td>
|
||||
<td></td>
|
||||
</tr>
|
||||
@ -122,7 +122,33 @@ const actionBtns = function(data) {
|
||||
<?php endif; ?>
|
||||
};
|
||||
|
||||
const autoNumericSubtotal = new AutoNumeric('#subtotal-sum', 0, {
|
||||
decimalPlaces: 2,
|
||||
digitGroupSeparator: ',',
|
||||
decimalCharacter: '.',
|
||||
unformatOnSubmit: true
|
||||
});
|
||||
|
||||
const autoNumericIVA = new AutoNumeric('#total-iva-sum', 0, {
|
||||
decimalPlaces: 2,
|
||||
digitGroupSeparator: ',',
|
||||
decimalCharacter: '.',
|
||||
unformatOnSubmit: true
|
||||
});
|
||||
|
||||
const autoNumericTotal = new AutoNumeric('#total-sum', 0, {
|
||||
decimalPlaces: 2,
|
||||
digitGroupSeparator: ',',
|
||||
decimalCharacter: '.',
|
||||
unformatOnSubmit: true
|
||||
});
|
||||
|
||||
const autoNumericPendientePago = new AutoNumeric('#pendiente-pago', 0, {
|
||||
decimalPlaces: 2,
|
||||
digitGroupSeparator: ',',
|
||||
decimalCharacter: '.',
|
||||
unformatOnSubmit: true
|
||||
});
|
||||
|
||||
var editor_lineas = new $.fn.dataTable.Editor( {
|
||||
ajax: {
|
||||
@ -174,56 +200,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 ) {
|
||||
|
||||
@ -297,7 +319,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 class="autonumeric" 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>
|
||||
`;
|
||||
|
||||
@ -384,6 +406,18 @@ var tableLineas = $('#tableOfLineasFactura').DataTable({
|
||||
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
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
},
|
||||
footerCallback: function (row, data, start, end, display) {
|
||||
const table = this.api();
|
||||
@ -394,21 +428,21 @@ var tableLineas = $('#tableOfLineasFactura').DataTable({
|
||||
const totalIVA = table.column(9).data().reduce((a, b) => intVal(a) + intVal(b), 0);
|
||||
const totalTotal = table.column(10).data().reduce((a, b) => intVal(a) + intVal(b), 0);
|
||||
|
||||
$('#subtotal-sum').html(totalSubtotal.toFixed(2));
|
||||
$('#total-iva-sum').html(totalIVA.toFixed(2));
|
||||
$('#total-sum').html(totalTotal.toFixed(2));
|
||||
autoNumericSubtotal.set(totalSubtotal);
|
||||
autoNumericIVA.set(totalIVA);
|
||||
autoNumericTotal.set(totalTotal);
|
||||
|
||||
<?php if($facturaEntity->estado == 'borrador') :?>
|
||||
var pendientePago = totalTotal;
|
||||
var total_pagos = 0;
|
||||
<?php else: ?>
|
||||
var total_pagos = parseFloat($('#totalCobrado-sum').html().replace(',', '.')) || 0;
|
||||
var total_pagos = autoNumericTotalCobrado.getNumber();
|
||||
var pendientePago = totalTotal - total_pagos;
|
||||
<?php endif; ?>
|
||||
|
||||
if (isNaN(pendientePago)) pendientePago = 0;
|
||||
|
||||
$('#pendiente-pago').html(pendientePago.toFixed(2));
|
||||
autoNumericPendientePago.set(pendientePago);
|
||||
|
||||
$.ajax({
|
||||
url: '<?= route_to('updateFacturaTotales', $facturaEntity->id) ?>',
|
||||
|
||||
@ -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,46 @@ 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,
|
||||
|
||||
});
|
||||
})
|
||||
})
|
||||
|
||||
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
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
@ -154,6 +185,19 @@ editor_pagos.on( 'postSubmit', function ( e, json, data, action ) {
|
||||
tablePagos.draw();
|
||||
});
|
||||
|
||||
const autoNumericTotalCobrado = new AutoNumeric('#totalCobrado-sum', 0, {
|
||||
decimalPlaces: 2,
|
||||
digitGroupSeparator: ',',
|
||||
decimalCharacter: '.',
|
||||
unformatOnSubmit: true
|
||||
});
|
||||
|
||||
const autoNumericPendienteCobro = new AutoNumeric('#pendienteCobro-sum', 0, {
|
||||
decimalPlaces: 2,
|
||||
digitGroupSeparator: ',',
|
||||
decimalCharacter: '.',
|
||||
unformatOnSubmit: true
|
||||
});
|
||||
|
||||
var tablePagos = $('#tableOfLineasPagos').DataTable({
|
||||
processing: true,
|
||||
@ -193,7 +237,7 @@ var tablePagos = $('#tableOfLineasPagos').DataTable({
|
||||
return data!='0000-00-00 00:00:00' ? moment(data).format('DD/MM/YYYY') : '';
|
||||
}
|
||||
},
|
||||
{data: "total"},
|
||||
{data: "total",render : (d) => `<span class="autonumeric">${d}</span>`},
|
||||
],
|
||||
order: [[1, "asc"]],
|
||||
dom: 't',
|
||||
@ -259,8 +303,8 @@ var tablePagos = $('#tableOfLineasPagos').DataTable({
|
||||
}, 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,63 +313,29 @@ 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(8)
|
||||
.data()
|
||||
.reduce(function (a, b) {
|
||||
return intVal(a) + intVal(b);
|
||||
}, 0);
|
||||
|
||||
var totalIVA = table
|
||||
.column(9)
|
||||
.data()
|
||||
.reduce(function (a, b) {
|
||||
return intVal(a) + intVal(b);
|
||||
}, 0);
|
||||
|
||||
var totalTotal = table
|
||||
.column(10)
|
||||
.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 pendientePago = autoNumericTotal.getNumber();
|
||||
var total_pagos = 0;
|
||||
<?php else: ?>
|
||||
var total_pagos = parseFloat($('#totalCobrado-sum').html()).toFixed(2);
|
||||
var pendientePago = totalTotal - total_pagos;
|
||||
var total_pagos = autoNumericTotalCobrado.getNumber();
|
||||
var pendientePago = autoNumericTotal.getNumber() - total_pagos;
|
||||
<?php endif; ?>
|
||||
// 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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user