Merge branch 'main' into 'mod/exceso_solapas_cubierta_sobrecubierta'

Main

See merge request jjimenez/safekat!493
This commit is contained in:
2025-01-23 13:30:04 +00:00
6 changed files with 46 additions and 8 deletions

View File

@ -13,6 +13,7 @@ class PedidoXML extends BaseConfig
public string $password; public string $password;
public string $base_dir; # FTP server directory public string $base_dir; # FTP server directory
public bool $xml_enabled; public bool $xml_enabled;
public int $id_offset;
public function __construct() { public function __construct() {
parent::__construct(); parent::__construct();
@ -22,6 +23,7 @@ class PedidoXML extends BaseConfig
$this->password = env("HIDRIVE_PASS","A77h3b0X4OA2rOYAf4w2"); $this->password = env("HIDRIVE_PASS","A77h3b0X4OA2rOYAf4w2");
$this->base_dir = env("HIDRIVE_PATH_ROOT","/home/admin/safekat"); # FTP server directory $this->base_dir = env("HIDRIVE_PATH_ROOT","/home/admin/safekat"); # FTP server directory
$this->xml_enabled = env("FTP_XML_ENABLED",false); $this->xml_enabled = env("FTP_XML_ENABLED",false);
$this->id_offset = env("XML_OFFSET_CUSTOMER_ID",1000000);
} }
} }

View File

@ -1555,12 +1555,14 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController
$presupuesto_id = $_POST['presupuesto_id']; $presupuesto_id = $_POST['presupuesto_id'];
$old_files = json_decode($_POST['oldFiles']); $old_files = json_decode($_POST['oldFiles']);
$ftp = new SafekatFtpClient();
// Comprobar si se han subido archivos // Comprobar si se han subido archivos
if (!empty($_FILES['file']) || !empty($old_files)) { if (!empty($_FILES['file']) || !empty($old_files)) {
// Borrar los archivos existentes del presupuesto // Borrar los archivos existentes del presupuesto
$ftp->removeFiles($presupuesto_id);
$model->deleteFiles($presupuesto_id, $old_files); $model->deleteFiles($presupuesto_id, $old_files);
if (!empty($_FILES['file'])) { if (!empty($_FILES['file'])) {
@ -1584,13 +1586,14 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController
if (!is_null($new_name)) { if (!is_null($new_name)) {
$path = WRITEPATH . 'uploads/presupuestos/' . $new_name; $path = WRITEPATH . 'uploads/presupuestos/' . $new_name;
move_uploaded_file($tmp_name, $path); move_uploaded_file($tmp_name, $path);
$ftp = new SafekatFtpClient();
$ftp->uploadFilePresupuesto($presupuesto_id);
} }
} }
$ftp->uploadFilePresupuesto($presupuesto_id);
} }
} else { } else {
// Borrar los archivos existentes del presupuesto // Borrar los archivos existentes del presupuesto
$ftp->removeFiles($presupuesto_id);
$model->deleteFiles($presupuesto_id); $model->deleteFiles($presupuesto_id);
} }
} }

View File

