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