Fecha cuota
This commit is contained in:
@ -13,6 +13,19 @@ class Pagos
|
||||
{
|
||||
use withJson;
|
||||
|
||||
public function get(ServerRequestInterface $request, ResponseInterface $response, Service\Venta\Pago $pagoService,
|
||||
Service\Format $formatService, int $pago_id): ResponseInterface
|
||||
{
|
||||
$output = [
|
||||
'pago_id' => $pago_id,
|
||||
'pago' => null
|
||||
];
|
||||
try {
|
||||
$output['pago'] = json_decode(json_encode($pagoService->getById($pago_id)), JSON_OBJECT_AS_ARRAY);
|
||||
$output['pago']['valor_uf'] = $formatService->ufs($output['pago']['valor_uf']);
|
||||
} catch (EmptyResult) {}
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function edit(ServerRequestInterface $request, ResponseInterface $response, Repository\Venta\Pago $pagoRepository, int $pago_id): ResponseInterface
|
||||
{
|
||||
$body = $request->getParsedBody();
|
||||
@ -31,33 +44,41 @@ class Pagos
|
||||
} catch (EmptyResult) {}
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function depositar(ServerRequestInterface $request, ResponseInterface $response, Service\Venta\Pago $pagoService, int $pago_id): ResponseInterface
|
||||
public function depositar(ServerRequestInterface $request, ResponseInterface $response,
|
||||
Service\Venta\Pago $pagoService, Service\Format $formatService, int $pago_id): ResponseInterface
|
||||
{
|
||||
$body = $request->getParsedBody();
|
||||
$output = [
|
||||
'pago_id' => $pago_id,
|
||||
'input' => $body,
|
||||
'pago' => null,
|
||||
'depositado' => false
|
||||
];
|
||||
try {
|
||||
$pago = $pagoService->getById($pago_id);
|
||||
$fecha = new DateTimeImmutable($body->fecha);
|
||||
$fecha = new DateTimeImmutable($body['fecha']);
|
||||
$output['depositado'] = $pagoService->depositar($pago, $fecha);
|
||||
$output['pago'] = json_decode(json_encode($pagoService->getById($pago_id)), JSON_OBJECT_AS_ARRAY);
|
||||
$output['pago']['valor_uf'] = $formatService->ufs($output['pago']['valor_uf']);
|
||||
} catch (EmptyResult) {}
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function abonar(ServerRequestInterface $request, ResponseInterface $response, Service\Venta\Pago $pagoService, int $pago_id): ResponseInterface
|
||||
public function abonar(ServerRequestInterface $request, ResponseInterface $response, Service\Venta\Pago $pagoService,
|
||||
Service\Format $formatService, int $pago_id): ResponseInterface
|
||||
{
|
||||
$body = $request->getParsedBody();
|
||||
$output = [
|
||||
'pago_id' => $pago_id,
|
||||
'input' => $body,
|
||||
'pago' => null,
|
||||
'abonado' => false
|
||||
];
|
||||
try {
|
||||
$pago = $pagoService->getById($pago_id);
|
||||
$fecha = new DateTimeImmutable($body->fecha);
|
||||
$fecha = new DateTimeImmutable($body['fecha']);
|
||||
$output['abonado'] = $pagoService->abonar($pago, $fecha);
|
||||
$output['pago'] = json_decode(json_encode($pagoService->getById($pago_id)), JSON_OBJECT_AS_ARRAY);
|
||||
$output['pago']['valor_uf'] = $formatService->ufs($output['pago']['valor_uf']);
|
||||
$output['input']['fecha'] = $fecha->format('d-m-Y');
|
||||
} catch (EmptyResult) {}
|
||||
return $this->withJson($response, $output);
|
||||
|
@ -98,7 +98,6 @@ class Ventas
|
||||
return $view->render($response, 'ventas.add', compact('regiones', 'proyectos'));
|
||||
}
|
||||
public function cuotas(ServerRequestInterface $request, ResponseInterface $response, Service\Venta $ventaService,
|
||||
Repository\Venta $ventaRepository,
|
||||
View $view, int $venta_id): ResponseInterface
|
||||
{
|
||||
$venta = $ventaService->getById($venta_id);
|
||||
@ -112,6 +111,11 @@ class Ventas
|
||||
$asociadas []= $ventaService->getByPie($asociado->id);
|
||||
}
|
||||
}
|
||||
if (count($venta->formaPago()->pie->asociados()) > 0) {
|
||||
foreach ($venta->formaPago()->pie->asociados() as $asociado) {
|
||||
$asociadas []= $ventaService->getByPie($asociado->id);
|
||||
}
|
||||
}
|
||||
return $view->render($response, 'ventas.pies.cuotas', compact('venta', 'asociadas'));
|
||||
}
|
||||
public function escriturar(ServerRequestInterface $request, ResponseInterface $response, Service\Venta $ventaService,
|
||||
|
@ -28,10 +28,27 @@ class Pago extends Model
|
||||
return $this->valor / (($moneda === Pago::UF) ? $uf : 1);
|
||||
}
|
||||
|
||||
public function estado(?string $tipoEstado = null): ?EstadoPago
|
||||
{
|
||||
if (!isset($this->estados)) {
|
||||
return null;
|
||||
}
|
||||
if ($tipoEstado === null) {
|
||||
return $this->currentEstado;
|
||||
}
|
||||
foreach ($this->estados as $estado) {
|
||||
if ($estado->tipoEstado->descripcion === $tipoEstado) {
|
||||
return $estado;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public function jsonSerialize(): mixed
|
||||
{
|
||||
return array_merge(parent::jsonSerialize(), [
|
||||
'valor' => $this->valor,
|
||||
'valor_uf' => $this->valor(),
|
||||
'banco' => $this->banco ?? '',
|
||||
'tipo_pago' => $this->tipoPago ?? '',
|
||||
'identificador' => $this->identificador ?? '',
|
||||
|
@ -2,12 +2,10 @@
|
||||
namespace Incoviba\Service;
|
||||
|
||||
use DateTimeInterface;
|
||||
use DateTimeImmutable;
|
||||
use DateInterval;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Incoviba\Common\Define\Money\Provider;
|
||||
use Incoviba\Common\Implement\Exception\EmptyResponse;
|
||||
use Incoviba\Service\Money\MiIndicador;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
class Money
|
||||
{
|
||||
@ -30,7 +28,6 @@ class Money
|
||||
public function get(string $provider, DateTimeInterface $dateTime): float
|
||||
{
|
||||
try {
|
||||
$upper = strtoupper($provider);
|
||||
return $this->getProvider($provider)->get(MiIndicador::getSymbol($provider), $dateTime);
|
||||
} catch (EmptyResponse) {
|
||||
return 0;
|
||||
|
@ -16,7 +16,7 @@ class Pago
|
||||
protected Repository\Venta\Pago $pagoRepository,
|
||||
protected Repository\Venta\EstadoPago $estadoPagoRepository,
|
||||
protected Repository\Venta\TipoEstadoPago $tipoEstadoPagoRepository,
|
||||
protected Service\Money $moneyService
|
||||
protected Service\UF $ufService
|
||||
) {}
|
||||
|
||||
public function depositar(Model\Venta\Pago $pago, DateTimeInterface $fecha): bool
|
||||
@ -118,7 +118,7 @@ class Pago
|
||||
public function add(array $data): Model\Venta\Pago
|
||||
{
|
||||
if (!isset($data['uf'])) {
|
||||
$data['uf'] = $this->moneyService->getUF(new DateTimeImmutable($data['fecha']));
|
||||
$data['uf'] = $this->ufService->get(new DateTimeImmutable($data['fecha']));
|
||||
}
|
||||
$fields = array_fill_keys([
|
||||
'valor',
|
||||
@ -157,15 +157,19 @@ class Pago
|
||||
{
|
||||
$pago->estados = $this->estadoPagoRepository->fetchByPago($pago->id);
|
||||
$pago->currentEstado = $this->estadoPagoRepository->fetchCurrentByPago($pago->id);
|
||||
$pago->uf = $this->getUF($pago);
|
||||
if ($pago->uf === null or $pago->uf === 0.0) {
|
||||
$pago->uf = $this->getUF($pago);
|
||||
}
|
||||
return $pago;
|
||||
}
|
||||
protected function getUF(Model\Venta\Pago $pago): ?float
|
||||
{
|
||||
if (($pago->uf === null or $pago->uf === 0.0)
|
||||
and in_array($pago->currentEstado->tipoEstadoPago->descripcion, ['depositado', 'abonado'])
|
||||
if (in_array($pago->currentEstado->tipoEstadoPago->descripcion, ['depositado', 'abonado'])
|
||||
and $pago->currentEstado->fecha <= new DateTimeImmutable()) {
|
||||
$uf = $this->moneyService->getUF($pago->currentEstado->fecha);
|
||||
$uf = $this->ufService->get($pago->currentEstado->fecha);
|
||||
if ($pago->uf === $uf) {
|
||||
return $uf;
|
||||
}
|
||||
if ($uf !== 0.0) {
|
||||
$this->pagoRepository->edit($pago, ['uf' => $uf]);
|
||||
return $uf;
|
||||
|
Reference in New Issue
Block a user