Merge branch 'mod/vista_factura_list' into 'main'

mejorada la vista de lista de facturas

See merge request jjimenez/safekat!602
This commit is contained in:
2025-03-22 17:51:17 +00:00
8 changed files with 132 additions and 68 deletions

View File

@ -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 '
<td class="text-right py-0 align-middle">
<div class="btn-group btn-group-sm">
<a href="javascript:void(0);"><i class="ti ti-pencil ti-sm btn-edit mx-2" data-id="' . $q->id . '"></i></a>
</div>
</td>';
';
} else {
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="' . $q->id . '"></i></a>
</div>
</td>';
';
}
});
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);
}

View File

@ -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){

View File

@ -41,6 +41,7 @@ return [
'concepto' => 'Concepto',
'precioUnidad' => '€/u',
'iva' => 'IVA',
'todos' => 'Todos',
'subtotal' => 'Subtotal',
'pendientePago' => 'Pendiente Pago',
'rectificativa' => 'Rectificativa',

View File

@ -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;
}

View File

@ -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();
}

View File

@ -30,7 +30,7 @@
<?php endif; ?>
<?= view("themes/vuexy/components/chat_internal_factura",data:["modelId" =>$facturaEntity->id,"type" => "factura"]) ?>
<div class="pt-4">
<div class="container-fluid pt-4">
<?php if($facturaEntity->estado =='borrador') : ?>
<input type="button"
class="btn btn-success float-start me-sm-3 me-1"

View File

@ -21,7 +21,7 @@
<th><?= lang('Facturas.numeroFactura') ?></th>
<th><?= lang('Facturas.fechaFactura') ?></th>
<?php if ($cliente_id == -1): ?>
<th><?= lang('Facturas.cliente') ?></th>
<th style="width: 20%;"><?= lang('Facturas.cliente') ?></th>
<?php endif; ?>
<th><?= lang('Facturas.base') ?></th>
<th><?= lang('Facturas.total') ?></th>
@ -37,9 +37,11 @@
<th class="text-nowrap"><?= lang('Basic.global.Action') ?></th>
</tr>
<tr>
<th><input type="text" class="form-control factura-filter" name="id"></th>
<th><input type="text" class="form-control factura-filter" name="numero"></th>
<th></th>
<th><input type="text" class="form-control factura-filter" name="numero"></th>
<th><input id="fechaFactura" type="text" class="form-control factura-filter"
name="fecha_factura_at"></th>
</th>
<?php if ($cliente_id == -1): ?>
<th><input type="text" class="form-control factura-filter" name="cliente"></th>
<?php endif; ?>
@ -47,14 +49,44 @@
<th></th>
<th></th>
<?php if ($cliente_id == -1): ?>
<th><select class="select2 form-select select-credito" id="credito-filter" name="creditoAsegurado"></select></th>
<th><select class="select2 form-select select-estado" id="estado-filter" name="estado"></select></th>
<th><select class="select2 form-select select-estadoPago" id="estadoPago-filter" name="estado_pago"></select></th>
<th><select class="select2 form-select select-formaPago" id="formaPago-filter" name="forma_pago"></select></th>
<th>
<select class="form-control factura-filter-select" name="creditoAsegurado">
<option value=""><?= lang('Facturas.todos')?></option>
<option value="0"><?= lang('Basic.global.no') ?></option>
<option value="1"><?= lang('Basic.global.yes') ?></option>
</select>
</th>
<th>
<select class="form-control factura-filter-select" name="estado">
<option value=""><?= lang('Facturas.todos')?></option>
<option value="borrador"><?= lang('Facturas.borrador') ?></option>
<option value="validada"><?= lang('Facturas.validada') ?></option>
</select>
</th>
<th>
<select class="form-control factura-filter-select" name="estado_pago">
<option value=""><?= lang('Facturas.todos')?></option>
<option value="pendiente"><?= lang('Facturas.pendiente') ?></option>
<option value="pagada"><?= lang('Facturas.pagada') ?></option>
<option value="insolvente"><?= lang('Facturas.insolvente') ?></option>
</select>
</th>
<th>
<select class="form-control factura-filter-select" name="forma_pago">
<option value=""><?= lang('Facturas.todos')?></option>
<option value="cheque"><?= lang('Facturas.cheque') ?></option>
<option value="compensada"><?= lang('Facturas.compensada') ?></option>
<option value="confirming"><?= lang('Facturas.confirming') ?></option>
<option value="giroDomiciliado"><?= lang('Facturas.giroDomiciliado') ?></option>
<option value="pagare"><?= lang('Facturas.pagare') ?></option>
<option value="transferencia"><?= lang('Facturas.transferencia') ?></option>
</select>
</th>
<th></th>
<th></th>
<th><input type="text" class="form-control factura-filter" name="dias_vencimiento"></th>
<?php endif; ?>
<th></th>
</tr>
</thead>
<tbody>
@ -71,13 +103,31 @@
<?= $this->endSection() ?>
<?= $this->section('additionalInlineJs') ?>
window.datepickerLang = <?= $datepickerLang; ?>;
window.datepickerLocale ='<?= $datepickerLocale; ?>';
<?= $this->endSection() ?>
<?= $this->section('css') ?>
<link rel="stylesheet"
href="<?= site_url("/themes/vuexy/vendor/libs/datatables-sk/plugins/buttons/buttons.bootstrap5.min.css") ?>">
<link rel="stylesheet"
href="<?= site_url("/themes/vuexy/vendor/libs/datatables-sk/plugins/fixedheader/fixedHeader.dataTables.min.css") ?>">
<link rel="stylesheet"
href="<?= site_url('themes/vuexy/vendor/libs/bootstrap-daterangepicker/bootstrap-daterangepicker.css') ?>" />
<?= $this->endSection() ?>
<?= $this->section('additionalExternalJs') ?>
<script src="<?= site_url('themes/vuexy/vendor/libs/moment/moment.js') ?>"></script>
<script
src="<?= site_url('themes/vuexy/vendor/libs/bootstrap-daterangepicker/bootstrap-daterangepicker.js') ?>"></script>
<script
src="<?= site_url("/themes/vuexy/vendor/libs/datatables-sk/plugins/buttons/dataTables.buttons.min.js") ?>"></script>
<script

View File

@ -86,13 +86,13 @@
<label class="form-label"><?= lang('Tickets.prioridad') ?></label>
<select id="prioridad" name="prioridad" class="form-control">
<option value="baja" <?= $ticket->prioridad == 'baja' ? ' selected' : '' ?>>
<?= lang('Tickets.alta') ?>
<?= lang('Tickets.baja') ?>
</option>
<option value="media" <?= $ticket->prioridad == 'media' ? ' selected' : '' ?>>
<?= lang('Tickets.media') ?>
</option>
<option value="alta" <?= $ticket->prioridad == 'alta' ? ' selected' : '' ?>>
<?= lang('Tickets.baja') ?>
<?= lang('Tickets.alta') ?>
</option>
</select>
</div>