Last active
January 5, 2016 00:45
-
-
Save ricardosiri68/7a05c73f6ef29c9f4d86 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | |
<html> | |
<head> | |
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> | |
<title>Carrito de Compras</title> | |
<link rel="stylesheet" type="text/css" href="/easy-autocomplete.min.css" /> | |
<link rel="stylesheet" type="text/css" href="/easy-autocomplete.themes.min.css" /> | |
</head> | |
<body> | |
<table id="hay_tabla"> | |
<tbody> | |
<tr id="add_product"> | |
<td><input type="text" id="txarticulo" name="txarticulo" style="width:300px;"></td> | |
<td><input type="text" id="txunitario" name="txunitario" style="width:150px; text-align:right;"></td> | |
<td><input type="number" id="txcant" name="txcant" style="width:100px; text-align:right;" value="1"></td> | |
<td id="txstotal">0</td> | |
</tr> | |
</tbody> | |
</table> | |
<button id="agregar">Agregar</button> | |
<script language="javascript" type="text/javascript" src="https://code.jquery.com/jquery-1.11.3.min.js"></script> | |
<script language="javascript" type="text/javascript" src="/jquery.easy-autocomplete.min.js"></script> | |
<script language="javascript" type="text/javascript" src="/index.js"></script> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 | Poleas | 5 | |
---|---|---|---|
26 | Baterías | 6 | |
27 | Baterías equipo pesado | 6 | |
29 | Bombas de agua ACDelco | 7 | |
30 | Kit Bomba de gasolina ACDelco | 8 | |
32 | Módulos de bombas de gasolina | 16 | |
33 | Bujías convencionales | 9 | |
34 | Bujías de platino | 9 | |
39 | General Motors Nacionales | 10 | |
40 | General Motors Importados | 10 | |
41 | Ford Nacionales | 10 | |
42 | Ford Importados | 10 | |
43 | Chrysler Nacionales | 10 | |
46 | Nissan Nacionales | 10 | |
51 | Clutch | 11 | |
52 | Bulbos | 12 | |
53 | Bobinas | 12 | |
62 | Sensores de oxigeno ACDelco | 13 | |
70 | Mazas delanteras | 15 | |
71 | Mazas traseras | 15 | |
73 | Plumas limpiaparabrisas | 17 | |
74 | Tapones de aceite | 18 | |
75 | Tapones de radiador | 18 | |
76 | Tapones de gasolina | 18 | |
77 | Tapones de tanque de recuperación | 18 | |
78 | Termostatos | 19 | |
79 | Zapatas | 20 | |
86 | Filtros de Aire | 14 | |
87 | Filtros de Aceite | 14 | |
88 | Filtros de Gasolina | 14 | |
90 | Filtros de Gasolina linea Azul | 14 | |
91 | Filtros de Transmisión | 14 | |
92 | Tambores | 21 | |
94 | Tensores | 23 | |
96 | Radiadores | 25 | |
98 | Cilindros de freno | 26 | |
99 | Crucetas | 27 | |
100 | Kit de tiempo | 28 | |
102 | Baleros | 29 | |
103 | Soporte de Moto | 30 | |
104 | Soporte de Transmisión | 30 | |
105 | Filtros de cabina | 14 | |
106 | Condensadores | 31 | |
107 | Flechas, Cubre polvo y Juntas homocinéticas | 32 | |
108 | Línea básica | 4 | |
109 | General Motors | 3 | |
110 | Equipo Pesado | 9 | |
111 | Tractores - Podadoras | 9 | |
112 | Motocicletas | 9 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*jslint nomen: true, debug: true, evil: true, vars: true, browser: true, | |
devel: true */ | |
/*global jQuery */ | |
(function($){ | |
var PuntoVenta = function(){ | |
var options = { | |
url: function(term){ | |
return "index.php?q=" + term; | |
}, | |
getValue: "desc", | |
list: { | |
match: { | |
enabled: true | |
}, | |
onSelectItemEvent: this.selectedItem.bind(this), | |
onChooseEvent: this.selectedItem.bind(this) | |
} | |
}; | |
this.tabla = $('#hay_tabla'); | |
this.txt_articulo = $('#txarticulo'); | |
this.tx_cantidad = $('#txcant'); | |
this.tx_total = $('#txstotal'); | |
this.tx_unitario = $('#txunitario'); | |
this.btn_agregar = $('#agregar'); | |
this.txt_articulo.easyAutocomplete(options); | |
this.btn_agregar.on('click', this.insertRow.bind(this)); | |
this.tx_unitario.on('change', this.setItemTotal.bind(this)); | |
this.tx_cantidad.on('change', this.setItemTotal.bind(this)); | |
this.tabla.delegate('.item_cant', 'change', this.setInsertedTotal.bind(this)); | |
this.tabla.delegate('.item_unitario', 'change', this.setInsertedTotal.bind(this)); | |
}; | |
PuntoVenta.prototype = { | |
selectedItem: function(){ | |
this.data_row = this.txt_articulo.getSelectedItemData(); | |
this.tx_unitario.val(this.data_row.unitario); | |
this.setItemTotal(); | |
}, | |
insertRow: function(){ | |
var row = document.createElement('tr'); | |
var desc_col = document.createElement('td'); | |
var unitario_col = document.createElement('td'); | |
var unitario_input = document.createElement('input'); | |
var cant_col = document.createElement('td'); | |
var cant_input = document.createElement('input'); | |
var total_col = document.createElement('td'); | |
desc_col.innerText = this.data_row.desc; | |
unitario_col.appendChild(unitario_input); | |
unitario_input.setAttribute('type', 'number'); | |
unitario_input.classList.add('item_unitario'); | |
unitario_input.value = this.tx_unitario.val(); | |
cant_col.appendChild(cant_input); | |
cant_input.setAttribute('type', 'number'); | |
cant_input.classList.add('item_cant'); | |
cant_input.value = this.tx_cantidad.val(); | |
total_col.classList.add('item_total'); | |
total_col.innerText = '$ ' + this.tx_cantidad.val() * this.tx_unitario.val(); | |
row.setAttribute('data', this.data_row.id); | |
row.appendChild(desc_col); | |
row.appendChild(unitario_col); | |
row.appendChild(cant_col); | |
row.appendChild(total_col); | |
this.tabla.find('tbody').prepend(row); | |
}, | |
setItemTotal: function(){ | |
this.tx_total.text('$ ' + this.tx_cantidad.val() * this.tx_unitario.val()); | |
}, | |
setInsertedTotal: function(e){ | |
var row = $(e.target.parentNode.parentNode); | |
var cantidad = row.find('.item_cant').val(); | |
var unitario = row.find('.item_unitario').val(); | |
row.find('.item_total').text('$ ' + cantidad * unitario); | |
} | |
}; | |
window.addEventListener('load', function(){ var pv = new PuntoVenta(); }); | |
}(jQuery)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* modulo de entrega de productos | |
* | |
* PHP version 5.6.16 | |
* | |
* @category Vista | |
* @package Richarpackage | |
* @author Mucha Cafeina <[email protected]> | |
* @license MIT https://tldrlegal.com/license/mit-license | |
* @link https://gist.github.com | |
*/ | |
/** | |
* recupera los datos almacenados dentro de data.csv | |
* | |
* @return (array): | |
* | |
*/ | |
function getProductsFromCSV() | |
{ | |
$data_list = []; | |
$data_file_handler = fopen('data.csv', 'r'); | |
while ($datos = fgetcsv($data_file_handler)) { | |
array_push($data_list, $datos); | |
} | |
fclose($data_file_handler); | |
return $data_list; | |
} | |
/** | |
* recupera productos segun un termino de busqueda que coincide con la | |
* descripcion del produco | |
* | |
* @param String $term termino de busqueda | |
* | |
* @return (array): resultados de busqueda | |
*/ | |
function search($term) | |
{ | |
$results = []; | |
foreach (getProductsFromCSV() as $row) { | |
if (preg_match("/".$term."/i", $row[1])) { | |
array_push( | |
$results, | |
[ | |
"id" => (int) $row[0], | |
"desc" => trim($row[1]), | |
"unitario" => (float) $row[2] | |
] | |
); | |
} | |
} | |
return json_encode($results); | |
} | |
echo @search($_GET['q']); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment