function InventoryArticle(){ this.article = new Article(); this.end = 0, this.start = 0; this.fetched = 0; this.lost = 0; } InventoryArticle.prototype = { get StartPortions() { countFull = Math.floor(this.start); fullPortions = countFull * this.article.Portions; rest = this.start - countFull; restPortions = rest / this.article.PortionSize; return fullPortions + restPortions; }, get FetchedPortions() { countFull = Math.floor(this.fetched); fullPortions = countFull * this.article.Portions; rest = this.fetched - countFull; restPortions = rest / this.article.PortionSize; return fullPortions + restPortions; }, get EndPortions() { countFull = Math.floor(this.end); fullPortions = countFull * this.article.Portions; rest = this.end - countFull; restPortions = rest / this.article.PortionSize; return fullPortions + restPortions; }, get LostPortions() { countFull = Math.floor(this.lost); fullPortions = countFull * this.article.Portions; rest = this.lost - countFull; restPortions = rest / this.article.PortionSize; return fullPortions + restPortions; }, get Sold() { adds = this.StartPortions + this.FetchedPortions; subs = this.EndPortions + this.LostPortions; return adds - subs; }, get Sale() { return this.Sold * this.article.PortionPrice; }, get StepSize() { singlePack = this.article.Portions == 1; return singlePack ? 1 : 0.05; }, get PortionPrecision() { singlePack = this.article.Portions == 1; return singlePack ? 0 : 2; } }; InventoryArticle.thaw = function(json){ this.name = json.name; this.start = json.start; this.fetched = json.fetched; this.end = json.end; this.lost = json.lost; };