Skip to content

Commit

Permalink
Added form to create an expense, with a basic functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
cbdavide committed Oct 13, 2017
1 parent a741c08 commit 3209d76
Show file tree
Hide file tree
Showing 2 changed files with 131 additions and 1 deletion.
68 changes: 68 additions & 0 deletions sales/static/js/gasto.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
$(document).ready(function() {

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

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

initialize(elements)

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

var price = to_int(elements['price']),
description = trimText(elements['descripcion']),
owner_document = trimText(elements['cedula_vendedor'])

if(!price || price <= 0) {

alert('Ingresa un precio válido')
elements['price'].val('')
elements['price'].focus()

} else {
$.post('/gasto/', {
value : price,
description:description,
owner_document: owner_document
}, function(data) {

if(data.ok) {
alert('La salida se registro correctamente.')
initialize(elements)

} else {
alert(data.msg)
}

})

}

e.preventDefault()
})


})

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

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

function initialize(elements) {

elements['price'].val('')
elements['descripcion'].val('')
elements['cedula_vendedor'].val('')

}
64 changes: 63 additions & 1 deletion sales/templates/sales/create_expense.html
Original file line number Diff line number Diff line change
@@ -1 +1,63 @@
create_expense.html
<!DOCTYPE html>
<html lang="es">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>Ingresar registro</title>
<link rel="stylesheet" type="text/css" href="/static/css/styles.css">
<link rel="stylesheet" type="text/css" href="/static/css/icons.css">
<link rel="stylesheet" type="text/css" href="/static/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="/static/css/bootstrap-grid.min.css">
<link rel="stylesheet" type="text/css" href="/static/css/bootstrap-reboot.min.css">
</head>
<body>

<!-- Content -->
<div class="container">

<h1>Salida</h1>

<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">Cédula: </label>
<div class="input-group">
<span class="input-group-addon">C.C.</span>
<input type="text" class="form-control" id="cedula_vendedor" placeholder="Cédula del trabajador" required>
</div>
</div>
</div>
<div class="col">
<div class="form-group">
<label for="product-price">Precio: </label>
<div class="input-group">
<span class="input-group-addon">$</span>
<input type="text" id="price" class="form-control input-right" aria-label="Precio" placeholder="0" required>
<span class="input-group-addon">.00</span>
</div>
</div>
</div>
</div>

<div class="form-group">
<div class=text-right>
<button type="submit" class="btn btn-primary pull-right">Enviar</button>
</div>
</div>
</form>
</div>

<!-- Dependencies -->
<script src="/static/js/jquery-3.2.1.min.js"></script>
<script src="/static/js/popper.min.js"></script>
<script src="/static/js/boostrap.min.js"></script>
<script src="/static/js/gasto.js"></script>
</body>
</html>

0 comments on commit 3209d76

Please sign in to comment.