Skip to content

Commit

Permalink
Implemented the handler of the register form
Browse files Browse the repository at this point in the history
  • Loading branch information
cbdavide committed Oct 12, 2017
1 parent e6389a4 commit a741c08
Showing 1 changed file with 62 additions and 1 deletion.
63 changes: 62 additions & 1 deletion sales/static/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,64 @@ $(document).ready(function() {
})

forms['register'].on('submit', function(e) {
console.log('ja')

var name = trimText(elements['name']),
price = to_int(elements['price']),
amount = to_int(elements['amount']),
is_card = elements['pay_with_card'].prop('checked'),
bar_code = trimText(elements['bar_code'])
comission = to_int(elements['comission']),
description = trimText(elements['descripcion']),
tipo_ingreso = elements['tipo_ingreso'].val(),
owner_document = trimText(elements['cedula_vendedor']),
client_document = trimText(elements['cedula_cliente'])


if(amount < 1) {
alert('La cantidad minima es 1')

} else if(tipo_ingreso == 'Producto' && !bar_code){

alert('Es necesario buscar un producto')
elements['bar_code'].focus()

}else if(tipo_ingreso === 'Servicio' && !price){

alert('Es necesario llenar el campo Precio')
elements['price'].focus()


}else if(tipo_ingreso === 'Servicio' && !name) {

alert('Es necesario llenar el campo Nombre')
elements['name'].focus()

} else if(!comission) {

alert('Es necesario llenar el campo Procentaje Vendedor')
elements['comission'].focus()

} else {
$.post('/venta/', {
el_name: name,
is_card: is_card,
value: amount * price,
description: description,
owner_document: owner_document,
client_document: client_document,
}, function(data) {

if(data.ok) {
alert('El ingreso se registro correctamente.')
initialize(elements)

} else {
alert(data.msg)
}

})

}
e.preventDefault()
})

Expand All @@ -97,6 +154,10 @@ function to_int($element) {
return value
}

function trimText($element) {
return $.trim($element.val())
}

function saleProduct(elements, buttons) {
elements['price'].attr('readonly', true)
elements['name'].attr('readonly', true)
Expand Down

0 comments on commit a741c08

Please sign in to comment.