viewData['pageTitle'] = lang('Presupuestos.moduleTitleCosidoTB'); $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 $this->viewData['breadcrumb'] = [ ['title' => lang("App.menu_presupuestos"), 'route' => "javascript:void(0);", 'active' => false], ['title' => lang("App.menu_libros_cosido_tapa_blanda"), 'route' => site_url('presupuestos/cosidotapablanda'), 'active' => true] ]; parent::initController($request, $response, $logger); $this->model = new PresupuestoModel(); } 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 . 'viewCosidotapablandaList', $viewData); } public function add() { // JJO $session = session(); $requestMethod = $this->request->getMethod(); if ($requestMethod === 'post') : $nullIfEmpty = true; // !(phpversion() >= '8.1'); $postData = $this->request->getPost(); $sanitizedData = $this->sanitized($postData, $nullIfEmpty); // JJO $sanitizedData['user_created_id'] = $session->id_user; $noException = true; if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) : if ($this->canValidate()) : try { $successfulResult = $this->model->skipValidation(true)->save($sanitizedData); } catch (\Exception $e) { $noException = false; $this->dealWithException($e); } else : $this->viewData['errorMessage'] = lang('Basic.global.formErr1', [mb_strtolower(lang('Presupuestos.presupuesto'))]); $this->session->setFlashdata('formErrors', $this->model->errors()); endif; $thenRedirect = true; // Change this to false if you want your user to stay on the form after submission endif; if ($noException && $successfulResult) : $id = $this->model->db->insertID(); $message = lang('Basic.global.saveSuccess', [mb_strtolower(lang('Presupuestos.presupuesto'))]) . '.'; $message .= anchor("admin/presupuestos/{$id}/edit", lang('Basic.global.continueEditing') . '?'); $message = ucfirst(str_replace("'", "\'", $message)); if ($thenRedirect) : if (!empty($this->indexRoute)) : //return redirect()->to(route_to( $this->indexRoute ) )->with('sweet-success', $message); return redirect()->to(site_url('presupuestos/presupuestos/edit/' . $id))->with('sweet-success', $message); else : return $this->redirect2listView('sweet-success', $message); endif; else : $this->session->setFlashData('sweet-success', $message); endif; endif; // $noException && $successfulResult endif; // ($requestMethod === 'post') $this->viewData['presupuestoEntity'] = isset($sanitizedData) ? new PresupuestoEntity($sanitizedData) : new PresupuestoEntity(); $this->viewData['clienteList'] = $this->getClienteListItems($presupuestoEntity->cliente_id ?? null); $this->viewData['incReiList'] = array('incidencia' => lang('Presupuestos.incidencia'), 'reimpresion' => lang('Presupuestos.reimpresion'), 'sin_cargo' => lang('Presupuestos.sinCargo')); $this->viewData['paisList'] = $this->getPaisListItems(); $this->viewData['papelFormatoList'] = $this->getPapelFormatoListItems($presupuestoEntity->papel_formato_id ?? null); $this->viewData['papelGenericoNegroList'] = $this->getPapelGenericoNegro(); $this->viewData['papelGenericoNegroHQList'] = $this->getPapelGenericoNegroHQ(); $this->viewData['papelGenericoColorList'] = $this->getPapelGenericoColor(); $this->viewData['papelGenericoColorHQList'] = $this->getPapelGenericoColorHQ(); $this->viewData['papelGenericoCubiertaList'] = $this->getPapelGenericoCubierta(); $this->viewData['papelGenericoSobrecubiertaList'] = $this->getPapelGenericoSobreCubierta(); // Tarifas $this->viewData['serviciosPreimpresion'] = $this->getServiciosPreimpresion(); $this->viewData['serviciosEncuadernacion'] = $this->getServiciosEncuadernacion(); $this->viewData['serviciosAcabado'] = $this->getServiciosAcabado(); $this->viewData['serviciosManipulado'] = $this->getServiciosManipulado(); /* $this->viewData['formAction'] = route_to('createCosidotapablanda'); $this->viewData['boxTitle'] = lang('Basic.global.addNew') . ' ' . lang('Presupuestos.moduleTitleCosidoTB') . ' ' . lang('Basic.global.addNewSuffix'); /* TEST JS LOADER */ //$this->viewData['global_js_variables'] = array('jsVarTest' => "'Hola Jaime'"); return $this->displayForm(__METHOD__); } // end function add() public function edit($requestedId = null) { // JJO $session = session(); if ($requestedId == null) : return $this->redirect2listView(); endif; $id = filter_var($requestedId, FILTER_SANITIZE_URL); $presupuestoEntity = $this->model->find($id); if ($presupuestoEntity == false) : $message = lang('Basic.global.notFoundWithIdErr', [mb_strtolower(lang('Presupuestos.presupuesto')), $id]); return $this->redirect2listView('sweet-error', $message); endif; $requestMethod = $this->request->getMethod(); if ($requestMethod === 'post') : $nullIfEmpty = true; // !(phpversion() >= '8.1'); $postData = $this->request->getPost(); $sanitizedData = $this->sanitized($postData, $nullIfEmpty); if ($this->request->getPost('recoger_en_taller') == null) { $sanitizedData['recoger_en_taller'] = false; } if ($this->request->getPost('ferro') == null) { $sanitizedData['ferro'] = false; } if ($this->request->getPost('ferro_digital') == null) { $sanitizedData['ferro_digital'] = false; } if ($this->request->getPost('marcapaginas') == null) { $sanitizedData['marcapaginas'] = false; } if ($this->request->getPost('papel_formato_personalizado') == null) { $sanitizedData['papel_formato_personalizado'] = false; } if ($this->request->getPost('solapas') == null) { $sanitizedData['solapas'] = false; } if ($this->request->getPost('cosido') == null) { $sanitizedData['cosido'] = false; } if ($this->request->getPost('cubiertas') == null) { $sanitizedData['cubiertas'] = false; } if ($this->request->getPost('imagenes_bn_interior') == null) { $sanitizedData['imagenes_bn_interior'] = false; } if ($this->request->getPost('en_produccion') == null) { $sanitizedData['en_produccion'] = false; } if ($this->request->getPost('en_espera') == null) { $sanitizedData['en_espera'] = false; } if ($this->request->getPost('modo_comparador') == null) { $sanitizedData['modo_comparador'] = false; } if ($this->request->getPost('paginas_negro_hq') == null) { $sanitizedData['paginas_negro_hq'] = false; } if ($this->request->getPost('paginas_negro_check_papel_total') == null) { $sanitizedData['paginas_negro_check_papel_total'] = false; } if ($this->request->getPost('paginas_negro_check_impresion_total') == null) { $sanitizedData['paginas_negro_check_impresion_total'] = false; } if ($this->request->getPost('paginas_color_check_papel_total') == null) { $sanitizedData['paginas_color_check_papel_total'] = false; } if ($this->request->getPost('paginas_color_check_impresion_total') == null) { $sanitizedData['paginas_color_check_impresion_total'] = false; } if ($this->request->getPost('paginas_portada_check_papel_total') == null) { $sanitizedData['paginas_portada_check_papel_total'] = false; } if ($this->request->getPost('paginas_portada_check_impresion_total') == null) { $sanitizedData['paginas_portada_check_impresion_total'] = false; } if ($this->request->getPost('paginas_cubierta_papel_impresion_id') == null) { $sanitizedData['paginas_cubierta_papel_impresion_id'] = false; } if ($this->request->getPost('paginas_cubierta_check_papel_total') == null) { $sanitizedData['paginas_cubierta_check_papel_total'] = false; } if ($this->request->getPost('paginas_cubierta_check_impresion_total') == null) { $sanitizedData['paginas_cubierta_check_impresion_total'] = false; } if ($this->request->getPost('isDig') == null) { $sanitizedData['isDig'] = false; } if ($this->request->getPost('envios_recoge_cliente') == null) { $sanitizedData['envios_recoge_cliente'] = false; } if ($this->request->getPost('fecha_entrega_real_aviso') == null) { $sanitizedData['fecha_entrega_real_aviso'] = false; } // JJO $sanitizedData['user_updated_id'] = $session->id_user; $noException = true; if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) : if ($this->canValidate()) : try { $successfulResult = $this->model->skipValidation(true)->update($id, $sanitizedData); } catch (\Exception $e) { $noException = false; $this->dealWithException($e); } else : $this->viewData['warningMessage'] = lang('Basic.global.formErr1', [mb_strtolower(lang('Presupuestos.presupuesto'))]); $this->session->setFlashdata('formErrors', $this->model->errors()); endif; $presupuestoEntity->fill($sanitizedData); $thenRedirect = true; endif; if ($noException && $successfulResult) : $id = $presupuestoEntity->id ?? $id; $message = lang('Basic.global.updateSuccess', [mb_strtolower(lang('Presupuestos.presupuesto'))]) . '.'; $message .= anchor("admin/presupuestos/{$id}/edit", lang('Basic.global.continueEditing') . '?'); $message = ucfirst(str_replace("'", "\'", $message)); if ($thenRedirect) : if (!empty($this->indexRoute)) : return redirect()->to(route_to($this->indexRoute))->with('sweet-success', $message); else : return $this->redirect2listView('sweet-success', $message); endif; else : $this->session->setFlashData('sweet-success', $message); endif; endif; // $noException && $successfulResult endif; // ($requestMethod === 'post') $this->viewData['presupuestoEntity'] = $presupuestoEntity; $this->viewData['clienteList'] = $this->getClienteListItems($presupuestoEntity->cliente_id ?? null); $this->viewData['formaPagoList'] = $this->getFormaPagoListItems(); $this->viewData['tiposImpresionList'] = $this->getTiposImpresionListItems($presupuestoEntity->tipo_impresion_id ?? null); $this->viewData['tipologiasLibroList'] = $this->getTipologiasLibroListItems($presupuestoEntity->tipologia_id ?? null); $this->viewData['paisList'] = $this->getPaisListItems(); $this->viewData['ubicacionLibroList'] = $this->getUbicacionLibroListItems($presupuestoEntity->ubicacion_id ?? null); $this->viewData['presupuestoEstadoList'] = $this->getPresupuestoEstadoListItems($presupuestoEntity->estado_id ?? null); $this->viewData['papelFormatoList'] = $this->getPapelFormatoListItems($presupuestoEntity->papel_formato_id ?? null); $this->viewData['papelGenericoList'] = $this->getPapelGenericoListItems($presupuestoEntity->paginas_negro_papel_id ?? null); $this->viewData['papelImpresionList'] = $this->getPapelImpresionListItems($presupuestoEntity->paginas_negro_papel_impresion_id ?? null); $this->viewData['maquinaList'] = $this->getMaquinaListItems($presupuestoEntity->paginas_negro_maquina_id ?? null); $this->viewData['maquinasTarifasImpresionList'] = $this->getMaquinasTarifasImpresionListItems($presupuestoEntity->paginas_negro_tarifa_impresion_id ?? null); $this->viewData['papelGenericoList2'] = $this->getPapelGenericoListItems2($presupuestoEntity->paginas_color_papel_id ?? null); $this->viewData['papelImpresionList2'] = $this->getPapelImpresionListItems2($presupuestoEntity->paginas_color_papel_impresion_id ?? null); $this->viewData['maquinaList2'] = $this->getMaquinaListItems2($presupuestoEntity->paginas_color_maquina_id ?? null); $this->viewData['maquinasTarifasImpresionList2'] = $this->getMaquinasTarifasImpresionListItems2($presupuestoEntity->paginas_color_tarifa_impresion_id ?? null); $this->viewData['papelGenericoList3'] = $this->getPapelGenericoListItems3($presupuestoEntity->paginas_portada_papel_id ?? null); $this->viewData['papelImpresionList3'] = $this->getPapelImpresionListItems3($presupuestoEntity->paginas_portada_papel_impresion_id ?? null); $this->viewData['maquinaList3'] = $this->getMaquinaListItems3($presupuestoEntity->paginas_portada_maquina_id ?? null); $this->viewData['maquinasTarifasImpresionList3'] = $this->getMaquinasTarifasImpresionListItems3($presupuestoEntity->paginas_portada_tarifa_impresion_id ?? null); $this->viewData['papelGenericoList4'] = $this->getPapelGenericoListItems4($presupuestoEntity->paginas_cubierta_papel_id ?? null); $this->viewData['papelImpresionList4'] = $this->getPapelImpresionListItems4($presupuestoEntity->paginas_cubierta_papel_impresion_id ?? null); $this->viewData['maquinaList4'] = $this->getMaquinaListItems4($presupuestoEntity->paginas_cubierta_maquina_id ?? null); $this->viewData['maquinasTarifasImpresionList4'] = $this->getMaquinasTarifasImpresionListItems4($presupuestoEntity->paginas_cubierta_tarifa_impresion_id ?? null); $this->viewData['userList'] = $this->getUserListItems($presupuestoEntity->total_confirmado_user_id ?? null); $this->viewData['userList2'] = $this->getUserListItems2($presupuestoEntity->aprobado_user_id ?? null); $this->viewData['userList3'] = $this->getUserListItems3($presupuestoEntity->pedido_espera_user_id ?? null); $this->viewData['paginasCubiertaList'] = $this->getPaginasCubiertaOptions(); $this->viewData['paginasPortadaList'] = $this->getPaginasPortadaOptions(); $this->viewData['papelGenericoNegroList'] = $this->getPapelGenericoNegro(); $this->viewData['papelGenericoNegroHQList'] = $this->getPapelGenericoNegroHQ(); $this->viewData['papelGenericoColorList'] = $this->getPapelGenericoColor(); $this->viewData['papelGenericoColorHQList'] = $this->getPapelGenericoColorHQ(); $this->viewData['papelGenericoCubiertaList'] = $this->getPapelGenericoCubierta(); $this->viewData['papelGenericoSobrecubiertaList'] = $this->getPapelGenericoSobreCubierta(); $this->viewData['formAction'] = route_to('updatePresupuesto', $id); $this->viewData['boxTitle'] = lang('Basic.global.edit2') . ' ' . lang('Presupuestos.moduleTitle') . ' ' . lang('Basic.global.edit3'); return $this->displayForm(__METHOD__, $id); } // end function edit(...) 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; $requestedOrder = $reqData['order']['0']['column'] ?? 0; $order = PresupuestoModel::SORTABLE[$requestedOrder >= 0 ? $requestedOrder : 0]; $dir = $reqData['order']['0']['dir'] ?? 'asc'; if (is_null($type)) { $resourceData = $this->model->getResource($search)->orderBy($order, $dir)->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->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, 'isCosido' => true, // 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; if ($type=='interior') { $resourceData = $this->getCompIntData($type, $datosPedido, $papel_generico, $gramaje, $isColor, $isHq); $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, ); $resourceData = $this->getCompIntRotData($datosPedido, $papel_generico, $gramaje, $paginas); $newTokenHash = csrf_hash(); $csrfTokenName = csrf_token(); $data = [ 'lineas' => $resourceData, $csrfTokenName => $newTokenHash ]; return $this->respond($data); } else if ($type=='cubierta') { $datosPedido->solapas = $reqData['solapas']; $datosPedido->solapas_ancho = $reqData['solapas_ancho']; $resourceData = $this->getCompIntData($type, $datosPedido, $papel_generico, $gramaje, $isColor, $isHq); $newTokenHash = csrf_hash(); $csrfTokenName = csrf_token(); $data = [ 'lineas' => $resourceData, $csrfTokenName => $newTokenHash ]; return $this->respond($data); } } return $this->respond(Collection::datatable( $resourceData, $this->model->getResource()->countAllResults(), $this->model->getResource($search)->countAllResults() )); } else { return $this->failUnauthorized('Invalid request', 403); } } public function getCompIntData($uso, $datosPedido, $papel_generico, $gramaje, $isColor, $isHq) { $tipo = $isColor? ($isHq?'colorhq':'color'): ($isHq?'negrohq':'negro'); if( $uso == 'cubierta' ){ $opciones_papel = array( 'cubierta' => 1, 'rotativa' => 0, ); } else if ( $uso == 'sobrecubierta' ){ $opciones_papel = array( 'sobrecubierta' => 1, 'rotativa' => 0, ); } else if( $isColor ){ $opciones_papel = array( 'color' => 1, 'rotativa' => 0, ); } else{ $opciones_papel = array( 'bn' => 1, 'rotativa' => 0, ); } // Se obtienen los papeles disponibles $papelimpresionmodel = new PapelImpresionModel(); $papeles = $papelimpresionmodel->getIdPapelesImpresionForPresupuesto( papel_generico_id: $papel_generico['id'], gramaje: $gramaje, options: $opciones_papel ); $lineas = array(); // Para cada papel, se obtienen las maquinas disponibles foreach ($papeles as $papel) { $maquinamodel = new MaquinaModel(); $maquinas = $maquinamodel->getMaquinaImpresionForPresupuesto( is_rotativa: 0, tarifa_tipo: $tipo, tirada: $datosPedido->tirada + $datosPedido->merma, papel_impresion_id: $papel->id, ); // Se recorren las máquinas y se calcula el coste de linea por cada una foreach ($maquinas as $maquina) { $tarifamodel = new MaquinasTarifasImpresionModel(); $tarifa = $tarifamodel->getTarifa($maquina->maquina_id, $uso, $tipo); if(!is_float($tarifa)){ continue; } $linea = PresupuestoService::getCostesLinea($uso, $datosPedido, $maquina, $papel, $opciones_papel, $tarifa); $linea['fields']['maquina'] = $maquina->maquina; $linea['fields']['maquina_id'] = $maquina->maquina_id; $linea['fields']['papel_impresion'] = $papel->nombre; $linea['fields']['papel_impresion_id'] = $papel->id; $linea['fields']['paginas'] = $datosPedido->paginas; $linea['fields']['gramaje'] = $gramaje; $linea['fields']['papel_generico_id'] = $papel_generico['id']; $linea['fields']['papel_generico'] = $papel_generico['nombre']; array_push($lineas, $linea); } } return $lineas; } public function getCompIntRotData($datosPedido, $papel_generico, $gramaje, $paginas) { $uso = 'interior'; $tipo = $paginas->color>0? 'color': 'negro'; $parametrosRotativa = (object)array( 'a_favor_fibra' => 0, // este parametro se cambia para comprobar // en las dos direcciones (menos en rustica fresada que es siempre 1) 'bnPages' => $paginas->negro, 'colorPages' => $paginas->color, 'rotativa_gota_negro' => 0, 'rotativa_gota_color' => 0, ); $opciones_papel = array( 'rotativa' => 1, ); $tipo = array(); if( $paginas->color > 0 ){ $tipo[] = 'color'; $opciones_papel['color'] = 1; } if( $paginas->negro > 0 ){ $opciones_papel['bn'] = 1; $tipo[] = 'negro'; } // Se obtienen los papeles disponibles $papelimpresionmodel = new PapelImpresionModel(); $papeles = $papelimpresionmodel->getIdPapelesImpresionForPresupuesto( papel_generico_id: $papel_generico['id'], gramaje: $gramaje, options: $opciones_papel ); $lineas = array(); // Para cada papel, se obtienen las maquinas disponibles foreach ($papeles as $papel) { $papelImpresionTipologiaModel = new \App\Models\Configuracion\PapelImpresionTipologiaModel(); $datosTipologias = $papelImpresionTipologiaModel ->findTipologiasForPapelImpresion($papel->id, $parametrosRotativa->colorPages>0?'color':'negro') ->get()->getResultObject(); $parametrosRotativa->rotativa_gota_negro = $datosTipologias[0]->gota_negro; $parametrosRotativa->rotativa_gota_color = $datosTipologias[0]->gota_color; $parametrosRotativa->rotativa_negro = $datosTipologias[0]->negro; $parametrosRotativa->rotativa_cyan = $datosTipologias[0]->cyan; $parametrosRotativa->rotativa_magenta = $datosTipologias[0]->magenta; $parametrosRotativa->rotativa_amarillo = $datosTipologias[0]->amarillo; $maquinamodel = new MaquinaModel(); $maquinas = $maquinamodel->getMaquinaImpresionForPresupuesto( is_rotativa: 1, tarifa_tipo: $tipo, tirada: $datosPedido->tirada + $datosPedido->merma, papel_impresion_id: $papel->id, ); // Se recorren las máquinas y se calcula el coste de linea por cada una foreach ($maquinas as $maquina) { for ($i = 0; $i <= 1; $i++) { $parametrosRotativa->a_favor_fibra = $i; $tarifamodel = new MaquinasTarifasImpresionModel(); $tarifa = $tarifamodel->getTarifa($maquina->maquina_id, $uso, is_array($tipo)?'color':$tipo); if(!is_float($tarifa)){ continue; } // precio del pliego de impresion $linea['fields'] = PresupuestoService::getCostesLineaRotativa($maquina, $papel, $datosPedido, $parametrosRotativa); $precio_pliego_impresion = PresupuestoService::getPrecioPliego($maquina, $papel, $datosPedido->paginas); $linea['fields']['precios_pliegos'] = $precio_pliego_impresion; $linea['fields']['precio_libro'] = $linea['fields']['pliegos_libro'] * $precio_pliego_impresion; // Precio papel pedido $linea['fields']['precio_pedido'] = $linea['fields']['precio_libro'] * ($datosPedido->tirada + $datosPedido->merma); $linea['fields']['a_favor_fibra'] = $parametrosRotativa->a_favor_fibra; $linea['fields']['maquina'] = $maquina->maquina; $linea['fields']['maquina_id'] = $maquina->maquina_id; $linea['fields']['papel_impresion'] = $papel->nombre; $linea['fields']['papel_impresion_id'] = $papel->id; $linea['fields']['paginas'] = $datosPedido->paginas; $linea['fields']['gramaje'] = $gramaje; $linea['fields']['papel_generico_id'] = $papel_generico['id']; $linea['fields']['papel_generico'] = $papel_generico['nombre']; $linea['fields']['posicion_formas'] = $parametrosRotativa->a_favor_fibra ? 'h' : 'v'; $linea['fields']['num_formas_horizontales'] = floor($linea['fields']['factor_anchura']); $linea['fields']['num_formas_verticales'] = floor($linea['fields']['factor_altura']); // impresion $linea['fields']['precio_click'] = $tarifa; $linea['fields']['precio_click_pedido'] = $linea['fields']['clicks_pedido'] * $linea['fields']['precio_click']; // total linea rotativa $linea['fields']['total_impresion'] = $linea['fields']['precio_pedido'] + $linea['fields']['precio_click_pedido'] + $linea['fields']['precio_tinta'] + $linea['fields']['total_corte']; array_push($lineas, $linea); } } } return $lineas; } 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(); $tipo = $reqData['tipo'] ?? null; $uso = $reqData['uso'] ?? null; $datos = $reqData['datos'] ?? null; //$searchStr = goSanitize($this->request->getPost('searchTerm'))[0]; if ($tipo == 'gramaje') { // En este caso contiene el nombre del papel generico $model = new PapelGenericoModel(); $menu = $model->getGramajeComparador($datos, $uso ); } $newTokenHash = csrf_hash(); $csrfTokenName = csrf_token(); $data = [ 'menu' => $menu, $csrfTokenName => $newTokenHash ]; return $this->respond($data); } else { return $this->failUnauthorized('Invalid request', 403); } } protected function getClienteListItems($selId = null) { $data = ['' => lang('Basic.global.pleaseSelectA', [mb_strtolower(lang('Clientes.cliente'))])]; if (!empty($selId)) : $clienteModel = model('App\Models\Clientes\ClienteModel'); $selOption = $clienteModel->where('id', $selId)->findColumn('nombre'); if (!empty($selOption)) : $data[$selId] = $selOption[0]; endif; endif; return $data; } protected function getPaisListItems() { $paisModel = model('App\Models\Configuracion\PaisModel'); $onlyActiveOnes = true; $data = $paisModel->getAllForMenu('id, nombre', 'nombre', $onlyActiveOnes); return $data; } protected function getPapelFormatoListItems($selId = null) { $papelFormatoModel = model('App\Models\Configuracion\PapelFormatoModel'); $data = $papelFormatoModel->getElementsForMenu(); array_unshift($data, (object)['id' => '', 'tamanio' => lang('Basic.global.pleaseSelectA', [mb_strtolower(lang('Presupuestos.papelFormatoId'))])]); return $data; } protected function getPapelGenericoNegro() { $model = model('App\Models\Configuracion\PapelGenericoModel'); $data = $model->getPapelForComparador('negro', false, false); array_unshift($data, (object)array( "id" => 0, "nombre" => lang('Basic.global.pleaseSelectA', [mb_strtolower(lang('Presupuestos.papel'))]) )); return $data; } protected function getPapelGenericoNegroHQ() { $model = model('App\Models\Configuracion\PapelGenericoModel'); $data = $model->getPapelForComparador('negrohq', false, false); array_unshift($data, (object)array( "id" => 0, "nombre" => lang('Basic.global.pleaseSelectA', [mb_strtolower(lang('Presupuestos.papel'))]) )); return $data; } protected function getPapelGenericoColor() { $model = model('App\Models\Configuracion\PapelGenericoModel'); $data = $model->getPapelForComparador('color', false, false); array_unshift($data, (object)array( "id" => 0, "nombre" => lang('Basic.global.pleaseSelectA', [mb_strtolower(lang('Presupuestos.papel'))]) )); return $data; } protected function getPapelGenericoColorHQ() { $model = model('App\Models\Configuracion\PapelGenericoModel'); $data = $model->getPapelForComparador('colorhq', false, false); array_unshift($data, (object)array( "id" => 0, "nombre" => lang('Basic.global.pleaseSelectA', [mb_strtolower(lang('Presupuestos.papel'))]) )); return $data; } protected function getPapelGenericoCubierta() { $model = model('App\Models\Configuracion\PapelGenericoModel'); $data = $model->getPapelForComparador('color', true, false); array_unshift($data, (object)array( "id" => 0, "nombre" => lang('Basic.global.pleaseSelectA', [mb_strtolower(lang('Presupuestos.papel'))]) )); return $data; } protected function getPapelGenericoSobreCubierta() { $model = model('App\Models\Configuracion\PapelGenericoModel'); $data = $model->getPapelForComparador('color', false, true); array_unshift($data, (object)array( "id" => 0, "nombre" => lang('Basic.global.pleaseSelectA', [mb_strtolower(lang('Presupuestos.papel'))]) )); return $data; } protected function getServiciosPreimpresion() { $model = model('App\Models\Tarifas\TarifapreimpresionModel'); $data = $model->getServiciosPreimpresionSelector(); array_unshift($data, (object)array( "value" => 0, "label" => lang('Basic.global.pleaseSelectA', [mb_strtolower(lang('Presupuestos.servicioPreimpresion'))]) )); return $data; } protected function getServiciosEncuadernacion() { $model = model('App\Models\Tarifas\TarifaEncuadernacionModel'); $data = $model->getServiciosEncuadernacionSelector(); array_unshift($data, (object)array( "value" => 0, "label" => lang('Basic.global.pleaseSelectA', [mb_strtolower(lang('Presupuestos.servicioEncuadernado'))]) )); return $data; } protected function getServiciosAcabado() { $model = model('App\Models\Tarifas\TarifaacabadoModel'); $data = $model->getServiciosAcabadoSelector(); array_unshift($data, (object)array( "value" => 0, "label" => lang('Basic.global.pleaseSelectA', [mb_strtolower(lang('Presupuestos.servicioAcabado'))]) )); return $data; } protected function getServiciosManipulado() { $model = model('App\Models\Tarifas\TarifaManipuladoModel'); $data = $model->getServiciosManipuladoSelector(); array_unshift($data, (object)array( "value" => 0, "label" => lang('Basic.global.pleaseSelectA', [mb_strtolower(lang('Presupuestos.servicioManipulado'))]) )); return $data; } /* protected function getUbicacionLibroListItems($selId = null) { $data = ['' => lang('Basic.global.pleaseSelectA', [mb_strtolower(lang('LgUbicacionesLibros.ubicacionLibro'))])]; if (!empty($selId)) : $ubicacionesLibroModel = model('App\Models\Configuracion\UbicacionesLibroModel'); $selOption = $ubicacionesLibroModel->where('id', $selId)->findColumn('nombre'); if (!empty($selOption)) : $data[$selId] = $selOption[0]; endif; endif; return $data; } protected function getFormaPagoListItems() { $formasPagoModel = model('App\Models\Configuracion\FormasPagoModel'); $onlyActiveOnes = true; $data = $formasPagoModel->getAllForMenu('id, nombre', 'nombre', $onlyActiveOnes); return $data; } protected function getPapelImpresionListItems4($selId = null) { $data = ['' => lang('Basic.global.pleaseSelectA', [mb_strtolower(lang('PapelImpresions.papelImpresion'))])]; if (!empty($selId)) : $papelImpresionModel = model('App\Models\Presupuestos\PapelImpresionModel'); $selOption = $papelImpresionModel->where('id', $selId)->findColumn('nombre'); if (!empty($selOption)) : $data[$selId] = $selOption[0]; endif; endif; return $data; } protected function getPresupuestoEstadoListItems($selId = null) { $data = ['' => lang('Basic.global.pleaseSelectA', [mb_strtolower(lang('PresupuestoEstados.presupuestoEstado'))])]; if (!empty($selId)) : $presupuestoEstadoModel = model('App\Models\Presupuestos\PresupuestoEstadoModel'); $selOption = $presupuestoEstadoModel->where('id', $selId)->findColumn('estado'); if (!empty($selOption)) : $data[$selId] = $selOption[0]; endif; endif; return $data; } protected function getPapelGenericoListItems3($selId = null) { $data = ['' => lang('Basic.global.pleaseSelectA', [mb_strtolower(lang('PapelGenericoes.papelGenerico'))])]; if (!empty($selId)) : $papelGenericoModel = model('App\Models\Presupuestos\PapelGenericoModel'); $selOption = $papelGenericoModel->where('id', $selId)->findColumn('nombre'); if (!empty($selOption)) : $data[$selId] = $selOption[0]; endif; endif; return $data; } protected function getPapelImpresionListItems2($selId = null) { $data = ['' => lang('Basic.global.pleaseSelectA', [mb_strtolower(lang('PapelImpresions.papelImpresion'))])]; if (!empty($selId)) : $papelImpresionModel = model('App\Models\Presupuestos\PapelImpresionModel'); $selOption = $papelImpresionModel->where('id', $selId)->findColumn('nombre'); if (!empty($selOption)) : $data[$selId] = $selOption[0]; endif; endif; return $data; } protected function getMaquinaListItems3($selId = null) { $data = ['' => lang('Basic.global.pleaseSelectA', [mb_strtolower(lang('Maquinas.maquina'))])]; if (!empty($selId)) : $maquinaModel = model('App\Models\Presupuestos\MaquinaModel'); $selOption = $maquinaModel->where('id', $selId)->findColumn('nombre'); if (!empty($selOption)) : $data[$selId] = $selOption[0]; endif; endif; return $data; } protected function getMaquinasTarifasImpresionListItems2($selId = null) { $data = ['' => lang('Basic.global.pleaseSelectA', [mb_strtolower(lang('MaquinasTarifasImpresions.maquinasTarifasImpresion'))])]; if (!empty($selId)) : $maquinasTarifasImpresionModel = model('App\Models\Presupuestos\MaquinasTarifasImpresionModel'); $selOption = $maquinasTarifasImpresionModel->where('id', $selId)->findColumn('precio'); if (!empty($selOption)) : $data[$selId] = $selOption[0]; endif; endif; return $data; } protected function getPapelGenericoListItems2($selId = null) { $data = ['' => lang('Basic.global.pleaseSelectA', [mb_strtolower(lang('PapelGenericoes.papelGenerico'))])]; if (!empty($selId)) : $papelGenericoModel = model('App\Models\Presupuestos\PapelGenericoModel'); $selOption = $papelGenericoModel->where('id', $selId)->findColumn('nombre'); if (!empty($selOption)) : $data[$selId] = $selOption[0]; endif; endif; return $data; } protected function getMaquinaListItems($selId = null) { $data = ['' => lang('Basic.global.pleaseSelectA', [mb_strtolower(lang('Maquinas.maquina'))])]; if (!empty($selId)) : $maquinaModel = model('App\Models\Presupuestos\MaquinaModel'); $selOption = $maquinaModel->where('id', $selId)->findColumn('nombre'); if (!empty($selOption)) : $data[$selId] = $selOption[0]; endif; endif; return $data; } protected function getMaquinaListItems2($selId = null) { $data = ['' => lang('Basic.global.pleaseSelectA', [mb_strtolower(lang('Maquinas.maquina'))])]; if (!empty($selId)) : $maquinaModel = model('App\Models\Presupuestos\MaquinaModel'); $selOption = $maquinaModel->where('id', $selId)->findColumn('nombre'); if (!empty($selOption)) : $data[$selId] = $selOption[0]; endif; endif; return $data; } protected function getTipologiasLibroListItems($selId = null) { $data = ['' => lang('Basic.global.pleaseSelectA', [mb_strtolower(lang('TipologiasLibros.tipologiasLibro'))])]; if (!empty($selId)) : $tipologiasLibroModel = model('App\Models\Presupuestos\TipologiasLibroModel'); $selOption = $tipologiasLibroModel->where('id', $selId)->findColumn('nombre'); if (!empty($selOption)) : $data[$selId] = $selOption[0]; endif; endif; return $data; } protected function getPapelImpresionListItems3($selId = null) { $data = ['' => lang('Basic.global.pleaseSelectA', [mb_strtolower(lang('PapelImpresions.papelImpresion'))])]; if (!empty($selId)) : $papelImpresionModel = model('App\Models\Presupuestos\PapelImpresionModel'); $selOption = $papelImpresionModel->where('id', $selId)->findColumn('nombre'); if (!empty($selOption)) : $data[$selId] = $selOption[0]; endif; endif; return $data; } protected function getMaquinasTarifasImpresionListItems4($selId = null) { $data = ['' => lang('Basic.global.pleaseSelectA', [mb_strtolower(lang('MaquinasTarifasImpresions.maquinasTarifasImpresion'))])]; if (!empty($selId)) : $maquinasTarifasImpresionModel = model('App\Models\Presupuestos\MaquinasTarifasImpresionModel'); $selOption = $maquinasTarifasImpresionModel->where('id', $selId)->findColumn('precio'); if (!empty($selOption)) : $data[$selId] = $selOption[0]; endif; endif; return $data; } protected function getUserListItems($selId = null) { $data = ['' => lang('Basic.global.pleaseSelectA', [mb_strtolower(lang('Users.user'))])]; if (!empty($selId)) : $userModel = model('App\Models\Presupuestos\UserModel'); $selOption = $userModel->where('id_user', $selId)->findColumn('first_name'); if (!empty($selOption)) : $data[$selId] = $selOption[0]; endif; endif; return $data; } protected function getMaquinasTarifasImpresionListItems3($selId = null) { $data = ['' => lang('Basic.global.pleaseSelectA', [mb_strtolower(lang('MaquinasTarifasImpresions.maquinasTarifasImpresion'))])]; if (!empty($selId)) : $maquinasTarifasImpresionModel = model('App\Models\Presupuestos\MaquinasTarifasImpresionModel'); $selOption = $maquinasTarifasImpresionModel->where('id', $selId)->findColumn('id'); if (!empty($selOption)) : $data[$selId] = $selOption[0]; endif; endif; return $data; } protected function getUserListItems3($selId = null) { $data = ['' => lang('Basic.global.pleaseSelectA', [mb_strtolower(lang('Users.user'))])]; if (!empty($selId)) : $userModel = model('App\Models\Presupuestos\UserModel'); $selOption = $userModel->where('id_user', $selId)->findColumn('first_name'); if (!empty($selOption)) : $data[$selId] = $selOption[0]; endif; endif; return $data; } protected function getPapelImpresionListItems($selId = null) { $data = ['' => lang('Basic.global.pleaseSelectA', [mb_strtolower(lang('PapelImpresions.papelImpresion'))])]; if (!empty($selId)) : $papelImpresionModel = model('App\Models\Presupuestos\PapelImpresionModel'); $selOption = $papelImpresionModel->where('id', $selId)->findColumn('nombre'); if (!empty($selOption)) : $data[$selId] = $selOption[0]; endif; endif; return $data; } protected function getTiposImpresionListItems($selId = null) { $data = ['' => lang('Basic.global.pleaseSelectA', [mb_strtolower(lang('TiposImpresions.tiposImpresion'))])]; if (!empty($selId)) : $tiposImpresionModel = model('App\Models\Presupuestos\TiposImpresionModel'); $selOption = $tiposImpresionModel->where('id', $selId)->findColumn('nombre'); if (!empty($selOption)) : $data[$selId] = $selOption[0]; endif; endif; return $data; } protected function getMaquinasTarifasImpresionListItems($selId = null) { $data = ['' => lang('Basic.global.pleaseSelectA', [mb_strtolower(lang('MaquinasTarifasImpresions.maquinasTarifasImpresion'))])]; if (!empty($selId)) : $maquinasTarifasImpresionModel = model('App\Models\Presupuestos\MaquinasTarifasImpresionModel'); $selOption = $maquinasTarifasImpresionModel->where('id', $selId)->findColumn('precio'); if (!empty($selOption)) : $data[$selId] = $selOption[0]; endif; endif; return $data; } protected function getPapelGenericoListItems4($selId = null) { $data = ['' => lang('Basic.global.pleaseSelectA', [mb_strtolower(lang('PapelGenericoes.papelGenerico'))])]; if (!empty($selId)) : $papelGenericoModel = model('App\Models\Presupuestos\PapelGenericoModel'); $selOption = $papelGenericoModel->where('id', $selId)->findColumn('nombre'); if (!empty($selOption)) : $data[$selId] = $selOption[0]; endif; endif; return $data; } protected function getMaquinaListItems4($selId = null) { $data = ['' => lang('Basic.global.pleaseSelectA', [mb_strtolower(lang('Maquinas.maquina'))])]; if (!empty($selId)) : $maquinaModel = model('App\Models\Presupuestos\MaquinaModel'); $selOption = $maquinaModel->where('id', $selId)->findColumn('nombre'); if (!empty($selOption)) : $data[$selId] = $selOption[0]; endif; endif; return $data; } protected function getUserListItems2($selId = null) { $data = ['' => lang('Basic.global.pleaseSelectA', [mb_strtolower(lang('Users.user'))])]; if (!empty($selId)) : $userModel = model('App\Models\Presupuestos\UserModel'); $selOption = $userModel->where('id_user', $selId)->findColumn('first_name'); if (!empty($selOption)) : $data[$selId] = $selOption[0]; endif; endif; return $data; } protected function getPapelGenericoListItems($selId = null) { $data = ['' => lang('Basic.global.pleaseSelectA', [mb_strtolower(lang('PapelGenericoes.papelGenerico'))])]; if (!empty($selId)) : $papelGenericoModel = model('App\Models\Presupuestos\PapelGenericoModel'); $selOption = $papelGenericoModel->where('id', $selId)->findColumn('nombre'); if (!empty($selOption)) : $data[$selId] = $selOption[0]; endif; endif; return $data; } protected function getPaginasCubiertaOptions() { $paginasCubiertaOptions = [ '' => lang('Basic.global.pleaseSelect'), '4x0' => '4x0', '4x4' => '4x4', ]; return $paginasCubiertaOptions; } protected function getPaginasPortadaOptions() { $paginasPortadaOptions = [ '' => lang('Basic.global.pleaseSelect'), '4x0' => '4x0', '4x4' => '4x4', ]; return $paginasPortadaOptions; } */ }