From e5389db7be4df6b208beab43a2c661a170060c0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaime=20Jim=C3=A9nez?= Date: Fri, 30 May 2025 11:31:53 +0200 Subject: [PATCH 01/10] cuando la tirada es 1 la merma es 0 --- ci4/app/Services/PresupuestoService.php | 5 ++++- .../safekat/pages/presupuestoAdmin/presupuestoAdminAdd.js | 7 ++++++- .../safekat/pages/presupuestoAdmin/sections/datosLibro.js | 5 ++++- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/ci4/app/Services/PresupuestoService.php b/ci4/app/Services/PresupuestoService.php index e23ca530..908999ad 100755 --- a/ci4/app/Services/PresupuestoService.php +++ b/ci4/app/Services/PresupuestoService.php @@ -2077,7 +2077,10 @@ class PresupuestoService extends BaseService $merma = 0; - if ($tirada > $POD) { + if ($tirada == 0) { + $merma = 0; + } + else if ($tirada > $POD) { $merma = $tirada * 0.1; } else { $merma_lineas = []; diff --git a/httpdocs/assets/js/safekat/pages/presupuestoAdmin/presupuestoAdminAdd.js b/httpdocs/assets/js/safekat/pages/presupuestoAdmin/presupuestoAdminAdd.js index 5d4e7b9f..135d0d4f 100644 --- a/httpdocs/assets/js/safekat/pages/presupuestoAdmin/presupuestoAdminAdd.js +++ b/httpdocs/assets/js/safekat/pages/presupuestoAdmin/presupuestoAdminAdd.js @@ -162,7 +162,12 @@ class PresupuestoAdminAdd { const POD = parseInt($('#POD').val()); let merma = 0; - merma = tirada * 0.1 <= POD ? tirada * 0.1 : POD; + if (tirada == 1) { + merma = 0; + } + else if (tirada > POD) { + merma = tirada * 0.1 <= POD ? tirada * 0.1 : POD; + } $('#mermacubierta').val(parseInt(merma)) $('#merma').val(parseInt(merma)) diff --git a/httpdocs/assets/js/safekat/pages/presupuestoAdmin/sections/datosLibro.js b/httpdocs/assets/js/safekat/pages/presupuestoAdmin/sections/datosLibro.js index 8c34316d..5c52998e 100644 --- a/httpdocs/assets/js/safekat/pages/presupuestoAdmin/sections/datosLibro.js +++ b/httpdocs/assets/js/safekat/pages/presupuestoAdmin/sections/datosLibro.js @@ -623,7 +623,10 @@ class DatosLibro { let merma = 0; let htmlString = ''; - if (tirada > POD) { + if (tirada == 1) { + merma = 0; + } + else if (tirada > POD) { merma = tirada * 0.1 <= POD ? tirada * 0.1 : POD; } else { From 52c53e6920ff40bd0c995d39183013a91afa217a Mon Sep 17 00:00:00 2001 From: amazuecos Date: Fri, 30 May 2025 11:45:48 +0200 Subject: [PATCH 02/10] feat: add filter maquina plana --- ci4/app/Config/Routes.php | 1 + .../Controllers/Produccion/Ordentrabajo.php | 9 ++ ci4/app/Language/es/Produccion.php | 4 +- ci4/app/Services/ProductionService.php | 29 ++++- .../tables/planning_maquina_table.php | 28 +++++ .../produccion/ot/viewPlanningRotativa.php | 7 +- .../planning_rotativa/planning_rotativa.js | 117 +++++++++++++----- 7 files changed, 159 insertions(+), 36 deletions(-) create mode 100755 ci4/app/Views/themes/vuexy/components/tables/planning_maquina_table.php diff --git a/ci4/app/Config/Routes.php b/ci4/app/Config/Routes.php index 0278a980..2b8b0b45 100755 --- a/ci4/app/Config/Routes.php +++ b/ci4/app/Config/Routes.php @@ -822,6 +822,7 @@ $routes->group('produccion', ['namespace' => 'App\Controllers\Produccion'], func $routes->get('rotativa', 'Ordentrabajo::index_planning_rotativa'); $routes->get('papel/datatable', 'Ordentrabajo::papel_gramaje_datatable'); $routes->get('papel/plana/datatable', 'Ordentrabajo::papel_pliego_datatable'); + $routes->get('maquina/plana/datatable', 'Ordentrabajo::maquina_plana_datatable'); $routes->get('rotativa/datatable', 'Ordentrabajo::planning_rotativa_datatable'); $routes->get('plana/datatable', 'Ordentrabajo::planning_plana_datatable'); $routes->post('tarea/toggle/corte/(:num)', 'Ordentrabajo::tarea_toggle_corte/$1'); diff --git a/ci4/app/Controllers/Produccion/Ordentrabajo.php b/ci4/app/Controllers/Produccion/Ordentrabajo.php index ce6dacdd..43194ba9 100755 --- a/ci4/app/Controllers/Produccion/Ordentrabajo.php +++ b/ci4/app/Controllers/Produccion/Ordentrabajo.php @@ -372,6 +372,15 @@ class Ordentrabajo extends BaseController ->add("action", fn($q) => ["title" => lang('Produccion.datatable.filter_by_paper'), 'data' => $q]) ->toJson(true); } + public function maquina_plana_datatable() + { + // return $this->response->setStatusCode(400); + $q = $this->produccionService->maquinaPlanaDatatableQuery(); + return DataTable::of($q) + ->edit("tiempoReal", fn($q) => $q->tiempoReal) + ->add("action", fn($q) => ["title" => lang('Produccion.datatable.filter_by_machine'), 'data' => $q]) + ->toJson(true); + } public function reset_tareas(int $orden_trabajo_id) { $r = $this->produccionService->init($orden_trabajo_id)->resetAllTareas(); diff --git a/ci4/app/Language/es/Produccion.php b/ci4/app/Language/es/Produccion.php index a7907544..9552d726 100755 --- a/ci4/app/Language/es/Produccion.php +++ b/ci4/app/Language/es/Produccion.php @@ -13,6 +13,7 @@ return [ 'prod' => 'Producción' ], "datatable" => [ + "nombre" => "Nombre", "ot_id" => "OT ID", "barcode" => "Código", "pedido_id" => "Pedido ID", @@ -38,6 +39,7 @@ return [ "progreso" => "Progreso", "logo" => "Logo impresion", "filter_by_task" => "Filtrar por tarea", + "filter_by_machine" => "Filtrar por máquina", "filter_by_paper" => "Filtrar por papel", "metros" => "Metros", "corte" => "Corte", @@ -141,7 +143,7 @@ return [ "attr_not_exist" => "El atributo {0,string} no pertenece al modelo Pedido" ], - + "maquinas_planas" => "Máquinas planas", "progress_ferro" => "Ferro", "progress_preimpresion" => "Preimpresión", "progress_logistica" => "Logística", diff --git a/ci4/app/Services/ProductionService.php b/ci4/app/Services/ProductionService.php index 18e769df..ba3be5b5 100755 --- a/ci4/app/Services/ProductionService.php +++ b/ci4/app/Services/ProductionService.php @@ -913,6 +913,29 @@ class ProductionService extends BaseService + return $q; + } + public function maquinaPlanaDatatableQuery() + { + $q = $this->otModel->builder()->select([ + "lg_maquinas.nombre as maquinaNombre", + "lg_maquinas.id as maquinaId", + "COUNT(orden_trabajo_tareas.id) as tareasCount", + "presupuesto_linea.pliegos_pedido as pliegosPedido", + "SUM(ordenes_trabajo.total_tirada) as totalTirada", + "SUM(orden_trabajo_tareas.tiempo_real) as tiempoReal" + ]) + ->join("orden_trabajo_tareas", "orden_trabajo_tareas.orden_trabajo_id = ordenes_trabajo.id", "left") + ->join("presupuesto_linea", "presupuesto_linea.id = orden_trabajo_tareas.presupuesto_linea_id", "left") + ->join("presupuestos", "presupuestos.id = presupuesto_linea.presupuesto_id", "right") + ->join('lg_maquinas',"lg_maquinas.id = orden_trabajo_tareas.maquina_id","left") + ->where("orden_trabajo_tareas.deleted_at", null) + ->where("orden_trabajo_tareas.presupuesto_linea_id IS NOT NULL", NULL, FALSE) + ->whereIn("presupuesto_linea.tipo", $this->TIPOS_PLANA) + ->groupBy('lg_maquinas.id'); + + + return $q; } /** @@ -1323,7 +1346,8 @@ class ProductionService extends BaseService ->whereIn("presupuesto_linea.tipo", $this->TIPOS_ROTATIVA) ->where('lg_maquinas.is_rotativa', true) ->where("orden_trabajo_tareas.deleted_at", null) - ->orderBy("orden_trabajo_tareas.orden", "ASC"); + ->orderBy("orden_trabajo_tareas.orden", "ASC") + ->groupBy('lg_maquinas.id'); if ($q) { $query->like('lg_maquinas.nombre', $q); } @@ -1341,7 +1365,8 @@ class ProductionService extends BaseService ->whereIn("presupuesto_linea.tipo", $this->TIPOS_PLANA) ->where('lg_maquinas.is_rotativa', false) ->where("orden_trabajo_tareas.deleted_at", null) - ->orderBy("orden_trabajo_tareas.orden", "ASC"); + ->orderBy("orden_trabajo_tareas.orden", "ASC") + ->groupBy('lg_maquinas.id'); if ($q) { $query->like('lg_maquinas.nombre', $q); } diff --git a/ci4/app/Views/themes/vuexy/components/tables/planning_maquina_table.php b/ci4/app/Views/themes/vuexy/components/tables/planning_maquina_table.php new file mode 100755 index 00000000..ef47fd01 --- /dev/null +++ b/ci4/app/Views/themes/vuexy/components/tables/planning_maquina_table.php @@ -0,0 +1,28 @@ +
+ + + + + + + + + + + + + + + + + + + + + + + + + +
(HH:MM)
Total:
+
\ No newline at end of file diff --git a/ci4/app/Views/themes/vuexy/form/produccion/ot/viewPlanningRotativa.php b/ci4/app/Views/themes/vuexy/form/produccion/ot/viewPlanningRotativa.php index 2c5f572c..29d216ab 100755 --- a/ci4/app/Views/themes/vuexy/form/produccion/ot/viewPlanningRotativa.php +++ b/ci4/app/Views/themes/vuexy/form/produccion/ot/viewPlanningRotativa.php @@ -76,14 +76,17 @@
- "planning-pliego-datatable"]) ?> +
+ "planning-pliego-datatable"]) ?> +
+ "planning-maquina-datatable"]) ?>
diff --git a/httpdocs/assets/js/safekat/pages/produccion/planning_rotativa/planning_rotativa.js b/httpdocs/assets/js/safekat/pages/produccion/planning_rotativa/planning_rotativa.js index eddacb06..ede9535b 100644 --- a/httpdocs/assets/js/safekat/pages/produccion/planning_rotativa/planning_rotativa.js +++ b/httpdocs/assets/js/safekat/pages/produccion/planning_rotativa/planning_rotativa.js @@ -10,6 +10,7 @@ class PlanningRotativa { this.tablePlanningPlana = this.item.find("#planning-plana-datatable") this.papelGramajeTablePlanning = this.item.find("#planning-papel-datatable") this.papelPliegoTablePlanning = this.item.find("#planning-pliego-datatable") + this.maquinaTablePlanning = this.item.find("#planning-maquina-datatable") this.papelImpresionHeader = this.item.find('#papel-impresion-name-header') this.papelImpresionPlanaHeader = this.item.find('#papel-impresion-name-plana-header') @@ -27,7 +28,7 @@ class PlanningRotativa { { data: 'papel_ancho', searchable: false, sortable: false, width: "5rem", render: d => `${d}` }, { data: 'papel_alto', searchable: false, sortable: false, width: "5rem", render: d => `${d}` }, { data: 'papel_impresion', searchable: false, sortable: false }, - { data: 'papel_gramaje',name:"presupuesto_linea.gramaje", searchable: false, sortable: false, width: "5rem", render: d => `${d}` }, + { data: 'papel_gramaje', name: "presupuesto_linea.gramaje", searchable: false, sortable: false, width: "5rem", render: d => `${d}` }, { data: 'corte', searchable: false, sortable: false, render: this.renderCorteImage.bind(this), width: "10rem" }, { data: 'metros_check', searchable: false, sortable: false, render: d => `` }, { data: 'metros', searchable: false, sortable: false, render: d => `${d}` }, @@ -44,10 +45,10 @@ class PlanningRotativa { { data: 'papel_ancho', searchable: false, sortable: false, width: "5rem", render: d => `${d}` }, { data: 'papel_alto', searchable: false, sortable: false, width: "5rem", render: d => `${d}` }, { data: 'papel_impresion', searchable: false, sortable: false }, - { data: 'papel_gramaje', name:"presupuesto_linea.gramaje", searchable: false, sortable: false, width: "5rem", render: d => `${d}` }, + { data: 'papel_gramaje', name: "presupuesto_linea.gramaje", searchable: false, sortable: false, width: "5rem", render: d => `${d}` }, { data: 'pliegos_check', searchable: false, sortable: false, render: d => `` }, { data: 'pliegosPedido', searchable: false, sortable: false, render: d => `${d}` }, - { data: 'tiempo_real_sum', searchable: false, sortable: false,render: d => this.formatSeconds(parseFloat(d))}, + { data: 'tiempo_real_sum', searchable: false, sortable: false, render: d => this.formatSeconds(parseFloat(d)) }, { data: 'action', searchable: false, sortable: false, render: this._renderBtnAction }, ] @@ -65,6 +66,20 @@ class PlanningRotativa { }, + ] + this.maquinaPlanaDatatableColumns = [ + { data: 'maquinaNombre', searchable: true, sortable: true }, + { data: 'tareasCount', searchable: true, sortable: true }, + { data: 'totalTirada', searchable: false, sortable: false }, + { data: 'pliegosPedido', searchable: false, sortable: false, render: d => `${d}` }, + { data: 'tiempoReal', searchable: false, sortable: false, render: d => this.formatSeconds(d) }, + { + data: 'action', searchable: false, sortable: false, render: (d) => { + return `` + } + }, + + ] this.papelPliegoDatatableColumns = [ { data: 'papelImpresionNombre', searchable: true, sortable: true }, @@ -86,8 +101,8 @@ class PlanningRotativa { `/produccion/ordentrabajo/planning/select/maquina/rotativa`, "Seleccione una maquina", true, { - dropdownCssClass: "h-2" - }, $('body')); + dropdownCssClass: "h-2" + }, $('body')); this.papelImpresionFilter = new ClassSelect(this.tablePlanningRot.find(".planning-papel-select"), `/produccion/ordentrabajo/planning/select/papel/rotativa`, "Seleccione un papel", true, {}, $('body')); this.maquinaSelectFilterPlana = new ClassSelect(this.tablePlanningPlana.find(".planning-maquina-select"), `/produccion/ordentrabajo/planning/select/maquina/plana`, "Seleccione una maquina", true, {}, $('body')); this.maquinaPadreSelectFilterPlana = new ClassSelect(this.tablePlanningPlana.find(".planning-maquina-padre-select"), `/produccion/ordentrabajo/planning/select/maquina/padre/plana`, "Máquina padre", true, {}, $('body')); @@ -116,6 +131,7 @@ class PlanningRotativa { this.totalMetros = new AutoNumeric(this.item.find('#total-metros')[0], autoNumericOptions); this.totalMetrosSel = new AutoNumeric(this.item.find('#metros-sel-total')[0], autoNumericOptions); this.totalPliegos = new AutoNumeric(this.item.find('#total-pliegos')[0], autoNumericPliegosOptions); + this.totalMaquinaPliegos = new AutoNumeric(this.item.find('#total-pliegos-maquina')[0], autoNumericPliegosOptions); this.totalPliegosSel = new AutoNumeric(this.item.find('#pliegos-sel-total')[0], autoNumericPliegosOptions); this.maquinaSelectFilter.init() @@ -133,7 +149,8 @@ class PlanningRotativa { }) this.papelGramajeTablePlanning.on('click', '.papel-gramaje-btn', this.filterPapelGramaje.bind(this)) this.papelPliegoTablePlanning.on('click', '.papel-pliego-btn', this.filterPapelGramajePlana.bind(this)) - + this.maquinaTablePlanning.on('click', '.maquina-planning-btn', this.filterMaquinaPlana.bind(this)) + //!AÑADIR MAQUINA this.papelImpresionFilter.onChange(() => { this.papelImpresionHeader.text(this.papelImpresionFilter.getText()) }) @@ -151,8 +168,8 @@ class PlanningRotativa { language: { url: "/themes/vuexy/vendor/libs/datatables-sk/plugins/i18n/es-ES.json" }, - createdRow: (row,data,dataIndex) => { - this.getColorOtStatus(row,data) + createdRow: (row, data, dataIndex) => { + this.getColorOtStatus(row, data) }, columns: this.datatableColumns, ajax: '/produccion/ordentrabajo/planning/rotativa/datatable' @@ -168,13 +185,13 @@ class PlanningRotativa { url: "/themes/vuexy/vendor/libs/datatables-sk/plugins/i18n/es-ES.json" }, columns: this.datatablePlanaColumns, - createdRow: (row,data,dataIndex) => { - this.getColorOtStatus(row,data) + createdRow: (row, data, dataIndex) => { + this.getColorOtStatus(row, data) }, ajax: { - url : '/produccion/ordentrabajo/planning/plana/datatable', - data : d => { - if(this.maquinaPadreSelectFilterPlana.getVal()){ + url: '/produccion/ordentrabajo/planning/plana/datatable', + data: d => { + if (this.maquinaPadreSelectFilterPlana.getVal()) { d.padre_id = this.maquinaPadreSelectFilterPlana.getVal() } } @@ -206,11 +223,23 @@ class PlanningRotativa { columns: this.papelPliegoDatatableColumns, ajax: '/produccion/ordentrabajo/planning/papel/plana/datatable' }); + this.maquinaPlanaDatatable = this.maquinaTablePlanning.DataTable({ + processing: true, + orderCellsTop: true, + dom: 'lrtip', + serverSide: true, + responsive: true, + pageLength: 10, + language: { + url: "/themes/vuexy/vendor/libs/datatables-sk/plugins/i18n/es-ES.json" + }, + columns: this.maquinaPlanaDatatableColumns, + ajax: '/produccion/ordentrabajo/planning/maquina/plana/datatable' + }); /** * PLANNING ROTATIVA */ this.tablePlanningRot.on("keyup", ".planning-filter", (event) => { - console.log(this.datatablePlanningRot.column($(event.currentTarget).attr("name"))) let columnIndex = this.datatableColumns.findIndex((element) => element.data == $(event.currentTarget).attr("name")) this.datatablePlanningRot.column(columnIndex).search($(event.currentTarget).val()).draw() }) @@ -225,12 +254,11 @@ class PlanningRotativa { this.papelGramajeDatatable.on('draw', this.addTotalFooter.bind(this)) this.tablePlanningRot.on('change', ".metros-check", this.calcMetrosCheck.bind(this)) - this.tablePlanningRot.on("click",'.change-corte',this.toggleCorte.bind(this)) + this.tablePlanningRot.on("click", '.change-corte', this.toggleCorte.bind(this)) /** * PLANNING PLANA */ this.tablePlanningPlana.on("keyup", ".planning-filter", (event) => { - console.log(this.datatablePlanningRot.column($(event.currentTarget).attr("name"))) let columnIndex = this.datatablePlanaColumns.findIndex((element) => element.data == $(event.currentTarget).attr("name")) this.datatablePlanningPlana.column(columnIndex).search($(event.currentTarget).val()).draw() }) @@ -246,7 +274,7 @@ class PlanningRotativa { this.datatablePlanningPlana.ajax.reload(); }) this.papelPliegoDatatable.on('draw', this.addTotalFooterPliego.bind(this)) - + this.maquinaPlanaDatatable.on('draw', this.addTotalFooterMaquinaPlana.bind(this)) this.tablePlanningPlana.on('change', ".pliegos-check", this.calcPliegosCheck.bind(this)) } _renderBtnAction(d) { @@ -254,7 +282,6 @@ class PlanningRotativa { } _columnFiltering() { this.api().columns() - console.log(this.api().columns()) } filterPapelGramaje(event) { const papelImpresionId = $(event.currentTarget).data('id') @@ -264,6 +291,10 @@ class PlanningRotativa { const papelImpresionId = $(event.currentTarget).data('id') this.getPapelImpresionPlana(papelImpresionId) } + filterMaquinaPlana(event) { + const maquinaId = $(event.currentTarget).data('id') + this.getMaquinaPlana(maquinaId) + } getPapelImpresion(papelImpresionId) { let ajax = new Ajax('/configuracion/papelesimpresion/show/' + papelImpresionId, null, @@ -282,6 +313,15 @@ class PlanningRotativa { ) ajax.get() } + getMaquinaPlana(maquinaId) { + let ajax = new Ajax('/configuracion/maquinas/' + maquinaId, + null, + null, + this.getMaquinaPlanaSuccess.bind(this), + this.getMaquinaPlanaError.bind(this) + ) + ajax.get() + } getPapelImpresionSuccess(response) { this.papelImpresionFilter.setOption(response.id, response.nombre) this.tablePlanningRot.find('input[name=papel_gramaje]').val(response.gramaje).trigger("change") @@ -293,7 +333,18 @@ class PlanningRotativa { this.tablePlanningPlana.find('input[name=papel_gramaje]').val(response.gramaje).trigger("change") this.papelImpresionPlanaHeader.text(response.nombre) } + getMaquinaPlanaSuccess(response) { + if (response.is_padre != 0) { + this.maquinaSelectFilterPlana.setOption(response.id, response.nombre) + this.tablePlanningPlana.find('input[name=maquina_planning_nombre]').val(response.nombre).trigger("change") + } else { + this.maquinaPadreSelectFilterPlana.setOption(response.id, response.nombre) + this.tablePlanningPlana.find('input[name=lg_maquinas.padre_id]').val(response.nombre).trigger("change") + } + this.papelImpresionPlanaHeader.text(response.nombre) + } getPapelImpresionPlanaError(response) { } + getMaquinaPlanaError(response) { } formatSeconds(s) { const hours = Math.floor(s / 60 / 60) const minutes = Math.floor(s / 60 % 60) @@ -316,8 +367,14 @@ class PlanningRotativa { const pliegos = this.papelPliegoDatatable.column(4).data().map((e) => parseFloat(e)) $('#total-tiempo-pliego').text(this.formatSeconds(seconds)) this.totalPliegos.set(pliegos.reduce((a, b) => a + b, 0)) - - + } + addTotalFooterMaquinaPlana() { + const seconds = this.maquinaPlanaDatatable.column(4).data().reduce((a, b) => { + return parseFloat(a) + parseFloat(b) + }, 0) + const pliegos = this.maquinaPlanaDatatable.column(3).data().map((e) => parseFloat(e)) + $('#total-tiempo-pliego-maquina').text(this.formatSeconds(seconds)) + this.totalMaquinaPliegos.set(pliegos.reduce((a, b) => a + b, 0)) } calcMetrosCheck() { const metros_sel = this.datatablePlanningRot.rows((idx, data, node) => { @@ -334,15 +391,13 @@ class PlanningRotativa { return $(node).find('input[type="checkbox"]').prop('checked'); }).data().toArray().map((e) => parseFloat(e.tiempo_real_sum)) this.totalPliegosSel.set(metros_sel.reduce((a, b) => a + b, 0)) - const totalSeconds = tiempo_total_sel.reduce((a,b) => a+b,0) - console.log("Total seconds",totalSeconds); + const totalSeconds = tiempo_total_sel.reduce((a, b) => a + b, 0) this.tiempoPlanaTotal.text(this.formatSeconds(totalSeconds)) } renderCorteImage(data) { const tipo_corte = data.tipo_corte == "bobina" ? "cortadora_bobinas" : "guillotina"; - console.log(data.tipo_corte) return `
@@ -351,7 +406,7 @@ class PlanningRotativa { ` } - toggleCorte(event){ + toggleCorte(event) { let otId = $(event.currentTarget).data('id') let ajax = new Ajax("/produccion/ordentrabajo/planning/tarea/toggle/corte/" + otId, null, @@ -361,18 +416,18 @@ class PlanningRotativa { ) ajax.post() } - toggleCorteSuccess(response){ + toggleCorteSuccess(response) { this.datatablePlanningRot.ajax.reload() alertSuccess(response.message).fire() } - toggleCorteError(){ + toggleCorteError() { } - getColorOtStatus(row,data){ - let ajax = new Ajax("/produccion/ordentrabajo/color/"+data.otId,null,null, + getColorOtStatus(row, data) { + let ajax = new Ajax("/produccion/ordentrabajo/color/" + data.otId, null, null, (response) => { - $(row).css("border-left",`10px solid ${response.color}`) - $(row).css("border-right",`10px solid ${response.color}`) - },null + $(row).css("border-left", `10px solid ${response.color}`) + $(row).css("border-right", `10px solid ${response.color}`) + }, null ) ajax.get() } From be16690f733fac76931bcfe947d2845a2d5a7c8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaime=20Jim=C3=A9nez?= Date: Fri, 30 May 2025 14:52:48 +0200 Subject: [PATCH 03/10] terminada funcionalidad reimpresion presupuestos --- ci4/app/Config/Routes/PresupuestosRoutes.php | 3 + .../Presupuestos/Presupuestoadmin.php | 235 ++++++++---------- ci4/app/Language/es/Presupuestos.php | 4 + .../Presupuestos/PresupuestoFicheroModel.php | 63 +++-- ci4/app/Services/PresupuestoService.php | 86 +++++++ .../admin/viewPresupuestoadminForm.php | 10 +- .../presupuestoAdmin/presupuestoAdminEdit.js | 68 ++++- 7 files changed, 323 insertions(+), 146 deletions(-) diff --git a/ci4/app/Config/Routes/PresupuestosRoutes.php b/ci4/app/Config/Routes/PresupuestosRoutes.php index 2f5ed704..4097a69e 100755 --- a/ci4/app/Config/Routes/PresupuestosRoutes.php +++ b/ci4/app/Config/Routes/PresupuestosRoutes.php @@ -31,6 +31,9 @@ $routes->group('presupuestoadmin', ['namespace' => 'App\Controllers\Presupuestos $routes->get('presupuestosCliente', 'Presupuestoadmin::tablaClienteForm'); $routes->get('getSumCliente/(:num)', 'Presupuestoadmin::obtenerTotalPresupuestosCliente/$1'); + $routes->get('hasFiles', 'Presupuestoadmin::hasFiles'); + $routes->post('reprint', 'Presupuestoadmin::reprintPresupuesto'); + $routes->post('download_zip', 'Presupuestocliente::download_zip', ['as' => 'descargarAdminArchivos']); }); diff --git a/ci4/app/Controllers/Presupuestos/Presupuestoadmin.php b/ci4/app/Controllers/Presupuestos/Presupuestoadmin.php index a2a5b194..a69fad38 100755 --- a/ci4/app/Controllers/Presupuestos/Presupuestoadmin.php +++ b/ci4/app/Controllers/Presupuestos/Presupuestoadmin.php @@ -130,11 +130,10 @@ class Presupuestoadmin extends \App\Controllers\BaseResourceController $POD = model('App\Models\Configuracion\ConfigVariableModel')->getVariable('POD')->value; $ancho = 0; $alto = 0; - if(isset($sanitizedData['papel_formato_personalizado']) && $sanitizedData['papel_formato_personalizado'] == '1'){ + if (isset($sanitizedData['papel_formato_personalizado']) && $sanitizedData['papel_formato_personalizado'] == '1') { $ancho = $sanitizedData['papel_formato_ancho']; $alto = $sanitizedData['papel_formato_alto']; - } - else{ + } else { $papelFormatoModel = new PapelFormatoModel(); $papelFormato = $papelFormatoModel->find($sanitizedData['papel_formato_id']); $ancho = $papelFormato->ancho; @@ -152,7 +151,7 @@ class Presupuestoadmin extends \App\Controllers\BaseResourceController ]); $model = new PresupuestoEncuadernacionesModel(); - foreach($servDefectoEnc as $servicio){ + foreach ($servDefectoEnc as $servicio) { $data = [ 'presupuesto_id' => $id, @@ -238,12 +237,14 @@ class Presupuestoadmin extends \App\Controllers\BaseResourceController $postData = $this->request->getPost(); $postData['updated_at'] = gmdate('Y-m-d H:m:s', time()); - + $sanitizedData = $this->sanitized($postData, $nullIfEmpty); $sanitizedData['user_updated_id'] = auth()->user()->id; - if(isset($sanitizedData['total_aceptado_revisado']) && $sanitizedData['total_aceptado_revisado'] != 0 - && $sanitizedData['total_aceptado_revisado'] != null && $sanitizedData['total_aceptado_revisado'] != ""){ + if ( + isset($sanitizedData['total_aceptado_revisado']) && $sanitizedData['total_aceptado_revisado'] != 0 + && $sanitizedData['total_aceptado_revisado'] != null && $sanitizedData['total_aceptado_revisado'] != "" + ) { $sanitizedData['aprobado_at'] = $sanitizedData['updated_at']; $sanitizedData['aprobado_user_id'] = $sanitizedData['user_updated_id']; } @@ -369,9 +370,9 @@ class Presupuestoadmin extends \App\Controllers\BaseResourceController } // modificar los datos del pedido y de la factura si no está la factura validada - if ($presupuestoEntity->estado_id == 2){ + if ($presupuestoEntity->estado_id == 2) { $facturaModel = model('App\Models\Facturas\FacturaModel'); - if(!$facturaModel->presupuestoHasFacturaValidada($id)){ + if (!$facturaModel->presupuestoHasFacturaValidada($id)) { // se actualiza primero el pedido $pedidoModel = model('App\Models\Pedidos\PedidoLineaModel'); $pedidoLineaId = $pedidoModel->where('presupuesto_id', $id)->first()->id; @@ -437,7 +438,7 @@ class Presupuestoadmin extends \App\Controllers\BaseResourceController $this->viewData['POD'] = $this->getPOD(); $this->viewData['no_envio_base'] = model('App\Models\Clientes\ClienteModel')->where('id', $presupuestoEntity->cliente_id)->first(); - if($this->viewData['no_envio_base']) + if ($this->viewData['no_envio_base']) $this->viewData['no_envio_base'] = $this->viewData['no_envio_base']->no_envio_base; $this->viewData['serviciosAutomaticos'] = [ @@ -465,11 +466,11 @@ class Presupuestoadmin extends \App\Controllers\BaseResourceController $modelPedidoLinea = new \App\Models\Pedidos\PedidoLineaModel(); $linea = $modelPedidoLinea->where('presupuesto_id', $id)->first(); - if($linea){ + if ($linea) { $this->viewData['pedido_id'] = $linea->pedido_id; $modelOrden = new \App\Models\OrdenTrabajo\OrdenTrabajoModel(); $orden = $modelOrden->where('pedido_id', $linea->pedido_id)->first(); - if($orden){ + if ($orden) { $this->viewData['orden_id'] = $orden->id; } } @@ -639,7 +640,7 @@ class Presupuestoadmin extends \App\Controllers\BaseResourceController $data['comparador']['json_data'] = json_decode($presupuesto->comparador_json_data, true); if ($data['comparador']['json_data'] != null) { foreach ($data['comparador']['json_data'] as &$item) { - if(intval($item['papel_id'])>0) + if (intval($item['papel_id']) > 0) $item['papel_nombre'] = $modelPapelGenerico->getNombre($item['papel_id'])['nombre']; } } @@ -663,7 +664,7 @@ class Presupuestoadmin extends \App\Controllers\BaseResourceController $data['comentarios_pdf'] = $presupuesto->comentarios_pdf; $data['comentarios_presupuesto'] = $presupuesto->comentarios_presupuesto; $data['comentarios_produccion'] = $presupuesto->comentarios_produccion; - + $data['tiradasAlternativas'] = json_decode($presupuesto->tirada_alternativa_json_data); @@ -694,9 +695,9 @@ class Presupuestoadmin extends \App\Controllers\BaseResourceController $data['resumen']['total_factor_ponderado'] = is_numeric($presupuesto->total_factor_ponderado) ? $presupuesto->total_factor_ponderado : 0; $data['total_aceptado_revisado'] = $presupuesto->total_aceptado_revisado; - $data['aprobado_by_at'] = ($presupuesto->aprobado_user_id != null)? - model('App\Models\Usuarios\UserModel')->getFullName($presupuesto->aprobado_user_id) . ', ' - . date('d/m/Y H:i:s', strtotime($presupuesto->aprobado_at)):''; + $data['aprobado_by_at'] = ($presupuesto->aprobado_user_id != null) ? + model('App\Models\Usuarios\UserModel')->getFullName($presupuesto->aprobado_user_id) . ', ' + . date('d/m/Y H:i:s', strtotime($presupuesto->aprobado_at)) : ''; $data['resumen']['iva_reducido'] = $presupuesto->iva_reducido; @@ -817,7 +818,7 @@ class Presupuestoadmin extends \App\Controllers\BaseResourceController $paginas_color = $sobrecubierta['datosPedido']['paginas'] ?? 0; $tipo_impresion_id = $sobrecubierta['tipo_impresion_id']; $faja = intval($sobrecubierta['faja'] ?? 0); - $uso = $faja==1? 'faja' : $sobrecubierta['uso']; + $uso = $faja == 1 ? 'faja' : $sobrecubierta['uso']; $data = array( @@ -1082,20 +1083,22 @@ class Presupuestoadmin extends \App\Controllers\BaseResourceController $resourceData = PresupuestoService::obtenerComparadorPlana($input_data); - if($calcular_merma == 1 && count($resourceData) > 0 && - count($resourceData[0]['fields']) >0 && $resourceData[0]['fields']['num_formas'] > 0) { + if ( + $calcular_merma == 1 && count($resourceData) > 0 && + count($resourceData[0]['fields']) > 0 && $resourceData[0]['fields']['num_formas'] > 0 + ) { usort($resourceData, function ($a, $b) { return $b['fields']['total_impresion'] <=> $a['fields']['total_impresion']; }); $num_formas = []; - $formas_linea = $datosPedido->isCosido ? intval($resourceData[0]['fields']['num_formas']['value']) / 2 : - intval($resourceData[0]['fields']['num_formas']['value']); + $formas_linea = $datosPedido->isCosido ? intval($resourceData[0]['fields']['num_formas']['value']) / 2 : + intval($resourceData[0]['fields']['num_formas']['value']); array_push($num_formas, $formas_linea); $POD = $this->getPOD(); - $datosPedido->merma = PresupuestoService::calcular_merma($datosPedido->tirada,$POD, $num_formas); + $datosPedido->merma = PresupuestoService::calcular_merma($datosPedido->tirada, $POD, $num_formas); $resourceData = PresupuestoService::obtenerComparadorPlana($input_data); } @@ -1132,20 +1135,22 @@ class Presupuestoadmin extends \App\Controllers\BaseResourceController $resourceData = PresupuestoService::obtenerComparadorRotativa($input_data); - if($calcular_merma == 1 && count($resourceData) > 0 && - count($resourceData[0]['fields']) >0 && $resourceData[0]['fields']['num_formas'] > 0) { + if ( + $calcular_merma == 1 && count($resourceData) > 0 && + count($resourceData[0]['fields']) > 0 && $resourceData[0]['fields']['num_formas'] > 0 + ) { usort($resourceData, function ($a, $b) { return $b['fields']['total_impresion'] <=> $a['fields']['total_impresion']; }); $num_formas = []; - $formas_linea = $datosPedido->isCosido ? intval($resourceData[0]['fields']['num_formas']['value']) / 2 : - intval($resourceData[0]['fields']['num_formas']['value']); + $formas_linea = $datosPedido->isCosido ? intval($resourceData[0]['fields']['num_formas']['value']) / 2 : + intval($resourceData[0]['fields']['num_formas']['value']); array_push($num_formas, $formas_linea); $POD = $this->getPOD(); - $datosPedido->merma = PresupuestoService::calcular_merma($datosPedido->tirada,$POD, $num_formas); + $datosPedido->merma = PresupuestoService::calcular_merma($datosPedido->tirada, $POD, $num_formas); $resourceData = PresupuestoService::obtenerComparadorRotativa($input_data); } @@ -1215,7 +1220,7 @@ class Presupuestoadmin extends \App\Controllers\BaseResourceController return $this->respond($data); } else if ($tipo == 'duplicar') { $presupuesto_id = $reqData['presupuesto_id'] ?? -1; - $result = $this->duplicarPresupuesto($presupuesto_id); + $result = PresupuestoService::duplicarPresupuesto($presupuesto_id); $newTokenHash = csrf_hash(); $csrfTokenName = csrf_token(); if ($result['success']) { @@ -1271,12 +1276,12 @@ class Presupuestoadmin extends \App\Controllers\BaseResourceController $cubierta = false; if ($uso == 'cubierta') { $cubierta = true; - $anchoLibro = 2* $ancho + 2 * $solapas + $lomo; + $anchoLibro = 2 * $ancho + 2 * $solapas + $lomo; } $sobrecubierta = false; if ($uso == 'sobrecubierta') { $sobrecubierta = true; - $anchoLibro = 2* $ancho + 2 * $solapas + $lomo; + $anchoLibro = 2 * $ancho + 2 * $solapas + $lomo; } $guardas = false; if ($uso == 'guardas') { @@ -1300,7 +1305,8 @@ class Presupuestoadmin extends \App\Controllers\BaseResourceController $isPOD, $anchoLibro, $alto, - $tirada); + $tirada + ); if ($this->request->getGet("q")) { $query->groupStart() ->orLike("t1.nombre", $this->request->getGet("q")) @@ -1339,12 +1345,12 @@ class Presupuestoadmin extends \App\Controllers\BaseResourceController $cubierta = false; if ($uso == 'cubierta') { $cubierta = true; - $anchoLibro = 2* $ancho + 2 * $solapas + $lomo; + $anchoLibro = 2 * $ancho + 2 * $solapas + $lomo; } $sobrecubierta = false; if ($uso == 'sobrecubierta') { $sobrecubierta = true; - $anchoLibro = 2* $ancho + 2 * $solapas + $lomo; + $anchoLibro = 2 * $ancho + 2 * $solapas + $lomo; } $guardas = false; if ($uso == 'guardas') { @@ -1356,7 +1362,8 @@ class Presupuestoadmin extends \App\Controllers\BaseResourceController } $model = model('App\Models\Configuracion\PapelGenericoModel'); - $query = $model->getGramajeForComparador($tipo, + $query = $model->getGramajeForComparador( + $tipo, $papel_generico_id, $cubierta, $sobrecubierta, @@ -1366,7 +1373,8 @@ class Presupuestoadmin extends \App\Controllers\BaseResourceController $isPOD, $anchoLibro, $alto, - $tirada); + $tirada + ); if ($this->request->getGet("q")) { $query->groupStart() ->orLike("t2.gramaje", $this->request->getGet("q")) @@ -1599,81 +1607,6 @@ class Presupuestoadmin extends \App\Controllers\BaseResourceController } - /** - * Duplica un presupuesto dado por su ID. - * - * Esta función duplica un presupuesto y todas sus entidades relacionadas como acabados, encuadernaciones, manipulados, - * preimpresiones, direcciones y lineas. El presupuesto duplicado se marca como tal y a su título se le añade - * una cadena 'duplicado'. La función devuelve un array con un estado de éxito y el ID del nuevo presupuesto. - * - * @param int $id El ID del presupuesto a duplicar. - * @return array Un array asociativo que contiene una clave 'success' que indica el estado de éxito de la operación, - * y una clave 'id' que contiene el ID del nuevo presupuesto si la operación fue exitosa. - * Si ocurre una excepción, la clave 'success' será false y una clave 'message' contendrá el mensaje de la excepción. - * @throws \Exception Si ocurre un error durante la operación. - */ - private function duplicarPresupuesto($id) - { - - try { - - $presupuesto = $this->model->find($id); - $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($servicioExtra); - } - - $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 [ - 'success' => true, - 'id' => $new_id - ]; - - } catch (\Exception $e) { - return [ - 'success' => false, - 'message' => $e->getMessage() - ]; - } - } public function allItemsSelect() { @@ -1812,10 +1745,11 @@ class Presupuestoadmin extends \App\Controllers\BaseResourceController $result = DataTable::of($q) ->edit( 'fecha', - fn($q) => $q->fecha?Time::createFromFormat("Y-m-d H:i:s", $q->fecha)->format("d/m/Y"):"" + fn($q) => $q->fecha ? Time::createFromFormat("Y-m-d H:i:s", $q->fecha)->format("d/m/Y") : "" ) ->edit( - 'estado', fn($q) => match ($q->estado) { + 'estado', + fn($q) => match ($q->estado) { "1" => lang('Presupuestos.borrador'), "2" => lang('Presupuestos.confirmado'), default => '--' @@ -1826,13 +1760,14 @@ class Presupuestoadmin extends \App\Controllers\BaseResourceController
'; - + }); - - return $result->toJson(returnAsObject: true) ; + + return $result->toJson(returnAsObject: true); } - public function obtenerTotalPresupuestosCliente($cliente_id){ + public function obtenerTotalPresupuestosCliente($cliente_id) + { $error = false; $result = [ @@ -1843,17 +1778,17 @@ class Presupuestoadmin extends \App\Controllers\BaseResourceController ->where('presupuestos.cliente_id', $cliente_id) ->select('SUM(presupuestos.total_aceptado) as total') ->groupBy('presupuestos.cliente_id')->get()->getResultObject(); - if(count($data) > 0){ + if (count($data) > 0) { $result['total_impresion'] = round(floatval($data[0]->total), 2); - } - else{ + } else { $error = true; } $result['total'] = $result['total_impresion'] + $result['total_maquetacion']; - return $this->respond(['status' => $error?'error':'success', 'totales' => $result]); + return $this->respond(['status' => $error ? 'error' : 'success', 'totales' => $result]); } - public function obtenerTotalPedidosCliente($cliente_id){ + public function obtenerTotalPedidosCliente($cliente_id) + { $error = false; $result = [ @@ -1866,14 +1801,58 @@ class Presupuestoadmin extends \App\Controllers\BaseResourceController ->join('pedidos_linea', 'pedidos_linea.pedido_id = pedidos.id') ->join('presupuestos', 'presupuestos.id = pedidos_linea.presupuesto_id') ->groupBy('presupuestos.cliente_id')->get()->getResultObject(); - if(count($data) > 0){ + if (count($data) > 0) { $result['total_impresion'] = round(floatval($data[0]->total), 2); - } - else{ + } else { $error = true; } $result['total'] = $result['total_impresion'] + $result['total_maquetacion']; - return $this->respond(['status' => $error?'error':'success', 'totales' => $result]); + return $this->respond(['status' => $error ? 'error' : 'success', 'totales' => $result]); + } + + + public function hasFiles() + { + + if ($this->request->isAJAX()) { + $id = $this->request->getGet('id'); + $presupuesto = $this->model->find($id); + if (!$presupuesto) { + return $this->respond([ + 'status' => 'error', + 'message' => lang('Presupuestos.presupuestoNotFound'), + ]); + } + + $files = $presupuesto->files() ?? []; + if (count($files) == 0) { + return $this->respond([ + 'status' => 'success', + 'hasFiles' => false, + ]); + } else { + return $this->respond([ + 'status' => 'success', + 'hasFiles' => true, + ]); + } + } else { + return $this->failUnauthorized('Invalid request', 403); + } + } + + public function reprintPresupuesto() + { + + if ($this->request->isAJAX()) { + $id = $this->request->getPost('id'); + $duplicateFiles = $this->request->getPost('duplicateFiles') ?? false; + $response = PresupuestoService::duplicarPresupuesto($id, true, $duplicateFiles); + return $this->respond($response); + + } else { + return $this->failUnauthorized('Invalid request', 403); + } } @@ -1903,7 +1882,7 @@ class Presupuestoadmin extends \App\Controllers\BaseResourceController $modelPapel = new PapelGenericoModel(); foreach ($lineas as $linea) { $linea->papel_generico = (new PapelGenericoModel())->find($linea->papel_id)->nombre; - if($linea->tipo == 'lp_faja'){ + if ($linea->tipo == 'lp_faja') { $linea->alto_faja = $presupuestoEntity->alto_faja_color; } } @@ -1972,4 +1951,6 @@ class Presupuestoadmin extends \App\Controllers\BaseResourceController return $direcciones; } + + } diff --git a/ci4/app/Language/es/Presupuestos.php b/ci4/app/Language/es/Presupuestos.php index f23b687b..ac209861 100755 --- a/ci4/app/Language/es/Presupuestos.php +++ b/ci4/app/Language/es/Presupuestos.php @@ -363,6 +363,9 @@ return [ 'borrador' => 'Borrador', 'confirmado' => 'Confirmado', + 'reprint' => 'Reimpresión', + 'presupuestoGenerado' => 'Presupuesto generado con éxito', + 'files' => 'Ficheros', 'titulos' => [ 'libroFresadoTapaDura' => 'Rústica Fresado tapa dura', @@ -402,6 +405,7 @@ return [ ], 'errores' => [ + 'presupuestoNotFound' => 'Presupuesto no encontrado', 'paginas' => 'El campo páginas tiene que ser mayor que cero', 'paginasLP' => 'El número de páginas no coincide con el total', 'tiradas' => 'El campo tiradas tiene que ser mayor que cero', diff --git a/ci4/app/Models/Presupuestos/PresupuestoFicheroModel.php b/ci4/app/Models/Presupuestos/PresupuestoFicheroModel.php index 46ab3db6..41deef1e 100755 --- a/ci4/app/Models/Presupuestos/PresupuestoFicheroModel.php +++ b/ci4/app/Models/Presupuestos/PresupuestoFicheroModel.php @@ -24,10 +24,11 @@ class PresupuestoFicheroModel extends \App\Models\BaseModel public static $labelField = "nombre"; - public function saveFileInBBDD($presupuesto_id, $filename, $extension ,$user_id) { - try{ + public function saveFileInBBDD($presupuesto_id, $filename, $extension, $user_id) + { + try { $new_filename = $this->generateFileHash($filename) . '.' . $extension; - + $this->db->table($this->table . " t1") ->set('presupuesto_id', $presupuesto_id) ->set('nombre', $filename) @@ -42,13 +43,14 @@ class PresupuestoFicheroModel extends \App\Models\BaseModel } } - public function deleteFiles($presupuesto_id, $old_files = []){ + public function deleteFiles($presupuesto_id, $old_files = []) + { $files = $this->db ->table($this->table . " t1") ->where('presupuesto_id', $presupuesto_id)->get()->getResult(); - if($files){ - foreach($files as $file){ + if ($files) { + foreach ($files as $file) { // se comprueba que el $file->nombre no sea igual a ninguno de los elementos del array $old_files if (!in_array($file->nombre, $old_files)) { @@ -67,21 +69,52 @@ class PresupuestoFicheroModel extends \App\Models\BaseModel } - public function getFiles($presupuesto_id){ + public function copyFiles($presupuesto_id_origen, $presupuesto_id_destino) + { + + $files = $this->db + ->table($this->table . " t1") + ->where('presupuesto_id', $presupuesto_id_origen)->get()->getResult(); + if ($files) { + + foreach ($files as $file) { + + $hash = $this->generateFileHash($file->nombre); + + // se copia el fichero a la nueva ubicación + if (!file_exists(WRITEPATH . $file->file_path)) { + copy($file->file_path, WRITEPATH . 'uploads/presupuestos/' . $hash); + } + + $this->db->table($this->table . " t1") + ->set('presupuesto_id', $presupuesto_id_destino) + ->set('nombre', $file->nombre) + ->set('file_path', WRITEPATH . 'uploads/presupuestos/' . $hash) + ->set('upload_by', auth()->user()->id) + ->set('upload_at', date('Y-m-d H:i:s')) + ->insert(); + } + } + } + + + public function getFiles($presupuesto_id) + { return $this->db ->table($this->table . " t1") ->where('presupuesto_id', $presupuesto_id)->get()->getResult(); } - + /** - * Función para convertir el nombre y extensión de un fichero en un hash único - * usando cifrado simétrico. - * - * @param string $filename Nombre del fichero con extensión - * @return string Hash encriptado del fichero - */ - private function generateFileHash($filename) { + * Función para convertir el nombre y extensión de un fichero en un hash único + * usando cifrado simétrico. + * + * @param string $filename Nombre del fichero con extensión + * @return string Hash encriptado del fichero + */ + private function generateFileHash($filename) + { return hash('sha256', $filename); } diff --git a/ci4/app/Services/PresupuestoService.php b/ci4/app/Services/PresupuestoService.php index 908999ad..b59ee7c0 100755 --- a/ci4/app/Services/PresupuestoService.php +++ b/ci4/app/Services/PresupuestoService.php @@ -2108,4 +2108,90 @@ class PresupuestoService extends BaseService } return null; } + + public static function duplicarPresupuesto($id = null, $is_reimpresion = false, $copy_files = false) + { + try { + + $modelPresupuesto = model('App\Models\Presupuestos\PresupuestoModel'); + $presupuesto = $modelPresupuesto->find($id); + if (!$presupuesto || $id == null) { + return [ + 'success' => false, + 'message' => lang('Presupuestos.presupuestoNotFound'), + ]; + } + $presupuesto->titulo = $presupuesto->titulo . ' - ' . lang('Presupuestos.duplicado'); + $presupuesto->is_duplicado = 1; + $presupuesto->estado_id = 1; + if($is_reimpresion){ + $presupuesto->inc_rei = "reimpresion"; + $modelPedidoLinea = model('App\Models\Pedidos\PedidoLineaModel'); + $pedido_linea = $modelPedidoLinea->where('presupuesto_id', $id)->first(); + if($pedido_linea){ + $text = "REIMPRESION [" . date('Y-m-d H:i:s') . "] - PEDIDO: " . $pedido_linea->pedido_id . + "\n================================================\n"; + $presupuesto->comentarios_safekat = $presupuesto->comentarios_safekat . $text; + } + } + $new_id = $modelPresupuesto->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($servicioExtra); + } + + $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); + + + if (boolval($copy_files)== true) { + $presupuestoFilesModel = model('App\Models\Presupuestos\PresupuestoFicheroModel'); + $presupuestoFilesModel->copyFiles($presupuesto->id, $new_id); + } + + return [ + 'success' => true, + 'id' => $new_id, + 'message' => lang('Presupuestos.presupuestoGenerado'), + ]; + + } catch (\Exception $e) { + return [ + 'success' => false, + 'message' => $e->getMessage() + ]; + } + } } diff --git a/ci4/app/Views/themes/vuexy/form/presupuestos/admin/viewPresupuestoadminForm.php b/ci4/app/Views/themes/vuexy/form/presupuestos/admin/viewPresupuestoadminForm.php index 2e47dec5..36dd39e3 100755 --- a/ci4/app/Views/themes/vuexy/form/presupuestos/admin/viewPresupuestoadminForm.php +++ b/ci4/app/Views/themes/vuexy/form/presupuestos/admin/viewPresupuestoadminForm.php @@ -93,11 +93,19 @@ "btn btn-dark float-start me-sm-3 me-1",'target' => '_blank']) ?> " /> + estado_id == 2): ?> + " + /> + "btn btn-secondary float-start",]) ?> diff --git a/httpdocs/assets/js/safekat/pages/presupuestoAdmin/presupuestoAdminEdit.js b/httpdocs/assets/js/safekat/pages/presupuestoAdmin/presupuestoAdminEdit.js index b441c819..292d4075 100644 --- a/httpdocs/assets/js/safekat/pages/presupuestoAdmin/presupuestoAdminEdit.js +++ b/httpdocs/assets/js/safekat/pages/presupuestoAdmin/presupuestoAdminEdit.js @@ -180,6 +180,7 @@ class PresupuestoAdminEdit { this.fileUploadDropzone.init() } + $('#reprint').on('click', this.reprintPresupuesto.bind(this)); } @@ -401,12 +402,12 @@ class PresupuestoAdminEdit { self.tipo_impresion.val(response.data.tipo_impresion); self.POD.val(response.data.POD); - const totalAceptadoRevisado = response.data.total_aceptado_revisado != null ? + const totalAceptadoRevisado = response.data.total_aceptado_revisado != null ? response.data.total_aceptado_revisado : response.data.resumen.total_aceptado; AutoNumeric.getAutoNumericElement($('#total_aceptado_revisado')[0]).set(totalAceptadoRevisado); - + $('#aprobado_by_at').html(response.data.aprobado_by_at); - + $('#created_by').html(response.data.created_by); $('#updated_by').html(response.data.updated_by); $('#created_at').html(response.data.created_at); @@ -677,6 +678,66 @@ class PresupuestoAdminEdit { }) } + reprintPresupuesto() { + + const id = window.location.href.split("/").pop(); + new Ajax('/presupuestoadmin/hasFiles', + { id: id }, {}, + function (response) { + if (response.status === 'success') { + if (response.hasFiles) { + + Swal.fire({ + title: 'El presupuesto tiene archivos adjuntos', + text: '¿Desea incluir los mismos ficheros en el nuevo presupuesto?', + icon: 'warning', + showCancelButton: true, + confirmButtonText: 'Sí', + cancelButtonText: 'No', + customClass: { + confirmButton: 'btn btn-danger me-1', + cancelButton: 'btn btn-secondary' + }, + buttonsStyling: false + }).then((result) => { + new Ajax('/presupuestoadmin/reprint', + { id: id, duplicateFiles: result.isConfirmed?1:0 }, {}, + function (response) { + if (response.success === true) { + Swal.fire({ + text: response.message, + icon: 'success', + confirmButtonColor: '#3085d6', + confirmButtonText: 'Ok', + customClass: { + confirmButton: 'btn btn-primary me-1', + }, + buttonsStyling: false + }) + window.open('/presupuestoadmin/edit/' + response.id, '_blank'); + } else { + popErrorAlert(response.mensaje); + } + }, + function (error) { + popErrorAlert(error); + } + ).post(); + }); + } + + } else { + popErrorAlert(response.mensaje); + } + $('#loader').modal('hide'); + }, + function (error) { + console.error(error); + $('#loader').modal('hide'); + } + ).get(); + } + } document.addEventListener('DOMContentLoaded', function () { @@ -704,4 +765,5 @@ document.addEventListener('DOMContentLoaded', function () { console.log("Error getting translations:", error); } ).post(); + }); \ No newline at end of file From 78c40825965e42ff2a1a5e41995ad2b5d6d03125 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaime=20Jim=C3=A9nez?= Date: Fri, 30 May 2025 14:55:29 +0200 Subject: [PATCH 04/10] si no se usan los mismos archivos no es reimpresion --- ci4/app/Services/PresupuestoService.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ci4/app/Services/PresupuestoService.php b/ci4/app/Services/PresupuestoService.php index b59ee7c0..d2cc320a 100755 --- a/ci4/app/Services/PresupuestoService.php +++ b/ci4/app/Services/PresupuestoService.php @@ -2124,7 +2124,7 @@ class PresupuestoService extends BaseService $presupuesto->titulo = $presupuesto->titulo . ' - ' . lang('Presupuestos.duplicado'); $presupuesto->is_duplicado = 1; $presupuesto->estado_id = 1; - if($is_reimpresion){ + if($is_reimpresion && boolval($copy_files)){ $presupuesto->inc_rei = "reimpresion"; $modelPedidoLinea = model('App\Models\Pedidos\PedidoLineaModel'); $pedido_linea = $modelPedidoLinea->where('presupuesto_id', $id)->first(); From b7563598e0ffbaf924b279bef83ba4403e3d6450 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaime=20Jim=C3=A9nez?= Date: Fri, 30 May 2025 15:10:34 +0200 Subject: [PATCH 05/10] cuando no tiene ficheros reimprimir directamente --- .../presupuestoAdmin/presupuestoAdminEdit.js | 26 +++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/httpdocs/assets/js/safekat/pages/presupuestoAdmin/presupuestoAdminEdit.js b/httpdocs/assets/js/safekat/pages/presupuestoAdmin/presupuestoAdminEdit.js index 292d4075..7bef3346 100644 --- a/httpdocs/assets/js/safekat/pages/presupuestoAdmin/presupuestoAdminEdit.js +++ b/httpdocs/assets/js/safekat/pages/presupuestoAdmin/presupuestoAdminEdit.js @@ -701,7 +701,7 @@ class PresupuestoAdminEdit { buttonsStyling: false }).then((result) => { new Ajax('/presupuestoadmin/reprint', - { id: id, duplicateFiles: result.isConfirmed?1:0 }, {}, + { id: id, duplicateFiles: result.isConfirmed ? 1 : 0 }, {}, function (response) { if (response.success === true) { Swal.fire({ @@ -727,7 +727,29 @@ class PresupuestoAdminEdit { } } else { - popErrorAlert(response.mensaje); + new Ajax('/presupuestoadmin/reprint', + { id: id, duplicateFiles: 0 }, {}, + function (response) { + if (response.success === true) { + Swal.fire({ + text: response.message, + icon: 'success', + confirmButtonColor: '#3085d6', + confirmButtonText: 'Ok', + customClass: { + confirmButton: 'btn btn-primary me-1', + }, + buttonsStyling: false + }) + window.open('/presupuestoadmin/edit/' + response.id, '_blank'); + } else { + popErrorAlert(response.mensaje); + } + }, + function (error) { + popErrorAlert(error); + } + ).post(); } $('#loader').modal('hide'); }, From 8ab2c2868682750aed76a2007060210b92f9fbe3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaime=20Jim=C3=A9nez?= Date: Fri, 30 May 2025 15:11:19 +0200 Subject: [PATCH 06/10] cuando no tiene ficheros reimprimir directamente --- .../js/safekat/pages/presupuestoAdmin/presupuestoAdminEdit.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/httpdocs/assets/js/safekat/pages/presupuestoAdmin/presupuestoAdminEdit.js b/httpdocs/assets/js/safekat/pages/presupuestoAdmin/presupuestoAdminEdit.js index 7bef3346..aa4607db 100644 --- a/httpdocs/assets/js/safekat/pages/presupuestoAdmin/presupuestoAdminEdit.js +++ b/httpdocs/assets/js/safekat/pages/presupuestoAdmin/presupuestoAdminEdit.js @@ -748,7 +748,7 @@ class PresupuestoAdminEdit { }, function (error) { popErrorAlert(error); - } + } ).post(); } $('#loader').modal('hide'); From b5128bdcafc1569fb0f1633645cac486e0ec84de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaime=20Jim=C3=A9nez?= Date: Fri, 30 May 2025 15:15:10 +0200 Subject: [PATCH 07/10] cuando no tiene ficheros reimprimir directamente --- .../pages/presupuestoAdmin/presupuestoAdminEdit.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/httpdocs/assets/js/safekat/pages/presupuestoAdmin/presupuestoAdminEdit.js b/httpdocs/assets/js/safekat/pages/presupuestoAdmin/presupuestoAdminEdit.js index aa4607db..f933ae32 100644 --- a/httpdocs/assets/js/safekat/pages/presupuestoAdmin/presupuestoAdminEdit.js +++ b/httpdocs/assets/js/safekat/pages/presupuestoAdmin/presupuestoAdminEdit.js @@ -701,7 +701,7 @@ class PresupuestoAdminEdit { buttonsStyling: false }).then((result) => { new Ajax('/presupuestoadmin/reprint', - { id: id, duplicateFiles: result.isConfirmed ? 1 : 0 }, {}, + { id: id, duplicateFiles: result.isConfirmed?1:0 }, {}, function (response) { if (response.success === true) { Swal.fire({ @@ -725,8 +725,7 @@ class PresupuestoAdminEdit { ).post(); }); } - - } else { + else { new Ajax('/presupuestoadmin/reprint', { id: id, duplicateFiles: 0 }, {}, function (response) { @@ -751,6 +750,10 @@ class PresupuestoAdminEdit { } ).post(); } + + } else { + popErrorAlert(response.mensaje); + } $('#loader').modal('hide'); }, function (error) { From 53ce60f6de847d1bc0f79f14b6b849573e9487c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaime=20Jim=C3=A9nez?= Date: Fri, 30 May 2025 15:15:28 +0200 Subject: [PATCH 08/10] cuando no tiene ficheros reimprimir directamente --- .../presupuestoAdmin/presupuestoAdminEdit.js | 49 +++++++++---------- 1 file changed, 24 insertions(+), 25 deletions(-) diff --git a/httpdocs/assets/js/safekat/pages/presupuestoAdmin/presupuestoAdminEdit.js b/httpdocs/assets/js/safekat/pages/presupuestoAdmin/presupuestoAdminEdit.js index f933ae32..0008af44 100644 --- a/httpdocs/assets/js/safekat/pages/presupuestoAdmin/presupuestoAdminEdit.js +++ b/httpdocs/assets/js/safekat/pages/presupuestoAdmin/presupuestoAdminEdit.js @@ -701,7 +701,7 @@ class PresupuestoAdminEdit { buttonsStyling: false }).then((result) => { new Ajax('/presupuestoadmin/reprint', - { id: id, duplicateFiles: result.isConfirmed?1:0 }, {}, + { id: id, duplicateFiles: result.isConfirmed ? 1 : 0 }, {}, function (response) { if (response.success === true) { Swal.fire({ @@ -726,35 +726,34 @@ class PresupuestoAdminEdit { }); } else { - new Ajax('/presupuestoadmin/reprint', - { id: id, duplicateFiles: 0 }, {}, - function (response) { - if (response.success === true) { - Swal.fire({ - text: response.message, - icon: 'success', - confirmButtonColor: '#3085d6', - confirmButtonText: 'Ok', - customClass: { - confirmButton: 'btn btn-primary me-1', - }, - buttonsStyling: false - }) - window.open('/presupuestoadmin/edit/' + response.id, '_blank'); - } else { - popErrorAlert(response.mensaje); + new Ajax('/presupuestoadmin/reprint', + { id: id, duplicateFiles: 0 }, {}, + function (response) { + if (response.success === true) { + Swal.fire({ + text: response.message, + icon: 'success', + confirmButtonColor: '#3085d6', + confirmButtonText: 'Ok', + customClass: { + confirmButton: 'btn btn-primary me-1', + }, + buttonsStyling: false + }) + window.open('/presupuestoadmin/edit/' + response.id, '_blank'); + } else { + popErrorAlert(response.mensaje); + } + }, + function (error) { + popErrorAlert(error); } - }, - function (error) { - popErrorAlert(error); - } - ).post(); - } + ).post(); + } } else { popErrorAlert(response.mensaje); } - $('#loader').modal('hide'); }, function (error) { console.error(error); From 744680198b10b47a6f458e5ae17399a9c8bdb033 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaime=20Jim=C3=A9nez?= Date: Fri, 30 May 2025 15:33:28 +0200 Subject: [PATCH 09/10] cambiado reimprimir --- ci4/app/Services/PresupuestoService.php | 3 + .../presupuestoAdmin/presupuestoAdminEdit.js | 107 ++++++------------ 2 files changed, 38 insertions(+), 72 deletions(-) diff --git a/ci4/app/Services/PresupuestoService.php b/ci4/app/Services/PresupuestoService.php index d2cc320a..38ad683e 100755 --- a/ci4/app/Services/PresupuestoService.php +++ b/ci4/app/Services/PresupuestoService.php @@ -2134,6 +2134,9 @@ class PresupuestoService extends BaseService $presupuesto->comentarios_safekat = $presupuesto->comentarios_safekat . $text; } } + else{ + $presupuesto->inc_rei = null; + } $new_id = $modelPresupuesto->insert($presupuesto); $presupuestoAcabadosModel = model('App\Models\Presupuestos\PresupuestoAcabadosModel'); diff --git a/httpdocs/assets/js/safekat/pages/presupuestoAdmin/presupuestoAdminEdit.js b/httpdocs/assets/js/safekat/pages/presupuestoAdmin/presupuestoAdminEdit.js index 0008af44..7073c1b8 100644 --- a/httpdocs/assets/js/safekat/pages/presupuestoAdmin/presupuestoAdminEdit.js +++ b/httpdocs/assets/js/safekat/pages/presupuestoAdmin/presupuestoAdminEdit.js @@ -681,85 +681,48 @@ class PresupuestoAdminEdit { reprintPresupuesto() { const id = window.location.href.split("/").pop(); - new Ajax('/presupuestoadmin/hasFiles', - { id: id }, {}, - function (response) { - if (response.status === 'success') { - if (response.hasFiles) { + Swal.fire({ + title: 'Reimpresion', + text: "¿Quiere usar los mismos ficheros para la reimpresión?\n(Si no usa los mismos, deberá subir unos nuevos)", + icon: 'warning', + showCancelButton: true, + confirmButtonText: 'Usar los MISMOS', + cancelButtonText: 'Cancelar', + denyButtonText: "Usar OTROS", + customClass: { + confirmButton: 'btn btn-primary me-1', + denyButton: 'btn btn-primary me-1', + cancelButton: 'btn btn-secondary' + }, + buttonsStyling: false + }).then((result) => { + if (result.isDenied || result.isConfirmed) { + new Ajax('/presupuestoadmin/reprint', + { id: id, duplicateFiles: result.isConfirmed ? 1 : 0 }, {}, + function (response) { + if (response.success === true) { Swal.fire({ - title: 'El presupuesto tiene archivos adjuntos', - text: '¿Desea incluir los mismos ficheros en el nuevo presupuesto?', - icon: 'warning', - showCancelButton: true, - confirmButtonText: 'Sí', - cancelButtonText: 'No', + text: response.message, + icon: 'success', + confirmButtonColor: '#3085d6', + confirmButtonText: 'Ok', customClass: { - confirmButton: 'btn btn-danger me-1', - cancelButton: 'btn btn-secondary' + confirmButton: 'btn btn-primary me-1', }, buttonsStyling: false - }).then((result) => { - new Ajax('/presupuestoadmin/reprint', - { id: id, duplicateFiles: result.isConfirmed ? 1 : 0 }, {}, - function (response) { - if (response.success === true) { - Swal.fire({ - text: response.message, - icon: 'success', - confirmButtonColor: '#3085d6', - confirmButtonText: 'Ok', - customClass: { - confirmButton: 'btn btn-primary me-1', - }, - buttonsStyling: false - }) - window.open('/presupuestoadmin/edit/' + response.id, '_blank'); - } else { - popErrorAlert(response.mensaje); - } - }, - function (error) { - popErrorAlert(error); - } - ).post(); - }); + }) + window.open('/presupuestoadmin/edit/' + response.id, '_blank'); + } else { + popErrorAlert(response.mensaje); } - else { - new Ajax('/presupuestoadmin/reprint', - { id: id, duplicateFiles: 0 }, {}, - function (response) { - if (response.success === true) { - Swal.fire({ - text: response.message, - icon: 'success', - confirmButtonColor: '#3085d6', - confirmButtonText: 'Ok', - customClass: { - confirmButton: 'btn btn-primary me-1', - }, - buttonsStyling: false - }) - window.open('/presupuestoadmin/edit/' + response.id, '_blank'); - } else { - popErrorAlert(response.mensaje); - } - }, - function (error) { - popErrorAlert(error); - } - ).post(); - } - - } else { - popErrorAlert(response.mensaje); + }, + function (error) { + popErrorAlert(error); } - }, - function (error) { - console.error(error); - $('#loader').modal('hide'); - } - ).get(); + ).post(); + } + }); } } From b9c18bf78c49541919b97ef8175609232d67f4ae Mon Sep 17 00:00:00 2001 From: amazuecos Date: Fri, 30 May 2025 16:57:08 +0200 Subject: [PATCH 10/10] fix --- ci4/app/Controllers/Produccion/Ordentrabajo.php | 3 ++- ci4/app/Services/ProductionService.php | 5 ++++- .../produccion/planning_rotativa/planning_rotativa.js | 7 ++++++- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/ci4/app/Controllers/Produccion/Ordentrabajo.php b/ci4/app/Controllers/Produccion/Ordentrabajo.php index 43194ba9..2d3baeca 100755 --- a/ci4/app/Controllers/Produccion/Ordentrabajo.php +++ b/ci4/app/Controllers/Produccion/Ordentrabajo.php @@ -522,7 +522,8 @@ class Ordentrabajo extends BaseController public function select_maquina_planning_plana() { $q = $this->request->getGet('q'); - $result = $this->produccionService->querySelectMaquinaPlanningPlana($q); + $padreId = $this->request->getGet('padre_id'); + $result = $this->produccionService->querySelectMaquinaPlanningPlana($q,$padreId); return $this->response->setJSON($result); } public function select_maquina_padre_planning_plana() diff --git a/ci4/app/Services/ProductionService.php b/ci4/app/Services/ProductionService.php index ba3be5b5..8332b322 100755 --- a/ci4/app/Services/ProductionService.php +++ b/ci4/app/Services/ProductionService.php @@ -1353,7 +1353,7 @@ class ProductionService extends BaseService } return $query->get()->getResultArray(); } - public function querySelectMaquinaPlanningPlana($q) + public function querySelectMaquinaPlanningPlana($q,?string $padreId) { $query = $this->otModel->builder()->select([ "orden_trabajo_tareas.maquina_id as id", @@ -1370,6 +1370,9 @@ class ProductionService extends BaseService if ($q) { $query->like('lg_maquinas.nombre', $q); } + if($padreId){ + $query->where('lg_maquinas.padre_id',$padreId); + } return $query->get()->getResultArray(); } public function querySelectMaquinaPadrePlanningPlana($q) diff --git a/httpdocs/assets/js/safekat/pages/produccion/planning_rotativa/planning_rotativa.js b/httpdocs/assets/js/safekat/pages/produccion/planning_rotativa/planning_rotativa.js index ede9535b..ddec1f65 100644 --- a/httpdocs/assets/js/safekat/pages/produccion/planning_rotativa/planning_rotativa.js +++ b/httpdocs/assets/js/safekat/pages/produccion/planning_rotativa/planning_rotativa.js @@ -104,8 +104,9 @@ class PlanningRotativa { dropdownCssClass: "h-2" }, $('body')); this.papelImpresionFilter = new ClassSelect(this.tablePlanningRot.find(".planning-papel-select"), `/produccion/ordentrabajo/planning/select/papel/rotativa`, "Seleccione un papel", true, {}, $('body')); - this.maquinaSelectFilterPlana = new ClassSelect(this.tablePlanningPlana.find(".planning-maquina-select"), `/produccion/ordentrabajo/planning/select/maquina/plana`, "Seleccione una maquina", true, {}, $('body')); this.maquinaPadreSelectFilterPlana = new ClassSelect(this.tablePlanningPlana.find(".planning-maquina-padre-select"), `/produccion/ordentrabajo/planning/select/maquina/padre/plana`, "Máquina padre", true, {}, $('body')); + this.maquinaSelectFilterPlana = new ClassSelect(this.tablePlanningPlana.find(".planning-maquina-select"), `/produccion/ordentrabajo/planning/select/maquina/plana`, "Seleccione una maquina", true, { + }, $('body')); this.papelImpresionFilterPlana = new ClassSelect(this.tablePlanningPlana.find(".planning-papel-select"), `/produccion/ordentrabajo/planning/select/papel/plana`, "Seleccione un papel", true, {}, $('body')); this.maquinaSelectFilter.config.dropdownParent = this.item } @@ -139,6 +140,10 @@ class PlanningRotativa { this.maquinaSelectFilterPlana.init() this.papelImpresionFilterPlana.init() this.maquinaPadreSelectFilterPlana.init(); + this.maquinaPadreSelectFilterPlana.onChange(() => { + const params = {padre_id : this.maquinaPadreSelectFilterPlana.getVal()} + this.maquinaSelectFilterPlana.params = {...params} + }) this.checkAllMetros.on('change', () => { let isChecked = this.checkAllMetros.prop('checked') this.item.find(".metros-check").prop('checked', isChecked).trigger("change")