Editar cuota
This commit is contained in:
@ -43,7 +43,8 @@ class Pagos
|
||||
$output = [
|
||||
'input' => $body,
|
||||
'pago_id' => $pago_id,
|
||||
'pago' => null
|
||||
'pago' => null,
|
||||
'editado' => false
|
||||
];
|
||||
try {
|
||||
$pago = $pagoRepository->fetchById($pago_id);
|
||||
@ -52,6 +53,7 @@ class Pagos
|
||||
$body['fecha'] = $fecha->format('Y-m-d');
|
||||
}
|
||||
$output['pago'] = $pagoRepository->edit($pago, $body);
|
||||
$output['editado'] = true;
|
||||
} catch (EmptyResult) {}
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
|
@ -98,6 +98,7 @@ class Ventas
|
||||
return $view->render($response, 'ventas.add', compact('regiones', 'proyectos'));
|
||||
}
|
||||
public function cuotas(ServerRequestInterface $request, ResponseInterface $response, Service\Venta $ventaService,
|
||||
Service\Contabilidad\Banco $bancoService,
|
||||
View $view, int $venta_id): ResponseInterface
|
||||
{
|
||||
$venta = $ventaService->getById($venta_id);
|
||||
@ -119,7 +120,11 @@ class Ventas
|
||||
$asociadas []= $ventaService->getByPie($asociado->id);
|
||||
}
|
||||
}
|
||||
return $view->render($response, 'ventas.pies.cuotas', compact('venta', 'asociadas'));
|
||||
$bancos = $bancoService->getAll();
|
||||
usort($bancos, function($a, $b) {
|
||||
return strcmp($a->nombre, $b->nombre);
|
||||
});
|
||||
return $view->render($response, 'ventas.pies.cuotas', compact('venta', 'asociadas', 'bancos'));
|
||||
}
|
||||
public function escriturar(ServerRequestInterface $request, ResponseInterface $response, Service\Venta $ventaService,
|
||||
Repository\Contabilidad\Banco $bancoRepository, View $view, int $venta_id): ResponseInterface
|
||||
|
59
app/src/Service/Contabilidad/Banco.php
Normal file
59
app/src/Service/Contabilidad/Banco.php
Normal file
@ -0,0 +1,59 @@
|
||||
<?php
|
||||
namespace Incoviba\Service\Contabilidad;
|
||||
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Common\Implement;
|
||||
use Incoviba\Controller\withRedis;
|
||||
use Incoviba\Model;
|
||||
use Incoviba\Repository;
|
||||
use Incoviba\Service\Redis;
|
||||
|
||||
class Banco extends Ideal\Service
|
||||
{
|
||||
use withRedis;
|
||||
|
||||
public function __construct(LoggerInterface $logger, protected Repository\Contabilidad\Banco $bancoRepository,
|
||||
protected Redis $redisService)
|
||||
{
|
||||
parent::__construct($logger);
|
||||
}
|
||||
|
||||
protected string $redisKey = 'bancos';
|
||||
|
||||
public function getAll(null|string|array $ordering = null): array
|
||||
{
|
||||
try {
|
||||
return $this->fetchRedis($this->redisService, $this->redisKey);
|
||||
} catch (Implement\Exception\EmptyRedis) {
|
||||
try {
|
||||
$bancos = array_map([$this, 'process'], $this->bancoRepository->fetchAll($ordering));
|
||||
$this->saveRedis($this->redisService, $this->redisKey, $bancos);
|
||||
return $bancos;
|
||||
} catch (Implement\Exception\EmptyResult) {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
}
|
||||
public function getById(int $banco_id): ?Model\Contabilidad\Banco
|
||||
{
|
||||
try {
|
||||
$bancos = $this->getAll();
|
||||
$bancos = array_filter($bancos, fn($banco) => $banco->getId() === $banco_id);
|
||||
return array_shift($bancos);
|
||||
} catch (Implement\Exception\EmptyRedis) {
|
||||
try {
|
||||
$banco = $this->process($this->bancoRepository->fetchById($banco_id));
|
||||
$this->saveRedis($this->redisService, $this->redisKey, [$banco]);
|
||||
return $banco;
|
||||
} catch (Implement\Exception\EmptyResult) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected function process(Model\Contabilidad\Banco $banco): Model\Contabilidad\Banco
|
||||
{
|
||||
return $banco;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user