Implement movimientos cuotas

This commit is contained in:
2024-01-08 21:24:34 -03:00
parent d225011ae9
commit 6393a1fced
4 changed files with 222 additions and 36 deletions

View File

@ -31,23 +31,52 @@ class Pagos
} catch (EmptyResult) {}
return $this->withJson($response, $output);
}
// NOT IMPLEMENTED
public function depositar(ServerRequestInterface $request, ResponseInterface $response, Service\Venta\Pago $pagoService): ResponseInterface
public function depositar(ServerRequestInterface $request, ResponseInterface $response, Service\Venta\Pago $pagoService, int $pago_id): ResponseInterface
{
$body = $request->getBody();
$json = json_decode($body->getContents());
$date = new DateTimeImmutable($json->fecha);
$response->getBody()->write(json_encode(['fecha' => $date->format('d-m-Y'), 'message' => 'Not implemented']));
return $response->withHeader('Content-Type', 'application/json');
$body = $request->getParsedBody();
$output = [
'pago_id' => $pago_id,
'input' => $body,
'depositado' => false
];
try {
$pago = $pagoService->getById($pago_id);
$fecha = new DateTimeImmutable($body->fecha);
$output['depositado'] = $pagoService->depositar($pago, $fecha);
} catch (EmptyResult) {}
return $this->withJson($response, $output);
}
// NOT IMPLEMENTED
public function abonar(ServerRequestInterface $request, ResponseInterface $response, Service\Venta\Pago $pagoService): ResponseInterface
public function abonar(ServerRequestInterface $request, ResponseInterface $response, Service\Venta\Pago $pagoService, int $pago_id): ResponseInterface
{
$body = $request->getBody();
$json = json_decode($body->getContents());
$date = new DateTimeImmutable($json->fecha);
$response->getBody()->write(json_encode(['fecha' => $date->format('d-m-Y'), 'message' => 'Not implemented']));
return $response->withHeader('Content-Type', 'application/json');
$body = $request->getParsedBody();
$output = [
'pago_id' => $pago_id,
'input' => $body,
'abonado' => false
];
try {
$pago = $pagoService->getById($pago_id);
$fecha = new DateTimeImmutable($body->fecha);
$output['abonado'] = $pagoService->abonar($pago, $fecha);
$output['input']['fecha'] = $fecha->format('d-m-Y');
} catch (EmptyResult) {}
return $this->withJson($response, $output);
}
public function devolver(ServerRequestInterface $request, ResponseInterface $response, Service\Venta\Pago $pagoService, int $pago_id): ResponseInterface
{
$body = $request->getParsedBody();
$output = [
'pago_id' => $pago_id,
'input' => $body,
'devuelto' => false
];
try {
$pago = $pagoService->getById($pago_id);
$fecha = new DateTimeImmutable($body->fecha);
$output['devuelto'] = $pagoService->devolver($pago, $fecha);
$output['input']['fecha'] = $fecha->format('d-m-Y');
} catch (EmptyResult) {}
return $this->withJson($response, $output);
}
public function para_pendientes(ServerRequestInterface $request, ResponseInterface $response, Service\Venta\Pago $pagoService): ResponseInterface
{
@ -82,4 +111,19 @@ class Pagos
}
return $this->withJson($response, ['pagos' => $rebotes, 'total' => count($rebotes)]);
}
public function anular(ServerRequestInterface $request, ResponseInterface $response, Service\Venta\Pago $pagoService, int $pago_id): ResponseInterface
{
$fecha = new DateTimeImmutable();
$output = [
'pago_id' => $pago_id,
'fecha' => $fecha->format('d-m-Y'),
'anulado' => false
];
try {
$pago = $pagoService->getById($pago_id);
$output['anulado'] = $pagoService->anular($pago, $fecha);
} catch (EmptyResult) {}
return $this->withJson($response, $output);
}
}

View File

@ -67,6 +67,22 @@ class Pago
return false;
}
}
public function anular(Model\Venta\Pago $pago, DateTimeInterface $fecha): bool
{
$tipo_estado = $this->tipoEstadoPagoRepository->fetchByDescripcion('anulado');
$data = [
'pago' => $pago->id,
'estado' => $tipo_estado->id,
'fecha' => $fecha->format('Y-m-d')
];
try {
$estado = $this->estadoPagoRepository->create($data);
$this->estadoPagoRepository->save($estado);
return true;
} catch (PDOException) {
return false;
}
}
public function getById(?int $pago_id): ?Model\Venta\Pago
{
if ($pago_id === null) {