37 lines
1.3 KiB
PHP
37 lines
1.3 KiB
PHP
|
<?php
|
||
|
namespace Incoviba\Controller\API\Ventas;
|
||
|
|
||
|
use Psr\Http\Message\ResponseInterface;
|
||
|
use Psr\Http\Message\ServerRequestInterface;
|
||
|
use Incoviba\Common\Implement\Exception\EmptyResult;
|
||
|
use Incoviba\Controller\API;
|
||
|
use Incoviba\Service;
|
||
|
|
||
|
class Precios
|
||
|
{
|
||
|
use API\withJson, API\emptyBody;
|
||
|
|
||
|
public function proyecto(ServerRequestInterface $request, ResponseInterface $response, Service\Venta\Precio $precioService): ResponseInterface
|
||
|
{
|
||
|
$body = $request->getBody();
|
||
|
$json = json_decode($body->getContents());
|
||
|
$proyecto_id = $json->proyecto_id;
|
||
|
$output = ['total' => 0];
|
||
|
try {
|
||
|
$precios = $precioService->getByProyecto($proyecto_id);
|
||
|
$output['precios'] = $precios;
|
||
|
$output['total'] = count($precios);
|
||
|
} catch (EmptyResult) {}
|
||
|
return $this->withJson($response, $output);
|
||
|
}
|
||
|
public function unidad(ServerRequestInterface $request, ResponseInterface $response, Service\Venta\Precio $precioService, int $unidad_id): ResponseInterface
|
||
|
{
|
||
|
try {
|
||
|
$precio = $precioService->getVigenteByUnidad($unidad_id);
|
||
|
return $this->withJson($response, compact('precio'));
|
||
|
} catch (EmptyResult) {
|
||
|
return $this->emptyBody($response);
|
||
|
}
|
||
|
}
|
||
|
}
|