From 44c5595173130d565494b36b5249b81198c3c0e1 Mon Sep 17 00:00:00 2001 From: jaimejimenezortega Date: Tue, 21 May 2024 20:43:47 +0200 Subject: [PATCH] terminado a falta del resumen --- .../Presupuestos/Presupuestocliente.php | 236 +- .../Clientes/ClienteDireccionesModel.php | 19 + .../Presupuestos/PresupuestoLineaModel.php | 2 +- .../Models/Presupuestos/PresupuestoModel.php | 18 +- .../cliente/_direccionesItems.php | 5 +- .../cliente/_disenioLibroItems.php | 30 +- .../presupuestos/cliente/_resumenItems.php | 10 +- .../form/presupuestos/cliente/direcciones.js | 51 +- .../form/presupuestos/cliente/resumen.js | 64 +- .../cliente/viewPresupuestoclienteForm.php | 23 +- xdebug.log | 38513 ++++++++++++++++ 11 files changed, 38841 insertions(+), 130 deletions(-) diff --git a/ci4/app/Controllers/Presupuestos/Presupuestocliente.php b/ci4/app/Controllers/Presupuestos/Presupuestocliente.php index e2c3b021..fcf345fe 100755 --- a/ci4/app/Controllers/Presupuestos/Presupuestocliente.php +++ b/ci4/app/Controllers/Presupuestos/Presupuestocliente.php @@ -158,7 +158,7 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController $datosPresupuesto->acabadosSobrecubierta = $this->getAcabadosSobrecubierta(); $datosPresupuesto->tipo_libro = $this->getTipoLibro($presupuestoEntity->tipo_impresion_id ?? null); - [$datosPresupuesto->color_impresion, $datosPresupuesto->calidad_impresion] = + [$datosPresupuesto->color_impresion, $datosPresupuesto->calidad_impresion] = $this->getTipoInterior($presupuestoEntity->id ?? null); $datosPresupuesto->tapa = $this->getTapa($presupuestoEntity->tipo_impresion_id ?? null); @@ -167,6 +167,7 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController $this->obtenerTiradas($presupuestoEntity); $this->obtenerDatosPapel($presupuestoEntity); $this->obtenerPaginasColor($presupuestoEntity); + $this->obtenerDireccionesEnvio($presupuestoEntity); $this->viewData['formAction'] = route_to('updateCosidotapablanda', $id); @@ -174,10 +175,10 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController $this->viewData['presupuestoEntity'] = $presupuestoEntity; $this->viewData['datosPresupuesto'] = $datosPresupuesto; - + // Si se ha llamado a esta funcion porque se ha duplicado el presupuesto // se actualiza la bbdd para que sólo ejecute algunas funciones una vez - if($presupuestoEntity->is_duplicado){ + if ($presupuestoEntity->is_duplicado) { $this->model->removeIsDuplicado($presupuestoEntity->id); } @@ -221,33 +222,7 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController } } - // Se borran las lineas de presupuesto - $model = new PresupuestoLineaModel(); - $model->where("presupuesto_id", $id)->delete(); - - // Se borran las direcciones de presupuesto - $model = new PresupuestoDireccionesModel(); - $model->where("presupuesto_id", $id)->delete(); - - // Se borran los servicios de acabado - $model = new PresupuestoAcabadosModel(); - $model->where("presupuesto_id", $id)->delete(); - - // Se borran los servicios de preimpresion - $model = new PresupuestoPreimpresionesModel(); - $model->where("presupuesto_id", $id)->delete(); - - // Se borran los servicios de encuadernacion - $model = new PresupuestoEncuadernacionesModel(); - $model->where("presupuesto_id", $id)->delete(); - - // Se borran los servicios de manipulado - $model = new PresupuestoManipuladosModel(); - $model->where("presupuesto_id", $id)->delete(); - - // Se borran los servicios extra - $model = new PresupuestoServiciosExtraModel(); - $model->where("presupuesto_id", $id)->delete(); + $this->borrarRelacionesPresupuesto($id); // $message = lang('Basic.global.deleteSuccess', [$objName]); IMN commented $message = lang('Basic.global.deleteSuccess', [lang('Basic.global.record')]); @@ -255,6 +230,7 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController return $response; } + public function getGramaje() { if ($this->request->isAJAX()) { @@ -373,7 +349,7 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController $sobreCubierta = $reqData["sobrecubierta"] ?? null; // Guardas - $datos_guardas = $reqData['guardas'] ?? 0; + $datos_guardas = $reqData['guardas'] ?? []; $servicios = $reqData['servicios'] ?? []; @@ -508,6 +484,9 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController $confirmar = $reqData['confirmar'] ?? 0; + $id = $reqData['id'] ?? 0; + $id = intval($id); + $datosCabecera = $reqData['datos_cabecera'] ?? []; $tirada = $reqData['datos_libro']['tirada'] ?? 0; @@ -604,12 +583,22 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController $proporcion = intval($direccion['unidades']) / $selected_tirada * 100.0; $unidades_calculo = floor($tirada[$i] * $proporcion / 100.0); - $coste_envio = $this->calcular_coste_envio( - $direccion['id'], - $peso_libro, - $unidades_calculo, - $direccion['tipo'] == 'cajas' ? 0 : 1 - ); + try{ + $coste_envio = $this->calcular_coste_envio( + $direccion['id'], + $peso_libro, + $unidades_calculo, + $direccion['tipo'] == 'cajas' ? 0 : 1 + ); + } + catch(Exception $e){ + return $this->respond([ + 'status' => -1, + 'message' => "Error al calcular el coste de envío (¿las direcciones están guardadas?)", + $csrfTokenName => $newTokenHash + ]); + } + if (count($coste_envio) > 0) { $coste = floatval($coste_envio[0]->coste); $margen = ($coste * floatval($coste_envio[0]->margen)) / 100.0; @@ -648,7 +637,13 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController } } + $borrar_antes = false; + if ($id != 0) { + $borrar_antes = true; + } + $id = $model_presupuesto->insertarPresupuestoCliente( + $id, $selected_tirada, $datos_presupuesto, $datosCabecera, @@ -660,6 +655,10 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController ); // Lineas Presupuesto + if ($borrar_antes && $id > 0) { + $this->borrarRelacionesPresupuesto($id); + } + foreach ($resultado_presupuesto['info']['interior'] as $linea) { if (count($linea) > 0) @@ -693,7 +692,7 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController $this->guardarLineaEnvio($id, $direccion, $peso_libro); } - if($confirmar == 1){ + if ($confirmar) { $model_presupuesto->confirmarPresupuesto($id); } @@ -714,6 +713,37 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController * Funciones auxiliares * **********************/ + protected function borrarRelacionesPresupuesto($id) + { + // Se borran las lineas de presupuesto + $model = new PresupuestoLineaModel(); + $model->where("presupuesto_id", $id)->delete(); + + // Se borran las direcciones de presupuesto + $model = new PresupuestoDireccionesModel(); + $model->where("presupuesto_id", $id)->delete(); + + // Se borran los servicios de acabado + $model = new PresupuestoAcabadosModel(); + $model->where("presupuesto_id", $id)->delete(); + + // Se borran los servicios de preimpresion + $model = new PresupuestoPreimpresionesModel(); + $model->where("presupuesto_id", $id)->delete(); + + // Se borran los servicios de encuadernacion + $model = new PresupuestoEncuadernacionesModel(); + $model->where("presupuesto_id", $id)->delete(); + + // Se borran los servicios de manipulado + $model = new PresupuestoManipuladosModel(); + $model->where("presupuesto_id", $id)->delete(); + + // Se borran los servicios extra + $model = new PresupuestoServiciosExtraModel(); + $model->where("presupuesto_id", $id)->delete(); + } + protected function guardarLineaPresupuesto($presupuestoId, $linea) { @@ -885,7 +915,7 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController $sobreCubierta = $datos_entrada["sobrecubierta"] ?? null; // Guardas - $datos_guardas = $datos_entrada['guardas'] ?? []; + $datos_guardas = $datos_entrada['datos_guardas'] ?? []; // Servicios $servicios = $datos_entrada['servicios'] ?? []; @@ -1086,11 +1116,11 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController $lomo_sobrecubierta = 0.0; if (!is_null($sobreCubierta)) { - $papel_generico = [ + $papel_generico_sobrecubierta = [ 'id' => $sobreCubierta['papel'] ?? 0, 'nombre' => $sobreCubierta['papel_nombre'] ?? "", ]; - $input_data['papel_generico'] = $papel_generico; + $input_data['papel_generico'] = $papel_generico_sobrecubierta; $input_data['gramaje'] = $sobreCubierta['gramaje'] ?? 0; $input_data['datosPedido']->paginas = 4; $input_data['paginas_color'] = 4; @@ -1146,11 +1176,11 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController if (count($datos_guardas) != 0) { $guardas = $datos_guardas; - $papel_generico = [ + $papel_generico_guardas = [ 'id' => $datos_guardas['papel'] ?? 0, 'nombre' => $datos_guardas['nombre'] ?? "", ]; - $input_data['papel_generico'] = $papel_generico; + $input_data['papel_generico'] = $papel_generico_guardas; $input_data['gramaje'] = $datos_guardas['gramaje'] ?? 0; $input_data['datosPedido']->paginas = 8; $input_data['paginas_color'] = 8; @@ -1323,7 +1353,7 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController )); } - if ($extra_info){// && $tirada[$t] == $selected_tirada) { + if ($extra_info) { // && $tirada[$t] == $selected_tirada) { $info['lomo_cubierta'] = $lomo; $info['lomo_sobrecubierta'] = $lomo_sobrecubierta; @@ -1375,7 +1405,7 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController if ($linea['tipo_maquina'] == 'inkjet') { $totalImpresion += $linea['precio_tinta']; - if(array_key_exists('total_corte', $linea)){ + if (array_key_exists('total_corte', $linea)) { $totalImpresion += $linea['total_corte']; $sumForFactor += $linea['total_corte']; } @@ -1503,120 +1533,148 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController return $data; } - - protected function getTipoLibro($tipo_impresion_id){ - if($tipo_impresion_id == 1 || $tipo_impresion_id == 2){ + + protected function getTipoLibro($tipo_impresion_id) + { + if ($tipo_impresion_id == 1 || $tipo_impresion_id == 2) { return 'fresado'; - } - else if ($tipo_impresion_id == 3 || $tipo_impresion_id == 4){ + } else if ($tipo_impresion_id == 3 || $tipo_impresion_id == 4) { return 'cosido'; - } - else if ($tipo_impresion_id == 5 || $tipo_impresion_id == 6){ + } else if ($tipo_impresion_id == 5 || $tipo_impresion_id == 6) { return 'espiral'; - } - else if ($tipo_impresion_id == 7 || $tipo_impresion_id == 8){ + } else if ($tipo_impresion_id == 7 || $tipo_impresion_id == 8) { return 'wireo'; - } - else if ($tipo_impresion_id == 21){ + } else if ($tipo_impresion_id == 21) { return 'grapado'; - } - else + } else return ''; } - protected function getTipoInterior($presupuestoId){ + protected function getTipoInterior($presupuestoId) + { $calidad = 'estandar'; $color = 'negro'; $model = model('App\Models\Presupuestos\PresupuestoLineaModel'); $data = $model->where('presupuesto_id', $presupuestoId)->findAll();; - foreach($data as $linea){ + foreach ($data as $linea) { if (strpos($linea->tipo, "hq") !== false) { // $linea->tipo contains the substring "hq" - $calidad='premium'; + $calidad = 'premium'; } if (strpos($linea->tipo, "color") !== false) { // $linea->tipo contains the substring "color" - $color='color'; + $color = 'color'; } } return [$color, $calidad]; - } - - protected function getTapa($tipo_impresion_id ){ - + + protected function getTapa($tipo_impresion_id) + { + $tapa = 'blanda'; - if($tipo_impresion_id == 1 || $tipo_impresion_id == 3 || - $tipo_impresion_id == 5 || $tipo_impresion_id == 7) + if ( + $tipo_impresion_id == 1 || $tipo_impresion_id == 3 || + $tipo_impresion_id == 5 || $tipo_impresion_id == 7 + ) $tapa = 'dura'; - - return $tapa; + return $tapa; } - protected function obtenerPaginasColor($presupuestoEntity){ + protected function obtenerPaginasColor($presupuestoEntity) + { $comparador_data = json_decode($presupuestoEntity->comparador_json_data); - if(property_exists($comparador_data, 'color')){ + if (property_exists($comparador_data, 'color')) { $presupuestoEntity->paginasColor = $comparador_data->color->paginas; } - if(property_exists($comparador_data, 'colorhq')){ + if (property_exists($comparador_data, 'colorhq')) { $presupuestoEntity->paginasColor = $comparador_data->colorhq->paginas; - } - else{ + } else { $presupuestoEntity->paginasColor = 0; } } - protected function obtenerTiradas($presupuestoEntity){ + protected function obtenerTiradas($presupuestoEntity) + { $tiradas_alternativas = json_decode($presupuestoEntity->tirada_alternativa_json_data, true); $tiradas = array(); array_push($tiradas, $presupuestoEntity->tirada); - if(!is_null($tiradas_alternativas)){ - if(count($tiradas_alternativas) > 0){ - foreach($tiradas_alternativas as $tirada){ + if (!is_null($tiradas_alternativas)) { + if (count($tiradas_alternativas) > 0) { + foreach ($tiradas_alternativas as $tirada) { array_push($tiradas, intval($tirada['tirada'])); } } } sort($tiradas); $presupuestoEntity->selected_tirada = $presupuestoEntity->tirada; - for($i=0; $i$key = $tiradas[$i]; } } - protected function obtenerDatosPapel($presupuestoEntity){ + protected function obtenerDireccionesEnvio($presupuestoEntity) + { + $model = model('App\Models\Presupuestos\PresupuestoDireccionesModel'); + $model_direcciones = model('App\Models\Clientes\ClienteDireccionesModel'); + $direcciones = $model->where('presupuesto_id', $presupuestoEntity->id)->findAll(); + + $result = []; + $temp = []; + for ($i=0; $igetIdForPresupuestoCliente( + $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) { + $temp = $direcciones[$i]->toArray(); + $temp['direccion_id'] = $direccion_id[0]->id; + array_push($result, $temp); + } + } + if(count($result) > 0) + $presupuestoEntity->direcciones_envio = $result; + } + + protected function obtenerDatosPapel($presupuestoEntity) + { $id = $presupuestoEntity->id; $model = model('App\Models\Presupuestos\PresupuestoLineaModel'); $data = $model->where('presupuesto_id', $id)->findAll(); - if(count($data)>0){ - foreach($data as $linea){ + if (count($data) > 0) { + foreach ($data as $linea) { // Se coje el primer papel que se encuentre para el interior // para presupuestos del cliente sólo se escoje un papel para el interior - if (strpos($linea->tipo, "bn") !== false || strpos($linea->tipo, "color") !== false) { + if (strpos($linea->tipo, "bn") !== false || strpos($linea->tipo, "color") !== false) { $presupuestoEntity->papel_interior = $linea->papel_id; $presupuestoEntity->gramaje_interior = $linea->gramaje; } // Si es cubierta - else if (strpos($linea->tipo, "cubierta") !== false && strpos($linea->tipo, "sobrecubierta") === false) { + else if (strpos($linea->tipo, "cubierta") !== false && strpos($linea->tipo, "sobrecubierta") === false) { $presupuestoEntity->papel_cubierta = $linea->papel_id; $presupuestoEntity->gramaje_cubierta = $linea->gramaje; $presupuestoEntity->paginas_cubierta = $linea->paginas; } // Si es sobrecubierta - else if (strpos($linea->tipo, "sobrecubierta") !== false) { + else if (strpos($linea->tipo, "sobrecubierta") !== false) { $presupuestoEntity->papel_sobrecubierta = $linea->papel_id; $presupuestoEntity->gramaje_sobrecubierta = $linea->gramaje; $presupuestoEntity->paginas_sobrecubierta = $linea->paginas; } // Si es guardas - else if (strpos($linea->tipo, "guardas") !== false) { - $presupuestoEntity->papel_guardas = $linea->papel_id;; + else if (strpos($linea->tipo, "guardas") !== false) { + $presupuestoEntity->papel_guardas = $linea->papel_id; + $presupuestoEntity->paginas_guardas = $linea->paginas; } } } diff --git a/ci4/app/Models/Clientes/ClienteDireccionesModel.php b/ci4/app/Models/Clientes/ClienteDireccionesModel.php index 09d8f385..5ea8db63 100755 --- a/ci4/app/Models/Clientes/ClienteDireccionesModel.php +++ b/ci4/app/Models/Clientes/ClienteDireccionesModel.php @@ -141,6 +141,25 @@ class ClienteDireccionesModel extends \App\Models\BaseModel return $builder->get()->getResultObject(); } + + public function getIdForPresupuestoCliente($cliente_id = -1, $att = "", $email = "", $direccion = "", $cp = "", $pais_id = -1, $telefono = "") + { + $builder = $this->db + ->table($this->table . " t1") + ->select("t1.id AS id") + ->where("t1.cliente_id", $cliente_id) + ->where("t1.att", $att) + ->where("t1.email", $email) + ->where("t1.direccion", $direccion) + ->where("t1.cp", $cp) + ->where("t1.pais_id", $pais_id) + ->where("t1.telefono", $telefono) + ->limit(1); + + + return $builder->get()->getResultObject(); + } + public function getMenuDirecciones($cliente_id=-1){ diff --git a/ci4/app/Models/Presupuestos/PresupuestoLineaModel.php b/ci4/app/Models/Presupuestos/PresupuestoLineaModel.php index 92b36152..6a34a602 100755 --- a/ci4/app/Models/Presupuestos/PresupuestoLineaModel.php +++ b/ci4/app/Models/Presupuestos/PresupuestoLineaModel.php @@ -521,7 +521,7 @@ class PresupuestoLineaModel extends \App\Models\BaseModel } if($new_linea['tipo_linea'] =='lp_guardas') - array_push($data, ['paginas_impresion' => $new_linea['paginas_impresion']]); + $data = array_merge($data, ['paginas_impresion' => $new_linea['paginas_impresion']]); return $this->db ->table($this->table . " t1") diff --git a/ci4/app/Models/Presupuestos/PresupuestoModel.php b/ci4/app/Models/Presupuestos/PresupuestoModel.php index c6f0bf8b..4a2ee863 100755 --- a/ci4/app/Models/Presupuestos/PresupuestoModel.php +++ b/ci4/app/Models/Presupuestos/PresupuestoModel.php @@ -372,11 +372,11 @@ class PresupuestoModel extends \App\Models\BaseModel $this->db ->table($this->table . " t1") ->where('t1.id', $presupuesto_id) - ->set('t1.estado', 2) + ->set('t1.estado_id', 2) ->update(); } - function insertarPresupuestoCliente($tirada, $data, $data_cabecera, $extra_info, $resumen_totales, $iva_reducido, $excluir_rotativa, $tiradas_alternativas) + function insertarPresupuestoCliente($id, $tirada, $data, $data_cabecera, $extra_info, $resumen_totales, $iva_reducido, $excluir_rotativa, $tiradas_alternativas) { helper('date'); @@ -462,9 +462,19 @@ class PresupuestoModel extends \App\Models\BaseModel 'excluir_rotativa' => $excluir_rotativa, ]; + if($id != 0){ + $fields['id'] = $id; + $fields['updated_at'] = date('Y-m-d H:i:s', now()); + } - $this->db->table($this->table)->insert($fields); - return $this->db->insertID(); + if($id != 0){ + $this->db->table($this->table)->where('id', $id)->update($fields); + return $id; + } + else{ + $this->db->table($this->table)->insert($fields); + return $this->db->insertID(); + } } private function generateJson($data) diff --git a/ci4/app/Views/themes/vuexy/form/presupuestos/cliente/_direccionesItems.php b/ci4/app/Views/themes/vuexy/form/presupuestos/cliente/_direccionesItems.php index 149ff801..eb4fe1d7 100644 --- a/ci4/app/Views/themes/vuexy/form/presupuestos/cliente/_direccionesItems.php +++ b/ci4/app/Views/themes/vuexy/form/presupuestos/cliente/_direccionesItems.php @@ -32,13 +32,14 @@
- - +
section("additionalInlineJs") ?> +window.direcciones = direcciones_envio) ?>; +window.direcciones_sel_tirada = selected_tirada) ?>; window.routes_direcciones = { direcciones: "", getDatos: "", diff --git a/ci4/app/Views/themes/vuexy/form/presupuestos/cliente/_disenioLibroItems.php b/ci4/app/Views/themes/vuexy/form/presupuestos/cliente/_disenioLibroItems.php index 3cb225c2..b54582ff 100644 --- a/ci4/app/Views/themes/vuexy/form/presupuestos/cliente/_disenioLibroItems.php +++ b/ci4/app/Views/themes/vuexy/form/presupuestos/cliente/_disenioLibroItems.php @@ -374,7 +374,7 @@
papel_sobrecubierta) && is_array($datosPresupuesto->papel_sobrecubierta) && !empty($datosPresupuesto->papel_sobrecubierta)) : + papel_sobrecubierta) && $presupuestoEntity->papel_sobrecubierta>0) : echo 'checked'; endif; ?> > @@ -384,7 +384,7 @@
papel_sobrecubierta) && is_array($datosPresupuesto->papel_sobrecubierta) && !empty($datosPresupuesto->papel_sobrecubierta)) : + papel_sobrecubierta) && $presupuestoEntity->papel_sobrecubierta>0) : echo ''; else: echo 'style="display: none;"'; @@ -414,14 +414,20 @@
papel_sobrecubierta) && is_array($datosPresupuesto->papel_sobrecubierta) && !empty($datosPresupuesto->papel_sobrecubierta)) : + papel_sobrecubierta) && $presupuestoEntity->papel_sobrecubierta>0) : echo ''; else: echo 'style="display: none;"'; endif; ?> > Opciones extra
-