Merge branch 'feat/seccion_facturas_en_pedidos' into 'main'

finalizado el ver facturas en pedidos

See merge request jjimenez/safekat!295
This commit is contained in:
2024-07-30 17:07:57 +00:00
4 changed files with 151 additions and 1 deletions

View File

@ -670,7 +670,7 @@ $routes->group('facturas', ['namespace' => 'App\Controllers\Facturacion'], funct
$routes->post('updateCabecera/(:any)', 'Facturas::updateCabecera/$1', ['as' => 'updateCabecera']);
$routes->post('datatablePagos/(:any)', 'FacturasPagos::datatable/$1', ['as' => 'dataTableOfPagosFacturas']);
$routes->post('editorPagos', 'FacturasPagos::datatable_editor', ['as' => 'editorOfPagosFacturas']);
$routes->post('datatablePedidos', 'Facturas::datatablePedidos', ['as' => 'dataTableOfFacturasPedido']);
});

View File

@ -218,6 +218,38 @@ class Facturas extends \App\Controllers\BaseResourceController
}
}
public function datatablePedidos(){
if ($this->request->isAJAX()) {
$reqData = $this->request->getPost();
if (!isset($reqData['draw']) || !isset($reqData['columns']) ) {
$errstr = 'No data available in response to this specific request.';
$response = $this->respond(Collection::datatable( [], 0, 0, $errstr ), 400, $errstr);
return $response;
}
$start = $reqData['start'] ?? 0;
$length = $reqData['length'] ?? 5;
$search = $reqData['search']['value'];
$requestedOrder = $reqData['order']['0']['column'] ?? 0;
$order = FacturaModel::SORTABLE_PEDIDOS[$requestedOrder >= 0 ? $requestedOrder : 0];
$dir = $reqData['order']['0']['dir'] ?? 'asc';
$pedido_id = $reqData['pedido_id'] ?? 0;
$resourceData = $this->model->getResourcePedidos($pedido_id)->orderBy($order, $dir)->limit($length, $start)->get()->getResultObject();
return $this->respond(Collection::datatable(
$resourceData,
$this->model->getResourcePedidos($pedido_id)->countAllResults(),
$this->model->getResourcePedidos($pedido_id)->countAllResults()
));
} else {
return $this->failUnauthorized('Invalid request', 403);
}
}
public function update($id = null){
if ($this->request->isAJAX()) {

View File

@ -23,6 +23,14 @@ class FacturaModel extends \App\Models\BaseModel {
11 => "DAFEDIFF(days, NOW(), t3.fecha_vencimiento_at)",
];
const SORTABLE_PEDIDOS = [
1 => "t1.numero",
2 => "t2.nombre",
3 => "t1.estado",
4 => "t1.fecha_factura_at",
5 => "t1.total",
];
// Lista de columnas basada en los campos de la tabla, para asignación masiva
protected $allowedFields = [
'pedido_id',
@ -93,6 +101,30 @@ class FacturaModel extends \App\Models\BaseModel {
->groupEnd();
}
public function getResourcePedidos($pedido_id)
{
$builder = $this->db
->table($this->table . " t1")
->select(
"t1.id AS id, t1.numero AS numero, t2.nombre AS serie, t1.estado AS estado,
DATE_FORMAT(t1.fecha_factura_at, '%d/%m/%Y') AS fecha_factura_at, t1.total AS total"
);
$builder->join("series t2", "t2.id = t1.serie_id", "left");
$builder->join("facturas_lineas t3", "t1.id = t3.factura_id", "left");
$builder->join("facturas_pedidos_lineas t4", "t1.id = t4.factura_id", "left");
$builder->join("pedidos_linea t5", "t4.pedido_linea_id = t5.id", "left");
$builder->join("pedidos t6", "t5.pedido_id = t6.id", "left");
$builder->where("t1.deleted_at IS NULL");
$builder->where("t6.id", $pedido_id);
$builder->groupBy("t1.id"); // Agrupa por id de la factura
return $builder;
}
public function getCantidadLineaPedidoFacturada($linea_pedido_id)
{
$builder = $this->db

View File

@ -10,6 +10,21 @@
<div id="accordionFacturasTip" class="accordion-collapse collapse show" data-bs-parent="#accordioFacturas">
<div class="accordion-body">
<table id="tableOfFacturas" class="table table-striped table-hover" style="width: 100%;grid-template-columns: 1fr 1fr 6fr 1fr 1fr 1fr;">
<thead>
<tr>
<th style="max-width:60px;"></th>
<th>ID</th>
<th><?= lang('Facturas.numeroFactura') ?></th>
<th><?= lang('Facturas.serieFacturacion') ?></th>
<th><?= lang('Facturas.estado') ?></th>
<th><?= lang('Facturas.fechaFactura') ?></th>
<th><?= lang('Facturas.total') ?></th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div> <!-- /.accordion-body -->
</div>
@ -19,6 +34,77 @@
<?=$this->section('additionalInlineJs') ?>
const actionBtns_facturas = function(data) {
return `
<td class="text-right py-0 align-middle">
<div class="btn-group btn-group-sm">
<a href="javascript:void(0);"><i class="ti ti-eye ti-sm btn-view-factura mx-2" data-id="${data.id}"></i></a>
</div>
</td>`;
};
tablaFacturasPedido = $('#tableOfFacturas').DataTable({
processing: true,
serverSide: true,
autoWidth: true,
responsive: true,
scrollX: true,
"dom": 't',
stateSave: true,
order: [[1, 'asc']],
language: {
url: "/themes/vuexy/vendor/libs/datatables-sk/plugins/i18n/es-ES.json"
},
ajax : $.fn.dataTable.pipeline( {
url: '<?= route_to('dataTableOfFacturasPedido') ?>',
method: 'POST',
data: function ( d ) {
d.pedido_id = <?= $pedidoEntity->id ?>;
},
headers: {'X-Requested-With': 'XMLHttpRequest'},
async: true,
}),
columnDefs: [
{
orderable: false,
searchable: false,
targets: [0]
}
],
columns : [
{ 'data': actionBtns_facturas },
{ 'data': 'id' },
{ 'data': 'numero' },
{ 'data': 'serie' },
{ 'data': 'estado',
render: function(data, type, row, meta) {
switch(data){
case "borrador":
return '<?= lang('Facturas.borrador') ?>';
break;
case "validada":
return '<?= lang('Facturas.validada') ?>';
break;
default:
return '--'; // Debug
break;
}
}
},
{ 'data': 'fecha_factura_at' },
{ 'data': 'total' },
]
});
$(document).on('click', '.btn-view-factura', function(e) {
var pedido_id = $(this).data('id');
var url = '<?= route_to('editarFactura', ':id') ?>';
url = url.replace(':id', pedido_id );
window.open(url, '_blank');
});
<?=$this->endSection() ?>