From d89c1b58154efbc51c79a16d9491164d441810f2 Mon Sep 17 00:00:00 2001 From: Juan Pablo Vial Date: Wed, 26 Nov 2025 17:10:55 -0300 Subject: [PATCH] FIX: mapping of prices import New template with filled units --- .../ventas/precios/modal/import.blade.php | 64 +++++++++++++++---- app/src/Controller/API/Ventas/Precios.php | 7 +- 2 files changed, 56 insertions(+), 15 deletions(-) diff --git a/app/resources/views/ventas/precios/modal/import.blade.php b/app/resources/views/ventas/precios/modal/import.blade.php index 8a5f8a9..a1f2a36 100644 --- a/app/resources/views/ventas/precios/modal/import.blade.php +++ b/app/resources/views/ventas/precios/modal/import.blade.php @@ -13,13 +13,19 @@ -
+
+
+
+ + +
+
@@ -58,26 +64,23 @@ class ImportTemplate { ids = { button: '', + filled: '', format: '' } components = { button: null, + $filled: null, $format: null } data = { filename: '', + filled: false, format: '', columns: [], csv: { separator: '', }, } - buildData() { - const data = [] - data.push(this.data.columns.map(column => column.charAt(0).toUpperCase() + column.slice(1))) - data.push(this.data.columns.map(column => '')) - return data - } download(event) { event.preventDefault() @@ -91,9 +94,7 @@ return false } downloadCsv() { - const data = [] - data.push(Object.keys(this.data.columns)) - data.push(Object.values(this.data.columns)) + const data = this.buildCsvData() const blob = new Blob([data.map(row => row.join(this.data.csv.separator)).join('\n')], {type: 'text/csv'}) const url = URL.createObjectURL(blob) const a = document.createElement('a') @@ -104,12 +105,43 @@ } downloadXlsx() { const workbook = XLSX.utils.book_new() - const worksheet = XLSX.utils.json_to_sheet([this.data.columns]) + const worksheet = XLSX.utils.json_to_sheet(this.buildData()) XLSX.utils.book_append_sheet(workbook, worksheet, 'Plantilla de Precios') XLSX.writeFile(workbook, this.data.filename + '.xlsx', { compression: true }) } + buildData() { + const data = [this.data.columns] + if (this.data.filled) { + const dateFormatter = new Intl.DateTimeFormat('es-CL') + const date = precios.components.modals.import.components.$calendar.calendar('get date') + precios.data.precios.forEach(tipologia => { + tipologia.lineas.forEach(linea => { + linea.unidades.forEach(unidad => { + data.push({ + 'Fecha*': date ? dateFormatter.format(date) : '', + 'Proyecto*': precios.data.proyecto, + 'Tipo*': tipologia.tipo, + Unidad: unidad.nombre, + Valor: '' + }) + }) + }) + }) + } + return data + } + buildCsvData() { + const data = this.buildData() + const output = [] + output.push(Object.keys(data[0])) + data.forEach(row => { + output.push(Object.values(row)) + }) + return output + } constructor() { this.ids.button = 'import_template' + this.ids.filled = 'import_filled' this.ids.format = 'import_format' this.data.filename = 'Plantilla de Precios' @@ -129,6 +161,16 @@ this.components.button = document.getElementById(this.ids.button) this.components.button.addEventListener('click', this.download.bind(this)) + this.components.$filled = $(`.${this.ids.filled}`) + this.components.$filled.checkbox({ + fireOnInit: true, + onChange: () => { + const checkbox = this.components.$filled.find('[name="filled"]').toArray()[0] + this.data.filled = checkbox.checked + } + }) + this.components.$filled.checkbox('set unchecked') + this.components.$format = $(`.${this.ids.format}`) this.components.$format.checkbox({ fireOnInit: true, diff --git a/app/src/Controller/API/Ventas/Precios.php b/app/src/Controller/API/Ventas/Precios.php index 61f594d..cfe9b6e 100644 --- a/app/src/Controller/API/Ventas/Precios.php +++ b/app/src/Controller/API/Ventas/Precios.php @@ -5,14 +5,14 @@ use DateTime; use Exception; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; +use Incoviba\Common\Ideal\Controller; use Incoviba\Common\Implement\Exception\{EmptyRedis,EmptyResult}; -use Psr\Log\LoggerInterface; use Incoviba\Controller\API\{withJson,emptyBody}; use Incoviba\Controller\withRedis; use Incoviba\Exception\ServiceAction\Create; use Incoviba\Service; -class Precios +class Precios extends Controller { use withJson, emptyBody, withRedis; @@ -56,7 +56,6 @@ class Precios } public function import(ServerRequestInterface $request, ResponseInterface $response, - LoggerInterface $logger, Service\Venta\Precio $precioService): ResponseInterface { $body = $request->getParsedBody(); @@ -79,7 +78,7 @@ class Precios $output['total'] = count($output['precios']); $output['status'] = true; } catch (Create | Exception $exception) { - $logger->warning($exception); + $this->logger->warning($exception); } return $this->withJson($response, $output); }