develop (#45)
Co-authored-by: Juan Pablo Vial <jpvialb@incoviba.cl> Reviewed-on: #45
This commit is contained in:
@ -13,439 +13,214 @@
|
||||
{{$venta->propiedad()->summary()}}
|
||||
</a>
|
||||
</h2>
|
||||
<div class="ui very basic segment">
|
||||
Valor Venta: {{$format->ufs($venta->valor)}}
|
||||
</div>
|
||||
<form id="venta_form" class="ui form">
|
||||
<div class="two wide field">
|
||||
<label for="proporcion">Proporción Factura</label>
|
||||
<div class="ui right labeled input">
|
||||
<input type="number" name="proporcion" id="proporcion" value="100" max="100" min="0"/>
|
||||
<div class="ui basic icon label">
|
||||
<i class="percent icon"></i>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="fields">
|
||||
@foreach ($venta->propiedad()->unidades as $unidad)
|
||||
<div class="three wide field">
|
||||
<label for="precio{{$unidad->pu_id}}">Precio {{ucwords($unidad->proyectoTipoUnidad->tipoUnidad->descripcion)}} {{$unidad->descripcion}}</label>
|
||||
<div class="ui right labeled input" id="input{{$unidad->pu_id}}">
|
||||
<input class="price" type="text" name="precio{{$unidad->pu_id}}" id="precio{{$unidad->pu_id}}" data-id="{{$unidad->pu_id}}" value="{{($unidad->valor > 0) ? $unidad->valor : $unidad->precio($venta->currentEstado()->fecha)->valor}}" />
|
||||
<div class="ui basic label">UF</div>
|
||||
</div>
|
||||
</div>
|
||||
@endforeach
|
||||
</div>
|
||||
<div class="fields">
|
||||
@foreach($venta->propiedad()->unidades as $unidad)
|
||||
<div class="three wide field">
|
||||
@if ($unidad->prorrateo === 0.0)
|
||||
<label for="prorrateo{{$unidad->id}}">Prorrateo {{ucwords($unidad->proyectoTipoUnidad->tipoUnidad->descripcion)}} {{$unidad->descripcion}}</label>
|
||||
<div class="ui right labeled input" id="prorrateo{{$unidad->id}}">
|
||||
<input class="prorrateo" type="text" data-id="{{$unidad->id}}" value="{{$unidad->prorrateo}}" />
|
||||
<div class="ui basic label">%</div>
|
||||
</div>
|
||||
@endif
|
||||
</div>
|
||||
@endforeach
|
||||
</div>
|
||||
<div class="ui very basic segment" id="total_unidades"></div>
|
||||
@php $lastDic = new DateTimeImmutable((new DateTimeImmutable())->sub(new DateInterval('P1Y'))->format('31-12-Y')); @endphp
|
||||
@if (!isset($venta->proyecto()->terreno->fecha) or $venta->proyecto()->terreno->fecha < $lastDic)
|
||||
<div class="four wide field">
|
||||
<label for="terreno">Valor Terreno al {{$lastDic->format('d-m-Y')}}</label>
|
||||
<div class="ui left labeled input">
|
||||
<div class="ui basic label">$</div>
|
||||
<input type="number" id="terreno" />
|
||||
</div>
|
||||
</div>
|
||||
@endif
|
||||
</form>
|
||||
@if ($venta->currentEstado()->fecha->sub(new DateInterval('P1M')) > $venta->proyecto()->terreno->fecha
|
||||
and $IPC->get($venta->proyecto()->terreno->fecha, $venta->currentEstado()->fecha->sub(new DateInterval('P1M'))) === 0.0)
|
||||
<div class="ui compact icon error message">
|
||||
<i class="exclamation triangle icon"></i>
|
||||
<div class="content">
|
||||
IPC no disponible para este mes.
|
||||
</div>
|
||||
</div>
|
||||
@endif
|
||||
<div class="ui divider"></div>
|
||||
<div id="factura">
|
||||
<div class="ui compact grid">
|
||||
<div class="two columns row">
|
||||
<div class="twelve wide column">
|
||||
<strong>
|
||||
{{mb_strtoupper($venta->proyecto()->inmobiliaria()->nombreCompleto())}}
|
||||
</strong><br/>
|
||||
GIRO: <br/>
|
||||
Dirección: {{$venta->proyecto()->direccion()->simple()}}
|
||||
</div>
|
||||
<div class="four wide column">
|
||||
<div class="ui center aligned red segment">
|
||||
<strong>
|
||||
RUT: {{$venta->proyecto()->inmobiliaria()->rut()}}<br/>
|
||||
FACTURA ELECTRÓNICA<br/>
|
||||
N° #
|
||||
</strong>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<table class="ui table">
|
||||
<tr>
|
||||
<td class="grey"><strong>Señor(es)</strong></td>
|
||||
<td>{{$venta->propietario()->nombreCompleto()}}</td>
|
||||
<td class="grey"><strong>RUT</strong></td>
|
||||
<td>{{$venta->propietario()->rut()}}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="grey"><strong>Giro</strong></td>
|
||||
<td>Otras Actividades Profesionales</td>
|
||||
<td class="grey"><strong>Fecha Emisión</strong></td>
|
||||
<td>{{(new IntlDateFormatter('es-CL', IntlDateFormatter::LONG, IntlDateFormatter::NONE))->format($venta->currentEstado()->fecha)}}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="grey"><strong>Dirección</strong></td>
|
||||
<td>{{$venta->propietario()->datos->direccion->simple()}}</td>
|
||||
<td class="grey"><strong>Comuna</strong></td>
|
||||
<td>{{mb_strtoupper($venta->propietario()->datos->direccion->comuna->descripcion)}}</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
<div class="row">
|
||||
<table class="ui celled table">
|
||||
<thead>
|
||||
<tr class="grey">
|
||||
<th class="center aligned" colspan="6">DETALLES</th>
|
||||
</tr>
|
||||
<tr class="grey">
|
||||
<th>N°</th>
|
||||
<th class="center aligned">Descripción</th>
|
||||
<th class="center aligned">Cant/Unidad</th>
|
||||
<th class="center aligned">Prec. Unit.</th>
|
||||
<th class="center aligned">Ind</th>
|
||||
<th class="center aligned">Total</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="unidades"></tbody>
|
||||
<tfoot>
|
||||
<tr>
|
||||
<td colspan="6">
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
</td>
|
||||
</tr>
|
||||
</tfoot>
|
||||
</table>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="ten wide column"></div>
|
||||
<div class="six wide column">
|
||||
<table class="ui celled very compact table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th class="center aligned grey" colspan="2">TOTALES</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td class="grey">Monto Neto</td>
|
||||
<td class="right aligned" id="neto"></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="grey">Monto Exento</td>
|
||||
<td class="right aligned" id="exento"></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="grey">19% IVA</td>
|
||||
<td class="right aligned" id="iva"></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="grey">Monto Total</td>
|
||||
<td class="right aligned"><strong id="total"></strong></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<span id="venta"></span>
|
||||
<div id="facturas"></div>
|
||||
</div>
|
||||
@endsection
|
||||
|
||||
@include('layout.body.scripts.rut')
|
||||
|
||||
@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 factura = {
|
||||
id: '#unidades',
|
||||
totales: {},
|
||||
proporcion: 1,
|
||||
precio: {{$UF->transform($venta->currentEstado()->fecha, $venta->valor)}},
|
||||
terreno: {{(isset($venta->proyecto()->terreno->fecha) and $venta->proyecto()->terreno->fecha >= $lastDic) ?
|
||||
$IPC->readjust($venta->proyecto()->terreno->valor, $venta->proyecto()->terreno->fecha, $venta->currentEstado()->fecha) : 0}},
|
||||
uf: {{$UF->get($venta->currentEstado()->fecha)}},
|
||||
unidades: JSON.parse('{!! json_encode(array_map(function(Incoviba\Model\Venta\PropiedadUnidad $unidad) use ($venta, $UF, $format) {
|
||||
$precio = ($unidad->valor > 0) ? $unidad->valor : ($unidad->precio($venta->currentEstado()->fecha) ? $unidad->precio($venta->currentEstado()->fecha)->valor : 0);
|
||||
return [
|
||||
'id' => $unidad->id,
|
||||
'pid' => $unidad->pu_id,
|
||||
'descripcion' => ucwords($unidad->proyectoTipoUnidad->tipoUnidad->descripcion) . ' ' . $unidad->descripcion,
|
||||
'precio' => $precio,
|
||||
'base' => $UF->transform($venta->currentEstado()->fecha, $precio),
|
||||
'prorrateo' => $unidad->prorrateo,
|
||||
];
|
||||
}, $venta->propiedad()->unidades)) !!}'),
|
||||
build: function() {
|
||||
const tbody = $(this.id)
|
||||
tbody.html('')
|
||||
const pesoFormatter = new Intl.NumberFormat('es-CL', {maximumFractionDigits: 0, minimumFractionDigits: 0})
|
||||
const ufFormatter = new Intl.NumberFormat('es-CL', {maximumFractionDigits: 2, minimumFractionDigits: 2})
|
||||
const percentFormatter = new Intl.NumberFormat('es-CL', {maximumFractionDigits: 5, minimumFractionDigits: 5})
|
||||
let terreno = 0
|
||||
let prorrateo = 0
|
||||
let totalUnidades = 0
|
||||
let precioUnidades = 0
|
||||
let c = 1
|
||||
const classes = [
|
||||
'',
|
||||
'',
|
||||
'center aligned',
|
||||
'right aligned',
|
||||
'center aligned',
|
||||
'right aligned'
|
||||
]
|
||||
this.unidades.forEach(unidad => {
|
||||
totalUnidades += unidad.base
|
||||
precioUnidades += unidad.precio
|
||||
const descuento = this.terreno * unidad.prorrateo
|
||||
terreno += descuento
|
||||
prorrateo += unidad.prorrateo
|
||||
const bruto = unidad.base - descuento
|
||||
const neto = bruto / 1.19
|
||||
const data = [
|
||||
c ++,
|
||||
unidad.descripcion + ' (UF ' + ufFormatter.format(unidad.precio * this.proporcion) + ')',
|
||||
'1 UNID',
|
||||
pesoFormatter.format(neto * this.proporcion),
|
||||
'AF',
|
||||
pesoFormatter.format(neto * this.proporcion)
|
||||
]
|
||||
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)
|
||||
this.venta.watch().facturas()
|
||||
}
|
||||
}
|
||||
},
|
||||
proporcion() {
|
||||
if (this.venta.props.facturas.facturas.length === 0) {
|
||||
return 1
|
||||
}
|
||||
return this.venta.props.facturas.facturas.reduce((sum, factura) => {
|
||||
return sum + factura.props.proporcion
|
||||
}, 0)
|
||||
},
|
||||
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]->uf->fecha->format('Y-m-d')}}'),
|
||||
valor: {{$facturas[0]->uf->valor}}
|
||||
}
|
||||
@foreach ($facturas as $factura)
|
||||
this.venta.props.facturas.facturas[{{$factura->index - 1}}] = new Factura({
|
||||
id: {{ $factura->id }},
|
||||
venta: this.venta.props,
|
||||
proporcion: {{ $factura->proporcion }},
|
||||
index: {{$factura->index}},
|
||||
fecha: new Date('{{$factura->fecha->format('Y-m-d')}}'),
|
||||
emisor: {
|
||||
rut: '{{$factura->venta->proyecto()->inmobiliaria()->rut}}',
|
||||
nombre: '{{$factura->venta->proyecto()->inmobiliaria()->razon}}',
|
||||
direccion: '{{$factura->venta->proyecto()->direccion()->simple()}}',
|
||||
comuna: '{{$factura->venta->proyecto()->direccion()->comuna->id}}',
|
||||
},
|
||||
receptor: {
|
||||
rut: '{{$factura->cliente->rutCompleto()}}',
|
||||
nombre: '{{$factura->cliente->nombreCompleto()}}',
|
||||
direccion: '{{$factura->cliente->datos()->direccion->simple()}}',
|
||||
comuna: '{{$factura->cliente->datos()->direccion->comuna->id}}',
|
||||
},
|
||||
terreno: {
|
||||
@if ($terreno->fecha != null) fecha: new Date('{{$terreno->fecha->add(new DateInterval('P1D'))->format('Y-m-d')}}'),
|
||||
@else fecha: null,
|
||||
@endif
|
||||
valor: {{ $factura->terreno}}
|
||||
},
|
||||
unidades: [
|
||||
@foreach ($factura->unidades as $unidad)
|
||||
{
|
||||
unidad: new Unidad({
|
||||
id: {{$unidad->unidad->id}},
|
||||
tipo: '{{ucwords($unidad->unidad->proyectoTipoUnidad->tipoUnidad->descripcion)}}',
|
||||
descripcion: '{{ $unidad->unidad->descripcion }}',
|
||||
prorrateo: {{$unidad->prorrateo}},
|
||||
propiedad_unidad_id: {{ array_values(array_filter($venta->propiedad()->unidades, function($uni) use ($unidad) {return $uni->id === $unidad->unidad->id;}))[0]->pu_id }},
|
||||
valor: {{$unidad->precio}}
|
||||
}),
|
||||
descripcion: '{{ucwords($unidad->unidad->proyectoTipoUnidad->tipoUnidad->descripcion)}} {{ $unidad->unidad->descripcion }} (UF {{ number_format(array_values(array_filter($venta->propiedad()->unidades, function($uni) use ($unidad, $factura) {return $uni->id === $unidad->unidad->id;}))[0]->precio($venta->currentEstado()->fecha)->valor * $factura->proporcion, 2) }})',
|
||||
precio: {{ $unidad->precio }},
|
||||
prorrateo: {{ $unidad->prorrateo }},
|
||||
},
|
||||
@endforeach
|
||||
],
|
||||
detalle: {
|
||||
base: {{ $factura->base() }},
|
||||
terreno: {{ $factura->terreno * $factura->proporcion * $factura->prorrateo }},
|
||||
neto: {{ $factura->neto() }},
|
||||
iva: {{ $factura->iva() }},
|
||||
bruto: {{ $factura->bruto() }},
|
||||
total: {{ $factura->total() }},
|
||||
descuento: {{ array_reduce($factura->unidades, function($sum, $unidad) use ($factura) { return $sum + $unidad->prorrateo * $factura->proporcion; }, 0) }}
|
||||
},
|
||||
total: {
|
||||
neto: {{ array_reduce($factura->unidades, function($sum, $unidad) {return $sum + $unidad->precio * $factura->proporcion;}, 0) }},
|
||||
exento: {{ $factura->terreno * $factura->proporcion }},
|
||||
iva: {{ $factura->iva() }},
|
||||
total: {{ $factura->total() }}
|
||||
},
|
||||
saved: true,
|
||||
uf: {
|
||||
fecha: new Date('{{$factura->uf->fecha->format('Y-m-d')}}'),
|
||||
valor: {{$factura->uf->valor}}
|
||||
}
|
||||
})
|
||||
this.venta.props.facturas.facturas[{{$factura->index - 1}}].props.saved = true
|
||||
this.venta.props.propietarios[{{$factura->index - 1}}] = new Propietario({
|
||||
index: {{$factura->index}},
|
||||
proporcion: {{$factura->proporcion}},
|
||||
rut: '{{$factura->cliente->rutCompleto()}}',
|
||||
nombre: '{{$factura->cliente->nombreCompleto()}}',
|
||||
direccion: '{{$factura->cliente->datos()->direccion->simple()}}',
|
||||
comuna: '{{$factura->cliente->datos()->direccion->comuna->id}}',
|
||||
fecha: new Date('{{$factura->fecha->format('Y-m-d')}}'),
|
||||
})
|
||||
@endforeach
|
||||
this.draw().venta()
|
||||
if (this.proporcion() < 1) {
|
||||
const p = 1 - this.proporcion()
|
||||
const propietario = this.venta.add().propietario({
|
||||
rut: '',
|
||||
nombre: '',
|
||||
proporcion: (p*100).toFixed(0)/100,
|
||||
direccion: '',
|
||||
comuna: '0'
|
||||
})
|
||||
document.getElementById('propietarios').innerHTML = this.venta.draw().propietarios()
|
||||
document.getElementById('cantidad_propietarios').value = this.venta.props.propietarios.length
|
||||
this.venta.add().factura(propietario)
|
||||
|
||||
const row = $('<tr></tr')
|
||||
data.forEach((value, i) => {
|
||||
const cell = $('<td></td>')
|
||||
if (classes[i] !== '') {
|
||||
cell.addClass(classes[i])
|
||||
}
|
||||
cell.html(value)
|
||||
row.append(cell)
|
||||
this.draw().facturas()
|
||||
}
|
||||
@else
|
||||
const propietario = 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}}'
|
||||
})
|
||||
tbody.append(row)
|
||||
})
|
||||
$('#total_unidades')
|
||||
.attr('class', 'ui compact segment ' + ((totalUnidades.toFixed(2) !== this.precio.toFixed(2)) ? 'inverted red' : 'inverted green'))
|
||||
.html('Total Unidades: ' + ufFormatter.format(precioUnidades) + ' UF' +
|
||||
((totalUnidades.toFixed(2) !== this.precio.toFixed(2)) ? '; Diferencia: ' + ufFormatter.format({{$venta->valor}} - precioUnidades) + ' UF' : ''))
|
||||
if (totalUnidades.toFixed(2) !== this.precio.toFixed(2)) {
|
||||
this.highlight()
|
||||
}
|
||||
const bruto = this.precio - terreno
|
||||
const base = bruto / 1.19
|
||||
const iva = base * .19
|
||||
const subtotal = base + iva
|
||||
const total = subtotal + terreno
|
||||
const totalUF = total / this.uf
|
||||
|
||||
const emptyTerreno = '<div class="ui tiny red horizontal circular label">0</div>'
|
||||
const data = [
|
||||
c,
|
||||
'Valor con Terreno ' + pesoFormatter.format((base + terreno) * this.proporcion) + ' - Menos valor terreno ' + ((terreno > 0) ? pesoFormatter.format(-terreno * this.proporcion) : emptyTerreno) + '<br />' +
|
||||
'Base imponible ' + pesoFormatter.format(base * this.proporcion) + '<br />' +
|
||||
'IVA ' + pesoFormatter.format(iva * this.proporcion) + '<br />' +
|
||||
'SUBTOTAL ' + pesoFormatter.format(subtotal * this.proporcion) + '<br />' +
|
||||
'Mas valor terreno ' + ((terreno > 0) ? pesoFormatter.format(terreno * this.proporcion) : emptyTerreno) + '<br />' +
|
||||
'TOTAL ' + pesoFormatter.format(total * this.proporcion) + ';' + ufFormatter.format(totalUF * this.proporcion) + ' UF<br /><br />' +
|
||||
'Descuento Terreno: ' + ((terreno > 0) ? percentFormatter.format(prorrateo * 100) : emptyTerreno) + '%<br /><br />' +
|
||||
'UF: ' + ufFormatter.format(this.uf),
|
||||
'1 UNID',
|
||||
pesoFormatter.format(terreno * this.proporcion),
|
||||
'EX',
|
||||
pesoFormatter.format(terreno * this.proporcion)
|
||||
]
|
||||
const row = $('<tr></tr>').addClass('top aligned')
|
||||
data.forEach((value, i) => {
|
||||
const cell = $('<td></td>')
|
||||
if (classes[i] !== '') {
|
||||
cell.addClass(classes[i])
|
||||
this.draw().venta()
|
||||
if (typeof propietario !== 'undefined') {
|
||||
this.venta.add().factura(propietario)
|
||||
}
|
||||
cell.html(value)
|
||||
row.append(cell)
|
||||
})
|
||||
tbody.append(row)
|
||||
|
||||
$(this.totales.afecto).html(pesoFormatter.format(base * this.proporcion))
|
||||
$(this.totales.exento).html(pesoFormatter.format(terreno * this.proporcion))
|
||||
$(this.totales.iva).html(pesoFormatter.format(iva * this.proporcion))
|
||||
$(this.totales.total).html(pesoFormatter.format(total * this.proporcion))
|
||||
},
|
||||
update: function() {
|
||||
return {
|
||||
price: (id, value) => {
|
||||
this.unhighlight()
|
||||
const idx = this.unidades.findIndex(unidad => unidad.pid === id)
|
||||
if (idx === -1) {
|
||||
return
|
||||
}
|
||||
const old_value = this.unidades[idx].precio
|
||||
if (old_value === parseFloat(value)) {
|
||||
return
|
||||
}
|
||||
const url = '{{$urls->api}}/ventas/propiedades/unidad/' + id + '/edit'
|
||||
const data = new FormData()
|
||||
data.set('valor', value)
|
||||
return fetchAPI(url, {method: 'post', body: data}).then(response => {
|
||||
if (response.ok) {
|
||||
return response.json()
|
||||
}
|
||||
}).then(json => {
|
||||
if (!json.edited) {
|
||||
return
|
||||
}
|
||||
const idx = this.unidades.findIndex(unidad => unidad.pid === json.propiedad_unidad_id)
|
||||
this.unidades[idx].precio = parseFloat(json.input.valor)
|
||||
this.unidades[idx].base = parseFloat(json.input.valor * this.unidades[idx].base / old_value)
|
||||
this.build()
|
||||
})
|
||||
},
|
||||
terreno: value => {
|
||||
const url = '{{$urls->api}}/proyecto/{{$venta->proyecto()->id}}/terreno/edit'
|
||||
const data = new FormData()
|
||||
data.set('valor', value)
|
||||
data.set('fecha', '{{$lastDic->format('Y-m-d')}}')
|
||||
return fetchAPI(url, {method: 'post', body: data}).then(response => {
|
||||
if (response.ok) {
|
||||
return response.json()
|
||||
}
|
||||
}).then(json => {
|
||||
if (!json.edited) {
|
||||
return
|
||||
}
|
||||
this.terreno = parseInt(json.input.valor)
|
||||
const data = new FormData()
|
||||
data.set('start', '{{$lastDic->format('Y-m-d')}}')
|
||||
data.set('end', '{{$venta->currentEstado()->fecha->sub(new DateInterval('P1M'))->format('Y-m-d')}}')
|
||||
const url = '{{$urls->api}}/money/ipc'
|
||||
return fetchAPI(url, {method: 'post', body: data}).then(response => {
|
||||
if (response.ok) {
|
||||
return response.json()
|
||||
}
|
||||
}).then(json => {
|
||||
this.terreno *= (1 + parseFloat(json.ipc))
|
||||
this.build()
|
||||
})
|
||||
})
|
||||
},
|
||||
prorrateo: (id, value) => {
|
||||
if (parseFloat(value) === 0) {
|
||||
return
|
||||
}
|
||||
const url = '{{$urls->api}}/ventas/unidad/' + id + '/prorrateo'
|
||||
const data = new FormData()
|
||||
data.set('prorrateo', value)
|
||||
return fetchAPI(url, {method: 'post', body: data}).then(response => {
|
||||
if (response.ok) {
|
||||
return response.json()
|
||||
}
|
||||
}).then(json => {
|
||||
if (!json.edited) {
|
||||
return
|
||||
}
|
||||
const idx = this.unidades.findIndex(unidad => unidad.id === json.unidad_id)
|
||||
this.unidades[idx].prorrateo = parseFloat(json.input.prorrateo)
|
||||
this.build()
|
||||
})
|
||||
}
|
||||
}
|
||||
},
|
||||
watch: function() {
|
||||
return {
|
||||
proporcion: id => {
|
||||
$(id).change(event => {
|
||||
const val = $(event.currentTarget).val()
|
||||
if (val / 100 === this.proporcion) {
|
||||
return
|
||||
}
|
||||
this.proporcion = val / 100
|
||||
this.build()
|
||||
})
|
||||
},
|
||||
prices: class_name => {
|
||||
$(class_name).change(event => {
|
||||
const val = $(event.currentTarget).val()
|
||||
const id = $(event.currentTarget).data('id')
|
||||
this.update().price(id, val)
|
||||
})
|
||||
},
|
||||
prorrateo: class_name => {
|
||||
$(class_name).change(event => {
|
||||
const val = $(event.currentTarget).val()
|
||||
const id = $(event.currentTarget).data('id')
|
||||
this.update().prorrateo(id, val)
|
||||
})
|
||||
},
|
||||
terreno: id => {
|
||||
$(id).change(event => {
|
||||
const val = $(event.currentTarget).val()
|
||||
this.update().terreno(val).then(() => {
|
||||
$(id).parent().parent().hide()
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
},
|
||||
highlight: function() {
|
||||
const pid = this.unidades[0].pid
|
||||
const input = $('#input' + pid)
|
||||
input.addClass('error')
|
||||
input.find('.label').addClass('red')
|
||||
input.attr('data-content', 'Valor total no es igual a valor de venta')
|
||||
input.popup()
|
||||
},
|
||||
unhighlight: function() {
|
||||
const pid = this.unidades[0].pid
|
||||
const input = $('#input' + pid)
|
||||
input.removeClass('error')
|
||||
input.find('.label').removeClass('red')
|
||||
input.removeAttr('data-content')
|
||||
},
|
||||
setup: function({form_id, tbody_id, input_id, prices_class, prorrateo_class, terreno_id, totales_ids}) {
|
||||
$(form_id).submit(event => {
|
||||
event.preventDefault()
|
||||
return false
|
||||
})
|
||||
this.id = tbody_id
|
||||
this.totales = totales_ids
|
||||
this.proporcion = $(input_id).val() / 100
|
||||
this.watch().proporcion(input_id)
|
||||
this.watch().prices(prices_class)
|
||||
this.watch().prorrateo(prorrateo_class)
|
||||
@if (!isset($venta->proyecto()->terreno->fecha) or $venta->proyecto()->terreno->fecha <= $lastDic)
|
||||
this.watch().terreno(terreno_id)
|
||||
@endif
|
||||
this.build()
|
||||
this.draw().facturas()
|
||||
}
|
||||
}
|
||||
$(document).ready(() => {
|
||||
factura.setup({form_id: '#venta_form', tbody_id: '#unidades', input_id: '#proporcion',
|
||||
prices_class: '.price', prorrateo_class: '.prorrateo', terreno_id: '#terreno', totales_ids: {
|
||||
afecto: '#neto',
|
||||
exento: '#exento',
|
||||
iva: '#iva',
|
||||
total: '#total'
|
||||
}})
|
||||
facturas.setup({
|
||||
ids: {
|
||||
venta: 'venta',
|
||||
facturas: 'facturas'
|
||||
}
|
||||
})
|
||||
})
|
||||
</script>
|
||||
@endpush
|
||||
|
Reference in New Issue
Block a user