mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-16 12:50:38 +00:00
fix: mail state
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import * as moment from 'moment';
|
||||
import { Model } from 'objection';
|
||||
import { defaultTo } from 'lodash';
|
||||
import { TenantBaseModel } from '@/modules/System/models/TenantBaseModel';
|
||||
import { ExportableModel } from '@/modules/Export/decorators/ExportableModel.decorator';
|
||||
import { ImportableModel } from '@/modules/Import/decorators/Import.decorator';
|
||||
@@ -8,6 +9,7 @@ import { SaleEstimateMeta } from './SaleEstimate.meta';
|
||||
import { ItemEntry } from '@/modules/TransactionItemEntry/models/ItemEntry';
|
||||
import { Document } from '@/modules/ChromiumlyTenancy/models/Document';
|
||||
import { Customer } from '@/modules/Customers/models/Customer';
|
||||
import { DiscountType } from '@/common/types/Discount';
|
||||
|
||||
@ExportableModel()
|
||||
@ImportableModel()
|
||||
@@ -42,6 +44,11 @@ export class SaleEstimate extends TenantBaseModel {
|
||||
branchId?: number;
|
||||
warehouseId?: number;
|
||||
|
||||
discount: number;
|
||||
discountType: DiscountType;
|
||||
|
||||
adjustment: number;
|
||||
|
||||
public entries!: ItemEntry[];
|
||||
public attachments!: Document[];
|
||||
public customer!: Customer;
|
||||
@@ -71,9 +78,69 @@ export class SaleEstimate extends TenantBaseModel {
|
||||
'isConvertedToInvoice',
|
||||
'isApproved',
|
||||
'isRejected',
|
||||
'discountAmount',
|
||||
'discountPercentage',
|
||||
'total',
|
||||
'totalLocal',
|
||||
'subtotal',
|
||||
'subtotalLocal',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Estimate subtotal.
|
||||
* @returns {number}
|
||||
*/
|
||||
get subtotal() {
|
||||
return this.amount;;
|
||||
}
|
||||
|
||||
/**
|
||||
* Estimate subtotal in local currency.
|
||||
* @returns {number}
|
||||
*/
|
||||
get subtotalLocal() {
|
||||
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 adjustmentAmount = defaultTo(this.adjustment, 0);
|
||||
|
||||
return this.subtotal - this.discountAmount - adjustmentAmount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Estimate total in local currency.
|
||||
* @returns {number}
|
||||
*/
|
||||
get totalLocal() {
|
||||
return this.total * this.exchangeRate;
|
||||
}
|
||||
|
||||
/**
|
||||
* Estimate amount in local currency.
|
||||
* @returns {number}
|
||||
|
||||
@@ -28,6 +28,12 @@ export class GetEstimateMailTemplateAttributesTransformer extends Transformer {
|
||||
'dueAmount',
|
||||
'dueAmountLabel',
|
||||
|
||||
'discount',
|
||||
'discountLabel',
|
||||
|
||||
'adjustment',
|
||||
'adjustmentLabel',
|
||||
|
||||
'viewEstimateButtonLabel',
|
||||
'viewEstimateButtonUrl',
|
||||
|
||||
@@ -103,7 +109,7 @@ export class GetEstimateMailTemplateAttributesTransformer extends Transformer {
|
||||
* Estimate total.
|
||||
*/
|
||||
public total(): string {
|
||||
return this.options.estimate.formattedAmount;
|
||||
return this.options.estimate.totalFormatted;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -114,11 +120,43 @@ export class GetEstimateMailTemplateAttributesTransformer extends Transformer {
|
||||
return 'Total';
|
||||
}
|
||||
|
||||
/**
|
||||
* Estimate discount.
|
||||
* @returns {string}
|
||||
*/
|
||||
public discount(): string {
|
||||
return this.options.estimate?.discountAmountFormatted;
|
||||
}
|
||||
|
||||
/**
|
||||
* Estimate discount label.
|
||||
* @returns {string}
|
||||
*/
|
||||
public discountLabel(): string {
|
||||
return 'Discount';
|
||||
}
|
||||
|
||||
/**
|
||||
* Estimate adjustment.
|
||||
* @returns {string}
|
||||
*/
|
||||
public adjustment(): string {
|
||||
return this.options.estimate?.adjustmentFormatted;
|
||||
}
|
||||
|
||||
/**
|
||||
* Estimate adjustment label.
|
||||
* @returns {string}
|
||||
*/
|
||||
public adjustmentLabel(): string {
|
||||
return 'Adjustment';
|
||||
}
|
||||
|
||||
/**
|
||||
* Estimate subtotal.
|
||||
*/
|
||||
public subtotal(): string {
|
||||
return this.options.estimate.formattedAmount;
|
||||
return this.options.estimate.formattedSubtotal;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -20,6 +20,16 @@ export class GetSaleEstimateMailStateTransformer extends SaleEstimateTransfromer
|
||||
'subtotal',
|
||||
'subtotalFormatted',
|
||||
|
||||
'discountAmount',
|
||||
'discountAmountFormatted',
|
||||
'discountPercentage',
|
||||
'discountPercentageFormatted',
|
||||
'discountLabel',
|
||||
|
||||
'adjustment',
|
||||
'adjustmentFormatted',
|
||||
'adjustmentLabel',
|
||||
|
||||
'estimateNumber',
|
||||
'entries',
|
||||
|
||||
@@ -98,15 +108,14 @@ export class GetSaleEstimateMailStateTransformer extends SaleEstimateTransfromer
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the formatted total of the estimate.
|
||||
* Retrieves the discount label of the estimate.
|
||||
* @param estimate
|
||||
* @returns {string}
|
||||
*/
|
||||
protected totalFormatted(estimate) {
|
||||
return this.formatMoney(estimate.amount, {
|
||||
currencyCode: estimate.currencyCode,
|
||||
money: true,
|
||||
});
|
||||
protected discountLabel(estimate) {
|
||||
return estimate.discountType === 'percentage'
|
||||
? `Discount [${estimate.discountPercentageFormatted}]`
|
||||
: 'Discount';
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -115,7 +124,7 @@ export class GetSaleEstimateMailStateTransformer extends SaleEstimateTransfromer
|
||||
* @returns {string}
|
||||
*/
|
||||
protected subtotalFormatted = (estimate) => {
|
||||
return this.formatNumber(estimate.amount, { money: false });
|
||||
return this.formattedSubtotal(estimate);
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -17,6 +17,13 @@ export class SaleEstimateTransfromer extends Transformer {
|
||||
'formattedDeliveredAtDate',
|
||||
'formattedApprovedAtDate',
|
||||
'formattedRejectedAtDate',
|
||||
|
||||
'discountAmountFormatted',
|
||||
'discountPercentageFormatted',
|
||||
'adjustmentFormatted',
|
||||
'totalFormatted',
|
||||
'totalLocalFormatted',
|
||||
|
||||
'formattedCreatedAt',
|
||||
'entries',
|
||||
'attachments',
|
||||
@@ -97,6 +104,65 @@ export class SaleEstimateTransfromer extends Transformer {
|
||||
return this.formatNumber(estimate.amount, { money: false });
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Retrieves formatted discount amount.
|
||||
* @param {SaleEstimate} estimate
|
||||
* @returns {string}
|
||||
*/
|
||||
protected discountAmountFormatted = (estimate: SaleEstimate): string => {
|
||||
return this.formatNumber(estimate.discountAmount, {
|
||||
currencyCode: estimate.currencyCode,
|
||||
excerptZero: true,
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Retrieves formatted discount percentage.
|
||||
* @param estimate
|
||||
* @returns {string}
|
||||
*/
|
||||
protected discountPercentageFormatted = (estimate: SaleEstimate): string => {
|
||||
return estimate.discountPercentage
|
||||
? `${estimate.discountPercentage}%`
|
||||
: '';
|
||||
};
|
||||
|
||||
/**
|
||||
* Retrieves formatted adjustment amount.
|
||||
* @param estimate
|
||||
* @returns {string}
|
||||
*/
|
||||
protected adjustmentFormatted = (estimate: SaleEstimate): string => {
|
||||
return this.formatMoney(estimate.adjustment, {
|
||||
currencyCode: estimate.currencyCode,
|
||||
excerptZero: true,
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Retrieves the formatted estimate total.
|
||||
* @returns {string}
|
||||
*/
|
||||
protected totalFormatted = (estimate: SaleEstimate): string => {
|
||||
return this.formatMoney(estimate.total, {
|
||||
currencyCode: estimate.currencyCode,
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Retrieves the formatted estimate total in local currency.
|
||||
* @param estimate
|
||||
* @returns {string}
|
||||
*/
|
||||
protected totalLocalFormatted = (estimate: SaleEstimate): string => {
|
||||
return this.formatMoney(estimate.totalLocal, {
|
||||
currencyCode: estimate.currencyCode,
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Retrieves the entries of the sale estimate.
|
||||
* @param {ISaleEstimate} estimate
|
||||
|
||||
Reference in New Issue
Block a user