mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
mejorada la vista de lista de facturas
This commit is contained in:
@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -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){
|
||||
|
||||
Reference in New Issue
Block a user