From 8d06ec7051bbf9677a463fefcf91b3bdb22ed590 Mon Sep 17 00:00:00 2001 From: David Castelblanco Benavides Date: Thu, 19 Oct 2017 16:20:01 -0500 Subject: [PATCH] Service sales and product sales are two different things now. --- sales/static/js/{app.js => product.js} | 101 ++--------------- sales/static/js/service.js | 103 ++++++++++++++++++ ...ate_sale.html => create_product_sale.html} | 47 ++------ .../templates/sales/create_service_sale.html | 96 ++++++++++++++++ 4 files changed, 218 insertions(+), 129 deletions(-) rename sales/static/js/{app.js => product.js} (50%) create mode 100644 sales/static/js/service.js rename sales/templates/sales/{create_sale.html => create_product_sale.html} (66%) create mode 100644 sales/templates/sales/create_service_sale.html diff --git a/sales/static/js/app.js b/sales/static/js/product.js similarity index 50% rename from sales/static/js/app.js rename to sales/static/js/product.js index c7b2dea..f7a6a61 100644 --- a/sales/static/js/app.js +++ b/sales/static/js/product.js @@ -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') } @@ -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()) @@ -74,8 +38,6 @@ $(document).ready(function() { elements['name'].val(data.name) elements['price'].val(data.price) - elements['amount_holder'].val(data.amount) - } }) @@ -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) { @@ -155,13 +97,12 @@ $(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 } @@ -169,35 +110,13 @@ 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) diff --git a/sales/static/js/service.js b/sales/static/js/service.js new file mode 100644 index 0000000..d860645 --- /dev/null +++ b/sales/static/js/service.js @@ -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) + +} \ No newline at end of file diff --git a/sales/templates/sales/create_sale.html b/sales/templates/sales/create_product_sale.html similarity index 66% rename from sales/templates/sales/create_sale.html rename to sales/templates/sales/create_product_sale.html index fb54995..a0d824c 100644 --- a/sales/templates/sales/create_sale.html +++ b/sales/templates/sales/create_product_sale.html @@ -15,15 +15,7 @@
-

Ingreso

-
- - -
- +

Venta de producto

@@ -55,19 +47,15 @@

Ingreso

-
- - -
Nombre: - {% for employee in employees %} - + {% endfor %}
@@ -75,7 +63,7 @@

Ingreso

- +
C.C. @@ -84,27 +72,10 @@

Ingreso

-
-
- -
- - % -
-
-
- -
- - - - -
-
+ +
+ + %
@@ -132,6 +103,6 @@

Ingreso

- + \ No newline at end of file diff --git a/sales/templates/sales/create_service_sale.html b/sales/templates/sales/create_service_sale.html new file mode 100644 index 0000000..a8864f8 --- /dev/null +++ b/sales/templates/sales/create_service_sale.html @@ -0,0 +1,96 @@ + + + + + + Ingresar registro + + + + + + + + + +
+ +

Venta de servicio

+ + +
+ + +
+ +
+
+
+ +
+ Nombre: + +
+
+
+
+
+ +
+ C.C. + +
+
+
+
+
+
+
+ +
+ $ + + .00 +
+
+
+ +
+ + % +
+
+
+
+ +
+
+ +
+
+ +
+
+ +
+
+ + + +
+ + + + + + + + + \ No newline at end of file