public setId(id) {
if (id) this.id = id;
else {
console.log('An ID must be provided');
}
};
public getId() : number {
return this.id;
};
public setArticleId(articleId) {
if (articleId) this.articleId = articleId;
else {
console.log('An Article ID must be provided');
}
};
public getArticleId() : string {
return this.articleId;
};
public setName(name) {
if (name) this.name = name;
else {
console.log('A name must be provided');
}
};
public getName() : string{
return this.name;
};
public setPrice = function (price) {
let priceFloat = parseFloat(price);
if (priceFloat) {
if (priceFloat <= 0) {
console.log('A price must be over 0');
} else {
this.price = (priceFloat);
}
} else {
console.log('A price must be provided');
}
};
public getPrice = function () {
return this.price;
};
public setQuantity(quantity, relative) {
let quantityInt = parseInt(quantity);
let quantityOrg = parseInt(this.quantity);
if (quantityInt % 1 === 0) {
if (relative === true) {
quantityOrg += quantityInt;
this.quantity = quantityOrg.toString();
if (quantityOrg >= this.packagingUnit) {
this.setPrice(this.scaledPrice);
}
else {
this.setPrice(this.price);
};
} else {
quantityOrg = quantityInt;
this.quantity = quantityOrg.toString();
}
if (quantityOrg < 1) quantityOrg = 1;
this.quantity = quantityOrg.toString();
} else {
quantityOrg = 1;
this.quantity = quantityOrg.toString();
console.log('Quantity must be an integer and was defaulted to 1');
}
};
public getQuantity(){
return parseInt(this.quantity);
};
public setPackagingUnit(packagingUnit){
if (packagingUnit) this.packagingUnit = packagingUnit;
};
public getPackagingUnit(){
if (this.packagingUnit) return this.packagingUnit;
};
public setScaledPrice(scaledPrice){
if (scaledPrice) this.scaledPrice = scaledPrice;
};
public getScaledPrice() {
if (this.scaledPrice) return this.scaledPrice;
};
public setImagePath(imagePath){
if (imagePath) this.imagePath = imagePath;
};
public getImagePath() : string{
if (this.imagePath) return this.imagePath;
};
public getTotal(){
return(this.getQuantity() * this.getPrice());
//return parseFloat(""+this.getQuantity() * +this.getPrice()).toFixed(2);
};
public toObject(){
return {
id: this.getId(),
articleId: this.getArticleId(),
name: this.getName(),
price: this.getPrice(),
quantity: this.getQuantity(),
packagingUnit: this.getPackagingUnit(),
scaledPrice: this.getScaledPrice(),
imagePath: this.getImagePath(),
//total: parseFloat(""+this.getTotal()).toFixed(2)
total: parseFloat(this.getTotal().toFixed(2))
}
};
}