Implemented repository mapper, and venta show

This commit is contained in:
Juan Pablo Vial
2023-08-08 23:53:49 -04:00
parent ef30ae67d2
commit 59825259b6
111 changed files with 2766 additions and 612 deletions

View File

@ -0,0 +1,88 @@
<div class="ui inverted grey two column grid segment">
<div class="column">
COMENTARIOS
</div>
<div class="right aligned column">
<a href="javascript: addComment()" style="color: inherit;">
<i class="plus icon"></i>
</a>
</div>
</div>
<div class="ui segment">
<table class="ui very basic table">
<tbody id="comentarios"></tbody>
</table>
</div>
@push('page_scripts')
<script type="text/javascript">
class Comentario
{
fecha
texto
constructor({fecha, texto})
{
this.fecha = new Date(fecha + 'T00:00:00')
this.texto = texto
}
draw(dateFormatter)
{
return $('<tr></tr>').append(
$('<td></td>').html(dateFormatter.format(this.fecha))
).append(
$('<td></td>').html(this.texto)
).append(
$('<td></td>').addClass('right aligned').append(
$('<a></a>').attr('href', 'javascript: removeComment();').append(
$('<i></i>').addClass('minus icon')
)
)
)
}
}
const comentarios = {
comentarios: [],
id: '',
fetch: function() {
return {
comentarios: () => {
const uri = '{{$urls->api}}/venta/{{$venta->id}}/comentarios'
return fetch(uri).then(response => {
if (response.ok) {
return response.json()
}
}).then(data => {
if (data.total === 0) {
return
}
data.comentarios.forEach(settings => {
this.comentarios.push(new Comentario(settings))
})
this.draw().comentarios()
})
}
}
},
draw: function() {
return {
comentarios: () => {
const body = $(this.id)
const dateFormatter = new Intl.DateTimeFormat('es-CL', {dateStyle: 'medium'})
body.html('')
this.comentarios.forEach(comentario => {
body.append(comentario.draw(dateFormatter))
})
}
}
},
setup: function(id) {
this.id = id
this.fetch().comentarios()
}
}
$(document).ready(() => {
comentarios.setup('#comentarios')
})
</script>
@endpush

View File

@ -0,0 +1,38 @@
<div class="ui inverted grey two column grid segment">
<div class="column">
VENTA
</div>
<div class="right aligned column">
<a style="color: inherit;" href="{{$urls->base}}/venta/{{$venta->id}}/edit">
<i class="edit icon"></i>
</a>
</div>
</div>
<div class="ui segment">
<table class="ui very basic fluid table">
<thead>
<tr>
<th>Valor Promesa</th>
<th>Valor Util</th>
<th>UF/</th>
<th>Comisión</th>
<th>
Fecha Promesa <br/>
Fecha Ingreso
</th>
</tr>
</thead>
<tbody>
<tr>
<td>{{$format->ufs($venta->valor)}}</td>
<td>{{$format->ufs($venta->util())}}</td>
<td>{{$format->number($venta->util() / $venta->propiedad()->vendible(), 2)}} UF/</td>
<td>0,00 UF (0,00%)</td>
<td>
{{$venta->fecha->format('d-m-Y')}}<br/>
{{$venta->fechaIngreso->format('d-m-Y')}}
</td>
</tr>
</tbody>
</table>
</div>

View File

@ -0,0 +1,11 @@
<div class="ui inverted grey segment">
ENTREGA
</div>
<div class="ui segment">
@if ($venta->entrega() !== null)
@else
<a href="{{$urls->base}}/venta/{{$venta->id}}/entregar">
No <i class="right chevron icon"></i>
</a>
@endif
</div>

View File

@ -0,0 +1,22 @@
<div class="ui inverted grey segment">
ESCRITURA
</div>
@if ($venta->formaPago()->escritura !== null)
<div class="ui segment">
Escriturado {{$venta->formaPago()->escritura->fecha->format('d-m-Y')}}
<a href="{{$urls->base}}/venta/{{$venta->id}}/escritura/informe">
Informe
<i class="right chevron icon"></i>
</a>
<br />
<a href="{{$urls->base}}/venta{{$venta->id}}/escritura/firmar">
Firmar
</a>
</div>
@else
<div class="ui segment">
<a href="{{$urls->base}}/venta/{{$venta->id}}/escriturar">
Escriturar
</a>
</div>
@endif

