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>
|
<tfoot>
|
||||||
<tr>
|
<tr>
|
||||||
<td colspan="8" style="text-align:right">Subtotal:</td>
|
<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>
|
||||||
<td></td>
|
<td></td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td colspan="8" style="text-align:right">I.V.A.:</td>
|
<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>
|
||||||
<td></td>
|
<td></td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td colspan="8" style="text-align:right">Total:</td>
|
<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>
|
||||||
<td></td>
|
<td></td>
|
||||||
</tr>
|
</tr>
|
||||||
<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;'":"" ?> 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>
|
||||||
<td></td>
|
<td></td>
|
||||||
</tr>
|
</tr>
|
||||||
@ -122,7 +122,33 @@ const actionBtns = function(data) {
|
|||||||
<?php endif; ?>
|
<?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( {
|
var editor_lineas = new $.fn.dataTable.Editor( {
|
||||||
ajax: {
|
ajax: {
|
||||||
@ -174,56 +200,52 @@ var editor_lineas = new $.fn.dataTable.Editor( {
|
|||||||
|
|
||||||
var old_cantidad = 0;
|
var old_cantidad = 0;
|
||||||
editor_lineas.on('open', (event) => {
|
editor_lineas.on('open', (event) => {
|
||||||
$("input.autonumeric").each(function () {
|
$("input.autonumeric").each(function () {
|
||||||
let autoNumericInstance = AutoNumeric.getAutoNumericElement(this)
|
let autoNumericInstance = AutoNumeric.getAutoNumericElement(this)
|
||||||
if (autoNumericInstance) {
|
if (autoNumericInstance) {
|
||||||
autoNumericInstance.remove()
|
autoNumericInstance.remove()
|
||||||
|
|
||||||
}
|
}
|
||||||
new AutoNumeric(this, {
|
new AutoNumeric(this, {
|
||||||
decimalCharacter: ",",
|
decimalCharacter: ",",
|
||||||
digitGroupSeparator: ".",
|
digitGroupSeparator: ".",
|
||||||
allowDecimalPadding : 'floats',
|
allowDecimalPadding : 'floats',
|
||||||
decimalPlaces: 2,
|
decimalPlaces: 2,
|
||||||
unformatOnSubmit: true,
|
unformatOnSubmit: true,
|
||||||
});
|
});
|
||||||
})
|
|
||||||
})
|
})
|
||||||
editor_lineas.on('preSubmit', (e, d, type) => {
|
})
|
||||||
if (d.data) {
|
editor_lineas.on('preSubmit', (e, d, type) => {
|
||||||
Object.keys(d.data).forEach(function (key) {
|
if (d.data) {
|
||||||
// Find all elements with class .autonumeric
|
if ( type === 'create'){
|
||||||
$("input.autonumeric").each(function () {
|
d.data[0]['factura_id'] = <?= $facturaEntity->id ?>;
|
||||||
let autoNumericInstance = AutoNumeric.getAutoNumericElement(this)
|
d.data[0]['old_cantidad'] = null;
|
||||||
if (autoNumericInstance) {
|
}
|
||||||
// Get raw value and update the corresponding field
|
else if(type === 'edit' ) {
|
||||||
let rawValue = autoNumericInstance.getNumericString();
|
for (v in d.data){
|
||||||
d.data[key][this.name] = rawValue; // Ensure the correct name attribute is used
|
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 ) {
|
editor_lineas.on( 'preEdit', function ( e, json, data, id ) {
|
||||||
|
|
||||||
old_cantidad = data.cantidad;
|
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 ) {
|
editor_lineas.on( 'postSubmit', function ( e, json, data, action ) {
|
||||||
|
|
||||||
@ -297,7 +319,7 @@ var tableLineas = $('#tableOfLineasFactura').DataTable({
|
|||||||
<div class="row mt-2">
|
<div class="row mt-2">
|
||||||
<div style="margin-top: auto;" class="col-md-12 col-lg-2 px-4">
|
<div style="margin-top: auto;" class="col-md-12 col-lg-2 px-4">
|
||||||
<label for="total-aceptado_-${meta.row}">Total aceptado</label>
|
<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>
|
</div>
|
||||||
`;
|
`;
|
||||||
|
|
||||||
@ -384,6 +406,18 @@ var tableLineas = $('#tableOfLineasFactura').DataTable({
|
|||||||
drawCallback: function() {
|
drawCallback: function() {
|
||||||
$(this.api().table().container()).find('table').css('width', '100%');
|
$(this.api().table().container()).find('table').css('width', '100%');
|
||||||
this.api().columns.adjust();
|
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) {
|
footerCallback: function (row, data, start, end, display) {
|
||||||
const table = this.api();
|
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 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);
|
const totalTotal = table.column(10).data().reduce((a, b) => intVal(a) + intVal(b), 0);
|
||||||
|
|
||||||
$('#subtotal-sum').html(totalSubtotal.toFixed(2));
|
autoNumericSubtotal.set(totalSubtotal);
|
||||||
$('#total-iva-sum').html(totalIVA.toFixed(2));
|
autoNumericIVA.set(totalIVA);
|
||||||
$('#total-sum').html(totalTotal.toFixed(2));
|
autoNumericTotal.set(totalTotal);
|
||||||
|
|
||||||
<?php if($facturaEntity->estado == 'borrador') :?>
|
<?php if($facturaEntity->estado == 'borrador') :?>
|
||||||
var pendientePago = totalTotal;
|
var pendientePago = totalTotal;
|
||||||
var total_pagos = 0;
|
var total_pagos = 0;
|
||||||
<?php else: ?>
|
<?php else: ?>
|
||||||
var total_pagos = parseFloat($('#totalCobrado-sum').html().replace(',', '.')) || 0;
|
var total_pagos = autoNumericTotalCobrado.getNumber();
|
||||||
var pendientePago = totalTotal - total_pagos;
|
var pendientePago = totalTotal - total_pagos;
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
|
|
||||||
if (isNaN(pendientePago)) pendientePago = 0;
|
if (isNaN(pendientePago)) pendientePago = 0;
|
||||||
|
|
||||||
$('#pendiente-pago').html(pendientePago.toFixed(2));
|
autoNumericPendientePago.set(pendientePago);
|
||||||
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: '<?= route_to('updateFacturaTotales', $facturaEntity->id) ?>',
|
url: '<?= route_to('updateFacturaTotales', $facturaEntity->id) ?>',
|
||||||
|
|||||||
@ -73,7 +73,7 @@ const actionBtns_pagos = function(data) {
|
|||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
}
|
}
|
||||||
|
|
||||||
var editor_pagos = new $.fn.dataTable.Editor( {
|
const editor_pagos = new $.fn.dataTable.Editor( {
|
||||||
ajax: {
|
ajax: {
|
||||||
url: "<?= route_to('editorOfPagosFacturas') ?>",
|
url: "<?= route_to('editorOfPagosFacturas') ?>",
|
||||||
headers: {
|
headers: {
|
||||||
@ -99,8 +99,10 @@ var editor_pagos = new $.fn.dataTable.Editor( {
|
|||||||
{
|
{
|
||||||
name: "total",
|
name: "total",
|
||||||
attr: {
|
attr: {
|
||||||
style: "min-width: 65px;"
|
style: "min-width: 65px;",
|
||||||
}
|
class :"autonumeric",
|
||||||
|
name: 'total'
|
||||||
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "fecha_pago_at",
|
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 ) {
|
editor_pagos.on( 'preSubmit', function ( e, d, type ) {
|
||||||
|
|
||||||
if ( type === 'create'){
|
if (d.data) {
|
||||||
d.data[0]['factura_id'] = <?= $facturaEntity->id ?>;
|
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 ?>;
|
|
||||||
}
|
}
|
||||||
|
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();
|
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({
|
var tablePagos = $('#tableOfLineasPagos').DataTable({
|
||||||
processing: true,
|
processing: true,
|
||||||
@ -193,7 +237,7 @@ var tablePagos = $('#tableOfLineasPagos').DataTable({
|
|||||||
return data!='0000-00-00 00:00:00' ? moment(data).format('DD/MM/YYYY') : '';
|
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"]],
|
order: [[1, "asc"]],
|
||||||
dom: 't',
|
dom: 't',
|
||||||
@ -259,8 +303,8 @@ var tablePagos = $('#tableOfLineasPagos').DataTable({
|
|||||||
}, 0);
|
}, 0);
|
||||||
|
|
||||||
// Update footer
|
// Update footer
|
||||||
$('#totalCobrado-sum').html(totalPagos.toFixed(2));
|
autoNumericTotalCobrado.set(totalPagos);
|
||||||
$('#pendienteCobro-sum').html(totalPendiente.toFixed(2));
|
autoNumericPendienteCobro.set(totalPendiente);
|
||||||
|
|
||||||
// call footerCallback of the other table
|
// call footerCallback of the other table
|
||||||
if (typeof tableLineas !== 'undefined') {
|
if (typeof tableLineas !== 'undefined') {
|
||||||
@ -269,63 +313,29 @@ var tablePagos = $('#tableOfLineasPagos').DataTable({
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
function updateFooterLineas(table){
|
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
|
// Assuming pendiente de pago is totalTotal - totalIVA for this example
|
||||||
<?php if($facturaEntity->estado == 'borrador') :?>
|
<?php if($facturaEntity->estado == 'borrador') :?>
|
||||||
var pendientePago = totalTotal ;
|
var pendientePago = autoNumericTotal.getNumber();
|
||||||
var total_pagos = 0;
|
var total_pagos = 0;
|
||||||
<?php else: ?>
|
<?php else: ?>
|
||||||
var total_pagos = parseFloat($('#totalCobrado-sum').html()).toFixed(2);
|
var total_pagos = autoNumericTotalCobrado.getNumber();
|
||||||
var pendientePago = totalTotal - total_pagos;
|
var pendientePago = autoNumericTotal.getNumber() - total_pagos;
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
// Se comprueba si pendientePago es un numero o NAN
|
// Se comprueba si pendientePago es un numero o NAN
|
||||||
if(isNaN(pendientePago)){
|
if(isNaN(pendientePago)){
|
||||||
pendientePago = 0;
|
pendientePago = 0;
|
||||||
}
|
}
|
||||||
$('#pendiente-pago').html(pendientePago.toFixed(2));
|
autoNumericPendientePago.set(pendientePago);
|
||||||
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: '<?= route_to('updateFacturaTotales', $facturaEntity->id) ?>',
|
url: '<?= route_to('updateFacturaTotales', $facturaEntity->id) ?>',
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
data: {
|
data: {
|
||||||
base: totalSubtotal,
|
base: autoNumericSubtotal.getNumber(),
|
||||||
total: totalTotal,
|
total: autoNumericTotal.getNumber(),
|
||||||
total_pagos: total_pagos,
|
total_pagos: total_pagos,
|
||||||
pendiente: pendientePago
|
pendiente: pendientePago
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user