2024-06-18
This commit is contained in:
@ -656,9 +656,9 @@
|
||||
}
|
||||
add() {
|
||||
return {
|
||||
propietario: ({rut, nombre, proporcion, direccion, comuna, fecha, uf}) => {
|
||||
propietario: ({rut, nombre, proporcion, direccion, comuna, fecha}) => {
|
||||
const index = this.props.propietarios.length + 1
|
||||
const propietario = new Propietario({index, rut, nombre, proporcion, direccion, comuna, fecha, uf})
|
||||
const propietario = new Propietario({index, proporcion, rut, nombre, direccion, comuna, fecha})
|
||||
this.props.propietarios.push(propietario)
|
||||
this.add().factura(propietario)
|
||||
return propietario
|
||||
@ -691,6 +691,47 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
save() {
|
||||
return {
|
||||
factura: ({index}) => {
|
||||
const factura = this.props.facturas[index]
|
||||
if (factura.props.saved) {
|
||||
return
|
||||
}
|
||||
const url = '{{$urls->api}}/ventas/facturas/add'
|
||||
const method = 'post'
|
||||
const body = new FormData()
|
||||
body.set('venta_id', this.props.id)
|
||||
body.set('index', (index+1).toString())
|
||||
const data = structuredClone(factura.props)
|
||||
delete data.index
|
||||
data.detalle.base = data.detalle.base.toFixed(0)
|
||||
data.detalle.terreno = data.detalle.terreno.toFixed(0)
|
||||
data.detalle.neto = data.detalle.neto.toFixed(0)
|
||||
data.detalle.iva = data.detalle.iva.toFixed(0)
|
||||
data.detalle.bruto = data.detalle.bruto.toFixed(0)
|
||||
data.detalle.total = data.detalle.total.toFixed(0)
|
||||
data.total.neto = data.total.neto.toFixed(0)
|
||||
data.total.exento = data.total.exento.toFixed(0)
|
||||
data.total.iva = data.total.iva.toFixed(0)
|
||||
data.total.total = data.total.total.toFixed(0)
|
||||
data.fecha = [data.fecha.getFullYear(), data.fecha.getMonth()+1, data.fecha.getDate()].join('-')
|
||||
data.uf.fecha = [data.uf.fecha.getFullYear(), data.uf.fecha.getMonth()+1, data.uf.fecha.getDate()].join('-')
|
||||
body.set('data', JSON.stringify(data))
|
||||
return fetchAPI(url, {method, body}).then(response => {
|
||||
if (!response) {
|
||||
return
|
||||
}
|
||||
return response.json().then(json => {
|
||||
if (!json.saved) {
|
||||
return
|
||||
}
|
||||
this.props.facturas[json.factura.index-1].props.saved = true
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
class Factura extends BaseObject {
|
||||
draw() {
|
||||
@ -699,6 +740,45 @@
|
||||
return '<div class="ui divider" data-index="'+index+'"></div>'
|
||||
},
|
||||
factura: ({proyecto, propietario, unidades, terreno, venta, uf, formatters = {date, pesos, ufs, percent}}) => {
|
||||
this.props.proporcion = propietario.props.proporcion
|
||||
this.props.emisor = {
|
||||
nombre: proyecto.inmobiliaria.nombre,
|
||||
rut: proyecto.inmobiliaria.rut,
|
||||
direccion: proyecto.direccion
|
||||
}
|
||||
this.props.receptor = {
|
||||
nombre: propietario.props.nombre,
|
||||
rut: propietario.props.rut,
|
||||
direccion: propietario.props.direccion,
|
||||
comuna: propietario.props.comuna
|
||||
}
|
||||
this.props.fecha = propietario.props.fecha
|
||||
this.props.unidades = []
|
||||
this.props.detalle = {
|
||||
base: venta.base * propietario.props.proporcion,
|
||||
terreno: venta.exento * propietario.props.proporcion,
|
||||
neto: venta.neto * propietario.props.proporcion,
|
||||
iva: venta.iva * propietario.props.proporcion,
|
||||
bruto: venta.bruto * propietario.props.proporcion,
|
||||
descuento: venta.descuento * propietario.props.proporcion,
|
||||
total: venta.total * propietario.props.proporcion
|
||||
}
|
||||
this.props.total = {
|
||||
neto: venta.neto * propietario.props.proporcion,
|
||||
exento: venta.exento * propietario.props.proporcion,
|
||||
iva: venta.iva * propietario.props.proporcion,
|
||||
total: venta.total * propietario.props.proporcion,
|
||||
}
|
||||
this.props.uf = uf
|
||||
unidades.forEach(unidad => {
|
||||
const descuento = terreno.reajustado * unidad.props.prorrateo
|
||||
const bruto = unidad.props.valor * uf.valor - descuento
|
||||
const neto = bruto / 1.19
|
||||
this.props.unidades.push({
|
||||
descripcion: unidad.props.tipo + ' ' + unidad.props.descripcion + ' (UF ' + formatters.ufs.format(unidad.props.valor * propietario.props.proporcion) + ')',
|
||||
precio: (neto * propietario.props.proporcion).toFixed(0)
|
||||
})
|
||||
})
|
||||
return [
|
||||
this.draw().divider(propietario.props.index),
|
||||
'<div class="factura" data-index="'+propietario.props.index+'">',
|
||||
@ -707,6 +787,7 @@
|
||||
this.draw().propietario({propietario, formatters}),
|
||||
this.draw().table({venta, unidades, propietario, terreno, uf, formatters}),
|
||||
this.draw().totales({propietario, venta, uf, formatters}),
|
||||
this.draw().guardar({index: propietario.props.index}),
|
||||
'</div>',
|
||||
'</div>'
|
||||
].join("\n")
|
||||
@ -868,7 +949,7 @@
|
||||
'SUBTOTAL (Bruto): $' + formatters.pesos.format((venta.neto + venta.iva) * propietario.props.proporcion) + '<br />' +
|
||||
'Mas valor terreno: $' + ((venta.exento > 0) ? formatters.pesos.format(venta.exento * propietario.props.proporcion) : emptyTerreno) + '<br />' +
|
||||
'TOTAL (Escritura): $' + formatters.pesos.format(venta.total * propietario.props.proporcion) + '; ' + formatters.ufs.format(venta.totalUF * propietario.props.proporcion) + ' UF<br /><br />' +
|
||||
'Descuento Terreno: ' + ((venta.exento > 0) ? formatters.percent.format(venta.descuento * 100) : emptyTerreno) + '%<br /><br />' +
|
||||
'Descuento Terreno: ' + ((venta.exento > 0) ? formatters.percent.format(venta.descuento * propietario.props.proporcion * 100) : emptyTerreno) + '%<br /><br />' +
|
||||
'UF (' + formatters.date.format(uf.fecha) + '): $' + formatters.ufs.format(uf.valor),
|
||||
'1 UNID',
|
||||
formatters.pesos.format(venta.exento * propietario.props.proporcion),
|
||||
@ -920,6 +1001,28 @@
|
||||
'</div>',
|
||||
'</div>'
|
||||
].join("\n")
|
||||
},
|
||||
guardar: ({index}) => {
|
||||
if (this.props.saved) {
|
||||
return [
|
||||
'<div class="row">',
|
||||
'<div class="fourteen wide column"></div>',
|
||||
'<div class="two wide center aligned column">',
|
||||
'<div class="ui green message">',
|
||||
'<i class="check icon"></i>',
|
||||
'Guardada',
|
||||
'</div>',
|
||||
'</div>',
|
||||
'</div>'
|
||||
].join("\n")
|
||||
}
|
||||
return [
|
||||
'<div class="row">',
|
||||
'<div class="right aligned sixteen wide column">',
|
||||
`<button class="ui primary button guardar" data-index="${index}">Guardar</button>`,
|
||||
'</div>',
|
||||
'</div>'
|
||||
].join("\n")
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -942,6 +1045,10 @@
|
||||
},
|
||||
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})
|
||||
})
|
||||
}
|
||||
}
|
||||
},
|
||||
@ -955,7 +1062,7 @@
|
||||
rut: '{{$venta->proyecto()->inmobiliaria()->rut()}}',
|
||||
nombre: '{{$venta->proyecto()->inmobiliaria()->nombreCompleto()}}'
|
||||
},
|
||||
direccion: '{{$venta->proyecto()->direccion()->simple()}}'
|
||||
direccion: '{{$venta->proyecto()->direccion()->simple()}}, {{$venta->proyecto()->direccion()->comuna->descripcion}}'
|
||||
},
|
||||
valor: {{$venta->valor}},
|
||||
uf: {
|
||||
@ -990,15 +1097,35 @@
|
||||
propietarios: [],
|
||||
facturas: []
|
||||
})
|
||||
this.venta.add().propietario({
|
||||
rut: '{{$venta->propietario()->rut()}}',
|
||||
nombre: '{{$venta->propietario()->nombreCompleto()}}',
|
||||
proporcion: 1,
|
||||
direccion: '{{$venta->propietario()->datos->direccion->simple()}}',
|
||||
comuna: '{{$venta->propietario()->datos->direccion->comuna->descripcion}}',
|
||||
fecha: new Date('{{$venta->currentEstado()->fecha->add(new DateInterval('P1D'))->format('Y-m-d')}}'),
|
||||
uf: {{$uf}}
|
||||
})
|
||||
@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({
|
||||
rut: '{{$venta->propietario()->rut()}}',
|
||||
nombre: '{{$venta->propietario()->nombreCompleto()}}',
|
||||
proporcion: 1,
|
||||
direccion: '{{$venta->propietario()->datos->direccion->simple()}}',
|
||||
comuna: '{{$venta->propietario()->datos->direccion->comuna->descripcion}}',
|
||||
fecha: new Date('{{$venta->currentEstado()->fecha->add(new DateInterval('P1D'))->format('Y-m-d')}}'),
|
||||
uf: {{$uf}}
|
||||
})
|
||||
@endif
|
||||
this.draw().venta()
|
||||
this.draw().facturas()
|
||||
}
|
||||
|
Reference in New Issue
Block a user