View File

@ -0,0 +1,229 @@
<div class="ui inverted grey segment">
FORMA DE PAGO
</div>
<div class="ui segment">
<table class="ui very basic fluid table">
@include('ventas.show.forma_pago.pie', ['pie' => $formaPago->pie])
@include('ventas.show.forma_pago.escritura', ['escritura' => $formaPago->escritura])
@include('ventas.show.forma_pago.anticipo', ['anticipo' => ['uf' => $formaPago->anticipo(), 'pesos' => $formaPago->anticipo('pesos')]])
@include('ventas.show.forma_pago.bono_pie', ['bonoPie' => $formaPago->bonoPie])
@include('ventas.show.forma_pago.subsidio', ['subsidio' => $formaPago->subsidio])
@include('ventas.show.forma_pago.credito', ['credito' => $formaPago->credito])
@include('ventas.show.forma_pago.total')
@include('ventas.show.forma_pago.devolucion', ['devolucion' => $formaPago->devolucion])
</table>
</div>
<div id="pago_modal" class="ui modal">
<div class="content">
<div class="ui form">
<div class="inline field">
<label for="fecha">Fecha</label>
<div class="ui calendar">
<div class="ui icon input">
<input id="fecha" name="fecha" type="text" />
<i class="calendar icon"></i>
</div>
</div>
</div>
<button class="ui button">
Guardar
</button>
</div>
</div>
</div>
@push('page_scripts')
<script type="text/javascript">
class Anchor
{
classes
title
row_id
pago_id
method
icon
status
constructor({classes, title, row_id, pago_id, method, icon})
{
this.classes = classes
this.title = title
this.row_id = row_id
this.pago_id = pago_id
this.method = method
this.icon = icon
this.status = true
}
draw()
{
const row = $(this.row_id)
const anchor = row.find('a')
anchor.attr('class', this.classes)
anchor.attr('title', this.title)
anchor.attr('href', 'javascript: ' + this.method + "({row_id: '" + this.row_id + "', pago_id: " + this.pago_id + '});')
anchor.html('')
anchor.append(
$('<i></i>').addClass(this.icon + ' icon')
)
}
toggle()
{
if (this.status) {
$(this.row_id).find('a').css('pointer-events', 'none')
this.status = false
return
}
$(this.row_id).find('a').css('pointer-events', '')
this.status = true
}
}
class Cell
{
id
classes
text
anchor
status
constructor({id, classes, text, anchor})
{
this.id = id
this.classes = classes
this.text = text
this.anchor = anchor
this.status = true
}
draw()
{
const row = $(this.id)
row.attr('class', this.classes)
row.html('').append(
$('<span></span>').html(this.text)
).append(this.anchor.draw())
}
toggle()
{
if (this.status) {
$(this.id).css('cursor', 'wait')
this.status = false
return
}
$(this.id).css('cursor', 'default')
this.status = true
}
}
class Modal
{
id
date
uri
constructor({id}) {
this.id = id
}
show() {
$(this.id).find('div.ui.calendar').calendar('reset')
$(this.id).find('div.ui.calendar input').val('')
$(this.id).modal('show')
}
setup() {
const modal = $(this.id)
modal.modal({
onHide: function($element) {
const pagos = $("[id$='_pago']")
pagos.css('cursor', 'default')
const anchor = pagos.find("a")
anchor.css('pointer-events', '')
}
})
modal.find('div.ui.calendar').calendar({
type: 'date'
})
}
}
const pagos = {
modal: null,
cells: [],
setup: function({modal_id}) {
this.modal = new Modal({id: modal_id})
this.modal.setup()
},
add: function() {
return {
cell: ({cell_id, classes, text, anchor}) => {
this.cells.push(new Cell({id: cell_id, classes, text, anchor}))
}
}
},
}
function depositar({row_id, pago_id}) {
const row = $(row_id)
const anchor = row.find("a[title='Depositar']")
const uri = '{{$urls->api}}/ventas/pago/' + pago_id + '/depositar'
const modal = $('#pago_modal')
row.css('cursor', 'wait')
anchor.css('pointer-events', 'none')
modal.find('#fecha').calendar('clear')
modal.modal('show')
modal.find('.ui.button').click(event => {
modal.modal('hide')
const date = modal.find('#fecha').val()
return fetch(uri,
{method: 'put', body: JSON.stringify({fecha: date}), headers: {'Content-Type': 'application/json'}}
).then(response => {
anchor.css('pointer-events', '')
row.css('cursor', 'default')
if (response.ok) {
anchor.attr('href', "javascript: abonar({row_id: '" + row_id + "', pago_id: " + pago_id + "});")
anchor.attr('title', 'Abonar')
anchor.html('')
anchor.append(
$('<i></i>').addClass('piggy bank icon')
)
row.removeClass('warning').addClass('positive')
response.json().then(data => {
row.find('.text').html(data.fecha)
})
}
})
})
}
function abonar({row_id, pago_id}) {
const row = $(row_id)
row.css('cursor', 'wait')
const anchor = row.find("a[title='Abonar']")
anchor.css('pointer-events', 'none')
const uri = '{{$urls->api}}/ventas/pago/' + pago_id + '/abonar'
const modal = $('#pago_modal')
modal.modal('show')
modal.find('.ui.button').click(event => {
const date = modal.find('#fecha').val()
return fetch(uri,
{method: 'put', body: JSON.stringify({fecha: date}), headers: {'Content-Type': 'application/json'}}
).then(response => {
anchor.css('pointer-events', '')
row.css('cursor', 'default')
if (response.ok) {
anchor.remove()
row.removeClass('positive')
response.json().then(data => {
row.find('.text').html(data.fecha)
})
}
})
})
}
$(document).ready(() => {
const modal = new Modal({id: '#pago_modal'})
modal.setup()
})
</script>
@endpush

