Files
safekat/ci4/app/Controllers/Presupuestos/Importadorpresupuestos.php

88 lines
2.9 KiB
PHP

<?php
namespace App\Controllers\Presupuestos;
use App\Models\Presupuestos\ImportadorModel;
use App\Models\Clientes\ClienteModel;
class Importadorpresupuestos extends \App\Controllers\BaseResourceController
{
protected $modelName = "ImportadorModel";
protected $format = 'json';
protected static $singularObjectName = 'Importadorpresupuesto';
protected static $singularObjectNameCc = 'Importadorpresupuesto';
protected static $pluralObjectName = 'ImportadorPresupuestos';
protected static $pluralObjectNameCc = 'Importadorpresupuestos';
protected static $controllerSlug = 'importadorpresupuestos';
protected static $viewPath = 'themes/vuexy/form/presupuestos/importador/';
protected $indexRoute = 'listaPresupuestos';
public function initController(\CodeIgniter\HTTP\RequestInterface $request, \CodeIgniter\HTTP\ResponseInterface $response, \Psr\Log\LoggerInterface $logger)
{
$this->viewData['usingSweetAlert'] = true;
$this->viewData = ['usingServerSideDataTable' => true]; // JJO
// Breadcrumbs
$this->viewData['breadcrumb'] = [
['title' => lang("App.menu_presupuestos"), 'route' => "javascript:void(0);", 'active' => false],
['title' => "Listado", 'route' => site_url('presupuestocliente/list'), 'active' => true]
];
$this->messageService = service('messages');
parent::initController($request, $response, $logger);
$this->model = new ImportadorModel();
}
public function index()
{
$viewData = [
'currentModule' => static::$controllerSlug,
'pageSubTitle' => lang('Basic.global.ManageAllRecords', [lang('Presupuestos.moduleName')]),
];
$viewData = array_merge($this->viewData, $viewData); // merge any possible values from the parent controller class
return view(static::$viewPath . 'viewImportadorPresupuestos', $viewData);
}
public function getClientList()
{
$search = "";
if ($this->request->getGet("q")) {
$search = $this->request->getGet("q");
}
$dataOld = (new ImportadorModel())->getClientList();
$dataNew = (new ClienteModel())->getIdName($search);
$newKeys = array_map(fn($item) => $item->id . '_' . $item->name, $dataNew);
// Filtrar $dataOld para obtener solo los elementos comunes
$commonData = array_filter($dataOld, fn($item) => in_array($item->id . '_' . $item->name, $newKeys));
return $this->response->setJSON(array_values($commonData));
}
public function getPresupuestosList(){
$search = "";
if ($this->request->getGet("q")) {
$search = $this->request->getGet("q");
}
$clienteId = $this->request->getGet("clienteId");
$data = (new ImportadorModel())->getPresupuestosList($clienteId, $search);
return $this->response->setJSON($data);
}
}