tengo un problema al momento que se agreguen ya sea al principio o al final, si se agregan pero se ordenan por ID, yo estoy buscando que se agreguen a como voy escribiendo ya sea nombre o codigo, al principio unshift o al final push.
este es el codigo donde les muestro donde esta la funcion de agregar los items, donde los tomo de la bd y donde los agrega a la tabla.
function add_invoice_item(t) {
if (1 == count && (spositems = {}), null != t) {
var e = 1 == Settings.item_addition ? t.item_id : t.id;
return spositems[e] ? spositems[e].row.qty = parseFloat(spositems[e].row.qty) + 1 : spositems[e] = t, store("spositems", JSON.stringify(spositems), loadItems(), !0
}
}
function loadItems() {
if (1 == count && (spositems = {}), get("spositems")) {
total = 0, count = 1, an = 1, product_tax = 0, invoice_tax = 0, product_discount = 0, order_discount = 0, total_discount = 0, $("#posTable tbody").empty();
var t = (new Date).getTime() / 1e3;
if (1 != Settings.remote_printing) {
var e = (r = "C: " + $("#select2-spos_customer-container").text() + "\n") + (i = "R: " + $("#hold_ref").val() + "\n") + (l = "U: " + username + "\n") + (c = "T: " + date(Settings.dateformat + " " + Settings.timeformat, t) + "\n") + "\n";
order_data.info = e, bill_data.info = e;
var a = "",
o = ""
} else {
$("#order_span").empty(), $("#bill_span").empty();
var n = "<style>.bb td, .bb th { border-bottom: 1px solid #DDD; }</style>",
s = '<span style="text-align:center;"><h3>' + Settings.site_name + "</h3>",
r = "<h5>C: " + $("#select2-spos_customer-container").text() + "</h5>",
i = "<h5>R: " + $("#hold_ref").val() + "</h5>",
l = "<h5>U: " + username + "</h5>",
c = "<h5>T: " + date(Settings.dateformat + " " + Settings.timeformat, t) + "</h5>";
$("#order_span").prepend(n + s + "<h4>" + lang.order + "</h4></span>" + r + i + l + c), $("#bill_span").prepend(n + s + "<h4>" + lang.bill + "</h4></span>" + r + i + l + c), $("#order-table").empty(), $("#bill-table").empty()
}
spositems = JSON.parse(get("spositems")), $.each(spositems, function() {
var t = this,
e = 1 == Settings.item_addition ? t.item_id : t.id;
spositems[e] = t;
var n = t.row.id,
s = t.row.type,
r = parseFloat(t.row.tax_method),
i = t.combo_items,
l = t.row.qty,
c = parseFloat(t.row.quantity),
h = t.row.quantity,
s = t.row.type,
d = t.row.discount,
p = t.row.code,
u = t.row.name.replace(/"/g, """).replace(/'/g, "'"),
m = parseFloat(t.row.real_unit_price),
_ = t.row.comment,
g = t.row.ordered ? t.row.ordered : 0,
f = d || "0",
v = formatDecimal(f);
if (-1 !== f.indexOf("%")) {
var h = f.split("%");
isNaN(h[0]) || (v = formatDecimal(parseFloat(m * parseFloat(h[0]) / 100), 4))
}