diff --git a/ci4/app/Config/Routes.php b/ci4/app/Config/Routes.php index 58673a18..77d018b3 100644 --- a/ci4/app/Config/Routes.php +++ b/ci4/app/Config/Routes.php @@ -681,6 +681,7 @@ $routes->group('importador', ['namespace' => 'App\Controllers\Presupuestos'], fu $routes->get('presupuestoslist', 'Importadorpresupuestos::getPresupuestosList', ['as' => 'presupuestosList']); $routes->get('getencuadernacion', 'Importadorpresupuestos::getEncuadernacionList'); $routes->get('getpresupuestodata', 'Importadorpresupuestos::getPresupuesto', ['as' => 'getPresupuesto']); + $routes->post('importar', 'Importadorpresupuestos::importarPresupuesto'); }); $routes->resource('presupuestocliente', ['namespace' => 'App\Controllers\Presupuestos', 'controller' => 'Presupuestocliente', 'except' => 'show,new,create,update']); diff --git a/ci4/app/Controllers/Presupuestos/Importadorpresupuestos.php b/ci4/app/Controllers/Presupuestos/Importadorpresupuestos.php index 48c594ee..42101624 100644 --- a/ci4/app/Controllers/Presupuestos/Importadorpresupuestos.php +++ b/ci4/app/Controllers/Presupuestos/Importadorpresupuestos.php @@ -183,7 +183,7 @@ class Importadorpresupuestos extends \App\Controllers\BaseResourceController 'ferro' => $data['datosGenerales']->ferro, 'ferroDigital' => $data['datosGenerales']->ferro_digital, 'marcapaginas' => $data['datosGenerales']->marcapaginas, - 'prototipo' => $data['datosGenerales']->prototipo + //'prototipo' => $data['datosGenerales']->prototipo ] ] @@ -422,4 +422,141 @@ class Importadorpresupuestos extends \App\Controllers\BaseResourceController ]; } + + public function importarPresupuesto(){ + + if($this->request->isAJAX()){ + + $presupuesto_id = $this->request->getPost('id'); + + $tipo_presupuesto_id = intval($this->request->getPost('encuadernacion') ?? 0); + + $papel_formato_id = $this->request->getPost('papel_formato_id'); + $papel_formato_personalizado = intval($this->request->getPost('papel_formato_personalizado') ?? 0); + $papel_formato_ancho = intval($this->request->getPost('papel_formato_ancho') ?? 0); + $papel_formato_alto = intval($this->request->getPost('papel_formato_alto') ?? 0); + + if($papel_formato_personalizado){ + $tamanio = array( + "ancho" => $papel_formato_ancho, + "alto" => $papel_formato_alto + ); + } + else{ + $medidas = model('App\Models\Configuracion\PapelFormatoModel')->select('ancho, alto')->where('id', $papel_formato_id)->first(); + $tamanio = array( + "ancho" => $medidas->ancho, + "alto" => $medidas->alto + ); + } + + $isHq = intval($this->request->getPost('isHq') ?? 0); + $paginas_bn = intval($this->request->getPost('paginas_bn') ?? 0); + $paginas_color = intval($this->request->getPost('paginas_color') ?? 0); + $gramaje_bn = intval($this->request->getPost('gramaje_bn') ?? 0); + $gramaje_color = intval($this->request->getPost('gramaje_color') ?? 0); + $papel_bn = intval($this->request->getPost('papel_bn') ?? 0); + $papel_color = intval($this->request->getPost('papel_color') ?? 0); + + $papel_interior_diferente = false; + if($papel_bn != $papel_color && $papel_bn != 0 && $papel_color != 0){ + $papel_interior_diferente = true; + $papel_interior = array( + "negro" => $papel_bn, + "color" => $papel_color + ); + $gramaje_interior = array( + "negro" => $gramaje_bn, + "color" => $gramaje_color + ); + } + else{ + $papel_interior = $papel_bn == 0 ? $papel_color : $papel_bn; + $gramaje_interior = $gramaje_bn == 0 ? $gramaje_color : $gramaje_bn; + } + + $interior = array( + "papelInterior" => $papel_interior, + "gramajeInterior" => $gramaje_interior + ); + + $isColor = false; + if(intval($paginas_color)>0){ + $isColor = true; + } + + $tapaCubierta = model('App\Models\Configuracion\TipoPresupuestoModel')-> + select("is_tapa_dura")->where('id', $tipo_presupuesto_id)->first(); + $tapaCubierta = $tapaCubierta->is_tapa_dura == 0 ? "tapaBlanda" : "tapaDura"; + $cubierta = array( + "carasImpresion" => intval($this->request->getPost('paginas_cubierta') ?? 0), + "tipoCubierta" => $tapaCubierta, + "papelCubierta" => intval($this->request->getPost('papel_cubierta') ?? 0), + "gramajeCubierta" => intval($this->request->getPost('gramaje_cubierta') ?? 0), + "acabado" => intval($this->request->getPost('acabado_cubierta') ?? 0), + ); + + $solapas_cubierta = intval($this->request->getPost('solapas_cubierta') ?? 0); + if($solapas_cubierta>0){ + $cubierta["solapas"] = 1; + $cubierta["tamanioSolapas"] = $solapas_cubierta; + } + else{ + $cubierta["solapas"] = 0; + } + + $sobrecubierta = intval($this->request->getPost('sobrecubierta') ?? 0); + if($sobrecubierta>0){ + $sobrecubierta = array( + "papel" => intval($this->request->getPost('papel_sobrecubierta') ?? 0), + "gramaje" => intval($this->request->getPost('gramaje_sobrecubierta') ?? 0), + "solapas" => intval($this->request->getPost('solapas_sobrecubierta') ?? 0), + "acabado" => intval($this->request->getPost('acabado_sobrecubierta') ?? 0), + ); + + // para corregir el fallo de un presupuesto sin solapas en sobrecubierta + if($sobrecubierta["solapas"] == 0){ + $sobrecubierta["solapas"] = 80; + } + } + else{ + $sobrecubierta = false; + } + + $datos = array( + "tirada" => array(intval($this->request->getPost('tirada') ?? 0)), + "paginas" => intval($this->request->getPost('paginas') ?? 0), + "tamanio" => $tamanio, + "tipo_presupuesto_id" => $tipo_presupuesto_id, + "clienteId" => intval($this->request->getPost('cliente_id') ?? 0), + "isColor" => $isColor, + "isHq" => $isHq, + "papelDiferente" => $papel_interior_diferente, + "paginasColor" => $paginas_color, + "paginasCuadernillo" => 32, + + "interior" => $interior, + + "cubierta" => $cubierta, + + "sobrecubierta" => $sobrecubierta, + "guardas" => false, + ); + + $value = (new Presupuestocliente())->calcular($datos); + + $returnData = [ + 'success' => true, + 'data' => $value + ]; + + return $this->response->setJSON($returnData); + + } + else{ + + return $this->failUnauthorized('Invalid request', 403); + } + } + } \ No newline at end of file diff --git a/ci4/app/Controllers/Presupuestos/Presupuestocliente.php b/ci4/app/Controllers/Presupuestos/Presupuestocliente.php index 5051af87..f594db7a 100755 --- a/ci4/app/Controllers/Presupuestos/Presupuestocliente.php +++ b/ci4/app/Controllers/Presupuestos/Presupuestocliente.php @@ -460,7 +460,7 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController $tamanio = $reqData['tamanio']; $paginas = $reqData['paginas'] ?? 0; $paginas_color = $reqData['paginasColor'] ?? 0; - $tipo = $reqData['tipo']; + $tipo = $reqData['tipo'] ?? 'cosido'; $paginasCuadernillo = $reqData['paginasCuadernillo'] ?? null; $papelInteriorDiferente = intval($reqData['papelInteriorDiferente'] ?? null); @@ -478,7 +478,8 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController $direcciones = $reqData['direcciones'] ?? []; - $tipo_impresion_id = $this->getTipoImpresion($tipo, $cubierta['tipoCubierta']); + $tipo_impresion_id = intval($reqData['tipo_presupuesto_id'] ?? 0) == 0? + $this->getTipoImpresion($tipo, $cubierta['tipoCubierta']) : intval($reqData['tipo_presupuesto_id']); $lomoRedondo = $cubierta['lomoRedondo'] ?? 0; if ($papelInteriorDiferente) { diff --git a/ci4/app/Views/themes/vuexy/form/presupuestos/importador/viewImportadorPresupuestos.php b/ci4/app/Views/themes/vuexy/form/presupuestos/importador/viewImportadorPresupuestos.php index 959fb31a..e00d8c92 100644 --- a/ci4/app/Views/themes/vuexy/form/presupuestos/importador/viewImportadorPresupuestos.php +++ b/ci4/app/Views/themes/vuexy/form/presupuestos/importador/viewImportadorPresupuestos.php @@ -368,27 +368,35 @@ - +
+
+ +
+
- + - + - - - + - endSection() ?> + + + + + endSection() ?> - section('css') ?> + section('css') ?> - endSection() ?> + endSection() ?> - section('additionalExternalJs') ?> - - endSection() ?> \ No newline at end of file + section('additionalExternalJs') ?> + + endSection() ?> \ No newline at end of file diff --git a/httpdocs/assets/js/safekat/pages/importadorPresupuestos/importador.js b/httpdocs/assets/js/safekat/pages/importadorPresupuestos/importador.js index ce098e26..49d42c94 100644 --- a/httpdocs/assets/js/safekat/pages/importadorPresupuestos/importador.js +++ b/httpdocs/assets/js/safekat/pages/importadorPresupuestos/importador.js @@ -73,6 +73,8 @@ class Importador { this.openBtn = $('#openOld'); this.initImport = $('#initImport'); + this.makeImport = $('#makeImport'); + } init() { @@ -120,8 +122,74 @@ class Importador { this.getPresupuestoData.bind(this)(); } }); + + this.makeImport.on('click', this.importPresupuesto.bind(this)); } + importPresupuesto(){ + + if ($("#clienteId").val() != '' && $("#presupuesto").val() != '') { + let data = this.collectData(); + new Ajax( + '/importador/importar', + data, + {}, + (response) => { + if (response.success) { + alert('Presupuesto importado correctamente'); + console.log(response); + } + }, + (error) => { + console.error(error); + } + ).post(); + } + + } + + collectData() { + + let data = {}; + + data.id = $("#presupuesto").val(); + data.cliente_id = $("#clienteId").val(); + + data.paginas = $('#paginas').val(); + data.tirada = $('#tirada').val(); + data.papel_formato_id = $('#tamanio').val(); + data.papel_formato_personalizado = $('#papelFormatoPersonalizado').prop('checked')?1:0; + data.papel_formato_ancho = $('#papelFormatoAncho').val(); + data.papel_formato_alto = $('#papelFormatoAlto').val(); + + data.encuadernacion = this.encuadernacion.getVal(); + data.isHq = $('#hq').val(); + + data.paginas_bn = $('#compPaginasNegro').val(); + data.papel_bn = this.compPapelNegroSelected.getVal(); + data.gramaje_bn = $('#compGramajeNegro').val(); + + data.paginas_color = $('#compPaginasColor').val(); + data.papel_color = this.compPapelColorSelected.getVal(); + data.gramaje_color = $('#compGramajeColor').val(); + + data.paginas_cubierta = $('#compCarasCubierta').val(); + data.papel_cubierta = this.compPapelCubiertaSelected.getVal(); + data.gramaje_cubierta = $('#compGramajeCubierta').val(); + data.solapas_cubierta = $('#compSolapasCubierta').val(); + data.acabado_cubierta = this.acabadoCubierta.getVal(); + + data.sobrecubierta = $('#compSobrecubierta').val(); + data.papel_sobrecubierta = this.compSobrecubiertaSelected.getVal(); + data.gramaje_sobrecubierta = $('#compGramajeSobrecubierta').val(); + data.solapas_sobrecubierta = $('#compSolapasSobrecubierta').val(); + data.acabado_sobrecubierta = this.acabadosSobrecubierta.getVal(); + + + return data; + } + + getPresupuestoData() {