feat: discount vendor credit

This commit is contained in:
Ahmed Bouhuolia
2024-11-28 18:17:47 +02:00
parent e02ad1e795
commit 17b3bbe1d8
5 changed files with 135 additions and 7 deletions

View File

@@ -104,20 +104,37 @@ export default class Bill extends mixin(TenantModel, [
return this.taxAmountWithheld * this.exchangeRate;
}
/**
* Discount amount.
* @returns {number}
*/
get discountAmount() {
return this.discountType === DiscountType.Amount
? this.discount
: this.subtotal * (this.discount / 100);
}
/**
* Discount percentage.
* @returns {number | null}
*/
get discountPercentage(): number | null {
return this.discountType === DiscountType.Percentage ? this.discount : null;
}
/**
* Invoice total. (Tax included)
* @returns {number}
*/
get total() {
const discountAmount = this.discountType === DiscountType.Amount
? this.discount
: this.subtotal * (this.discount / 100);
const adjustmentAmount = defaultTo(this.adjustment, 0);
return this.isInclusiveTax
? this.subtotal - discountAmount - adjustmentAmount
: this.subtotal + this.taxAmountWithheld - discountAmount - adjustmentAmount;
? this.subtotal - this.discountAmount - adjustmentAmount
: this.subtotal +
this.taxAmountWithheld -
this.discountAmount -
adjustmentAmount;
}
/**

View File

@@ -58,6 +58,24 @@ export default class VendorCredit extends mixin(TenantModel, [
return this.subtotal * this.exchangeRate;
}
/**
* Discount amount.
* @returns {number}
*/
get discountAmount() {
return this.discountType === DiscountType.Amount
? this.discount
: this.subtotal * (this.discount / 100);
}
/**
* Discount percentage.
* @returns {number | null}
*/
get discountPercentage(): number | null {
return this.discountType === DiscountType.Percentage ? this.discount : null;
}
/**
* Vendor credit total.
* @returns {number}