Agregar y editar abono cuotas.
This commit is contained in:
60
app/src/Controller/API/Ventas/Abonos/Cuotas.php
Normal file
60
app/src/Controller/API/Ventas/Abonos/Cuotas.php
Normal file
@ -0,0 +1,60 @@
|
||||
<?php
|
||||
namespace Incoviba\Controller\API\Ventas\Abonos;
|
||||
|
||||
use DateTimeImmutable;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Common\Implement;
|
||||
use Incoviba\Controller\API;
|
||||
use Incoviba\Repository;
|
||||
use Incoviba\Service;
|
||||
|
||||
class Cuotas extends Ideal\Controller
|
||||
{
|
||||
use API\withJson;
|
||||
|
||||
public function add(ServerRequestInterface $request, ResponseInterface $response,
|
||||
Service\Venta\Pago $pagoService,
|
||||
Service\UF $ufService,
|
||||
Service\Valor $valorService,
|
||||
Repository\Venta\Abono\Cuota $cuotaRepository): ResponseInterface
|
||||
{
|
||||
$input = $request->getParsedBody();
|
||||
$output = [
|
||||
'input' => $input,
|
||||
'cuota' => null,
|
||||
'success' => false,
|
||||
];
|
||||
try {
|
||||
$input['valor'] = $valorService->clean($input['valor']);
|
||||
if (isset($input['uf']) and !empty($input['uf'])) {
|
||||
$uf = $ufService->get(new DateTimeImmutable($input['fecha']));
|
||||
$input['valor'] = $uf * $valorService->clean($input['uf']);
|
||||
}
|
||||
$pagoData = array_intersect_key($input, array_flip(['fecha', 'valor']));
|
||||
$pago = $pagoService->add($pagoData);
|
||||
$cuotaData = array_intersect_key($input, array_flip(['venta_id', 'numero']));
|
||||
$cuotaData['pago_id'] = $pago->id;
|
||||
$cuota = $cuotaRepository->create($cuotaData);
|
||||
$output['cuota'] = $cuotaRepository->save($cuota);
|
||||
$output['success'] = true;
|
||||
} catch (Implement\Exception\EmptyResult) {}
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function edit(ServerRequestInterface $request, ResponseInterface $response, Repository\Venta\Abono\Cuota $cuotaRepository, int $cuota_id): ResponseInterface
|
||||
{
|
||||
$input = $request->getParsedBody();
|
||||
$output = [
|
||||
'input' => $input,
|
||||
'cuota' => null,
|
||||
'success' => false,
|
||||
];
|
||||
try {
|
||||
$cuota = $cuotaRepository->fetchById($cuota_id);
|
||||
$output['cuota'] = $cuotaRepository->edit($cuota, $input);
|
||||
$output['success'] = true;
|
||||
} catch (Implement\Exception\EmptyResult) {}
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
}
|
@ -12,6 +12,7 @@ class Cuotas
|
||||
{
|
||||
public function __invoke(ServerRequestInterface $request, ResponseInterface $response,
|
||||
Service\Venta $ventaService,
|
||||
Repository\Venta\TipoEstadoPago $estadoPagoRepository,
|
||||
Repository\Venta\Abono\Cuota $cuotaRepository, View $view, int $venta_id): ResponseInterface
|
||||
{
|
||||
$venta = null;
|
||||
@ -22,6 +23,10 @@ class Cuotas
|
||||
try {
|
||||
$cuotas = $cuotaRepository->fetchByVenta($venta_id);
|
||||
} catch (EmptyResult $e) {}
|
||||
return $view->render($response, 'ventas.escrituras.abono.cuotas', compact('venta', 'cuotas'));
|
||||
$estados = [];
|
||||
try {
|
||||
$estados = $estadoPagoRepository->fetchAll();
|
||||
} catch (EmptyResult $e) {}
|
||||
return $view->render($response, 'ventas.escrituras.abono.cuotas', compact('venta', 'cuotas', 'estados'));
|
||||
}
|
||||
}
|
||||
|
@ -10,10 +10,12 @@ use Psr\Http\Message\ServerRequestInterface;
|
||||
class Escrituras
|
||||
{
|
||||
public function show(ServerRequestInterface $request, ResponseInterface $response, View $view,
|
||||
Repository\Venta\TipoEstadoPago $estadoPagoRepository,
|
||||
Service\Venta $ventaService, int $venta_id): ResponseInterface
|
||||
{
|
||||
$venta = $ventaService->getById($venta_id);
|
||||
return $view->render($response, 'ventas.escrituras.show', compact('venta'));
|
||||
$estados = $estadoPagoRepository->fetchAll();
|
||||
return $view->render($response, 'ventas.escrituras.show', compact('venta', 'estados'));
|
||||
}
|
||||
public function informe(ServerRequestInterface $request, ResponseInterface $response, View $view,
|
||||
Service\Venta $ventaService, int $venta_id): ResponseInterface
|
||||
|
@ -7,11 +7,12 @@ use Incoviba\Common\Implement;
|
||||
use Incoviba\Common\Implement\Exception\EmptyResult;
|
||||
use Incoviba\Model;
|
||||
use Incoviba\Repository;
|
||||
use Incoviba\Service;
|
||||
|
||||
class Cuota extends Ideal\Repository
|
||||
{
|
||||
public function __construct(Define\Connection $connection, protected Repository\Venta $ventaRepository,
|
||||
protected Repository\Venta\Pago $pagoRepository)
|
||||
protected Service\Venta\Pago $pagoService)
|
||||
{
|
||||
parent::__construct($connection);
|
||||
$this->setTable('venta_abono_cuotas');
|
||||
@ -29,7 +30,7 @@ class Cuota extends Ideal\Repository
|
||||
->register('pago_id', (new Implement\Repository\Mapper())
|
||||
->setProperty('pago')
|
||||
->setFunction(function($data) {
|
||||
return $this->pagoRepository->fetchById($data['pago_id']);
|
||||
return $this->pagoService->getById($data['pago_id']);
|
||||
})
|
||||
);
|
||||
return $this->parseData(new Model\Venta\Abono\Cuota(), $data, $map);
|
||||
|
Reference in New Issue
Block a user