Skip to content

Commit

Permalink
Service sales and product sales are two different things now.
Browse files Browse the repository at this point in the history
  • Loading branch information
cbdavide committed Oct 19, 2017
1 parent 892f1dc commit 8d06ec7
Show file tree
Hide file tree
Showing 4 changed files with 218 additions and 129 deletions.
101 changes: 10 additions & 91 deletions sales/static/js/app.js → sales/static/js/product.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,15 @@ $(document).ready(function() {
elements = {
'name': $('#name'),
'price': $('#price'),
'amount': $('#amount'),
'bar_code': $('#bar_code'),
'comission': $('#comission'),
'descripcion': $('#descripcion'),
'tipo_ingreso': $('#tipo_ingreso'),
'pay_with_card': $('#pay_with_card'),
'amount_holder': $('#amount_holder'),
'cedula_cliente': $('#cedula_cliente'),
'cedula_vendedor': $('#cedula_vendedor')
}

buttons = {
'add_product': $('#add_product'),
'search_product': $('#search_product'),
'remove_product': $('#remove_product'),
'enviar': $('#enviar')
}

Expand All @@ -27,36 +21,6 @@ $(document).ready(function() {
}

initialize(elements)
elements['tipo_ingreso'].val('Producto')

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

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

else
saleService(elements, buttons)

})

buttons['add_product'].on('click', function() {

var maximum_value = to_int(elements['amount_holder'])

var value = to_int(elements['amount']) + 1
value = (value > maximum_value) ? maximum_value : value
elements['amount'].val(value)

})

buttons['remove_product'].on('click', function() {

var value = to_int(elements['amount']) - 1
elements['amount'].val(value < 0 ? 0 : value)

})

forms['get_product'].on('submit', function(e) {
var codigo = $.trim(elements['bar_code'].val())
Expand All @@ -74,8 +38,6 @@ $(document).ready(function() {

elements['name'].val(data.name)
elements['price'].val(data.price)
elements['amount_holder'].val(data.amount)

}

})
Expand All @@ -90,53 +52,33 @@ $(document).ready(function() {

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')
buttons['enviar'].attr('disabled', false)

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

if(!bar_code){

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

} else if(comission !== 0 && !comission) {

}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')
alert('El porcentaje de comision tiene que ser un número')
elements['comission'].focus()
elements['comission'].val()
buttons['enviar'].attr('disabled', false)

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

Expand All @@ -155,49 +97,26 @@ $(document).ready(function() {
}
e.preventDefault()
})


})

function to_int($element) {
var value = $element.val()
value = value == '' ? 0 : parseInt(value)
if(value < 0) return NaN
return value
}

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

function saleProduct(elements, buttons) {
elements['price'].attr('readonly', true)
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)
}

function saleService(elements, buttons) {
elements['price'].attr('readonly', false)
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)
}

function initialize(elements) {

elements['name'].val('')
elements['price'].val('')
elements['amount'].val('')
elements['bar_code'].val('')
elements['comission'].val('')
elements['descripcion'].val('')
elements['amount_holder'].val('')
elements['cedula_cliente'].val('')
elements['cedula_vendedor'].val('')

elements['pay_with_card'].prop('checked', false)

Expand Down
103 changes: 103 additions & 0 deletions sales/static/js/service.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
$(document).ready(function() {

elements = {
'price': $('#price'),
'comission': $('#comission'),
'descripcion': $('#descripcion'),
'pay_with_card': $('#pay_with_card'),
'cedula_cliente': $('#cedula_cliente'),
'cedula_vendedor': $('#cedula_vendedor')
}

buttons = {
'enviar': $('#enviar')
}

forms = {
'register': $('#register'),
}

initialize(elements)

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

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

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

if(!description) {

alert('Tienes que ingresar una descripción')
elements['descripcion'].val('')
buttons['enviar'].attr('disabled', false)

} else if(!price) {

alert('El precio tiene que ser mayor a cero.')
elements['price'].val('')
elements['price'].focus()
buttons['enviar'].attr('disabled', false)

} else if(comission !== 0 && !comission) {

alert('El porcentaje del vendedor tiene que ser un número.')
elements['comission'].val('')
elements['comission'].focus()
buttons['enviar'].attr('disabled', false)

}else {

$.post('venta/servicio', {
el_name: description,
is_card: is_card,
value: price,
owner_document: owner_document,
client_document: client_document,
percent: comission,
}, function(data) {

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

} else {
alert(data.msg)
}

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

})

}
e.preventDefault()
})


})

