mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
Limpieza de modelos para buscador
This commit is contained in:
@ -37,7 +37,6 @@ class Buscador extends \App\Controllers\GoBaseResourceController
|
||||
protected $indexRoute = 'buscadorPresupuestosList';
|
||||
|
||||
|
||||
|
||||
public function initController(\CodeIgniter\HTTP\RequestInterface $request, \CodeIgniter\HTTP\ResponseInterface $response, \Psr\Log\LoggerInterface $logger)
|
||||
{
|
||||
|
||||
@ -47,7 +46,7 @@ class Buscador extends \App\Controllers\GoBaseResourceController
|
||||
$this->soft_delete = true;
|
||||
// Se indica el flag para los ficheros borrados
|
||||
$this->delete_flag = 1;
|
||||
|
||||
|
||||
$this->viewData = ['usingServerSideDataTable' => true]; // JJO
|
||||
|
||||
// Breadcrumbs (IMN)
|
||||
@ -71,20 +70,18 @@ class Buscador extends \App\Controllers\GoBaseResourceController
|
||||
];
|
||||
|
||||
$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.';
|
||||
@ -95,7 +92,7 @@ class Buscador extends \App\Controllers\GoBaseResourceController
|
||||
}
|
||||
$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';
|
||||
@ -106,358 +103,19 @@ class Buscador extends \App\Controllers\GoBaseResourceController
|
||||
$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;
|
||||
$searchValues = get_filter_datatables_columns($reqData);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
$resourceData = $this->model->getResource($searchValues)->orderBy($order1, $dir1)->orderBy($order2, $dir2)
|
||||
->orderBy($order3, $dir3)->limit($length, $start)->get()->getResultObject();
|
||||
|
||||
return $this->respond(Collection::datatable(
|
||||
$resourceData,
|
||||
$this->model->getResource("", $tipo_impresion_id)->countAllResults(),
|
||||
$this->model->getResource($search, $tipo_impresion_id)->countAllResults()
|
||||
$this->model->getResource("")->countAllResults(),
|
||||
$this->model->getResource($search)->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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user