Optimizacion de obtencion de datos.
This commit is contained in:
@ -305,14 +305,14 @@
|
||||
return Promise.all(promises)
|
||||
},
|
||||
prices: progress_bar => {
|
||||
const unsold = [...units.data.units.filter(unit => !unit.sold), ...units.data.units.filter(unit => unit.sold && unit.proyecto_tipo_unidad.tipo_unidad.descripcion !== 'departamento')]
|
||||
/*const unsold = [...units.data.units.filter(unit => !unit.sold), ...units.data.units.filter(unit => unit.sold && unit.proyecto_tipo_unidad.tipo_unidad.descripcion !== 'departamento')]
|
||||
const current_total = progress_bar.progress('get total')
|
||||
progress_bar.progress('set total', current_total + unsold.length)
|
||||
progress_bar.progress('set total', current_total + unsold.length)*/
|
||||
|
||||
const chunkSize = 100
|
||||
const chunks = []
|
||||
for (let i = 0; i < unsold.length; i += chunkSize) {
|
||||
chunks.push(unsold.slice(i, i + chunkSize).map(u => u.id))
|
||||
for (let i = 0; i < units.data.units.length; i += chunkSize) {
|
||||
chunks.push(units.data.units.slice(i, i + chunkSize).map(u => u.id))
|
||||
}
|
||||
const promises = []
|
||||
const url = `{{ $urls->api }}/proyecto/{{ $contract->project->id }}/unidades/precios`
|
||||
@ -368,12 +368,13 @@
|
||||
return
|
||||
}
|
||||
const sum_precios = departamentos.map(departamento => {
|
||||
return departamento.valor
|
||||
const idx = units.data.units.findIndex(unit => unit.id === departamento.id)
|
||||
return units.data.units[idx].precio
|
||||
}).reduce((sum, precio) => sum + precio, 0)
|
||||
departamentos.forEach(departamento => {
|
||||
const idx = units.data.units.findIndex(unit => unit.id === departamento.id)
|
||||
const saldo = venta.valor - precios
|
||||
units.data.units[idx].valor = saldo / sum_precios * departamento.valor
|
||||
units.data.units[idx].valor = saldo / sum_precios * departamento.precio
|
||||
units.data.units[idx].venta = venta
|
||||
})
|
||||
})
|
||||
@ -448,7 +449,7 @@
|
||||
|
||||
const units_length = units.data.units.length
|
||||
const progress_bar = $(`#${units.ids.load_progress}`)
|
||||
progress_bar.progress({ total: units_length * 2 })
|
||||
progress_bar.progress({ total: units_length * 3 })
|
||||
|
||||
loader.hide()
|
||||
|
||||
|
@ -11,7 +11,9 @@ use Incoviba\Service;
|
||||
|
||||
class Propiedad extends Ideal\Repository
|
||||
{
|
||||
public function __construct(Define\Connection $connection, protected Service\Venta\PropiedadUnidad $propiedadUnidadService, protected Service\Venta\Unidad $unidadService)
|
||||
public function __construct(Define\Connection $connection,
|
||||
protected Service\Venta\PropiedadUnidad $propiedadUnidadService,
|
||||
protected Service\Venta\Unidad $unidadService)
|
||||
{
|
||||
parent::__construct($connection);
|
||||
$this->setTable('propiedad');
|
||||
@ -71,4 +73,21 @@ class Propiedad extends Ideal\Repository
|
||||
->where('`unidad_principal` = ? AND `estado` = 1');
|
||||
return $this->fetchOne($query, [$unidad_id]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $propiedad_id
|
||||
* @return array
|
||||
* @throws Implement\Exception\EmptyResult
|
||||
*/
|
||||
public function fetchArrayById(int $propiedad_id): array
|
||||
{
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
->select()
|
||||
->from($this->getTable())
|
||||
->where('`id` = ?')
|
||||
->limit(1);
|
||||
$propiedad = $this->fetchAsArray($query, [$propiedad_id])[0];
|
||||
$propiedad['unidades'] = $this->propiedadUnidadService->getArrayByPropiedad($propiedad_id);
|
||||
return $propiedad;
|
||||
}
|
||||
}
|
||||
|
@ -104,6 +104,26 @@ class PropiedadUnidad extends Ideal\Repository
|
||||
return $this->fetchMany($query, [$propiedad_id]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $propiedad_id
|
||||
* @return array
|
||||
* @throws Implement\Exception\EmptyResult
|
||||
*/
|
||||
public function fetchArrayByPropiedad(int $propiedad_id): array
|
||||
{
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
->select('a.id AS pu_id, a.valor, a.propiedad, unidad.*')
|
||||
->from("{$this->getTable()} a")
|
||||
->joined('INNER JOIN `unidad` ON a.`unidad` = `unidad`.`id`')
|
||||
->where('a.`propiedad` = ?')
|
||||
->group('`unidad`.`id`');
|
||||
$unidades = $this->fetchAsArray($query, [$propiedad_id]);
|
||||
array_walk($unidades, function(&$unidad) {
|
||||
$unidad['proyecto_tipo_unidad'] = json_decode(json_encode($this->proyectoTipoUnidadService->getById($unidad['pt'])), true);
|
||||
});
|
||||
return $unidades;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Define\Model $model
|
||||
* @return void
|
||||
|
@ -44,7 +44,7 @@ class Propiedad extends Service
|
||||
public function getArrayById(int $propiedad_id): array
|
||||
{
|
||||
try {
|
||||
return json_decode(json_encode($this->propiedadRepository->fetchById($propiedad_id)), true);
|
||||
return $this->propiedadRepository->fetchArrayById($propiedad_id);
|
||||
} catch (EmptyResult $exception) {
|
||||
throw new Exception\ServiceAction\Read(__CLASS__, $exception);
|
||||
}
|
||||
|
@ -42,6 +42,14 @@ class PropiedadUnidad
|
||||
return [];
|
||||
}
|
||||
}
|
||||
public function getArrayByPropiedad(int $propiedad_id): array
|
||||
{
|
||||
try {
|
||||
return $this->propiedadUnidadRepository->fetchArrayByPropiedad($propiedad_id);
|
||||
} catch (EmptyResult) {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
|
Reference in New Issue
Block a user