}
make_ancestors(this.root_category_id, []);
},
+ category_contains: function(categ_id, product_id) {
+ var product = this.product_by_id[product_id];
+ if (product) {
+ var cid = product.pos_categ_id[0];
+ while (cid && cid !== categ_id){
+ cid = this.category_parent[cid];
+ }
+ return !!cid;
+ }
+ return false;
+ },
/* loads a record store from the database. returns default if nothing is found */
load: function(store,deft){
if(this.cache[store] !== undefined){
return fulldetails;
},
+ // Returns a total only for the orderlines with products belonging to the category
+ get_total_for_category_with_tax: function(categ_id){
+ var total = 0;
+ var self = this;
+
+ if (categ_id instanceof Array) {
+ for (var i = 0; i < categ_id.length; i++) {
+ total += this.get_total_for_category_with_tax(categ_id[i]);
+ }
+ return total;
+ }
+
+ this.orderlines.each(function(line){
+ if ( self.pos.db.category_contains(categ_id,line.product.id) ) {
+ total += line.get_price_with_tax();
+ }
+ });
+
+ return total;
+ },
get_change: function(paymentline) {
if (!paymentline) {
var change = this.get_total_paid() - this.get_total_with_tax();