Separacion de objetos
This commit is contained in:
@ -115,7 +115,7 @@
|
||||
})
|
||||
@endforeach
|
||||
@else
|
||||
this.venta.add().propietario({
|
||||
const propietario = this.venta.add().propietario({
|
||||
proporcion: 1,
|
||||
rut: '{{$venta->propietario()->rut()}}',
|
||||
nombre: '{{$venta->propietario()->nombreCompleto()}}',
|
||||
@ -124,7 +124,9 @@
|
||||
})
|
||||
@endif
|
||||
this.draw().venta()
|
||||
this.venta.update().facturas()
|
||||
if (typeof propietario !== 'undefined') {
|
||||
this.venta.add().factura(propietario)
|
||||
}
|
||||
this.draw().facturas()
|
||||
}
|
||||
}
|
||||
|
@ -186,16 +186,16 @@
|
||||
return unidadesData.join("\n")
|
||||
},
|
||||
unidad: ({unidad, no, classes, formatters}) => {
|
||||
const descuento = Math.round(this.props.detalle.terreno * unidad.prorrateo)
|
||||
const descuento = this.props.detalle.terreno * unidad.prorrateo
|
||||
const bruto = unidad.precio - descuento
|
||||
const neto = bruto / 1.19
|
||||
const data = [
|
||||
no,
|
||||
unidad.descripcion,
|
||||
'1 UNID',
|
||||
formatters.pesos.format(neto * this.props.proporcion),
|
||||
formatters.pesos.format(neto),
|
||||
'AF',
|
||||
formatters.pesos.format(neto * this.props.proporcion)
|
||||
formatters.pesos.format(neto)
|
||||
]
|
||||
|
||||
const row = ['<tr>']
|
||||
@ -308,22 +308,24 @@
|
||||
}
|
||||
}
|
||||
save() {
|
||||
let url = '{{$urls->api}}/venta/{{$venta->id}}/facturas/add'
|
||||
let url = '{{$urls->api}}/ventas/facturas/add'
|
||||
if (this.saved) {
|
||||
url = `{{$urls->api}}/venta/{{$venta->id}}/facturas/${this.props.id}/edit`
|
||||
url = `{{$urls->api}}/ventas/facturas/${this.props.id}/edit`
|
||||
}
|
||||
const method = 'post'
|
||||
const body = new FormData()
|
||||
body.set('venta_id', this.props.venta_id)
|
||||
body.set('venta_id', this.props.venta.id)
|
||||
body.set('index', this.props.index)
|
||||
body.set('proporcion', this.props.proporcion)
|
||||
body.set('cliente', JSON.stringify(this.props.receptor))
|
||||
body.set('terreno', this.props.terreno)
|
||||
body.set('unidades', JSON.stringify(this.props.unidades))
|
||||
body.set('terreno', this.props.detalle.terreno)
|
||||
body.set('unidades', JSON.stringify(this.props.unidades.map(unidad => {
|
||||
return {unidad_id: unidad.unidad.props.id, precio: unidad.precio, prorrateo: unidad.prorrateo}
|
||||
})))
|
||||
body.set('fecha', [this.props.fecha.getFullYear(), this.props.fecha.getMonth()+1, this.props.fecha.getDate()].join('-'))
|
||||
body.set('detalle', JSON.stringify(this.props.detalle))
|
||||
body.set('total', JSON.stringify(this.props.total))
|
||||
body.set('uf', JSON.stringify(this.props.uf))
|
||||
body.set('uf', JSON.stringify({fecha: [this.props.uf.fecha.getFullYear(), this.props.uf.fecha.getMonth()+1, this.props.uf.fecha.getDate()].join('-'), valor: this.props.uf.valor}))
|
||||
return APIClient.fetch(url, {method, body}).then(response => {
|
||||
if (!response) {
|
||||
return
|
||||
@ -345,10 +347,11 @@
|
||||
this.props.uf.valor = venta.props.uf.valor
|
||||
this.update().propietario(venta.props.propietarios.find(propietario => propietario.props.index === this.props.index))
|
||||
this.update().unidades(venta.props.unidades)
|
||||
this.props.detalle.total = venta.props.valor * this.props.proporcion * venta.props.uf.valor
|
||||
this.props.total.total = this.props.detalle.total = venta.props.valor * this.props.proporcion * venta.props.uf.valor
|
||||
this.update().detalle(venta.props.facturas.terreno.valor * venta.prorrateo)
|
||||
this.props.total.exento = this.props.detalle.terreno
|
||||
this.props.total.iva = this.props.detalle.iva
|
||||
this.props.total.neto = this.props.unidades.reduce((sum, unidad) => sum + unidad.precio, 0)
|
||||
this.props.detalle.descuento = venta.prorrateo * this.props.proporcion
|
||||
},
|
||||
detalle: terreno => {
|
||||
@ -360,7 +363,6 @@
|
||||
},
|
||||
unidades: unidades => {
|
||||
this.props.unidades = []
|
||||
let neto = 0
|
||||
unidades.forEach(unidad => {
|
||||
this.props.unidades.push({
|
||||
unidad: unidad,
|
||||
@ -368,9 +370,7 @@
|
||||
precio: unidad.props.valor * this.props.uf.valor * this.props.proporcion,
|
||||
prorrateo: unidad.props.prorrateo * this.props.proporcion
|
||||
})
|
||||
neto += unidad.props.valor
|
||||
})
|
||||
this.props.total.neto = neto
|
||||
},
|
||||
propietario: propietario => {
|
||||
this.props.proporcion = propietario.props.proporcion
|
||||
|
@ -20,27 +20,27 @@
|
||||
return {
|
||||
proporcion: (valor) => {
|
||||
this.props.proporcion = valor
|
||||
facturas.venta.update().totalPropietarios()
|
||||
facturas.venta.update().facturas()
|
||||
facturas.draw().facturas()
|
||||
},
|
||||
rut: rut => {
|
||||
this.props.rut = rut
|
||||
facturas.venta.update().totalPropietarios()
|
||||
facturas.venta.update().facturas()
|
||||
facturas.draw().facturas()
|
||||
},
|
||||
nombre: nombre => {
|
||||
this.props.nombre = nombre
|
||||
facturas.venta.update().totalPropietarios()
|
||||
facturas.venta.update().facturas()
|
||||
facturas.draw().facturas()
|
||||
},
|
||||
direccion: direccion => {
|
||||
this.props.direccion = direccion
|
||||
facturas.venta.update().totalPropietarios()
|
||||
facturas.venta.update().facturas()
|
||||
facturas.draw().facturas()
|
||||
},
|
||||
comuna: comuna => {
|
||||
this.props.comuna = comuna
|
||||
facturas.venta.update().totalPropietarios()
|
||||
facturas.venta.update().facturas()
|
||||
facturas.draw().facturas()
|
||||
},
|
||||
}
|
||||
|
@ -59,16 +59,20 @@
|
||||
p -= this.props.propietarios[index].props.proporcion
|
||||
})
|
||||
p /= diff
|
||||
const propietarios = []
|
||||
for (let i = 0; i < diff; i ++) {
|
||||
this.add().propietario({
|
||||
propietarios.push(this.add().propietario({
|
||||
rut: '',
|
||||
nombre: '',
|
||||
proporcion: (p*100).toFixed(0)/100,
|
||||
direccion: '',
|
||||
comuna: ''
|
||||
})
|
||||
}))
|
||||
}
|
||||
document.getElementById('propietarios').innerHTML = this.draw().propietarios()
|
||||
propietarios.forEach(propietario => {
|
||||
this.add().factura(propietario)
|
||||
})
|
||||
this.watch().propietarios()
|
||||
this.update().facturas()
|
||||
return
|
||||
@ -121,16 +125,7 @@
|
||||
'</div>')
|
||||
$total.find('.ui.message').css('display', 'inline-block')
|
||||
|
||||
this.props.facturas.forEach(factura => {
|
||||
factura.update().unidades(this.props.unidades)
|
||||
})
|
||||
},
|
||||
totalPropietarios: () => {
|
||||
this.props.propietarios.forEach(propietario => {
|
||||
const index = propietario.props.index
|
||||
const factura = this.props.facturas.facturas.find(factura => factura.props.index === index)
|
||||
factura.update().venta(this)
|
||||
})
|
||||
this.update().facturas()
|
||||
},
|
||||
terreno: newValue => {
|
||||
const date = this.props.last.november
|
||||
@ -250,7 +245,6 @@
|
||||
return
|
||||
}
|
||||
this.update().propietarios(count)
|
||||
this.update().totalPropietarios()
|
||||
facturas.draw().facturas()
|
||||
})
|
||||
},
|
||||
@ -396,7 +390,6 @@
|
||||
const index = this.props.propietarios.length + 1
|
||||
const propietario = new Propietario({index, proporcion, rut, nombre, direccion, comuna})
|
||||
this.props.propietarios.push(propietario)
|
||||
this.add().factura(propietario)
|
||||
return propietario
|
||||
},
|
||||
factura: propietario => {
|
||||
@ -455,7 +448,7 @@
|
||||
this.remove().factura(index)
|
||||
},
|
||||
factura: index => {
|
||||
this.props.facturas.splice(index, 1)
|
||||
this.props.facturas.facturas.splice(index, 1)
|
||||
document.getElementById('facturas').querySelectorAll("[data-index='"+(index+1)+"']").forEach(factura => {
|
||||
factura.remove()
|
||||
})
|
||||
@ -465,7 +458,7 @@
|
||||
save() {
|
||||
return {
|
||||
factura: ({index}) => {
|
||||
const factura = this.props.facturas[index]
|
||||
const factura = this.props.facturas.facturas[index]
|
||||
return factura.save()
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user