diff --git a/ci4/app/Config/PedidoXML.php b/ci4/app/Config/PedidoXML.php index 9bce6c7c..18d494ca 100644 --- a/ci4/app/Config/PedidoXML.php +++ b/ci4/app/Config/PedidoXML.php @@ -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); } } diff --git a/ci4/app/Controllers/Presupuestos/Presupuestocliente.php b/ci4/app/Controllers/Presupuestos/Presupuestocliente.php index bd98adab..9e7ffe24 100755 --- a/ci4/app/Controllers/Presupuestos/Presupuestocliente.php +++ b/ci4/app/Controllers/Presupuestos/Presupuestocliente.php @@ -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); } } diff --git a/ci4/app/Language/es/App.php b/ci4/app/Language/es/App.php index 846ff301..d41d02fe 100755 --- a/ci4/app/Language/es/App.php +++ b/ci4/app/Language/es/App.php @@ -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", diff --git a/ci4/app/Libraries/SafekatFtpClient.php b/ci4/app/Libraries/SafekatFtpClient.php index 98259ba2..663e8c7a 100644 --- a/ci4/app/Libraries/SafekatFtpClient.php +++ b/ci4/app/Libraries/SafekatFtpClient.php @@ -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; diff --git a/ci4/app/Views/themes/vuexy/form/presupuestos/cliente/items/_resumen.php b/ci4/app/Views/themes/vuexy/form/presupuestos/cliente/items/_resumen.php index 25751b64..1e183862 100644 --- a/ci4/app/Views/themes/vuexy/form/presupuestos/cliente/items/_resumen.php +++ b/ci4/app/Views/themes/vuexy/form/presupuestos/cliente/items/_resumen.php @@ -196,11 +196,15 @@ - + - + \ No newline at end of file diff --git a/httpdocs/assets/js/safekat/pages/presupuestoCliente/presupuestoCliente.js b/httpdocs/assets/js/safekat/pages/presupuestoCliente/presupuestoCliente.js index 61c52bf9..2476ba59 100644 --- a/httpdocs/assets/js/safekat/pages/presupuestoCliente/presupuestoCliente.js +++ b/httpdocs/assets/js/safekat/pages/presupuestoCliente/presupuestoCliente.js @@ -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")) {