From 6979670eae36a9a6937a98e63606bf30940da701 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaime=20Jim=C3=A9nez?= Date: Sat, 22 Mar 2025 18:50:44 +0100 Subject: [PATCH] mejorada la vista de lista de facturas --- ci4/app/Controllers/Facturacion/Facturas.php | 78 ++++++------------- ci4/app/Controllers/Test.php | 44 ++++++++++- ci4/app/Language/es/Facturas.php | 1 + ci4/app/Models/Facturas/FacturaModel.php | 4 +- ci4/app/Models/Pedidos/PedidoModel.php | 1 + .../vuexy/form/facturas/viewFacturaForm.php | 2 +- .../vuexy/form/facturas/viewFacturasList.php | 66 ++++++++++++++-- .../vuexy/form/soporte/viewTicketForm.php | 4 +- 8 files changed, 132 insertions(+), 68 deletions(-) diff --git a/ci4/app/Controllers/Facturacion/Facturas.php b/ci4/app/Controllers/Facturacion/Facturas.php index 676ae45a..76ccccc6 100755 --- a/ci4/app/Controllers/Facturacion/Facturas.php +++ b/ci4/app/Controllers/Facturacion/Facturas.php @@ -86,6 +86,16 @@ class Facturas extends \App\Controllers\BaseResourceController $viewData['cliente_id'] = $clienteId; + // Establecer el idioma (opcional, si no está configurado en app/Config/App.php) + $locale = explode('-', config('Basics')->i18n)[0]; // Or dynamically set it: \Config\Services::language()->getLocale(); + // Specify the language file name (without .php) + $fileName = 'datePicker'; + // Build the path to the language file + $filePath = APPPATH . "Language/{$locale}/{$fileName}.php"; + // Load the entire language file as an array + $viewData['datepickerLang'] = json_encode(file_exists($filePath) ? require $filePath : []); + $viewData['datepickerLocale'] = config('Basics')->i18n; + return view(static::$viewPath . 'viewFacturasList', $viewData); } @@ -220,38 +230,8 @@ class Facturas extends \App\Controllers\BaseResourceController return $this->displayForm(__METHOD__, $id); } - /* - 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'; - $cliente_id = $reqData['cliente_id'] ?? -1; - - $resourceData = $this->model->getResource($search, $cliente_id)->orderBy($order, $dir)->limit($length, $start)->get()->getResultObject(); - - return $this->respond(Collection::datatable( - $resourceData, - $this->model->getResource("", $cliente_id)->countAllResults(), - $this->model->getResource($search, $cliente_id)->countAllResults() - )); - } else { - return $this->failUnauthorized('Invalid request', 403); - } - } - */ public function datatable() { @@ -267,6 +247,18 @@ class Facturas extends \App\Controllers\BaseResourceController $model = model(FacturaModel::class); $q = $model->getDatatableQuery($clienteId); + $searchValue = $this->request->getGet('fecha_factura') ?? ''; + + if (!empty($searchValue)) { + // Extraer las fechas del formato "YYYY-MM-DD|YYYY-MM-DD" + $dates = explode('|', $searchValue); + if (count($dates) == 2) { + $q->where('t1.fecha_factura_at >=', $dates[0] . ' 00:00:00') + ->where('t1.fecha_factura_at <=', $dates[1] . ' 23:59:59'); + } + } + + $result = DataTable::of($q) ->edit( "creditoAsegurado", @@ -334,18 +326,16 @@ class Facturas extends \App\Controllers\BaseResourceController ->add("action", callback: function ($q) { if ($q->estado == 'borrador') { return ' -
- '; + '; } else { return ' -
- '; + '; } }); if ($clienteId != -1) { @@ -358,25 +348,7 @@ class Facturas extends \App\Controllers\BaseResourceController $result->hide('dias_vencimiento'); } - //return $result->toJson(returnAsObject: true); - - // Obtener el resultado como array para inspeccionarlo - $jsonResult = $result->toJson(returnAsObject: true); - $data = json_decode($jsonResult->getBody(), true); - - // Verificar si "data" contiene solo una fila vacía - if (empty($data['data']) || (count($data['data']) === 1 && $data['data'][0]['id'] === null)) { - return $this->response->setJSON([ - 'draw' => $data['draw'] ?? $this->request->getVar('draw') ?? 0, - 'recordsTotal' => $data['recordsTotal'] ?? 0, - 'recordsFiltered' => 0, - 'data' => [] - ]); - } - - // Si hay datos válidos, devolver el resultado original - return $jsonResult; - + return $result->toJson(returnAsObject: true); } diff --git a/ci4/app/Controllers/Test.php b/ci4/app/Controllers/Test.php index 9e73792d..9ee22475 100755 --- a/ci4/app/Controllers/Test.php +++ b/ci4/app/Controllers/Test.php @@ -14,6 +14,8 @@ use App\Models\Usuarios\GroupModel; use App\Models\Usuarios\PermisosModel; use App\Services\PresupuestoService; use CodeIgniter\Shield\Entities\User; +use App\Models\Sistema\SettingsModel; + class Test extends BaseController { @@ -29,12 +31,48 @@ class Test extends BaseController public function index() { - - // (new Presupuestocliente())->testRemoteDB(); - (new Importadorpresupuestos())->getClientList(); + $this->sendMail('prueba', 'Esto es una prueba', ['jaimejimenezortega@gmail.com','jaime0jimenez0ortega@gmail.com']); + } + private function sendMail($subject, $body, $recipient) + { + $settings_model = new SettingsModel(); + $config = $settings_model->first()->toArray(); + $gateway = $config['email_gateway']; + $body = html_entity_decode($body); + if ($gateway == 'smtp') { + try { + //https://codeigniter.com/user_guide/libraries/email.html + $email = \Config\Services::email(); + $config['protocol'] = $config['email_gateway']; + $config['SMTPHost'] = $config['email_smtp']; + $config['SMTPUser'] = $config['email_address']; + $config['SMTPPass'] = $config['email_pass']; + $config['SMTPPort'] = intval($config['email_port']); + $config['SMTPCrypto'] = $config['email_cert'] == 'none' ? '' : $config['email_cert']; + $config['SMTPTimeout'] = 15; + $config['mailType'] = 'html'; + $config['wordWrap'] = true; + $email->initialize($config); + + $email->setFrom($config['email_address'], $config['email_name']); + $email->setTo($recipient); + + $email->setSubject($subject); + $email->setMessage($body); + + if (!$email->send()) { + return false; + } else { + return true; + } + } catch (\Exception $ex) { + return false; + } + } + return false; } private function clonar_tarifa_encuadernacion($teOrigen, $teDestino){ diff --git a/ci4/app/Language/es/Facturas.php b/ci4/app/Language/es/Facturas.php index 90e6962f..15ffc70b 100644 --- a/ci4/app/Language/es/Facturas.php +++ b/ci4/app/Language/es/Facturas.php @@ -41,6 +41,7 @@ return [ 'concepto' => 'Concepto', 'precioUnidad' => '€/u', 'iva' => 'IVA', + 'todos' => 'Todos', 'subtotal' => 'Subtotal', 'pendientePago' => 'Pendiente Pago', 'rectificativa' => 'Rectificativa', diff --git a/ci4/app/Models/Facturas/FacturaModel.php b/ci4/app/Models/Facturas/FacturaModel.php index bf4fd2e2..b9f34a61 100644 --- a/ci4/app/Models/Facturas/FacturaModel.php +++ b/ci4/app/Models/Facturas/FacturaModel.php @@ -127,9 +127,9 @@ class FacturaModel extends \App\Models\BaseModel $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"); + $builder->where("t1.deleted_at", null); - $builder->where("t1.deleted_at IS NULL"); if (auth()->user()->inGroup("cliente-admin") || auth()->user()->inGroup("cliente-editor")) { $builder->where("t1.estado", "validada"); } @@ -138,6 +138,8 @@ class FacturaModel extends \App\Models\BaseModel $builder->where("t1.cliente_id", $cliente_id); } + $builder->groupBy("t1.id"); + //$query = $builder->getCompiledSelect(); return $builder; } diff --git a/ci4/app/Models/Pedidos/PedidoModel.php b/ci4/app/Models/Pedidos/PedidoModel.php index 9c955f40..e8431542 100644 --- a/ci4/app/Models/Pedidos/PedidoModel.php +++ b/ci4/app/Models/Pedidos/PedidoModel.php @@ -71,6 +71,7 @@ class PedidoModel extends \App\Models\BaseModel $builder->join("clientes t4", "t4.id = t3.cliente_id", "left"); $builder->join("users t5", "t5.id = t4.comercial_id", "left"); + $builder->where("t1.id", $pedido_id); return $builder->get()->getResultObject(); } diff --git a/ci4/app/Views/themes/vuexy/form/facturas/viewFacturaForm.php b/ci4/app/Views/themes/vuexy/form/facturas/viewFacturaForm.php index 297cb26e..0736152a 100644 --- a/ci4/app/Views/themes/vuexy/form/facturas/viewFacturaForm.php +++ b/ci4/app/Views/themes/vuexy/form/facturas/viewFacturaForm.php @@ -30,7 +30,7 @@ $facturaEntity->id,"type" => "factura"]) ?> -
+
estado =='borrador') : ?> - + @@ -37,9 +37,11 @@ - - + + + @@ -47,14 +49,44 @@ - - - - + + + + + + + + + + + + + - + @@ -71,13 +103,31 @@ endSection() ?> + +section('additionalInlineJs') ?> + + +window.datepickerLang = ; +window.datepickerLocale =''; + +endSection() ?> + + + section('css') ?> "> +"> + endSection() ?> section('additionalExternalJs') ?> + +