FIX: mapping of prices import
New template with filled units
This commit is contained in:
@ -13,13 +13,19 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="ui two column grid">
|
<div class="ui three column grid">
|
||||||
<div class="column">
|
<div class="column">
|
||||||
<button class="ui button" id="import_template">
|
<button class="ui button" id="import_template">
|
||||||
<i class="file icon"></i>
|
<i class="file icon"></i>
|
||||||
Descargar plantilla
|
Descargar plantilla
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="column">
|
||||||
|
<div class="ui checkbox import_filled">
|
||||||
|
<input type="checkbox" name="filled" />
|
||||||
|
<label>¿Con unidades del proyecto?</label>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
<div class="column">
|
<div class="column">
|
||||||
<div class="ui radio checkbox import_format">
|
<div class="ui radio checkbox import_format">
|
||||||
<input type="radio" name="format" value="csv" />
|
<input type="radio" name="format" value="csv" />
|
||||||
@ -58,26 +64,23 @@
|
|||||||
class ImportTemplate {
|
class ImportTemplate {
|
||||||
ids = {
|
ids = {
|
||||||
button: '',
|
button: '',
|
||||||
|
filled: '',
|
||||||
format: ''
|
format: ''
|
||||||
}
|
}
|
||||||
components = {
|
components = {
|
||||||
button: null,
|
button: null,
|
||||||
|
$filled: null,
|
||||||
$format: null
|
$format: null
|
||||||
}
|
}
|
||||||
data = {
|
data = {
|
||||||
filename: '',
|
filename: '',
|
||||||
|
filled: false,
|
||||||
format: '',
|
format: '',
|
||||||
columns: [],
|
columns: [],
|
||||||
csv: {
|
csv: {
|
||||||
separator: '',
|
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) {
|
download(event) {
|
||||||
event.preventDefault()
|
event.preventDefault()
|
||||||
|
|
||||||
@ -91,9 +94,7 @@
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
downloadCsv() {
|
downloadCsv() {
|
||||||
const data = []
|
const data = this.buildCsvData()
|
||||||
data.push(Object.keys(this.data.columns))
|
|
||||||
data.push(Object.values(this.data.columns))
|
|
||||||
const blob = new Blob([data.map(row => row.join(this.data.csv.separator)).join('\n')], {type: 'text/csv'})
|
const blob = new Blob([data.map(row => row.join(this.data.csv.separator)).join('\n')], {type: 'text/csv'})
|
||||||
const url = URL.createObjectURL(blob)
|
const url = URL.createObjectURL(blob)
|
||||||
const a = document.createElement('a')
|
const a = document.createElement('a')
|
||||||
@ -104,12 +105,43 @@
|
|||||||
}
|
}
|
||||||
downloadXlsx() {
|
downloadXlsx() {
|
||||||
const workbook = XLSX.utils.book_new()
|
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.utils.book_append_sheet(workbook, worksheet, 'Plantilla de Precios')
|
||||||
XLSX.writeFile(workbook, this.data.filename + '.xlsx', { compression: true })
|
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() {
|
constructor() {
|
||||||
this.ids.button = 'import_template'
|
this.ids.button = 'import_template'
|
||||||
|
this.ids.filled = 'import_filled'
|
||||||
this.ids.format = 'import_format'
|
this.ids.format = 'import_format'
|
||||||
|
|
||||||
this.data.filename = 'Plantilla de Precios'
|
this.data.filename = 'Plantilla de Precios'
|
||||||
@ -129,6 +161,16 @@
|
|||||||
this.components.button = document.getElementById(this.ids.button)
|
this.components.button = document.getElementById(this.ids.button)
|
||||||
this.components.button.addEventListener('click', this.download.bind(this))
|
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 = $(`.${this.ids.format}`)
|
||||||
this.components.$format.checkbox({
|
this.components.$format.checkbox({
|
||||||
fireOnInit: true,
|
fireOnInit: true,
|
||||||
|
|||||||
@ -5,14 +5,14 @@ use DateTime;
|
|||||||
use Exception;
|
use Exception;
|
||||||
use Psr\Http\Message\ResponseInterface;
|
use Psr\Http\Message\ResponseInterface;
|
||||||
use Psr\Http\Message\ServerRequestInterface;
|
use Psr\Http\Message\ServerRequestInterface;
|
||||||
|
use Incoviba\Common\Ideal\Controller;
|
||||||
use Incoviba\Common\Implement\Exception\{EmptyRedis,EmptyResult};
|
use Incoviba\Common\Implement\Exception\{EmptyRedis,EmptyResult};
|
||||||
use Psr\Log\LoggerInterface;
|
|
||||||
use Incoviba\Controller\API\{withJson,emptyBody};
|
use Incoviba\Controller\API\{withJson,emptyBody};
|
||||||
use Incoviba\Controller\withRedis;
|
use Incoviba\Controller\withRedis;
|
||||||
use Incoviba\Exception\ServiceAction\Create;
|
use Incoviba\Exception\ServiceAction\Create;
|
||||||
use Incoviba\Service;
|
use Incoviba\Service;
|
||||||
|
|
||||||
class Precios
|
class Precios extends Controller
|
||||||
{
|
{
|
||||||
use withJson, emptyBody, withRedis;
|
use withJson, emptyBody, withRedis;
|
||||||
|
|
||||||
@ -56,7 +56,6 @@ class Precios
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function import(ServerRequestInterface $request, ResponseInterface $response,
|
public function import(ServerRequestInterface $request, ResponseInterface $response,
|
||||||
LoggerInterface $logger,
|
|
||||||
Service\Venta\Precio $precioService): ResponseInterface
|
Service\Venta\Precio $precioService): ResponseInterface
|
||||||
{
|
{
|
||||||
$body = $request->getParsedBody();
|
$body = $request->getParsedBody();
|
||||||
@ -79,7 +78,7 @@ class Precios
|
|||||||
$output['total'] = count($output['precios']);
|
$output['total'] = count($output['precios']);
|
||||||
$output['status'] = true;
|
$output['status'] = true;
|
||||||
} catch (Create | Exception $exception) {
|
} catch (Create | Exception $exception) {
|
||||||
$logger->warning($exception);
|
$this->logger->warning($exception);
|
||||||
}
|
}
|
||||||
return $this->withJson($response, $output);
|
return $this->withJson($response, $output);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user