diff --git a/ci4/app/Config/Routes.php b/ci4/app/Config/Routes.php index 9b02775c..8358097a 100644 --- a/ci4/app/Config/Routes.php +++ b/ci4/app/Config/Routes.php @@ -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', diff --git a/ci4/app/Controllers/Facturacion/Factura.php b/ci4/app/Controllers/Facturacion/Factura.php deleted file mode 100755 index 36cf7938..00000000 --- a/ci4/app/Controllers/Facturacion/Factura.php +++ /dev/null @@ -1,41 +0,0 @@ -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); + } + } + +} + \ No newline at end of file diff --git a/ci4/app/Language/en/Facturas.php b/ci4/app/Language/en/Facturas.php new file mode 100644 index 00000000..a03f164c --- /dev/null +++ b/ci4/app/Language/en/Facturas.php @@ -0,0 +1,59 @@ + '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', + 'contado' => 'Cash', + 'contrareembolso' => 'Cash on Delivery', + 'giroDocimiliado' => 'Direct Debit', + 'pagare' => 'Promissory Note', + 'transferencia' => 'Transfer', +]; \ No newline at end of file diff --git a/ci4/app/Language/es/Facturas.php b/ci4/app/Language/es/Facturas.php new file mode 100644 index 00000000..51458323 --- /dev/null +++ b/ci4/app/Language/es/Facturas.php @@ -0,0 +1,59 @@ + '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', + 'contado' => 'Contado', + 'contrareembolso' => 'Contrareembolso', + 'giroDomiciliado' => 'Giro domiciliado', + 'pagare' => 'Pagaré', + 'transferencia' => 'Transferencia', +]; \ No newline at end of file diff --git a/ci4/app/Models/Facturas/FacturaModel.php b/ci4/app/Models/Facturas/FacturaModel.php index 0c3a35f8..40b56d25 100644 --- a/ci4/app/Models/Facturas/FacturaModel.php +++ b/ci4/app/Models/Facturas/FacturaModel.php @@ -6,6 +6,23 @@ 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', @@ -47,4 +64,30 @@ class FacturaModel extends \App\Models\BaseModel { 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, + DAFEDIFF(days, NOW(), t3.fecha_vencimiento_at) AS dias" + //'DATEDIFF((SELECT MIN(facturas_pagos.fecha_vencimiento_at) FROM facturas_pagos WHERE facturas_pagos.deleted_at is null and factura_id = facturas.id), facturas.fecha_factura_at) + ); + + $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(); + } } \ No newline at end of file diff --git a/ci4/app/Views/themes/vuexy/form/facturas/viewAddFactura.php b/ci4/app/Views/themes/vuexy/form/facturas/viewAddFactura.php new file mode 100644 index 00000000..e69de29b diff --git a/ci4/app/Views/themes/vuexy/form/facturas/viewFacturasList.php b/ci4/app/Views/themes/vuexy/form/facturas/viewFacturasList.php new file mode 100644 index 00000000..9c93d492 --- /dev/null +++ b/ci4/app/Views/themes/vuexy/form/facturas/viewFacturasList.php @@ -0,0 +1,219 @@ +=$this->include('themes/_commonPartialsBs/datatables') ?> += $this->include('themes/_commonPartialsBs/_confirm2delete') ?> +=$this->extend('themes/vuexy/main/defaultlayout') ?> +=$this->section('content'); ?> +
| = lang('Facturas.idFactura') ?> | += lang('Facturas.numeroFactura') ?> | += lang('Facturas.fechaFactura') ?> | += lang('Facturas.cliente') ?> | += lang('Facturas.base') ?> | += lang('Facturas.total') ?> | += lang('Facturas.pendiente') ?> | += lang('Facturas.credito') ?> | += lang('Facturas.estado') ?> | += lang('Facturas.estadoPago') ?> | += lang('Facturas.formaPago') ?> | += lang('Facturas.vencimiento') ?> | += lang('Facturas.dias') ?> | += lang('Basic.global.Action') ?> | +
|---|