Fecha cuota
This commit is contained in:
@ -76,6 +76,9 @@
|
||||
@if (in_array($cuota->pago->currentEstado->tipoEstadoPago->descripcion, ['abonado', 'anulado', 'reemplazado']))
|
||||
{{$cuota->pago->currentEstado->fecha->format('d-m-Y')}}
|
||||
@elseif (!in_array($cuota->pago->currentEstado->tipoEstadoPago->descripcion, ['anulado', 'reemplazado']))
|
||||
@if ($cuota->pago->currentEstado->tipoEstadoPago->descripcion === 'depositado')
|
||||
{{$cuota->pago->currentEstado->fecha->format('d-m-Y')}}
|
||||
@endif
|
||||
<div class="ui calendar fecha_estado" data-date="{{$cuota->pago->currentEstado->fecha->format('Y-m-d')}}">
|
||||
<div class="ui action left icon input">
|
||||
<i class="calendar icon"></i>
|
||||
@ -169,9 +172,10 @@
|
||||
@push('page_scripts')
|
||||
<script type="text/javascript">
|
||||
$(document).ready(() => {
|
||||
function updateRow({pago_id, fecha, color, estado, remove_fecha=false, add_reject=false, disable=false}) {
|
||||
function updateRow({pago_id, valor, fecha, color, estado, remove_fecha=false, add_reject=false, disable=false}) {
|
||||
const tr = $("tr[data-pago='" + pago_id + "']")
|
||||
|
||||
tr.find(':nth-child(6)').html(valor)
|
||||
tr.find(':nth-child(7)').attr('class', color).html(estado)
|
||||
if (remove_fecha) {
|
||||
tr.find(':nth-child(8)').html(fecha)
|
||||
@ -206,7 +210,7 @@
|
||||
if (!json.depositado) {
|
||||
return
|
||||
}
|
||||
updateRow({pago_id: json.pago_id, fecha: json.input.fecha, estado: 'Depositado', color: 'yellow', add_reject: true})
|
||||
updateRow({pago_id: json.pago_id, valor: json.pago.valor_uf, fecha: json.input.fecha, estado: 'Depositado', color: 'yellow', add_reject: true})
|
||||
button.attr('data-estado', 'depositado')
|
||||
})
|
||||
})
|
||||
@ -214,7 +218,7 @@
|
||||
function abonar(pago_id, fecha) {
|
||||
const url = '{{$urls->api}}/ventas/pago/' + pago_id + '/abonar'
|
||||
const body = new FormData()
|
||||
body.set('fecha', fecha.toISOString())
|
||||
body.set('fecha', [fecha.getFullYear(), fecha.getMonth() + 1, fecha.getDate()].join('-'))
|
||||
return fetchAPI(url, {method: 'post', body}).then(response => {
|
||||
if (!response) {
|
||||
return
|
||||
|
@ -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