feat: discount formatted attributes of sale transactions

This commit is contained in:
Ahmed Bouhuolia
2024-11-28 17:59:09 +02:00
parent df8391201f
commit e02ad1e795
12 changed files with 246 additions and 25 deletions

View File

@@ -72,16 +72,32 @@ export default class CreditNote 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;
}
/**
* Credit note total.
* @returns {number}
*/
get total() {
const discountAmount = this.discountType === DiscountType.Amount
? this.discount
: this.subtotal * (this.discount / 100);
return this.subtotal - discountAmount - this.adjustment;
return this.subtotal - this.discountAmount - this.adjustment;
}
/**

View File

@@ -75,18 +75,34 @@ export default class SaleEstimate extends mixin(TenantModel, [
return this.localAmount;
}
/**
* 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;
}
/**
* Estimate total.
* @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.subtotal - discountAmount - adjustmentAmount;
return this.subtotal - this.discountAmount - adjustmentAmount;
}
/**

View File

@@ -28,7 +28,6 @@ export default class SaleInvoice extends mixin(TenantModel, [
public discountType: DiscountType;
public adjustments: number;
/**
* Table name
*/
@@ -72,6 +71,8 @@ export default class SaleInvoice extends mixin(TenantModel, [
'subtotalExludingTax',
'taxAmountWithheldLocal',
'discountAmount',
'total',
'totalLocal',
@@ -130,17 +131,33 @@ export default class SaleInvoice 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.adjustments, 0);
const differencies = discountAmount + adjustmentAmount;
const differencies = this.discountAmount + adjustmentAmount;
return this.isInclusiveTax
? this.subtotal - differencies
@@ -616,7 +633,7 @@ export default class SaleInvoice extends mixin(TenantModel, [
join: {
from: 'sales_invoices.pdfTemplateId',
to: 'pdf_templates.id',
}
},
},
};
}

View File

@@ -67,18 +67,34 @@ export default class SaleReceipt extends mixin(TenantModel, [
return this.localAmount;
}
/**
* 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;
}
/**
* Receipt total.
* @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.subtotal - discountAmount - adjustmentAmount;
return this.subtotal - this.discountAmount - adjustmentAmount;
}
/**