84 lines
3.0 KiB
PHP
84 lines
3.0 KiB
PHP
<?php
|
|
namespace Incoviba\Controller\API\Proyectos;
|
|
|
|
use Psr\Http\Message\ResponseInterface;
|
|
use Psr\Http\Message\ServerRequestInterface;
|
|
use Incoviba\Common\Ideal;
|
|
use Incoviba\Common\Implement;
|
|
use Incoviba\Controller\API\withJson;
|
|
use Incoviba\Controller\withRedis;
|
|
use Incoviba\Exception;
|
|
use Incoviba\Model;
|
|
use Incoviba\Repository;
|
|
use Incoviba\Service;
|
|
|
|
class Unidades extends Ideal\Controller
|
|
{
|
|
use withJson;
|
|
use withRedis;
|
|
|
|
public function precios(ServerRequestInterface $request, ResponseInterface $response,
|
|
Service\Proyecto $proyectoService,
|
|
Repository\Venta\Precio $precioRepository,
|
|
int $proyecto_id): ResponseInterface
|
|
{
|
|
$input = $request->getParsedBody();
|
|
$output = [
|
|
'proyecto_id' => $proyecto_id,
|
|
'input' => $input,
|
|
'precios' => []
|
|
];
|
|
$unidad_ids = $input['unidad_ids'];
|
|
if (is_string($unidad_ids)) {
|
|
$unidad_ids = json_decode($input['unidad_ids'], true);
|
|
}
|
|
try {
|
|
$proyecto = $proyectoService->getById($proyecto_id);
|
|
foreach ($unidad_ids as $unidad_id) {
|
|
try {
|
|
$output['precios'][] = [
|
|
'id' => $unidad_id,
|
|
'precio' => $precioRepository->fetchVigenteByUnidad((int) $unidad_id)
|
|
];
|
|
} catch (Implement\Exception\EmptyResult) {}
|
|
}
|
|
} catch (Implement\Exception\EmptyResult) {}
|
|
return $this->withJson($response, $output);
|
|
}
|
|
public function estados(ServerRequestInterface $request, ResponseInterface $response,
|
|
Service\Proyecto $proyectoService,
|
|
Repository\Venta\Unidad $unidadRepository,
|
|
int $proyecto_id): ResponseInterface
|
|
{
|
|
$input = $request->getParsedBody();
|
|
$output = [
|
|
'proyecto_id' => $proyecto_id,
|
|
'input' => $input,
|
|
'estados' => []
|
|
];
|
|
$unidad_ids = $input['unidad_ids'];
|
|
if (is_string($unidad_ids)) {
|
|
$unidad_ids = json_decode($input['unidad_ids'], true);
|
|
}
|
|
try {
|
|
$proyecto = $proyectoService->getById($proyecto_id);
|
|
foreach ($unidad_ids as $unidad_id) {
|
|
$output['estados'][] = [
|
|
'id' => $unidad_id,
|
|
'sold' => false
|
|
];
|
|
try {
|
|
$unidad = $unidadRepository->fetchById($unidad_id);
|
|
try {
|
|
$output['estados'][] = [
|
|
'id' => $unidad_id,
|
|
'sold' => $unidadRepository->fetchSoldByUnidad($unidad->id)
|
|
];
|
|
} catch (Implement\Exception\EmptyResult) {}
|
|
} catch (Implement\Exception\EmptyResult) {}
|
|
}
|
|
} catch (Implement\Exception\EmptyResult) {}
|
|
return $this->withJson($response, $output);
|
|
}
|
|
}
|