mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
Primeros pasos del buscador (estructura, controlador, modelo y vista
This commit is contained in:
@ -512,10 +512,10 @@ $routes->group('clientedirecciones', ['namespace' => 'App\Controllers\Clientes']
|
||||
});
|
||||
$routes->resource('clientedirecciones', ['namespace' => 'App\Controllers\Clientes', 'controller' => 'Clientedirecciones', 'except' => 'show,new,create,update']);
|
||||
|
||||
|
||||
|
||||
$routes->group('cosidotapablanda', ['namespace' => 'App\Controllers\Presupuestos'], function ($routes) {
|
||||
$routes->get('list/(:num)', 'Cosidotapablanda::list/$1', ['as' => 'cosidotapablandaList']); // HOMOGENIZAR CON ARGS DINAMICOS!!!
|
||||
$routes->get('add/(:num)', 'Cosidotapablanda::add/$1', ['as' => 'newCosidotapablanda']);
|
||||
$routes->get('add/(:num)', 'Cosidotapablanda::add/$1', ['as' => 'newCosidotapablanda']);
|
||||
$routes->post('add/(:num)', 'Cosidotapablanda::add/$1', ['as' => 'createCosidotapablanda']);
|
||||
$routes->post('create', 'Cosidotapablanda::create', ['as' => 'ajaxCreateCosidotapablanda']);
|
||||
$routes->put('(:num)/update', 'Cosidotapablanda::update/$1', ['as' => 'ajaxUpdateCosidotapablanda']);
|
||||
@ -560,7 +560,18 @@ $routes->group(
|
||||
function ($routes) {
|
||||
$routes->get('index/(:num)', 'PrintPresupuestos::index/$1', ['as' => 'viewPresupuesto']);
|
||||
$routes->get('generar/(:num)', 'PrintPresupuestos::generar/$1', ['as' => 'presupuestoToPdf']);
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
$routes->group(
|
||||
'buscadorpresupuestos',
|
||||
['namespace' => 'App\Controllers\Presupuestos'],
|
||||
function ($routes) {
|
||||
$routes->get('', 'Buscador::list', ['as' => 'buscadorPresupuestosList']);
|
||||
$routes->post('datatable', 'Buscador::datatable', ['as' => 'dataTableOfBuscador']);
|
||||
}
|
||||
);
|
||||
$routes->resource('buscadorpresupuestos', ['namespace' => 'App\Controllers\Presupuestos', 'controller' => 'Buscador', 'except' => 'show,new,create,update']);
|
||||
|
||||
|
||||
/*
|
||||
|
||||
463
ci4/app/Controllers/Presupuestos/Buscador.php
Normal file
463
ci4/app/Controllers/Presupuestos/Buscador.php
Normal file
@ -0,0 +1,463 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers\Presupuestos;
|
||||
|
||||
use App\Controllers\GoBaseResourceController;
|
||||
use App\Entities\Configuracion\Maquina;
|
||||
use App\Models\Collection;
|
||||
|
||||
use App\Entities\Presupuestos\PresupuestoEntity;
|
||||
use App\Models\Presupuestos\BuscadorModel;
|
||||
use App\Models\Presupuestos\PresupuestoDireccionesModel;
|
||||
use App\Models\Configuracion\PapelGenericoModel;
|
||||
use App\Models\Configuracion\TipoPresupuestoModel;
|
||||
use App\Models\Presupuestos\PresupuestoModel;
|
||||
|
||||
|
||||
use App\Services\PresupuestoService;
|
||||
use App\Models\Configuracion\PapelImpresionModel;
|
||||
use App\Models\Configuracion\MaquinaModel;
|
||||
use Exception;
|
||||
|
||||
class Buscador extends \App\Controllers\GoBaseResourceController
|
||||
{
|
||||
|
||||
protected $modelName = "BuscadorModel";
|
||||
protected $format = 'json';
|
||||
|
||||
protected static $singularObjectName = 'Buscador';
|
||||
protected static $singularObjectNameCc = 'buscador';
|
||||
protected static $pluralObjectName = 'Buscadores';
|
||||
protected static $pluralObjectNameCc = 'buscadores';
|
||||
|
||||
protected static $controllerSlug = 'buscador';
|
||||
|
||||
protected static $viewPath = 'themes/backend/vuexy/form/presupuestos/buscador/';
|
||||
|
||||
protected $indexRoute = 'buscadorPresupuestosList';
|
||||
|
||||
|
||||
|
||||
public function initController(\CodeIgniter\HTTP\RequestInterface $request, \CodeIgniter\HTTP\ResponseInterface $response, \Psr\Log\LoggerInterface $logger)
|
||||
{
|
||||
|
||||
$this->viewData['usingSweetAlert'] = true;
|
||||
|
||||
// Se indica que este controlador trabaja con soft_delete
|
||||
$this->soft_delete = true;
|
||||
// Se indica el flag para los ficheros borrados
|
||||
$this->delete_flag = 1;
|
||||
|
||||
$this->viewData = ['usingServerSideDataTable' => true]; // JJO
|
||||
|
||||
// Breadcrumbs (IMN)
|
||||
$this->viewData['breadcrumb'] = [
|
||||
['title' => lang("App.menu_presupuestos"), 'route' => "javascript:void(0);", 'active' => false],
|
||||
['title' => lang("App.menu_presupuesto_buscador"), 'route' => site_url('presupuestos/buscador'), 'active' => true]
|
||||
];
|
||||
|
||||
parent::initController($request, $response, $logger);
|
||||
$this->model = new BuscadorModel();
|
||||
}
|
||||
|
||||
|
||||
public function index()
|
||||
{
|
||||
$viewData = [
|
||||
'currentModule' => static::$controllerSlug,
|
||||
'pageSubTitle' => lang('Basic.global.ManageAllRecords', [lang('Presupuestos.presupuesto')]),
|
||||
'presupuestoEntity' => new PresupuestoEntity(),
|
||||
'usingServerSideDataTable' => true
|
||||
];
|
||||
|
||||
$viewData = array_merge($this->viewData, $viewData); // merge any possible values from the parent controller class
|
||||
|
||||
return view(static::$viewPath . 'viewBuscadorList', $viewData);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public function datatable()
|
||||
{
|
||||
if ($this->request->isAJAX()) {
|
||||
$reqData = $this->request->getPost();
|
||||
|
||||
$type = $reqData['type'] ?? null;
|
||||
|
||||
if (is_null($type)) {
|
||||
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;
|
||||
}
|
||||
$search = $reqData['search']['value'];
|
||||
}
|
||||
$start = $reqData['start'] ?? 0;
|
||||
$length = $reqData['length'] ?? 5;
|
||||
|
||||
$requestedOrder1 = $reqData['order']['0']['column'] ?? 0;
|
||||
$order1 = PresupuestoModel::SORTABLE[$requestedOrder1 >= 0 ? $requestedOrder1 : 0];
|
||||
$dir1 = $reqData['order']['0']['dir'] ?? 'asc';
|
||||
$requestedOrder2 = $reqData['order']['1']['column'] ?? 0;
|
||||
$order2 = PresupuestoModel::SORTABLE[$requestedOrder2 >= 0 ? $requestedOrder1 : 0];
|
||||
$dir2 = $reqData['order']['0']['dir'] ?? 'asc';
|
||||
$requestedOrder3 = $reqData['order']['2']['column'] ?? 0;
|
||||
$order3 = PresupuestoModel::SORTABLE[$requestedOrder3 >= 0 ? $requestedOrder1 : 0];
|
||||
$dir3 = $reqData['order']['0']['dir'] ?? 'asc';
|
||||
|
||||
// por defecto, se deja cosido tapa blanda por ahora JJO
|
||||
$tipo_impresion_id = $reqData['tipo_impresion_id'] ?? 4;
|
||||
|
||||
if (is_null($type)) {
|
||||
|
||||
$searchValues = get_filter_datatables_columns($reqData);
|
||||
|
||||
$resourceData = $this->model->getResource($searchValues, $tipo_impresion_id)->orderBy($order1, $dir1)->orderBy($order2, $dir2)
|
||||
->orderBy($order3, $dir3)->limit($length, $start)->get()->getResultObject();
|
||||
foreach ($resourceData as $item) :
|
||||
if (isset($item->comentarios_pdf) && strlen($item->comentarios_pdf) > 100) :
|
||||
$item->comentarios_pdf = character_limiter($item->comentarios_pdf, 100);
|
||||
endif;
|
||||
if (isset($item->causa_cancelacion) && strlen($item->causa_cancelacion) > 100) :
|
||||
$item->causa_cancelacion = character_limiter($item->causa_cancelacion, 100);
|
||||
endif;
|
||||
if (isset($item->comentarios_cliente) && strlen($item->comentarios_cliente) > 100) :
|
||||
$item->comentarios_cliente = character_limiter($item->comentarios_cliente, 100);
|
||||
endif;
|
||||
if (isset($item->comentarios_safekat) && strlen($item->comentarios_safekat) > 100) :
|
||||
$item->comentarios_safekat = character_limiter($item->comentarios_safekat, 100);
|
||||
endif;
|
||||
if (isset($item->comentarios_tarifa) && strlen($item->comentarios_tarifa) > 100) :
|
||||
$item->comentarios_tarifa = character_limiter($item->comentarios_tarifa, 100);
|
||||
endif;
|
||||
if (isset($item->comentarios_produccion) && strlen($item->comentarios_produccion) > 100) :
|
||||
$item->comentarios_produccion = character_limiter($item->comentarios_produccion, 100);
|
||||
endif;
|
||||
if (isset($item->tirada_alternativa_json_data) && strlen($item->tirada_alternativa_json_data) > 100) :
|
||||
$item->tirada_alternativa_json_data = character_limiter($item->tirada_alternativa_json_data, 100);
|
||||
endif;
|
||||
if (isset($item->titulo) && strlen($item->titulo) > 100) :
|
||||
$item->titulo = character_limiter($item->titulo, 100);
|
||||
endif;
|
||||
if (isset($item->paginas_color_posicion) && strlen($item->paginas_color_posicion) > 100) :
|
||||
$item->paginas_color_posicion = character_limiter($item->paginas_color_posicion, 100);
|
||||
endif;
|
||||
if (isset($item->aprobado_json_data) && strlen($item->aprobado_json_data) > 100) :
|
||||
$item->aprobado_json_data = character_limiter($item->aprobado_json_data, 100);
|
||||
endif;
|
||||
if (isset($item->comparador_json_data) && strlen($item->comparador_json_data) > 100) :
|
||||
$item->comparador_json_data = character_limiter($item->comparador_json_data, 100);
|
||||
endif;
|
||||
if (isset($item->ws_externo_json_data) && strlen($item->ws_externo_json_data) > 100) :
|
||||
$item->ws_externo_json_data = character_limiter($item->ws_externo_json_data, 100);
|
||||
endif;
|
||||
endforeach;
|
||||
} else {
|
||||
|
||||
$isColor = $reqData['color'] ?? false;
|
||||
$isHq = $reqData['hq'] ?? false;
|
||||
|
||||
$datosPedido = (object)array(
|
||||
'paginas' => intval($reqData['paginas']) ?? 0,
|
||||
'tirada' => intval($reqData['tirada']) ?? 0,
|
||||
'merma' => intval($reqData['merma']) ?? 0,
|
||||
'ancho' => intval($reqData['ancho']) ?? 100000,
|
||||
'alto' => intval($reqData['alto']) ?? 100000,
|
||||
'a_favor_fibra' => $reqData['a_favor_fibra'] ?? 1,
|
||||
'isCosido' => (new TipoPresupuestoModel())->get_isCosido($tipo_impresion_id), // JJO esto es custom por cada tipo de presupuesto
|
||||
);
|
||||
|
||||
$papel_generico = [
|
||||
'id' => $reqData['papel_generico_id'] ?? 0,
|
||||
'nombre' => $reqData['papel_generico'] ?? "",
|
||||
];
|
||||
|
||||
$gramaje = $reqData['gramaje'] ?? 0;
|
||||
|
||||
$cliente_id = $reqData['cliente_id'] ?? -1;
|
||||
|
||||
|
||||
|
||||
if ($type=='interior' || $type=='guardas') {
|
||||
|
||||
$datosTipolog = $reqData['negro'] ?? null;
|
||||
if(!is_null($datosTipolog)){
|
||||
$datosTipolog = [];
|
||||
$data = (object)array(
|
||||
'negro' => intval($reqData['negro']) ?? 0,
|
||||
'cyan' => intval($reqData['cyan']) ?? 0,
|
||||
'magenta' => intval($reqData['magenta']) ?? 0,
|
||||
'amarillo' => intval($reqData['amarillo']) ?? 0,
|
||||
'cg' => intval($reqData['cg']) ?? 0,
|
||||
'gota_negro' => intval($reqData['gota_negro']) ?? 0,
|
||||
'gota_color' => intval($reqData['gota_color']) ?? 0,
|
||||
);
|
||||
array_push($datosTipolog, $data);
|
||||
}
|
||||
|
||||
if ($type=='guardas') {
|
||||
$datosPedido->paginas_impresion = intval($reqData['paginas_impresion']) ?? 0;
|
||||
// Para el caso de Fresado y Cosido tapa dura, las guardas son un diptico
|
||||
// y hay que imprimirlas como "cosido" (dos hojas pegadas). En el caso de espiral
|
||||
// o wire-o tapa dura, las guardas se imprimen como hojas sueltas
|
||||
if($tipo_impresion_id == 1 || $tipo_impresion_id == 3){
|
||||
$datosPedido->isCosido = true;
|
||||
}else if ($tipo_impresion_id == 5 || $tipo_impresion_id == 7){
|
||||
$datosPedido->isCosido = false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$a_favor_fibra = $reqData['a_favor_fibra'] ?? false;
|
||||
|
||||
$resourceData = $this->getCompIntData($type, $datosPedido, $papel_generico, $gramaje, $isColor, $isHq, $cliente_id, $datosTipolog, $a_favor_fibra);
|
||||
|
||||
$newTokenHash = csrf_hash();
|
||||
$csrfTokenName = csrf_token();
|
||||
$data = [
|
||||
'lineas' => $resourceData,
|
||||
$csrfTokenName => $newTokenHash
|
||||
];
|
||||
|
||||
return $this->respond($data);
|
||||
}
|
||||
else if ($type=='interior_rot') {
|
||||
|
||||
$paginas = (object)array(
|
||||
'negro' => intval($reqData['paginas_negro']) ?? 0,
|
||||
'color' => intval($reqData['paginas_color']) ?? 0,
|
||||
);
|
||||
|
||||
$datosTipolog = $reqData['negro'] ?? null;
|
||||
if(!is_null($datosTipolog)){
|
||||
$datosTipolog = [];
|
||||
$data = (object)array(
|
||||
'negro' => intval($reqData['negro']) ?? 0,
|
||||
'cyan' => intval($reqData['cyan']) ?? 0,
|
||||
'magenta' => intval($reqData['magenta']) ?? 0,
|
||||
'amarillo' => intval($reqData['amarillo']) ?? 0,
|
||||
'gota_negro' => intval($reqData['gota_negro']) ?? 0,
|
||||
'gota_color' => intval($reqData['gota_color']) ?? 0,
|
||||
);
|
||||
array_push($datosTipolog, $data);
|
||||
}
|
||||
|
||||
$resourceData = $this->getCompIntRotData($datosPedido, $papel_generico, $gramaje, $paginas, $cliente_id, $datosTipolog);
|
||||
|
||||
$newTokenHash = csrf_hash();
|
||||
$csrfTokenName = csrf_token();
|
||||
$data = [
|
||||
'lineas' => $resourceData,
|
||||
$csrfTokenName => $newTokenHash
|
||||
];
|
||||
|
||||
return $this->respond($data);
|
||||
}
|
||||
else if ($type=='cubierta' || $type=='sobrecubierta') {
|
||||
|
||||
$datosPedido->solapas = $reqData['solapas'];
|
||||
$datosPedido->solapas_ancho = $reqData['solapas_ancho'];
|
||||
$datosPedido->lomo = $reqData['lomo'];
|
||||
|
||||
if($type=='sobrecubierta')
|
||||
$datosPedido->lomo_cubierta = $reqData['lomo_cubierta'];
|
||||
|
||||
$datosPedido->anchoExteriores = PresupuestoService::getAnchoTotalExteriores($tipo_impresion_id, $datosPedido);
|
||||
$datosPedido->altoExteriores = PresupuestoService::getAltoTotalExteriores($tipo_impresion_id, $datosPedido);
|
||||
// Cubierta y sobrecubierta siempre color HQ
|
||||
$resourceData = $this->getCompIntData($type, $datosPedido, $papel_generico, $gramaje, $isColor, 1, $cliente_id);
|
||||
|
||||
$newTokenHash = csrf_hash();
|
||||
$csrfTokenName = csrf_token();
|
||||
$data = [
|
||||
'lineas' => $resourceData,
|
||||
$csrfTokenName => $newTokenHash
|
||||
];
|
||||
|
||||
return $this->respond($data);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return $this->respond(Collection::datatable(
|
||||
$resourceData,
|
||||
$this->model->getResource("", $tipo_impresion_id)->countAllResults(),
|
||||
$this->model->getResource($search, $tipo_impresion_id)->countAllResults()
|
||||
));
|
||||
} else {
|
||||
return $this->failUnauthorized('Invalid request', 403);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function datatable_2()
|
||||
{
|
||||
if ($this->request->isAJAX()) {
|
||||
$reqData = $this->request->getPost();
|
||||
|
||||
$tipo = $reqData['tipo'] ?? '';
|
||||
|
||||
if($tipo=='lineasPresupuesto'){
|
||||
|
||||
$model = model('App\Models\Presupuestos\PresupuestoLineaModel');
|
||||
|
||||
$datos = $reqData['datos'] ?? null;
|
||||
|
||||
$presupuesto_id = $reqData['presupuesto_id'] ?? -1;
|
||||
|
||||
$model->where("presupuesto_id", $presupuesto_id)->delete();
|
||||
|
||||
if($datos != null){
|
||||
|
||||
$model->insertLineasPresupuesto($presupuesto_id, $datos);
|
||||
}
|
||||
$newTokenHash = csrf_hash();
|
||||
$csrfTokenName = csrf_token();
|
||||
$data = [
|
||||
$csrfTokenName => $newTokenHash
|
||||
];
|
||||
|
||||
return $this->respond($data);
|
||||
}
|
||||
|
||||
$newTokenHash = csrf_hash();
|
||||
$csrfTokenName = csrf_token();
|
||||
$data = [
|
||||
$csrfTokenName => $newTokenHash
|
||||
];
|
||||
|
||||
return $this->respond($data);
|
||||
|
||||
} else {
|
||||
return $this->failUnauthorized('Invalid request', 403);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function allItemsSelect()
|
||||
{
|
||||
if ($this->request->isAJAX()) {
|
||||
$onlyActiveOnes = true;
|
||||
$reqVal = $this->request->getPost('val') ?? 'id';
|
||||
$menu = $this->model->getAllForMenu($reqVal . ', titulo', 'titulo', $onlyActiveOnes, false);
|
||||
$nonItem = new \stdClass;
|
||||
$nonItem->id = '';
|
||||
$nonItem->titulo = '- ' . lang('Basic.global.None') . ' -';
|
||||
array_unshift($menu, $nonItem);
|
||||
|
||||
$newTokenHash = csrf_hash();
|
||||
$csrfTokenName = csrf_token();
|
||||
$data = [
|
||||
'menu' => $menu,
|
||||
$csrfTokenName => $newTokenHash
|
||||
];
|
||||
return $this->respond($data);
|
||||
} else {
|
||||
return $this->failUnauthorized('Invalid request', 403);
|
||||
}
|
||||
}
|
||||
|
||||
public function menuItems()
|
||||
{
|
||||
if ($this->request->isAJAX()) {
|
||||
|
||||
$reqData = $this->request->getPost();
|
||||
try{
|
||||
|
||||
$tipo = $reqData['tipo'] ?? null;
|
||||
$uso = $reqData['uso'] ?? null;
|
||||
$datos = $reqData['datos'] ?? null;
|
||||
//$searchStr = goSanitize($this->request->getPost('searchTerm'))[0];
|
||||
|
||||
$newTokenHash = csrf_hash();
|
||||
$csrfTokenName = csrf_token();
|
||||
|
||||
if ($tipo == 'gramaje') {
|
||||
// En este caso contiene el nombre del papel generico
|
||||
$tirada = $reqData['tirada'] ?? 0;
|
||||
$merma = $reqData['merma'] ?? 0;
|
||||
$model = new PapelGenericoModel();
|
||||
$menu = $model->getGramajeComparador($datos, $uso, intval($tirada+$merma) );
|
||||
|
||||
$data = [
|
||||
'menu' => $menu,
|
||||
$csrfTokenName => $newTokenHash
|
||||
];
|
||||
}
|
||||
elseif ($tipo == 'gramajeLineasPresupuesto') {
|
||||
$tipoLinea = $reqData['tipoLinea'] ?? null;
|
||||
// En este caso contiene el id del papel generico
|
||||
$model = new PapelGenericoModel();
|
||||
$menu = $model->getGramajeLineasPresupuesto($datos, $tipoLinea, $uso );
|
||||
|
||||
$data = [
|
||||
'menu' => $menu,
|
||||
$csrfTokenName => $newTokenHash
|
||||
];
|
||||
}
|
||||
elseif ($tipo == 'papelImpresion') {
|
||||
$gramaje = $reqData['gramaje'] ?? null;
|
||||
$tipoLinea = $reqData['tipoLinea'] ?? null;
|
||||
// En este caso contiene el nombre del papel generico
|
||||
// Uso: negro, negrohq, color, colorhq, rot_bn, rot_color,
|
||||
$model = new PapelImpresionModel();
|
||||
$menu = $model->getPapelesImpresionForMenu($datos, $gramaje, $tipoLinea, $uso );
|
||||
|
||||
$data = [
|
||||
'menu' => $menu,
|
||||
$csrfTokenName => $newTokenHash
|
||||
];
|
||||
}
|
||||
|
||||
elseif ($tipo == 'maquina') {
|
||||
$is_rotativa = $reqData['is_rotativa'] ?? null;
|
||||
$papel_impresion = $reqData['papel_impresion'] ?? null;
|
||||
$tipo_linea = $reqData['tipoLinea'] ?? null;
|
||||
$ancho = $reqData['ancho'] ?? null;
|
||||
$alto = $reqData['alto'] ?? null;
|
||||
// Datos contiene la tirada
|
||||
// uso: negro, negrohq, color, colorhq,
|
||||
$uso_tarifa = $reqData['uso_tarifa'] ?? 'interior';
|
||||
$model = new MaquinaModel();
|
||||
$maquinas = $model->getMaquinaImpresionForPresupuesto($is_rotativa, $uso, $uso_tarifa ,$datos, $papel_impresion );
|
||||
$menu = [];
|
||||
foreach ($maquinas as $maquina){
|
||||
|
||||
$formas = PresupuestoService::getNumFormasPlana($tipo_linea, $maquina, floatval($ancho), floatval($alto), true);
|
||||
|
||||
if($formas['num_formas'] != 'n/a'){
|
||||
array_push($menu, $maquina);
|
||||
}
|
||||
}
|
||||
|
||||
$data = [
|
||||
'menu' => $menu,
|
||||
$csrfTokenName => $newTokenHash
|
||||
];
|
||||
}
|
||||
|
||||
else{
|
||||
|
||||
$data = [
|
||||
'tipo' => $tipo,
|
||||
$csrfTokenName => $newTokenHash
|
||||
];
|
||||
}
|
||||
}
|
||||
catch(Exception $e){
|
||||
$data = [
|
||||
'error' => $e,
|
||||
$csrfTokenName => $newTokenHash
|
||||
];
|
||||
}
|
||||
finally{
|
||||
return $this->respond($data);
|
||||
}
|
||||
|
||||
} else {
|
||||
return $this->failUnauthorized('Invalid request', 403);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -741,6 +741,7 @@ return [
|
||||
|
||||
"menu_presupuestos" => "Presupuestos",
|
||||
"menu_presupuesto" => "Libros",
|
||||
"menu_presupuesto_buscador" => "Buscador",
|
||||
"menu_libros" => "Libros",
|
||||
"menu_libros_fresasdo_tapa_dura" => "Fresado tapa dura",
|
||||
"menu_libros_fresasdo_tapa_blanda" => "Fresado tapa blanda",
|
||||
|
||||
191
ci4/app/Models/Presupuestos/BuscadorModel.php
Normal file
191
ci4/app/Models/Presupuestos/BuscadorModel.php
Normal file
@ -0,0 +1,191 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Presupuestos;
|
||||
|
||||
class BuscadorModel extends \App\Models\GoBaseModel
|
||||
{
|
||||
protected $table = "presupuestos";
|
||||
|
||||
/**
|
||||
* Whether primary key uses auto increment.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $useAutoIncrement = true;
|
||||
|
||||
const SORTABLE = [
|
||||
0 => "t1.id",
|
||||
1 => "t1.created_at",
|
||||
2 => "t2.nombre",
|
||||
3 => "t3.first_name",
|
||||
4 => "t1.titulo",
|
||||
5 => "t5.nombre",
|
||||
6 => "t1.inc_rei",
|
||||
7 => "t1.paginas",
|
||||
8 => "t1.tirada",
|
||||
9 => "t1.total_presupuesto",
|
||||
10 => "t6.estado",
|
||||
];
|
||||
|
||||
protected $allowedFields = [
|
||||
"cliente_id",
|
||||
"user_created_id",
|
||||
"user_update_id",
|
||||
"tipo_impresion_id",
|
||||
"tipologia_id",
|
||||
"pais_id",
|
||||
"estado_id",
|
||||
"inc_rei",
|
||||
"causa_cancelacion",
|
||||
"retractilado",
|
||||
"retractilado5",
|
||||
"guardas",
|
||||
"faja_color",
|
||||
"recoger_en_taller",
|
||||
"ferro",
|
||||
"ferro_digital",
|
||||
"marcapaginas",
|
||||
"prototipo",
|
||||
"papel_formato_id",
|
||||
"papel_formato_personalizado",
|
||||
"papel_formato_ancho",
|
||||
"papel_formato_alto",
|
||||
"titulo",
|
||||
"autor",
|
||||
"coleccion",
|
||||
"numero_edicion",
|
||||
"isbn",
|
||||
"referencia_cliente",
|
||||
"paginas",
|
||||
"tirada",
|
||||
"solapas",
|
||||
"solapas_ancho",
|
||||
"cosido",
|
||||
"sobrecubiertas",
|
||||
"sobrecubiertas_ancho",
|
||||
"merma",
|
||||
"merma_cubierta",
|
||||
"comentarios_cliente",
|
||||
"comentarios_safekat",
|
||||
"comentarios_pdf",
|
||||
"comentarios_tarifa",
|
||||
"comentarios_produccion",
|
||||
"lomo",
|
||||
"total_presupuesto",
|
||||
"envios_recoge_cliente",
|
||||
"tirada_alternativa_json_data",
|
||||
"aprobado_user_id",
|
||||
"aprobado_at",
|
||||
"comparador_json_data",
|
||||
"is_deleted",
|
||||
"comp_tipo_impresion",
|
||||
"comp_pos_paginas_color",
|
||||
"total_coste_papel",
|
||||
"total_margen_papel",
|
||||
"total_margenPercent_papel",
|
||||
"total_coste_impresion",
|
||||
"total_margen_impresion",
|
||||
"total_margenPercent_impresion",
|
||||
"total_coste_servicios",
|
||||
"total_margen_servicios",
|
||||
"total_margenPercent_servicios",
|
||||
"total_coste_envios",
|
||||
"total_margen_envios",
|
||||
"total_costes",
|
||||
"total_margenes",
|
||||
"total_antes_descuento",
|
||||
"total_descuento",
|
||||
"total_descuentoPercent",
|
||||
"total_presupuesto",
|
||||
"total_precio_unidad",
|
||||
];
|
||||
protected $returnType = "App\Entities\Presupuestos\PresupuestoEntity";
|
||||
|
||||
protected $useTimestamps = true;
|
||||
protected $useSoftDeletes = false;
|
||||
|
||||
protected $createdField = "created_at";
|
||||
|
||||
protected $updatedField = "updated_at";
|
||||
|
||||
public static $labelField = "titulo";
|
||||
|
||||
|
||||
public function findAllWithAllRelations(string $selcols = "*", int $limit = null, int $offset = 0)
|
||||
{
|
||||
$sql =
|
||||
"SELECT t1." .
|
||||
$selcols .
|
||||
", t2.nombre AS cliente, t3.nombre AS forma_pago, t4.nombre AS tipo_impresion, t5.nombre AS tipologia, t6.nombre AS pais, t7.estado AS estado, t8.id AS papel_formato, t9.first_name AS total_confirmado_user, t10.first_name AS aprobado_user FROM " .
|
||||
$this->table .
|
||||
" t1 LEFT JOIN clientes
|
||||
t2 ON t1.cliente_id = t2.id LEFT JOIN lg_formas_pago
|
||||
t3 ON t1.forma_pago_id = t3.id LEFT JOIN lg_tipos_impresion
|
||||
t4 ON t1.tipo_impresion_id = t4.id LEFT JOIN lg_tipologias_libros
|
||||
t5 ON t1.tipologia_id = t5.id LEFT JOIN lg_paises
|
||||
t6 ON t1.pais_id = t6.id = t7.id LEFT JOIN presupuesto_estados
|
||||
t7 ON t1.estado_id = t8.id LEFT JOIN lg_papel_formato
|
||||
t8 ON t1.papel_formato_id = t9.id LEFT JOIN lg_papel_generico
|
||||
t9 ON t1.total_confirmado_user_id = t26.id_user LEFT JOIN auth_user
|
||||
t10 ON t1.aprobado_user_id = t27.id_user LEFT JOIN auth_user";
|
||||
|
||||
if (!is_null($limit) && intval($limit) > 0) {
|
||||
$sql .= " LIMIT " . intval($limit);
|
||||
}
|
||||
|
||||
if (!is_null($offset) && intval($offset) > 0) {
|
||||
$sql .= " OFFSET " . intval($offset);
|
||||
}
|
||||
|
||||
$query = $this->db->query($sql);
|
||||
$result = $query->getResultObject();
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get resource data.
|
||||
*
|
||||
* @param string $search
|
||||
*
|
||||
* @return \CodeIgniter\Database\BaseBuilder
|
||||
*/
|
||||
public function getResource($search = [])
|
||||
{
|
||||
$builder = $this->db
|
||||
->table($this->table . " t1")
|
||||
->select(
|
||||
"t1.id AS id, t1.created_at AS fecha, t2.nombre AS cliente,
|
||||
CONCAT(t3.first_name, ' ', t3.last_name) AS comercial, t1.titulo AS titulo,
|
||||
t5.nombre AS pais, t1.inc_rei AS inc_rei, t1.paginas AS paginas, t1.tirada AS tirada,
|
||||
t1.total_presupuesto AS total_presupuesto, t1.total_presupuesto AS total_presupuesto,
|
||||
t6.estado AS estado"
|
||||
);
|
||||
$builder->join("clientes t2", "t1.cliente_id = t2.id", "left");
|
||||
$builder->join("auth_user t3", "t1.user_update_id = t3.id_user", "left");
|
||||
$builder->join("lg_paises t5", "t1.pais_id = t5.id", "left");
|
||||
$builder->join("presupuesto_estados t6", "t1.estado_id = t6.id", "left");
|
||||
|
||||
$builder->where("t1.is_deleted", 0);
|
||||
|
||||
if (empty($search))
|
||||
return $builder;
|
||||
else {
|
||||
$builder->groupStart();
|
||||
foreach ($search as $col_search) {
|
||||
if ($col_search[0] != 1)
|
||||
$builder->like(self::SORTABLE[$col_search[0]], $col_search[2]);
|
||||
else {
|
||||
$dates = explode(" ", $col_search[2]);
|
||||
$builder->where(self::SORTABLE[$col_search[0]] . ">=", $dates[0]);
|
||||
$builder->where(self::SORTABLE[$col_search[0]] . "<=", $dates[1]);
|
||||
}
|
||||
}
|
||||
$builder->groupEnd();
|
||||
return $builder;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,268 @@
|
||||
<?=$this->include('themes/_commonPartialsBs/select2bs5') ?>
|
||||
<?=$this->include('themes/_commonPartialsBs/datatables') ?>
|
||||
<?=$this->include('themes/_commonPartialsBs/sweetalert') ?>
|
||||
<?= $this->include('themes/_commonPartialsBs/_confirm2delete') ?>
|
||||
<?= $this->extend('themes/backend/vuexy/main/defaultlayout') ?>
|
||||
<?=$this->section('content'); ?>
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
|
||||
<div class="card card-info">
|
||||
<div class="card-header">
|
||||
<h3 class="card-title"><?= $pageTitle ?></h3>
|
||||
</div><!--//.card-header -->
|
||||
<div class="card-body">
|
||||
<?= view('themes/_commonPartialsBs/_alertBoxes'); ?>
|
||||
|
||||
<table id="tableOfPresupuestos" class="table table-striped table-hover" style="width: 100%;">
|
||||
<thead>
|
||||
<tr>
|
||||
<th><?=lang('Presupuestos.id')?></th>
|
||||
<th><?= lang('Presupuestos.created_at') ?></th>
|
||||
<th><?= lang('Clientes.cliente') ?></th>
|
||||
<th><?= lang('Presupuestos.comercial') ?></th>
|
||||
<th><?= lang('Presupuestos.titulo') ?></th>
|
||||
<th><?= lang('Paises.pais') ?></th>
|
||||
<th><?= lang('Presupuestos.incRei') ?></th>
|
||||
<th class='noFilter'><?= lang('Presupuestos.paginas') ?></th>
|
||||
<th class='noFilter'><?= lang('Presupuestos.tirada') ?></th>
|
||||
<th class='noFilter'><?= lang('Presupuestos.totalPresupuesto') ?></th>
|
||||
<th><?= lang('Presupuestos.presupuestoEstado') ?></th>
|
||||
<th class="noFilter text-nowrap"><?= lang('Basic.global.Action') ?></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
|
||||
</tbody>
|
||||
</table>
|
||||
</div><!--//.card-body -->
|
||||
<div class="card-footer">
|
||||
|
||||
</div><!--//.card-footer -->
|
||||
</div><!--//.card -->
|
||||
</div><!--//.col -->
|
||||
</div><!--//.row -->
|
||||
|
||||
<?=$this->endSection() ?>
|
||||
|
||||
|
||||
<?=$this->section('additionalInlineJs') ?>
|
||||
|
||||
const lastColNr = $('#tableOfPresupuestos').find("tr:first th").length - 1;
|
||||
const actionBtns = function(data) {
|
||||
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="${data.id}"></i></a>
|
||||
<a href="javascript:void(0);"><i class="ti ti-trash ti-sm btn-delete mx-2" data-id="${data.id}" data-bs-toggle="modal" data-bs-target="#confirm2delete"></i></a>
|
||||
</div>
|
||||
</td>`;
|
||||
};
|
||||
|
||||
// Setup - add a text input to each footer cell
|
||||
$('#tableOfPresupuestos thead tr').clone(true).appendTo('#tableOfPresupuestos thead');
|
||||
$('#tableOfPresupuestos thead tr:eq(1) th').each(function (i) {
|
||||
if (!$(this).hasClass("noFilter")) {
|
||||
var title = $(this).text();
|
||||
if(i==1){
|
||||
|
||||
$(this).html('<input id="bs-rangepicker-range" type="text" class="form-control " style="min-width:100px;max-width:120px;font-size:0.8rem !important;" />');
|
||||
var bsRangePickerRange = $('#bs-rangepicker-range')
|
||||
bsRangePickerRange.daterangepicker({
|
||||
ranges: {
|
||||
'<?= lang('datePicker.hoy') ?>': [moment(), moment()],
|
||||
'<?= lang('datePicker.ayer') ?>': [moment().subtract(1, 'days'), moment().subtract(1, 'days')],
|
||||
'<?= lang('datePicker.ultimos7') ?>': [moment().subtract(6, 'days'), moment()],
|
||||
'<?= lang('datePicker.ultimos30') ?>': [moment().subtract(29, 'days'), moment()],
|
||||
'<?= lang('datePicker.esteMes') ?>': [moment().startOf('month'), moment().endOf('month')],
|
||||
'<?= lang('datePicker.ultimoMes') ?>': [moment().subtract(1, 'month').startOf('month'), moment().subtract(1, 'month').endOf('month')]
|
||||
},
|
||||
opens: 'right',
|
||||
language: '<?= config('Basics')->i18n ?>',
|
||||
"locale": {
|
||||
"customRangeLabel": "<?= lang('datePicker.personalizar') ?>",
|
||||
"format": "YYYY-MM-DD",
|
||||
"separator": " ",
|
||||
"applyLabel": "<?= lang('datePicker.aplicar') ?>",
|
||||
"cancelLabel": "<?= lang('datePicker.limpiar') ?>",
|
||||
|
||||
},
|
||||
"alwaysShowCalendars": true,
|
||||
autoUpdateInput: false,
|
||||
|
||||
});
|
||||
|
||||
bsRangePickerRange.on('apply.daterangepicker', function(ev, picker) {
|
||||
$(this).val(picker.startDate.format('YYYY-MM-DD') + ' ' + picker.endDate.format('YYYY-MM-DD'));
|
||||
theTable
|
||||
.column(i)
|
||||
.search(this.value)
|
||||
.draw();
|
||||
});
|
||||
|
||||
bsRangePickerRange.on('cancel.daterangepicker', function(ev, picker) {
|
||||
$(this).val('');
|
||||
theTable
|
||||
.column(i)
|
||||
.search(this.value)
|
||||
.draw();
|
||||
});
|
||||
|
||||
}
|
||||
else{
|
||||
$(this).html('<input type="text" class="form-control " style="min-width:100px;max-width:120px;font-size:0.8rem !important;" />');
|
||||
|
||||
$('input', this).on('change clear', function () {
|
||||
if (theTable.column(i).search() !== this.value) {
|
||||
theTable
|
||||
.column(i)
|
||||
.search(this.value)
|
||||
.draw();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
else {
|
||||
$(this).html('<span></span>');
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
theTable = $('#tableOfPresupuestos').DataTable({
|
||||
orderCellsTop: true,
|
||||
fixedHeader: true,
|
||||
processing: true,
|
||||
serverSide: true,
|
||||
autoWidth: true,
|
||||
responsive: true,
|
||||
scrollX: true,
|
||||
lengthMenu: [ 5, 10, 25, 50, 75, 100, 250, 500, 1000, 2500 ],
|
||||
pageLength: 50,
|
||||
lengthChange: true,
|
||||
"dom": 'lBrtip',
|
||||
"buttons": [
|
||||
'colvis', 'copy', 'csv', 'excel', 'print', {
|
||||
extend: 'pdfHtml5',
|
||||
orientation: 'landscape',
|
||||
pageSize: 'A4'
|
||||
}
|
||||
],
|
||||
stateSave: false,
|
||||
order: [[1, 'asc']],
|
||||
language: {
|
||||
url: "//cdn.datatables.net/plug-ins/1.13.4/i18n/<?= config('Basics')->i18n ?>.json"
|
||||
},
|
||||
ajax : $.fn.dataTable.pipeline( {
|
||||
url: '<?= route_to('dataTableOfBuscador') ?>',
|
||||
method: 'POST',
|
||||
headers: {'X-Requested-With': 'XMLHttpRequest'},
|
||||
async: true,
|
||||
}),
|
||||
columnDefs: [
|
||||
{
|
||||
orderable: false,
|
||||
searchable: false,
|
||||
targets: [lastColNr]
|
||||
}
|
||||
],
|
||||
columns : [
|
||||
{ 'data': 'id' },
|
||||
{ 'data': 'fecha' },
|
||||
{ 'data': 'cliente' },
|
||||
{ 'data': 'comercial' },
|
||||
{ 'data': 'titulo' },
|
||||
{ 'data': 'pais' },
|
||||
{ 'data': 'inc_rei' },
|
||||
{ 'data': 'paginas' },
|
||||
{ 'data': 'tirada' },
|
||||
{ 'data': 'total_presupuesto' },
|
||||
{ 'data': 'estado' ,
|
||||
'render': function ( data, type, row, meta ) {
|
||||
if(data=='borrador')
|
||||
return '<?= lang('Presupuestos.presupuestoEstadoBorrador') ?>';
|
||||
else if(data=='aceptado')
|
||||
return '<?= lang('Presupuestos.presupuestoEstadoAceptado') ?>';
|
||||
}
|
||||
},
|
||||
{ 'data': actionBtns }
|
||||
]
|
||||
});
|
||||
|
||||
|
||||
theTable.on( 'draw.dt', function () {
|
||||
|
||||
const dateCols = [1];
|
||||
const priceCols = [9];
|
||||
|
||||
for (let coln of dateCols) {
|
||||
theTable.column(coln, { page: 'current' }).nodes().each( function (cell, i) {
|
||||
const datestr = cell.innerHTML;
|
||||
const dateStrLen = datestr.toString().trim().length;
|
||||
if (dateStrLen > 0) {
|
||||
let dateTimeParts= datestr.split(/[- :]/); // regular expression split that creates array with: year, month, day, hour, minutes, seconds values
|
||||
dateTimeParts[1]--; // monthIndex begins with 0 for January and ends with 11 for December so we need to decrement by one
|
||||
const d = new Date(...dateTimeParts); // new Date(datestr);
|
||||
cell.innerHTML = d.toLocaleDateString();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
for (let coln of priceCols) {
|
||||
theTable.column(coln, { page: 'current' }).nodes().each( function (cell, i) {
|
||||
cell.innerHTML = parseFloat(cell.innerHTML).toFixed(2);
|
||||
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
$(document).on('click', '.btn-edit', function(e) {
|
||||
window.location.href = `/presupuestos/cosidotapablanda/edit/${$(this).attr('data-id')}/`;
|
||||
});
|
||||
|
||||
|
||||
$(document).on('click', '.btn-delete', function(e) {
|
||||
$(".btn-remove").attr('data-id', $(this).attr('data-id'));
|
||||
});
|
||||
|
||||
|
||||
$(document).on('click', '.btn-remove', function(e) {
|
||||
const dataId = $(this).attr('data-id');
|
||||
const row = $(this).closest('tr');
|
||||
if ($.isNumeric(dataId)) {
|
||||
$.ajax({
|
||||
url: `/presupuestos/cosidotapablanda/delete/${dataId}`,
|
||||
method: 'GET',
|
||||
}).done((data, textStatus, jqXHR) => {
|
||||
$('#confirm2delete').modal('toggle');
|
||||
theTable.clearPipeline();
|
||||
theTable.row($(row)).invalidate().draw();
|
||||
popSuccessAlert(data.msg ?? jqXHR.statusText);
|
||||
}).fail((jqXHR, textStatus, errorThrown) => {
|
||||
popErrorAlert(jqXHR.responseJSON.messages.error)
|
||||
})
|
||||
}
|
||||
});
|
||||
<?=$this->endSection() ?>
|
||||
|
||||
|
||||
<?=$this->section('css') ?>
|
||||
<link rel="stylesheet" href="https://cdn.datatables.net/buttons/2.2.3/css/buttons.bootstrap5.min.css">
|
||||
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/fixedheader/3.1.7/css/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="https://cdn.datatables.net/buttons/2.2.3/js/dataTables.buttons.min.js"></script>
|
||||
<script src="https://cdn.datatables.net/buttons/2.2.3/js/buttons.bootstrap5.min.js"></script>
|
||||
<script src="https://cdn.datatables.net/buttons/2.2.3/js/buttons.html5.min.js"></script>
|
||||
<script src="https://cdn.datatables.net/buttons/2.2.3/js/buttons.print.min.js"></script>
|
||||
<script src="https://cdn.datatables.net/buttons/2.2.3/js/buttons.colVis.min.js"></script>
|
||||
<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="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.10.0/jszip.min.js" integrity="sha512-xcHCGC5tQ0SHlRX8Anbz6oy/OullASJkEhb4gjkneVpGE3/QGYejf14CUO5n5q5paiHfRFTa9HKgByxzidw2Bw==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.2.5/pdfmake.min.js" integrity="sha512-rDbVu5s98lzXZsmJoMa0DjHNE+RwPJACogUCLyq3Xxm2kJO6qsQwjbE5NDk2DqmlKcxDirCnU1wAzVLe12IM3w==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.2.5/vfs_fonts.js" integrity="sha512-cktKDgjEiIkPVHYbn8bh/FEyYxmt4JDJJjOCu5/FQAkW4bc911XtKYValiyzBiJigjVEvrIAyQFEbRJZyDA1wQ==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
|
||||
<?=$this->endSection() ?>
|
||||
|
||||
@ -69,6 +69,17 @@
|
||||
<div data-i18n="<?= lang("App.menu_presupuestos") ?>"><?= lang("App.menu_presupuestos") ?></div>
|
||||
</a>
|
||||
<ul class="menu-sub">
|
||||
<?php if (count($temp = getArrayItem($menus, 'name', 'Buscador')) > 0): ?>
|
||||
<?php if (count(getArrayItem($temp, 'methods', 'index', true)) > 0): ?>
|
||||
<li class="menu-item">
|
||||
<a href="<?= site_url("presupuestos/buscador") ?>" class="menu-link">
|
||||
<div data-i18n="<?= lang("App.menu_presupuesto_buscador") ?>"><?= lang("App.menu_presupuesto_buscador") ?></div>
|
||||
</a>
|
||||
</li>
|
||||
<?php endif; ?>
|
||||
<?php endif; ?>
|
||||
|
||||
|
||||
<?php if (allowMenuSection(
|
||||
$menus,
|
||||
['Fresadotapadura', 'Fresadotapablanda', 'Cosidotapadura', 'Cosidotapablanda',
|
||||
|
||||
Reference in New Issue
Block a user