diff --git a/ci4/app/Config/Routes.php b/ci4/app/Config/Routes.php index 5b9bd98c..01f07dbd 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/Entities/Facturas/FacturaEntity.php b/ci4/app/Entities/Facturas/FacturaEntity.php new file mode 100644 index 00000000..8d4e97a5 --- /dev/null +++ b/ci4/app/Entities/Facturas/FacturaEntity.php @@ -0,0 +1,55 @@ + 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', + ]; + +} \ No newline at end of file diff --git a/ci4/app/Entities/Facturas/FacturaLineaEntity.php b/ci4/app/Entities/Facturas/FacturaLineaEntity.php new file mode 100644 index 00000000..f9df393a --- /dev/null +++ b/ci4/app/Entities/Facturas/FacturaLineaEntity.php @@ -0,0 +1,39 @@ + 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', + ]; + +} \ No newline at end of file diff --git a/ci4/app/Entities/Facturas/FacturaPagoEntity.php b/ci4/app/Entities/Facturas/FacturaPagoEntity.php new file mode 100644 index 00000000..a47ce19a --- /dev/null +++ b/ci4/app/Entities/Facturas/FacturaPagoEntity.php @@ -0,0 +1,28 @@ + 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', + ]; + +} \ 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..2645b729 --- /dev/null +++ b/ci4/app/Language/en/Facturas.php @@ -0,0 +1,57 @@ + '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', +]; \ 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..39bc6aa9 --- /dev/null +++ b/ci4/app/Language/es/Facturas.php @@ -0,0 +1,57 @@ + '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', +]; \ No newline at end of file diff --git a/ci4/app/Models/Facturas/FacturaLineaModel.php b/ci4/app/Models/Facturas/FacturaLineaModel.php new file mode 100644 index 00000000..f53cf805 --- /dev/null +++ b/ci4/app/Models/Facturas/FacturaLineaModel.php @@ -0,0 +1,33 @@ + "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(); + } +} \ No newline at end of file diff --git a/ci4/app/Models/Facturas/FacturaPagoModel.php b/ci4/app/Models/Facturas/FacturaPagoModel.php new file mode 100644 index 00000000..1a17f9fb --- /dev/null +++ b/ci4/app/Models/Facturas/FacturaPagoModel.php @@ -0,0 +1,26 @@ +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('Basic.global.Action') ?> | +
|---|