2023-07-24 20:55:26 -04:00
|
|
|
<?php
|
|
|
|
namespace Incoviba\Controller\Ventas;
|
|
|
|
|
|
|
|
use DateTimeImmutable;
|
|
|
|
use Psr\Http\Message\ResponseInterface;
|
|
|
|
use Psr\Http\Message\ServerRequestInterface;
|
2023-09-07 23:03:21 -03:00
|
|
|
use Incoviba\Common\Implement\Exception\EmptyResult;
|
2023-07-24 20:55:26 -04:00
|
|
|
use Incoviba\Common\Alias\View;
|
|
|
|
use Incoviba\Repository;
|
|
|
|
use Incoviba\Service;
|
|
|
|
|
|
|
|
class Cuotas
|
|
|
|
{
|
2023-09-07 23:03:21 -03:00
|
|
|
public function pendientes(ServerRequestInterface $request, ResponseInterface $response, View $view, Service\Venta\Cuota $cuotaService): ResponseInterface
|
2023-07-24 20:55:26 -04:00
|
|
|
{
|
2023-09-07 23:03:21 -03:00
|
|
|
$cuotas_pendientes = $cuotaService->pendientes();
|
2023-07-24 20:55:26 -04:00
|
|
|
return $view->render($response, 'ventas.cuotas.pendientes', compact('cuotas_pendientes'));
|
|
|
|
}
|
2023-09-07 23:03:21 -03:00
|
|
|
public function depositadas(ServerRequestInterface $request, ResponseInterface $response, View $view, Service\Venta\Cuota $cuotaService): ResponseInterface
|
|
|
|
{
|
|
|
|
$cuotas_depositadas = $cuotaService->depositadas();
|
|
|
|
return $view->render($response, 'ventas.cuotas.abonar', compact('cuotas_depositadas'));
|
|
|
|
}
|
2023-08-08 23:53:49 -04:00
|
|
|
public function depositar(ServerRequestInterface $request, ResponseInterface $response, Repository\Venta\Cuota $cuotaRepository, Service\Venta\Pago $pagoService): ResponseInterface
|
2023-07-24 20:55:26 -04:00
|
|
|
{
|
|
|
|
$body = $request->getBody();
|
|
|
|
$json = json_decode($body->getContents());
|
|
|
|
$cuota_id = $json->cuota_id;
|
2023-09-07 23:03:21 -03:00
|
|
|
$fecha = new DateTimeImmutable($json->fecha);
|
2023-07-24 20:55:26 -04:00
|
|
|
$output = [
|
|
|
|
'cuota_id' => $cuota_id,
|
2023-08-08 23:53:49 -04:00
|
|
|
'depositada' => false
|
2023-07-24 20:55:26 -04:00
|
|
|
];
|
2023-08-08 23:53:49 -04:00
|
|
|
try{
|
|
|
|
$cuota = $cuotaRepository->fetchById($cuota_id);
|
2023-09-07 23:03:21 -03:00
|
|
|
$output['depositada'] = $pagoService->depositar($cuota->pago, $fecha);
|
|
|
|
} catch (EmptyResult) {}
|
|
|
|
$response->getBody()->write(json_encode($output));
|
|
|
|
return $response->withHeader('Content-Type', 'application/json');
|
|
|
|
}
|
|
|
|
public function abonar(ServerRequestInterface $request, ResponseInterface $response, Repository\Venta\Cuota $cuotaRepository, Service\Venta\Pago $pagoService): ResponseInterface
|
|
|
|
{
|
|
|
|
$body = $request->getBody();
|
|
|
|
$json = json_decode($body->getContents());
|
|
|
|
$cuota_id = $json->cuota_id;
|
|
|
|
$fecha = new DateTimeImmutable($json->fecha);
|
|
|
|
$output = [
|
|
|
|
'cuota_id' => $cuota_id,
|
|
|
|
'abonada' => false
|
|
|
|
];
|
|
|
|
try{
|
|
|
|
$cuota = $cuotaRepository->fetchById($cuota_id);
|
|
|
|
$output['abonada'] = $pagoService->abonar($cuota->pago, $fecha);
|
|
|
|
} catch (EmptyResult) {}
|
|
|
|
$response->getBody()->write(json_encode($output));
|
|
|
|
return $response->withHeader('Content-Type', 'application/json');
|
|
|
|
}
|
|
|
|
public function devolver(ServerRequestInterface $request, ResponseInterface $response, Repository\Venta\Cuota $cuotaRepository, Service\Venta\Pago $pagoService): ResponseInterface
|
|
|
|
{
|
|
|
|
$body = $request->getBody();
|
|
|
|
$json = json_decode($body->getContents());
|
|
|
|
$cuota_id = $json->cuota_id;
|
|
|
|
$fecha = new DateTimeImmutable($json->fecha);
|
|
|
|
$output = [
|
|
|
|
'cuota_id' => $cuota_id,
|
|
|
|
'devuelta' => false
|
|
|
|
];
|
|
|
|
try{
|
|
|
|
$cuota = $cuotaRepository->fetchById($cuota_id);
|
|
|
|
$output['devuelta'] = $pagoService->devolver($cuota->pago, $fecha);
|
2023-08-08 23:53:49 -04:00
|
|
|
} catch (EmptyResult) {}
|
2023-07-24 20:55:26 -04:00
|
|
|
$response->getBody()->write(json_encode($output));
|
|
|
|
return $response->withHeader('Content-Type', 'application/json');
|
|
|
|
}
|
|
|
|
}
|