View File

@ -0,0 +1,7 @@
<tr>
<td><strong>Anticipo</strong></td>
<td></td>
<td class="right aligned"><strong>{{$format->ufs($anticipo['uf'])}}</strong></td>
<td class="right aligned"><strong>{{$format->pesos($anticipo['pesos'])}}</strong></td>
<td colspan="2"></td>
</tr>

View File

@ -0,0 +1,22 @@
<tr>
<td>
Bono Pie
@if ($bonoPie !== null)
<a href="{{$urls->base}}/venta/{{$venta->id}}/bono_pie">
<i class="edit button"></i>
</a>
@else
<a href="{{$urls->base}}/venta/{{$venta->id}}/bono_pie/add">
<i class="add icon"></i>
</a>
@endif
</td>
@if ($bonoPie !== null)
<td></td>
<td class="right aligned">{{$format->ufs($bonoPie->pago->valor())}}</td>
<td class="right aligned">{{$format->pesos($bonoPie->pago->valor)}}</td>
<td colspan="2"></td>
@else
<td colspan="5"></td>
@endif
</tr>

View File

@ -0,0 +1,40 @@
<tr>
<td>
Crédito
@if ($credito !== null)
<a href="{{$urls->base}}/venta/{{$venta->id}}/credito">
<i class="edit icon"></i>
</a>
@else
<a href="{{$urls->base}}/venta/{{$venta->id}}/credito/add">
<i class="plus icon"></i>
</a>
@endif
</td>
@if ($credito !== null)
<td></td>
<td class="right aligned">
{{$format->ufs($credito->pago->valor())}}
</td>
<td class="right aligned">
{{$format->pesos($credito->pago->valor)}}
</td>
<td id="credito_pago" class="{{$credito->pago->currentEstado->tipoEstadoPago->descripcion === 'no pagado' ? 'warning' : ($credito->pago->currentEstado->tipoEstado->descripcion === 'depositado' ? 'positive' : '')}}">
<span class="text">{{$credito->pago->currentEstado->fecha->format('d-m-Y')}}</span>
@if ($credito->pago->currentEstado->tipoEstadoPago->descripcion === 'no pagado')
<a href="javascript: depositar({row_id: '#credito_pago', pago_id: {{$credito->pago->id}}});" title="Depositar">
<i class="dollar sign icon"></i>
</a>
@elseif($credito->pago->currentEstado->tipoEstadoPago->descripcion === 'depositado')
<a href="javascript: abonar({row_id: '#credito_pago', pago_id: {{$credito->pago->id}}});" title="Abonar">
<i class="piggy bank icon"></i>
</a>
@endif
</td>
<td>
Banco: {{$credito->pago->banco?->nombre}}
</td>
@else
<td colspan="5"></td>
@endif
</tr>

