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

@ -7,7 +7,9 @@ $app->group('/pagos', function($app) {
$app->get('/rebotes', [Pagos::class, 'rebotes']);
});
$app->group('/pago/{pago_id:[0-9]+}', function($app) {
$app->put('/depositar[/]', [Pagos::class, 'depositar']);
$app->put('/abonar[/]', [Pagos::class, 'abonar']);
$app->post('/depositar[/]', [Pagos::class, 'depositar']);
$app->post('/abonar[/]', [Pagos::class, 'abonar']);
$app->post('/devolver[/]', [Pagos::class, 'devolver']);
$app->get('/anular[/]', [Pagos::class, 'anular']);
$app->post('[/]', [Pagos::class, 'edit']);
});

View File

@ -24,6 +24,7 @@
<th>Estado</th>
<th>Fecha Estado</th>
<th>Fecha Estado ISO</th>
<th></th>
</tr>
</thead>
<tbody>@php
@ -31,7 +32,10 @@
$uf_venta = $venta->uf === 0.0 ? $UF->get($venta->currentEstado()->fecha) : $venta->uf;
@endphp
@foreach ($venta->formaPago()->pie->cuotas() as $cuota)
<tr>
<tr data-pago="{{$cuota->pago->id}}"
@if (in_array($cuota->pago->currentEstado->tipoEstadoPago->descripcion, ['anulado', 'reemplazado']))
class="disabled"
@endif >
<td>{{$cuota->numero}}</td>
<td>{{$cuota->pago->fecha->format('d-m-Y')}}</td>
<td>{{$cuota->pago->fecha->format('Y-m-d')}}</td>
@ -53,28 +57,33 @@
@endif
>{{ucwords($cuota->pago->currentEstado->tipoEstadoPago->descripcion)}}</td>
<td>
@if ($cuota->pago->currentEstado->tipoEstadoPago->descripcion === 'abonado')
@if (in_array($cuota->pago->currentEstado->tipoEstadoPago->descripcion, ['abonado', 'anulado', 'reemplazado']))
{{$cuota->pago->currentEstado->fecha->format('d-m-Y')}}
@else
<div class="ui action input">
<div class="ui calendar fecha_estado" data-date="{{$cuota->pago->currentEstado->fecha->format('Y-m-d')}}">
<div class="ui icon input">
<i class="calendar icon"></i>
<input type="text" name="fecha_estado" />
</div>
</div>
<button class="ui green basic icon button" id="accept_estado" data-pago="{{$cuota->pago->id}}">
<i class="check icon"></i>
</button>
@if ($cuota->pago->currentEstado->tipoEstadoPago->descripcion === 'depositado')
<button class="ui red basic icon button" id="reject_estado" data-pago="{{$cuota->pago->id}}">
<i class="remove icon"></i>
@elseif (!in_array($cuota->pago->currentEstado->tipoEstadoPago->descripcion, ['anulado', 'reemplazado']))
<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>
<input type="text" name="fecha_estado" />
<button class="ui green basic icon button accept_estado" data-pago="{{$cuota->pago->id}}" data-estado="{{$cuota->pago->currentEstado->tipoEstadoPago->descripcion}}">
<i class="check icon"></i>
</button>
@endif
@if ($cuota->pago->currentEstado->tipoEstadoPago->descripcion === 'depositado')
<button class="ui red basic icon button reject_estado" data-pago="{{$cuota->pago->id}}">
<i class="remove icon"></i>
</button>
@endif
</div>
</div>
@endif
</td>
<td>{{$cuota->pago->currentEstado->fecha->format('Y-m-d')}}</td>
<td>
@if ($cuota->pago->currentEstado->tipoEstadoPago->descripcion !== 'anulado')
<button class="ui mini red icon basic button anular" data-pago="{{$cuota->pago->id}}">
<i class="remove icon"></i>
</button>
@endif
</td>
</tr>
@endforeach
</tbody>
@ -95,7 +104,7 @@
$cuota->pago->valor());
}, 0.0))}}
</th>
<th colspan="3"></th>
<th colspan="4"></th>
</tr>
<tr>
<th colspan="5">TOTAL PAGADO</th>
@ -114,7 +123,7 @@
<th class="right aligned">
{{$format->number($pagado / $total * 100, 2)}}%
</th>
<th colspan="2"></th>
<th colspan="3"></th>
</tr>
<tr>
<th colspan="5">POR PAGAR</th>
@ -127,7 +136,7 @@
<th class="right aligned">
{{$format->number(($total - $pagado) / $total * 100, 2)}}%
</th>
<th colspan="2"></th>
<th colspan="3"></th>
</tr>
</tfoot>
</table>
@ -139,12 +148,127 @@
@push('page_scripts')
<script type="text/javascript">
$(document).ready(() => {
function updateRow({pago_id, fecha, color, estado, remove_fecha=false, add_reject=false, disable=false}) {
const tr = $("tr[data-pago='" + pago_id + "']")
tr.find(':nth-child(7)').attr('class', color).html(estado)
if (remove_fecha) {
tr.find(':nth-child(8)').html(fecha)
}
if (add_reject) {
tr.find(':nth-child(8)>.calendar>.input').append(
$('<button></button>').addClass('ui red basic icon button reject_estado').attr('data-pago', pago_id).append(
$('<i></i>').addClass('remove icon')
).click(event => {
const target = $(event.currentTarget)
const pago_id = target.data('pago')
const fecha = target.parent().parent().calendar('get date')
devolver(target, pago_id, fecha)
})
)
}
if (disable) {
tr.addClass('disabled')
tr.find(':nth-child(9)').html('')
}
return tr
}
function depositar(button, pago_id, fecha) {
const url = '{{$urls->api}}/ventas/pago/' + pago_id + '/depositar'
const body = new FormData()
body.set('fecha', fecha.toISOString())
return fetchAPI(url, {method: 'post', body}).then(response => {
if (!response) {
return
}
return response.json().then(json => {
if (!json.depositado) {
return
}
updateRow({pago_id: json.pago_id, fecha: json.input.fecha, estado: 'Depositado', color: 'yellow', add_reject: true})
button.attr('data-estado', 'depositado')
})
})
}
function abonar(pago_id, fecha) {
const url = '{{$urls->api}}/ventas/pago/' + pago_id + '/abonar'
const body = new FormData()
body.set('fecha', fecha.toISOString())
return fetchAPI(url, {method: 'post', body}).then(response => {
if (!response) {
return
}
return response.json().then(json => {
if (!json.abonado) {
return
}
updateRow({pago_id: json.pago_id, fecha: json.input.fecha, estado: 'Abonado', color: 'green', remove_fecha: true})
})
})
}
function anular(pago_id) {
const url = '{{$urls->api}}/ventas/pago/' + pago_id + '/anular'
return fetchAPI(url).then(response => {
if (!response) {
return
}
return response.json().then(json => {
if (!json.anulado) {
return
}
updateRow({pago_id: json.pago_id, fecha: json.fecha, estado: 'Anulado', color: 'red', remove_fecha: true, disable: true})
/*const tr = $("button[data-id='" + json.pago_id + "']").parent().parent()
tr.addClass('disabled')
tr.find(':nth-child(7)').addClass('red').html('Anulado')
tr.find(':nth-child(8)').html(json.fecha)
tr.find(':nth-child(9)').html('')*/
})
})
}
function devolver(button, pago_id, fecha) {
const url = '{{$urls->api}}/ventas/pago/' + pago_id + '/devolver'
const body = new FormData()
body.set('fecha', fecha.toISOString())
return fetchAPI(url, {method: 'post', body}).then(response => {
if (!response) {
return
}
return response.json().then(json => {
if (!json.devuelto) {
return
}
updateRow({pago_id: json.pago_id, fecha: json.input.fecha, estado: 'Devuelto', color: 'red'})
button.parent().find('.accept_estado').attr('data-estado', 'devuelto')
button.remove()
})
})
}
$('.fecha_estado').calendar({
type: 'date',
formatter: {
date: 'DD-MM-YYYY'
}
})
$('.accept_estado').click(event => {
const target = $(event.currentTarget)
const pago_id = target.data('pago')
const fecha = target.parent().parent().calendar('get date')
if (target.attr('data-estado') === 'depositado') {
return abonar(pago_id, fecha)
}
return depositar(target, pago_id, fecha)
})
$('.reject_estado').click(event => {
const target = $(event.currentTarget)
const pago_id = target.data('pago')
const fecha = target.parent().parent().calendar('get date')
devolver(target, pago_id, fecha)
})
$('.anular').click(event => {
const pago_id = $(event.currentTarget).data('pago')
anular(pago_id)
})
new DataTable('#cuotas', {
language: {