From 2231e943c766a1ee159641159fbfd15fe0a4978a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaime=20Jim=C3=A9nez?= Date: Tue, 31 Dec 2024 12:37:16 +0100 Subject: [PATCH] trabajando en lineas presupuesto eventos --- ci4/app/Config/Routes.php | 3 + .../Presupuestos/Presupuestoadmin.php | 414 +++++--- ci4/app/Models/Configuracion/MaquinaModel.php | 4 +- .../Configuracion/PapelImpresionModel.php | 32 +- ci4/app/Services/PresupuestoService.php | 4 +- .../admin/viewPresupuestoadminForm.php | 1 + .../assets/js/safekat/components/select2.js | 7 +- .../presupuestoAdmin/presupuestoAdminEdit.js | 15 +- .../presupuestoAdmin/sections/comparador.js | 12 +- .../presupuestoAdmin/sections/datosLibro.js | 14 +- .../sections/lineasPresupuesto.js | 900 +++++++++++++++--- 11 files changed, 1130 insertions(+), 276 deletions(-) diff --git a/ci4/app/Config/Routes.php b/ci4/app/Config/Routes.php index 37d0bb7c..fd475aec 100644 --- a/ci4/app/Config/Routes.php +++ b/ci4/app/Config/Routes.php @@ -585,6 +585,9 @@ $routes->group('presupuestoadmin', ['namespace' => 'App\Controllers\Presupuestos $routes->post('comparadorguardas', 'Presupuestoadmin::obtenerComparadorGuardas'); $routes->get('papelgenerico', 'Presupuestoadmin::getPapelGenerico'); $routes->get('papelgramaje', 'Presupuestoadmin::getGramaje'); + $routes->get('papelimpresion', 'Presupuestoadmin::getPapelImpresion'); + $routes->get('maquinas', 'Presupuestoadmin::getMaquinas'); + $routes->post('getlinea', 'Presupuestoadmin::getLineaPresupuesto'); }); $routes->resource('presupuestoadmin', ['namespace' => 'App\Controllers\Presupuestos', 'controller' => 'Presupuestoadmin', 'except' => 'show,new,create,update']); diff --git a/ci4/app/Controllers/Presupuestos/Presupuestoadmin.php b/ci4/app/Controllers/Presupuestos/Presupuestoadmin.php index b436fe5c..9fc72223 100644 --- a/ci4/app/Controllers/Presupuestos/Presupuestoadmin.php +++ b/ci4/app/Controllers/Presupuestos/Presupuestoadmin.php @@ -481,6 +481,7 @@ class Presupuestoadmin extends \App\Controllers\BaseResourceController $data['lsc'] = $presupuesto->lomo_sobrecubierta; $data['tipo_impresion'] = $presupuesto->tipo_impresion_id; $data['cosido'] = $presupuesto->cosido; + $data['POD'] = $this->getPOD(); $data['datosGenerales']['id'] = $presupuesto->id; $data['datosGenerales']['state'] = intval($presupuesto->estado_id); @@ -623,8 +624,8 @@ class Presupuestoadmin extends \App\Controllers\BaseResourceController $papel_generico = $this->request->getPost('papel_generico'); $gramaje = $this->request->getPost('gramaje'); $paginas_color = $this->request->getPost('paginas_color'); - $isColor = $this->request->getPost('isColor'); - $isHq = $this->request->getPost('isHq'); + $isColor = $this->request->getPost('isColor')?1:0; + $isHq = $this->request->getPost('isHq')?1:0; $tipo_impresion_id = $this->request->getPost('tipo_impresion_id'); $uso = $this->request->getPost('uso'); @@ -867,140 +868,7 @@ class Presupuestoadmin extends \App\Controllers\BaseResourceController 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; - - $resourceData = []; - - if ($type == 'interior' || $type == 'guardas') { - - $datosTipolog = $reqData['negro'] ?? null; - if (!is_null($datosTipolog)) { - $datosTipolog = []; - $data = (object) array( - 'negro' => floatval($reqData['negro']) ?? 0, - 'cyan' => floatval($reqData['cyan']) ?? 0, - 'magenta' => floatval($reqData['magenta']) ?? 0, - 'amarillo' => floatval($reqData['amarillo']) ?? 0, - 'cg' => floatval($reqData['cg']) ?? 0, - 'gota_negro' => floatval($reqData['gota_negro']) ?? 0, - 'gota_color' => floatval($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; - - $input_data = array( - 'uso' => $type, - 'tipo_impresion_id' => $tipo_impresion_id, - 'datosPedido' => $datosPedido, - 'papel_generico' => $papel_generico, - 'gramaje' => $gramaje, - 'isColor' => $isColor, - 'isHq' => $isHq, - 'cliente_id' => $cliente_id, - 'datosTipolog' => $datosTipolog, - 'a_favor_fibra' => $a_favor_fibra - ); - - $resourceData = PresupuestoService::obtenerComparadorPlana($input_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' => floatval($reqData['negro']) ?? 0, - 'cyan' => floatval($reqData['cyan']) ?? 0, - 'magenta' => floatval($reqData['magenta']) ?? 0, - 'amarillo' => floatval($reqData['amarillo']) ?? 0, - 'gota_negro' => floatval($reqData['gota_negro']) ?? 0, - 'gota_color' => floatval($reqData['gota_color']) ?? 0, - ); - array_push($datosTipolog, $data); - } - - $input_data = [ - 'datosPedido' => $datosPedido, - 'papel_generico' => $papel_generico, - 'gramaje' => $gramaje, - 'paginas' => $paginas, - 'cliente_id' => $cliente_id, - 'datosTipolog' => $datosTipolog - ]; - - $resourceData = PresupuestoService::obtenerComparadorRotativa($input_data); - - } else if ($type == 'cubierta' || $type == 'sobrecubierta') { - - $datosPedido->solapas = $reqData['solapas']; - $datosPedido->solapas_ancho = $reqData['solapas_ancho']; - $datosPedido->lomo = $reqData['lomo']; - - $input_data = array( - 'uso' => $type, - 'tipo_impresion_id' => $tipo_impresion_id, - 'datosPedido' => $datosPedido, - 'papel_generico' => $papel_generico, - 'gramaje' => $gramaje, - 'isColor' => 1, // Cubierta y sobrecubierta siempre color HQ - 'isHq' => 1, - 'cliente_id' => $cliente_id, - ); - - $resourceData = PresupuestoService::obtenerComparadorPlana($input_data); - } - - $newTokenHash = csrf_hash(); - $csrfTokenName = csrf_token(); - $data = [ - 'lineas' => $resourceData, - $csrfTokenName => $newTokenHash - ]; - - return $this->respond($data); - } + } return $this->respond(Collection::datatable( $resourceData, @@ -1013,6 +881,154 @@ class Presupuestoadmin extends \App\Controllers\BaseResourceController } + public function getLineaPresupuesto() + { + if ($this->request->isAJAX()) { + + $reqData = $this->request->getPost(); + + $type = $reqData['type'] ?? null; + // por defecto, se deja cosido tapa blanda por ahora JJO + $tipo_impresion_id = $reqData['tipo_impresion_id'] ?? 4; + + $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; + + $resourceData = []; + + if ($type == 'interior' || $type == 'guardas') { + + $datosTipolog = $reqData['negro'] ?? null; + if (!is_null($datosTipolog)) { + $datosTipolog = []; + $data = (object) array( + 'negro' => floatval($reqData['negro']) ?? 0, + 'cyan' => floatval($reqData['cyan']) ?? 0, + 'magenta' => floatval($reqData['magenta']) ?? 0, + 'amarillo' => floatval($reqData['amarillo']) ?? 0, + 'cg' => floatval($reqData['cg']) ?? 0, + 'gota_negro' => floatval($reqData['gota_negro']) ?? 0, + 'gota_color' => floatval($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; + + $input_data = array( + 'uso' => $type, + 'tipo_impresion_id' => $tipo_impresion_id, + 'datosPedido' => $datosPedido, + 'papel_generico' => $papel_generico, + 'gramaje' => $gramaje, + 'isColor' => $isColor, + 'isHq' => $isHq, + 'cliente_id' => $cliente_id, + 'datosTipolog' => $datosTipolog, + 'a_favor_fibra' => $a_favor_fibra + ); + + $resourceData = PresupuestoService::obtenerComparadorPlana($input_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' => floatval($reqData['negro']) ?? 0, + 'cyan' => floatval($reqData['cyan']) ?? 0, + 'magenta' => floatval($reqData['magenta']) ?? 0, + 'amarillo' => floatval($reqData['amarillo']) ?? 0, + 'gota_negro' => floatval($reqData['gota_negro']) ?? 0, + 'gota_color' => floatval($reqData['gota_color']) ?? 0, + ); + array_push($datosTipolog, $data); + } + + $input_data = [ + 'datosPedido' => $datosPedido, + 'papel_generico' => $papel_generico, + 'gramaje' => $gramaje, + 'paginas' => $paginas, + 'cliente_id' => $cliente_id, + 'datosTipolog' => $datosTipolog + ]; + + $resourceData = PresupuestoService::obtenerComparadorRotativa($input_data); + + } else if ($type == 'cubierta' || $type == 'sobrecubierta') { + + $datosPedido->solapas = $reqData['solapas']; + $datosPedido->solapas_ancho = $reqData['solapas_ancho']; + $datosPedido->lomo = $reqData['lomo']; + + $input_data = array( + 'uso' => $type, + 'tipo_impresion_id' => $tipo_impresion_id, + 'datosPedido' => $datosPedido, + 'papel_generico' => $papel_generico, + 'gramaje' => $gramaje, + 'isColor' => 1, // Cubierta y sobrecubierta siempre color HQ + 'isHq' => 1, + 'cliente_id' => $cliente_id, + ); + + $resourceData = PresupuestoService::obtenerComparadorPlana($input_data); + } + + $newTokenHash = csrf_hash(); + $csrfTokenName = csrf_token(); + $data = [ + 'lineas' => $resourceData, + $csrfTokenName => $newTokenHash + ]; + + return $this->respond($data); + + } else { + return $this->failUnauthorized('Invalid request', 403); + } + } + + public function datatable_2() { if ($this->request->isAJAX()) { @@ -1502,6 +1518,132 @@ class Presupuestoadmin extends \App\Controllers\BaseResourceController } + public function getPapelImpresion() + { + + if ($this->request->isAJAX()) { + + $papel_generico_id = $this->request->getGet('papel_generico'); + $gramaje = $this->request->getGet('gramaje'); + + $tipo_impresion_id = $this->request->getGet("tipo_impresion"); + $tapa_dura = model('App\Models\Configuracion\TipoPresupuestoModel')->get_isTapaDura(intval($tipo_impresion_id)); + + $tipo = $this->request->getGet("tipo"); + + $uso = $this->request->getGet("uso") ?? 'interior'; + + $model = model('App\Models\Configuracion\PapelImpresionModel'); + $query = $model->getPapelesImpresionForMenu( + $papel_generico_id, + $gramaje, + $tipo, + $uso, + $tapa_dura, + false + ); + if ($this->request->getGet("q")) { + $query->groupStart() + ->orLike("lg_papel_impresion.nombre", $this->request->getGet("q")) + ->groupEnd(); + } + + return $this->response->setJSON($query->orderBy("t1.nombre", "asc")->get()->getResultObject()); + } else { + return $this->failUnauthorized('Invalid request', 403); + } + } + + + public function getMaquinas() + { + + if ($this->request->isAJAX()) { + + $ancho = $this->request->getGet('ancho'); + $alto = $this->request->getGet('alto'); + $tirada = $this->request->getGet('tirada'); + $merma = $this->request->getGet('merma'); + $tipo_impresion_id = $this->request->getGet('tipo_impresion'); + $isCosido = (new TipoPresupuestoModel())->get_isCosido($tipo_impresion_id); + $papel_impresion_id = $this->request->getGet('papel_impresion'); + $tarifa_tipo = $this->request->getGet("tarifa_tipo"); // negro, color, negrohq, colorhq + $uso_tarifa = $this->request->getGet("uso_tarifa") ?? 'interior'; // interior, cubierta, sobrecubierta + $is_rotativa = $this->request->getGet('is_rotativa') ?? 0; + $lomo_redondo = $this->request->getGet('lomo_redondo'); + $lomo = $this->request->getGet('lomo'); + $solapas = $this->request->getGet('solapas'); + $solapas_ancho = $this->request->getGet('solapas_ancho'); + + $model = model('App\Models\Configuracion\MaquinaModel'); + $query = $model->getMaquinaImpresionForPresupuesto( + $is_rotativa, + $tarifa_tipo, + $uso_tarifa, + intval($tirada) + intval($merma), + $papel_impresion_id + ); + if ($this->request->getGet("q")) { + $query->groupStart() + ->orLike("lg_maquinas.nombre", $this->request->getGet("q")) + ->groupEnd(); + } + $data = $query->orderBy("t1.nombre", "asc")->get()->getResultObject(); + + $query = $model->db->getLastQuery(); + $datosPedido = ((object) array( + 'ancho' => $ancho, + 'alto' => $alto, + 'isCosido' => $isCosido, + 'lomo' => $lomo, + 'solapas' => $solapas, + 'solapas_ancho' => $solapas_ancho, + )); + + for ($i = 0; $i < count($data); $i++) { + + if ($is_rotativa) { + + $has_error = true; + for ($f = 0; $f < 2; $f++) { + + $parametrosRotativa = (object) array( + 'a_favor_fibra' => $f, + ); + $values = []; + [$values['ancho'], $values['alto']] = PresupuestoService::calculoDimForma($datosPedido, $parametrosRotativa); + + $factor_anchura = round($data[$i]->ancho_impresion / $values['ancho'], 2); + + if (floor($factor_anchura) != 0) { + $has_error = false; + } + } + if ($has_error) { + unset($data[$i]); + } + } else { + + if ($uso_tarifa != 'interior') { + $datosPedido->anchoExteriores = PresupuestoService::getAnchoTotalExteriores($uso_tarifa, $tipo_impresion_id, $datosPedido, $data[$i]->maquina_id, $lomo_redondo); + $datosPedido->altoExteriores = PresupuestoService::getAltoTotalExteriores($uso_tarifa, $tipo_impresion_id, $datosPedido); + } + + $ancho_calculo = ($uso_tarifa == 'cubierta' || $uso_tarifa == 'sobrecubierta') ? $datosPedido->anchoExteriores : $datosPedido->ancho; + $alto_calculo = ($uso_tarifa == 'cubierta' || $uso_tarifa == 'sobrecubierta') ? $datosPedido->altoExteriores : $datosPedido->alto; + $formas = PresupuestoService::getNumFormasPlana($uso_tarifa, $data[$i], $ancho_calculo, $alto_calculo, $datosPedido->isCosido); + if ($formas['num_formas']['posicion_formas'] == 'n/a') { + unset($data[$i]); + } + } + } + + return $this->response->setJSON($data); + } else { + return $this->failUnauthorized('Invalid request', 403); + } + } + protected function getServiciosPreimpresion() diff --git a/ci4/app/Models/Configuracion/MaquinaModel.php b/ci4/app/Models/Configuracion/MaquinaModel.php index be6f7d01..b2f269e8 100755 --- a/ci4/app/Models/Configuracion/MaquinaModel.php +++ b/ci4/app/Models/Configuracion/MaquinaModel.php @@ -330,7 +330,7 @@ class MaquinaModel extends \App\Models\BaseModel ->table($this->table . " t1") ->distinct('t1.id') ->select( - "t1.id AS maquina_id, t1.nombre AS maquina, t1.ancho_impresion AS ancho_impresion, + "t1.id AS id, t1.id AS maquina_id, t1.nombre AS maquina, t1.nombre AS nombre, t1.ancho_impresion AS ancho_impresion, t1.alto_impresion AS alto_impresion, t1.ancho AS ancho, t1.alto AS alto, t1.is_rotativa AS is_rotativa, t1.is_inkjet AS is_inkjet, t1.alto_click AS alto_click, t1.velocidad AS velocidad, t1.precio_tinta_negro AS precio_tinta_negro, t1.precio_tinta_color AS precio_tinta_color, t1.precio_tinta_cg AS precio_tinta_cg, @@ -361,7 +361,7 @@ class MaquinaModel extends \App\Models\BaseModel $builder->where("t2.uso", $uso_tarifa); } - return $builder->orderBy("t1.id", "asc")->get()->getResultObject(); + return $builder; } diff --git a/ci4/app/Models/Configuracion/PapelImpresionModel.php b/ci4/app/Models/Configuracion/PapelImpresionModel.php index de9473b9..3625daa7 100755 --- a/ci4/app/Models/Configuracion/PapelImpresionModel.php +++ b/ci4/app/Models/Configuracion/PapelImpresionModel.php @@ -279,8 +279,15 @@ class PapelImpresionModel extends \App\Models\BaseModel //tipo: negro, negrohq, color, colorhq //uso: interior, rotativa, cubierta, sobrecubierta - public function getPapelesImpresionForMenu($papel_generico = null, $gramaje = null, $tipo = null, $uso = "") - { + public function getPapelesImpresionForMenu( + $papel_generico = null, + $gramaje = null, + $tipo = null, + $uso = "", + $tapaDura = false, + $forInkjet = false + ) { + $builder = $this->db ->table($this->table . " t1") ->distinct("t1.id") @@ -289,7 +296,7 @@ class PapelImpresionModel extends \App\Models\BaseModel ->join("lg_maquinas t4", "t3.maquina_id = t4.id", "left") ->join("lg_maquinas_tarifas_impresion t5", "t4.id = t5.maquina_id", "left") ->select( - "t1.id AS id, t1.nombre AS text" + "t1.id AS id, t1.nombre AS nombre" ); $builder->where("t1.is_deleted", 0); @@ -304,24 +311,31 @@ class PapelImpresionModel extends \App\Models\BaseModel $builder->where("t2.id", $papel_generico); $builder->where("t1.gramaje", $gramaje); - if ($uso == 'cubierta') + if ($uso == 'cubierta') { + if ($tapaDura) + $builder->where("t1.use_for_tapa_dura", 1); $builder->where("t1.cubierta", 1); - else if ($uso == 'sobrecubierta') + } else if ($uso == 'sobrecubierta') $builder->where("t1.sobrecubierta", 1); else if ($uso == 'guardas') $builder->where("t1.guardas", 1); else { + $builder->where("t1.interior", 1); if ($tipo == 'negro' || $tipo == 'negrohq') $builder->where("t1.bn", 1); else if ($tipo == 'color' || $tipo == 'colorhq') $builder->where("t1.color", 1); } - if ($uso == 'rotativa') + if ($uso == 'rotativa') { $builder->where("t1.rotativa", 1); - else + $builder->where("t4.is_rotativa", 1); + } else $builder->where("t1.rotativa", 0); - return $builder->orderBy("t1.id", "asc")->get()->getResultObject(); + if ($forInkjet) + $builder->where("t1.inkjet", 1); + + return $builder; } public function getNombre($id) @@ -355,5 +369,5 @@ class PapelImpresionModel extends \App\Models\BaseModel return ""; } - + } diff --git a/ci4/app/Services/PresupuestoService.php b/ci4/app/Services/PresupuestoService.php index a9495780..39120a3b 100755 --- a/ci4/app/Services/PresupuestoService.php +++ b/ci4/app/Services/PresupuestoService.php @@ -1687,7 +1687,7 @@ class PresupuestoService extends BaseService uso_tarifa: $uso, tirada: $datosPedido->tirada + $datosPedido->merma, papel_impresion_id: $papel->id, - ); + )->orderBy("t1.id", "asc")->get()->getResultObject(); $data['uso'] = $uso; $data['tipo'] = $tipo; @@ -1775,7 +1775,7 @@ class PresupuestoService extends BaseService uso_tarifa: ($uso == 'guardas') ? 'interior' : $uso, tirada: $datosPedido->tirada + $datosPedido->merma, papel_impresion_id: $papel->id, - ); + )->orderBy("t1.id", "asc")->get()->getResultObject(); // Se recorren las máquinas y se calcula el coste de linea por cada una foreach ($maquinas as $maquina) { diff --git a/ci4/app/Views/themes/vuexy/form/presupuestos/admin/viewPresupuestoadminForm.php b/ci4/app/Views/themes/vuexy/form/presupuestos/admin/viewPresupuestoadminForm.php index 120cb0e9..016f4cac 100644 --- a/ci4/app/Views/themes/vuexy/form/presupuestos/admin/viewPresupuestoadminForm.php +++ b/ci4/app/Views/themes/vuexy/form/presupuestos/admin/viewPresupuestoadminForm.php @@ -19,6 +19,7 @@ getErrors()) ? $validation->listErrors("bootstrap_style") : "" ?> + diff --git a/httpdocs/assets/js/safekat/components/select2.js b/httpdocs/assets/js/safekat/components/select2.js index febfa86c..06bca1f8 100644 --- a/httpdocs/assets/js/safekat/components/select2.js +++ b/httpdocs/assets/js/safekat/components/select2.js @@ -4,15 +4,16 @@ * @param {String} url * @param {String} placeholder */ -let ClassSelect = function (domItem, url, placeholder, allowClear = false, params = {}) { +let ClassSelect = function (domItem, url, placeholder, allowClear = false, params = {}, dropdownParent = "") { this.url = url; this.item = domItem; this.params = params; - + this.dropdownParent = dropdownParent; + this.config = { placeholder: placeholder, allowClear: allowClear, - dropdownParent: domItem.parent(), + dropdownParent: dropdownParent!=""?dropdownParent:domItem.parent(), language: "es", ajax: { url: () => { diff --git a/httpdocs/assets/js/safekat/pages/presupuestoAdmin/presupuestoAdminEdit.js b/httpdocs/assets/js/safekat/pages/presupuestoAdmin/presupuestoAdminEdit.js index 0b281814..2d4b041c 100644 --- a/httpdocs/assets/js/safekat/pages/presupuestoAdmin/presupuestoAdminEdit.js +++ b/httpdocs/assets/js/safekat/pages/presupuestoAdmin/presupuestoAdminEdit.js @@ -4,6 +4,7 @@ import Ajax from '../../components/ajax.js'; import DatosGenerales from './sections/datosGenerales.js'; import DatosLibro from './sections/datosLibro.js'; import Comparador from './sections/comparador.js'; +import LineasPresupuesto from './sections/lineasPresupuesto.js'; class PresupuestoAdminEdit { @@ -19,6 +20,7 @@ class PresupuestoAdminEdit { this.cosido = $("#isCosido"); this.tipo_impresion = $("#tipo_impresion_id"); this.cosido = $("#isCosido"); + this.POD = $("#POD"); this.datosGenerales = new DatosGenerales(this.domItem.find('#accordionDatosPresupuestoTip')); this.datosLibro = new DatosLibro(this.domItem.find('#accordionDatosLibroTip'), @@ -28,6 +30,10 @@ class PresupuestoAdminEdit { checkPaginasPresupuesto: this.checkPaginasPresupuesto, }); this.comparador = new Comparador(this.domItem.find('#accordionDatosPresupuestoClienteTip')); + this.lineasPresupuesto = new LineasPresupuesto(this.domItem.find('#accordionLineasPresupuestoTip'), + { + getDimensionLibro: this.getDimensionLibro, + }); this.calcularPresupuesto = false; } @@ -42,6 +48,7 @@ class PresupuestoAdminEdit { this.datosGenerales.init(); this.datosLibro.init(); this.comparador.init(); + this.lineasPresupuesto.init(); if (window.location.href.includes("edit")) { @@ -74,6 +81,7 @@ class PresupuestoAdminEdit { self.lsc.val(parseFloat(response.data.lsc).toFixed(2)); self.cosido.val(response.data.cosido); self.tipo_impresion.val(response.data.tipo_impresion); + self.POD.val(response.data.POD); self.calcularPresupuesto = false; @@ -164,8 +172,11 @@ class PresupuestoAdminEdit { alto = parseFloat($('#papelFormatoAlto').val()); } else { - ancho = parseFloat($('#papelFormatoId').getText().trim().split(" x ")[0]); - alto = parseFloat($('#papelFormatoId').getText().trim().split(" x ")[1]); + const selectedText = $('#papelFormatoId').find('option:selected').text(); + if (selectedText.length > 0) { + ancho = parseFloat(selectedText.trim().split(" x ")[0]); + alto = parseFloat(selectedText.trim().split(" x ")[1]); + } } return { diff --git a/httpdocs/assets/js/safekat/pages/presupuestoAdmin/sections/comparador.js b/httpdocs/assets/js/safekat/pages/presupuestoAdmin/sections/comparador.js index 61c553f2..60cf5a34 100644 --- a/httpdocs/assets/js/safekat/pages/presupuestoAdmin/sections/comparador.js +++ b/httpdocs/assets/js/safekat/pages/presupuestoAdmin/sections/comparador.js @@ -961,8 +961,8 @@ class Comparador { cliente_id: $('#clienteId').select2('data')[0].id, papel_generico: papel_generico, gramaje: gramaje, - isColor: this.tipo_impresion.val().includes('color'), - isHq: this.tipo_impresion.val().includes('hq'), + isColor: this.tipo_impresion.val().includes('color')?1:0, + isHq: this.tipo_impresion.val().includes('hq')?1:0, paginas_color: paginasColor } @@ -970,7 +970,9 @@ class Comparador { datos.datosPedido.lomo = this.getLomoLineasPresupuesto('interior'); datos.datosPedido.solapas = $('#solapas').prop('checked') ? 1 : 0; datos.datosPedido.solapas_ancho = $('#solapas').prop('checked') ? parseInt($('#solapas_ancho').val()) : 0; - datos.lomoRedondo = this.lomoRedondo.val(); + if (this.tipo_impresion_id == 1 || this.tipo_impresion_id == 3){ + datos.lomoRedondo = this.lomoRedondo.val(); + } } else if (uso == 'sobrecubierta') { datos.datosPedido.lomo = this.getLomoLineasPresupuesto() + this.getLomoLineasPresupuesto('cubierta'); @@ -1039,8 +1041,8 @@ class Comparador { } else { - const isHq = this.tipo_impresion.val().includes('hq'); - const isColor = this.tipo_impresion.val().includes('color'); + const isHq = this.tipo_impresion.val().includes('hq')?1:0; + const isColor = this.tipo_impresion.val().includes('color')?1:0; datosComp.data['tipo_maquina'] = 'plana'; datosComp.data[this.csrf_token] = this.csrf_hash; diff --git a/httpdocs/assets/js/safekat/pages/presupuestoAdmin/sections/datosLibro.js b/httpdocs/assets/js/safekat/pages/presupuestoAdmin/sections/datosLibro.js index 65637230..fe29d3e1 100644 --- a/httpdocs/assets/js/safekat/pages/presupuestoAdmin/sections/datosLibro.js +++ b/httpdocs/assets/js/safekat/pages/presupuestoAdmin/sections/datosLibro.js @@ -289,15 +289,16 @@ class DatosLibro { calcular_mermas(){ - const tirada = parseInt($('#tirada').val()) - var merma = 0 - htmlString = '' + const tirada = parseInt($('#tirada').val()); + const POD = parseInt($('#POD').val()); + let merma = 0; + let htmlString = ''; - if(tirada> parseInt($('#POD').val())){ - merma = tirada*0.1<=30 ? tirada*0.1 : 30 + if(tirada> POD){ + merma = tirada*0.1<=POD ? tirada*0.1 : POD; } else{ - merma_lineas = [] + let merma_lineas = [] tableLineasPresupuesto.rows().every( function ( rowIdx, tableLoop, rowLoop ) { var rowData = this.data(); if(rowData.row_id != 'lp_guardas' && rowData.row_id != 'lp_cubierta' && rowData.row_id != 'lp_sobrecubierta'){ @@ -342,6 +343,7 @@ class DatosLibro { this.paginas.val(datos.paginas); this.tirada.val(datos.tirada); + this.calcular_mermas(); if (datos.papelFormatoPersonalizado) { this.tamanioPersonalizado.prop('checked', true); $(".tamanio-personalizado").removeClass('d-none'); diff --git a/httpdocs/assets/js/safekat/pages/presupuestoAdmin/sections/lineasPresupuesto.js b/httpdocs/assets/js/safekat/pages/presupuestoAdmin/sections/lineasPresupuesto.js index 1e655a47..869655af 100644 --- a/httpdocs/assets/js/safekat/pages/presupuestoAdmin/sections/lineasPresupuesto.js +++ b/httpdocs/assets/js/safekat/pages/presupuestoAdmin/sections/lineasPresupuesto.js @@ -1,26 +1,62 @@ -import Ajax from "../../../components/ajax"; -import ClassSelect from "../../../components/select2"; +import ClassSelect from '../../../components/select2.js'; +import { getToken } from '../../../common/common.js'; +import Ajax from '../../../components/ajax.js'; + class LineasPresupuesto { constructor(domItem, functions = {}) { this.domItem = domItem; - this.functions = functions; + this.getDimensionLibro = functions.getDimensionLibro; this.table = null; + this.csrf_token = getToken(); + this.csrf_hash = $('#mainContainer').find('input[name="' + this.csrf_token + '"]').val(); + this.addLineaManual = this.domItem.find("#btn_addLinea"); } init() { + const self = this; + this.#initTable(); - this.addLineaManual.on('click', + this.addLineaManual.on('click', this.#insertLineaManual.bind(this)); + + // Botones de borrar de las lineas de presupuesto + $(document).on('click', '.btn-delete-lp', function (e) { + + const row = $(this).closest('tr'); + const data = self.table.row(row).data() + self.table.row(row) + .remove() + .draw(); + + // TO-DO + /*updatePresupuesto({ + update_lineas: false, + update_servicios: true, + update_envios: true, + update_resumen: true, + update_tiradas_alternativas: true + }) + if (data.row_id == 'lp_guardas') + servicioGuardas(false) + */ + + // Si existe cubierta, hay que actualizar con el valor del lomo + if (self.table.row('#lp_cubierta').length > 0) { + self.obtenerLinea('lp_cubierta', false, false); + } + }); } #initTable() { + const self = this; + const lastColNr_lp = $('#tableLineasPresupuesto').find("tr:first th").length - 1; const actionBtns_lp = function (data) { @@ -113,7 +149,7 @@ class LineasPresupuesto { if (row.row_id != "lp_cubierta" && row.row_id != "lp_sobrecubierta" && row.row_id != "lp_guardas") return ''; else if (row.row_id == "lp_cubierta") { - select = '' if (data == 2) { select += ''; + select.append(option); } return select[0].outerHTML @@ -223,8 +251,10 @@ class LineasPresupuesto { .addClass('form-control form-select-sm lp-cell lp-select ')//+ row.row_class + '-select') .css('min-width', '40px') - var option = ''; - select.append(option); + if (data) { + var option = ''; + select.append(option); + } return select[0].outerHTML } @@ -238,8 +268,10 @@ class LineasPresupuesto { .addClass('form-control form-select-sm lp-cell lp-select ' + row.row_class + '-select') .css('min-width', '150px') - var option = ''; - select.append(option); + if (data) { + var option = ''; + select.append(option); + } return select[0].outerHTML } @@ -253,8 +285,10 @@ class LineasPresupuesto { .addClass('form-control form-select-sm lp-cell lp-select ' + row.row_class + '-select') .css('min-width', '110px') - var option = ''; - select.append(option); + if (data) { + var option = ''; + select.append(option); + } return select[0].outerHTML } @@ -288,12 +322,12 @@ class LineasPresupuesto { className: 'row-edit dt-center' } ], - "order": [10, 'asc'] + "order": [10, 'asc'], }); this.table.on('click', 'td.dt-control', function (e) { let tr = e.target.closest('tr'); - let row = tableLineasPresupuesto.row(tr); + let row = self.table.row(tr); if (row.child.isShown()) { // This row is already open - close it @@ -301,7 +335,7 @@ class LineasPresupuesto { } else { // Open this row - row.child(format(row.data())).show(); + row.child(self.formatRow(row.data())).show(); } }); } @@ -320,20 +354,20 @@ class LineasPresupuesto { if (dataRows[number].row_id == 'lp_bn' || dataRows[number].row_id == 'lp_bnhq' || dataRows[number].row_id == 'lp_rot_bn') { - hayLinea = true - continue + hayLinea = true; + continue; } } if (hayLinea) { popErrorAlert(window.language.Presupuestos.errores.lineaDuplicada, 'divAlarmasLineasPresupuesto'); - break + break; } - var data = processRowData({ tipo_maquina: 'toner' }, 'lp_bn', 'lp-bn'); - tableLineasPresupuesto.row.add(data).draw() - eventos_lp_bn() - break + var data = this.#processRowData({ tipo_maquina: 'toner' }, 'lp_bn', 'lp-bn'); + this.table.row.add(data).draw(); + this.#addEventosLineas('lp_bn', false); + break; case 'lp_bnhq': var hayLinea = false @@ -351,9 +385,9 @@ class LineasPresupuesto { break } - var data = processRowData({ tipo_maquina: 'toner' }, 'lp_bnhq', 'lp-bnhq'); - tableLineasPresupuesto.row.add(data).draw() - eventos_lp_bnhq() + var data = this.#processRowData({ tipo_maquina: 'toner' }, 'lp_bnhq', 'lp-bnhq'); + this.table.row.add(data).draw() + this.#addEventosLineas('lp_bnhq', false); break case 'lp_color': @@ -362,19 +396,19 @@ class LineasPresupuesto { if (dataRows[number].row_id == 'lp_color' || dataRows[number].row_id == 'lp_colorhq' || dataRows[number].row_id == 'lp_rot_color') { - hayLinea = true - continue + hayLinea = true; + continue; } } if (hayLinea) { popErrorAlert(window.language.Presupuestos.errores.lineaDuplicada, 'divAlarmasLineasPresupuesto'); - break + break; } - var data = processRowData({ tipo_maquina: 'toner' }, 'lp_color', 'lp-color'); - tableLineasPresupuesto.row.add(data).draw() - eventos_lp_color() + var data = this.#processRowData({ tipo_maquina: 'toner' }, 'lp_color', 'lp-color'); + this.table.row.add(data).draw(); + this.#addEventosLineas('lp_color', false); break case 'lp_colorhq': @@ -390,13 +424,13 @@ class LineasPresupuesto { if (hayLinea) { popErrorAlert(window.language.Presupuestos.errores.lineaDuplicada, 'divAlarmasLineasPresupuesto'); - break + break; } - var data = processRowData({ tipo_maquina: 'toner' }, 'lp_colorhq', 'lp-colorhq'); - tableLineasPresupuesto.row.add(data).draw() - eventos_lp_colorhq() - break + var data = this.#processRowData({ tipo_maquina: 'toner' }, 'lp_colorhq', 'lp-colorhq'); + this.table.row.add(data).draw(); + this.#addEventosLineas('lp_colorhq', false); + break; case 'lp_rot_bn': var hayLinea = false @@ -404,19 +438,19 @@ class LineasPresupuesto { if (dataRows[number].row_id == 'lp_bn' || dataRows[number].row_id == 'lp_bnhq' || dataRows[number].row_id == 'lp_rot_bn') { - hayLinea = true - continue + hayLinea = true; + continue; } } if (hayLinea) { popErrorAlert(window.language.Presupuestos.errores.lineaDuplicada, 'divAlarmasLineasPresupuesto'); - break + break; } - var data = processRowData({ tipo_maquina: 'toner' }, 'lp_rot_bn', 'lp-rot-bn'); - tableLineasPresupuesto.row.add(data).draw() - eventos_lp_rot_bn() + var data = this.#processRowData({ tipo_maquina: 'toner' }, 'lp_rot_bn', 'lp-rot-bn'); + this.table.row.add(data).draw(); + this.#addEventosLineas('lp_rot_bn', false); break case 'lp_rot_color': @@ -425,85 +459,82 @@ class LineasPresupuesto { if (dataRows[number].row_id == 'lp_color' || dataRows[number].row_id == 'lp_colorhq' || dataRows[number].row_id == 'lp_rot_color') { - hayLinea = true - continue + hayLinea = true; + continue; } } if (hayLinea) { popErrorAlert(window.language.Presupuestos.errores.lineaDuplicada, 'divAlarmasLineasPresupuesto'); - break + break; } - var data = processRowData({ tipo_maquina: 'toner' }, 'lp_rot_color', 'lp-rot-color'); - tableLineasPresupuesto.row.add(data).draw() - eventos_lp_rot_color() - break + var data = this.#processRowData({ tipo_maquina: 'toner' }, 'lp_rot_color', 'lp-rot-color'); + this.table.row.add(data).draw() + this.#addEventosLineas('lp_rot_color', false); + break; case 'lp_cubierta': var hayLinea = false for (let number = 0; number < dataRows.length; number++) { if (dataRows[number].row_id == 'lp_cubierta') { - hayLinea = true - continue + hayLinea = true; + continue; } } if (hayLinea) { popErrorAlert(window.language.Presupuestos.errores.lineaDuplicada, 'divAlarmasLineasPresupuesto'); - break + break; } - var data = processRowData({ tipo_maquina: 'toner' }, 'lp_cubierta', 'lp-cubierta'); - tableLineasPresupuesto.row.add(data).draw() - eventos_lp_cubierta() + var data = this.#processRowData({ tipo_maquina: 'toner' }, 'lp_cubierta', 'lp-cubierta'); + this.table.row.add(data).draw(); + this.#addEventosLineas('lp_cubierta', false); break case 'lp_sobrecubierta': var hayLinea = false for (let number = 0; number < dataRows.length; number++) { if (dataRows[number].row_id == 'lp_sobrecubierta') { - hayLinea = true - continue + hayLinea = true; + continue; } } if (hayLinea) { popErrorAlert(window.language.Presupuestos.errores.lineaDuplicada, 'divAlarmasLineasPresupuesto'); - break + break; } - var data = processRowData({ tipo_maquina: 'toner' }, 'lp_sobrecubierta', 'lp-sobrecubierta'); - tableLineasPresupuesto.row.add(data).draw() - eventos_lp_sobrecubierta() + var data = this.#processRowData({ tipo_maquina: 'toner' }, 'lp_sobrecubierta', 'lp-sobrecubierta'); + this.table.row.add(data).draw(); + this.#addEventosLineas('lp_sobrecubierta', false); break case 'lp_guardas': var hayLinea = false for (let number = 0; number < dataRows.length; number++) { if (dataRows[number].row_id == 'lp_guardas') { - hayLinea = true - continue + hayLinea = true; + continue; } } if (hayLinea) { popErrorAlert(window.language.Presupuestos.errores.lineaDuplicada, 'divAlarmasLineasPresupuesto'); - break + break; } - var data = processRowData({ tipo_maquina: 'toner' }, 'lp_guardas', 'lp-guardas'); - tableLineasPresupuesto.row.add(data).draw() - $('#lp_guardas_gramaje').empty() - var o = new Option("170", "170"); - $('#lp_guardas_gramaje').append(o) - eventos_lp_guardas() - servicioGuardas(true) + var data = this.#processRowData({ tipo_maquina: 'toner' }, 'lp_guardas', 'lp-guardas'); + this.table.row.add(data).draw() + this.#addEventosLineas('lp_guardas', false); + servicioGuardas(true); break default: break } - $("#tableLineasPresupuesto").DataTable().columns.adjust(); + this.table.columns.adjust(); } #processRowData(row, rowId, rowClass) { @@ -511,40 +542,40 @@ class LineasPresupuesto { var icon = "" if (rowId == 'lp_bn') { if (row.tipo_maquina == 'toner') - icon = '' + icon = '/themes/vuexy/img/safekat/presupuestos/icon_bn.png' else - icon = '' + icon = '/themes/vuexy/img/safekat/presupuestos/icon_inkjet_bn.png'; } else if (rowId == 'lp_bnhq') { if (row.tipo_maquina == 'toner') - icon = '' + icon = '/themes/vuexy/img/safekat/presupuestos/icon_bnhq.png'; else - icon = '' + icon = '/themes/vuexy/img/safekat/presupuestos/icon_inkjet_bn.png'; } else if (rowId == 'lp_color') { if (row.tipo_maquina == 'toner') - icon = '' + icon = '/themes/vuexy/img/safekat/presupuestos/icon_color.png'; else - icon = '' + icon = '/themes/vuexy/img/safekat/presupuestos/icon_inkjet_color.png'; } else if (rowId == 'lp_colorhq') { if (row.tipo_maquina == 'toner') - icon = '' + icon = '/themes/vuexy/img/safekat/presupuestos/icon_colorhq.png'; else - icon = '' + icon = '/themes/vuexy/img/safekat/presupuestos/icon_inkjet_color.png'; } else if (rowId == 'lp_cubierta') - icon = '' + icon = '/themes/vuexy/img/safekat/presupuestos/icon_cubierta.png'; else if (rowId == 'lp_sobrecubierta') - icon = '' + icon = '/themes/vuexy/img/safekat/presupuestos/icon_sobrecubierta.png'; else if (rowId == 'lp_guardas') - icon = '' + icon = '/themes/vuexy/img/safekat/presupuestos/icon_guardas.png'; else if (rowId == 'lp_rot_bn') - icon = '' + icon = '/themes/vuexy/img/safekat/presupuestos/icon_rotativa_bn.png'; else if (rowId == 'lp_rot_color') - icon = '' + icon = '/themes/vuexy/img/safekat/presupuestos/icon_rotativa_color.png'; const blank_line = (typeof row.tarifa_impresion_id === 'undefined') ? 1 : 0; var data = { @@ -565,6 +596,7 @@ class LineasPresupuesto { 'paginas': blank_line ? 0 : row.paginas, 'paginas_impresion': rowId == 'lp_guardas' ? row.paginas_impresion : 0, 'papel': blank_line ? "" : row.papel_generico_id, + 'papel_nombre': blank_line ? "" : row.papel_generico, 'gramaje': blank_line ? "" : row.gramaje, 'papel_impresion': blank_line ? "" : row.papel_impresion, 'papel_impresion_id': blank_line ? "" : row.papel_impresion_id, @@ -662,28 +694,674 @@ class LineasPresupuesto { return data } - #addEventosLineas(tipoLinea, isInkjet = false) { + formatRow(d) { + + var value = ''+ + ''+ + ''+ + ''+ + '
' + + '
' + + window.language.Presupuestos.numeroPliegos + + ''+ + '
'+ + '
' + + window.language.Presupuestos.pliegosPedido + + ''+ + '
'+ + '
' + + window.language.Presupuestos.precioPliego + + ''+ + '
'+ + '
' + + window.language.Presupuestos.libro + + ''+ + '
'+ + '
' + + window.language.Presupuestos.totalPapelPedido + + ''+ + '
'+ + '' + + '
' + + '' + + '
'+ + '
' + + window.language.Presupuestos.click + + ''+ + '
'+ + '
' + + window.language.Presupuestos.totalClicks + + ''+ + '
'+ + '
' + + window.language.Presupuestos.horas + + ''+ + '
'+ + '
' + + window.language.Presupuestos.precioHora + + ''+ + '
'+ + '
' + + window.language.Presupuestos.precioImpresion + + ''+ + '
'+ + '
' + + '' + + '
'+ + '' + + '' + + '
' + + '' + + + + + value += '' + + if(d.maquinaTipo=='inkjet'){ + value += + ''+ + ''+ + ''+ + ''+ + '
' + + '
' + + '' + + '
'+ + '
' + + window.language.Presupuestos.numPagColor + + '' + + '
' + + ((d.row_id.includes('rot'))?'
' + + window.language.Presupuestos.saturacion + + '' + + '
':'') + + '
' + + window.language.Presupuestos.cobNegro + + '' + + '
' + + '
' + + window.language.Presupuestos.cobCyan + + '' + + '
' + + '
' + + window.language.Presupuestos.cobMagenta + + '' + + '
' + + '
' + + window.language.Presupuestos.cobAmarillo + + '' + + '
' + + ((!d.row_id.includes('rot'))? + '
' + + window.language.Presupuestos.cobCG + + '' + + '
':'') + + '
' + + window.language.Presupuestos.gotaNegro + + '' + + '
' + + '
' + + window.language.Presupuestos.gotaColor + + '' + + '
' + + '
' + + window.language.Presupuestos.aFavorFibra + + '' + + '
' + + '
' + + '' + + '
' + + '
' + + + '' + + '' + + ''+ + ''+ + ''+ + ''+ + '
' + + ((!d.row_id.includes('rot'))? + '
' + + window.language.Presupuestos.factorAltura + + '' + + '
' + + '
' + + window.language.Presupuestos.factorAnchura + + '' + + '
':'') + + (d.row_id.includes('rot')?'
': '' + + + (d.row_id.includes('rot')?'
' + + window.language.Presupuestos.resolucion + + '' + + '
':'') + + (d.row_id.includes('rot')?'
' + + window.language.Presupuestos.areaPaginas + + '' + + '
':'') + + '
' + + window.language.Presupuestos.gotasNegro + + '' + + '
' + + '
' + + window.language.Presupuestos.gotasCyan + + '' + + '
' + + '
' + + window.language.Presupuestos.gotasMagenta + + '' + + '
' + + '
' + + window.language.Presupuestos.gotasAmarillo + + '' + + '
' + + (!(d.row_id.includes('rot'))?'
' + + window.language.Presupuestos.gotasCG + + '' + + '
':'') + + '
' + + window.language.Presupuestos.precioPagNegro + + '' + + '
' + + '
' + + window.language.Presupuestos.precioPagColor + + '' + + '
' + + (d.row_id.includes('rot')? + '
' + + window.language.Presupuestos.factorAltura + + '' + + '
' + + '
' + + window.language.Presupuestos.factorAnchura + + '' + + '
':'') + + (d.row_id.includes('rot')?'
' + + window.language.Presupuestos.paginasPliego + + '' + + '
':'') + + '
' + + '' + + '' + + ''+ + ''+ + ''+ + ''+ + '
' + + (d.row_id.includes('rot')?'
': '' + + (d.row_id.includes('rot')?'
': '' + + (d.row_id.includes('rot')?'
' + + window.language.Presupuestos.clicksLibro + + '' + + '
':'') + + ((!d.row_id.includes('rot'))?'
' + + window.language.Presupuestos.saturacion + + '' + + '
':'') + + ((!d.row_id.includes('rot'))?'
' + + window.language.Presupuestos.paginasPliego + + '' + + '
':'') + + '
' + + window.language.Presupuestos.gTintaNegro + + '' + + '
' + + '
' + + window.language.Presupuestos.gTintaCyan + + '' + + '
' + + '
' + + window.language.Presupuestos.gTintaMagenta + + '' + + '
' + + '
' + + window.language.Presupuestos.gTintaAmarillo + + '' + + '
' + + (!(d.row_id.includes('rot'))?'
' + + window.language.Presupuestos.gTintaCG + + '' + + '
':'') + + ((!d.row_id.includes('rot'))?'
' + + window.language.Presupuestos.clicksLibro + + '' + + '
':'') + + '
' + + window.language.Presupuestos.clicksPedido + + '' + + '
' + + '
' + + window.language.Presupuestos.totalClicks + + '' + + '
' + + '
' + + window.language.Presupuestos.totalTinta + + '' + + '
' + + (d.row_id.includes('rot')?'
': '' + + '
' + + window.language.Presupuestos.totalImpresion + + '' + + '
' + + '
' + + '' + + '' + + ''+ + ''+ + ''+ + ''+ + '
' + + ((!d.row_id.includes('rot'))?'
' + + window.language.Presupuestos.resolucion + + '' + + '
':'') + + ((!d.row_id.includes('rot'))?'
' + + window.language.Presupuestos.areaPaginas + + '' + + '
':'') + + (d.row_id.includes('rot')?'
': '' + + (d.row_id.includes('rot')?'
': '' + + (d.row_id.includes('rot')?'
': '' + + '
' + + window.language.Presupuestos.gTintaNegroPed + + '' + + '
' + + '
' + + window.language.Presupuestos.gTintaCyanPed + + '' + + '
' + + '
' + + window.language.Presupuestos.gTintaMagentaPed + + '' + + '
' + + '
' + + window.language.Presupuestos.gTintaAmarilloPed + + ''+ + '
' + + (!(d.row_id.includes('rot'))?'
' + + window.language.Presupuestos.gTintaCGPed + + ''+ + '
':'') + + '
' + + '' + + '' + } + + return $(value).toArray(); + } - $('#' + tipoLinea + '_papel').on("change", change_papelGenerico_lp_bn); - $('#' + tipoLinea + '_gramaje').on("focus", { mantenerSeleccion: true }, set_lp_bn_gramaje); - $('#' + tipoLinea + '_gramaje').on('change', function () { - var previous = $(this).data('val'); - const selected = $("select#lp_bn_gramaje option:selected"); - if (selected.text() != previous) { - clear_lp_bn(true) + + getLomoInterior() { + let lomo = 0; + this.table.rows().every(function (rowIdx, tableLoop, rowLoop) { + if (this.data().row_id != 'lp_cubierta' && this.data().row_id != 'lp_sobrecubierta' && this.data().row_id != 'lp_guardas' && this.data().row_id != 'lp_rot_bn' && this.data().row_id != 'lp_fajas') { + lomo += parseFloat(this.data().mano); } }); - $('#' + tipoLinea + '_papelImpresion').on("focus", set_lp_bn_papelImpresion); - $('#' + tipoLinea + '_maquina').on("focus", set_lp_bn_maquina); - $('#' + tipoLinea + '_maquina').on("change", change_lp_bn_maquina); - $('#' + tipoLinea + '_vercalculos').on("click", { rowId: 'lp_bn' }, verCalculosInkjet); + return lomo; + } + + getLomoCubierta() { + this.table.rows().every(function (rowIdx, tableLoop, rowLoop) { + if (this.data().row_id == 'lp_cubierta') { + return parseFloat(this.data().mano); + } + }); + return 0; + } + + + obtenerLinea(linea = 'lp_bn', fromComparador = false, updatedTipologias = false, input_data = {}) { + + const self = this; + const dimension = this.getDimensionLibro(); + + if (Object.keys(input_data).length == 0) { + + input_data = { + paginas: parseInt($('#' + linea + '_paginas').val()), + papel_generico_id: $('#' + linea +'_papel option:selected').val(), + papel_generico: $('#' + linea + '_papel option:selected').text().trim(), + gramaje: $('#' + linea + '_gramaje option:selected').text().trim(), + maquina_id: $('#' + linea + '_maquina option:selected').val(), + papel_impresion_id: $('#' + linea + '_papelImpresion option:selected').val() + } + } + + + if(input_data.maquina_id == undefined || input_data.maquina_id == '') { + return; + } + if(linea != 'lp_guardas' && linea != 'lp_sobrecubierta' && linea != 'lp_faja' ) { + if(input_data.paginas == 0 ) + return; + } + + let uso = 'interior'; + switch (linea) { + case 'lp_cubierta': + uso = 'cubierta'; + break; + case 'lp_sobrecubierta': + uso = 'sobrecubierta'; + break; + case 'lp_guardas': + uso = 'guardas'; + break; + case 'lp_rot_bn': + case 'lp_rot_color': + uso = 'interior_rot'; + break; + } + + let color = 1; + if (linea == 'lp_bn' || linea == 'lp_bnhq' || linea == 'lp_rot_bn') { + color = 0; + } + let hq = 1; + if (linea == 'lp_bn' || linea == 'lp_color' || linea == 'lp_rot_bn' || linea == 'lp_rot_color') { + hq = 0; + } + + + var datos = { + tipo_impresion_id: $('#tipo_impresion_id').val(), + type: uso, + color: color, + hq: hq, + paginas: input_data.paginas, + tirada: parseInt($('#tirada').val()), + merma: parseInt($('#merma').val()), + ancho: dimension.ancho, + alto: dimension.alto, + papel_generico_id: input_data.papel_generico_id, + papel_generico: input_data.papel_generico, + gramaje: input_data.gramaje, + cliente_id: $('#clienteId').find(":selected").val(), + }; + datos = Object.assign(datos, window.token_ajax); + + // Si es inkjet, existe este check + if ($('#lp_bn_aFavorFibra').length) { + datos.a_favor_fibra = $('#lp_bn_aFavorFibra').prop('checked') + } + + if (updatedTipologias && $('#lp_bn_gotaNegro').length) { + datos.gota_negro = $('#lp_bn_gotaNegro').val() + datos.gota_color = $('#lp_bn_gotaColor').val() + datos.negro = $('#lp_bn_cobNegro').val() + datos.cyan = $('#lp_bn_cobCyan').val() + datos.magenta = $('#lp_bn_cobMagenta').val() + datos.amarillo = $('#lp_bn_cobAmarillo').val() + if ($('#lp_bn_cobCG').length) { + datos.cg = $('#lp_bn_cobCG').val() + } + } + + new Ajax('/presupuestoadmin/getlinea', + datos, + {}, + (response) =>{ + if(response.lineas.length >0){ + + $.each(response.lineas, function(key, value) { + // Se cogen los valores de la linea con los datos correspondientes + if(value.fields.maquina_id === input_data.maquina_id && + value.fields.papel_generico_id === input_data.papel_generico_id && + value.fields.papel_impresion_id === input_data.papel_impresion_id) { + + // Si viene del comparador + if(Object.keys(input_data).length == 0){ + value.fields.check_papel_total = $('#'+ linea + '_checkPapel').is(":checked")?1:0 + value.fields.check_impresion_total = $('#'+ linea + '_checkClicks').is(":checked")?1:0 + + } + else{ + value.fields.check_papel_total = 1 + value.fields.check_impresion_total = 1 + } + self.rellenarDatosLinea(linea,value.fields); + + return false; + } + }); + } + else{ + let pags = $("#" + linea + "_paginas" ).val() + $("." + linea +"-input" ).val("0") + $("#"+ linea +"_paginas" ).val(pags) + + } + }, + (error) =>{ + console.error(error); + } + ).post(); + + } + + rellenarDatosLinea(linea, row, fromComparator=false){ + + + if(fromComparator){ + + var input_data = { + paginas: row.paginas, + papel_generico_id: row.papelGenericoId, + gramaje: row.gramaje, + papel_impresion_id: row.papelImpresionId, + maquina_id: row.maquinaId, + } + this.obtenerLinea(linea, fromComparator, input_data) + } + else{ + // Se guarda el estado de "ver calculos" + const mostrar_calculos = ($( ".calculos_"+ linea).css('display') == 'table-row') + + // Si viene de hacerlo a mano... + let data = this.#processRowData(row, linea, linea.replace('_', '-')); + + let currentRow = this.table.row('#' + linea); + if(currentRow.length>0) + this.table.row('#' + linea).data(data).draw() + else{ + this.table.row.add(data).draw() + currentRow = this.table.row('#' + linea); + } + currentRow.child(this.formatRow(currentRow.data())).show(); + + this.#addEventosLineas(linea, data.maquinaTipo=='inkjet'?true:false); + + + $('#'+ linea + '_checkPapel').trigger('change'); + + + /* TO-DO + calcular_mermas() + + updatePresupuesto({ + update_lineas: false, + update_servicios: true, + update_envios: true, + update_resumen: true, + update_tiradas_alternativas: true + }) + */ + + // Si existe cubierta, hay que actualizar con el valor del lomo + if (this.table.row('#lp_cubierta').length > 0) { + this.obtenerLinea('lp_cubierta', false, false); + } + if(mostrar_calculos){ + $( ".calculos_" + linea).css('display','table-row') + } + } + + this.table.columns.adjust(); + + } + + #addEventosLineas(tipoLinea, isInkjet = false) { + + const self = this; + + let tipo = 'negro'; + let uso = 'interior'; + switch (tipoLinea) { + case 'lp_negrohq': + tipo = 'negrohq'; + break; + case 'lp_rot_color': + case 'lp_color': + tipo = 'color'; + break; + case 'lp_colorhq': + case 'lp_guardas': + case 'lp_cubierta': + case 'lp_sobrecubierta': + tipo = 'colorhq'; + break + default: + break; + } + + switch (tipoLinea) { + case 'lp_cubierta': + uso = 'cubierta'; + break; + case 'lp_sobrecubierta': + uso = 'sobrecubierta'; + break; + case 'lp_guardas': + uso = 'guardas'; + break; + case 'lp_rot_bn': + case 'lp_rot_color': + uso = 'rotativa'; + break; + default: + break; + } + + let select_papel = new ClassSelect($('#' + tipoLinea + '_papel'), + '/presupuestoadmin/papelgenerico', 'Seleccione papel', false, + { + [this.csrf_token]: this.csrf_hash, + tipo_impresion: () => $("#tipo_impresion_id").val(), + tirada: () => $('#tirada').val(), + tipo: tipo, + uso: uso, + }, $('body')); + select_papel.init(); + + + let select_gramaje = new ClassSelect($('#' + tipoLinea + '_gramaje'), + '/presupuestoadmin/papelgramaje', 'Seleccione gramaje', false, + { + [this.csrf_token]: this.csrf_hash, + papel_generico: () => select_papel.getVal(), + tipo_impresion: () => $("#tipo_impresion_id").val(), + tirada: () => $('#tirada').val(), + tipo: tipo, + uso: uso, + }, $('body')); + select_gramaje.init(); + + let papel_impresion = new ClassSelect($('#' + tipoLinea + '_papelImpresion'), + '/presupuestoadmin/papelimpresion', 'Seleccione papel', false, + { + [this.csrf_token]: this.csrf_hash, + papel_generico: () => select_papel.getVal(), + gramaje: () => select_gramaje.getVal(), + tipo_impresion: () => $("#tipo_impresion_id").val(), + tipo: tipo, + uso: uso, + }, $('body')); + papel_impresion.init(); + + let merma = uso == 'interior' ? $('#merma').val() : $('#mermacubierta').val(); + uso = ((uso == 'guardas') ? 'cubierta' : uso); + + let maquinas = new ClassSelect($('#' + tipoLinea + '_maquina'), + '/presupuestoadmin/maquinas', 'Seleccione maquina', false, + { + [this.csrf_token]: this.csrf_hash, + ancho: () => this.getDimensionLibro().ancho, + alto: () => this.getDimensionLibro().alto, + solapas: () => uso == 'cubierta' ? $('#solapas').prop('checked') : $('#solapas_sobrecubierta').prop('checked'), + solapas_ancho: () => uso == 'cubierta' ? $('#solapas_ancho').val() : $('#solapas_ancho_sobrecubierta').val(), + tirada: () => $('#tirada').val(), + merma: merma, + papel_impresion: () => papel_impresion.getVal(), + tipo_impresion: () => $("#tipo_impresion_id").val(), + tarifa_tipo: tipo, + uso_tarifa: uso == 'rotativa' ? 'interior' : uso, + is_rotativa: () => tipoLinea.includes('rot') ? 1 : 0, + lomo_redondo: () => (this.tipo_impresion_id == 1 || this.tipo_impresion_id == 3) ? $('#compLomoRedondo').val() : 0, + lomo: () => uso == 'sobrecubierta' ? this.getLomoCubierta() : this.getLomoInterior(), + }, $('body')); + maquinas.init(); + + + $('#' + tipoLinea + '_papel').on("change", () => { + select_gramaje.reset(); + papel_impresion.reset(); + maquinas.reset(); + }); + $('#' + tipoLinea + '_gramaje').on('change', () => { + papel_impresion.reset(); + maquinas.reset(); + }); + $('#' + tipoLinea + '_papelImpresion').on("change", () => { maquinas.reset(); }); + + $('#' + tipoLinea + '_maquina').on("change", function (event) { + self.obtenerLinea(tipoLinea, false, false, {}, event); // Pasamos explícitamente 'tipoLinea' + }.bind(this)); + $('#' + tipoLinea + '_paginas').on("change", function (event) { + if(tipoLinea != 'lp_sobrecubierta') { + self.obtenerLinea(tipoLinea, false, false, {}, event); // Pasamos explícitamente 'tipoLinea' + } + }.bind(this)); + $('#' + tipoLinea + '_vercalculos').on("click", ()=> self.verCalculosInkjet(tipoLinea)); + /* TO-DO if (isInkjet) { $('.' + tipoLinea + '-tipologia').on("change", change_lp_bn_tipologia); $('#' + tipoLinea + '_defecto').on("click", por_defecto_lp_bn); $('#' + tipoLinea + '_aFavorFibra').on("change", change_lp_bn_aFavorFibra); - } + }*/ } + + + verCalculosInkjet(linea){ + if($( ".calculos_" + linea ).css('display') == 'none') + $( ".calculos_" + linea ).css('display', 'table-row') + else{ + $( ".calculos_" + linea ).css('display', 'none') + } + }; } export default LineasPresupuesto; \ No newline at end of file