mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
Merge branch 'fix/ot_zip_naming' into 'main'
Diferenciar naming en base a donde se invoca la descarga, OT vs PRESUPUESTO See merge request jjimenez/safekat!884
This commit is contained in:
@ -3686,21 +3686,30 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController
|
|||||||
public function download_zip()
|
public function download_zip()
|
||||||
{
|
{
|
||||||
$presupuesto_id = $this->request->getPost('presupuesto_id');
|
$presupuesto_id = $this->request->getPost('presupuesto_id');
|
||||||
|
$ot_id = $this->request->getPost('ot_id');
|
||||||
|
|
||||||
if (!$presupuesto_id) {
|
if (!$presupuesto_id) {
|
||||||
return $this->response->setStatusCode(400)->setBody('Presupuesto ID requerido');
|
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();
|
$ftpClient = new \App\Libraries\SafekatFtpClient();
|
||||||
try {
|
try {
|
||||||
$zipPath = $ftpClient->downloadZipPresupuesto((int) $presupuesto_id);
|
$zipPath = $ftpClient->downloadZipPresupuesto((int) $presupuesto_id, $prefijo);
|
||||||
|
|
||||||
if ($zipPath === null || !file_exists($zipPath)) {
|
if ($zipPath === null || !file_exists($zipPath)) {
|
||||||
return $this->response->setStatusCode(404)->setBody('No se encontraron archivos');
|
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
|
return $this->response
|
||||||
->download($zipPath, null) // null = usar nombre original del archivo
|
->download($zipPath, null)
|
||||||
->setFileName('archivos_presupuesto_' . $presupuesto_id . '.zip');
|
->setFileName($nombreArchivo);
|
||||||
} catch (\Throwable $e) {
|
} catch (\Throwable $e) {
|
||||||
log_message('error', $e->getMessage());
|
log_message('error', $e->getMessage());
|
||||||
return $this->response->setStatusCode(500)->setBody('Error interno');
|
return $this->response->setStatusCode(500)->setBody('Error interno');
|
||||||
@ -3708,4 +3717,5 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,35 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Controllers\Produccion;
|
|
||||||
use App\Controllers\BaseController;
|
|
||||||
|
|
||||||
|
|
||||||
class Ordenmaquina extends BaseController
|
|
||||||
{
|
|
||||||
function __construct()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public function index()
|
|
||||||
{
|
|
||||||
echo 'Orden maquina';
|
|
||||||
}
|
|
||||||
|
|
||||||
public function delete()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public function add()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public function edit()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@ -1,35 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Controllers\Produccion;
|
|
||||||
use App\Controllers\BaseController;
|
|
||||||
|
|
||||||
|
|
||||||
class Ordentrabajomaquetacion extends BaseController
|
|
||||||
{
|
|
||||||
function __construct()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public function index()
|
|
||||||
{
|
|
||||||
echo 'Orden maquetación';
|
|
||||||
}
|
|
||||||
|
|
||||||
public function delete()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public function add()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public function edit()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@ -1,35 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Controllers\Produccion;
|
|
||||||
use App\Controllers\BaseController;
|
|
||||||
|
|
||||||
|
|
||||||
class Pedidoproduccion extends BaseController
|
|
||||||
{
|
|
||||||
function __construct()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public function index()
|
|
||||||
{
|
|
||||||
echo 'Pedido produccion';
|
|
||||||
}
|
|
||||||
|
|
||||||
public function delete()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public function add()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public function edit()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@ -115,7 +115,7 @@ class SafekatFtpClient
|
|||||||
return implode('/', [$this->base_dir, 'pedidos_files', $rootIdExtern]);
|
return implode('/', [$this->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);
|
$modelPedidoLinea = model(PedidoLineaModel::class);
|
||||||
$model = model(PresupuestoFicheroModel::class);
|
$model = model(PresupuestoFicheroModel::class);
|
||||||
@ -143,8 +143,11 @@ class SafekatFtpClient
|
|||||||
|
|
||||||
foreach ($files as $file) {
|
foreach ($files as $file) {
|
||||||
$originalName = $file->nombre ?? basename($file->file_path);
|
$originalName = $file->nombre ?? basename($file->file_path);
|
||||||
$localFile = $localTempDir . '/' . $originalName;
|
$prefixedName = $prefijo ? $prefijo . '_' . $originalName : $originalName;
|
||||||
|
|
||||||
|
$localFile = $localTempDir . '/' . $prefixedName;
|
||||||
$remoteFile = $remotePath . '/' . basename($file->file_path);
|
$remoteFile = $remotePath . '/' . basename($file->file_path);
|
||||||
|
|
||||||
$this->ftp->get($remoteFile, $localFile);
|
$this->ftp->get($remoteFile, $localFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -167,4 +170,5 @@ class SafekatFtpClient
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -12,7 +12,7 @@
|
|||||||
data-bs-parent="#accordionPresupuestoFiles">
|
data-bs-parent="#accordionPresupuestoFiles">
|
||||||
<div class="accordion-body">
|
<div class="accordion-body">
|
||||||
<div class="col-12">
|
<div class="col-12">
|
||||||
<div class="dropzone needsclick" id="<?= $id ?>" data-id="<?= $modelId ?>">
|
<div class="dropzone needsclick" id="<?= $id ?>" data-id="<?= $modelId ?>" data-ot-id="<?= $otId ?? '' ?>">
|
||||||
|
|
||||||
<div class="dz-message needsclick">
|
<div class="dz-message needsclick">
|
||||||
Arrastre aquí los ficheros o haga click
|
Arrastre aquí los ficheros o haga click
|
||||||
|
|||||||
@ -1,5 +1,9 @@
|
|||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-md-12">
|
<div class="col-md-12">
|
||||||
<?= view("themes/vuexy/components/dropzone",data: ['id' => 'dropzone-ot-files','modelId' => $presupuesto->id]) ?>
|
<?= view("themes/vuexy/components/dropzone", data: [
|
||||||
|
'id' => 'dropzone-ot-files',
|
||||||
|
'modelId' => $presupuesto->id,
|
||||||
|
'otId' => $ot->id
|
||||||
|
]) ?>
|
||||||
</div><!--//.col -->
|
</div><!--//.col -->
|
||||||
</div><!--//.row -->
|
</div><!--//.row -->
|
||||||
@ -1,6 +1,6 @@
|
|||||||
|
|
||||||
import Ajax from '../ajax.js';
|
import Ajax from '../ajax.js';
|
||||||
import { alertSuccessMessage } from '../alerts/sweetAlert.js'
|
import { alertSuccessMessage, alertWarningMessage } from '../alerts/sweetAlert.js'
|
||||||
|
|
||||||
const PREVIEW_TEMPLATE = `
|
const PREVIEW_TEMPLATE = `
|
||||||
<div class="dz-preview dz-file-preview">
|
<div class="dz-preview dz-file-preview">
|
||||||
@ -25,7 +25,7 @@ const PREVIEW_TEMPLATE = `
|
|||||||
class FileUploadDropzone {
|
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;
|
Dropzone.autoDiscover = false;
|
||||||
this.domElement = domElement
|
this.domElement = domElement
|
||||||
this.jqElement = $(domElement)
|
this.jqElement = $(domElement)
|
||||||
@ -35,6 +35,7 @@ class FileUploadDropzone {
|
|||||||
this.btnDownloadFiles = $(`#${domElement.replace('#', '')}_btnDownloadFiles`);
|
this.btnDownloadFiles = $(`#${domElement.replace('#', '')}_btnDownloadFiles`);
|
||||||
this.dataPost = {}
|
this.dataPost = {}
|
||||||
this.nameId = nameId;
|
this.nameId = nameId;
|
||||||
|
this.otId = otId;
|
||||||
this.getUri = getUri
|
this.getUri = getUri
|
||||||
this.postUri = postUri
|
this.postUri = postUri
|
||||||
this.dataPost[nameId] = this.modelId;
|
this.dataPost[nameId] = this.modelId;
|
||||||
@ -160,7 +161,8 @@ class FileUploadDropzone {
|
|||||||
url: `/presupuestoadmin/download_zip`,
|
url: `/presupuestoadmin/download_zip`,
|
||||||
type: 'POST',
|
type: 'POST',
|
||||||
data: {
|
data: {
|
||||||
[this.nameId]: this.modelId
|
[this.nameId]: this.modelId,
|
||||||
|
'ot_id': this.otId
|
||||||
},
|
},
|
||||||
xhrFields: {
|
xhrFields: {
|
||||||
responseType: 'blob'
|
responseType: 'blob'
|
||||||
@ -185,7 +187,7 @@ class FileUploadDropzone {
|
|||||||
window.URL.revokeObjectURL(url);
|
window.URL.revokeObjectURL(url);
|
||||||
},
|
},
|
||||||
error: () => {
|
error: () => {
|
||||||
alertWarningMessage("Error al descargar el archivo ZIP.");
|
alertWarningMessage("Error", "Error al descargar el archivo ZIP.");
|
||||||
},
|
},
|
||||||
complete: () => {
|
complete: () => {
|
||||||
$("#loader").modal('hide');
|
$("#loader").modal('hide');
|
||||||
|
|||||||
@ -10,6 +10,7 @@ class OrdenTrabajo {
|
|||||||
this.otForm = this.item.find("#ot-edit-form")
|
this.otForm = this.item.find("#ot-edit-form")
|
||||||
this.block = document.querySelector('.section-block');
|
this.block = document.querySelector('.section-block');
|
||||||
this.modelId = this.item.data("id");
|
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.tareasTableItem = this.item.find("#ot-task-table");
|
||||||
this.tareasId = []
|
this.tareasId = []
|
||||||
this.summaryData = {}
|
this.summaryData = {}
|
||||||
@ -70,6 +71,7 @@ class OrdenTrabajo {
|
|||||||
this.configUploadDropzone = {
|
this.configUploadDropzone = {
|
||||||
domElement: '#dropzone-ot-files',
|
domElement: '#dropzone-ot-files',
|
||||||
nameId: "presupuesto_id",
|
nameId: "presupuesto_id",
|
||||||
|
otId: this.otId,
|
||||||
getUri: '/presupuestos/presupuestocliente/get_files',
|
getUri: '/presupuestos/presupuestocliente/get_files',
|
||||||
postUri: '/presupuestos/presupuestocliente/upload_files'
|
postUri: '/presupuestos/presupuestocliente/upload_files'
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user