From e1fa993fcde6e814cd6dadc9efb3c6d98a1e083a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaime=20Jim=C3=A9nez?= Date: Sun, 30 Mar 2025 21:36:17 +0200 Subject: [PATCH 1/4] =?UTF-8?q?a=C3=B1adido=20facturas.=20faltan=20filtros?= =?UTF-8?q?=20pedidos?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ci4/app/Config/Routes.php | 2 + ci4/app/Controllers/Facturacion/Facturas.php | 16 ++++- ci4/app/Controllers/Pedidos/Pedido.php | 70 +++++++++++++++++++ ci4/app/Language/es/Facturas.php | 3 + ci4/app/Language/es/Pedidos.php | 4 ++ ci4/app/Models/Facturas/FacturaModel.php | 34 +++++++++ ci4/app/Models/Pedidos/PedidoModel.php | 15 ++++ .../clientes/cliente/_clienteFormItems.php | 34 ++++----- .../form/clientes/cliente/viewClienteForm.php | 2 +- .../js/safekat/pages/cliente/cliente.js | 17 ++++- 10 files changed, 175 insertions(+), 22 deletions(-) diff --git a/ci4/app/Config/Routes.php b/ci4/app/Config/Routes.php index e9590f5c..c0afb0ed 100644 --- a/ci4/app/Config/Routes.php +++ b/ci4/app/Config/Routes.php @@ -757,6 +757,7 @@ $routes->group('pedidos', ['namespace' => 'App\Controllers\Pedidos'], function ( $routes->post('insertfactura', 'Pedido::addFactura'); $routes->get('xml/(:num)', 'Pedido::get_xml_pedido/$1', ['as' => 'getXMLPedido']); $routes->post('produccion/(:num)', 'Pedido::to_produccion/$1', ['as' => 'toProduccion']); + $routes->get('pedidosCliente', 'Pedido::tablaClienteForm'); }); $routes->resource('pedidos', ['namespace' => 'App\Controllers\Pedidos', 'controller' => 'Pedido', 'except' => 'show,new,create,update']); @@ -797,6 +798,7 @@ $routes->group('facturas', ['namespace' => 'App\Controllers\Facturacion'], funct $routes->post('datatablePagos/(:any)', 'FacturasPagos::datatable/$1', ['as' => 'dataTableOfPagosFacturas']); $routes->post('editorPagos', 'FacturasPagos::datatable_editor', ['as' => 'editorOfPagosFacturas']); $routes->post('datatablePedidos', 'Facturas::datatablePedidos', ['as' => 'dataTableOfFacturasPedido']); + $routes->get('getdatoscliente/(:any)', 'Facturas::getDatosFacturacionClienteForm/$1'); }); diff --git a/ci4/app/Controllers/Facturacion/Facturas.php b/ci4/app/Controllers/Facturacion/Facturas.php index fd5416c4..3d914183 100755 --- a/ci4/app/Controllers/Facturacion/Facturas.php +++ b/ci4/app/Controllers/Facturacion/Facturas.php @@ -236,13 +236,16 @@ class Facturas extends \App\Controllers\BaseResourceController public function datatable() { + $dataForClienteForm = false; if (auth()->user()->inGroup('cliente-admin') || auth()->user()->inGroup('cliente-editor')) { // Se obtiene el cliente ID a partir del usuario de la sesion $model_user = model('App\Models\Usuarios\UserModel'); $user = $model_user->find(auth()->user()->id); $clienteId = $user->cliente_id; } else { - $clienteId = -1; + $temp = $this->request->getGet('cliente_id'); + $clienteId = ($temp && $temp != null && $temp != "") ? $temp : -1; + $dataForClienteForm = ($temp && $temp != null && $temp != "") ? true : false; } $model = model(FacturaModel::class); @@ -342,8 +345,10 @@ class Facturas extends \App\Controllers\BaseResourceController if ($clienteId != -1) { $result->hide('cliente'); $result->hide('creditoAsegurado'); - $result->hide('estado'); - $result->hide('estado_pago'); + if(!$dataForClienteForm){ + $result->hide('estado'); + $result->hide('estado_pago'); + } $result->hide('forma_pago'); $result->hide('vencimiento'); $result->hide('dias_vencimiento'); @@ -352,6 +357,11 @@ class Facturas extends \App\Controllers\BaseResourceController return $result->toJson(returnAsObject: true); } + public function getDatosFacturacionClienteForm($cliente_id){ + + return $this->respond($this->model->getSumatoriosFacturacionCliente($cliente_id)); + } + public function datatablePedidos() { diff --git a/ci4/app/Controllers/Pedidos/Pedido.php b/ci4/app/Controllers/Pedidos/Pedido.php index e17c26ef..84c843e1 100755 --- a/ci4/app/Controllers/Pedidos/Pedido.php +++ b/ci4/app/Controllers/Pedidos/Pedido.php @@ -8,6 +8,8 @@ use App\Models\Collection; use App\Models\Pedidos\PedidoModel; use App\Services\PedidoXMLService; use App\Services\ProductionService; +use Hermawan\DataTables\DataTable; +use CodeIgniter\I18n\Time; class Pedido extends \App\Controllers\BaseResourceController { @@ -34,6 +36,7 @@ class Pedido extends \App\Controllers\BaseResourceController $this->viewData['breadcrumb'] = [ ['title' => lang("App.menu_pedidos"), 'route' => "javascript:void(0);", 'active' => false], ]; + helper("time"); parent::initController($request, $response, $logger); @@ -371,6 +374,73 @@ class Pedido extends \App\Controllers\BaseResourceController } } + public function tablaClienteForm() + { + + $clienteId = $this->request->getGet('cliente_id') ?? -1; + + $q = $this->model->getPedidosClienteForm($clienteId); + + /*$searchValue = $this->request->getGet('fecha') ?? ''; + if (!empty($searchValue)) { + // Extraer las fechas del formato "YYYY-MM-DD|YYYY-MM-DD" + $dates = explode('|', $searchValue); + if (count($dates) == 2) { + $q->where('created_at >=', $dates[0] . ' 00:00:00') + ->where('created_at <=', $dates[1] . ' 23:59:59'); + } + } + $searchValue = $this->request->getGet('fecha_entrega') ?? ''; + if (!empty($searchValue)) { + // Extraer las fechas del formato "YYYY-MM-DD|YYYY-MM-DD" + $dates = explode('|', $searchValue); + if (count($dates) == 2) { + $q->where('fecha_entrega_real >=', $dates[0] . ' 00:00:00') + ->where('fecha_entrega_real <=', $dates[1] . ' 23:59:59'); + } + }*/ + + + $result = DataTable::of($q) + ->edit( + 'fecha', + fn($q) => $q->fecha?Time::createFromFormat("Y-m-d H:i:s", $q->fecha)->format("d/m/Y"):"" + ) + ->edit( + 'fecha_entrega', + fn($q) => $q->fecha_entrega?Time::createFromFormat("Y-m-d H:i:s", $q->fecha_entrega)->format("d/m/Y"):"" + ) + ->edit( + "estado", + function ($row, $meta) { + switch ($row->estado) { + case "validacion": + return lang('Pedidos.validacion'); + case "produccion": + return lang('Pedidos.produccion'); + case "finalizado": + return lang('Pedidos.finalizado'); + case "enviado": + return lang('Pedidos.enviado'); + case "cancelado": + return lang('Pedidos.cancelado'); + default: + return '--'; // Debug + } + } + ) + ->add("action", callback: function ($q) { + return ' +
+ +
+ '; + + }); + + return $result->toJson(returnAsObject: true) ; + } + public function obtenerPedidosForFacturas(){ if ($this->request->isAJAX()) { diff --git a/ci4/app/Language/es/Facturas.php b/ci4/app/Language/es/Facturas.php index 9be71bb4..fd058b51 100644 --- a/ci4/app/Language/es/Facturas.php +++ b/ci4/app/Language/es/Facturas.php @@ -74,6 +74,9 @@ return [ "ejemplares" => "Ejemplares", "addPago" => "Añadir Pago", "facturaPagada" => "Factura rectificativa ya abonada", + + "acumuladoFacturacion" => "Acumulado Facturación", + "totalPendientePago" => "Pendiente de pago", 'errors' => [ 'requiredFields' => 'Los campos marcados con * son obligatorios', diff --git a/ci4/app/Language/es/Pedidos.php b/ci4/app/Language/es/Pedidos.php index aa9c20e2..d5708bc8 100644 --- a/ci4/app/Language/es/Pedidos.php +++ b/ci4/app/Language/es/Pedidos.php @@ -82,6 +82,10 @@ return [ 'showTotal' => 'Mostrar totales', + 'pedidosImpresion' => 'Pedidos impresión', + 'pedidosMaquetacion' => 'Pedidos maquetación', + 'pedidosTotal' => 'Total en pedidos', + 'validation' => [ 'errorCantidadAlbaranes' => 'Total en albaranes {0} no coincide con la tirada {1}', diff --git a/ci4/app/Models/Facturas/FacturaModel.php b/ci4/app/Models/Facturas/FacturaModel.php index 718f94f6..dc11b5e2 100644 --- a/ci4/app/Models/Facturas/FacturaModel.php +++ b/ci4/app/Models/Facturas/FacturaModel.php @@ -145,6 +145,40 @@ class FacturaModel extends \App\Models\BaseModel return $builder; } + public function getSumatoriosFacturacionCliente($cliente_id = -1){ + + if($cliente_id == -1){ + return [ + 'total_facturacion' => 0, + 'total_pendiente' => 0 + ]; + } + + $result = []; + $data = $this->db->table('facturas f') + ->select('sum(f.total) as total') + ->where('f.cliente_id', $cliente_id) + ->where('f.deleted_at IS NULL') + ->where('f.estado', 'validada') + ->get() + ->getResultObject(); + $result['total_facturacion'] = + round(floatval(($data && $data[0]->total != null) ? $data[0]->total : 0), 2); + + $data = $this->db->table('facturas f') + ->select('sum(f.pendiente) as pendiente') + ->where('f.cliente_id', $cliente_id) + ->where('f.deleted_at IS NULL') + ->where('f.estado', 'validada') + ->where('f.estado_pago', 'pendiente') + ->get() + ->getResultObject(); + $result['total_pendiente'] = + round(floatval(($data && $data[0]->pendiente != null) ? $data[0]->pendiente : 0), 2); + + return $result; + } + /** * Get resource data for creating PDFs. diff --git a/ci4/app/Models/Pedidos/PedidoModel.php b/ci4/app/Models/Pedidos/PedidoModel.php index d5957dce..4ce4a16e 100644 --- a/ci4/app/Models/Pedidos/PedidoModel.php +++ b/ci4/app/Models/Pedidos/PedidoModel.php @@ -232,6 +232,21 @@ class PedidoModel extends \App\Models\BaseModel return $presupuesto_ficheros; } + + public function getPedidosClienteForm($cliente_id = -1){ + $builder = $this->db + ->table($this->table . " p") + ->select('p.id, p.created_at as fecha, p.fecha_entrega_real as fecha_entrega, + pr.paginas as paginas, p.total_tirada, p.total_precio, p.estado') + ->join('pedidos_linea pl', 'pl.pedido_id = p.id', 'left') + ->join('presupuestos pr', 'pr.id = pl.presupuesto_id', 'left') + //->where('pr.deleted_at IS NULL') + ->where('pr.cliente_id', $cliente_id) + ->orderBy('p.created_at', 'DESC') + ->groupBy('p.id'); + return $builder; + } + /** * Crea una orden de trabajo asociada al pedido * diff --git a/ci4/app/Views/themes/vuexy/form/clientes/cliente/_clienteFormItems.php b/ci4/app/Views/themes/vuexy/form/clientes/cliente/_clienteFormItems.php index 6c67d6a6..707661bb 100644 --- a/ci4/app/Views/themes/vuexy/form/clientes/cliente/_clienteFormItems.php +++ b/ci4/app/Views/themes/vuexy/form/clientes/cliente/_clienteFormItems.php @@ -56,19 +56,7 @@ - + +