inventur/app/js/model/inventory_article.js
2020-01-13 16:09:25 +01:00

72 lines
2.0 KiB
JavaScript

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