mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
Merge branch 'main' into 'mod/exceso_solapas_cubierta_sobrecubierta'
Main See merge request jjimenez/safekat!493
This commit is contained in:
@ -13,6 +13,7 @@ class PedidoXML extends BaseConfig
|
||||
public string $password;
|
||||
public string $base_dir; # FTP server directory
|
||||
public bool $xml_enabled;
|
||||
public int $id_offset;
|
||||
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
@ -22,6 +23,7 @@ class PedidoXML extends BaseConfig
|
||||
$this->password = env("HIDRIVE_PASS","A77h3b0X4OA2rOYAf4w2");
|
||||
$this->base_dir = env("HIDRIVE_PATH_ROOT","/home/admin/safekat"); # FTP server directory
|
||||
$this->xml_enabled = env("FTP_XML_ENABLED",false);
|
||||
$this->id_offset = env("XML_OFFSET_CUSTOMER_ID",1000000);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -1555,12 +1555,14 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController
|
||||
|
||||
$presupuesto_id = $_POST['presupuesto_id'];
|
||||
$old_files = json_decode($_POST['oldFiles']);
|
||||
$ftp = new SafekatFtpClient();
|
||||
|
||||
// Comprobar si se han subido archivos
|
||||
if (!empty($_FILES['file']) || !empty($old_files)) {
|
||||
|
||||
|
||||
// Borrar los archivos existentes del presupuesto
|
||||
$ftp->removeFiles($presupuesto_id);
|
||||
$model->deleteFiles($presupuesto_id, $old_files);
|
||||
|
||||
if (!empty($_FILES['file'])) {
|
||||
@ -1584,13 +1586,14 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController
|
||||
if (!is_null($new_name)) {
|
||||
$path = WRITEPATH . 'uploads/presupuestos/' . $new_name;
|
||||
move_uploaded_file($tmp_name, $path);
|
||||
$ftp = new SafekatFtpClient();
|
||||
$ftp->uploadFilePresupuesto($presupuesto_id);
|
||||
|
||||
}
|
||||
}
|
||||
$ftp->uploadFilePresupuesto($presupuesto_id);
|
||||
}
|
||||
} else {
|
||||
// Borrar los archivos existentes del presupuesto
|
||||
$ftp->removeFiles($presupuesto_id);
|
||||
$model->deleteFiles($presupuesto_id);
|
||||
}
|
||||
}
|
||||
|
||||
@ -32,7 +32,8 @@ return [
|
||||
"global_pdf" => "PDF",
|
||||
"global_prev" => "Anterior",
|
||||
"global_next" => "Siguiente",
|
||||
|
||||
"global_save_file" => "Guardar ficheros",
|
||||
"global_upload_files" => "Subir ficheros",
|
||||
// LOGIN - Index
|
||||
"login_title" => "Iniciar sesión en su cuenta",
|
||||
"login_email" => "Correo Electrónico",
|
||||
|
||||
@ -58,12 +58,14 @@ class SafekatFtpClient
|
||||
public function uploadFilePresupuesto(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 = 1e6 + $pedidoLinea->pedido_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];
|
||||
$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->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) {
|
||||
log_message('error', $e->getMessage());
|
||||
throw $e;
|
||||
|
||||
@ -196,11 +196,15 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<button id="submit-all-files" 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>
|
||||
<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"><?= lang('App.global_upload_files') ?></span>
|
||||
<i class="ti ti-upload ti-xs"></i>
|
||||
</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>
|
||||
<?php endif; ?>
|
||||
|
||||
|
||||
</div>
|
||||
@ -23,6 +23,7 @@ class PresupuestoCliente {
|
||||
this.btnPrint = $('#btnPrint');
|
||||
this.btnSave = $('#btnSave');
|
||||
this.btnConfirm = $('#btnConfirm');
|
||||
this.btnUploadFile = $('#btnUploadFile')
|
||||
|
||||
this.c = $("#c");
|
||||
this.lc = $("#lc");
|
||||
@ -91,7 +92,9 @@ class PresupuestoCliente {
|
||||
this.btnSave.on('click', this.#savePresupuesto.bind(this));
|
||||
this.btnConfirm.on('click', this.#confirmPresupuesto.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));
|
||||
|
||||
if (window.location.href.includes("edit")) {
|
||||
|
||||
Reference in New Issue
Block a user