From e804aa3768100d5c6f37c21cce4c15a41796b91f Mon Sep 17 00:00:00 2001 From: imnavajas Date: Thu, 17 Jul 2025 14:17:42 +0200 Subject: [PATCH] Diferenciar naming en base a donde se invoca la descarga, OT vs PRESUPUESTO --- .../Presupuestos/Presupuestocliente.php | 16 +++++++-- .../Controllers/Produccion/Ordenmaquina.php | 35 ------------------- .../Produccion/Ordentrabajomaquetacion.php | 35 ------------------- .../Produccion/Pedidoproduccion.php | 35 ------------------- ci4/app/Libraries/SafekatFtpClient.php | 8 +++-- .../themes/vuexy/components/dropzone.php | 2 +- .../vuexy/form/produccion/ot/otFiles.php | 6 +++- .../components/forms/fileUploadDropzone.js | 10 +++--- .../assets/js/safekat/pages/produccion/ot.js | 2 ++ 9 files changed, 33 insertions(+), 116 deletions(-) delete mode 100755 ci4/app/Controllers/Produccion/Ordenmaquina.php delete mode 100755 ci4/app/Controllers/Produccion/Ordentrabajomaquetacion.php delete mode 100755 ci4/app/Controllers/Produccion/Pedidoproduccion.php diff --git a/ci4/app/Controllers/Presupuestos/Presupuestocliente.php b/ci4/app/Controllers/Presupuestos/Presupuestocliente.php index 15e036e9..6ed7c197 100755 --- a/ci4/app/Controllers/Presupuestos/Presupuestocliente.php +++ b/ci4/app/Controllers/Presupuestos/Presupuestocliente.php @@ -3686,21 +3686,30 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController public function download_zip() { $presupuesto_id = $this->request->getPost('presupuesto_id'); + $ot_id = $this->request->getPost('ot_id'); + if (!$presupuesto_id) { return $this->response->setStatusCode(400)->setBody('Presupuesto ID requerido'); } + // Definir prefijo si se recibió un ot_id válido + $prefijo = (!empty($ot_id) && is_numeric($ot_id)) ? "OT_{$ot_id}" : null; + $ftpClient = new \App\Libraries\SafekatFtpClient(); try { - $zipPath = $ftpClient->downloadZipPresupuesto((int) $presupuesto_id); + $zipPath = $ftpClient->downloadZipPresupuesto((int) $presupuesto_id, $prefijo); if ($zipPath === null || !file_exists($zipPath)) { return $this->response->setStatusCode(404)->setBody('No se encontraron archivos'); } + $nombreArchivo = $prefijo + ? "{$prefijo}_PRESUPUESTO_{$presupuesto_id}.zip" + : "archivos_presupuesto_{$presupuesto_id}.zip"; + return $this->response - ->download($zipPath, null) // null = usar nombre original del archivo - ->setFileName('archivos_presupuesto_' . $presupuesto_id . '.zip'); + ->download($zipPath, null) + ->setFileName($nombreArchivo); } catch (\Throwable $e) { log_message('error', $e->getMessage()); return $this->response->setStatusCode(500)->setBody('Error interno'); @@ -3708,4 +3717,5 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController } + } diff --git a/ci4/app/Controllers/Produccion/Ordenmaquina.php b/ci4/app/Controllers/Produccion/Ordenmaquina.php deleted file mode 100755 index a92f0ae8..00000000 --- a/ci4/app/Controllers/Produccion/Ordenmaquina.php +++ /dev/null @@ -1,35 +0,0 @@ -base_dir, 'pedidos_files', $rootIdExtern]); } - public function downloadZipPresupuesto(int $presupuesto_id): ?string + public function downloadZipPresupuesto(int $presupuesto_id, ?string $prefijo = null): ?string { $modelPedidoLinea = model(PedidoLineaModel::class); $model = model(PresupuestoFicheroModel::class); @@ -143,8 +143,11 @@ class SafekatFtpClient foreach ($files as $file) { $originalName = $file->nombre ?? basename($file->file_path); - $localFile = $localTempDir . '/' . $originalName; + $prefixedName = $prefijo ? $prefijo . '_' . $originalName : $originalName; + + $localFile = $localTempDir . '/' . $prefixedName; $remoteFile = $remotePath . '/' . basename($file->file_path); + $this->ftp->get($remoteFile, $localFile); } @@ -167,4 +170,5 @@ class SafekatFtpClient } + } diff --git a/ci4/app/Views/themes/vuexy/components/dropzone.php b/ci4/app/Views/themes/vuexy/components/dropzone.php index 4065ca91..3ca591e9 100755 --- a/ci4/app/Views/themes/vuexy/components/dropzone.php +++ b/ci4/app/Views/themes/vuexy/components/dropzone.php @@ -12,7 +12,7 @@ data-bs-parent="#accordionPresupuestoFiles">
-
+
Arrastre aquí los ficheros o haga click diff --git a/ci4/app/Views/themes/vuexy/form/produccion/ot/otFiles.php b/ci4/app/Views/themes/vuexy/form/produccion/ot/otFiles.php index e44420b3..a41d93a0 100755 --- a/ci4/app/Views/themes/vuexy/form/produccion/ot/otFiles.php +++ b/ci4/app/Views/themes/vuexy/form/produccion/ot/otFiles.php @@ -1,5 +1,9 @@
- 'dropzone-ot-files','modelId' => $presupuesto->id]) ?> + 'dropzone-ot-files', + 'modelId' => $presupuesto->id, + 'otId' => $ot->id + ]) ?>
\ No newline at end of file diff --git a/httpdocs/assets/js/safekat/components/forms/fileUploadDropzone.js b/httpdocs/assets/js/safekat/components/forms/fileUploadDropzone.js index 5de39541..c9dc14a6 100644 --- a/httpdocs/assets/js/safekat/components/forms/fileUploadDropzone.js +++ b/httpdocs/assets/js/safekat/components/forms/fileUploadDropzone.js @@ -1,6 +1,6 @@ import Ajax from '../ajax.js'; -import { alertSuccessMessage } from '../alerts/sweetAlert.js' +import { alertSuccessMessage, alertWarningMessage } from '../alerts/sweetAlert.js' const PREVIEW_TEMPLATE = `
@@ -25,7 +25,7 @@ const PREVIEW_TEMPLATE = ` class FileUploadDropzone { - constructor({ domElement, nameId = "presupuesto_id", getUri = null, postUri = null, resourcePath = "presupuestos" }) { + constructor({ domElement, nameId = "presupuesto_id", getUri = null, postUri = null, resourcePath = "presupuestos", otId = null }) { Dropzone.autoDiscover = false; this.domElement = domElement this.jqElement = $(domElement) @@ -35,6 +35,7 @@ class FileUploadDropzone { this.btnDownloadFiles = $(`#${domElement.replace('#', '')}_btnDownloadFiles`); this.dataPost = {} this.nameId = nameId; + this.otId = otId; this.getUri = getUri this.postUri = postUri this.dataPost[nameId] = this.modelId; @@ -160,7 +161,8 @@ class FileUploadDropzone { url: `/presupuestoadmin/download_zip`, type: 'POST', data: { - [this.nameId]: this.modelId + [this.nameId]: this.modelId, + 'ot_id': this.otId }, xhrFields: { responseType: 'blob' @@ -185,7 +187,7 @@ class FileUploadDropzone { window.URL.revokeObjectURL(url); }, error: () => { - alertWarningMessage("Error al descargar el archivo ZIP."); + alertWarningMessage("Error", "Error al descargar el archivo ZIP."); }, complete: () => { $("#loader").modal('hide'); diff --git a/httpdocs/assets/js/safekat/pages/produccion/ot.js b/httpdocs/assets/js/safekat/pages/produccion/ot.js index ef2a16e9..b4909d85 100644 --- a/httpdocs/assets/js/safekat/pages/produccion/ot.js +++ b/httpdocs/assets/js/safekat/pages/produccion/ot.js @@ -10,6 +10,7 @@ class OrdenTrabajo { this.otForm = this.item.find("#ot-edit-form") this.block = document.querySelector('.section-block'); this.modelId = this.item.data("id"); + this.otId = parseInt($("#dropzone-ot-files").data("ot-id")) || null; this.tareasTableItem = this.item.find("#ot-task-table"); this.tareasId = [] this.summaryData = {} @@ -70,6 +71,7 @@ class OrdenTrabajo { this.configUploadDropzone = { domElement: '#dropzone-ot-files', nameId: "presupuesto_id", + otId: this.otId, getUri: '/presupuestos/presupuestocliente/get_files', postUri: '/presupuestos/presupuestocliente/upload_files' }