mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
Implementada funcionalidad descarga en zip
This commit is contained in:
@ -30,6 +30,8 @@ $routes->group('presupuestoadmin', ['namespace' => 'App\Controllers\Presupuestos
|
||||
|
||||
$routes->get('presupuestosCliente', 'Presupuestoadmin::tablaClienteForm');
|
||||
$routes->get('getSumCliente/(:num)', 'Presupuestoadmin::obtenerTotalPresupuestosCliente/$1');
|
||||
|
||||
$routes->post('download_zip', 'Presupuestocliente::download_zip', ['as' => 'descargarAdminArchivos']);
|
||||
});
|
||||
|
||||
//$routes->resource('presupuestoadmin', ['namespace' => 'App\Controllers\Presupuestos', 'controller' => 'Presupuestoadmin', 'except' => 'show,new,create,update']);
|
||||
@ -51,6 +53,7 @@ $routes->group('presupuestocliente', ['namespace' => 'App\Controllers\Presupuest
|
||||
$routes->post('calcular', 'Presupuestocliente::calcular', ['as' => 'calcularPresupuesto']);
|
||||
$routes->post('calcularsolapas', 'Presupuestocliente::calcularMaxSolapas', ['as' => 'calcularSolapas']);
|
||||
$routes->post('checklomo', 'Presupuestocliente::check_lomo_interior');
|
||||
$routes->post('download_zip', 'Presupuestocliente::download_zip', ['as' => 'descargarClienteArchivos']);
|
||||
});
|
||||
//$routes->resource('presupuestocliente', ['namespace' => 'App\Controllers\Presupuestos', 'controller' => 'Presupuestocliente', 'except' => 'show,new,create,update']);
|
||||
|
||||
|
||||
@ -332,15 +332,14 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController
|
||||
|
||||
$cliente_model = model(('App\Models\Clientes\ClienteModel'));
|
||||
$cliente = $cliente_model->find($cliente_id);
|
||||
|
||||
|
||||
$forzarRotativa = false;
|
||||
if ($tirada[0] <= $POD && $cliente->forzar_rotativa_pod) {
|
||||
$forzarRotativa = true;
|
||||
}
|
||||
else if ($tirada[0] <= $POD && !$cliente->forzar_rotativa_pod) {
|
||||
} else if ($tirada[0] <= $POD && !$cliente->forzar_rotativa_pod) {
|
||||
$excluirRotativa = true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
$input_data = array(
|
||||
'uso' => 'interior',
|
||||
@ -760,14 +759,13 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController
|
||||
|
||||
$cliente_model = model(('App\Models\Clientes\ClienteModel'));
|
||||
$cliente = $cliente_model->find($cliente_id);
|
||||
|
||||
|
||||
$forzarRotativa = false;
|
||||
if ($tirada[0] <= $POD && $cliente->forzar_rotativa_pod) {
|
||||
$forzarRotativa = true;
|
||||
}
|
||||
else if ($tirada[0] <= $POD && !$cliente->forzar_rotativa_pod) {
|
||||
} else if ($tirada[0] <= $POD && !$cliente->forzar_rotativa_pod) {
|
||||
$excluirRotativa = true;
|
||||
}
|
||||
}
|
||||
|
||||
$input_data = array(
|
||||
'uso' => 'interior',
|
||||
@ -1340,8 +1338,8 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController
|
||||
$datos_presupuesto['entrega_taller'] = $reqData['entrega_taller'] ?? 0;
|
||||
|
||||
|
||||
$resultado_presupuesto['info']['merma'] = isset($resultado_presupuesto['info']['num_formas']) ?
|
||||
PresupuestoService::calcular_merma($selected_tirada, $POD, $resultado_presupuesto['info']['num_formas']): PresupuestoService::calcular_merma($selected_tirada, $POD);
|
||||
$resultado_presupuesto['info']['merma'] = isset($resultado_presupuesto['info']['num_formas']) ?
|
||||
PresupuestoService::calcular_merma($selected_tirada, $POD, $resultado_presupuesto['info']['num_formas']) : PresupuestoService::calcular_merma($selected_tirada, $POD);
|
||||
|
||||
$datos_presupuesto['faja'] = $faja;
|
||||
|
||||
@ -2080,14 +2078,13 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController
|
||||
|
||||
$cliente_model = model(('App\Models\Clientes\ClienteModel'));
|
||||
$cliente = $cliente_model->find($cliente_id);
|
||||
|
||||
|
||||
$forzarRotativa = false;
|
||||
if ($tirada[$t] <= $POD && $cliente->forzar_rotativa_pod) {
|
||||
$forzarRotativa = true;
|
||||
}
|
||||
else if ($tirada[0] <= $POD && !$cliente->forzar_rotativa_pod) {
|
||||
} else if ($tirada[0] <= $POD && !$cliente->forzar_rotativa_pod) {
|
||||
$excluirRotativa = true;
|
||||
}
|
||||
}
|
||||
|
||||
$input_data = array(
|
||||
'uso' => 'interior',
|
||||
@ -3586,4 +3583,29 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController
|
||||
return $servicios;
|
||||
}
|
||||
|
||||
public function download_zip()
|
||||
{
|
||||
$presupuesto_id = $this->request->getPost('presupuesto_id');
|
||||
if (!$presupuesto_id) {
|
||||
return $this->response->setStatusCode(400)->setBody('Presupuesto ID requerido');
|
||||
}
|
||||
|
||||
$ftpClient = new \App\Libraries\SafekatFtpClient();
|
||||
try {
|
||||
$zipPath = $ftpClient->downloadZipPresupuesto((int) $presupuesto_id);
|
||||
|
||||
if ($zipPath === null || !file_exists($zipPath)) {
|
||||
return $this->response->setStatusCode(404)->setBody('No se encontraron archivos');
|
||||
}
|
||||
|
||||
return $this->response
|
||||
->download($zipPath, null) // null = usar nombre original del archivo
|
||||
->setFileName('archivos_presupuesto_' . $presupuesto_id . '.zip');
|
||||
} catch (\Throwable $e) {
|
||||
log_message('error', $e->getMessage());
|
||||
return $this->response->setStatusCode(500)->setBody('Error interno');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -35,6 +35,7 @@ return [
|
||||
"global_next" => "Siguiente",
|
||||
"global_save_file" => "Guardar ficheros",
|
||||
"global_upload_files" => "Subir ficheros",
|
||||
"global_download_files" => "Descargar ficheros",
|
||||
"global_all" => "Todos",
|
||||
// LOGIN - Index
|
||||
"login_title" => "Iniciar sesión en su cuenta",
|
||||
|
||||
@ -114,4 +114,57 @@ class SafekatFtpClient
|
||||
|
||||
return implode('/', [$this->base_dir, 'pedidos_files', $rootIdExtern]);
|
||||
}
|
||||
|
||||
public function downloadZipPresupuesto(int $presupuesto_id): ?string
|
||||
{
|
||||
$modelPedidoLinea = model(PedidoLineaModel::class);
|
||||
$model = model(PresupuestoFicheroModel::class);
|
||||
|
||||
$pedidoLinea = $modelPedidoLinea->findByPresupuesto($presupuesto_id);
|
||||
$rootIdExtern = $this->pedido_xml_config->id_offset + $pedidoLinea->pedido_id;
|
||||
|
||||
$remotePath = implode('/', [$this->base_dir, 'pedidos_files', $rootIdExtern]);
|
||||
|
||||
$this->ftp->login(username: $this->username, password: $this->password);
|
||||
|
||||
if (!$this->ftp->is_dir($remotePath)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$files = $model->getFiles($presupuesto_id);
|
||||
if (empty($files)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$localTempDir = WRITEPATH . 'zip_presupuestos/' . uniqid("presupuesto_");
|
||||
if (!is_dir($localTempDir)) {
|
||||
mkdir($localTempDir, 0777, true);
|
||||
}
|
||||
|
||||
foreach ($files as $file) {
|
||||
$originalName = $file->nombre ?? basename($file->file_path);
|
||||
$localFile = $localTempDir . '/' . $originalName;
|
||||
$remoteFile = $remotePath . '/' . basename($file->file_path);
|
||||
$this->ftp->get($remoteFile, $localFile);
|
||||
}
|
||||
|
||||
$zipPath = $localTempDir . '.zip';
|
||||
$zip = new \ZipArchive();
|
||||
if ($zip->open($zipPath, \ZipArchive::CREATE | \ZipArchive::OVERWRITE)) {
|
||||
foreach (glob($localTempDir . '/*') as $localFile) {
|
||||
$zip->addFile($localFile, basename($localFile));
|
||||
}
|
||||
$zip->close();
|
||||
}
|
||||
|
||||
// Limpieza temporal
|
||||
foreach (glob($localTempDir . '/*') as $localFile) {
|
||||
unlink($localFile);
|
||||
}
|
||||
rmdir($localTempDir);
|
||||
|
||||
return $zipPath;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -31,6 +31,10 @@
|
||||
<span class="align-middle d-sm-inline-block d-none me-sm-1"><?= lang('App.global_save_file') ?></span>
|
||||
<i class="ti ti-device-floppy ti-xs"></i>
|
||||
</button>
|
||||
<button id="<?= $id ?>_btnDownloadFiles" class="btn mt-3 btn-secondary btn-sm waves-effect waves-light ml-2">
|
||||
<span class="align-middle d-sm-inline-block d-none me-sm-1"><?= lang('App.global_download_files') ?></span>
|
||||
<i class="ti ti-device-floppy ti-xs"></i>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -213,6 +213,10 @@
|
||||
<span class="align-middle d-sm-inline-block d-none me-sm-1"><?= lang('App.global_save_file') ?></span>
|
||||
<i class="ti ti-device-floppy ti-xs"></i>
|
||||
</button>
|
||||
<button id="download-all-files" class="btn mt-3 btn-secondary btn-submit waves-effect waves-light ml-2">
|
||||
<span class="align-middle d-sm-inline-block d-none me-sm-1"><?= lang('App.global_download_files') ?></span>
|
||||
<i class="ti ti-device-floppy ti-xs"></i>
|
||||
</button>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user