Agregar Pie
This commit is contained in:
@ -5,7 +5,8 @@ use Psr\Http\Message\ServerRequestInterface;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Incoviba\Controller\API\{withJson, emptyBody};
|
||||
use Incoviba\Controller\withRedis;
|
||||
use Incoviba\Common\Implement\Exception\{EmptyRedis, EmptyResult};
|
||||
use Incoviba\Common\Implement\Exception\EmptyResult;
|
||||
use Incoviba\Exception\ServiceAction\{Create, Read, Update};
|
||||
use Incoviba\Service;
|
||||
|
||||
class Pies
|
||||
@ -27,4 +28,35 @@ class Pies
|
||||
} catch (EmptyResult) {}
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function add(ServerRequestInterface $request, ResponseInterface $response, Service\Venta $ventaService,
|
||||
Service\Venta\Pie $pieService, int $venta_id): ResponseInterface
|
||||
{
|
||||
$input = $request->getParsedBody();
|
||||
$output = [
|
||||
'venta_id' => $venta_id,
|
||||
'input' => $input,
|
||||
'pie' => null,
|
||||
'success' => false
|
||||
];
|
||||
try {
|
||||
$venta = $ventaService->getById($venta_id);
|
||||
|
||||
} catch (Read $exception) {
|
||||
return $this->withError($response, $exception);
|
||||
}
|
||||
try {
|
||||
$pie = $pieService->add($input);
|
||||
} catch (Create $exception) {
|
||||
return $this->withError($response, $exception);
|
||||
}
|
||||
try {
|
||||
$ventaService->edit($venta, ['pie' => $pie->id]);
|
||||
|
||||
$output['pie'] = $pie;
|
||||
$output['success'] = true;
|
||||
} catch (Update $exception) {
|
||||
return $this->withError($response, $exception);
|
||||
}
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
}
|
||||
|
@ -1,12 +1,12 @@
|
||||
<?php
|
||||
namespace Incoviba\Controller\Ventas;
|
||||
|
||||
use Incoviba\Common\Alias\View;
|
||||
use Incoviba\Model;
|
||||
use Incoviba\Repository;
|
||||
use Incoviba\Service;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Incoviba\Common\Alias\View;
|
||||
use Incoviba\Exception\ServiceAction\Read;
|
||||
use Incoviba\Repository;
|
||||
use Incoviba\Service;
|
||||
|
||||
class Pies
|
||||
{
|
||||
@ -21,4 +21,13 @@ class Pies
|
||||
$estados = $tipoEstadoPagoRepository->fetchAll('descripcion');
|
||||
return $view->render($response, 'ventas.pies.cuotas', compact('pie', 'venta', 'bancos', 'estados', 'ventaRepository'));
|
||||
}
|
||||
public function add(ServerRequestInterface $request, ResponseInterface $response, Service\Venta $ventaService,
|
||||
View $view, int $venta_id): ResponseInterface
|
||||
{
|
||||
$venta = null;
|
||||
try {
|
||||
$venta = $ventaService->getById($venta_id);
|
||||
} catch (Read) {}
|
||||
return $view->render($response, 'ventas.pies.add', compact('venta'));
|
||||
}
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ namespace Incoviba\Service;
|
||||
use Exception;
|
||||
use DateTimeImmutable;
|
||||
use DateMalformedStringException;
|
||||
use Incoviba\Exception\ServiceAction\{Read, Update};
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Incoviba\Common\Ideal\Service;
|
||||
use Incoviba\Common\Implement;
|
||||
@ -36,9 +37,18 @@ class Venta extends Service
|
||||
parent::__construct($logger);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $venta_id
|
||||
* @return Model\Venta
|
||||
* @throws Read
|
||||
*/
|
||||
public function getById(int $venta_id): Model\Venta
|
||||
{
|
||||
return $this->process($this->ventaRepository->fetchById($venta_id));
|
||||
try {
|
||||
return $this->process($this->ventaRepository->fetchById($venta_id));
|
||||
} catch (Implement\Exception\EmptyResult $exception) {
|
||||
throw new Read(__CLASS__, $exception);
|
||||
}
|
||||
}
|
||||
public function getByProyecto(int $proyecto_id): array
|
||||
{
|
||||
@ -285,6 +295,22 @@ class Venta extends Service
|
||||
return $this->formaPagoService->add($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Model\Venta $venta
|
||||
* @param array $data
|
||||
* @return Model\Venta
|
||||
* @throws Update
|
||||
*/
|
||||
public function edit(Model\Venta $venta, array $data): Model\Venta
|
||||
{
|
||||
try {
|
||||
$filteredData = $this->ventaRepository->filterData($data);
|
||||
return $this->ventaRepository->edit($venta, $filteredData);
|
||||
} catch (Implement\Exception\EmptyResult $exception) {
|
||||
throw new Update(__CLASS__, $exception);
|
||||
}
|
||||
}
|
||||
|
||||
protected function addEstado(Model\Venta $venta, Model\Venta\TipoEstadoVenta $tipoEstadoVenta, array $data): void
|
||||
{
|
||||
try {
|
||||
|
@ -1,17 +1,22 @@
|
||||
<?php
|
||||
namespace Incoviba\Service\Venta;
|
||||
|
||||
use PDOException;
|
||||
use DateTimeImmutable;
|
||||
use DateMalformedStringException;
|
||||
use Incoviba\Common\Implement\Exception\EmptyResult;
|
||||
use Incoviba\Exception\ServiceAction\Read;
|
||||
use Incoviba\Repository;
|
||||
use Incoviba\Exception\ServiceAction\{Create, Read};
|
||||
use Incoviba\Model;
|
||||
use Incoviba\Repository;
|
||||
use Incoviba\Service\UF;
|
||||
|
||||
class Pie
|
||||
{
|
||||
public function __construct(
|
||||
protected Repository\Venta\Pie $pieRepository,
|
||||
protected Cuota $cuotaService,
|
||||
protected Pago $pagoService
|
||||
protected Pago $pagoService,
|
||||
protected UF $ufService
|
||||
) {}
|
||||
|
||||
public function getById(int $pie_id): Model\Venta\Pie
|
||||
@ -27,11 +32,26 @@ class Pie
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
* @return Model\Venta\Pie
|
||||
* @throws Create
|
||||
*/
|
||||
public function add(array $data): Model\Venta\Pie
|
||||
{
|
||||
$filteredData = $this->pieRepository->filterData($data);
|
||||
$pie = $this->pieRepository->create($filteredData);
|
||||
return $this->pieRepository->save($pie);
|
||||
try {
|
||||
$filteredData = $this->pieRepository->filterData($data);
|
||||
if (!isset($filteredData['uf'])) {
|
||||
try {
|
||||
$date = new DateTimeImmutable($filteredData['fecha']);
|
||||
$filteredData['uf'] = $this->ufService->get($date);
|
||||
} catch (DateMalformedStringException) {}
|
||||
}
|
||||
$pie = $this->pieRepository->create($filteredData);
|
||||
return $this->pieRepository->save($pie);
|
||||
} catch (PDOException $exception) {
|
||||
throw new Create(__CLASS__, $exception);
|
||||
}
|
||||
}
|
||||
public function addCuota(array $data): Model\Venta\Cuota
|
||||
{
|
||||
|
Reference in New Issue
Block a user