141 lines
6.7 KiB
PHP
141 lines
6.7 KiB
PHP
@extends('layout.base')
|
|
|
|
@section('page_content')
|
|
<div class="ui container">
|
|
<h2 class="ui header">
|
|
Facturación -
|
|
<a href="{{$urls->base}}/proyecto/{{$venta->proyecto()->id}}">
|
|
{{$venta->proyecto()->descripcion}}<span class="ui tiny text"><sub><i
|
|
class="search icon"></i></sub></span>
|
|
</a>
|
|
-
|
|
<a href="{{$urls->base}}/venta/{{$venta->id}}">
|
|
{{$venta->propiedad()->summary()}}
|
|
</a>
|
|
</h2>
|
|
<span id="venta"></span>
|
|
<div id="facturas"></div>
|
|
</div>
|
|
@endsection
|
|
|
|
@push('page_scripts')
|
|
@include('ventas.facturacion.show.factura')
|
|
@include('ventas.facturacion.show.propietario')
|
|
@include('ventas.facturacion.show.unidad')
|
|
@include('ventas.facturacion.show.venta')
|
|
<script>
|
|
const facturas = {
|
|
ids: {},
|
|
venta: null,
|
|
formatters: {
|
|
date: new Intl.DateTimeFormat('es-CL', {year: 'numeric', month: '2-digit', day: '2-digit'}),
|
|
pesos: new Intl.NumberFormat('es-CL', {minimumFractionDigits: 0, maximumFractionDigits: 0}),
|
|
ufs: new Intl.NumberFormat('es-CL', {minimumFractionDigits: 2, maximumFractionDigits: 2}),
|
|
percent: new Intl.NumberFormat('es-CL', {minimumFractionDigits: 4, maximumFractionDigits: 4})
|
|
},
|
|
draw() {
|
|
return {
|
|
venta: () => {
|
|
document.getElementById(this.ids.venta).innerHTML = this.venta.draw().venta(this.formatters.ufs)
|
|
this.venta.watch().venta()
|
|
},
|
|
facturas: () => {
|
|
document.getElementById(this.ids.facturas).innerHTML = this.venta.draw().facturas(this.formatters)
|
|
$('button.guardar').click(clickEvent => {
|
|
const index = clickEvent.currentTarget.getAttribute('data-index')
|
|
facturas.venta.save().factura({index: index-1})
|
|
})
|
|
}
|
|
}
|
|
},
|
|
setup({ids}) {
|
|
this.ids = ids
|
|
this.venta = new Venta({
|
|
id: {{$venta->id}},
|
|
inmobiliaria: {
|
|
rut: '{{$venta->proyecto()->inmobiliaria()->rut()}}',
|
|
nombre: '{{$venta->proyecto()->inmobiliaria()->nombreCompleto()}}',
|
|
direccion: '{{$venta->proyecto()->direccion()->simple()}}',
|
|
comuna: '{{$venta->proyecto()->direccion()->comuna->descripcion}}'
|
|
},
|
|
proyecto: {
|
|
id: {{$venta->proyecto()->id}},
|
|
},
|
|
valor: {{$venta->valor}},
|
|
uf: {
|
|
fecha: new Date('{{$venta->currentEstado()->fecha->add(new DateInterval('P1D'))->format('Y-m-d')}}'),
|
|
valor: {{$uf}}
|
|
},
|
|
estado: {
|
|
fecha: new Date('{{$venta->currentEstado()->fecha->add(new DateInterval('P1D'))->format('Y-m-d')}}')
|
|
},
|
|
last: {
|
|
november: new Date('{{(new DateTimeImmutable())->sub(new DateInterval('P1Y'))->format('Y-11-30')}}')
|
|
},
|
|
unidades: [
|
|
@foreach ($venta->propiedad()->unidades as $unidad)
|
|
new Unidad({
|
|
id: {{$unidad->id}},
|
|
tipo: '{{ucwords($unidad->proyectoTipoUnidad->tipoUnidad->descripcion)}}',
|
|
descripcion: '{{$unidad->descripcion}}',
|
|
prorrateo: {{$unidad->prorrateo}},
|
|
propiedad_unidad_id: {{$unidad->pu_id}},
|
|
valor: {{($unidad->valor > 0) ? $unidad->valor : $unidad->precio($venta->currentEstado()->fecha)->valor}}
|
|
}),
|
|
@endforeach
|
|
],
|
|
propietarios: [],
|
|
facturas: {
|
|
fecha: new Date('{{$venta->currentEstado()->fecha->add(new DateInterval('P1D'))->format('Y-m-d')}}'),
|
|
terreno: {
|
|
@if ($terreno->fecha != null) fecha: new Date('{{$terreno->fecha->add(new DateInterval('P1D'))->format('Y-m-d')}}'),
|
|
@else fecha: null,
|
|
@endif
|
|
valor: {{($terreno->valor ?? 0) * (1+$ipc)}}
|
|
},
|
|
facturas: []
|
|
}
|
|
})
|
|
@if (count($facturas) > 0)
|
|
this.venta.props.uf = {
|
|
fecha: new Date('{{$facturas[0]->fechaUF->format('Y-m-d')}}'),
|
|
valor: {{$facturas[0]->valorUF}}
|
|
}
|
|
@foreach ($facturas as $factura)
|
|
this.venta.props.facturas[{{$factura->index-1}}] = new Factura(JSON.parse('{!! json_encode($factura) !!}'))
|
|
this.venta.props.facturas[{{$factura->index-1}}].props.saved = true
|
|
this.venta.props.propietarios[{{$factura->index-1}}] = new Propietario({
|
|
index: {{$factura->index}},
|
|
proporcion: {{$factura->proporcion}},
|
|
rut: '{{$factura->receptorRut}}',
|
|
nombre: '{{$factura->receptorNombre}}',
|
|
direccion: '{{$factura->receptorDireccion}}',
|
|
comuna: '{{$factura->receptorComuna}}',
|
|
fecha: new Date('{{$factura->fecha->format('Y-m-d')}}'),
|
|
})
|
|
@endforeach
|
|
@else
|
|
this.venta.add().propietario({
|
|
proporcion: 1,
|
|
rut: '{{$venta->propietario()->rut()}}',
|
|
nombre: '{{$venta->propietario()->nombreCompleto()}}',
|
|
direccion: '{{$venta->propietario()->datos->direccion->simple()}}',
|
|
comuna: '{{$venta->propietario()->datos->direccion->comuna->id}}'
|
|
})
|
|
@endif
|
|
this.draw().venta()
|
|
this.venta.update().facturas()
|
|
this.draw().facturas()
|
|
}
|
|
}
|
|
$(document).ready(() => {
|
|
facturas.setup({
|
|
ids: {
|
|
venta: 'venta',
|
|
facturas: 'facturas'
|
|
}
|
|
})
|
|
})
|
|
</script>
|
|
@endpush
|