inventur/js/model/inventory_article.js
TLRZ Seyfferth 49146a8ba6 updates
2018-01-10 17:29:27 +01:00

62 lines
1.8 KiB
JavaScript

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;
}
};
InventoryArticle.thaw = function(json){
this.name = json.name;
this.start = json.start;
this.fetched = json.fetched;
this.end = json.end;
this.lost = json.lost;
};