Skip to content

Commit

Permalink
Fixing some problems
Browse files Browse the repository at this point in the history
  • Loading branch information
cbdavide committed Oct 13, 2017
1 parent 7c27a82 commit 5072698
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions sales/static/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ $(document).ready(function() {
'add_product': $('#add_product'),
'search_product': $('#search_product'),
'remove_product': $('#remove_product'),
'enviar': $('#enviar')
}

forms = {
Expand All @@ -30,14 +31,14 @@ $(document).ready(function() {

elements['tipo_ingreso'].change(function() {
$tipo = elements['tipo_ingreso']
initialize(elements)

if($tipo.val() === 'Producto')
saleProduct(elements, buttons)

else
saleService(elements, buttons)

initialize(elements)
})

buttons['add_product'].on('click', function() {
Expand Down Expand Up @@ -85,6 +86,8 @@ $(document).ready(function() {

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

buttons['enviar'].attr('disabled', true)

var name = trimText(elements['name']),
price = to_int(elements['price']),
amount = to_int(elements['amount']),
Expand All @@ -99,27 +102,32 @@ $(document).ready(function() {

if(amount < 1) {
alert('La cantidad minima es 1')
buttons['enviar'].attr('disabled', false)

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

alert('Es necesario buscar un producto')
elements['bar_code'].focus()
buttons['enviar'].attr('disabled', false)


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

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

buttons['enviar'].attr('disabled', false)

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

alert('Es necesario llenar el campo Nombre')
elements['name'].focus()
buttons['enviar'].attr('disabled', false)

} else if(!comission) {

alert('Es necesario llenar el campo Procentaje Vendedor')
elements['comission'].focus()
buttons['enviar'].attr('disabled', false)

} else {
$.post('/venta/', {
Expand All @@ -129,6 +137,7 @@ $(document).ready(function() {
description: description,
owner_document: owner_document,
client_document: client_document,
percent: comission,
}, function(data) {

if(data.ok) {
Expand All @@ -139,6 +148,8 @@ $(document).ready(function() {
alert(data.msg)
}

buttons['enviar'].attr('disabled', false)

})

}
Expand All @@ -163,6 +174,7 @@ function saleProduct(elements, buttons) {
elements['name'].attr('readonly', true)
elements['name'].attr('placeholder', 'Nombre del producto')
elements['bar_code'].attr('disabled', false)
elements['amount_holder'].val('')
buttons['search_product'].attr('disabled', false)
}

Expand All @@ -171,6 +183,7 @@ function saleService(elements, buttons) {
elements['name'].attr('readonly', false)
elements['name'].attr('placeholder', 'Nombre del servicio')
elements['bar_code'].attr('disabled', true)
elements['amount_holder'].val('100')
buttons['search_product'].attr('disabled', true)
}

Expand Down

0 comments on commit 5072698

Please sign in to comment.