View File

@ -0,0 +1,34 @@
<tr>
<td>
Escritura
@if ($escritura !== null)
<a href="{{$urls->base}}/venta/{{$venta->id}}/escritura">
<i class="edit icon"></i>
</a>
@else
<a href="{{$urls->base}}/venta/{{$venta->id}}/escritura/add">
<i class="plus icon"></i>
</a>
@endif
</td>
@if ($escritura !== null)
<td></td>
<td class="right aligned">{{$format->ufs($escritura->pago->valor())}}</td>
<td class="right aligned">{{$format->pesos($escritura->pago->valor)}}</td>
<td id="escritura_pago" class="{{$escritura->pago->currentEstado->tipoEstadoPago->descripcion === 'no pagado' ? 'warning' : ($escritura->pago->currentEstado->tipoEstadoPago->descripcion === 'depositado' ? 'positive' : '')}}">
<span class="text">{{$escritura->pago->currentEstado->fecha->format('d-m-Y')}}</span>
@if ($escritura->pago->currentEstado->tipoEstadoPago->descripcion === 'no pagado')
<a href="javascript: depositar({row_id: '#escritura_pago', pago_id: {{$escritura->pago->id}}});" title="Depositar">
<i class="dollar sign icon"></i>
</a>
@elseif ($escritura->pago->currentEstado->tipoEstadoPago->descripcion === 'depositado')
<a href="javascript: abonar({row_id: '#escritura_pago', pago_id: {{$escritura->pago->id}}});" title="Abonar">
<i clasS="piggy bank icon"></i>
</a>
@endif
</td>
<td></td>
@else
<td colspan="5"></td>
@endif
</tr>

View File

@ -0,0 +1,31 @@
@if ($pie !== null)
<tr>
<td>
Pie
<a href="{{$urls->base}}/venta/{{$venta->id}}/pie">
<i class="edit icon"></i>
</a>
</td>
<td></td>
<td class="right aligned">{{$format->ufs($pie->valor)}}</td>
<td class="right aligned">{{$format->pesos($pie->valor * $pie->uf)}}</td>
<td class="right aligned">Cuotas</td>
<td>
<a href="{{$urls->base}}/venta/{{$venta->id}}/pie/cuotas">
{{count($pie->cuotas(true))}}/{{$pie->cuotas}}
</a>
@if (count($pie->cuotas()) < $pie->cuotas)
<a href="{{$urls->base}}/ventas/pie/{{$pie->id}}/cuotas/add">
<i class="plus icon"></i>
</a>
@endif
</td>
</tr>
<tr>
<td>Pagado</td>
<td></td>
<td class="right aligned">{{$format->ufs($pie->pagado())}}</td>
<td class="right aligned">{{$format->pesos($pie->pagado('pesos'))}}</td>
<td colspan="2"></td>
</tr>
@endif

View File

