mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-19 22:30:31 +00:00
feat: discount formatted attributes of sale transactions
This commit is contained in:
@@ -25,6 +25,11 @@ export interface ISaleEstimate {
|
|||||||
|
|
||||||
branchId?: number;
|
branchId?: number;
|
||||||
warehouseId?: number;
|
warehouseId?: number;
|
||||||
|
|
||||||
|
discountAmount?: number;
|
||||||
|
discountPercentage?: number | null;
|
||||||
|
|
||||||
|
adjustment?: number;
|
||||||
}
|
}
|
||||||
export interface ISaleEstimateDTO {
|
export interface ISaleEstimateDTO {
|
||||||
customerId: number;
|
customerId: number;
|
||||||
|
|||||||
@@ -83,8 +83,8 @@ export interface ISaleInvoice {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export enum DiscountType {
|
export enum DiscountType {
|
||||||
Percentage = 'Percentage',
|
Percentage = 'percentage',
|
||||||
Amount = 'Amount',
|
Amount = 'amount',
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ISaleInvoiceDTO {
|
export interface ISaleInvoiceDTO {
|
||||||
|
|||||||
@@ -28,6 +28,11 @@ export interface ISaleReceipt {
|
|||||||
|
|
||||||
localAmount?: number;
|
localAmount?: number;
|
||||||
entries?: IItemEntry[];
|
entries?: IItemEntry[];
|
||||||
|
|
||||||
|
discountAmount: number;
|
||||||
|
discountPercentage?: number | null;
|
||||||
|
|
||||||
|
adjustment?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ISalesReceiptsFilter {
|
export interface ISalesReceiptsFilter {
|
||||||
|
|||||||
@@ -72,16 +72,32 @@ export default class CreditNote extends mixin(TenantModel, [
|
|||||||
return this.subtotal * this.exchangeRate;
|
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.
|
* Credit note total.
|
||||||
* @returns {number}
|
* @returns {number}
|
||||||
*/
|
*/
|
||||||
get total() {
|
get total() {
|
||||||
const discountAmount = this.discountType === DiscountType.Amount
|
return this.subtotal - this.discountAmount - this.adjustment;
|
||||||
? this.discount
|
|
||||||
: this.subtotal * (this.discount / 100);
|
|
||||||
|
|
||||||
return this.subtotal - discountAmount - this.adjustment;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -75,18 +75,34 @@ export default class SaleEstimate extends mixin(TenantModel, [
|
|||||||
return this.localAmount;
|
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.
|
* Estimate total.
|
||||||
* @returns {number}
|
* @returns {number}
|
||||||
*/
|
*/
|
||||||
get total() {
|
get total() {
|
||||||
const discountAmount = this.discountType === DiscountType.Amount
|
|
||||||
? this.discount
|
|
||||||
: this.subtotal * (this.discount / 100);
|
|
||||||
|
|
||||||
const adjustmentAmount = defaultTo(this.adjustment, 0);
|
const adjustmentAmount = defaultTo(this.adjustment, 0);
|
||||||
|
|
||||||
return this.subtotal - discountAmount - adjustmentAmount;
|
return this.subtotal - this.discountAmount - adjustmentAmount;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -28,7 +28,6 @@ export default class SaleInvoice extends mixin(TenantModel, [
|
|||||||
public discountType: DiscountType;
|
public discountType: DiscountType;
|
||||||
public adjustments: number;
|
public adjustments: number;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Table name
|
* Table name
|
||||||
*/
|
*/
|
||||||
@@ -72,6 +71,8 @@ export default class SaleInvoice extends mixin(TenantModel, [
|
|||||||
'subtotalExludingTax',
|
'subtotalExludingTax',
|
||||||
|
|
||||||
'taxAmountWithheldLocal',
|
'taxAmountWithheldLocal',
|
||||||
|
'discountAmount',
|
||||||
|
|
||||||
'total',
|
'total',
|
||||||
'totalLocal',
|
'totalLocal',
|
||||||
|
|
||||||
@@ -130,17 +131,33 @@ export default class SaleInvoice extends mixin(TenantModel, [
|
|||||||
return this.taxAmountWithheld * this.exchangeRate;
|
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)
|
* Invoice total. (Tax included)
|
||||||
* @returns {number}
|
* @returns {number}
|
||||||
*/
|
*/
|
||||||
get total() {
|
get total() {
|
||||||
const discountAmount = this.discountType === DiscountType.Amount
|
|
||||||
? this.discount
|
|
||||||
: this.subtotal * (this.discount / 100);
|
|
||||||
|
|
||||||
const adjustmentAmount = defaultTo(this.adjustments, 0);
|
const adjustmentAmount = defaultTo(this.adjustments, 0);
|
||||||
const differencies = discountAmount + adjustmentAmount;
|
const differencies = this.discountAmount + adjustmentAmount;
|
||||||
|
|
||||||
return this.isInclusiveTax
|
return this.isInclusiveTax
|
||||||
? this.subtotal - differencies
|
? this.subtotal - differencies
|
||||||
@@ -616,7 +633,7 @@ export default class SaleInvoice extends mixin(TenantModel, [
|
|||||||
join: {
|
join: {
|
||||||
from: 'sales_invoices.pdfTemplateId',
|
from: 'sales_invoices.pdfTemplateId',
|
||||||
to: 'pdf_templates.id',
|
to: 'pdf_templates.id',
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -67,18 +67,34 @@ export default class SaleReceipt extends mixin(TenantModel, [
|
|||||||
return this.localAmount;
|
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.
|
* Receipt total.
|
||||||
* @returns {number}
|
* @returns {number}
|
||||||
*/
|
*/
|
||||||
get total() {
|
get total() {
|
||||||
const discountAmount = this.discountType === DiscountType.Amount
|
|
||||||
? this.discount
|
|
||||||
: this.subtotal * (this.discount / 100);
|
|
||||||
|
|
||||||
const adjustmentAmount = defaultTo(this.adjustment, 0);
|
const adjustmentAmount = defaultTo(this.adjustment, 0);
|
||||||
|
|
||||||
return this.subtotal - discountAmount - adjustmentAmount;
|
return this.subtotal - this.discountAmount - adjustmentAmount;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -18,6 +18,9 @@ export class CreditNoteTransformer extends Transformer {
|
|||||||
'formattedAmount',
|
'formattedAmount',
|
||||||
'formattedCreditsUsed',
|
'formattedCreditsUsed',
|
||||||
'formattedSubtotal',
|
'formattedSubtotal',
|
||||||
|
'discountAmountFormatted',
|
||||||
|
'discountPercentageFormatted',
|
||||||
|
'adjustmentFormatted',
|
||||||
'entries',
|
'entries',
|
||||||
'attachments',
|
'attachments',
|
||||||
];
|
];
|
||||||
@@ -83,6 +86,40 @@ export class CreditNoteTransformer extends Transformer {
|
|||||||
return formatNumber(credit.amount, { money: false });
|
return formatNumber(credit.amount, { money: false });
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves formatted discount amount.
|
||||||
|
* @param credit
|
||||||
|
* @returns {string}
|
||||||
|
*/
|
||||||
|
protected discountAmountFormatted = (credit): string => {
|
||||||
|
return formatNumber(credit.discountAmount, {
|
||||||
|
currencyCode: credit.currencyCode,
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves formatted discount percentage.
|
||||||
|
* @param credit
|
||||||
|
* @returns {string}
|
||||||
|
*/
|
||||||
|
protected discountPercentageFormatted = (credit): string => {
|
||||||
|
return credit.discountPercentage
|
||||||
|
? `${credit.discountPercentage}%`
|
||||||
|
: '';
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves formatted adjustment amount.
|
||||||
|
* @param credit
|
||||||
|
* @returns {string}
|
||||||
|
*/
|
||||||
|
protected adjustmentFormatted = (credit): string => {
|
||||||
|
return this.formatMoney(credit.adjustment, {
|
||||||
|
currencyCode: credit.currencyCode,
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves the entries of the credit note.
|
* Retrieves the entries of the credit note.
|
||||||
* @param {ICreditNote} credit
|
* @param {ICreditNote} credit
|
||||||
|
|||||||
@@ -18,6 +18,9 @@ export class SaleEstimateTransfromer extends Transformer {
|
|||||||
'formattedDeliveredAtDate',
|
'formattedDeliveredAtDate',
|
||||||
'formattedApprovedAtDate',
|
'formattedApprovedAtDate',
|
||||||
'formattedRejectedAtDate',
|
'formattedRejectedAtDate',
|
||||||
|
'discountAmountFormatted',
|
||||||
|
'discountPercentageFormatted',
|
||||||
|
'adjustmentFormatted',
|
||||||
'formattedCreatedAt',
|
'formattedCreatedAt',
|
||||||
'entries',
|
'entries',
|
||||||
'attachments',
|
'attachments',
|
||||||
@@ -98,6 +101,39 @@ export class SaleEstimateTransfromer extends Transformer {
|
|||||||
return formatNumber(estimate.amount, { money: false });
|
return formatNumber(estimate.amount, { money: false });
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves formatted discount amount.
|
||||||
|
* @param estimate
|
||||||
|
* @returns {string}
|
||||||
|
*/
|
||||||
|
protected discountAmountFormatted = (estimate: ISaleEstimate): string => {
|
||||||
|
return formatNumber(estimate.discountAmount, {
|
||||||
|
currencyCode: estimate.currencyCode,
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves formatted discount percentage.
|
||||||
|
* @param estimate
|
||||||
|
* @returns {string}
|
||||||
|
*/
|
||||||
|
protected discountPercentageFormatted = (estimate: ISaleEstimate): string => {
|
||||||
|
return estimate.discountPercentage
|
||||||
|
? `${estimate.discountPercentage}%`
|
||||||
|
: '';
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves formatted adjustment amount.
|
||||||
|
* @param estimate
|
||||||
|
* @returns {string}
|
||||||
|
*/
|
||||||
|
protected adjustmentFormatted = (estimate: ISaleEstimate): string => {
|
||||||
|
return this.formatMoney(estimate.adjustment, {
|
||||||
|
currencyCode: estimate.currencyCode,
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves the entries of the sale estimate.
|
* Retrieves the entries of the sale estimate.
|
||||||
* @param {ISaleEstimate} estimate
|
* @param {ISaleEstimate} estimate
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import { formatNumber } from 'utils';
|
|||||||
import { SaleInvoiceTaxEntryTransformer } from './SaleInvoiceTaxEntryTransformer';
|
import { SaleInvoiceTaxEntryTransformer } from './SaleInvoiceTaxEntryTransformer';
|
||||||
import { ItemEntryTransformer } from './ItemEntryTransformer';
|
import { ItemEntryTransformer } from './ItemEntryTransformer';
|
||||||
import { AttachmentTransformer } from '@/services/Attachments/AttachmentTransformer';
|
import { AttachmentTransformer } from '@/services/Attachments/AttachmentTransformer';
|
||||||
|
import { DiscountType } from '@/interfaces';
|
||||||
|
|
||||||
export class SaleInvoiceTransformer extends Transformer {
|
export class SaleInvoiceTransformer extends Transformer {
|
||||||
/**
|
/**
|
||||||
@@ -23,6 +24,9 @@ export class SaleInvoiceTransformer extends Transformer {
|
|||||||
'subtotalExludingTaxFormatted',
|
'subtotalExludingTaxFormatted',
|
||||||
'taxAmountWithheldFormatted',
|
'taxAmountWithheldFormatted',
|
||||||
'taxAmountWithheldLocalFormatted',
|
'taxAmountWithheldLocalFormatted',
|
||||||
|
'discountAmountFormatted',
|
||||||
|
'discountPercentageFormatted',
|
||||||
|
'adjustmentFormatted',
|
||||||
'totalFormatted',
|
'totalFormatted',
|
||||||
'totalLocalFormatted',
|
'totalLocalFormatted',
|
||||||
'taxes',
|
'taxes',
|
||||||
@@ -158,6 +162,39 @@ export class SaleInvoiceTransformer extends Transformer {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves formatted discount amount.
|
||||||
|
* @param invoice
|
||||||
|
* @returns {string}
|
||||||
|
*/
|
||||||
|
protected discountAmountFormatted = (invoice): string => {
|
||||||
|
return formatNumber(invoice.discountAmount, {
|
||||||
|
currencyCode: invoice.currencyCode,
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves formatted discount percentage.
|
||||||
|
* @param invoice
|
||||||
|
* @returns {string}
|
||||||
|
*/
|
||||||
|
protected discountPercentageFormatted = (invoice): string => {
|
||||||
|
return invoice.discountType === DiscountType.Percentage
|
||||||
|
? `${invoice.discount}%`
|
||||||
|
: '';
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves formatted adjustment amount.
|
||||||
|
* @param invoice
|
||||||
|
* @returns {string}
|
||||||
|
*/
|
||||||
|
protected adjustmentFormatted = (invoice): string => {
|
||||||
|
return this.formatMoney(invoice.adjustment, {
|
||||||
|
currencyCode: invoice.currencyCode,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves formatted total in foreign currency.
|
* Retrieves formatted total in foreign currency.
|
||||||
* @param invoice
|
* @param invoice
|
||||||
|
|||||||
@@ -14,6 +14,9 @@ export class SaleReceiptTransformer extends Transformer {
|
|||||||
public includeAttributes = (): string[] => {
|
public includeAttributes = (): string[] => {
|
||||||
return [
|
return [
|
||||||
'formattedSubtotal',
|
'formattedSubtotal',
|
||||||
|
'discountAmountFormatted',
|
||||||
|
'discountPercentageFormatted',
|
||||||
|
'adjustmentFormatted',
|
||||||
'formattedAmount',
|
'formattedAmount',
|
||||||
'formattedReceiptDate',
|
'formattedReceiptDate',
|
||||||
'formattedClosedAtDate',
|
'formattedClosedAtDate',
|
||||||
@@ -70,6 +73,39 @@ export class SaleReceiptTransformer extends Transformer {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves formatted discount amount.
|
||||||
|
* @param receipt
|
||||||
|
* @returns {string}
|
||||||
|
*/
|
||||||
|
protected discountAmountFormatted = (receipt: ISaleReceipt): string => {
|
||||||
|
return formatNumber(receipt.discountAmount, {
|
||||||
|
currencyCode: receipt.currencyCode,
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves formatted discount percentage.
|
||||||
|
* @param receipt
|
||||||
|
* @returns {string}
|
||||||
|
*/
|
||||||
|
protected discountPercentageFormatted = (receipt: ISaleReceipt): string => {
|
||||||
|
return receipt.discountPercentage
|
||||||
|
? `${receipt.discountPercentage}%`
|
||||||
|
: '';
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves formatted adjustment amount.
|
||||||
|
* @param receipt
|
||||||
|
* @returns {string}
|
||||||
|
*/
|
||||||
|
protected adjustmentFormatted = (receipt: ISaleReceipt): string => {
|
||||||
|
return this.formatMoney(receipt.adjustment, {
|
||||||
|
currencyCode: receipt.currencyCode,
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves the entries of the credit note.
|
* Retrieves the entries of the credit note.
|
||||||
* @param {ISaleReceipt} credit
|
* @param {ISaleReceipt} credit
|
||||||
|
|||||||
Reference in New Issue
Block a user