diff --git a/ci4/app/Config/Routes.php b/ci4/app/Config/Routes.php index 90a9702f..df17c46b 100644 --- a/ci4/app/Config/Routes.php +++ b/ci4/app/Config/Routes.php @@ -172,6 +172,7 @@ $routes->group('tarifapreimpresion', ['namespace' => 'App\Controllers\Tarifas'], $routes->get('delete/(:num)', 'Tarifapreimpresion::delete/$1', ['as' => 'deleteTarifapreimpresion']); $routes->post('allmenuitems', 'Tarifapreimpresion::allItemsSelect', ['as' => 'select2ItemsOfTarifaspreimpresion']); $routes->post('menuitems', 'Tarifapreimpresion::menuItems', ['as' => 'menuItemsOfTarifaspreimpresion']); + $routes->get('gettarifas', 'Tarifapreimpresion::getSelect2'); }); @@ -186,6 +187,7 @@ $routes->group('tarifaextra', ['namespace' => 'App\Controllers\Tarifas'], functi $routes->get('delete/(:num)', 'Tarifaextra::delete/$1', ['as' => 'deleteTarifaextra']); $routes->post('allmenuitems', 'Tarifaextra::allItemsSelect', ['as' => 'select2ItemsOfTarifasextra']); $routes->post('menuitems', 'Tarifaextra::menuItems', ['as' => 'menuItemsOfTarifasextra']); + $routes->get('gettarifas', 'Tarifaextra::getSelect2'); }); @@ -201,6 +203,7 @@ $routes->group('tarifasmanipulado', ['namespace' => 'App\Controllers\Tarifas'], $routes->post('allmenuitems', 'Tarifasmanipulado::allItemsSelect', ['as' => 'select2ItemsOfTarifasManipulado']); $routes->post('menuitems', 'Tarifasmanipulado::menuItems', ['as' => 'menuItemsOfTarifasManipulado']); $routes->get('select', 'Tarifasmanipulado::show_select', ["as" => "showSelectTarifaManipulado"]); + $routes->get('gettarifas', 'Tarifasmanipulado::getSelect2'); }); $routes->resource('tarifasmanipulado', ['namespace' => 'App\Controllers\Tarifas', 'controller' => 'Tarifasmanipulado', 'except' => 'show,new,create,update']); @@ -496,6 +499,7 @@ $routes->group('tarifasencuadernacion', ['namespace' => 'App\Controllers\Tarifas $routes->post('datatable', 'Tarifasencuadernacion::datatable', ['as' => 'dataTableOfTarifasEncuadernacion']); $routes->post('allmenuitems', 'Tarifasencuadernacion::allItemsSelect', ['as' => 'select2ItemsOfTarifasEncuadernacion']); $routes->post('menuitems', 'Tarifasencuadernacion::menuItems', ['as' => 'menuItemsOfTarifasEncuadernacion']); + $routes->get('gettarifas', 'Tarifasencuadernacion::getSelect2'); }); $routes->resource('tarifasencuadernacion', ['namespace' => 'App\Controllers\Tarifas', 'controller' => 'Tarifasencuadernacion', 'except' => 'show,new,create,update']); @@ -663,24 +667,30 @@ $routes->group('serviciosacabados', ['namespace' => 'App\Controllers\Presupuesto $routes->group('serviciosencuadernaciones', ['namespace' => 'App\Controllers\Presupuestos'], function ($routes) { $routes->post('datatable', 'Presupuestoencuadernaciones::datatable', ['as' => 'dataTableOfPresupuestoEncuadernaciones']); + $routes->post('getvalues', 'Presupuestoencuadernaciones::getRowValues'); $routes->post('menuitems', 'Presupuestoencuadernaciones::menuItems', ['as' => 'menuItemsOfPresupuestoEncuadernaciones']); $routes->get('delete/(:num)', 'Presupuestoencuadernaciones::delete/$1', ['as' => 'deletePresupuestoencuadernaciones']); $routes->post('edit/(:num)', 'Presupuestoencuadernaciones::edit/$1', ['as' => 'updatePresupuestoencuadernaciones']); + }); $routes->group('serviciosmanipulados', ['namespace' => 'App\Controllers\Presupuestos'], function ($routes) { + $routes->post('getvalues', 'Presupuestomanipulados::getRowValues'); $routes->post('datatable', 'Presupuestomanipulados::datatable', ['as' => 'dataTableOfPresupuestoManipulados']); $routes->post('edit/(:num)', 'Presupuestomanipulados::edit/$1', ['as' => 'updatePresupuestomanipulados']); }); $routes->group('serviciospreimpresiones', ['namespace' => 'App\Controllers\Presupuestos'], function ($routes) { + $routes->post('getvalues', 'Presupuestopreimpresiones::getRowValues'); $routes->post('datatable', 'Presupuestopreimpresiones::datatable', ['as' => 'dataTableOfPresupuestoPreimpresiones']); $routes->post('edit/(:num)', 'Presupuestopreimpresiones::edit/$1', ['as' => 'updatePresupuestopreimpresiones']); + $routes->get('cargar', 'Presupuestopreimpresiones::getSelect2'); }); $routes->group('serviciosextra', ['namespace' => 'App\Controllers\Presupuestos'], function ($routes) { $routes->post('datatable', 'Presupuestoserviciosextra::datatable', ['as' => 'dataTableOfPresupuestoServiciosExtra']); $routes->post('edit/(:num)', 'Presupuestoserviciosextra::edit/$1', ['as' => 'updatePresupuestoServiciosExtra']); + $routes->post('getvalues', 'Presupuestoserviciosextra::getRowValues'); }); $routes->group('presupuestodirecciones', ['namespace' => 'App\Controllers\Presupuestos'], function ($routes) { diff --git a/ci4/app/Controllers/Presupuestos/Presupuestoadmin.php b/ci4/app/Controllers/Presupuestos/Presupuestoadmin.php index cc676379..bb989119 100644 --- a/ci4/app/Controllers/Presupuestos/Presupuestoadmin.php +++ b/ci4/app/Controllers/Presupuestos/Presupuestoadmin.php @@ -330,43 +330,6 @@ class Presupuestoadmin extends \App\Controllers\BaseResourceController else $this->viewData['comp_data'] = ""; - $this->viewData['clienteList'] = $this->getClienteListItems($presupuestoEntity->cliente_id ?? null); - $this->viewData['paisList'] = $this->getPaisListItems(); - $this->viewData['ccaaList'] = $this->getCcaaListItems(); - - $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['papelFormatoList'] = $this->getPapelFormatoListItems($presupuestoEntity->papel_formato_id ?? null); - - - // Acabados exteriores - $this->viewData['acabadosCubierta'] = $this->getAcabadosCubierta(); - $this->viewData['acabadosSobrecubierta'] = $this->getAcabadosSobrecubierta(); - - // Lineas Presupuesto - [$cambios_lineas, $this->viewData['lineasPresupuesto']] = $this->loadLineasPresupuesto($presupuestoEntity); - $this->viewData['presupuestoEntity']->cambios_lineas = $cambios_lineas; - - // Servicios - $this->viewData['serviciosPreimpresion'] = $this->getServiciosPreimpresion(); - $this->viewData['serviciosEncuadernacion'] = $this->getServiciosEncuadernacion(); - $this->viewData['serviciosManipulado'] = $this->getServiciosManipulado(); - $this->viewData['serviciosAcabado'] = $this->getServiciosAcabado(); - $this->viewData['serviciosExtra'] = $this->getServiciosExtra(); - - [$cambios_en_servicios, $servicios] = $this->getLineasServicios($presupuestoEntity); - $this->viewData['presupuestoEntity']->cambios_servicios = $cambios_en_servicios; - - $this->viewData['serviciosEncuadernacionList'] = $servicios->serviciosEncuadernacion; - $this->viewData['serviciosAcabadosList'] = $servicios->serviciosAcabado; - $this->viewData['serviciosManipuladoList'] = $servicios->serviciosManipulado; - $this->viewData['serviciosPreimpresionList'] = $servicios->serviciosPreimpresion; - $this->viewData['serviciosExtraList'] = $servicios->serviciosExtra; - - // Direciones presupuesto - [$cambios_en_direcciones, $this->viewData['direccionesList']] = $this->getLineasDirecciones($presupuestoEntity); - $this->viewData['presupuestoEntity']->cambios_direcciones = $cambios_en_direcciones; - $this->viewData['POD'] = $this->getPOD(); $this->viewData['serviciosAutomaticos'] = [ @@ -494,6 +457,7 @@ class Presupuestoadmin extends \App\Controllers\BaseResourceController $data['datosGenerales']['numero_edicion'] = $presupuesto->numero_edicion; $data['datosGenerales']['isbn'] = $presupuesto->isbn; $data['datosGenerales']['pais'] = $presupuesto->pais_id; + $data['datosGenerales']['pais_nombre'] = model('App\Models\Configuracion\PaisModel')->find($presupuesto->pais_id)->nombre; $data['datosGenerales']['cliente']['id'] = $presupuesto->cliente_id; $data['datosGenerales']['cliente']['nombre'] = $modelCliente->getNombre($presupuesto->cliente_id); $data['datosGenerales']['referenciaCliente'] = $presupuesto->referencia_cliente; @@ -544,6 +508,7 @@ class Presupuestoadmin extends \App\Controllers\BaseResourceController $data['lineasPresupuesto'] = $this->loadLineasPresupuesto($presupuesto); + $data['servicios'] = $this->getLineasServicios($presupuesto)[1]; /* @@ -1397,319 +1362,6 @@ class Presupuestoadmin extends \App\Controllers\BaseResourceController return $data; } - protected function getPaisListItems() - { - $paisModel = model('App\Models\Configuracion\PaisModel'); - $onlyActiveOnes = true; - $data = $paisModel->getAllForMenu('id, nombre', 'nombre', $onlyActiveOnes); - - return $data; - } - - protected function getCcaaListItems($selId = null) - { - $ccaaModel = model('App\Models\Configuracion\ComunidadAutonomaModel'); - $onlyActiveOnes = true; - $data = $ccaaModel->getAllForMenu('id, nombre', 'nombre', $onlyActiveOnes); - - return $data; - } - - - protected function getAcabadosCubierta() - { - $model = model('App\Models\Tarifas\Acabados\TarifaAcabadoModel'); - $data = $model->getServiciosAcabadoCubierta(); - array_unshift($data, (object) ['id' => '', 'label' => lang('Basic.global.None')]); - return $data; - } - - protected function getAcabadosSobrecubierta() - { - $model = model('App\Models\Tarifas\Acabados\TarifaAcabadoModel'); - $data = $model->getServiciosAcabadoSobrecubierta(); - array_unshift($data, (object) ['id' => '', 'label' => lang('Basic.global.None')]); - return $data; - } - - public function getPapelGenerico() - { - - if ($this->request->isAJAX()) { - - $POD_value = $this->getPOD(); - $tirada = $this->request->getGet("tirada"); - $isPOD = intval($tirada) <= intval($POD_value); - - $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'; - $cubierta = false; - if ($uso == 'cubierta') { - $cubierta = true; - } - $sobrecubierta = false; - if ($uso == 'sobrecubierta') { - $sobrecubierta = true; - } - $guardas = false; - if ($uso == 'guardas') { - $guardas = true; - } - $rotativa = false; - if ($uso == 'rotativa') { - $rotativa = true; - } - - $model = model('App\Models\Configuracion\PapelGenericoModel'); - $query = $model->getPapelForComparador($tipo, $cubierta, $sobrecubierta, $rotativa, $guardas, $tapa_dura, $isPOD); - if ($this->request->getGet("q")) { - $query->groupStart() - ->orLike("lg_papel_generico.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 getGramaje() - { - if ($this->request->isAJAX()) { - - $papel_generico_id = $this->request->getGet("papel_generico"); - - $POD_value = $this->getPOD(); - $tirada = $this->request->getGet("tirada"); - $isPOD = intval($tirada) <= intval($POD_value); - - $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'; - $cubierta = false; - if ($uso == 'cubierta') { - $cubierta = true; - } - $sobrecubierta = false; - if ($uso == 'sobrecubierta') { - $sobrecubierta = true; - } - $guardas = false; - if ($uso == 'guardas') { - $guardas = true; - } - $rotativa = false; - if ($uso == 'rotativa') { - $rotativa = true; - } - - $model = model('App\Models\Configuracion\PapelGenericoModel'); - $query = $model->getGramajeForComparador($tipo, $papel_generico_id, $cubierta, $sobrecubierta, $rotativa, $guardas, $tapa_dura, $isPOD); - if ($this->request->getGet("q")) { - $query->groupStart() - ->orLike("lg_papel_impresion.gramaje", $this->request->getGet("q")) - ->groupEnd(); - } - - return $this->response->setJSON($query->orderBy("t2.gramaje", "asc")->get()->getResultObject()); - } else { - return $this->failUnauthorized('Invalid request', 403); - } - } - - - 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() - { - $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 getServiciosExtra() - { - $model = model('App\Models\Tarifas\TarifaextraModel'); - $data = $model->getServiciosExtraSelector(); - array_unshift($data, (object) array( - "value" => 0, - "label" => lang('Basic.global.pleaseSelectA', [mb_strtolower(lang('Presupuestos.servicioExtra'))]) - )); - return $data; - } - - protected function getServiciosEncuadernacion() - { - $model = model('App\Models\Tarifas\TarifaEncuadernacionModel'); - $data = $model->getServiciosEncuadernacionSelector(); - return $data; - } - - protected function getPapelFormatoListItems($selId = null) - { - $papelFormatoModel = model('App\Models\Configuracion\PapelFormatoModel'); - $data = $papelFormatoModel->getElementsForMenu(); - array_shift($data); - array_unshift($data, (object) ['id' => '', 'tamanio' => lang('Basic.global.pleaseSelectA', [mb_strtolower(lang('Presupuestos.papelFormatoId'))])]); - return $data; - } - - protected function getServiciosAcabado() - { - $model = model('App\Models\Tarifas\Acabados\TarifaAcabadoModel'); - $data = $model->getServiciosAcabadoSelector(); - 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 getPOD() { return model('App\Models\Configuracion\ConfigVariableModel')->getVariable('POD')->value; diff --git a/ci4/app/Controllers/Presupuestos/Presupuestoencuadernaciones.php b/ci4/app/Controllers/Presupuestos/Presupuestoencuadernaciones.php index 69198d50..09b577cd 100755 --- a/ci4/app/Controllers/Presupuestos/Presupuestoencuadernaciones.php +++ b/ci4/app/Controllers/Presupuestos/Presupuestoencuadernaciones.php @@ -1,4 +1,5 @@ -request->getJSON(); $tarifas = array_column($postData->datos, 'tarifa_id'); - if(count($tarifas)>0){ + if (count($tarifas) > 0) { $this->model->deleteServiciosNotInArray($requestedId, $tarifas); - } - else{ + } else { $this->model->deleteAllServicios($requestedId); } - if(count($tarifas)>0){ + if (count($tarifas) > 0) { $this->model->updateTarifas($requestedId, $postData->datos); } @@ -57,7 +57,7 @@ class Presupuestoencuadernaciones extends \App\Controllers\BaseResourceControlle $data = [ $csrfTokenName => $newTokenHash ]; - + return $this->respond($data); } @@ -65,7 +65,7 @@ class Presupuestoencuadernaciones extends \App\Controllers\BaseResourceControlle { $tarifaModel = model('App\Models\Tarifas\TarifaEncuadernacionModel'); - if ($requestedId == null) : + if ($requestedId == null): return; endif; @@ -78,24 +78,24 @@ class Presupuestoencuadernaciones extends \App\Controllers\BaseResourceControlle $alto = $postData->alto ?? 0; $result = []; - if(count($tarifas)>0){ - foreach ($tarifas as $tarifa){ - if($tarifaModel->isTarifaPorHoras($tarifa)){ + if (count($tarifas) > 0) { + foreach ($tarifas as $tarifa) { + if ($tarifaModel->isTarifaPorHoras($tarifa)) { $values = $this->model->getPrecioTarifaHoras($tarifa, $paginas, $tirada, -1, $POD); - }else{ + } else { $values = $this->model->getPrecioTarifa($tarifa, $paginas, $tirada, $ancho, $alto, -1, $POD); } array_push($result, $values); } } - + $newTokenHash = csrf_hash(); $csrfTokenName = csrf_token(); $data = [ 'lines' => $result, $csrfTokenName => $newTokenHash ]; - + return $this->respond($data); } @@ -105,96 +105,127 @@ class Presupuestoencuadernaciones extends \App\Controllers\BaseResourceControlle if ($this->request->isAJAX()) { $reqData = $this->request->getPost(); $tipo = $reqData['tipo'] ?? null; - if(is_null($tipo) || $tipo=='tarifa'){ + if (is_null($tipo) || $tipo == 'tarifa') { $tarifa_encuadernacion_id = $reqData['tarifa_encuadernacion_id'] ?? 0; $proveedor_id = $reqData['proveedor_id'] ?? 0; - } - else{ + } else { $solapas = $reqData['solapas'] ?? 0; } $paginas = $reqData['paginas'] ?? 0; $tirada = $reqData['tirada'] ?? 0; $ancho = $reqData['ancho'] ?? 0; $alto = $reqData['alto'] ?? 0; - + $POD = $reqData['POD'] ?? 0; $paginas_cuadernillo = $reqData['paginas_por_cuadernillo'] ?? null; - + $newTokenHash = csrf_hash(); $csrfTokenName = csrf_token(); - + $tarifaModel = model('App\Models\Tarifas\TarifaEncuadernacionModel'); - if(is_null($tipo)){ - if($tarifaModel->isTarifaPorHoras($tarifa_encuadernacion_id)){ + if (is_null($tipo)) { + if ($tarifaModel->isTarifaPorHoras($tarifa_encuadernacion_id)) { $values = $this->model->getPrecioTarifaHoras($tarifa_encuadernacion_id, $paginas, $tirada, $proveedor_id, $POD, $paginas_cuadernillo); - }else{ + } else { $values = $this->model->getPrecioTarifa($tarifa_encuadernacion_id, $paginas, $tirada, $ancho, $alto, $proveedor_id, $POD); } - } - - else if($tipo=='tarifa'){ - if($tarifaModel->isTarifaPorHoras($tarifa_encuadernacion_id)){ + } else if ($tipo == 'tarifa') { + if ($tarifaModel->isTarifaPorHoras($tarifa_encuadernacion_id)) { $values = $this->model->getPrecioTarifaHoras($tarifa_encuadernacion_id, $paginas, $tirada, -1, $POD); - } - else{ + } else { $values = $this->model->getPrecioTarifa($tarifa_encuadernacion_id, $paginas, $tirada, $ancho, $alto, -1, $POD); } - } - - else{ + } else { $tipo_impresion_id = $reqData['tipo_impresion_id'] ?? 4; $values = $this->model->initPresupuesto($tipo_impresion_id, $solapas, $tirada, $paginas, $ancho, $alto, $POD); } - + $data = [ 'values' => $values, $csrfTokenName => $newTokenHash ]; - + return $this->respond($data); - + } else { return $this->failUnauthorized('Invalid request', 403); } } - + + public function getRowValues() + { + if ($this->request->isAJAX()) { + + $tarifaModel = model('App\Models\Tarifas\TarifaEncuadernacionModel'); + + $reqData = $this->request->getPost(); + + $tarifa_enc_id = $reqData['tarifa_enc_id'] ?? 0; + $tirada = $reqData['tirada'] ?? 0; + $paginas = $reqData['paginas'] ?? 0; + $ancho = $reqData['ancho'] ?? 0; + $alto = $reqData['alto'] ?? 0; + $proveedor_id = $reqData['proveedor_id'] ?? -1; + $paginas_cuadernillo = $reqData['paginas_por_cuadernillo'] ?? 32; + $POD = model('App\Models\Configuracion\ConfigVariableModel')->getVariable('POD')->value; + + + $newTokenHash = csrf_hash(); + $csrfTokenName = csrf_token(); + + if ($tarifaModel->isTarifaPorHoras($tarifa_enc_id)) { + $values = $this->model->getPrecioTarifaHoras($tarifa_enc_id, $paginas, $tirada, $proveedor_id, $POD, $paginas_cuadernillo); + } else { + $values = $this->model->getPrecioTarifa($tarifa_enc_id, $paginas, $tirada, $ancho, $alto, $proveedor_id, $POD); + } + + $data = [ + 'values' => $values, + $csrfTokenName => $newTokenHash + ]; + + return $this->respond($data); + + } else { + return $this->failUnauthorized('Invalid request', 403); + } + } + public function menuItems() { if ($this->request->isAJAX()) { $reqData = $this->request->getPost(); - try{ + try { $tarifa_id = $reqData['tarifa_id'] ?? -1; $paginas = $reqData['paginas'] ?? 0; $tirada = $reqData['tirada'] ?? 0; $ancho = $reqData['ancho'] ?? 0; $alto = $reqData['alto'] ?? 0; - //$searchStr = goSanitize($this->request->getPost('searchTerm'))[0]; + $paginas_cuadernillo = $reqData['paginas_por_cuadernillo'] ?? 32; $newTokenHash = csrf_hash(); $csrfTokenName = csrf_token(); - $menu = $this->model->getProveedoresForSelector($tarifa_id, $paginas, $tirada, $ancho, $alto); + $menu = $this->model->getProveedoresForSelector($tarifa_id, $paginas, $tirada, $ancho, $alto, $paginas_cuadernillo); $data = [ 'menu' => $menu, $csrfTokenName => $newTokenHash ]; - } - catch(Exception $e){ + } catch (Exception $e) { $data = [ 'error' => $e, $csrfTokenName => $newTokenHash ]; - } - finally{ + } finally { return $this->respond($data); } - + } else { return $this->failUnauthorized('Invalid request', 403); } diff --git a/ci4/app/Controllers/Presupuestos/Presupuestomanipulados.php b/ci4/app/Controllers/Presupuestos/Presupuestomanipulados.php index 0423bb19..e78b5191 100755 --- a/ci4/app/Controllers/Presupuestos/Presupuestomanipulados.php +++ b/ci4/app/Controllers/Presupuestos/Presupuestomanipulados.php @@ -101,7 +101,7 @@ class Presupuestomanipulados extends \App\Controllers\BaseResourceController $tarifa_manipulado_id = $reqData['tarifa_manipulado_id'] ?? 0; $tirada = $reqData['tirada'] ?? 0; - $POD = $reqData['POD'] ?? 0; + $POD = model('App\Models\Configuracion\ConfigVariableModel')->getVariable('POD')->value; $tipo = $reqData['tipo'] ?? null; @@ -129,4 +129,29 @@ class Presupuestomanipulados extends \App\Controllers\BaseResourceController } } + public function getRowValues() + { + if ($this->request->isAJAX()) { + $reqData = $this->request->getPost(); + + $tarifa_manipulado_id = $reqData['tarifa_manipulado_id'] ?? 0; + $tirada = $reqData['tirada'] ?? 0; + $POD = model('App\Models\Configuracion\ConfigVariableModel')->getVariable('POD')->value; + + $newTokenHash = csrf_hash(); + $csrfTokenName = csrf_token(); + + $values = $this->model->getPrecioTarifa($tarifa_manipulado_id, $tirada, $POD); + + $data = [ + 'values' => $values, + $csrfTokenName => $newTokenHash + ]; + + return $this->respond($data); + + } else { + return $this->failUnauthorized('Invalid request', 403); + } + } } diff --git a/ci4/app/Controllers/Presupuestos/Presupuestopreimpresiones.php b/ci4/app/Controllers/Presupuestos/Presupuestopreimpresiones.php index 465ad7be..06e99718 100755 --- a/ci4/app/Controllers/Presupuestos/Presupuestopreimpresiones.php +++ b/ci4/app/Controllers/Presupuestos/Presupuestopreimpresiones.php @@ -110,4 +110,47 @@ class Presupuestopreimpresiones extends \App\Controllers\BaseResourceController } } + public function getRowValues() + { + if ($this->request->isAJAX()) { + $reqData = $this->request->getPost(); + + $tarifa_preimpresion_id = $reqData['tarifa_preimpresion_id'] ?? 0; + + $newTokenHash = csrf_hash(); + $csrfTokenName = csrf_token(); + + $values = $this->model->getPrecioTarifa($tarifa_preimpresion_id); + + $data = [ + 'values' => $values, + $csrfTokenName => $newTokenHash + ]; + + return $this->respond($data); + + } else { + return $this->failUnauthorized('Invalid request', 403); + } + } + + public function cargar() + { + if($this->request->isAJAX()) { + $presupuesto_id = $this->request->getGet('presupuesto_id') ?? null; + + $rows = $this->model->getResource($presupuesto_id)->get()->getResultObject(); + + $newTokenHash = csrf_hash(); + $csrfTokenName = csrf_token(); + $data = [ + 'rows' => $rows, + $csrfTokenName => $newTokenHash + ]; + + return $this->respond($data); + } else { + return $this->failUnauthorized('Invalid request', 403); + } + } } diff --git a/ci4/app/Controllers/Presupuestos/Presupuestoserviciosextra.php b/ci4/app/Controllers/Presupuestos/Presupuestoserviciosextra.php index 09497d14..0e5bc23b 100755 --- a/ci4/app/Controllers/Presupuestos/Presupuestoserviciosextra.php +++ b/ci4/app/Controllers/Presupuestos/Presupuestoserviciosextra.php @@ -110,4 +110,28 @@ class Presupuestoserviciosextra extends \App\Controllers\BaseResourceController } } + public function getRowValues() + { + if ($this->request->isAJAX()) { + $reqData = $this->request->getPost(); + + $tarifa_extra_id = $reqData['tarifa_extra_id'] ?? 0; + + $newTokenHash = csrf_hash(); + $csrfTokenName = csrf_token(); + + $values = $this->model->getPrecioTarifa($tarifa_extra_id); + + $data = [ + 'values' => $values, + $csrfTokenName => $newTokenHash + ]; + + return $this->respond($data); + + } else { + return $this->failUnauthorized('Invalid request', 403); + } + } + } diff --git a/ci4/app/Controllers/Tarifas/Tarifaextra.php b/ci4/app/Controllers/Tarifas/Tarifaextra.php index 1b5591a4..28ea2f1b 100755 --- a/ci4/app/Controllers/Tarifas/Tarifaextra.php +++ b/ci4/app/Controllers/Tarifas/Tarifaextra.php @@ -239,4 +239,25 @@ class Tarifaextra extends \App\Controllers\GoBaseController } } + public function getSelect2() + { + if ($this->request->isAJAX()) { + $query = $this->model->builder()->select( + [ + "id", + "nombre as name" + ] + )->where("deleted_at", null) + ->where("mostrar_en_presupuesto", 1); + if ($this->request->getGet("q")) { + $query->groupStart() + ->orLike("tarifa_extra.nombre", $this->request->getGet("q")) + ->groupEnd(); + } + + return $this->response->setJSON($query->get()->getResultObject()); + } else { + return $this->failUnauthorized('Invalid request', 403); + } + } } diff --git a/ci4/app/Controllers/Tarifas/Tarifapreimpresion.php b/ci4/app/Controllers/Tarifas/Tarifapreimpresion.php index 5b6ada95..6d26178e 100755 --- a/ci4/app/Controllers/Tarifas/Tarifapreimpresion.php +++ b/ci4/app/Controllers/Tarifas/Tarifapreimpresion.php @@ -242,4 +242,25 @@ class Tarifapreimpresion extends \App\Controllers\GoBaseController } } + public function getSelect2() + { + if ($this->request->isAJAX()) { + $query = $this->model->builder()->select( + [ + "id", + "nombre as name" + ] + )->where("deleted_at", null) + ->where("mostrar_en_presupuesto", 1); + if ($this->request->getGet("q")) { + $query->groupStart() + ->orLike("lg_tarifa_preimpresion.nombre", $this->request->getGet("q")) + ->groupEnd(); + } + + return $this->response->setJSON($query->get()->getResultObject()); + } else { + return $this->failUnauthorized('Invalid request', 403); + } + } } diff --git a/ci4/app/Controllers/Tarifas/Tarifasencuadernacion.php b/ci4/app/Controllers/Tarifas/Tarifasencuadernacion.php index 4fea5fe3..11d8b273 100755 --- a/ci4/app/Controllers/Tarifas/Tarifasencuadernacion.php +++ b/ci4/app/Controllers/Tarifas/Tarifasencuadernacion.php @@ -356,4 +356,26 @@ class Tarifasencuadernacion extends \App\Controllers\BaseResourceController } return $dimensiones; } + + public function getSelect2() + { + if ($this->request->isAJAX()) { + $query = $this->model->builder()->select( + [ + "id", + "nombre as name" + ] + )->where("deleted_at", null) + ->where("mostrar_en_presupuesto", 1); + if ($this->request->getGet("q")) { + $query->groupStart() + ->orLike("tarifa_encuadernacion.nombre", $this->request->getGet("q")) + ->groupEnd(); + } + + return $this->response->setJSON($query->get()->getResultObject()); + } else { + return $this->failUnauthorized('Invalid request', 403); + } + } } diff --git a/ci4/app/Controllers/Tarifas/Tarifasmanipulado.php b/ci4/app/Controllers/Tarifas/Tarifasmanipulado.php index ce497cd4..a55c900b 100755 --- a/ci4/app/Controllers/Tarifas/Tarifasmanipulado.php +++ b/ci4/app/Controllers/Tarifas/Tarifasmanipulado.php @@ -310,4 +310,26 @@ class Tarifasmanipulado extends \App\Controllers\BaseResourceController } return $this->response->setJSON($query->get()->getResultObject()); } + + public function getSelect2() + { + if ($this->request->isAJAX()) { + $query = $this->model->builder()->select( + [ + "id", + "nombre as name" + ] + )->where("deleted_at", null) + ->where("mostrar_en_presupuesto", 1); + if ($this->request->getGet("q")) { + $query->groupStart() + ->orLike("lg_tarifa_manipulado.nombre", $this->request->getGet("q")) + ->groupEnd(); + } + + return $this->response->setJSON($query->get()->getResultObject()); + } else { + return $this->failUnauthorized('Invalid request', 403); + } + } } diff --git a/ci4/app/Models/Presupuestos/PresupuestoEncuadernacionesModel.php b/ci4/app/Models/Presupuestos/PresupuestoEncuadernacionesModel.php index 7ce6c1c4..b4360ea1 100755 --- a/ci4/app/Models/Presupuestos/PresupuestoEncuadernacionesModel.php +++ b/ci4/app/Models/Presupuestos/PresupuestoEncuadernacionesModel.php @@ -84,9 +84,11 @@ class PresupuestoEncuadernacionesModel extends \App\Models\BaseModel $datos = [ 'tarifa_id'=> $tarifa['tarifa_id'], 'tarifa_nombre'=> $tarifa_proveedor->tarifa_enc_nombre, + 'nombre'=> $tarifa_proveedor->tarifa_enc_nombre, 'precio_unidad'=> $result_data[0], 'tiempo' => $tiempo, 'total'=> $result_data[1], + 'precio_total'=> $result_data[1], 'margen' => $result_data[2], 'proveedor' => $tarifa_proveedor->proveedor_nombre, 'proveedor_id' => $tarifa_proveedor->proveedor_id, @@ -117,10 +119,12 @@ class PresupuestoEncuadernacionesModel extends \App\Models\BaseModel (object)[ 'tarifa_id'=> $tarifa['tarifa_id'], 'tarifa_nombre'=> $tarifa['tarifa_nombre'], + 'nombre'=> $tarifa['tarifa_nombre'], 'proveedor' => lang('Presupuestos.no_disponible'), 'precio_unidad'=> 0, 'tiempo' => null, 'total'=> 0, + 'precio_total'=> 0, 'margen' => 0, ]); } @@ -135,9 +139,11 @@ class PresupuestoEncuadernacionesModel extends \App\Models\BaseModel array_push($result_array, (object)[ 'tarifa_id'=> $tarifa_proveedor->tarifa_enc_id, 'tarifa_nombre'=> $tarifa_proveedor->tarifa_enc_nombre, + 'nombre'=> $tarifa_proveedor->tarifa_enc_nombre, 'precio_unidad'=> $result_data[0], 'tiempo' => null, 'total'=> $result_data[1], + 'precio_total'=> $result_data[1], 'margen'=> $result_data[2], 'proveedor' => $tarifa_proveedor->proveedor_nombre, 'proveedor_id' => $tarifa_proveedor->proveedor_id, @@ -159,10 +165,12 @@ class PresupuestoEncuadernacionesModel extends \App\Models\BaseModel (object)[ 'tarifa_id'=> $tarifa['tarifa_id'] , 'tarifa_nombre'=> $tarifa['tarifa_nombre'], + 'nombre'=> $tarifa['tarifa_nombre'], 'proveedor' => lang('Presupuestos.no_disponible'), 'precio_unidad'=> 0, 'tiempo' => null, 'total'=> 0, + 'precio_total'=> 0, 'margen' => 0, ]); } @@ -173,17 +181,17 @@ class PresupuestoEncuadernacionesModel extends \App\Models\BaseModel } - public function getProveedoresForSelector($tarifa_encuadernacion_id, $paginas, $tirada, $ancho, $alto){ + public function getProveedoresForSelector($tarifa_encuadernacion_id, $paginas, $tirada, $ancho, $alto, $paginasCuadernillo = 32){ $proveedores = []; $modelTarifa = model('App\Models\Tarifas\TarifaEncuadernacionModel'); - $tiempo = $this->calcularTiempo(16, $paginas, $tirada); // ID fija. Cambiar cuando se metan maquinas de corte. Velocidad en minutos - if($modelTarifa->isTarifaPorHoras($tarifa_encuadernacion_id)){ + $tiempo = $this->calcularTiempoCosido(16, $paginas, $tirada, $paginasCuadernillo); // ID fija. Cambiar cuando se metan maquinas de corte. Velocidad en minutos $tarifa_value = $modelTarifa->getTarifaPresupuestoEncuadernacionHoras($tarifa_encuadernacion_id, $tiempo, $tirada); } else{ + $tiempo = $this->calcularTiempo(16, $paginas, $tirada); // ID fija. Cambiar cuando se metan maquinas de corte. Velocidad en minutos $tarifa_value = $modelTarifa->getTarifaPresupuestoEncuadernacion($tarifa_encuadernacion_id, $paginas, $tirada, $ancho, $alto); } if (count($tarifa_value)>0) { @@ -215,9 +223,11 @@ class PresupuestoEncuadernacionesModel extends \App\Models\BaseModel array_push($ret_array, (object)[ 'tarifa_id'=> $tarifa->tarifa_enc_id, 'tarifa_nombre'=> $tarifa->tarifa_enc_nombre, + 'nombre'=> $tarifa->tarifa_enc_nombre, 'precio_unidad'=> $result_data[0], 'tiempo' => null, 'total'=> $result_data[1], + 'precio_total'=> $result_data[1], 'margen'=> $result_data[2], 'proveedor' => $tarifa->proveedor_nombre, 'proveedor_id' => $tarifa->proveedor_id, @@ -237,10 +247,12 @@ class PresupuestoEncuadernacionesModel extends \App\Models\BaseModel $ret_array[] = (object)[ 'tarifa_id'=> $tarifa_encuadernacion_id, 'tarifa_nombre'=> $modelTarifa->getNombreTarifaEncuadernacion($tarifa_encuadernacion_id)[0]->nombre, + 'nombre'=> $modelTarifa->getNombreTarifaEncuadernacion($tarifa_encuadernacion_id)[0]->nombre, 'proveedor' => lang('Presupuestos.no_disponible'), 'precio_unidad'=> 0, 'tiempo' => null, 'total'=> 0, + 'precio_total'=> 0, 'margen'=> 0, ]; return $ret_array; @@ -286,9 +298,11 @@ class PresupuestoEncuadernacionesModel extends \App\Models\BaseModel (object)[ 'tarifa_id'=> $tarifa_proveedor->tarifa_enc_id, 'tarifa_nombre'=> $tarifa_proveedor->tarifa_enc_nombre, + 'nombre'=> $tarifa_proveedor->tarifa_enc_nombre, 'precio_unidad'=> $result_data[0], 'tiempo' => $tiempo, 'paginas_por_cuadernillo' => $paginas_cuadernillo, + 'precio_total'=> $result_data[1], 'total'=> $result_data[1], 'margen' => $result_data[2], 'proveedor' => $tarifa_proveedor->proveedor_nombre, @@ -310,11 +324,13 @@ class PresupuestoEncuadernacionesModel extends \App\Models\BaseModel $ret_array[] = (object)[ 'tarifa_id'=> $tarifa_encuadernacion_id, 'tarifa_nombre'=> $modelTarifa->getNombreTarifaEncuadernacion($tarifa_encuadernacion_id)[0]->nombre, + 'nombre'=> $modelTarifa->getNombreTarifaEncuadernacion($tarifa_encuadernacion_id)[0]->nombre, 'proveedor' => lang('Presupuestos.no_disponible'), 'precio_unidad'=> 0, 'tiempo' => null, 'paginas_por_cuadernillo' => null, 'total'=> 0, + 'precio_total'=> 0, 'margen' => 0, ]; return $ret_array; diff --git a/ci4/app/Models/Presupuestos/PresupuestoManipuladosModel.php b/ci4/app/Models/Presupuestos/PresupuestoManipuladosModel.php index 8612e8a4..72211db4 100755 --- a/ci4/app/Models/Presupuestos/PresupuestoManipuladosModel.php +++ b/ci4/app/Models/Presupuestos/PresupuestoManipuladosModel.php @@ -50,28 +50,37 @@ class PresupuestoManipuladosModel extends \App\Models\BaseModel $modelTarifa = model('App\Models\Tarifas\TarifaManipuladoModel'); $tarifa_value = $modelTarifa->getTarifaPresupuestoManipulado($tarifa_manipulado_id, $tirada); if (count($tarifa_value)>0) { + $ret_array = []; + foreach($tarifa_value as $tarifa){ + $result_data = $this->calcularTarifa($tarifa, $tirada, $POD<$tirada?false:true); + array_push($ret_array, (object)[ + 'tarifa_id'=> $tarifa->tarifa_manipulado_id, + 'tarifa_nombre'=> $tarifa->tarifa_manipulado_nombre, + 'nombre'=> $tarifa->tarifa_manipulado_nombre, + 'precio_unidad'=> $result_data[0], + 'total'=> $result_data[1], + 'precio_total'=> $result_data[1], + 'margen' => $result_data[2], + ]); + } + + usort($ret_array, function($a, $b) { + return $a->precio_total <=> $b->precio_total; + }); - $result_data = $this->calcularTarifa($tarifa_value[0], $tirada, $POD<$tirada?false:true); - $ret_array[] = (object)[ - 'tarifa_id'=> $tarifa_value[0]->tarifa_manipulado_id, - 'tarifa_nombre'=> $tarifa_value[0]->tarifa_manipulado_nombre, - 'precio_unidad'=> $result_data[0], - 'total'=> $result_data[1], - 'margen' => $result_data[2], - ]; return $ret_array; } else{ $ret_array[] = (object)[ 'tarifa_id'=> $tarifa_manipulado_id, 'tarifa_nombre'=> $modelTarifa->getNombreTarifaManipulado($tarifa_manipulado_id)[0]->nombre, + 'nombre'=> $modelTarifa->getNombreTarifaManipulado($tarifa_manipulado_id)[0]->nombre, 'precio_unidad' => 0, 'total'=> 0, 'margen' => 0, ]; return $ret_array; } - return []; } private function calcularTarifa($tarifa, $tirada, $is_POD=false){ @@ -170,8 +179,10 @@ class PresupuestoManipuladosModel extends \App\Models\BaseModel array_push($tarifas, (object)[ 'tarifa_id'=> $tarifa_value[0]->tarifa_manipulado_id, 'tarifa_nombre'=> $tarifa_value[0]->tarifa_manipulado_nombre, + 'nombre'=> $tarifa_value[0]->tarifa_manipulado_nombre, 'precio_unidad'=> $result_data[0], 'total'=> $result_data[1], + 'precio_total'=> $result_data[1], 'margen'=> $result_data[2], ]); } @@ -180,8 +191,10 @@ class PresupuestoManipuladosModel extends \App\Models\BaseModel (object)[ 'tarifa_id'=> $tarifa['tarifa_id'] , 'tarifa_nombre'=> $tarifa['tarifa_nombre'], + 'nombre'=> $tarifa['tarifa_nombre'], 'precio_unidad' => 0, 'total'=> 0, + 'precio_total'=> 0, 'margen' => 0, ]); } diff --git a/ci4/app/Models/Presupuestos/PresupuestoPreimpresionesModel.php b/ci4/app/Models/Presupuestos/PresupuestoPreimpresionesModel.php index a2828855..f59520ea 100755 --- a/ci4/app/Models/Presupuestos/PresupuestoPreimpresionesModel.php +++ b/ci4/app/Models/Presupuestos/PresupuestoPreimpresionesModel.php @@ -51,19 +51,30 @@ class PresupuestoPreimpresionesModel extends \App\Models\BaseModel $tarifa_value = $modelTarifa->getTarifaPresupuestoPreimpresion($tarifa_preimpresion_id); if (count($tarifa_value)>0) { - $result_data = $this->calcularTarifa($tarifa_value[0]); - $ret_array[] = (object)[ - 'tarifa_id'=> $tarifa_value[0]->tarifa_preimpresion_id, - 'tarifa_nombre'=> $tarifa_value[0]->tarifa_preimpresion_nombre, - 'precio'=> $result_data[0], - 'margen'=> $result_data[1], - ]; + + $ret_array = []; + foreach ($tarifa_value as $tarifa) { + $result_data = $this->calcularTarifa($tarifa); + array_push($ret_array, (object)[ + 'tarifa_id'=> $tarifa->tarifa_preimpresion_id, + 'tarifa_nombre'=> $tarifa->tarifa_preimpresion_nombre, + 'nombre'=> $tarifa->tarifa_preimpresion_nombre, + 'precio'=> $result_data[0], + 'margen'=> $result_data[1], + ]); + } + + usort($ret_array, function($a, $b) { + return $a->precio <=> $b->precio; + }); + return $ret_array; } else{ $ret_array[] = (object)[ 'tarifa_id'=> $tarifa_preimpresion_id, 'tarifa_nombre'=> $modelTarifa->getNombreTarifaPreimpresion($tarifa_preimpresion_id)[0]->nombre, + 'nombre'=> $modelTarifa->getNombreTarifaPreimpresion($tarifa_preimpresion_id)[0]->nombre, 'precio' => 0, 'margen' => 0, ]; @@ -146,7 +157,7 @@ class PresupuestoPreimpresionesModel extends \App\Models\BaseModel $builder = $this->db ->table($this->table . " t1") ->select( - "t1.id AS id, t1.tarifa_preimpresion_id AS tarifa_preimpresion_id, t1.precio AS precio, t1.margen AS margen, t2.nombre AS nombre" + "t1.id AS id, t1.tarifa_preimpresion_id AS tarifa_preimpresion_id, t1.tarifa_preimpresion_id AS tarifa_id, t1.precio AS precio, t1.margen AS margen, t2.nombre AS nombre" ); $builder->where('t1.presupuesto_id', $presupuesto_id); diff --git a/ci4/app/Models/Presupuestos/PresupuestoServiciosExtraModel.php b/ci4/app/Models/Presupuestos/PresupuestoServiciosExtraModel.php index 75e9b1ef..f7141ebb 100755 --- a/ci4/app/Models/Presupuestos/PresupuestoServiciosExtraModel.php +++ b/ci4/app/Models/Presupuestos/PresupuestoServiciosExtraModel.php @@ -50,19 +50,27 @@ class PresupuestoServiciosExtraModel extends \App\Models\BaseModel $tarifa_value = $modelTarifa->getTarifaPresupuestoExtra($tarifa_extra_id); if (count($tarifa_value)>0) { - $result_data = $this->calcularTarifa($tarifa_value[0]); - $ret_array[] = (object)[ - 'tarifa_id'=> $tarifa_value[0]->tarifa_extra_id, - 'tarifa_nombre'=> $tarifa_value[0]->tarifa_extra_nombre, - 'precio'=> $result_data[0], - 'margen'=> $result_data[1], - ]; + $ret_array = []; + foreach($tarifa_value as $tarifa){ + $result_data = $this->calcularTarifa($tarifa); + array_push($ret_array, (object)[ + 'tarifa_id'=> $tarifa->tarifa_extra_id, + 'tarifa_nombre'=> $tarifa->tarifa_extra_nombre, + 'nombre'=> $tarifa->tarifa_extra_nombre, + 'precio'=> $result_data[0], + 'margen'=> $result_data[1], + ]); + } + usort($ret_array, function($a, $b) { + return $a->precio <=> $b->precio; + }); return $ret_array; } else{ $ret_array[] = (object)[ 'tarifa_id'=> $tarifa_extra_id, 'tarifa_nombre'=> $modelTarifa->getNombreTarifaExtra($tarifa_extra_id)[0]->nombre, + 'tarifa'=> $modelTarifa->getNombreTarifaExtra($tarifa_extra_id)[0]->nombre, 'precio' => 0, 'margen' => 0, ]; diff --git a/ci4/app/Views/themes/vuexy/form/presupuestos/admin/_datosEnvios.php b/ci4/app/Views/themes/vuexy/form/presupuestos/admin/_datosEnvios.php index 641d40f8..b1aa33f1 100644 --- a/ci4/app/Views/themes/vuexy/form/presupuestos/admin/_datosEnvios.php +++ b/ci4/app/Views/themes/vuexy/form/presupuestos/admin/_datosEnvios.php @@ -55,24 +55,3 @@ - - - -section("additionalInlineJs") ?> -/* -window.paisList = ; -window.direccionesList = ; - -window.routes_envios = { - dataTableOfPresupuestoDirecciones: '' -} - -window.url_get_precio_envio = ''; -window.error_no_tarifa_envio = '' -window.token_ajax= {: v}; - -$( document ).ready(function() { - load_datos_envios(); -}); -*/ -endSection() ?> \ No newline at end of file diff --git a/ci4/app/Views/themes/vuexy/form/presupuestos/admin/_datosPresupuestoItems.php b/ci4/app/Views/themes/vuexy/form/presupuestos/admin/_datosPresupuestoItems.php index 31e708a0..f044e4f9 100644 --- a/ci4/app/Views/themes/vuexy/form/presupuestos/admin/_datosPresupuestoItems.php +++ b/ci4/app/Views/themes/vuexy/form/presupuestos/admin/_datosPresupuestoItems.php @@ -125,12 +125,6 @@ diff --git a/ci4/app/Views/themes/vuexy/form/presupuestos/admin/_datosServiciosItems.php b/ci4/app/Views/themes/vuexy/form/presupuestos/admin/_datosServiciosItems.php index fbe6ffd5..aa8b93f3 100644 --- a/ci4/app/Views/themes/vuexy/form/presupuestos/admin/_datosServiciosItems.php +++ b/ci4/app/Views/themes/vuexy/form/presupuestos/admin/_datosServiciosItems.php @@ -127,7 +127,7 @@ - + @@ -137,12 +137,6 @@
@@ -164,11 +158,11 @@ - + - + @@ -179,12 +173,6 @@
@@ -207,7 +195,7 @@ - + @@ -217,12 +205,6 @@
@@ -245,7 +227,7 @@ - + @@ -255,12 +237,6 @@
@@ -276,91 +252,3 @@
- - - -section("additionalInlineJs") ?> - - // Generación de la lista de servicios de acabado (id, nombre) - ; - window.serviciosacabadosList = ; - window.serviciosAutomaticos = ; - - window.serviciosencuadernadosList = ; - - window.serviciosmanipuladoList = ; - - window.serviciospreimpresionList = ; - - window.serviciosextraList = ; - - window.routes_servicios = { - dataTableOfPresupuestoAcabados: "", - menuItemsOfPresupuestoAcabados: '', - dataTableOfPresupuestoPreimpresion: "", - dataTableOfPresupuestoEncuadernaciones: "", - dataTableOfPresupuestoManipulados: "", - menuItemsOfPresupuestoEncuadernaciones: '', - dataTableOfPresupuestoServiciosExtra: "", - } - - init_servicio_acabado() - - init_servicio_encuadernado() - - init_servicio_manipulado() - - init_servicio_preimpresion() - - init_servicio_extra() - - /// ELIMINADO PARA COMPROBAR EL MAXIMO DE SOLAPAS DESDE EL BACKEND - PENDIENTE - $('.solapas_cubierta').on('change', function(){ - - const ancho_libro = getDimensionLibro().ancho; - - // ancho_libro*2 + lomo + solapas*2 <= 630 - const limite_1 = ((630 - ancho_libro*2 - getLomoLineasPresupuesto()) / 2.0).toFixed(1); - // solapas <= ancho_libro - 10 - const limite_2 = ancho_libro - 10; - const limite = Math.min(limite_1, limite_2); - - if(parseInt($('#solapas_ancho').val()) > limite){ - $('#solapas_ancho').val(limite) - asyncMessageDialog( - window.Presupuestos.advertencia, - window.Presupuestos.actualizacionSolapasCubierta, - function(){}); - } - - $('#compGramajeCubierta').trigger('change') - - }) - - - $('.solapas_sobrecubierta').on('change', function(){ - - const ancho_libro = getDimensionLibro().ancho; - - // ancho_libro*2 + lomo + solapas*2 <= 630 - const limite_1 = ((630 - ancho_libro*2 - getLomoLineasPresupuesto()) / 2.0).toFixed(1); - // solapas <= ancho_libro - 10 - const limite_2 = ancho_libro - 10; - const limite = Math.min(limite_1, limite_2); - - if(parseInt($('#solapas_ancho_sobrecubierta').val()) > limite){ - $('#solapas_ancho_sobrecubierta').val(limite) - asyncMessageDialog( - window.Presupuestos.advertencia, - window.Presupuestos.actualizacionSolapasSobrecubierta, - function(){}); - } - - $('#compGramajeSobrecubierta').trigger('change') - }) - - */?> - -endSection() ?> diff --git a/ci4/app/Views/themes/vuexy/form/presupuestos/admin/_lineasPresupuestoItems.php b/ci4/app/Views/themes/vuexy/form/presupuestos/admin/_lineasPresupuestoItems.php index 1b655662..cda116b4 100644 --- a/ci4/app/Views/themes/vuexy/form/presupuestos/admin/_lineasPresupuestoItems.php +++ b/ci4/app/Views/themes/vuexy/form/presupuestos/admin/_lineasPresupuestoItems.php @@ -70,36 +70,3 @@
- - - -section("additionalInlineJs") ?> -/*window.papelGenericoNegroList = []; -window.papelGenericoNegroHQList = []; -window.papelGenericoColorList = []; -window.papelGenericoColorHQList = []; -window.papelGenericoCubiertaList = []; -window.papelGenericoSobrecubiertaList = []; -window.papelGenericoRotativaNegroList = []; -window.papelGenericoRotativaColorList = []; - - - window.papelGenericoGuardasList = []; - - -window.lineasPresupuestoList = ; - -window.routes_lp = { - menuItemsOfPresupuestoAdmin: '', - updateDataOfPresupuestoAdmin: '', - -} - -*/ -/* -fill_lp_from_bbdd() - -checkPaginasPresupuesto() -*/ - -endSection() ?> \ No newline at end of file diff --git a/ci4/app/Views/themes/vuexy/form/presupuestos/admin/_presupuestoDireccionesForm.php b/ci4/app/Views/themes/vuexy/form/presupuestos/admin/_presupuestoDireccionesForm.php index 6a25b1b9..91afd269 100644 --- a/ci4/app/Views/themes/vuexy/form/presupuestos/admin/_presupuestoDireccionesForm.php +++ b/ci4/app/Views/themes/vuexy/form/presupuestos/admin/_presupuestoDireccionesForm.php @@ -47,12 +47,6 @@ *
diff --git a/httpdocs/assets/js/safekat/pages/presupuestoAdmin/presupuestoAdminEdit.js b/httpdocs/assets/js/safekat/pages/presupuestoAdmin/presupuestoAdminEdit.js index 36087d6f..3f0bf29b 100644 --- a/httpdocs/assets/js/safekat/pages/presupuestoAdmin/presupuestoAdminEdit.js +++ b/httpdocs/assets/js/safekat/pages/presupuestoAdmin/presupuestoAdminEdit.js @@ -123,7 +123,7 @@ class PresupuestoAdminEdit { self.comparador.cargarDatos(response.data.comparador); self.lineasPresupuesto.cargarDatos(response.data.lineasPresupuesto); - self.servicios.cargar(); + self.servicios.cargar(response.data.servicios); /*self.direcciones.handleChangeCliente(); self.direcciones.cargarDatos(response.data.direcciones, response.data.datosGenerales); diff --git a/httpdocs/assets/js/safekat/pages/presupuestoAdmin/sections/comparador.js b/httpdocs/assets/js/safekat/pages/presupuestoAdmin/sections/comparador.js index 516727f3..73406411 100644 --- a/httpdocs/assets/js/safekat/pages/presupuestoAdmin/sections/comparador.js +++ b/httpdocs/assets/js/safekat/pages/presupuestoAdmin/sections/comparador.js @@ -195,6 +195,8 @@ class Comparador { initSelect2() { + const self = this; + this.paginasCubierta.select2({ allowClear: false, minimumResultsForSearch: Infinity, @@ -240,7 +242,7 @@ class Comparador { }); this.papelSobrecubierta.init(); this.gramajeSobrecubierta.init(); - this.papelSobrecubierta.onChange(() => this.gramajeSobrecubierta.setVal(0)) + this.papelSobrecubierta.onChange(() => self.gramajeSobrecubierta.empty()); this.sobrecubierta.on('change', () => { if (this.sobrecubierta.val() == 1) { $('#solapas_sobrecubierta').prop('checked', true); @@ -262,15 +264,14 @@ class Comparador { if (this.tipo_impresion_id == 1 || this.tipo_impresion_id == 3 || this.tipo_impresion_id == 5 || this.tipo_impresion_id == 7) { this.papelGuardas.init(); this.gramajeGuardas.init(); - this.papelGuardas.onChange(() => this.gramajeGuardas.setVal(0)) + this.papelGuardas.onChange(() => self.gramajeGuardas.empty()); } - this.papelNegro.onChange(() => this.gramajeNegro.setVal(0)) - this.papelNegrohq.onChange(() => this.gramajeNegrohq.setVal(0)) - this.papelColor.onChange(() => this.gramajeColor.setVal(0)) - this.papelColorhq.onChange(() => this.gramajeColorhq.setVal(0)) - this.papelCubierta.onChange(() => this.gramajeCubierta.setVal(0)) - this.papelCubierta.onChange(() => this.gramajeSobrecubierta.setVal(0)) + this.papelNegro.onChange(() => self.gramajeNegro.empty()); + this.papelNegrohq.onChange(() => self.gramajeNegrohq.empty()); + this.papelColor.onChange(() => self.gramajeColor.empty()); + this.papelColorhq.onChange(() => self.gramajeColorhq.empty()); + this.papelCubierta.onChange(() => self.gramajeCubierta.empty()); this.tipo_impresion.select2({ diff --git a/httpdocs/assets/js/safekat/pages/presupuestoAdmin/sections/datosGenerales.js b/httpdocs/assets/js/safekat/pages/presupuestoAdmin/sections/datosGenerales.js index 9b39ff91..f981d106 100644 --- a/httpdocs/assets/js/safekat/pages/presupuestoAdmin/sections/datosGenerales.js +++ b/httpdocs/assets/js/safekat/pages/presupuestoAdmin/sections/datosGenerales.js @@ -15,9 +15,10 @@ class DatosGenerales{ this.coleccion = this.domItem.find('#coleccion'); this.numeroEdicion = this.domItem.find('#numeroEdicion'); this.isbn = this.domItem.find('#isbn'); - this.pais = this.domItem.find('#paisId'); + this.cliente = new ClassSelect($('#clienteId'), '/clientes/cliente/getSelect2', 'Seleccione cliente'); + this.pais = new ClassSelect($('#paisId'), '/paises/menuitems2', 'Seleccione País'); this.referenciaCliente = this.domItem.find('#referenciaCliente'); } @@ -25,14 +26,11 @@ class DatosGenerales{ init(){ this.cliente.init(); + this.pais.init(); this.inc_rei.select2({ allowClear: false, }); - - this.pais.select2({ - allowClear: false, - }); } cargarDatos(datos){ @@ -46,9 +44,10 @@ class DatosGenerales{ this.coleccion.val(datos.coleccion); this.numeroEdicion.val(datos.numero_edicion); this.isbn.val(datos.isbn); - this.pais.val(datos.pais).trigger('change'); + this.cliente.setOption(datos.cliente.id, datos.cliente.nombre); + this.pais.setOption(datos.pais, datos.pais_nombre); this.referenciaCliente.val(datos.referenciaCliente); } } diff --git a/httpdocs/assets/js/safekat/pages/presupuestoAdmin/sections/datosLibro.js b/httpdocs/assets/js/safekat/pages/presupuestoAdmin/sections/datosLibro.js index 38235303..b7957ec0 100644 --- a/httpdocs/assets/js/safekat/pages/presupuestoAdmin/sections/datosLibro.js +++ b/httpdocs/assets/js/safekat/pages/presupuestoAdmin/sections/datosLibro.js @@ -219,10 +219,10 @@ class DatosLibro { changeSolapasCubierta() { if (this.solapasCubierta.prop('checked')) { - $('#div_solapas_ancho_sobrecubierta').removeClass('d-none'); + $('#div_solapas_ancho').removeClass('d-none'); } else { - $('#div_solapas_ancho_sobrecubierta').divSolapasCubierta.addClass('d-none'); + $('#div_solapas_ancho').divSolapasCubierta.addClass('d-none'); this.anchoSolapasCubierta.val(0); } $('#serv_default').trigger('click'); @@ -327,7 +327,7 @@ class DatosLibro { } else{ let merma_lineas = [] - tableLineasPresupuesto.rows().every( function ( rowIdx, tableLoop, rowLoop ) { + $('#tableLineasPresupuesto').DataTable().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'){ const formas_linea = parseInt($('#isCosido').val())==0?parseInt(rowData.formas):parseInt(rowData.formas)/2 @@ -350,7 +350,7 @@ class DatosLibro {
` + - window.Presupuestos.validation.no_lp_for_merma + + window.language.Presupuestos.validation.no_lp_for_merma + `
`; diff --git a/httpdocs/assets/js/safekat/pages/presupuestoAdmin/sections/servicios.js b/httpdocs/assets/js/safekat/pages/presupuestoAdmin/sections/servicios.js index 6c318376..a6d64f93 100644 --- a/httpdocs/assets/js/safekat/pages/presupuestoAdmin/sections/servicios.js +++ b/httpdocs/assets/js/safekat/pages/presupuestoAdmin/sections/servicios.js @@ -10,28 +10,82 @@ class Servicios { this.csrf_hash = $('#mainContainer').find('input[name="' + this.csrf_token + '"]').val(); this.serviciosAcabado = new ServiciosAcabado(this.csrf_token, this.csrf_hash); + this.serviciosPreimpresion = new ServiciosPreimpresion(this.csrf_token, this.csrf_hash); + this.ServiciosEncuadernacion = new ServiciosEncuadernacion(this.csrf_token, this.csrf_hash); + this.ServiciosManipulado = new ServiciosManipulado(this.csrf_token, this.csrf_hash); + this.serviciosExtra = new ServiciosExtra(this.csrf_token, this.csrf_hash); + + this.serviciosDefecto = $('#serv_default'); } init() { + const self = this; + this.serviciosAcabado.init(); + this.serviciosPreimpresion.init(); + this.ServiciosEncuadernacion.init(); + this.ServiciosManipulado.init(); + this.serviciosExtra.init(); + + this.serviciosDefecto.on('click', function () { + + $('#loader').modal('show'); + try { + self.ServiciosEncuadernacion.getServiciosDefecto().then(function (response) { + self.ServiciosManipulado.getServiciosDefecto().then(function (response) { + $('#loader').modal('hide'); + }); + }); + } + catch (error) { + console.log(error); + $('#loader').modal('hide'); + } + }); $('.nav-servicios button').on('shown.bs.tab', function () { - this.serviciosAcabado.table.columns.adjust(); - /*$("#tableOfServiciosEncuadernacion").DataTable().columns.adjust(); - $("#tableOfServiciosPreimpresion").DataTable().columns.adjust(); - $("#tableOfServiciosManipulado").DataTable().columns.adjust(); $("#tableOfServiciosAcabado").DataTable().columns.adjust(); - $("#tableOfServiciosExtra").DataTable().columns.adjust();*/ + $("#tableOfServiciosPreimpresion").DataTable().columns.adjust(); + $("#tableOfServiciosEncuadernacion").DataTable().columns.adjust(); + $("#tableOfServiciosManipulado").DataTable().columns.adjust(); + $("#tableOfServiciosExtra").DataTable().columns.adjust(); }) $(document).on('add-servicio-lineas', this.addServicio.bind(this)); $(document).on('remove-servicio-lineas', this.addServicio.bind(this)); + + + $(document).on('change', '.update-totales-servicios', function () { + + const row = $(this).closest('tr'); + const table = $(this).closest('table').DataTable(); + + if (!row.length || !table) return; + + const data = table.row(row).data(); + data.precio_total = parseFloat($(this).val().replace(',', '.')); + table.row(row).data(data).draw(); + + showBreadCrumbSaveButton(true); + }); + } - cargar() { - this.serviciosAcabado.cargarServiciosAcabado(); + cargar(datos) { + + if (datos.serviciosAcabado.length > 0) + this.serviciosAcabado.cargarServiciosAcabado(datos.serviciosAcabado); + if (datos.serviciosPreimpresion.length > 0) + this.serviciosPreimpresion.cargarServiciosPreimpresion(datos.serviciosPreimpresion); + if (datos.serviciosEncuadernacion.length > 0) + this.ServiciosEncuadernacion.cargarServiciosEncuadernacion(datos.serviciosEncuadernacion); + if (datos.serviciosManipulado.length > 0) + this.ServiciosManipulado.cargarServiciosManipulado(datos.serviciosManipulado); + if (datos.serviciosExtra.length > 0) + this.serviciosExtra.cargarServiciosExtra(datos.serviciosExtra); + } addServicio(event, servicio) { @@ -99,7 +153,7 @@ class ServiciosAcabado { { data: 'proveedor', render: function (data, type, row) { return ` - `; @@ -115,7 +169,9 @@ class ServiciosAcabado { }, { data: 'precio_total', render: function (data, type, row) { - return parseFloat(data).toLocaleString('es-ES', { minimumFractionDigits: 2, maximumFractionDigits: 2 }); + const total = parseFloat(data).toLocaleString('es-ES', { minimumFractionDigits: 2, maximumFractionDigits: 2 }); + return ` + `; } }, { data: 'margen' }, @@ -169,9 +225,11 @@ class ServiciosAcabado { } }); - $('.proveedor_acabado').on('change.select2', function () { + $('.proveedor_acabado').on('select2:close', function () { self.getPresupuestoAcabado(null, null, $(this)); }) + + self.check_serv_acabado_error(); } }); @@ -290,39 +348,21 @@ class ServiciosAcabado { this.check_serv_acabado_error(); - /* TO-DO - showBreadCrumbSaveButton(true); - */ + } - cargarServiciosAcabado() { + cargarServiciosAcabado(datos) { - const self = this; - const id = window.location.href.split('/').pop(); + this.table.rows.add(datos).draw(); - new Ajax( - '/serviciosacabados/cargar', - { - [this.csrf_token]: this.csrf_token, - presupuesto_id: id - }, - {}, - function (response) { - if (response.rows.length > 0) { - - self.table.clear().draw(); - self.table.rows.add(response.rows).draw(); - } - }, - function (response) { - console.error(response); - } - ).get(); } guardarServiciosAcabado() { + /* TO-DO + + */ } @@ -330,27 +370,972 @@ class ServiciosAcabado { check_serv_acabado_error() { var htmlString = ''; + var error = false; - // recorre las filas de la tabla de servicios acabado - this.table.rows().every(function () { - var data = this.data(); - if (data.precio_total == 0) { - htmlString = ` + const rows = this.table.rows().data().toArray(); + for (let i = 0; i < rows.length; i++) { + if (rows[i]['precio_total'] == 0) { + error = true; + break; + } + } + + if (error) { + htmlString = ` `; - } - }); + } $('#serv-acabado-error').html(htmlString) } } +class ServiciosPreimpresion { + + constructor(token, hash) { + + this.csrf_token = token; + this.csrf_hash = hash; + + this.table = null; + + this.selectorServicios = new ClassSelect($('#add_servicio_preimpresion_list'), + '/tarifapreimpresion/gettarifas', window.language.Presupuestos.servicioPreimpresionList, false, {}); + this.addServicio = $('#insertar_serv_preimpresion'); + } + + init() { + + const self = this; + + this.selectorServicios.init(); + + this.table = new DataTable('#tableOfServiciosPreimpresion', { + scrollX: true, + searching: false, + paging: false, + info: false, + ordering: false, + responsive: true, + select: false, + language: { + url: "/themes/vuexy/vendor/libs/datatables-sk/plugins/i18n/es-ES.json" + }, + columns: [ + { data: 'tarifa_id' }, + { data: 'nombre' }, + + { + data: 'coste', render: function (data, type, row) { + let coste = (row.precio / (1 + row.margen / 100)).toFixed(2); + coste = parseFloat(coste).toLocaleString('es-ES', { minimumFractionDigits: 2, maximumFractionDigits: 2 }); + return coste; + } + }, + { + data: 'precio', render: function (data, type, row) { + + const total = parseFloat(data).toLocaleString('es-ES', { minimumFractionDigits: 2, maximumFractionDigits: 2 }); + return ` + `; + + } + }, + { data: 'margen' }, + { + data: function (row) { + return ` + + `; + } + } + ], + drawCallback: function (settings) { + + self.check_serv_preimpresion_error(); + } + + + }); + + + $(document).on('click', '.btn-delete-servpreimpresion', function () { + const rowId = $(this).closest('td').parent()[0].sectionRowIndex; + self.table.row(rowId).remove().draw(); + }); + + + + this.addServicio.on('click', this.addServicioPreimpresion.bind(this)); + + /*this.table.on('draw.dt', function () { + + /* TO-DO + updatePresupuesto({ + update_resumen: true, + update_tiradas_alternativas: true}) + + }); */ + } + + getPresupuestoPreimpresion(tarifa_id = -1) { + + const self = this; + + let datos = { + tarifa_preimpresion_id: tarifa_id + }; + + if (datos.tarifa_preimpresion_id > 0) { + new Ajax('/serviciospreimpresiones/getvalues', datos, {}, + function (response) { + if (response.values) { + + self.table.rows.add([response.values[0]]).draw(); + } + }, + function (error) { + console.error(error); + } + ).post(); + } + } + + addServicioPreimpresion() { + + const tarifa_text = this.selectorServicios.getText(); + const tarifa_id = this.selectorServicios.getVal(); + + if (tarifa_text.length > 0) { + + var rows = this.table.rows().data().toArray(); + var found = rows.some(row => row.tarifa_id === tarifa_id); + + if (!found) + this.getPresupuestoPreimpresion(this.selectorServicios.getVal()); + else + popErrorAlert(window.language.Presupuestos.errores.error_servicios_duplicados, 'serv-preimpresion-alert'); + } + + this.check_serv_preimpresion_error(); + + showBreadCrumbSaveButton(true); + } + + cargarServiciosPreimpresion(datos) { + + this.table.rows.add(datos).draw(); + } + + + check_serv_preimpresion_error() { + + var htmlString = ''; + var error = false; + + const rows = this.table.rows().data().toArray(); + for (let i = 0; i < rows.length; i++) { + if (rows[i]['precio_total'] == 0) { + error = true; + break; + } + } + + if (error) { + htmlString = ` + `; + } + + $('#serv-preimpresion-error').html(htmlString) + } + + guardarServiciosPreimpresion() { + /* TO-DO + + */ + + } +} + +class ServiciosEncuadernacion { + + constructor(token, hash) { + + this.csrf_token = token; + this.csrf_hash = hash; + + this.table = null; + + this.selectorServicios = new ClassSelect($('#add_servicio_enc_list'), + '/tarifasencuadernacion/gettarifas', window.language.Presupuestos.servicioEncuadernacionList, false, {}); + this.addServicio = $('#insertar_serv_enc'); + } + + init() { + + const self = this; + + this.selectorServicios.init(); + + this.table = new DataTable('#tableOfServiciosEncuadernacion', { + scrollX: true, + searching: false, + paging: false, + info: false, + ordering: false, + responsive: true, + select: false, + language: { + url: "/themes/vuexy/vendor/libs/datatables-sk/plugins/i18n/es-ES.json" + }, + columns: [ + { data: 'tarifa_id' }, + { data: 'nombre' }, + { + data: 'proveedor', render: function (data, type, row) { + return ` + + `; + } + }, + { + data: 'paginas_por_cuadernillo', render: function (data, type, row) { + if (data == null) return ''; + else { + const value_list = [32, 28, 24, 20, 16]; + var string = + ''; + return string; + } + } + }, + { + data: 'tiempo', render: function (data, type, row) { + return self.convertirTiempo(data); + } + }, + { + data: 'precio_unidad', render: function (data, type, row) { + let precio_unidad_coste = (row.precio_unidad / (1 + row.margen / 100)).toFixed(2); + precio_unidad_coste = parseFloat(precio_unidad_coste).toLocaleString('es-ES', { minimumFractionDigits: 2, maximumFractionDigits: 2 }); + const precio_unidad = parseFloat(row.precio_unidad).toLocaleString('es-ES', { minimumFractionDigits: 2, maximumFractionDigits: 2 }); + return precio_unidad_coste + '/' + precio_unidad; + } + }, + { + data: 'precio_total', render: function (data, type, row) { + const total = parseFloat(data).toLocaleString('es-ES', { minimumFractionDigits: 2, maximumFractionDigits: 2 }); + return ` + `; + } + }, + { data: 'margen' }, + { + data: function (row) { + return ` + + `; + } + } + ], + + drawCallback: function (settings) { + + $('.cuadernillo_enc').select2({ + allowClear: false, + minimumResultsForSearch: -1, + }); + + $('.proveedor_encuadernacion').select2({ + + allowClear: false, + minimumResultsForSearch: -1, + ajax: { + url: '/serviciosencuadernaciones/menuitems', + type: 'post', + dataType: 'json', + + data: function (params) { + + let tirada = 0; + if (parseInt($('#tirada').val()) > 0) { + tirada = parseInt($('#tirada').val()) + } + + let paginas = 0; + if (parseInt($('#paginas').val()) > 0) { + paginas = parseInt($('#paginas').val()) + } + + const row = self.table.row($(this).closest('tr')).data(); + const tamanio = self.getDimensionLibro(); + + let return_data = { + tarifa_id: row.tarifa_id, + tirada: tirada, + paginas: paginas, + ancho: tamanio.ancho, + alto: tamanio.alto, + }; + + if (row.paginas_por_cuadernillo) { + return_data.paginas_por_cuadernillo = row.paginas_por_cuadernillo; + } + + return return_data; + }, + delay: 60, + processResults: function (response) { + yeniden(response[window.csrf_token]); + return { + results: response.menu + }; + }, + cache: true + } + }); + + $('.proveedor_encuadernacion').on('select2:close', function () { + + const row = $(this).closest('tr'); + const table = $(this).closest('table').DataTable(); + + if (!row.length || !table || $(this).select2('data') <= 0) return; + + const data = table.row(row).data(); + + data.proveedor_id = parseInt($(this).select2('data')[0].id); + data.proveedor_nombre = $(this).select2('data')[0].text; + //table.row(row).data(data).draw(); + + self.getPresupuestoEncuadernacion(null, $(this)); + }) + + $('.cuadernillo_enc').on('select2:close', function () { + + const row = $(this).closest('tr'); + const table = $(this).closest('table').DataTable(); + + if (!row.length || !table || $(this).select2('data') <= 0) return; + + const data = table.row(row).data(); + data.paginas_por_cuadernillo = parseInt($(this).select2('data')[0].text); + self.getPresupuestoEncuadernacion(null, $(this)); + }) + + self.check_serv_enc_error(); + } + }); + + $(document).on('click', '.btn-delete-servencuadernacion', function () { + const rowId = $(this).closest('td').parent()[0].sectionRowIndex; + self.table.row(rowId).remove().draw(); + }); + + + + this.addServicio.on('click', this.addServicioEncuadernacion.bind(this)); + + /*this.table.on('draw.dt', function () { + + /* TO-DO + updatePresupuesto({ + update_resumen: true, + update_tiradas_alternativas: true}) + + }); */ + } + + cargarServiciosEncuadernacion(datos) { + + this.table.rows.add(datos).draw(); + } + + async getServiciosDefecto() { + + this.table.clear().draw(); + + const self = this; + + let tirada = 0; + if (parseInt($('#tirada').val()) > 0) { + tirada = parseInt($('#tirada').val()) + } + let paginas = 0; + if (parseInt($('#paginas').val()) > 0) { + paginas = parseInt($('#paginas').val()) + } + + const tamanio = self.getDimensionLibro(); + let datos = { + tirada: tirada, + paginas: paginas, + ancho: tamanio.ancho, + alto: tamanio.alto, + solapas: $('#solapas').is(':checked') ? 1 : 0, + tipo_impresion_id: $('#tipo_impresion_id').val(), + tipo: 'default' + }; + + new Ajax('/serviciosencuadernaciones/datatable', datos, {}, + function (response) { + if (response.values) { + self.table.rows.add(response.values).draw(); + } + }, + function (error) { + console.error(error); + } + ).post(); + + this.check_serv_enc_error(); + + showBreadCrumbSaveButton(true); + } + + + getPresupuestoEncuadernacion(tarifa_id = -1, updateSelect = null) { + + const self = this; + + let tirada = 0; + if (parseInt($('#tirada').val()) > 0) { + tirada = parseInt($('#tirada').val()) + } + let paginas = 0; + if (parseInt($('#paginas').val()) > 0) { + paginas = parseInt($('#paginas').val()) + } + + const tamanio = self.getDimensionLibro(); + let datos = { + tirada: tirada, + paginas: paginas, + ancho: tamanio.ancho, + alto: tamanio.alto, + }; + + if (updateSelect != null) { + const row = updateSelect.closest('tr'); + const data = self.table.row(row).data(); + datos.tarifa_enc_id = data.tarifa_id; + datos.proveedor_id = data.proveedor_id; + if (data.paginas_por_cuadernillo) { + datos.paginas_por_cuadernillo = data.paginas_por_cuadernillo; + } + } + else { + datos.tarifa_enc_id = tarifa_id; + } + + if (datos.tarifa_enc_id > 0) { + new Ajax('/serviciosencuadernaciones/getvalues', datos, {}, + function (response) { + if (response.values) { + if (updateSelect != null) { + + self.table.row(updateSelect.closest('tr')).data(response.values[0]).draw(); + } + else { + self.table.rows.add([response.values[0]]).draw(); + } + } + }, + function (error) { + console.error(error); + } + ).post(); + } + } + + addServicioEncuadernacion() { + + const tarifa_text = this.selectorServicios.getText(); + const tarifa_id = this.selectorServicios.getVal(); + + if (tarifa_text.length > 0) { + + var rows = this.table.rows().data().toArray(); + var found = rows.some(row => row.tarifa_id === tarifa_id); + + if (!found) + this.getPresupuestoEncuadernacion(tarifa_id); + else + popErrorAlert(window.language.Presupuestos.errores.error_servicios_duplicados, 'serv-enc-alert'); + } + + this.check_serv_enc_error(); + + showBreadCrumbSaveButton(true); + + } + + guardarServiciosEncuadernacion() { + /* TO-DO + + */ + } + + + check_serv_enc_error() { + + var htmlString = ''; + var error = false; + + const rows = this.table.rows().data().toArray(); + for (let i = 0; i < rows.length; i++) { + if (rows[i]['precio_total'] == 0) { + error = true; + break; + } + } + + if (error) { + htmlString = ` + `; + } + $('#serv-enc-error').html(htmlString) + } + + + convertirTiempo(horas) { + + if (horas != null) { + + if (parseFloat(horas) > 0) { + + const seconds = parseFloat(horas) * 3600; + // se convierte a formato hh:mm:ss + const h = Math.floor(seconds / 3600); + const minutos = Math.floor((seconds % 3600) / 60); + const segundos = Math.round(seconds % 60, 0); + return h + ':' + minutos + ':' + segundos; + } + else { + return ""; + } + } + else { + return ""; + } + } + + getDimensionLibro() { + + var ancho = 0; + var alto = 0; + + + if ($('#papelFormatoPersonalizado').is(':checked')) { + ancho = parseFloat($('#papelFormatoAncho').val()); + alto = parseFloat($('#papelFormatoAlto').val()); + } + else { + 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 { + ancho: ancho, + alto: alto + } + } +} + +class ServiciosManipulado { + + constructor(token, hash) { + + this.csrf_token = token; + this.csrf_hash = hash; + + this.table = null; + + this.selectorServicios = new ClassSelect($('#add_servicio_manipulado_list'), + '/tarifasmanipulado/gettarifas', window.language.Presupuestos.servicioManipuladoList, false, {}); + this.addServicio = $('#insertar_serv_manipulado'); + } + + init() { + + const self = this; + + this.selectorServicios.init(); + + this.table = new DataTable('#tableOfServiciosManipulado', { + scrollX: true, + searching: false, + paging: false, + info: false, + ordering: false, + responsive: true, + select: false, + language: { + url: "/themes/vuexy/vendor/libs/datatables-sk/plugins/i18n/es-ES.json" + }, + columns: [ + { data: 'tarifa_id' }, + { data: 'nombre' }, + { + data: 'precio_unidad', render: function (data, type, row) { + let precio_unidad_coste = (row.precio_unidad / (1 + row.margen / 100)).toFixed(2); + precio_unidad_coste = parseFloat(precio_unidad_coste).toLocaleString('es-ES', { minimumFractionDigits: 2, maximumFractionDigits: 2 }); + const precio_unidad = parseFloat(row.precio_unidad).toLocaleString('es-ES', { minimumFractionDigits: 2, maximumFractionDigits: 2 }); + return precio_unidad_coste + '/' + precio_unidad; + } + }, + { + data: 'precio_total', render: function (data, type, row) { + const total = parseFloat(data).toLocaleString('es-ES', { minimumFractionDigits: 2, maximumFractionDigits: 2 }); + return ` + `; + } + }, + { data: 'margen' }, + { + data: function (row) { + return ` + + `; + } + } + ], + drawCallback: function (settings) { + + self.check_serv_manipulado_error(); + } + }); + + this.addServicio.on('click', this.addServicioManipulado.bind(this)); + + $(document).on('click', '.btn-delete-servmanipulado', function () { + const rowId = $(this).closest('td').parent()[0].sectionRowIndex; + self.table.row(rowId).remove().draw(); + }); + } + + + addServicioManipulado() { + + const tarifa_text = this.selectorServicios.getText(); + const tarifa_id = this.selectorServicios.getVal(); + + if (tarifa_text.length > 0) { + + var rows = this.table.rows().data().toArray(); + var found = rows.some(row => row.tarifa_id === tarifa_id); + + if (!found) + this.getPresupuestoManipulado(tarifa_id); + else + popErrorAlert(window.language.Presupuestos.errores.error_servicios_duplicados, 'serv-manipulado-alert'); + } + } + + async getServiciosDefecto() { + + this.table.clear().draw(); + + const self = this; + + let tirada = 0; + if (parseInt($('#tirada').val()) > 0) { + tirada = parseInt($('#tirada').val()) + } + + let datos = { + tirada: tirada, + solapas: $('#solapas').is(':checked') ? 1 : 0, + tipo_impresion_id: $('#tipo_impresion_id').val(), + tipo: 'default' + }; + + new Ajax('/serviciosmanipulados/datatable', datos, {}, + function (response) { + if (response.values) { + self.table.rows.add(response.values).draw(); + } + }, + function (error) { + console.error(error); + } + ).post(); + + this.check_serv_manipulado_error(); + + showBreadCrumbSaveButton(true); + } + + getPresupuestoManipulado(tarifa_id = -1) { + + const self = this; + + let tirada = 0; + if (parseInt($('#tirada').val()) > 0) { + tirada = parseInt($('#tirada').val()) + } + + let datos = { + tirada: tirada, + tarifa_manipulado_id: tarifa_id + }; + + if (datos.tarifa_manipulado_id > 0) { + new Ajax('/serviciosmanipulados/getvalues', datos, {}, + function (response) { + if (response.values) { + self.table.rows.add([response.values[0]]).draw(); + } + }, + function (error) { + console.error(error); + } + ).post(); + } + } + + cargarServiciosManipulado(datos) { + + this.table.rows.add(datos).draw(); + } + + guardarServiciosManipulado() { + /* TO-DO + + */ + } + + check_serv_manipulado_error() { + + var htmlString = ''; + var error = false; + + // get all rows of the table + const rows = this.table.rows().data().toArray(); + for (let i = 0; i < rows.length; i++) { + if (rows[i]['precio_total'] == 0) { + error = true; + break; + } + } + + if (error) { + htmlString = ` + `; + } + $('#serv-manipulado-error').html(htmlString) + } +} + +class ServiciosExtra { + + constructor(token, hash) { + + this.csrf_token = token; + this.csrf_hash = hash; + + this.table = null; + + this.selectorServicios = new ClassSelect($('#add_servicio_extra_list'), + '/tarifaextra/gettarifas', window.language.Presupuestos.servicioExtraList, false, {}); + this.addServicio = $('#insertar_serv_extra'); + + } + + init() { + + const self = this; + + this.selectorServicios.init(); + + this.table = new DataTable('#tableOfServiciosExtra', { + scrollX: true, + searching: false, + paging: false, + info: false, + ordering: false, + responsive: true, + select: false, + language: { + url: "/themes/vuexy/vendor/libs/datatables-sk/plugins/i18n/es-ES.json" + }, + columns: [ + { data: 'tarifa_id' }, + { data: 'nombre' }, + + { + data: 'coste', render: function (data, type, row) { + let coste = (row.precio / (1 + row.margen / 100)).toFixed(2); + coste = parseFloat(coste).toLocaleString('es-ES', { minimumFractionDigits: 2, maximumFractionDigits: 2 }); + return coste; + } + }, + { + data: 'precio', render: function (data, type, row) { + + const total = parseFloat(data).toLocaleString('es-ES', { minimumFractionDigits: 2, maximumFractionDigits: 2 }); + return ` + `; + + } + }, + { data: 'margen' }, + { + data: function (row) { + return ` + + `; + } + } + ], + drawCallback: function (settings) { + + self.check_serv_extra_error(); + } + + + }); + + $(document).on('click', '.btn-delete-servextra', function () { + const rowId = $(this).closest('td').parent()[0].sectionRowIndex; + self.table.row(rowId).remove().draw(); + }); + + this.addServicio.on('click', this.addServicioExtra.bind(this)); + } + + addServicioExtra() { + + const tarifa_text = this.selectorServicios.getText(); + const tarifa_id = this.selectorServicios.getVal(); + + if (tarifa_text.length > 0) { + + var rows = this.table.rows().data().toArray(); + var found = rows.some(row => row.tarifa_id === tarifa_id); + + if (!found) + this.getPresupuestoExtra(this.selectorServicios.getVal()); + else + popErrorAlert(window.language.Presupuestos.errores.error_servicios_duplicados, 'serv-extra-alert'); + } + + this.check_serv_extra_error(); + + showBreadCrumbSaveButton(true); + + } + + cargarServiciosExtra(datos) { + + this.table.rows.add(datos).draw(); + } + + guardarServiciosExtra() { + /* TO-DO + + */ + } + + getPresupuestoExtra(tarifa_id = -1) { + + const self = this; + + let datos = { + tarifa_extra_id: tarifa_id + }; + + if (datos.tarifa_extra_id > 0) { + new Ajax('/serviciosextra/getvalues', datos, {}, + function (response) { + if (response.values) { + self.table.rows.add([response.values[0]]).draw(); + } + }, + function (error) { + console.error(error); + } + ).post(); + } + } + + check_serv_extra_error() { + + var htmlString = ''; + var error = false; + + const rows = this.table.rows().data().toArray(); + for (let i = 0; i < rows.length; i++) { + if (rows[i]['precio_total'] == 0) { + error = true; + break; + } + } + + if (error) { + htmlString = ` + `; + } + + $('#serv-extra-error').html(htmlString) + } +} + export default Servicios; \ No newline at end of file