develop (#45)
Co-authored-by: Juan Pablo Vial <jpvialb@incoviba.cl> Reviewed-on: #45
This commit is contained in:
166
app/resources/views/ventas/escrituras/abono/cuotas.blade.php
Normal file
166
app/resources/views/ventas/escrituras/abono/cuotas.blade.php
Normal file
@ -0,0 +1,166 @@
|
||||
@extends('ventas.base')
|
||||
|
||||
@section('venta_subtitle')
|
||||
Cuotas - Abono a Escritura
|
||||
@endsection
|
||||
|
||||
@section('venta_content')
|
||||
<table class="ui table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th rowspan="2">#</th>
|
||||
<th rowspan="2">Fecha</th>
|
||||
<th colspan="2">Valor</th>
|
||||
<th rowspan="2" colspan="2">Estado</th>
|
||||
<th class="right aligned" rowspan="2">
|
||||
<button class="ui tertiary green icon button" id="add_button">
|
||||
<i class="plus icon"></i>
|
||||
</button>
|
||||
</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<th class="right aligned">$</th>
|
||||
<th class="right aligned">UF</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="cuotas">
|
||||
@foreach ($cuotas as $cuota)
|
||||
<tr data-id="{{$cuota->id}}">
|
||||
<td class="numero" data-value="{{$cuota->numero}}">{{$cuota->numero}}</td>
|
||||
<td class="fecha" data-value="{{$cuota->pago->fecha->format('Y-m-d')}}">{{$cuota->pago->fecha->format('d-m-Y')}}</td>
|
||||
<td class="valor right aligned" data-value="{{$cuota->pago->valor}}">{{$format->pesos($cuota->pago->valor)}}</td>
|
||||
<td class="valor_uf right aligned" data-value="{{$cuota->pago->valor()}}">{{$format->ufs($cuota->pago->valor())}}</td>
|
||||
<td class="estado{{$cuota->pago->currentEstado->tipoEstadoPago->descripcion === 'no pagado' ? ' warning' :
|
||||
($cuota->pago->currentEstado->tipoEstadoPago->descripcion === 'abonado' ? ' positive' : '')}}"
|
||||
data-value="{{$cuota->pago->currentEstado->tipoEstadoPago->id}}">
|
||||
{{ucwords($cuota->pago->currentEstado->tipoEstadoPago->descripcion)}}
|
||||
@if (in_array($cuota->pago->currentEstado->tipoEstadoPago->descripcion, ['abonado', 'depositado']))
|
||||
<br />
|
||||
{{$cuota->pago->currentEstado->fecha->format('d-m-Y')}}
|
||||
@endif
|
||||
</td>
|
||||
<td class="collapsing">
|
||||
@if (in_array($cuota->pago->currentEstado->tipoEstadoPago->descripcion, ['depositado', 'no pagado']))
|
||||
<form class="ui compact form avance_pago_form" data-id="{{$cuota->id}}"
|
||||
data-pago="{{$cuota->pago->id}}"
|
||||
data-estado="{{$cuota->pago->currentEstado->tipoEstadoPago->descripcion}}">
|
||||
<div class="inline field">
|
||||
<div class="ui calendar">
|
||||
<div class="ui icon input">
|
||||
<input type="text" name="fecha_avance_pago{{$cuota->id}}" />
|
||||
<i class="calendar icon"></i>
|
||||
</div>
|
||||
</div>
|
||||
<button class="ui tertiary green icon button accept_button" data-id="{{$cuota->id}}"><i class="check icon"></i></button>
|
||||
@if ($cuota->pago->currentEstado->tipoEstadoPago->descripcion === 'depositado')
|
||||
<button class="ui tertiary red icon button cancel_button" data-id="{{$cuota->id}}"><i class="remove icon"></i></button>
|
||||
@endif
|
||||
</div>
|
||||
</form>
|
||||
@endif
|
||||
</td>
|
||||
<td class="right aligned">
|
||||
<button class="ui tertiary icon button edit_button" data-id="{{$cuota->id}}">
|
||||
<i class="edit icon"></i>
|
||||
</button>
|
||||
<button class="ui tertiary red icon button remove_button" data-id="{{$cuota->id}}">
|
||||
<i class="remove icon"></i>
|
||||
</button>
|
||||
</td>
|
||||
</tr>
|
||||
@endforeach
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
@include('ventas.escrituras.abono.cuotas.add_modal')
|
||||
@include('ventas.escrituras.abono.cuotas.edit_modal')
|
||||
@endsection
|
||||
|
||||
@push('page_scripts')
|
||||
<script>
|
||||
$(document).ready(function () {
|
||||
const addModal = new AddModal({
|
||||
modal: '#add_cuota_modal',
|
||||
form: 'add_cuota_form',
|
||||
fecha: '#add_fecha',
|
||||
})
|
||||
const editModal = new EditModal({
|
||||
table: 'cuotas',
|
||||
modal: '#edit_cuota_modal',
|
||||
form: 'edit_cuota_form',
|
||||
fecha: '#edit_fecha',
|
||||
estado: '#edit_estado'
|
||||
})
|
||||
|
||||
document.getElementById('add_button').addEventListener('click', clickEvent => {
|
||||
addModal.draw()
|
||||
})
|
||||
Array.from(document.getElementsByClassName('edit_button')).forEach(button => {
|
||||
button.addEventListener('click', clickEvent => {
|
||||
const id = $(clickEvent.currentTarget).data('id')
|
||||
editModal.getData({cuota_id: id})
|
||||
})
|
||||
})
|
||||
Array.from(document.getElementsByClassName('remove_button')).forEach(button => {
|
||||
button.addEventListener('click', clickEvent => {
|
||||
const id = $(clickEvent.currentTarget).data('id')
|
||||
const url = `{{$urls->api}}/venta/{{$venta->id}}/cuota/${id}`
|
||||
const method = 'delete'
|
||||
console.debug(url)
|
||||
})
|
||||
})
|
||||
|
||||
Array.from(document.getElementsByClassName('avance_pago_form')).forEach(form => {
|
||||
form.addEventListener('submit', submitEvent => {
|
||||
submitEvent.preventDefault()
|
||||
return false
|
||||
})
|
||||
const cdo = structuredClone(calendar_date_options)
|
||||
cdo['initialDate'] = new Date()
|
||||
cdo['maxDate'] = new Date()
|
||||
@if ($cuota->pago->currentEstado->tipoEstadoPago->descripcion === 'depositado')
|
||||
cdo['initialDate'] = new Date('{{$cuota->pago->currentEstado->fecha->format('Y-m-d')}}')
|
||||
@endif
|
||||
$(form).find('.ui.calendar').calendar(cdo)
|
||||
})
|
||||
Array.from(document.getElementsByClassName('accept_button')).forEach(button => {
|
||||
button.addEventListener('click', clickEvent => {
|
||||
const id = $(clickEvent.currentTarget).data('id')
|
||||
const method = 'post'
|
||||
const form = Array.from(document.getElementsByClassName('avance_pago_form')).filter(form => parseInt(form.dataset.id) === id)[0]
|
||||
const pago = form.dataset.pago
|
||||
const estado = form.dataset.estado
|
||||
const newEstado = estado === 'depositado' ? 'abonar' : 'depositar'
|
||||
const url = `{{$urls->api}}/ventas/pago/${pago}/${newEstado}`
|
||||
const body = new FormData()
|
||||
const fecha = $(form).find('.ui.calendar').calendar('get date')[0]
|
||||
body.set('fecha', fecha.getFullYear() + '-' + (fecha.getMonth() + 1).toString().padStart(2, '0') + '-' + fecha.getDate().toString().padStart(2, '0'))
|
||||
|
||||
APIClient.fetch(url, {method, body}).then(response => {
|
||||
if (response.ok) {
|
||||
return response.json().then(json => {
|
||||
if (json.success) {
|
||||
window.location.reload()
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
})
|
||||
})
|
||||
Array.from(document.getElementsByClassName('cancel_button')).forEach(button => {
|
||||
button.addEventListener('click', clickEvent => {
|
||||
const id = $(clickEvent.currentTarget).data('id')
|
||||
const method = 'post'
|
||||
const form = Array.from(document.getElementsByClassName('avance_pago_form')).filter(form => parseInt(form.dataset.id) === id)[0]
|
||||
const pago = form.dataset.pago
|
||||
const url = `{{$urls->api}}/ventas/pago/${pago}/devolver`
|
||||
const body = new FormData()
|
||||
const fecha = $(form).find('.ui.calendar').calendar('get date')[0]
|
||||
body.set('fecha', fecha.getFullYear() + '-' + (fecha.getMonth() + 1).toString().padStart(2, '0') + '-' + fecha.getDate().toString().padStart(2, '0'))
|
||||
|
||||
console.debug(url, body)
|
||||
})
|
||||
})
|
||||
})
|
||||
</script>
|
||||
@endpush
|
@ -0,0 +1,87 @@
|
||||
<div class="ui modal" id="add_cuota_modal">
|
||||
<div class="header">
|
||||
Agregar Cuota
|
||||
</div>
|
||||
<div class="content">
|
||||
<form class="ui form" id="add_cuota_form">
|
||||
<input type="hidden" name="venta_id" value="{{$venta->id}}" />
|
||||
<div class="two wide field">
|
||||
<label>Número</label>
|
||||
<input type="text" name="numero" />
|
||||
</div>
|
||||
<div class="three wide field">
|
||||
<label>Fecha</label>
|
||||
<div class="ui calendar" id="add_fecha">
|
||||
<div class="ui icon input">
|
||||
<i class="calendar icon"></i>
|
||||
<input type="text" name="fecha" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="three wide field">
|
||||
<label>Valor $</label>
|
||||
<div class="ui left labeled input">
|
||||
<div class="ui basic label">$</div>
|
||||
<input type="text" name="valor" />
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<div class="actions">
|
||||
<div class="ui negative button">
|
||||
Cancelar
|
||||
</div>
|
||||
<div class="ui positive right labeled icon button">
|
||||
Agregar
|
||||
<i class="add icon"></i>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@push('page_scripts')
|
||||
<script>
|
||||
class AddModal {
|
||||
props
|
||||
|
||||
constructor(props) {
|
||||
this.setup(props)
|
||||
}
|
||||
draw() {
|
||||
$(this.props.modal).modal('show')
|
||||
}
|
||||
save() {
|
||||
const form = document.getElementById(this.props.form)
|
||||
const body = new FormData(form)
|
||||
const fecha = $(this.props.fecha).calendar('get date')
|
||||
body.set('fecha', fecha.getFullYear() + '-' + (fecha.getMonth() + 1).toString().padStart(2, '0') + '-' + fecha.getDate().toString().padStart(2, '0'))
|
||||
const url = `{{$urls->api}}/venta/{{$venta->id}}/escritura/cuotas/add`
|
||||
const method = 'post'
|
||||
APIClient.fetch(url, {method, body}).then(response => {
|
||||
if (!response) {
|
||||
return
|
||||
}
|
||||
return response.json().then(json => {
|
||||
if (json.success) {
|
||||
window.location.reload()
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
setup(ids) {
|
||||
this.props = ids
|
||||
|
||||
$(this.props.modal).modal({
|
||||
onApprove: () => {
|
||||
this.save()
|
||||
}
|
||||
})
|
||||
$(this.props.form).submit(event => {
|
||||
event.preventDefault()
|
||||
this.save()
|
||||
return false
|
||||
})
|
||||
$(this.props.fecha).calendar(calendar_date_options)
|
||||
}
|
||||
}
|
||||
</script>
|
||||
@endpush
|
@ -0,0 +1,130 @@
|
||||
<div class="ui modal" id="edit_cuota_modal">
|
||||
<div class="header">
|
||||
Editar Cuota <span class="numero"></span>
|
||||
</div>
|
||||
<div class="content">
|
||||
<form class="ui form" id="edit_cuota_form">
|
||||
<input type="hidden" name="id" />
|
||||
<div class="two wide field">
|
||||
<label>Número</label>
|
||||
<input type="text" name="numero" />
|
||||
</div>
|
||||
<div class="three wide field">
|
||||
<label>Fecha</label>
|
||||
<div class="ui calendar" id="edit_fecha">
|
||||
<div class="ui icon input">
|
||||
<i class="calendar icon"></i>
|
||||
<input type="text" name="fecha" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="three wide field">
|
||||
<label>Valor $</label>
|
||||
<div class="ui left labeled input">
|
||||
<div class="ui basic label">$</div>
|
||||
<input type="text" name="valor" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="three wide field">
|
||||
<label>Estado</label>
|
||||
<div class="ui selection search dropdown" id="edit_estado">
|
||||
<i class="dropdown icon"></i>
|
||||
<input type="hidden" name="tipo_estado_id" />
|
||||
<div class="default text">Estado</div>
|
||||
<div class="menu">
|
||||
@foreach($estados as $estado)
|
||||
<div class="item" data-value="{{$estado->id}}">{{$estado->descripcion}}</div>
|
||||
@endforeach
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<div class="actions">
|
||||
<div class="ui negative button">
|
||||
Cancelar
|
||||
</div>
|
||||
<div class="ui positive right labeled icon button">
|
||||
Editar
|
||||
<i class="edit icon"></i>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@push('page_scripts')
|
||||
<script>
|
||||
class EditModal {
|
||||
props
|
||||
data
|
||||
|
||||
constructor(props) {
|
||||
this.setup(props)
|
||||
this.data = null
|
||||
}
|
||||
getData({cuota_id}) {
|
||||
const table = document.getElementById(this.props.table)
|
||||
const row = table.querySelector(`tr[data-id='${cuota_id}']`)
|
||||
const fecha = row.querySelector('.fecha').dataset.value.split('-')
|
||||
this.data = {
|
||||
id: cuota_id,
|
||||
numero: row.querySelector('.numero').dataset.value,
|
||||
fecha: new Date(fecha[0], fecha[1] - 1, fecha[2]),
|
||||
valor: row.querySelector('.valor').dataset.value,
|
||||
estado: row.querySelector('.estado').dataset.value
|
||||
}
|
||||
|
||||
this.draw()
|
||||
}
|
||||
draw() {
|
||||
const form = document.getElementById(this.props.form)
|
||||
form.querySelector('input[name="id"]').value = this.data.id
|
||||
form.querySelector('input[name="numero"]').value = this.data.numero
|
||||
$(this.props.fecha).calendar('set date', this.data.fecha)
|
||||
form.querySelector('input[name="valor"]').value = this.data.valor
|
||||
$(this.props.estado).dropdown('set selected', this.data.estado)
|
||||
|
||||
$(this.props.modal).find('.header .numero').text(this.data.numero)
|
||||
|
||||
$(this.props.modal).modal('show')
|
||||
}
|
||||
save() {
|
||||
const form = document.getElementById(this.props.form)
|
||||
const body = new FormData(form)
|
||||
const fecha = $(this.props.fecha).calendar('get date')
|
||||
body.set('fecha', fecha.getFullYear() + '-' + (fecha.getMonth() + 1).toString().padStart(2, '0') + '-' + fecha.getDate().toString().padStart(2, '0'))
|
||||
body.set('tipo_estado_id', $(this.props.estado).dropdown('get value'))
|
||||
const url = `{{$urls->api}}/venta/{{$venta->id}}/escritura/cuota/${this.data.id}/edit`
|
||||
const method = 'post'
|
||||
APIClient.fetch(url, {method, body}).then(response => {
|
||||
if (!response) {
|
||||
return
|
||||
}
|
||||
return response.json().then(json => {
|
||||
if (json.success) {
|
||||
window.location.reload()
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
setup(ids) {
|
||||
this.props = ids
|
||||
|
||||
$(this.props.modal).modal({
|
||||
onApprove: () => {
|
||||
this.save()
|
||||
},
|
||||
onHidden: () => {
|
||||
this.data = null
|
||||
}
|
||||
})
|
||||
$(this.props.form).submit(event => {
|
||||
event.preventDefault()
|
||||
this.save()
|
||||
return false
|
||||
})
|
||||
$(this.props.fecha).calendar(calendar_date_options)
|
||||
$(this.props.estado).dropdown()
|
||||
}
|
||||
}
|
||||
</script>
|
||||
@endpush
|
@ -14,6 +14,7 @@
|
||||
<p>Crédito {{$format->ufs($venta->formaPago()->credito->pago->valor())}}</p>
|
||||
@endif
|
||||
</div>
|
||||
<a href="{{$urls->base}}/venta/{{$venta->id}}/escritura/cuotas" class="ui small green button"><i class="plus icon"></i> Agregar Cuotas</a>
|
||||
<form class="ui form" id="add_form">
|
||||
<div class="three wide field">
|
||||
<label for="fecha">Fecha</label>
|
||||
|
@ -6,7 +6,12 @@
|
||||
|
||||
@section('venta_content')
|
||||
<div class="ui segment">
|
||||
El departamento {{$venta->propiedad()->departamentos()[0]->descripcion}}:<br />
|
||||
@if (count($venta->propiedad()->departamentos()) > 0)
|
||||
El departamento {{$venta->propiedad()->departamentos()[0]->descripcion}}:<br />
|
||||
@else
|
||||
La unidad {{ ucwords($venta->propiedad()->principal()?->proyectoTipoUnidad->tipoUnidad->descripcion) }}
|
||||
{{ $venta->propiedad()->principal()?->descripcion }}:<br />
|
||||
@endif
|
||||
@php
|
||||
$estacionamientos = $venta->propiedad()->estacionamientos();
|
||||
@endphp
|
||||
|
@ -5,6 +5,24 @@
|
||||
@endsection
|
||||
|
||||
@section('venta_content')
|
||||
@if (count($venta->formaPago()->cuotasAbono) > 0)
|
||||
<a href="{{$urls->base}}/venta/{{$venta->id}}/escritura/cuotas" class="ui tertiary green button">Ver Cuotas</a>
|
||||
<div class="ui compact segment">
|
||||
<div class="header">
|
||||
Cuotas
|
||||
</div>
|
||||
<div class="ui horizontal list">
|
||||
<div class="item">
|
||||
{{$format->pesos($venta->formaPago()->cuotasAbono('pesos'))}}
|
||||
</div>
|
||||
<div class="item">
|
||||
{{$format->ufs($venta->formaPago()->cuotasAbono())}}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@else
|
||||
<a href="{{$urls->base}}/venta/{{$venta->id}}/escritura/cuotas" class="ui small green button"><i class="plus icon"></i> Agregar Cuotas</a>
|
||||
@endif
|
||||
<form class="ui form" id="edit_form">
|
||||
<div class="three wide field">
|
||||
<label for="fecha">Fecha</label>
|
||||
@ -15,6 +33,26 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="three wide field">
|
||||
<label for="valor">Valor</label>
|
||||
<div class="ui left labeled input">
|
||||
<div class="ui basic label">$</div>
|
||||
<input type="text" name="valor" id="valor" value="{{$venta->formaPago()->escritura->pago->valor}}" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="three wide field">
|
||||
<label>Estado</label>
|
||||
<div class="ui selection dropdown" id="estado">
|
||||
<input type="hidden" name="estado" />
|
||||
<div class="default text">Estado</div>
|
||||
<i class="dropdown icon"></i>
|
||||
<div class="menu">
|
||||
@foreach($estados as $estado)
|
||||
<div class="item" data-value="{{$estado->id}}">{{ucwords($estado->descripcion)}}</div>
|
||||
@endforeach
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<button class="ui button">Guardar</button>
|
||||
</form>
|
||||
@endsection
|
||||
@ -24,23 +62,27 @@
|
||||
function editEscritura() {
|
||||
const url = '{{$urls->api}}/ventas/escritura/{{$venta->id}}/edit'
|
||||
const data = new FormData()
|
||||
data.set('venta', {{$venta->id}})
|
||||
const fecha = $('#fecha').calendar('get date')
|
||||
data.set('fecha', fecha.toISOString())
|
||||
data.set('valor', $('#valor').val())
|
||||
data.set('estado', $('#estado').dropdown('get value'))
|
||||
return fetchAPI(url, {method: 'post', body: data}).then(response => {
|
||||
if (response.ok) {
|
||||
return response.json()
|
||||
}
|
||||
}).then(json => {
|
||||
if (!json.edited) {
|
||||
if (!json.success) {
|
||||
return
|
||||
}
|
||||
window.location = '{{$urls->base}}/venta/{{$venta->id}}'
|
||||
})
|
||||
}
|
||||
$(document).ready(() => {
|
||||
calendar_date_options.initialDate = new Date({{$venta->currentEstado()->fecha->format('Y, m-1, j')}})
|
||||
calendar_date_options.initialDate = new Date({{$venta->formaPago()->escritura->pago->currentEstado->fecha->format('Y, m-1, j')}})
|
||||
$('#fecha').calendar(calendar_date_options)
|
||||
const $estado = $('#estado')
|
||||
$estado.dropdown()
|
||||
$estado.dropdown('set selected', '{{$venta->formaPago()->escritura->pago->currentEstado->tipoEstadoPago->id}}')
|
||||
$('#edit_form').submit(event => {
|
||||
event.preventDefault()
|
||||
editEscritura()
|
||||
|
Reference in New Issue
Block a user