@ -32,7 +32,8 @@ return [
"global_pdf" => "PDF", "global_pdf" => "PDF",
"global_prev" => "Anterior", "global_prev" => "Anterior",
"global_next" => "Siguiente", "global_next" => "Siguiente",
"global_save_file" => "Guardar ficheros",
"global_upload_files" => "Subir ficheros",
// LOGIN - Index // LOGIN - Index
"login_title" => "Iniciar sesión en su cuenta", "login_title" => "Iniciar sesión en su cuenta",
"login_email" => "Correo Electrónico", "login_email" => "Correo Electrónico",

View File

@ -58,12 +58,14 @@ class SafekatFtpClient
public function uploadFilePresupuesto(int $presupuesto_id) public function uploadFilePresupuesto(int $presupuesto_id)
{ {
try { try {
if ($this->xml_enabled == false) return false;
$model = model(PresupuestoFicheroModel::class); $model = model(PresupuestoFicheroModel::class);
$modelPedidoLinea = model(PedidoLineaModel::class); $modelPedidoLinea = model(PedidoLineaModel::class);
$pedidoLinea = $modelPedidoLinea->findByPresupuesto($presupuesto_id); $pedidoLinea = $modelPedidoLinea->findByPresupuesto($presupuesto_id);
$rootIdExtern = 1e6 + $pedidoLinea->pedido_id; $rootIdExtern = $this->pedido_xml_config->id_offset + $pedidoLinea->pedido_id;
$presupuestoFiles = $model->getFiles($presupuesto_id); $presupuestoFiles = $model->getFiles($presupuesto_id);
$this->ftp->login(username: $this->username, password: $this->password); $this->ftp->login(username: $this->username, password: $this->password);
foreach ($presupuestoFiles as $key => $value) { foreach ($presupuestoFiles as $key => $value) {
$filename = array_reverse(explode("/", $value->file_path))[0]; $filename = array_reverse(explode("/", $value->file_path))[0];
$remoteDir = implode("/", [$this->base_dir,"pedidos_files",$rootIdExtern]); $remoteDir = implode("/", [$this->base_dir,"pedidos_files",$rootIdExtern]);
@ -73,6 +75,29 @@ class SafekatFtpClient
} }
$this->ftp->put($remoteFile,$value->file_path,mode:$this->ftp::SOURCE_LOCAL_FILE); $this->ftp->put($remoteFile,$value->file_path,mode:$this->ftp::SOURCE_LOCAL_FILE);
} }
$this->ftp->disconnect();
} catch (Exception $e) {
log_message('error', $e->getMessage());
throw $e;
}
}
public function removeFiles(int $presupuesto_id)
{
try {
// if ($this->xml_enabled == false) return false;
$model = model(PresupuestoFicheroModel::class);
$modelPedidoLinea = model(PedidoLineaModel::class);
$pedidoLinea = $modelPedidoLinea->findByPresupuesto($presupuesto_id);
$rootIdExtern = $this->pedido_xml_config->id_offset + $pedidoLinea->pedido_id;
$presupuestoFiles = $model->getFiles($presupuesto_id);
$this->ftp->login(username: $this->username, password: $this->password);
foreach ($presupuestoFiles as $key => $value) {
$filename = array_reverse(explode("/", $value->file_path))[0];
$remoteFile = implode("/", [$this->base_dir,"pedidos_files",$rootIdExtern,$filename]);
$this->ftp->delete($remoteFile);
}
$this->ftp->disconnect();
} catch (Exception $e) { } catch (Exception $e) {
log_message('error', $e->getMessage()); log_message('error', $e->getMessage());
throw $e; throw $e;

View File

@ -196,11 +196,15 @@
</div> </div>
</div> </div>
</div> </div>
<button id="submit-all-files" class="btn mt-3 btn-primary btn-submit waves-effect waves-light ml-2"> <button id="btnUploadFile" class="btn mt-3 btn-primary btn-submit waves-effect waves-light ml-2 ">
<span class="align-middle d-sm-inline-block d-none me-sm-1">Actualizar ficheros</span> <span class="align-middle d-sm-inline-block d-none me-sm-1"><?= lang('App.global_upload_files') ?></span>
<i class="ti ti-upload ti-xs"></i> <i class="ti ti-upload ti-xs"></i>
</button> </button>
<button id="submit-all-files" class="btn mt-3 btn-success btn-submit waves-effect waves-light ml-2">
<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>
</div> </div>
<?php endif; ?> <?php endif; ?>
</div> </div>

View File

@ -23,6 +23,7 @@ class PresupuestoCliente {
this.btnPrint = $('#btnPrint'); this.btnPrint = $('#btnPrint');
this.btnSave = $('#btnSave'); this.btnSave = $('#btnSave');
this.btnConfirm = $('#btnConfirm'); this.btnConfirm = $('#btnConfirm');
this.btnUploadFile = $('#btnUploadFile')
this.c = $("#c"); this.c = $("#c");
this.lc = $("#lc"); this.lc = $("#lc");
@ -91,7 +92,9 @@ class PresupuestoCliente {
this.btnSave.on('click', this.#savePresupuesto.bind(this)); this.btnSave.on('click', this.#savePresupuesto.bind(this));
this.btnConfirm.on('click', this.#confirmPresupuesto.bind(this)); this.btnConfirm.on('click', this.#confirmPresupuesto.bind(this));
this.btnPrint.on('click', this.#printPresupuesto.bind(this)); this.btnPrint.on('click', this.#printPresupuesto.bind(this));
this.btnUploadFile.on('click', () => {
$('#dropzone-multi').trigger('click');
})
this.titulosMenu.on('click', this.#handleTitulosMenu.bind(this)); this.titulosMenu.on('click', this.#handleTitulosMenu.bind(this));
if (window.location.href.includes("edit")) { if (window.location.href.includes("edit")) {