@ -0,0 +1,32 @@
<tr>
<td
@if ($subsidio !== null)
rowspan="2"
@endif
>
Subsidio
@if ($subsidio !== null)
<a href="{{$urls->base}}/venta/{{$venta->id}}/subsidio">
<i class="edit icon"></i>
</a>
@else
<a href="{{$urls->base}}/venta/{{$venta->id}}/subsidio/add">
<i class="plus icon"></i>
</a>
@endif
</td>
@if ($subsidio !== null)
<td>Ahorro</td>
<td class="right aligned">{{$format->ufs($subsidio->ahorro->valor())}}</td>
<td class="right aligned">{{$format->pesos($subsidio->ahorro->valor)}}</td>
<td colspan="2"></td>
</tr>
<tr>
<td>Subsidio</td>
<td class="right aligned">{{$format->ufs($subsidio->ahorro->valor())}}</td>
<td class="right aligned">{{$format->pesos($subsidio->ahorro->valor)}}</td>
<td colspan="2"></td>
@else
<td colspan="5"></td>
@endif
</tr>

View File

@ -0,0 +1,28 @@
<tr class="{{$venta->saldo() < 0 ? 'positive' : ($venta->saldo() > 0 ? 'error' : '')}}">
<td>
<strong>
Total
</strong>
</td>
<td></td>
<td class="right aligned">
<strong>
{{$format->ufs($formaPago->total())}}
</strong>
</td>
<td class="right aligned">
<strong>
{{$format->pesos($formaPago->total('pesos'))}}
</strong>
</td>
<td class="right aligned" >
@if ($venta->saldo() / $venta->valor > 0.01)
<strong>
&Delta;
{{$format->ufs($venta->saldo())}}
({{$format->number($venta->saldo() / $venta->valor * 100, 2)}} %)
</strong>
@endif
</td>
<td></td>
</tr>

View File

@ -0,0 +1,56 @@
<div class="ui inverted grey two column grid segment">
<div class="column">
PROPIEDAD
</div>
<div class="right aligned column">
<a style="color: inherit;" href="{{$urls->base}}/venta/{{$venta->id}}/propiedad">
<i class="edit icon"></i>
</a>
</div>
</div>
<div class="ui segment">
<table class="ui very basic fluid table">
<thead>
<tr>
<th colspan="2">Unidad</th>
<th class="center aligned">Piso</th>
<th class="right aligned">Metros vendibles</th>
<th class="right aligned">Precio</th>
<th class="right aligned">UF/</th>
<th class="center aligned">Orientacion</th>
</tr>
</thead>
<tbody>
@foreach($venta->propiedad()->unidades as $unidad)
<tr>
<td>
{{ucwords($unidad->proyectoTipoUnidad->tipoUnidad->descripcion)}}
@if ($unidad->proyectoTipoUnidad->tipoUnidad->descripcion === 'departamento')
{{$unidad->proyectoTipoUnidad->abreviacion}}
@endif
</td>
<td class="right aligned">
{{$unidad->descripcion}}
</td>
<td class="center aligned">
{{$unidad->piso}}
</td>
<td class="right aligned">
{{$format->number($unidad->proyectoTipoUnidad->vendible(), 2)}}
</td>
<td class="right aligned">
{{$format->ufs($unidad->precio($venta->fecha)->valor)}}
</td>
<td class="right aligned">
@if ($unidad->proyectoTipoUnidad->tipoUnidad->descripcion === 'departamento')
{{$format->number($unidad->precio($venta->fecha)->valor / $unidad->proyectoTipoUnidad->vendible(), 2)}} UF/
@endif
</td>
<td class="center aligned">
{{$unidad->orientacion}}
</td>
</tr>
@endforeach
</tbody>
</table>
</div>

View File

@ -0,0 +1,15 @@
<div class="ui fluid card">
<div class="content">
<a class="right floated icon link" href="{{$urls->base}}/venta/{{$venta->id}}/propietario">
<i class="edit icon"></i>
</a>
<a class="header" href="{{$urls->base}}/search/{{urlencode($venta->propietario()->nombreCompleto())}}">
{{$venta->propietario()->nombreCompleto()}}
<i class="tiny search icon"></i>
</a>
{{$venta->propietario()->rut()}}
<div class="meta">
{{$venta->propietario()->datos->direccion}}
</div>
</div>
</div>