Cleanup logs, fixed add Venta, fixed search
This commit is contained in:
@ -107,9 +107,10 @@
|
||||
const uri = '{{$urls->api}}/search'
|
||||
this.data = []
|
||||
return fetchAPI(uri, {method: 'post', body: data}).then(response => {
|
||||
if (response.ok) {
|
||||
return response.json()
|
||||
if (!response) {
|
||||
return
|
||||
}
|
||||
return response.json()
|
||||
}).catch(error => {
|
||||
this.draw().clear()
|
||||
this.draw().error(error)
|
||||
@ -123,7 +124,11 @@
|
||||
const promises = []
|
||||
data.results.forEach(row => {
|
||||
if (row.tipo === 'venta') {
|
||||
promises.push(this.get().venta(row.id).then(json => {
|
||||
return promises.push(this.get().venta(row.id).then(json => {
|
||||
if (json.venta === null) {
|
||||
console.debug(json)
|
||||
return
|
||||
}
|
||||
const venta = json.venta
|
||||
progress.progress('increment')
|
||||
const r = new Row({unidad: venta.propiedad.unidades[0], proyecto: venta.proyecto})
|
||||
@ -134,7 +139,6 @@
|
||||
console.error(row)
|
||||
console.error(error)
|
||||
}))
|
||||
return
|
||||
}
|
||||
promises.push(this.get().unidad(row.id).then(json => {
|
||||
const unidad = json.unidad
|
||||
@ -164,9 +168,10 @@
|
||||
venta: id => {
|
||||
const url = '{{$urls->api}}/venta/' + id
|
||||
return fetchAPI(url).then(response => {
|
||||
if (response.ok) {
|
||||
return response.json()
|
||||
if (!response) {
|
||||
return
|
||||
}
|
||||
return response.json()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -3,7 +3,7 @@
|
||||
@section('page_content')
|
||||
<div class="ui container">
|
||||
<h2 class="ui header">Nueva Venta</h2>
|
||||
<form class="ui form" id="add_form" action="{{$urls->api}}/ventas/add" method="post">
|
||||
<form class="ui form" id="add_form" method="post">
|
||||
<label for="fecha_venta">Fecha de Venta</label>
|
||||
<div class="inline field">
|
||||
<div class="ui calendar" id="fecha_venta_calendar">
|
||||
@ -686,7 +686,7 @@
|
||||
$('<div></div>').addClass('content').append(tipo.charAt(0).toUpperCase() + tipo.slice(1) + ' ').append(
|
||||
unidad.draw(this.unidades[tipo])
|
||||
).append(
|
||||
$('<button></button>').addClass('ui icon button').attr('type', 'button').attr('data-number', number).append(
|
||||
$('<button></button>').addClass('ui basic red icon button').attr('type', 'button').attr('data-number', number).append(
|
||||
$('<i></i>').addClass('remove icon')
|
||||
).click(event => {
|
||||
const number = $(event.currentTarget).attr('data-number')
|
||||
@ -766,7 +766,7 @@
|
||||
}
|
||||
|
||||
function showErrors(errors) {
|
||||
console.debug(errors)
|
||||
console.error(errors)
|
||||
}
|
||||
|
||||
$(document).ready(() => {
|
||||
@ -789,20 +789,21 @@
|
||||
|
||||
$('#add_form').submit(event => {
|
||||
event.preventDefault()
|
||||
const data = new FormData(event.currentTarget)
|
||||
const uri = $(event.currentTarget).attr('action')
|
||||
fetch(uri, {method: 'post', body: data}).then(response => {
|
||||
if (response.ok) {
|
||||
return response.json()
|
||||
const body = new FormData(event.currentTarget)
|
||||
const uri = '{{$urls->api}}/ventas/add'
|
||||
return fetchAPI(uri, {method: 'post', body}).then(response => {
|
||||
if (!response) {
|
||||
return false
|
||||
}
|
||||
}).then(data => {
|
||||
if (data.status) {
|
||||
window.location = '{{$urls->base}}'
|
||||
return true
|
||||
}
|
||||
showErrors(data.errors)
|
||||
return response.json().then(data => {
|
||||
if (data.status) {
|
||||
window.location = '{{$urls->base}}/venta/' + data.venta_id
|
||||
return true
|
||||
}
|
||||
showErrors(data.errors)
|
||||
return false
|
||||
})
|
||||
})
|
||||
return false
|
||||
})
|
||||
})
|
||||
</script>
|
||||
|
Reference in New Issue
Block a user