casi terminado

This commit is contained in:
2024-07-17 14:51:47 +02:00
parent 99e9bf51a6
commit 4c33167764
5 changed files with 52 additions and 18 deletions

View File

@ -7,6 +7,7 @@ use App\Models\Collection;
use DataTables\Editor; use DataTables\Editor;
use DataTables\Editor\Field; use DataTables\Editor\Field;
use DataTables\Editor\Validate; use DataTables\Editor\Validate;
use DataTables\Editor\Format;
class FacturasPagos extends \App\Controllers\BaseResourceController class FacturasPagos extends \App\Controllers\BaseResourceController
{ {
@ -61,16 +62,13 @@ class FacturasPagos extends \App\Controllers\BaseResourceController
'message' => lang('Facturas.validation.requerido')) 'message' => lang('Facturas.validation.requerido'))
), ),
Field::inst( 'fecha_pago_at' ) Field::inst( 'fecha_pago_at' )
->set( function ($val, $data, $field) { ->validator( Validate::dateFormat( 'Y-m-d H:i:s' ) )
// Convierte la fecha de formato DD/MM/YYYY a YYYY-MM-DD ->getFormatter( Format::dateSqlToFormat( 'Y-m-d H:i:s' ) )
$date = DateTime::createFromFormat('d/m/Y', $val)->format('Y-m-d'); ->setFormatter( Format::dateFormatToSql( 'Y-m-d H:i:s' ) ),
return DateTime::createFromFormat('d/m/Y', $val)->format('Y-m-d');
}),
Field::inst( 'fecha_vencimiento_at' ) Field::inst( 'fecha_vencimiento_at' )
->set( function ($val, $data, $field) { ->validator( Validate::dateFormat( 'Y-m-d H:i:s' ) )
// Convierte la fecha de formato DD/MM/YYYY a YYYY-MM-DD ->getFormatter( Format::dateSqlToFormat( 'Y-m-d H:i:s' ) )
return DateTime::createFromFormat('d/m/Y', $val)->format('Y-m-d'); ->setFormatter( Format::dateFormatToSql( 'Y-m-d H:i:s' ) ),
}),
Field::inst( 'total' ) Field::inst( 'total' )
->validator('Validate::numeric', array( ->validator('Validate::numeric', array(
'message' => lang('Facturas.validation.numerico')) 'message' => lang('Facturas.validation.numerico'))

View File

@ -3,7 +3,7 @@ namespace App\Models\Configuracion;
class FormaPagoModel extends \App\Models\BaseModel class FormaPagoModel extends \App\Models\BaseModel
{ {
protected $table = "lg_formas_pago"; protected $table = "formas_pago";
/** /**
* Whether primary key uses auto increment. * Whether primary key uses auto increment.

View File

@ -72,7 +72,9 @@ class FacturaModel extends \App\Models\BaseModel {
"t1.id AS id, t1.numero AS numero, DATE_FORMAT(t1.fecha_factura_at, '%d/%m/%Y') AS fecha_factura_at, "t1.id AS id, t1.numero AS numero, DATE_FORMAT(t1.fecha_factura_at, '%d/%m/%Y') AS fecha_factura_at,
t2.nombre AS cliente, t1.base AS base, t1.total AS total, t1.pendiente AS pendiente, t2.nombre AS cliente, t1.base AS base, t1.total AS total, t1.pendiente AS pendiente,
t1.creditoAsegurado AS creditoAsegurado, t1.estado AS estado, t1.estado_pago AS estado_pago, t1.creditoAsegurado AS creditoAsegurado, t1.estado AS estado, t1.estado_pago AS estado_pago,
t4.nombre AS forma_pago, DATE_FORMAT(t3.fecha_vencimiento_at, '%d/%m/%Y') AS vencimiento" GROUP_CONCAT(DISTINCT t4.nombre ORDER BY t4.nombre ASC SEPARATOR ', ') AS forma_pago,
DATE_FORMAT(MIN(CASE WHEN t3.fecha_vencimiento_at != '0000-00-00 00:00:00' THEN t3.fecha_vencimiento_at ELSE NULL END), '%d/%m/%Y') AS vencimiento,
t2.vencimiento AS dias_vencimiento"
); );
$builder->join("clientes t2", "t2.id = t1.cliente_id", "left"); $builder->join("clientes t2", "t2.id = t1.cliente_id", "left");
@ -80,6 +82,7 @@ class FacturaModel extends \App\Models\BaseModel {
$builder->join("formas_pago t4", "t3.forma_pago_id = t4.id", "left"); $builder->join("formas_pago t4", "t3.forma_pago_id = t4.id", "left");
$builder->where("t1.deleted_at IS NULL"); $builder->where("t1.deleted_at IS NULL");
$builder->groupBy("t1.id"); // Agrupa por id de la factura
return empty($search) return empty($search)
? $builder ? $builder

View File

@ -28,7 +28,7 @@
</tfoot> </tfoot>
</table> </table>
<div class="row"> <div id="addPagoRow" class="row">
<div class="col-md-12 col-lg-2"> <div class="col-md-12 col-lg-2">
<button <button
type="button" type="button"
@ -50,6 +50,10 @@
<?=$this->section('additionalInlineJs') ?> <?=$this->section('additionalInlineJs') ?>
const formas_pago = <?= json_encode($facturaEntity->formas_pago) ?>; const formas_pago = <?= json_encode($facturaEntity->formas_pago) ?>;
var formaPagoLookup = {};
formas_pago.forEach(function(pago) {
formaPagoLookup[pago.value] = pago.label;
});
const actionBtns_pagos = function(data) { const actionBtns_pagos = function(data) {
return ` return `
@ -92,12 +96,21 @@ var editor_pagos = new $.fn.dataTable.Editor( {
{ {
name: "fecha_pago_at", name: "fecha_pago_at",
type: "datetime", type: "datetime",
format: "DD/MM/YYYY" def: function () {
return new Date().toISOString().split('T')[0]; // YYYY-MM-DD
},
wireFormat: 'YYYY-MM-DD HH:mm:ss',
displayFormat: 'DD/MM/YYYY',
}, },
{ {
name: "fecha_vencimiento_at", name: "fecha_vencimiento_at",
type: "datetime", type: "datetime",
format: "DD/MM/YYYY" def: () => new Date(),
def: function () {
return new Date().toISOString().split('T')[0]; // YYYY-MM-DD
},
wireFormat: 'YYYY-MM-DD HH:mm:ss',
displayFormat: 'DD/MM/YYYY',
}, },
{ {
name: "id", name: "id",
@ -146,7 +159,12 @@ var tablePagos = $('#tableOfLineasPagos').DataTable({
className: 'row-edit dt-center' className: 'row-edit dt-center'
}, },
{data: "id"}, {data: "id"},
{data: "forma_pago_id"}, {
data: "forma_pago_id",
render: function(data, type, row) {
return formaPagoLookup[data] || data;
}
},
{data: "notes"}, {data: "notes"},
{ {
data: "fecha_vencimiento_at", data: "fecha_vencimiento_at",
@ -183,7 +201,16 @@ var tablePagos = $('#tableOfLineasPagos').DataTable({
{ {
visible: false, visible: false,
targets: [1] targets: [1]
} },
{
width: '40%', // Ajusta el ancho para la columna de notas
targets: 3
},
{
width: '10%', // Ajusta el ancho para la columna de notas
targets: [4, 5, 6]
},
], ],
footerCallback: function (row, data, start, end, display) { footerCallback: function (row, data, start, end, display) {
var api = this.api(); var api = this.api();
@ -268,7 +295,11 @@ function updateFooterLineas(table){
pendiente: pendientePago pendiente: pendientePago
} }
}).done((data, textStatus, jqXHR) => { }).done((data, textStatus, jqXHR) => {
//console.log(data); if($('#pendiente-pago').html() == '0.00'){
$('#addPagoRow').hide();
} else {
$('#validarFactura').show();
}
}).fail((jqXHR, textStatus, errorThrown) => { }).fail((jqXHR, textStatus, errorThrown) => {
popErrorAlert(jqXHR.responseJSON.messages.error) popErrorAlert(jqXHR.responseJSON.messages.error)
}) })

View File

@ -27,6 +27,7 @@
<th><?= lang('Facturas.estadoPago') ?></th> <th><?= lang('Facturas.estadoPago') ?></th>
<th><?= lang('Facturas.formaPago') ?></th> <th><?= lang('Facturas.formaPago') ?></th>
<th><?= lang('Facturas.vencimiento') ?></th> <th><?= lang('Facturas.vencimiento') ?></th>
<th><?= lang('Facturas.dias') ?></th>
<th class="text-nowrap"><?= lang('Basic.global.Action') ?></th> <th class="text-nowrap"><?= lang('Basic.global.Action') ?></th>
</tr> </tr>
</thead> </thead>
@ -196,13 +197,14 @@
break; break;
default: default:
return '--'; // Debug return data; // Debug
break; break;
} }
} }
}, },
{ 'data': 'vencimiento' }, { 'data': 'vencimiento' },
{ 'data': 'dias_vencimiento' },
{ 'data': actionBtns } { 'data': actionBtns }
] ]
}); });