Merge branch 'feat/entidades_modelos_facturas' into 'main'

Feat/entidades modelos facturas

See merge request jjimenez/safekat!283
This commit is contained in:
2024-07-06 15:20:35 +00:00
14 changed files with 711 additions and 53 deletions

View File

@ -648,6 +648,11 @@ $routes->group('albaranes', ['namespace' => 'App\Controllers\Pedidos'], function
$routes->resource('albaranes', ['namespace' => 'App\Controllers\Pedidos', 'controller' => 'Albaran', 'except' => 'show,new,create,update']);
$routes->group('facturas', ['namespace' => 'App\Controllers\Facturacion'], function ($routes) {
$routes->get('list', 'Facturas::list', ['as' => 'facturasList']);
$routes->post('datatable', 'Facturas::datatable', ['as' => 'dataTableOfFacturas']);
});
$routes->group(
'printpresupuestos',

View File

@ -1,41 +0,0 @@
<?php
namespace App\Controllers\Facturacion;
use App\Controllers\BaseController;
class Factura extends BaseController
{
function __construct()
{
}
public function index()
{
echo 'Facturas';
}
public function nueva()
{
echo 'Nueva Factura';
}
public function vencimiento()
{
echo 'Vencimiento Factura';
}
public function delete()
{
}
public function export()
{
}
}

View File

@ -0,0 +1,99 @@
<?php
namespace App\Controllers\Facturacion;
use App\Models\Facturas\FacturaModel;
use App\Models\Collection;
class Facturas extends \App\Controllers\BaseResourceController
{
protected $modelName = FacturaModel::class;
protected $format = 'json';
protected static $singularObjectNameCc = 'factura';
protected static $singularObjectName = 'Factura';
protected static $pluralObjectName = 'Facturas';
protected static $controllerSlug = 'factura';
protected static $viewPath = 'themes/vuexy/form/facturas/';
protected $indexRoute = 'facturaList';
public function initController(\CodeIgniter\HTTP\RequestInterface $request, \CodeIgniter\HTTP\ResponseInterface $response, \Psr\Log\LoggerInterface $logger)
{
$this->viewData['pageTitle'] = lang('Pedidos.moduleTitle');
// Se indica que este controlador trabaja con soft_delete
$this->viewData = ['usingServerSideDataTable' => true];
// Breadcrumbs
$this->viewData['breadcrumb'] = [
['title' => lang("App.menu_pedidos"), 'route' => "javascript:void(0);", 'active' => false],
];
parent::initController($request, $response, $logger);
}
public function index()
{
$this->viewData['usingClientSideDataTable'] = true;
$this->viewData['pageSubTitle'] = lang('Basic.global.ManageAllRecords', [lang('Tarifaextra.tarifaextra')]);
parent::index();
}
public function list()
{
$viewData = [
'currentModule' => static::$controllerSlug,
'pageSubTitle' => lang('Basic.global.ManageAllRecords', [lang('Pedidos.pedido')]),
'usingServerSideDataTable' => true,
'pageTitle' => lang('Facturas.facturas'),
'estadoPedidos' => 'todos',
['title' => lang("App.menu_facturas"), 'route' => site_url('facturas/list'), 'active' => true]
];
$viewData['breadcrumb'] = [
['title' => lang("App.menu_facturas"), 'route' => "javascript:void(0);", 'active' => false],
['title' => lang("Facturas.facturaList"), 'route' => "javascript:void(0);", 'active' => true]
];
return view(static::$viewPath . 'viewFacturasList', $viewData);
}
public function datatable(){
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[$requestedOrder >= 0 ? $requestedOrder : 0];
$dir = $reqData['order']['0']['dir'] ?? 'asc';
$resourceData = $this->model->getResource($search)->orderBy($order, $dir)->limit($length, $start)->get()->getResultObject();
return $this->respond(Collection::datatable(
$resourceData,
$model_linea->getResource("")->countAllResults(),
$model_linea->getResource($search)->countAllResults()
));
} else {
return $this->failUnauthorized('Invalid request', 403);
}
}
}

View File

@ -0,0 +1,55 @@
<?php
namespace App\Entities\Facturas;
class FacturaEntity extends \CodeIgniter\Entity\Entity
{
protected $attributes = [
'id' => null,
'pedido_id' => null,
'factura_retificada_id' => null,
'factura_retificativa_id' => null,
'cliente_id' => null,
'serie_id' => null,
'numero' => null,
'estado' => null,
'estado_pago' => null,
'fecha_factura_at' => null,
'notas' => null,
'base' => null,
'total' => null,
'pendiente' => null,
'total_pagos' => null,
'creditoAsegurado' => null,
'cliente_nombre' => null,
'cliente_address' => null,
'cliente_cif' => null,
'cliente_pais' => null,
'cliente_cp' => null,
'cliente_ciudad' => null,
'cliente_provincia' => null,
'created_at' => null,
'updated_at' => null,
'deleted_at' => null,
'user_created_id' => null,
'user_update_id' => null,
];
protected $casts = [
'id' => 'int',
'pedido_id' => 'int',
'factura_retificada_id' => 'int',
'factura_retificativa_id' => 'int',
'cliente_id' => 'int',
'serie_id' => 'int',
'estado' => 'int',
'estado_pago' => 'int',
'base' => 'float',
'total' => 'float',
'pendiente' => 'float',
'total_pagos' => 'float',
'creditoAsegurado' => 'float',
];
}

View File

@ -0,0 +1,39 @@
<?php
namespace App\Entities\Facturas;
class FacturaLineaEntity extends \CodeIgniter\Entity\Entity
{
protected $attributes = [
'id' => null,
'factura_id' => null,
'pedido_impresion_id' => null,
'pedido_maquetacion_id' => null,
'descripcion' => null,
'cantidad' => null,
'precio_unidad' => null,
'iva' => null,
'base' => null,
'total_iva' => null,
'total' => null,
'data' => null,
'deleted_at' => null,
'user_update_id' => null,
];
protected $casts = [
'id' => 'int',
'factura_id' => 'int',
'pedido_impresion_id' => 'int',
'pedido_maquetacion_id' => 'int',
'cantidad' => 'float',
'precio_unidad' => 'float',
'iva' => 'float',
'base' => 'float',
'total_iva' => 'float',
'total' => 'float',
];
}

View File

@ -0,0 +1,28 @@
<?php
namespace App\Entities\Facturas;
class FacturaPagoEntity extends \CodeIgniter\Entity\Entity
{
protected $attributes = [
'id' => null,
'factura_id' => null,
'notes' => null,
'fecha_pago_at' => null,
'fecha_vencimiento_at' => null,
'forma_pago_id' => null,
'total' => null,
'deleted_at' => null,
'user_update_id' => null,
];
protected $casts = [
'id' => 'int',
'factura_id' => 'int',
'forma_pago_id' => 'int',
'total' => 'float',
];
}

View File

@ -0,0 +1,57 @@
<?php
return [
'factura' => 'Invoice',
'facturaList' => 'Invoice List',
'facturas' => 'Invoices',
'facturasList' => 'List of Invoices',
'numeroFactura' => 'Number',
'idFactura' => 'ID',
'fechaFactura' => 'Date',
'cliente' => 'Client',
'base' => 'Base',
'total' => 'Total',
'pendiente' => 'Pending',
'credito' => 'Credit',
'estado' => 'Status',
'estadoPago' => 'Payment Status',
'formaPago' => 'Payment Method',
'vencimiento' => 'Due Date',
'dias' => 'Days',
'serieFacturacion' => 'Billing Series',
'creditoAsegurado' => 'Secured Credit',
'facturaRectificada' => 'Rectified Invoice',
'razonSocial' => 'Business Name',
'cif' => 'Tax ID',
'direccion' => 'Address',
'cp' => 'Postal Code',
'pais' => 'Country',
'localidad' => 'Town',
'provincia' => 'Province',
'pasarBorrador' => 'Move to Draft',
'exportarLineas' => 'Export Lines',
'duplicar' => 'Duplicate',
'pedidos' => 'Orders',
'titulo' => 'Title',
'tirada' => 'Print Run',
'lineas' => 'Lines',
'unidades' => 'Units',
'concepto' => 'Concept',
'precioUnidad' => '€/u',
'iva' => 'VAT',
'subtotal' => 'Subtotal',
'pendientePago' => 'Outstanding Payment',
'rectificativa' => 'Rectifying',
'facturaYaRectificada' => 'Already Rectified Invoice',
'imprimir' => 'Print',
'validada' => 'Validated',
'borrador' => 'Draft',
'pagada' => 'Paid',
'insolvente' => 'Insolvent',
'cheque' => 'Check',
'compensada' => 'Compensated',
'confirming' => 'Confirming',
'giroDocimiliado' => 'Direct Debit',
'pagare' => 'Promissory Note',
'transferencia' => 'Transfer',
];

View File

@ -0,0 +1,57 @@
<?php
return [
'factura' => 'Factura',
'facturaList' => 'Listado de Facturas',
'facturas' => 'Facturas',
'facturasList' => 'Listado de Facturas',
'numeroFactura' => 'Número',
'idFactura' => 'ID',
'fechaFactura' => 'Fecha',
'cliente' => 'Cliente',
'base' => 'Base',
'total' => 'Total',
'pendiente' => 'Pendiente',
'credito' => 'Crédito',
'estado' => 'Estado',
'estadoPago' => 'Estado Pago',
'formaPago' => 'Forma Pago',
'vencimiento' => 'Vencimiento',
'dias' => 'Días',
'serieFacturacion' => 'Serie facturación',
'creditoAsegurado' => 'Crédito asegurado',
'facturaRectificada' => 'Factura rectificada',
'razonSocial' => 'Razón Social',
'cif' => 'CIF',
'direccion' => 'Dirección',
'cp' => 'CP',
'pais' => 'País',
'localidad' => 'Localidad',
'provincia' => 'Provincia',
'pasarBorrador' => 'Pasar a borrador',
'exportarLineas' => 'Exportar líneas',
'duplicar' => 'Duplicar',
'pedidos' => 'Pedidos',
'titulo' => 'Título',
'tirada' => 'Tirada',
'lineas' => 'Líneas',
'unidades' => 'Unidades',
'concepto' => 'Concepto',
'precioUnidad' => '€/u',
'iva' => 'IVA',
'subtotal' => 'Subtotal',
'pendientePago' => 'Pendiente Pago',
'rectificativa' => 'Rectificativa',
'facturaYaRectificada' => 'Factura ya rectificada',
'imprimir' => 'Imprimir',
'validada' => 'Validada',
'borrador' => 'Borrador',
'pagada' => 'Pagada',
'insolvente' => 'Insolvente',
'cheque' => 'Cheque',
'compensada' => 'Compensada',
'confirming' => 'Confirming',
'giroDomiciliado' => 'Giro domiciliado',
'pagare' => 'Pagaré',
'transferencia' => 'Transferencia',
];

View File

@ -0,0 +1,33 @@
<?php
namespace App\Models\Facturas;
class FacturaLineaModel extends \App\Models\BaseModel {
protected $table = 'facturas_lineas';
// Lista de columnas basada en los campos de la tabla, para asignación masiva
protected $allowedFields = [
'factura_id',
'pedido_impresion_id',
'pedido_maquetacion_id',
'descripcion',
'cantidad',
'precio_unidad',
'iva',
'base',
'total_iva',
'total',
'data',
'deleted_at',
'user_update_id'
];
protected $returnType = "App\Entities\Facturas\FacturaLineaEntity";
protected $useTimestamps = false;
protected $useSoftDeletes = true;
public static $labelField = "id";
}

View File

@ -0,0 +1,91 @@
<?php
namespace App\Models\Facturas;
class FacturaModel extends \App\Models\BaseModel {
protected $table = 'facturas';
protected $useAutoIncrement = true;
const SORTABLE = [
0 => "t1.id",
1 => "t1.numero",
2 => "t1.fecha_factura_at",
3 => "t2.nombre",
4 => "t1.base",
5 => "t1.total",
6 => "t1.pendiente",
7 => "t1.creditoAsegurado",
8 => "t1.estado",
9 => "t1.estado_pago",
10 => "t4.nombre",
11 => "DAFEDIFF(days, NOW(), t3.fecha_vencimiento_at)",
];
// Lista de columnas basada en los campos de la tabla, para asignación masiva
protected $allowedFields = [
'pedido_id',
'factura_retificada_id',
'factura_retificativa_id',
'customer_id',
'serie_id',
'numero',
'estado',
'estado_pago',
'fecha_factura_at',
'notas',
'base',
'total',
'pendiente',
'total_pagos',
'creditoAsegurado',
'customer_nombre',
'customer_address',
'customer_cif',
'customer_pais',
'customer_cp',
'customer_ciudad',
'customer_provincia',
'created_at',
'updated_at',
'deleted_at',
'user_created_id',
'user_update_id'
];
protected $returnType = "App\Entities\Facturas\FacturaEntity";
protected $useTimestamps = true;
protected $useSoftDeletes = true;
protected $createdField = "created_at";
protected $updatedField = "updated_at";
public static $labelField = "id";
public function getResource(string $search = "")
{
$builder = $this->db
->table($this->table . " t1")
->select(
"t1.id AS id, t1.numero AS numero, t1.fecha_factura_at AS fecha_factura_at,
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,
t4.nombre AS forma_pago, t3.fecha_vencimiento_at AS venciemento"
);
$builder->join("clientes t2", "t2.id = t1.cliente_id", "left");
$builder->join("facturas_pagos t3", "t3.factura_id = t1.id", "left");
$builder->join("formas_pago t4", "t3.forma_pago_id = t4.id", "left");
return empty($search)
? $builder
: $builder
->groupStart()
->like("t1.id", $search)
->orLike("t1.id", $search)
->groupEnd();
}
}

View File

@ -0,0 +1,26 @@
<?php
namespace App\Models\Facturas;
class FacturaPagoModel extends \App\Models\BaseModel {
protected $table = 'facturas_pagos';
protected $allowedFields = [
'factura_id',
'notes',
'fecha_pago_at',
'fecha_vencimiento_at',
'forma_pago_id',
'total',
'deleted_at',
'user_update_id'
];
protected $returnType = "App\Entities\Facturas\FacturaPagoEntity";
protected $useTimestamps = false;
protected $useSoftDeletes = true;
public static $labelField = "id";
}

View File

@ -0,0 +1,209 @@
<?=$this->include('themes/_commonPartialsBs/datatables') ?>
<?= $this->include('themes/_commonPartialsBs/_confirm2delete') ?>
<?=$this->extend('themes/vuexy/main/defaultlayout') ?>
<?=$this->section('content'); ?>
<div class="row">
<div class="col-md-12">
<div class="card card-info">
<div class="card-header">
<h3 class="card-title"><?=lang('Facturas.facturasList') ?></h3>
</div><!--//.card-header -->
<div class="card-body">
<?= view('themes/_commonPartialsBs/_alertBoxes'); ?>
<table id="tableOfFacturas" class="table table-striped table-hover" style="width: 100%;">
<thead>
<tr>
<th><?= lang('Facturas.idFactura') ?></th>
<th><?= lang('Facturas.numeroFactura') ?></th>
<th><?= lang('Facturas.fechaFactura') ?></th>
<th><?= lang('Facturas.cliente') ?></th>
<th><?= lang('Facturas.base') ?></th>
<th><?= lang('Facturas.total') ?></th>
<th><?= lang('Facturas.pendiente') ?></th>
<th><?= lang('Facturas.credito') ?></th>
<th><?= lang('Facturas.estado') ?></th>
<th><?= lang('Facturas.estadoPago') ?></th>
<th><?= lang('Facturas.formaPago') ?></th>
<th><?= lang('Facturas.vencimiento') ?></th>
<th class="text-nowrap"><?= lang('Basic.global.Action') ?></th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div><!--//.card-body -->
<div class="card-footer">
</div><!--//.card-footer -->
</div><!--//.card -->
</div><!--//.col -->
</div><!--//.row -->
<?=$this->endSection() ?>
<?=$this->section('additionalInlineJs') ?>
const lastColNr = $('#tableOfFacturas').find("tr:first th").length - 1;
const actionBtns = 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-edit mx-2" data-id="${data.id}"></i></a>
</div>
</td>`;
};
theTable = $('#tableOfFacturas').DataTable({
processing: true,
serverSide: true,
autoWidth: true,
responsive: true,
scrollX: true,
lengthMenu: [ 5, 10, 25, 50, 75, 100, 250, 500, 1000, 2500 ],
pageLength: 250,
lengthChange: true,
"dom": 'lfBrtip',
"buttons": [
'copy', 'csv', 'excel', 'print', {
extend: 'pdfHtml5',
orientation: 'landscape',
pageSize: 'A4'
}
],
stateSave: true,
order: [[0, 'asc']],
language: {
url: "/themes/vuexy/vendor/libs/datatables-sk/plugins/i18n/es-ES.json"
},
ajax : $.fn.dataTable.pipeline( {
url: '<?= route_to('dataTableOfFacturas') ?>',
method: 'POST',
headers: {'X-Requested-With': 'XMLHttpRequest'},
async: true,
}),
columnDefs: [
{
orderable: false,
searchable: false,
targets: [lastColNr]
}
],
columns : [
{ 'data': 'id' },
{ 'data': 'numero' },
{ 'data': 'fecha_factura_at' },
{ 'data': 'cliente' },
{ 'data': 'base' },
{ 'data': 'total' },
{ 'data': 'pendiente' },
{ 'data': 'creditoAsegurado' },
{ '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': 'estado_pago',
render: function(data, type, row, meta) {
switch(data){
case "pendiente":
return '<?= lang('Facturas.pendiente') ?>';
break;
case "pagada":
return '<?= lang('Facturas.pagada') ?>';
break;
case "insolvente":
return '<?= lang('Facturas.insolvente') ?>';
break;
default:
return '--'; // Debug
break;
}
}
},
{ 'data': 'total_presupuesto' },
{ 'data': forma_pago,
render: function(data, type, row, meta) {
switch(data){
case "cheque":
return '<?= lang('Facturas.cheque') ?>';
break;
case "compensada":
return '<?= lang('Facturas.compensada') ?>';
break;
case "confirming":
return '<?= lang('Facturas.confirming') ?>';
break;
case "giroDomiciliado":
return '<?= lang('Facturas.giroDomiciliado') ?>';
break;
case "pagare":
return '<?= lang('Facturas.pagare') ?>';
break;
case "transferencia":
return '<?= lang('Facturas.transferencia') ?>';
break;
default:
return '--'; // Debug
break;
}
}
},
{ 'data': vencimiento },
{ 'data': actionBtns }
]
});
$(document).on('click', '.btn-edit', function(e) {
var url = '<?= route_to('editarPedido', ':id') ?>';
url = url.replace(':id', `${$(this).attr('data-id')}` );
window.location.href = url;
});
<?=$this->endSection() ?>
<?=$this->section('css') ?>
<link rel="stylesheet" href="<?= site_url("/themes/vuexy/vendor/libs/datatables-sk/plugins/buttons/buttons.bootstrap5.min.css") ?>">
<?=$this->endSection() ?>
<?= $this->section('additionalExternalJs') ?>
<script src="<?= site_url("/themes/vuexy/vendor/libs/datatables-sk/plugins/buttons/dataTables.buttons.min.js") ?>"></script>
<script src="<?= site_url("/themes/vuexy/vendor/libs/datatables-sk/plugins/buttons/buttons.bootstrap5.min.js") ?>"></script>
<script src="<?= site_url("/themes/vuexy/vendor/libs/datatables-sk/plugins/buttons/buttons.html5.min.js") ?>"></script>
<script src="<?= site_url("/themes/vuexy/vendor/libs/datatables-sk/plugins/buttons/buttons.print.min.js") ?>"></script>
<script src="<?= site_url("/themes/vuexy/vendor/libs/datatables-sk/plugins/jszip/jszip.min.js") ?>"></script>
<script src="<?= site_url("/themes/vuexy/vendor/libs/datatables-sk/plugins/pdfmake/pdfmake.min.js") ?>" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script src="<?= site_url("/themes/vuexy/vendor/libs/datatables-sk/plugins/pdfmake/vfs_fonts.js") ?>"></script>
<?=$this->endSection() ?>

View File

@ -12,22 +12,22 @@ if (auth()->user()->inGroup('beta')) {
</a>
<ul class="menu-sub">
<li class="menu-item">
<a href="<?= site_url("facturacion/factura") ?>" class="menu-link">
<?= lang("App.menu_facturas") ?>
</a>
</li>
<li class="menu-item">
<a href="<?= site_url("facturacion/factura/vencimiento") ?>" class="menu-link">
<?= lang("App.menu_facturas_vencimiento") ?>
</a>
</li>
<li class="menu-item">
<a href="<?= site_url("facturacion/factura/nueva") ?>" class="menu-link">
<a href="<?= route_to('facturasList') ?>" class="menu-link">
<?= lang("App.menu_facturas_nueva") ?>
</a>
</li>
<li class="menu-item">
<a href="<?= site_url("facturacion/albaran") ?>" class="menu-link">
<a href="<?= site_url("facturas/list") ?>" class="menu-link">
<?= lang("App.menu_facturas") ?>
</a>
</li>
<li class="menu-item">
<a href="<?= site_url("facturas/vencimientos") ?>" class="menu-link">
<?= lang("App.menu_facturas_vencimiento") ?>
</a>
</li>
<li class="menu-item">
<a href="<?= site_url("facturas/albaranes") ?>" class="menu-link">
<?= lang("App.menu_albaran") ?>
</a>
</li>