Listado de Precios para Contrato Broker
This commit is contained in:
@ -5,9 +5,11 @@ use DateTimeImmutable;
|
||||
use DateMalformedStringException;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Incoviba\Common\Implement;
|
||||
use Incoviba\Controller\API\withJson;
|
||||
use Incoviba\Service;
|
||||
use Incoviba\Exception\ServiceAction;
|
||||
use Incoviba\Repository;
|
||||
use Incoviba\Service;
|
||||
|
||||
class Contracts
|
||||
{
|
||||
@ -140,4 +142,34 @@ class Contracts
|
||||
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
|
||||
public function promotions(ServerRequestInterface $request, ResponseInterface $response,
|
||||
Service\Proyecto\Broker\Contract $contractService,
|
||||
Repository\Venta\Unidad $unitRepository,
|
||||
Repository\Venta\Promotion $promotionRepository,
|
||||
int $contract_id): ResponseInterface
|
||||
{
|
||||
$input = $request->getParsedBody();
|
||||
$output = [
|
||||
'contract_id' => $contract_id,
|
||||
'input' => $input,
|
||||
'unidades' => [],
|
||||
];
|
||||
$unit_ids = $input['unidad_ids'];
|
||||
if (is_string($unit_ids)) {
|
||||
$unit_ids = json_decode($input['unidad_ids'], true);
|
||||
}
|
||||
foreach ($unit_ids as $unit_id) {
|
||||
try {
|
||||
$unit = $unitRepository->fetchById($unit_id);
|
||||
$contractService->getById($contract_id);
|
||||
$promotion = $promotionRepository->fetchByContractAndUnit($contract_id, $unit->id);
|
||||
$output['unidades'] []= [
|
||||
'id' => $unit->id,
|
||||
'promotion' => $promotion
|
||||
];
|
||||
} catch (ServiceAction\Read | Implement\Exception\EmptyResult) {}
|
||||
}
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user