Co-authored-by: Juan Pablo Vial <jpvialb@incoviba.cl>
Reviewed-on: #45
This commit is contained in:
2025-10-04 11:40:52 -03:00
parent 6ddc48ec60
commit 742de657c5
815 changed files with 62089 additions and 3287 deletions

View File

@ -4,8 +4,45 @@
Cuotas - Pie
@endsection
@push('page_scripts')
<script>
const bancos = JSON.parse('{!! json_encode($bancos) !!}')
const estados = JSON.parse('{!! json_encode($estados) !!}')
</script>
@endpush
@section('venta_content')
<table class="ui table" id="cuotas">
@if (count($asociadas) > 0)
<div class="ui grid">
<div class="two wide column">Asociados</div>
<div class="six wide column">
{!! implode(' - ', array_map(function(Incoviba\Model\Venta $venta) use ($urls) {
return "<a href=\"{$urls->base}/venta/{$venta->id}\">{$venta->propiedad()->departamentos()[0]->descripcion}</a>";
}, $asociadas)) !!}
</div>
@if ($venta->formaPago()->pie->asociado !== null)
<div class="row">
<div class="ui tiny basic segment">
* Este pie no es la base para el cálculo de las cuotas
</div>
</div>
@endif
</div>
@endif
<div class="ui grid">
<div class="column">Valor</div>
<div class="four wide column">
{{$format->ufs($venta->formaPago()->pie->valor)}}
@if (count($asociadas) > 0)
[{{$format->ufs($venta->formaPago()->pie->valor + array_reduce($asociadas, function(float $sum, Incoviba\Model\Venta $venta) {
return $sum + $venta->formaPago()->pie->valor;
}, 0.0))}}]
@endif
</div>
<div class="column">Cuotas</div>
<div class="column">{{$venta->formaPago()->pie->cuotas}}</div>
</div>
<table class="ui compact table" id="cuotas">
<thead>
<tr>
<th>#</th>
@ -24,45 +61,63 @@
<tbody>@php
$now = new DateTimeImmutable();
$uf_venta = $venta->uf === 0.0 ? $UF->get($venta->currentEstado()->fecha) : $venta->uf;
if ($uf_venta === 0.0) {
$uf_venta = $UF->get();
}
@endphp
@foreach ($venta->formaPago()->pie->cuotas() as $cuota)
<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->numero}}
<button class="ui mini tertiary icon button edit_cuota" data-cuota="{{$cuota->pago->id}}">
<i class="edit icon"></i>
</button>
</td>
<td>{{$cuota->pago->fecha->format('d-m-Y')}}</td>
<td>{{$cuota->pago->fecha->format('Y-m-d')}}</td>
<td>{{$cuota->pago->banco->nombre}}</td>
<td>{{$cuota->pago->identificador}}</td>
<td class="right aligned">{{$format->pesos($cuota->pago->valor)}}</td>
<td class="right aligned">
@if ($cuota->pago->currentEstado->tipoEstadoPago->descripcion === 'abonado' and $cuota->pago->currentEstado->fecha <= $now)
@if (in_array($cuota->pago->currentEstado->tipoEstadoPago->descripcion, ['depositado', 'abonado'])
and $cuota->pago->currentEstado->fecha <= $now)
{{$format->ufs($cuota->pago->valor())}}
@else
~{{$format->ufs($cuota->pago->valor / $uf_venta)}}
@endif
</td>
<td
@if ($cuota->pago->currentEstado->tipoEstadoPago->descripcion === 'abonado')
class="green"
@elseif ($cuota->pago->currentEstado->tipoEstadoPago->descripcion === 'depositado')
class="yellow"
@elseif ($cuota->pago->currentEstado->tipoEstadoPago->activo !== 1)
class="red"
@endif
>{{ucwords($cuota->pago->currentEstado->tipoEstadoPago->descripcion)}}</td>
<td{!! ($cuota->pago->currentEstado->tipoEstadoPago->descripcion === 'abonado' ? ' class="green"' :
($cuota->pago->currentEstado->tipoEstadoPago->descripcion === 'depositado' ? ' class="yellow"' :
($cuota->pago->currentEstado->tipoEstadoPago->activo !== 1 ? ' class="red"' : ''))) !!}>
{{ucwords($cuota->pago->currentEstado->tipoEstadoPago->descripcion)}}
<button class="ui mini tertiary icon button edit_estado_cuota" data-cuota="{{$cuota->pago->id}}"
data-estado="{{$cuota->pago->currentEstado->tipoEstadoPago->id}}"
data-fecha="{{$cuota->pago->currentEstado->fecha->format('Y-m-d')}}">
<i class="edit icon"></i>
</button>
</td>
<td>
@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>
<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}}">
<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>
@if ($cuota->pago->currentEstado->tipoEstadoPago->descripcion === 'depositado')
<button class="ui red basic icon button reject_estado" data-pago="{{$cuota->pago->id}}">
<button class="ui red basic icon button reject_estado"
data-pago="{{$cuota->pago->id}}">
<i class="remove icon"></i>
</button>
@endif
@ -85,13 +140,13 @@
<tr>
<th colspan="5">TOTAL</th>
<th class="right aligned">
{{$format->pesos($total_pesos = array_reduce($venta->formaPago()->pie->cuotas(),
function(float $sum, Incoviba\Model\Venta\Cuota $cuota) {
{{$format->pesos($total_pesos = array_reduce($venta->formaPago()->pie->cuotas(vigentes: true),
function(int $sum, Incoviba\Model\Venta\Cuota $cuota) {
return $sum + $cuota->pago->valor;
}, 0))}}
</th>
<th class="right aligned">
{{$format->ufs($total = array_reduce($venta->formaPago()->pie->cuotas(),
{{$format->ufs($total = array_reduce($venta->formaPago()->pie->cuotas(vigentes: true),
function(float $sum, Incoviba\Model\Venta\Cuota $cuota) use ($now, $uf_venta) {
return $sum + (($cuota->pago->fecha > $now or $cuota->pago->uf === null) ?
$cuota->pago->valor / $uf_venta :
@ -103,19 +158,20 @@
<tr>
<th colspan="5">TOTAL PAGADO</th>
<th class="right aligned">
{{$format->pesos($pagado_pesos = array_reduce($venta->formaPago()->pie->cuotas(true),
{{$format->pesos($pagado_pesos = array_reduce($venta->formaPago()->pie->cuotas(pagadas: true, vigentes: true),
function(int $sum, Incoviba\Model\Venta\Cuota $cuota) {
return $sum + $cuota->pago->valor;
}, 0))}}
</th>
<th class="right aligned">
{{$format->ufs($pagado = array_reduce($venta->formaPago()->pie->cuotas(true),
{{$format->ufs($pagado = array_reduce($venta->formaPago()->pie->cuotas(pagadas: true, vigentes: true),
function(float $sum, Incoviba\Model\Venta\Cuota $cuota) {
return $sum + $cuota->pago->valor();
}, 0.0))}}
</th>
<th class="right aligned">
{{$format->number($pagado / $total * 100, 2)}}%
{{ $format->percent(($total > 0) ? $pagado / $total : 0, 2, true) }} Pie<br />
{{ $format->percent($pagado / $venta->valor, 2, true) }} Promesa
</th>
<th colspan="3"></th>
</tr>
@ -128,12 +184,18 @@
{{$format->ufs($total - $pagado)}}
</th>
<th class="right aligned">
{{$format->number(($total - $pagado) / $total * 100, 2)}}%
{{$format->percent(($total > 0) ? ($total - $pagado) / $total * 100 : 0, 2)}}*
</th>
<th colspan="3"></th>
</tr>
</tfoot>
</table>
<div class="ui tiny basic right aligned segment">
* Porcentaje calculado sobre el valor de la venta
</div>
@include('ventas.pies.cuotas.edit')
@include('ventas.pies.cuotas.estados.edit')
@endsection
@include('layout.head.styles.datatables')
@ -142,12 +204,17 @@
@include('layout.body.scripts.datatables.buttons')
@push('page_scripts')
<script type="text/javascript">
<script>
$(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(7)').attr('class', color).html(estado)
tr.find(':nth-child(6)').html(valor)
if (typeof color !== 'undefined') {
tr.find(':nth-child(7)').attr('class', color).html(estado)
} else {
tr.find(':nth-child(7)').html(estado)
}
if (remove_fecha) {
tr.find(':nth-child(8)').html(fecha)
}
@ -181,7 +248,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')
})
})
@ -189,7 +256,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
@ -234,6 +301,66 @@
})
})
}
function editar(id, body) {
const url = '{{$urls->api}}/ventas/pago/' + id
return fetchAPI(url, {method: 'post', body}).then(response => {
if (!response) {
return
}
return response.json().then(json => {
if (!json.editado) {
return
}
const tr = $(`tr[data-pago='${json.pago.id}']`)
tr.children(':nth-child(1)').html(json.pago.numero)
const fecha = json.pago.fecha.split(' ')[0].split('-').reverse().join('-')
tr.children(':nth-child(2)').html(fecha)
tr.children(':nth-child(3)').html(json.pago.banco.nombre)
tr.children(':nth-child(4)').html(json.pago.identificador)
const pesosFormatter = Intl.NumberFormat('es-CL', {style: 'currency', currency: 'CLP'})
tr.children(':nth-child(5)').html(pesosFormatter.format(json.pago.valor))
const ufFormatter = Intl.NumberFormat('es-CL', {minimumFractionDigits: 2, maximumFractionDigits: 2})
tr.children(':nth-child(6)').html(ufFormatter.format(json.pago.valor_uf) + ' UF')
})
})
}
const editModal = new EditModal({id: '#edit_cuota_modal', approve: ({id, data}) => {
editar(id, data)
}})
$('.edit_cuota').on('click', clickEvent => {
const id = $(clickEvent.currentTarget).data('cuota')
const tr = $(`tr[data-pago='${id}']`)
const number = tr.children(':nth-child(1)').text().split('<')[0].trim()
const fecha = tr.children(':nth-child(2)').text()
const nombre_banco = tr.children(':nth-child(3)').text()
const banco_id = bancos.filter(banco => banco.nombre === nombre_banco)[0].id
const identificador = tr.find(':nth-child(4)').text()
const valor = parseInt(tr.find(':nth-child(5)').text().replace('$', '').replaceAll('.', '').trim())
editModal.open({id, number, fecha, banco_id, identificador, valor})
})
const editCuotaModal = new EditEstadoModal({id: '#edit_estado_cuota_modal', approve: ({id, data}) => {
const url = '{{$urls->api}}/ventas/pago/' + id + '/estado'
return fetchAPI(url, {method: 'post', body: data}).then(response => {
if (!response) {
return
}
return response.json().then(json => {
if (!json.editado) {
return
}
window.location.reload()
})
})
}})
$('.edit_estado_cuota').on('click', clickEvent => {
const id = $(clickEvent.currentTarget).data('cuota')
const estado_id = $(clickEvent.currentTarget).data('estado')
const fecha = $(clickEvent.currentTarget).data('fecha')
editCuotaModal.open({id, estado_id, fecha})
})
$('.fecha_estado').calendar({
type: 'date',
formatter: {
@ -270,17 +397,30 @@
zeroRecords: 'No se encotró cuotas con ese criterio',
search: 'Buscar: '
},
pageLength: "25",
pageLength: "100",
columnDefs: [
{
target: 1,
orderData: [2]
orderData: [2],
className: 'dt-center'
},
{
target: 2,
visible: false,
searchable: false
},
{
target: 3,
className: 'dt-center'
},
{
targets: [5, 6],
className: 'dt-right'
},
{
target: 7,
className: 'dt-center'
},
{
target: 8,
orderData: [9]