Optimizacion de monedas
This commit is contained in:
@ -97,4 +97,45 @@ class Money
|
||||
$output['ipc'] = $ipcService->get($start, $end);
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function getMany(ServerRequestInterface $request, ResponseInterface $response, Service\Redis $redisService,
|
||||
Service\Money $moneyService): ResponseInterface
|
||||
{
|
||||
$input = $request->getParsedBody();
|
||||
$output = [
|
||||
'input' => $input,
|
||||
'values' => []
|
||||
];
|
||||
$data = json_decode($input['dates']);
|
||||
$ufs = [];
|
||||
$ipcs = [];
|
||||
try {
|
||||
$ufs = (array) $this->fetchRedis($redisService, 'ufs');
|
||||
} catch (EmptyRedis) {}
|
||||
try {
|
||||
$ipcs = (array) $this->fetchRedis($redisService, 'ipcs');
|
||||
} catch (EmptyRedis) {}
|
||||
foreach ($data as $date) {
|
||||
if ($date->type === 'uf') {
|
||||
if (!in_array($date->date, $ufs)) {
|
||||
$uf = $moneyService->getUF(new DateTimeImmutable($date->date));
|
||||
$ufs[$date->date] = $uf;
|
||||
}
|
||||
$date->value = $ufs[$date->date];
|
||||
$output['values'] []= $date;
|
||||
continue;
|
||||
}
|
||||
if ($date->type === 'ipc') {
|
||||
$dateString = "{$date->start}|{$date->end}";
|
||||
if (!in_array($dateString, $ipcs)) {
|
||||
$ipc = $moneyService->getIPC(new DateTimeImmutable($date->start), new DateTimeImmutable($date->end));
|
||||
$ipcs[$dateString] = $ipc;
|
||||
}
|
||||
$date->value = $ipcs[$dateString];
|
||||
$output['values'] []= $date;
|
||||
}
|
||||
}
|
||||
$this->saveRedis($redisService, 'ufs', $ufs, $this->time);
|
||||
$this->saveRedis($redisService, 'ipcs', $ipcs, $this->time);
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
}
|
||||
|
@ -43,6 +43,9 @@ class Money
|
||||
}
|
||||
public function getIPC(DateTimeInterface $start, DateTimeInterface $end): float
|
||||
{
|
||||
if ($start >= $end) {
|
||||
return 0;
|
||||
}
|
||||
try {
|
||||
return $this->getProvider('ipc')->getVar($start, $end);
|
||||
} catch (EmptyResponse) {
|
||||
|
@ -110,6 +110,7 @@ class Venta extends Service
|
||||
'tipo' => ucwords($unidad->proyectoTipoUnidad->tipoUnidad->descripcion),
|
||||
'descripcion' => $unidad->descripcion,
|
||||
'prorrateo' => $unidad->prorrateo,
|
||||
'valor' => $unidad->valor,
|
||||
'precio' => (isset($unidad->currentPrecio)) ? $unidad->currentPrecio->valor : 0
|
||||
];
|
||||
}
|
||||
|
Reference in New Issue
Block a user