function to_int($element) {
var value = $element.val()
value = value == '' ? 0 : parseInt(value)
if (value < 0) return NaN
return value
}

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

function initialize(elements) {

elements['price'].val('')
elements['comission'].val('')
elements['descripcion'].val('')
elements['cedula_cliente'].val('')

elements['pay_with_card'].prop('checked', false)

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,7 @@
<!-- Content -->
<div class="container">

<h1>Ingreso</h1>
<div class="form-group">
<label>Selecciona el tipo de ingreso: </label>
<select id="tipo_ingreso" class="form-control">
<option>Producto</option>
<option>Servicio</option>
</select>
</div>

<h1>Venta de producto</h1>
<form id="get_product">

<div class="form-group">
Expand Down Expand Up @@ -55,27 +47,23 @@ <h1>Ingreso</h1>
</form>

<form id="register">
<div class="form-group">
<label for="bar-code">Descripción: </label>
<input type="text" class="form-control" id="descripcion" placeholder="Descripción" required>
</div>
<div class="row">
<div class="col">
<div class="form-group">
<label for="bar-code">Empleado: </label>
<div class="input-group">
<span class="input-group-addon">Nombre: </span>
<select class="form-control">
<select id="cedula_vendedor" class="form-control">
{% for employee in employees %}
<option >{{ employee.name }}</option>
<option value="{{ employee.document }}">{{ employee.name }}</option>
{% endfor %}
</select>
</div>
</div>
</div>
<div class="col">
<div class="form-group">
<label for="bar-code">Cliente: </label>
<label for="bar-code">Cliente (opcional): </label>
<div class="input-group">
<span class="input-group-addon">C.C.</span>
<input type="text" class="form-control" id="cedula_cliente" placeholder="Cédula del cliente">
Expand All @@ -84,27 +72,10 @@ <h1>Ingreso</h1>
</div>
</div>
<div class="form-group">
<div class="row">
<div class="col">
<label for="product-price">Porcentaje Vendedor: </label>
<div class="input-group">
<input type="text" id="comission" class="form-control input-right" aria-label="Porcentaje" placeholder="0" required="">
<span class="input-group-addon">%</span>
</div>
</div>
<div class="col">
<label for="product-amount">Cantidad: </label>
<div class="input-group">
<button type="button" id="remove_product" class="btn btn-danger">
<span class="icon-minus label"></span>
</button>
<input type="text" class="form-control input-right" id="amount" placeholder="0" readonly>
<input type="text" class="form-control input-right" id="amount_holder" hidden>
<button type="button" id="add_product" class="btn btn-success">
<span class="icon-plus label"></span>
</button>
</div>
</div>
<label for="product-price">Porcentaje Vendedor: </label>
<div class="input-group">
<input type="text" id="comission" class="form-control input-right" aria-label="Porcentaje" placeholder="0">
<span class="input-group-addon">%</span>
</div>
</div>

Expand Down Expand Up @@ -132,6 +103,6 @@ <h1>Ingreso</h1>
<script src="/static/js/popper.min.js"></script>
<script src="/static/js/boostrap.min.js"></script>
<script src="/static/js/index.js"></script>
<script src="/static/js/app.js"></script>
<script src="/static/js/product.js"></script>
</body>
</html>
Loading

0 comments on commit 8d06ec7

Please sign in to comment.