diff --git a/ci4/app/Config/Routes.php b/ci4/app/Config/Routes.php index 09ef7eaf..443012e3 100644 --- a/ci4/app/Config/Routes.php +++ b/ci4/app/Config/Routes.php @@ -407,6 +407,7 @@ $routes->group('clienteusuarios', ['namespace' => 'App\Controllers\Clientes'], f $routes->group('misdirecciones', ['namespace' => 'App\Controllers\Clientes'], function ($routes) { $routes->get('', 'Clientedirecciones::index', ['as' => 'clientedireccionesIndex']); + $routes->get('get/(:num)', 'Clientedirecciones::get/$1', ['as' => 'get']); }); @@ -575,6 +576,7 @@ $routes->group('presupuestocliente', ['namespace' => 'App\Controllers\Presupuest $routes->post('getNuevaDireccion', 'Presupuestocliente::getNuevaDireccion', ['as' => 'nuevaDireccion']); $routes->post('guardarPresupuesto', 'Presupuestocliente::guardarPresupuesto', ['as' => 'guardarPresupuesto']); $routes->post('duplicarPresupuesto', 'Presupuestocliente::duplicarPresupuesto', ['as' => 'duplicarPresupuesto']); + $routes->post('calcular', 'Presupuestocliente::calcular', ['as' => 'calcularPresupuesto']); }); $routes->resource('presupuestocliente', ['namespace' => 'App\Controllers\Presupuestos', 'controller' => 'Presupuestocliente', 'except' => 'show,new,create,update']); diff --git a/ci4/app/Controllers/Clientes/Clientedirecciones.php b/ci4/app/Controllers/Clientes/Clientedirecciones.php index d37d665f..ff8b38d9 100755 --- a/ci4/app/Controllers/Clientes/Clientedirecciones.php +++ b/ci4/app/Controllers/Clientes/Clientedirecciones.php @@ -1,4 +1,6 @@ -viewData['breadcrumb'] = [ ['title' => lang("Clientes.direccionesEnvio"), 'route' => "javascript:void(0);", 'active' => false], - + ]; $this->viewData['comunidadAutonomaList'] = $this->getComunidadAutonomaListItems($clienteEntity->comunidad_autonoma_id ?? null); @@ -71,9 +73,10 @@ class Clientedirecciones extends \App\Controllers\BaseResourceController return view(static::$viewPath . 'viewClienteDireccionesList', $viewData); } - public function add(){ + public function add() + { if ($this->request->isAJAX()) { - + $reqData = $this->request->getPost(); $cliente_id = $reqData['cliente_id'] ?? -1; $att = $reqData['att'] ?? ""; @@ -85,7 +88,7 @@ class Clientedirecciones extends \App\Controllers\BaseResourceController $cp = $reqData['cp'] ?? ""; $telefono = $reqData['telefono'] ?? ""; $alias = $reqData['alias'] ?? ""; - + $data = [ "cliente_id" => $cliente_id, "att" => $att, @@ -99,7 +102,7 @@ class Clientedirecciones extends \App\Controllers\BaseResourceController "alias" => $alias, ]; $response = $this->model->insert($data); - + $newTokenHash = csrf_hash(); $csrfTokenName = csrf_token(); $data_ret = [ @@ -107,7 +110,6 @@ class Clientedirecciones extends \App\Controllers\BaseResourceController $csrfTokenName => $newTokenHash ]; return $this->respond($data_ret); - } else { return $this->failUnauthorized('Invalid request', 403); } @@ -117,14 +119,14 @@ class Clientedirecciones extends \App\Controllers\BaseResourceController public function menuItems() { if ($this->request->isAJAX()) { - + $reqData = $this->request->getPost(); $cliente_id = $reqData['cliente_id'] ?? -1; - + $clienteDireccionesModel = model('App\Models\Clientes\ClienteDireccionesModel'); $menu = $clienteDireccionesModel->getMenuDirecciones($cliente_id); //$menu = $this->model->getMenuItems($cliente_id); - + $newTokenHash = csrf_hash(); $csrfTokenName = csrf_token(); $data = [ @@ -145,7 +147,7 @@ class Clientedirecciones extends \App\Controllers\BaseResourceController $tipo = $reqData['tipo'] ?? null; - if(is_null($tipo)){ + if (is_null($tipo)) { if (!isset($reqData['draw']) || !isset($reqData['columns'])) { $errstr = 'No data available in response to this specific request.'; $response = $this->respond(Collection::datatable([], 0, 0, $errstr), 400, $errstr); @@ -160,22 +162,21 @@ class Clientedirecciones extends \App\Controllers\BaseResourceController $id_C = $reqData['cliente_id'] ?? -1; - + $resourceData = $this->model->getResource($search, $id_C)->orderBy($order, $dir)->limit($length, $start)->get()->getResultObject(); - + return $this->respond(Collection::datatable( $resourceData, $this->model->getResource()->countAllResults(), $this->model->getResource("", $id_C)->countAllResults() )); - } - else{ + } else { $id = $reqData['id'] ?? -1; $resourceData = $this->model->getDireccion($id); - + return $this->respond($resourceData); } @@ -184,6 +185,25 @@ class Clientedirecciones extends \App\Controllers\BaseResourceController } } + + public function get($id) + { + try { + $resourceData = $this->model->getDireccion($id); + $response = (object)[ + 'error' => false, + 'data' => $resourceData + ]; + return $this->respond($response); + } catch (\Exception $e) { + $response = (object)[ + 'error' => true, + 'message' => $e->getMessage() + ]; + return $this->fail($response); + } + } + public function datatable_editor() { if ($this->request->isAJAX()) { @@ -194,72 +214,116 @@ class Clientedirecciones extends \App\Controllers\BaseResourceController $response = Editor::inst($db, 'cliente_direcciones') ->fields( Field::inst('att') - ->validator('Validate::notEmpty', array( - 'message' => lang('ClienteDirecciones.validation.required')) + ->validator( + 'Validate::notEmpty', + array( + 'message' => lang('ClienteDirecciones.validation.required') + ) ) - ->validator( Validate::maxLen( 100 ) , array( - 'message' => lang('ClienteDirecciones.validation.max_length')) - ), + ->validator( + Validate::maxLen(100), + array( + 'message' => lang('ClienteDirecciones.validation.max_length') + ) + ), Field::inst('alias') - ->validator('Validate::notEmpty', array( - 'message' => lang('ClienteDirecciones.validation.required')) + ->validator( + 'Validate::notEmpty', + array( + 'message' => lang('ClienteDirecciones.validation.required') + ) ) - ->validator( Validate::maxLen( 100 ) , array( - 'message' => lang('ClienteDirecciones.validation.max_length')) - ), + ->validator( + Validate::maxLen(100), + array( + 'message' => lang('ClienteDirecciones.validation.max_length') + ) + ), Field::inst('email') - ->validator('Validate::notEmpty', array( - 'message' => lang('ClienteDirecciones.validation.required')) + ->validator( + 'Validate::notEmpty', + array( + 'message' => lang('ClienteDirecciones.validation.required') + ) ) - ->validator( Validate::maxLen( 100 ) , array( - 'message' => lang('ClienteDirecciones.validation.max_length')) - ), + ->validator( + Validate::maxLen(100), + array( + 'message' => lang('ClienteDirecciones.validation.max_length') + ) + ), Field::inst('direccion') - ->validator('Validate::notEmpty', array( - 'message' => lang('ClienteDirecciones.validation.required')) + ->validator( + 'Validate::notEmpty', + array( + 'message' => lang('ClienteDirecciones.validation.required') + ) ) - ->validator( Validate::maxLen( 255 ) , array( - 'message' => lang('ClienteDirecciones.validation.max_length')) - ), + ->validator( + Validate::maxLen(255), + array( + 'message' => lang('ClienteDirecciones.validation.max_length') + ) + ), Field::inst('municipio') - ->validator('Validate::notEmpty', array( - 'message' => lang('ClienteDirecciones.validation.required')) + ->validator( + 'Validate::notEmpty', + array( + 'message' => lang('ClienteDirecciones.validation.required') + ) ) - ->validator( Validate::maxLen( 100 ) , array( - 'message' => lang('ClienteDirecciones.validation.max_length')) - ), + ->validator( + Validate::maxLen(100), + array( + 'message' => lang('ClienteDirecciones.validation.max_length') + ) + ), Field::inst('cp') - ->validator('Validate::notEmpty', array( - 'message' => lang('ClienteDirecciones.validation.required')) + ->validator( + 'Validate::notEmpty', + array( + 'message' => lang('ClienteDirecciones.validation.required') + ) ) - ->validator( Validate::maxLen( 20 ) , array( - 'message' => lang('ClienteDirecciones.validation.max_length')) - ), + ->validator( + Validate::maxLen(20), + array( + 'message' => lang('ClienteDirecciones.validation.max_length') + ) + ), Field::inst('telefono') - ->validator('Validate::notEmpty', array( - 'message' => lang('ClienteDirecciones.validation.required')) + ->validator( + 'Validate::notEmpty', + array( + 'message' => lang('ClienteDirecciones.validation.required') + ) ) - ->validator( Validate::maxLen( 40 ) , array( - 'message' => lang('ClienteDirecciones.validation.max_length')) - ), + ->validator( + Validate::maxLen(40), + array( + 'message' => lang('ClienteDirecciones.validation.max_length') + ) + ), Field::inst('provincia') - ->validator( function ( $val, $data, $field, $host ) { - if ($data['pais_id'] == 1) { // Si es españa provincia y CCAA es obligatorio - if (strlen( $val ) > 100) - return lang('ClienteDirecciones.validation.max_length'); - else if (strlen( $val ) == 0) - lang('ClienteDirecciones.validation.required'); - else - return true; + ->validator( + function ($val, $data, $field, $host) { + if ($data['pais_id'] == 1) { // Si es españa provincia y CCAA es obligatorio + if (strlen($val) > 100) + return lang('ClienteDirecciones.validation.max_length'); + else if (strlen($val) == 0) + lang('ClienteDirecciones.validation.required'); + else + return true; + } + return true; } - return true; - } - ), + ), Field::inst('pais_id')->validator('Validate::notEmpty', array( - 'message' => lang('ClienteDirecciones.validation.required'))), + 'message' => lang('ClienteDirecciones.validation.required') + )), Field::inst('cliente_id'), ) - + ->debug(true) ->process($_POST) ->data(); @@ -270,7 +334,6 @@ class Clientedirecciones extends \App\Controllers\BaseResourceController $response[$csrfTokenName] = $newTokenHash; echo json_encode($response); - } else { return $this->failUnauthorized('Invalid request', 403); } diff --git a/ci4/app/Controllers/Presupuestos/Presupuestocliente.php b/ci4/app/Controllers/Presupuestos/Presupuestocliente.php index 0be955ff..4026fcfb 100755 --- a/ci4/app/Controllers/Presupuestos/Presupuestocliente.php +++ b/ci4/app/Controllers/Presupuestos/Presupuestocliente.php @@ -93,7 +93,7 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController $model_user = model('App\Models\Usuarios\UserModel'); $user = $model_user->find(auth()->user()->id); $clienteId = $user->cliente_id; - + $presupuestoEntity = isset($sanitizedData) ? new PresupuestoEntity($sanitizedData) : new PresupuestoEntity(); $presupuestoEntity->clienteId = $clienteId; @@ -119,7 +119,7 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController $datosPresupuesto->tapa = 'blanda'; $datosPresupuesto->clienteList = $this->getClienteListItems($clienteId ?? null); - $datosPresupuesto->paginasCuadernillo = [32, 28, 24, 20 , 16]; + $datosPresupuesto->paginasCuadernillo = [32, 28, 24, 20, 16]; $presupuestoEntity->estado_id = 1; $presupuestoEntity->paginas_por_cuadernillo = 32; @@ -144,7 +144,7 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController endif; $id = filter_var($requestedId, FILTER_SANITIZE_URL); $presupuestoEntity = $this->model->find($id); - + if ($presupuestoEntity == false) : $message = lang('Basic.global.notFoundWithIdErr', [mb_strtolower(lang('Presupuestos.presupuesto')), $id]); return $this->redirect2listView('sweet-error', $message); @@ -185,13 +185,13 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController $this->obtenerDireccionesEnvio($presupuestoEntity); // Si el presupuesto está confirmado, se generan los datos del resumen - if($presupuestoEntity->estado_id == 2){ + if ($presupuestoEntity->estado_id == 2) { $this->generarResumen($presupuestoEntity); } - $datosPresupuesto->paginasCuadernillo = [32, 28, 24, 20 , 16]; + $datosPresupuesto->paginasCuadernillo = [32, 28, 24, 20, 16]; $presupuestoEntity->paginas_por_cuadernillo = $this->obtenerPaginasCuadernillo($presupuestoEntity); - + $this->viewData['formAction'] = 'edit'; $this->viewData['paisList'] = $this->getPaisListItems(); @@ -255,40 +255,7 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController } - public function getGramaje() - { - if ($this->request->isAJAX()) { - $reqData = $this->request->getPost(); - - try { - $newTokenHash = csrf_hash(); - $csrfTokenName = csrf_token(); - - $tirada = $reqData['tirada'] ?? 0; - $merma = $reqData['merma'] ?? 0; - $papel = $reqData['papel'] ?? ""; - $uso = $reqData['uso'] ?? ""; - - $model = new PapelGenericoModel(); - $menu = $model->getGramajeComparador($papel, $uso, intval($tirada + $merma)); - - $data = [ - 'menu' => $menu, - $csrfTokenName => $newTokenHash - ]; - } catch (Exception $e) { - $data = [ - 'error' => $e, - $csrfTokenName => $newTokenHash - ]; - } finally { - return $this->respond($data); - } - } else { - return $this->failUnauthorized('Invalid request', 403); - } - } public function datatable() { @@ -334,83 +301,102 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController - public function presupuesto() + public function calcular() { if ($this->request->isAJAX()) { - $reqData = $this->request->getPost(); - $newTokenHash = csrf_hash(); - $csrfTokenName = csrf_token(); + try { - $tirada = $reqData['tirada'] ?? 0; - $tamanio = $reqData['tamanio']; - $tipo_impresion_id = $this->getTipoImpresion($reqData['tipo'], $reqData['tapa']); - $cliente_id = $reqData['clienteId'] ?? -1; - $isColor = intval($reqData['isColor']) ?? 0; - $isHq = intval($reqData['isHq']) ?? 0; + $reqData = $this->request->getPost(); + $modelPapelGenerico = new PapelGenericoModel(); - // Interior - $papel_generico = [ - 'id' => $reqData['papelInterior'] ?? 0, - 'nombre' => $reqData['papelInteriorNombre'] ?? "", - ]; - $gramaje = $reqData['gramajeInterior'] ?? 0; - $excluirRotativa = $reqData['excluirRotativa'] ?? 0; - $paginas = intval($reqData['paginas']) ?? 0; - $paginas_color = intval($reqData['paginasColor']) ?? 0; - // Cubierta - $papel_generico_cubierta = [ - 'id' => $reqData['papelCubierta'] ?? 0, - 'nombre' => $reqData['papelCubiertaNombre'] ?? "", - ]; - $gramajeCubierta = $reqData['gramajeCubierta'] ?? 0; - $carasCubierta = intval($reqData['carasCubierta'] ?? 0); - $solapasCubierta = intval($reqData['solapasCubierta'] ?? 0); - $acabadoCubierta = $reqData['acabadoCubierta'] ?? 0; + $cliente_id = $reqData['clienteId'] ?? -1; - // Sobrecubierta - $sobreCubierta = $reqData["sobrecubierta"] ?? null; + $tirada = $reqData['tirada'] ?? 0; + $tamanio = $reqData['tamanio']; + $paginas = $reqData['paginas'] ?? 0; + $paginas_color = $reqData['paginasColor'] ?? 0; + $tipo = $reqData['tipo']; - // Guardas - $datos_guardas = $reqData['guardas'] ?? []; + $paginasCuadernillo = $reqData['paginasCuadernillo'] ?? null; - $servicios = $reqData['servicios'] ?? []; + $isColor = intval($reqData['isColor']) ?? 0; + $isHq = intval($reqData['isHq']) ?? 0; - $paginasCuadernillo = $reqData['paginasCuadernillo'] ?? null; + $interior = $reqData['interior'] ?? []; + $cubierta = $reqData['cubierta'] ?? []; + $sobrecubierta = $reqData['sobrecubierta'] ?? []; + $guardas = $reqData['guardas'] ?? []; + $faja = $reqData['faja'] ?? []; + $excluirRotativa = $reqData['excluirRotativa'] ?? 0; + $ivaReducido = $reqData['ivaReducido'] ?? 0; - $datos_presupuesto = array( - 'tirada' => $tirada, - 'tamanio' => $tamanio, - 'tipo_impresion_id' => $tipo_impresion_id, - 'clienteId' => $cliente_id, - 'isColor' => $isColor, - 'isHq' => $isHq, - 'paginasCuadernillo' => $paginasCuadernillo, + $tipo_impresion_id = $this->getTipoImpresion($tipo, $cubierta['tipoCubierta']); - 'interior' => array( - 'papel_generico' => $papel_generico, - 'gramaje' => $gramaje, - 'excluirRotativa' => $excluirRotativa, + // Interior + $interior = [ + 'papel_generico' => $modelPapelGenerico->getIdFromCode($interior['papelInterior']), + 'gramaje' => intval($interior['gramajeInterior']), + 'excluirRotativa' => $excluirRotativa == "false" ? false: true, 'paginas' => $paginas, 'paginas_color' => $paginas_color, - ), - 'cubierta' => array( - 'papel_generico_cubierta' => $papel_generico_cubierta, - 'gramajeCubierta' => $gramajeCubierta, - 'carasCubierta' => $carasCubierta, - 'solapasCubierta' => $solapasCubierta, - ), - 'acabadoCubierta' => $acabadoCubierta, - 'sobrecubierta' => $sobreCubierta, - 'datos_guardas' => $datos_guardas, - 'servicios' => $servicios, - ); + ]; - $return_data = $this->calcular_presupuesto($datos_presupuesto, 0, false); //TRUE FOR DEBUG - array_merge($return_data, [$csrfTokenName => $newTokenHash]); - return $this->respond($return_data); + // Cubierta + $cubierta = [ + 'papel_generico_cubierta' => $modelPapelGenerico->getIdFromCode($cubierta['papelCubierta']), + 'gramajeCubierta' => intval($cubierta['gramajeCubierta']), + 'carasCubierta' => intval($cubierta['carasImpresion'] ?? 0), + 'solapasCubierta' => intval($cubierta['solapas'] ?? 0), + 'acabadosCubierta' => $cubierta['acabados'] ?? 0, + ]; + + // Sobrecubierta + if ($sobrecubierta != "false" && $sobrecubierta != null) { + $sobrecubierta = [ + 'papel' => $modelPapelGenerico->getIdFromCode($sobrecubierta['papel']), + 'gramaje' => intval($sobrecubierta['gramaje']), + 'solapas' => intval($sobrecubierta['solapas'] ?? 0), + 'acabados' => $sobrecubierta['plastificado'] ?? 0, + ]; + } + else + $sobrecubierta = false; + + // Guardas + if ($guardas != "false" && $guardas != null) { + $datos_guardas = [ + 'papel' => $modelPapelGenerico->getIdFromCode($guardas['papel']), + 'gramaje' => intval($guardas['gramaje']), + 'caras' => intval($guardas['guardasImpresas']), + ]; + } + else + $datos_guardas = false; + + $datos_presupuesto = array( + 'tirada' => $tirada, + 'tamanio' => $tamanio, + 'tipo_impresion_id' => $tipo_impresion_id, + 'clienteId' => $cliente_id, + 'isColor' => $isColor, + 'isHq' => $isHq, + 'paginasCuadernillo' => $paginasCuadernillo, + + 'interior' => $interior, + 'cubierta' => $cubierta, + 'sobrecubierta' => $sobrecubierta, + 'datos_guardas' => $datos_guardas, + ); + + $return_data = $this->calcular_presupuesto($datos_presupuesto, 0, false); //TRUE FOR DEBUG + + return $this->respond($return_data); + } catch (Exception $e) { + return $this->failServerError($e->getMessage()); + } } else { return $this->failUnauthorized('Invalid request', 403); } @@ -500,7 +486,8 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController } } - public function duplicarPresupuesto(){ + public function duplicarPresupuesto() + { if ($this->request->isAJAX()) { $reqData = $this->request->getPost(); @@ -510,61 +497,60 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController $id = $reqData['id'] ?? 0; - if($id > 0){ - try{ - + if ($id > 0) { + try { + $presupuesto = $this->model->find($id); - $presupuesto->titulo = $presupuesto->titulo .' - ' . lang('Presupuestos.duplicado'); + $presupuesto->titulo = $presupuesto->titulo . ' - ' . lang('Presupuestos.duplicado'); $presupuesto->is_duplicado = 1; $presupuesto->estado_id = 1; $new_id = $this->model->insert($presupuesto); - + $presupuestoAcabadosModel = model('App\Models\Presupuestos\PresupuestoAcabadosModel'); foreach ($presupuestoAcabadosModel->where('presupuesto_id', $presupuesto->id)->findAll() as $acabado) { $acabado->presupuesto_id = $new_id; $presupuestoAcabadosModel->insert($acabado); } - + $presupuestoEncuadernacionesModel = model('App\Models\Presupuestos\PresupuestoEncuadernacionesModel'); foreach ($presupuestoEncuadernacionesModel->where('presupuesto_id', $presupuesto->id)->findAll() as $encuadernacion) { $encuadernacion->presupuesto_id = $new_id; $presupuestoEncuadernacionesModel->insert($encuadernacion); } - + $presupuestoManipuladosModel = model('App\Models\Presupuestos\PresupuestoManipuladosModel'); foreach ($presupuestoManipuladosModel->where('presupuesto_id', $presupuesto->id)->findAll() as $manipulado) { $manipulado->presupuesto_id = $new_id; $presupuestoManipuladosModel->insert($manipulado); } - + $presupuestoPreimpresionesModel = model('App\Models\Presupuestos\PresupuestoPreimpresionesModel'); foreach ($presupuestoPreimpresionesModel->where('presupuesto_id', $presupuesto->id)->findAll() as $preimpresion) { $preimpresion->presupuesto_id = $new_id; $presupuestoPreimpresionesModel->insert($preimpresion); } - + $presupuestoServiciosExtraModel = model('App\Models\Presupuestos\PresupuestoServiciosExtraModel'); foreach ($presupuestoServiciosExtraModel->where('presupuesto_id', $presupuesto->id)->findAll() as $servicioExtra) { $servicioExtra->presupuesto_id = $new_id; $presupuestoServiciosExtraModel->insert($preimpresion); } - + $presupuestoDireccionesModel = model('App\Models\Presupuestos\PresupuestoDireccionesModel'); foreach ($presupuestoDireccionesModel->where('presupuesto_id', $presupuesto->id)->findAll() as $direccion) { $direccion->presupuesto_id = $new_id; $presupuestoDireccionesModel->insert($direccion); } - + $presupuestoLineaModel = model('App\Models\Presupuestos\PresupuestoLineaModel'); $presupuestoLineaModel->duplicateLineasPresupuesto($presupuesto->id, $new_id); - + return $this->respond([ 'success' => true, 'id' => $new_id, $csrfTokenName => $newTokenHash ]); - - }catch(\Exception $e){ + } catch (\Exception $e) { return $this->respond([ 'success' => false, 'message' => $e->getMessage(), @@ -577,9 +563,8 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController 'success' => false, 'message' => "No existe el presupuesto", $csrfTokenName => $newTokenHash - + ]); - } else { return $this->failUnauthorized('Invalid request', 403); } @@ -697,7 +682,7 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController $proporcion = intval($direccion['unidades']) / $selected_tirada * 100.0; $unidades_calculo = floor($tirada[$i] * $proporcion / 100.0); - try{ + try { $coste_envio = $this->calcular_coste_envio( $direccion['id'], $peso_libro, @@ -712,8 +697,7 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController $resultado_presupuesto['info']['totales'][$i]['coste_envio'] += $coste; $resultado_presupuesto['info']['totales'][$i]['margen_envio'] += $margen; } - } - catch(Exception $e){ + } catch (Exception $e) { return $this->respond([ 'status' => -1, 'message' => "Error al calcular el coste de envío (¿las direcciones están guardadas?)", @@ -793,14 +777,13 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController if ($servicio->tarifa_id == 3 || $servicio->tarifa_id == 5 || $servicio->tarifa_id == 16) { // Servicios acabado $this->guardarServicio($id, $servicio, 'acabado'); - } else if ($servicio->tarifa_id == 24 ) { + } else if ($servicio->tarifa_id == 24) { // Servicios preimpresion $this->guardarServicio($id, $servicio, 'preimpresion'); } else if ($servicio->tarifa_id == 9) { // Servicios extra $this->guardarServicio($id, $servicio, 'extra'); - } - else if ($servicio->tarifa_id == 62) { + } else if ($servicio->tarifa_id == 62) { // Servicios manipulado $this->guardarServicio($id, $servicio, 'manipulado'); } @@ -826,7 +809,8 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController } } - public function get_files(){ + public function get_files() + { // Check if the request is a POST request if ($_SERVER['REQUEST_METHOD'] == 'POST') { @@ -842,14 +826,15 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController $size = filesize($file->file_path); $splitPath = explode("presupuestos/", $file->file_path); - + // se crea un objeto con el nombre del fichero y el tamaño $obj = (object) array( 'name' => $file->nombre, 'size' => $size, - 'hash' => $splitPath[1] ?? $file->file_path); + 'hash' => $splitPath[1] ?? $file->file_path + ); + - // se añade el objeto al array array_push($result, $obj); } @@ -858,23 +843,24 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController } } - public function upload_files(){ + public function upload_files() + { $model = model('App\Models\Presupuestos\PresupuestoFicheroModel'); if ($_SERVER['REQUEST_METHOD'] == 'POST') { $presupuesto_id = $_POST['presupuesto_id']; - $old_files = json_decode($_POST['oldFiles']); - + $old_files = json_decode($_POST['oldFiles']); + // Comprobar si se han subido archivos if (!empty($_FILES['file']) || !empty($old_files)) { - - + + // Borrar los archivos existentes del presupuesto $model->deleteFiles($presupuesto_id, $old_files); - if (!empty($_FILES['file'])){ + if (!empty($_FILES['file'])) { $files = $_FILES['file']; // Iterar sobre los archivos @@ -885,23 +871,22 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController $tmp_name = $files['tmp_name'][$i]; $new_name = $model->saveFileInBBDD($presupuesto_id, $name, $extension, auth()->id()); - + // Se sube el fichero // Pero primero se comprueba que la carpeta presupuestos exista if (!is_dir(WRITEPATH . 'uploads/presupuestos')) { mkdir(WRITEPATH . 'uploads/presupuestos', 0777, true); } - if(!is_null($new_name)){ + if (!is_null($new_name)) { $path = WRITEPATH . 'uploads/presupuestos/' . $new_name; - move_uploaded_file($tmp_name,$path); + move_uploaded_file($tmp_name, $path); $ftp = new SafekatFtpClient(); $ftp->uploadFilePresupuesto($presupuesto_id); } } } - } - else{ + } else { // Borrar los archivos existentes del presupuesto $model->deleteFiles($presupuesto_id); } @@ -910,7 +895,7 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController } - + /*********************** @@ -1002,7 +987,7 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController if (isset($servicio->paginas_por_cuadernillo)) { $data['paginas_por_cuadernillo'] = $servicio->paginas_por_cuadernillo; } - + $model->insert($data); } else if ($tipo == 'extra') { $model = new PresupuestoServiciosExtraModel(); @@ -1077,7 +1062,7 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController $coste = $tarifas_envio[0]->precio; } } - if (count($data) > 0 && count($tarifas_envio) > 0){ + if (count($data) > 0 && count($tarifas_envio) > 0) { $data[0]->coste = $coste; $data[0]->tipo = $entregaPieCalle ? 'palets' : 'cajas'; $data[0]->margen = $margen; @@ -1324,13 +1309,9 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController $linea_sobrecubierta = []; $acabadoSobrecubierta = []; $lomo_sobrecubierta = 0.0; - if (!is_null($sobreCubierta)) { + if (!is_null($sobreCubierta) && $sobreCubierta) { - $papel_generico_sobrecubierta = [ - 'id' => $sobreCubierta['papel'] ?? 0, - 'nombre' => $sobreCubierta['papel_nombre'] ?? "", - ]; - $input_data['papel_generico'] = $papel_generico_sobrecubierta; + $input_data['papel_generico'] = $sobreCubierta['papel'] ?? 0; $input_data['gramaje'] = $sobreCubierta['gramaje'] ?? 0; $input_data['datosPedido']->paginas = 4; $input_data['paginas_color'] = 4; @@ -1365,7 +1346,8 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController $lomo_sobrecubierta = $lomo + floatval($linea_sobrecubierta['mano']); - $tarifaAcabadoSobrecubierta = intval(strlen($sobreCubierta['acabado']) == 0 ? 0 : $sobreCubierta['acabado']); + ////////////////////////////////////JJJO + $tarifaAcabadoSobrecubierta = intval(strlen($sobreCubierta['acabados']) == 0 ? 0 : $sobreCubierta['acabados']); $acabadoSobrecubierta = []; if ($tarifaAcabadoSobrecubierta > 0) { $model = model('App\Models\Presupuestos\PresupuestoAcabadosModel'); @@ -1382,15 +1364,11 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController $guardas = []; $peso_guardas = 0.0; $coste_guardas = 0.0; - if($datos_guardas != 0){ - if (count($datos_guardas) != 0) { + if ($datos_guardas != 0) { + if (count($datos_guardas) != 0 && $datos_guardas) { $guardas = $datos_guardas; - $papel_generico_guardas = [ - 'id' => $datos_guardas['papel'] ?? 0, - 'nombre' => $datos_guardas['nombre'] ?? "", - ]; - $input_data['papel_generico'] = $papel_generico_guardas; + $input_data['papel_generico'] = $datos_guardas['papel'] ?? 0; $input_data['gramaje'] = $datos_guardas['gramaje'] ?? 0; $input_data['datosPedido']->paginas = 8; $input_data['paginas_color'] = 8; @@ -1470,17 +1448,16 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController // Servicios // se comprueba si $datos guardas es un array - if(is_array($datos_guardas)){ - if(count($datos_guardas) > 0){ + if (is_array($datos_guardas)) { + if (count($datos_guardas) > 0) { array_push($servicios, 62); // Plegado de guardas } - } - else{ + } else { if ($datos_guardas > 0) { array_push($servicios, 62); // Plegado de guardas } } - + /* 'retractilado' => 3, 'retractilado5' => 5, @@ -1523,7 +1500,7 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController $margenServicios += floatval($resultado[0]->precio) * floatval($resultado[0]->margen) / 100.0; } } - if(intval($servicio) == 9) { + if (intval($servicio) == 9) { // Servicios preimpresion $resultado = PresupuestoCLienteService::getServiciosExtra([ 'tarifa_id' => $servicio, @@ -1541,7 +1518,7 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController // Servicios manipulado $resultado = PresupuestoCLienteService::getServiciosManipulado([ 'tarifa_id' => $servicio, - 'tirada' => $datosPedido->tirada, + 'tirada' => $tirada[$t], 'POD' => $POD, ]); array_push($serviciosAutomaticos, $resultado[0]); @@ -1591,7 +1568,7 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController $info['lomo_cubierta'] = $lomo; $info['lomo_sobrecubierta'] = $lomo_sobrecubierta; $return_data['info'] = $info; - + if ($extra_info) { // && $tirada[$t] == $selected_tirada) { @@ -1622,7 +1599,11 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController return $return_data; } catch (Exception $e) { - return ['exception' => $e->getMessage()]; + return [ + 'exception' => $e->getMessage(), + "line" => $e->getLine(), + "file" => $e->getFile() + ]; } } @@ -1665,37 +1646,41 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController protected function getTipoImpresion($tipo, $tapa) { - $tipo_impresion_id = 0; + $tipo_impresion_id = -1; - if ($tipo == 'fresado') { + try { + if ($tipo == 'fresado') { - if ($tapa == 'blanda') - $tipo_impresion_id = 2; - else - $tipo_impresion_id = 1; - } else if ($tipo == 'cosido') { + if (strpos(strtolower($tapa), 'blanda') !== false) + $tipo_impresion_id = 2; + else + $tipo_impresion_id = 1; + } else if ($tipo == 'cosido') { - if ($tapa == 'blanda') - $tipo_impresion_id = 4; - else - $tipo_impresion_id = 3; - } else if ($tipo == 'espiral') { + if (strpos(strtolower($tapa), 'blanda') !== false) + $tipo_impresion_id = 4; + else + $tipo_impresion_id = 3; + } else if ($tipo == 'espiral') { - if ($tapa == 'blanda') - $tipo_impresion_id = 6; - else - $tipo_impresion_id = 5; - } else if ($tipo == 'wireo') { + if (strpos(strtolower($tapa), 'blanda') !== false) + $tipo_impresion_id = 6; + else + $tipo_impresion_id = 5; + } else if ($tipo == 'wireo') { - if ($tapa == 'blanda') - $tipo_impresion_id = 8; - else - $tipo_impresion_id = 7; - } else if ($tipo == 'grapado') { - $tipo_impresion_id = 21; + if (strpos(strtolower($tapa), 'blanda') !== false) + $tipo_impresion_id = 8; + else + $tipo_impresion_id = 7; + } else if ($tipo == 'grapado') { + $tipo_impresion_id = 21; + } + + return $tipo_impresion_id; + } catch (Exception $e) { + return -1; } - - return $tipo_impresion_id; } @@ -1805,11 +1790,11 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController $tipo = "negro"; - if($calidad == 'premium' && $color=='negro') + if ($calidad == 'premium' && $color == 'negro') $tipo = "negroHq"; - else if ($calidad == 'estandar' && $color=='color') + else if ($calidad == 'estandar' && $color == 'color') $tipo = "color"; - else if ($calidad == 'premium' && $color=='color') + else if ($calidad == 'premium' && $color == 'color') $tipo = "colorHq"; return $tipo; @@ -1832,7 +1817,7 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController protected function obtenerPaginasColor($presupuestoEntity) { $comparador_data = json_decode($presupuestoEntity->comparador_json_data); - if(!is_null($comparador_data)){ + if (!is_null($comparador_data)) { if (property_exists($comparador_data, 'color')) { $presupuestoEntity->paginasColor = $comparador_data->color->paginas; } @@ -1841,8 +1826,7 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController } else { $presupuestoEntity->paginasColor = 0; } - } - else + } else $presupuestoEntity->paginasColor = 0; } @@ -1876,23 +1860,24 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController $result = []; $temp = []; - for ($i=0; $igetIdForPresupuestoCliente( - $presupuestoEntity->cliente_id, + $presupuestoEntity->cliente_id, $direcciones[$i]->att, $direcciones[$i]->email, $direcciones[$i]->direccion, $direcciones[$i]->cp, $direcciones[$i]->pais_id, - $direcciones[$i]->telefono); - if(count($direccion_id) > 0) { + $direcciones[$i]->telefono + ); + if (count($direccion_id) > 0) { $temp = $direcciones[$i]->toArray(); $temp['pais'] = $model_pais->where('id', $direcciones[$i]->pais_id)->first()->nombre; $temp['direccion_id'] = $direccion_id[0]->id; - array_push($result, $temp); + array_push($result, $temp); } } - if(count($result) > 0) + if (count($result) > 0) $presupuestoEntity->direcciones_envio = $result; } @@ -1932,8 +1917,9 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController } } - protected function generarResumen($presupuestoEntity){ - + protected function generarResumen($presupuestoEntity) + { + $presupuestoEntity->resumen = (object)[ 'titulo' => $this->generarTitulo($presupuestoEntity), 'tamanio' => $this->obtenerTamanio($presupuestoEntity), @@ -1941,37 +1927,39 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController ]; $model_papelGenerico = model('App\Models\Configuracion\PapelGenericoModel'); - if(!is_null($presupuestoEntity->papel_interior)){ + if (!is_null($presupuestoEntity->papel_interior)) { $nombre = $model_papelGenerico->where('id', $presupuestoEntity->papel_interior)->first()->nombre; - if($nombre != null) + if ($nombre != null) $presupuestoEntity->papel_interior_nombre = $nombre; } - if(!is_null($presupuestoEntity->papel_cubierta)){ + if (!is_null($presupuestoEntity->papel_cubierta)) { $nombre = $model_papelGenerico->where('id', $presupuestoEntity->papel_interior)->first()->nombre; - if($nombre != null) + if ($nombre != null) $presupuestoEntity->papel_cubierta_nombre = $nombre; } - if(!is_null($presupuestoEntity->papel_sobrecubierta)){ + if (!is_null($presupuestoEntity->papel_sobrecubierta)) { $nombre = $model_papelGenerico->where('id', $presupuestoEntity->papel_sobrecubierta)->first()->nombre; - if($nombre != null) + if ($nombre != null) $presupuestoEntity->papel_sobrecubierta_nombre = $nombre; } - if(!is_null($presupuestoEntity->papel_guardas)){ + if (!is_null($presupuestoEntity->papel_guardas)) { $nombre = $model_papelGenerico->where('id', $presupuestoEntity->papel_guardas)->first()->nombre; - if($nombre != null) + if ($nombre != null) $presupuestoEntity->papel_guardas_nombre = $nombre; } } - protected function generarTitulo($presupuestoEntity){ + protected function generarTitulo($presupuestoEntity) + { $model = model('App\Models\Configuracion\TipoPresupuestoModel'); $codigo = $model->where('id', $presupuestoEntity->tipo_impresion_id)->first()->codigo; - $titulo = lang('Presupuestos.titulos.'.$codigo); + $titulo = lang('Presupuestos.titulos.' . $codigo); return $titulo; } - protected function obtenerTamanio($presupuestoEntity){ + protected function obtenerTamanio($presupuestoEntity) + { $ancho = 0; $alto = 0; @@ -1979,15 +1967,14 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController $model = model('App\Models\Presupuestos\PresupuestoModel'); $data = $model->where('id', $presupuestoEntity->id)->first(); - if($data != null){ - if($data->papel_formato_personalizado == 0){ + if ($data != null) { + if ($data->papel_formato_personalizado == 0) { $model_papel_formato = model('App\Models\Configuracion\PapelFormatoModel'); $data_papel_formato = $model_papel_formato->where('id', $data->papel_formato_id)->first(); $ancho = $data_papel_formato->ancho; $alto = $data_papel_formato->alto; - } - else{ + } else { $ancho = $data->papel_formato_ancho; $alto = $data->papel_formato_alto; } @@ -1996,7 +1983,8 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController return $ancho . "x" . $alto; } - protected function obtenerTipoImpresion($presupuestoEntity){ + protected function obtenerTipoImpresion($presupuestoEntity) + { $id = $presupuestoEntity->id; @@ -2019,14 +2007,15 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController return $tipo; } - protected function obtenerPaginasCuadernillo($presupuestoEntity){ + protected function obtenerPaginasCuadernillo($presupuestoEntity) + { $model = model('App\Models\Presupuestos\PresupuestoEncuadernacionesModel'); $lineas = $model->getResource($presupuestoEntity->id)->get()->getResultObject(); - - foreach ($lineas as $linea){ + + foreach ($lineas as $linea) { // check if exist - if($linea->paginas_por_cuadernillo != null) + if ($linea->paginas_por_cuadernillo != null) return $linea->paginas_por_cuadernillo; } return 32; // valor por defecto diff --git a/ci4/app/Controllers/Tarifas/Acabados/TarifaAcabados.php b/ci4/app/Controllers/Tarifas/Acabados/TarifaAcabados.php index eb9e47eb..85920898 100644 --- a/ci4/app/Controllers/Tarifas/Acabados/TarifaAcabados.php +++ b/ci4/app/Controllers/Tarifas/Acabados/TarifaAcabados.php @@ -39,10 +39,10 @@ class TarifaAcabados extends BaseResourceController $this->viewData = ['usingServerSideDataTable' => true]; - // Breadcrumbs + // Breadcrumbs $this->viewData['breadcrumb'] = [ ['title' => lang("App.menu_tarifas"), 'route' => "javascript:void(0);", 'active' => false], - ['title' => lang("App.menu_tarifaacabado"), 'route' => site_url('tarifas/tarifaacabado'), 'active' => true] + ['title' => lang("App.menu_tarifaacabado"), 'route' => site_url('tarifas/acabados'), 'active' => true] ]; parent::initController($request, $response, $logger); @@ -133,6 +133,8 @@ class TarifaAcabados extends BaseResourceController endif; // ($requestMethod === 'post') + $this->viewData['proveedores'] = $this->getProveedores(); + $this->viewData['tarifaacabadoEntity'] = isset($sanitizedData) ? new TarifaAcabadoEntity($sanitizedData) : new TarifaAcabadoEntity(); $this->viewData['formAction'] = route_to('tarifaAcabadoAdd'); $this->viewData['boxTitle'] = lang('Basic.global.addNew') . ' ' . lang('Tarifaacabado.moduleTitle') . ' ' . lang('Basic.global.addNewSuffix'); diff --git a/ci4/app/Models/Configuracion/PapelGenericoModel.php b/ci4/app/Models/Configuracion/PapelGenericoModel.php index 6b55a382..9b27c5a2 100755 --- a/ci4/app/Models/Configuracion/PapelGenericoModel.php +++ b/ci4/app/Models/Configuracion/PapelGenericoModel.php @@ -61,6 +61,21 @@ class PapelGenericoModel extends \App\Models\BaseModel ], ]; + + public function getIdFromCode(string $code=""){ + $builder = $this->db + ->table($this->table . " t1") + ->select( + "t1.id AS id, t1.nombre AS nombre" + ) + ->where("t1.code", $code) + ->where("t1.is_deleted", 0); + $data = $builder->get()->getFirstRow(); + // se convierte a de stdClass a array + $data = json_decode(json_encode($data), true); + return $data; + } + /** * Get resource data. * diff --git a/ci4/app/Services/PresupuestoClienteService.php b/ci4/app/Services/PresupuestoClienteService.php index bf6c6408..e4d24f0b 100644 --- a/ci4/app/Services/PresupuestoClienteService.php +++ b/ci4/app/Services/PresupuestoClienteService.php @@ -15,7 +15,10 @@ class PresupuestoClienteService extends BaseService { $rotativa = []; - $plana = PresupuestoClienteService::obtenerPresupuestoClienteInterior($data); + $plana = []; + // no se busca en plana cuando es estándar (no Premium) + if($data['isHq']) + $plana = PresupuestoClienteService::obtenerPresupuestoClienteInterior($data); if (!$data['excluirRotativa'] && !$data['isHq']) $rotativa = PresupuestoClienteService::obtenerPresupuestoClienteInteriorRotativa($data); diff --git a/ci4/app/Views/themes/vuexy/form/presupuestos/cliente/items/_datosGenerales.php b/ci4/app/Views/themes/vuexy/form/presupuestos/cliente/items/_datosGenerales.php index 58792d5e..8236f00e 100644 --- a/ci4/app/Views/themes/vuexy/form/presupuestos/cliente/items/_datosGenerales.php +++ b/ci4/app/Views/themes/vuexy/form/presupuestos/cliente/items/_datosGenerales.php @@ -1,5 +1,9 @@
+
+

Datos del libro

+
+
+
+
+ + +
+
+ +
-
+
@@ -116,10 +128,26 @@
+
+ +
+ + +
+
+
- +
@@ -136,8 +164,8 @@
-
- +
+
@@ -147,25 +175,25 @@
-
+
" alt="Fresado">
Fresado (a partir de 32 páginas)
-
+
" alt="Grapado">
Grapado (entre 12 y 40 páginas)
-
+
" alt="Espiral">
Espiral
-
+
" alt="Cosido">
Cosido (a partir de 32 páginas) @@ -173,4 +201,37 @@
+
+

Servicios extra

+
+ +
+
+ + +
+
+ + +
+

Otros

+
+ +
+ +
+ + +
+ +

Se verificará que el pedido cumpla con los requisitos establecidos en el Artículo 91 de la Ley 37/1992, sobre inserción de publicidad, antes de proceder con su producción, lo que garantiza la aplicación del IVA reducido del 4%.

+
+
\ No newline at end of file diff --git a/ci4/app/Views/themes/vuexy/form/presupuestos/cliente/items/_direcciones.php b/ci4/app/Views/themes/vuexy/form/presupuestos/cliente/items/_direcciones.php index 006223e7..2e208438 100644 --- a/ci4/app/Views/themes/vuexy/form/presupuestos/cliente/items/_direcciones.php +++ b/ci4/app/Views/themes/vuexy/form/presupuestos/cliente/items/_direcciones.php @@ -47,7 +47,7 @@
-
+
diff --git a/ci4/app/Views/themes/vuexy/form/presupuestos/cliente/items/_disenioCubierta.php b/ci4/app/Views/themes/vuexy/form/presupuestos/cliente/items/_disenioCubierta.php index 3011902a..b5000969 100644 --- a/ci4/app/Views/themes/vuexy/form/presupuestos/cliente/items/_disenioCubierta.php +++ b/ci4/app/Views/themes/vuexy/form/presupuestos/cliente/items/_disenioCubierta.php @@ -16,7 +16,7 @@
+ class="calcular-presupuesto d-flex flex-column align-items-center justify-content-center tipo-cubierta imagen-selector image-container"> " alt="TapaBlanda">
+ class="calcular-presupuesto d-flex flex-column align-items-center justify-content-center tipo-cubierta imagen-selector image-container"> " alt="TapaDura">
+ class="calcular-presupuesto d-flex flex-column align-items-center justify-content-center tipo-cubierta imagen-selector image-container"> " alt="TapaDuraLomoRedondo"> @@ -46,10 +46,27 @@
+
+ +
+ + +
+ +
+ +
+ class="calcular-presupuesto d-flex flex-column align-items-center justify-content-center solapas-cubierta imagen-selector image-container"> " alt="Sin solapas">
+ class="calcular-presupuesto d-flex flex-column align-items-center justify-content-center solapas-cubierta imagen-selector image-container"> " alt="Con solapas">
@@ -192,7 +209,7 @@ 300 gr + class="check-gramaje-cubierta calcular-presupuesto form-check-input" type="radio" value="300" />
@@ -207,7 +224,7 @@ 350 gr + class="check-gramaje-cubierta calcular-presupuesto form-check-input" type="radio" value="350" />
@@ -224,7 +241,7 @@
- +
@@ -243,7 +260,7 @@ @@ -257,7 +274,7 @@
-
+
" alt="Retractilado">
-
@@ -320,12 +337,12 @@
-
@@ -382,12 +399,12 @@
-