mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-17 21:30:31 +00:00
fix: discount and adjustment fields across financial forms
This commit is contained in:
@@ -4,6 +4,7 @@ import { Inject, Service } from 'typedi';
|
||||
import {
|
||||
AbilitySubject,
|
||||
CreditNoteAction,
|
||||
DiscountType,
|
||||
ICreditNoteEditDTO,
|
||||
ICreditNoteNewDTO,
|
||||
} from '@/interfaces';
|
||||
@@ -253,7 +254,10 @@ export default class PaymentReceivesController extends BaseController {
|
||||
|
||||
// Discount.
|
||||
check('discount').optional({ nullable: true }).isNumeric().toFloat(),
|
||||
check('discount_type').optional({ nullable: true }).isString().trim(),
|
||||
check('discount_type')
|
||||
.optional({ nullable: true })
|
||||
.isString()
|
||||
.isIn([DiscountType.Percentage, DiscountType.Amount]),
|
||||
|
||||
// Adjustment.
|
||||
check('adjustment').optional({ nullable: true }).isNumeric().toFloat(),
|
||||
@@ -763,8 +767,9 @@ export default class PaymentReceivesController extends BaseController {
|
||||
const { tenantId } = req;
|
||||
|
||||
try {
|
||||
const data =
|
||||
await this.getCreditNoteStateService.getCreditNoteState(tenantId);
|
||||
const data = await this.getCreditNoteStateService.getCreditNoteState(
|
||||
tenantId
|
||||
);
|
||||
return res.status(200).send({ data });
|
||||
} catch (error) {
|
||||
next(error);
|
||||
|
||||
@@ -11,6 +11,7 @@ import {
|
||||
SaleInvoiceAction,
|
||||
AbilitySubject,
|
||||
SendInvoiceMailDTO,
|
||||
DiscountType,
|
||||
} from '@/interfaces';
|
||||
import CheckPolicies from '@/api/middleware/CheckPolicies';
|
||||
import { SaleInvoiceApplication } from '@/services/Sales/Invoices/SaleInvoicesApplication';
|
||||
@@ -284,10 +285,13 @@ export default class SaleInvoicesController extends BaseController {
|
||||
|
||||
// Discount
|
||||
check('discount').optional({ nullable: true }).isNumeric().toFloat(),
|
||||
check('discount_type').optional({ nullable: true }).isString().trim(),
|
||||
check('discount_type')
|
||||
.optional({ nullable: true })
|
||||
.isString()
|
||||
.isIn([DiscountType.Percentage, DiscountType.Amount]),
|
||||
|
||||
// Adjustments
|
||||
check('adjustment').optional({ nullable: true }).isArray(),
|
||||
check('adjustment').optional({ nullable: true }).isNumeric().toFloat(),
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@@ -176,14 +176,18 @@ export default class SalesReceiptsController extends BaseController {
|
||||
check('attachments').isArray().optional(),
|
||||
check('attachments.*.key').exists().isString(),
|
||||
|
||||
// Pdf template id.
|
||||
// # Pdf template
|
||||
check('pdf_template_id').optional({ nullable: true }).isNumeric().toInt(),
|
||||
|
||||
// # Discount
|
||||
check('discount').optional({ nullable: true }).isNumeric().toFloat(),
|
||||
check('discount_type')
|
||||
.optional({ nullable: true })
|
||||
.isString()
|
||||
.isIn([DiscountType.Percentage, DiscountType.Amount]),
|
||||
|
||||
// # Adjustment
|
||||
check('adjustment').optional({ nullable: true }).isNumeric().toFloat(),
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ exports.up = function (knex) {
|
||||
return knex.schema.alterTable('sales_invoices', (table) => {
|
||||
table.decimal('discount', 10, 2).nullable().after('credited_amount');
|
||||
table.string('discount_type').nullable().after('discount');
|
||||
table.decimal('adjustments', 10, 2).nullable().after('discount_type');
|
||||
table.decimal('adjustment', 10, 2).nullable().after('discount_type');
|
||||
});
|
||||
};
|
||||
|
||||
@@ -18,6 +18,6 @@ exports.down = function (knex) {
|
||||
return knex.schema.alterTable('sale_invoices', (table) => {
|
||||
table.dropColumn('discount');
|
||||
table.dropColumn('discount_type');
|
||||
table.dropColumn('adjustments');
|
||||
table.dropColumn('adjustment');
|
||||
});
|
||||
};
|
||||
|
||||
@@ -23,6 +23,14 @@ export default class SaleEstimate extends mixin(TenantModel, [
|
||||
|
||||
public adjustment: number;
|
||||
|
||||
public expirationDate!: string;
|
||||
public deliveredAt!: string | null;
|
||||
public approvedAt!: string | null;
|
||||
public rejectedAt!: string | null;
|
||||
|
||||
public convertedToInvoiceId!: number | null;
|
||||
public convertedToInvoiceAt!: string | null;
|
||||
|
||||
/**
|
||||
* Table name
|
||||
*/
|
||||
@@ -45,6 +53,10 @@ export default class SaleEstimate extends mixin(TenantModel, [
|
||||
'localAmount',
|
||||
'discountAmount',
|
||||
'discountPercentage',
|
||||
'total',
|
||||
'totalLocal',
|
||||
'subtotal',
|
||||
'subtotalLocal',
|
||||
'isDelivered',
|
||||
'isExpired',
|
||||
'isConvertedToInvoice',
|
||||
|
||||
@@ -26,7 +26,7 @@ export default class SaleInvoice extends mixin(TenantModel, [
|
||||
public deliveredAt: Date;
|
||||
public discount: number;
|
||||
public discountType: DiscountType;
|
||||
public adjustments: number;
|
||||
public adjustment: number | null;
|
||||
|
||||
/**
|
||||
* Table name
|
||||
@@ -157,7 +157,7 @@ export default class SaleInvoice extends mixin(TenantModel, [
|
||||
* @returns {number}
|
||||
*/
|
||||
get total() {
|
||||
const adjustmentAmount = defaultTo(this.adjustments, 0);
|
||||
const adjustmentAmount = defaultTo(this.adjustment, 0);
|
||||
const differencies = this.discountAmount + adjustmentAmount;
|
||||
|
||||
return this.isInclusiveTax
|
||||
|
||||
@@ -118,25 +118,13 @@ export class GetSaleEstimateMailStateTransformer extends SaleEstimateTransfromer
|
||||
: 'Discount';
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the formatted total of the estimate.
|
||||
* @param estimate
|
||||
* @returns {string}
|
||||
*/
|
||||
protected totalFormatted(estimate) {
|
||||
return this.formatMoney(estimate.amount, {
|
||||
currencyCode: estimate.currencyCode,
|
||||
money: true,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the formatted subtotal of the estimate.
|
||||
* @param estimate
|
||||
* @returns {string}
|
||||
*/
|
||||
protected subtotalFormatted = (estimate) => {
|
||||
return this.formatNumber(estimate.amount, { money: false });
|
||||
return this.formattedSubtotal(estimate);
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -141,7 +141,7 @@ export class SaleEstimateTransfromer extends Transformer {
|
||||
* @returns {string}
|
||||
*/
|
||||
protected totalFormatted = (estimate: ISaleEstimate): string => {
|
||||
return formatNumber(estimate.total, {
|
||||
return this.formatMoney(estimate.total, {
|
||||
currencyCode: estimate.currencyCode,
|
||||
});
|
||||
};
|
||||
@@ -152,7 +152,7 @@ export class SaleEstimateTransfromer extends Transformer {
|
||||
* @returns {string}
|
||||
*/
|
||||
protected totalLocalFormatted = (estimate: ISaleEstimate): string => {
|
||||
return formatNumber(estimate.totalLocal, {
|
||||
return this.formatMoney(estimate.totalLocal, {
|
||||
currencyCode: estimate.currencyCode,
|
||||
});
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user