mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-21 15:20:34 +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 {
|
import {
|
||||||
AbilitySubject,
|
AbilitySubject,
|
||||||
CreditNoteAction,
|
CreditNoteAction,
|
||||||
|
DiscountType,
|
||||||
ICreditNoteEditDTO,
|
ICreditNoteEditDTO,
|
||||||
ICreditNoteNewDTO,
|
ICreditNoteNewDTO,
|
||||||
} from '@/interfaces';
|
} from '@/interfaces';
|
||||||
@@ -253,7 +254,10 @@ export default class PaymentReceivesController extends BaseController {
|
|||||||
|
|
||||||
// Discount.
|
// Discount.
|
||||||
check('discount').optional({ nullable: true }).isNumeric().toFloat(),
|
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.
|
// Adjustment.
|
||||||
check('adjustment').optional({ nullable: true }).isNumeric().toFloat(),
|
check('adjustment').optional({ nullable: true }).isNumeric().toFloat(),
|
||||||
@@ -763,8 +767,9 @@ export default class PaymentReceivesController extends BaseController {
|
|||||||
const { tenantId } = req;
|
const { tenantId } = req;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const data =
|
const data = await this.getCreditNoteStateService.getCreditNoteState(
|
||||||
await this.getCreditNoteStateService.getCreditNoteState(tenantId);
|
tenantId
|
||||||
|
);
|
||||||
return res.status(200).send({ data });
|
return res.status(200).send({ data });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
next(error);
|
next(error);
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import {
|
|||||||
SaleInvoiceAction,
|
SaleInvoiceAction,
|
||||||
AbilitySubject,
|
AbilitySubject,
|
||||||
SendInvoiceMailDTO,
|
SendInvoiceMailDTO,
|
||||||
|
DiscountType,
|
||||||
} from '@/interfaces';
|
} from '@/interfaces';
|
||||||
import CheckPolicies from '@/api/middleware/CheckPolicies';
|
import CheckPolicies from '@/api/middleware/CheckPolicies';
|
||||||
import { SaleInvoiceApplication } from '@/services/Sales/Invoices/SaleInvoicesApplication';
|
import { SaleInvoiceApplication } from '@/services/Sales/Invoices/SaleInvoicesApplication';
|
||||||
@@ -284,10 +285,13 @@ export default class SaleInvoicesController extends BaseController {
|
|||||||
|
|
||||||
// Discount
|
// Discount
|
||||||
check('discount').optional({ nullable: true }).isNumeric().toFloat(),
|
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
|
// 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').isArray().optional(),
|
||||||
check('attachments.*.key').exists().isString(),
|
check('attachments.*.key').exists().isString(),
|
||||||
|
|
||||||
// Pdf template id.
|
// # Pdf template
|
||||||
check('pdf_template_id').optional({ nullable: true }).isNumeric().toInt(),
|
check('pdf_template_id').optional({ nullable: true }).isNumeric().toInt(),
|
||||||
|
|
||||||
// # Discount
|
// # Discount
|
||||||
check('discount').optional({ nullable: true }).isNumeric().toFloat(),
|
check('discount').optional({ nullable: true }).isNumeric().toFloat(),
|
||||||
check('discount_type')
|
check('discount_type')
|
||||||
.optional({ nullable: true })
|
.optional({ nullable: true })
|
||||||
|
.isString()
|
||||||
.isIn([DiscountType.Percentage, DiscountType.Amount]),
|
.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) => {
|
return knex.schema.alterTable('sales_invoices', (table) => {
|
||||||
table.decimal('discount', 10, 2).nullable().after('credited_amount');
|
table.decimal('discount', 10, 2).nullable().after('credited_amount');
|
||||||
table.string('discount_type').nullable().after('discount');
|
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) => {
|
return knex.schema.alterTable('sale_invoices', (table) => {
|
||||||
table.dropColumn('discount');
|
table.dropColumn('discount');
|
||||||
table.dropColumn('discount_type');
|
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 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
|
* Table name
|
||||||
*/
|
*/
|
||||||
@@ -45,6 +53,10 @@ export default class SaleEstimate extends mixin(TenantModel, [
|
|||||||
'localAmount',
|
'localAmount',
|
||||||
'discountAmount',
|
'discountAmount',
|
||||||
'discountPercentage',
|
'discountPercentage',
|
||||||
|
'total',
|
||||||
|
'totalLocal',
|
||||||
|
'subtotal',
|
||||||
|
'subtotalLocal',
|
||||||
'isDelivered',
|
'isDelivered',
|
||||||
'isExpired',
|
'isExpired',
|
||||||
'isConvertedToInvoice',
|
'isConvertedToInvoice',
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ export default class SaleInvoice extends mixin(TenantModel, [
|
|||||||
public deliveredAt: Date;
|
public deliveredAt: Date;
|
||||||
public discount: number;
|
public discount: number;
|
||||||
public discountType: DiscountType;
|
public discountType: DiscountType;
|
||||||
public adjustments: number;
|
public adjustment: number | null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Table name
|
* Table name
|
||||||
@@ -157,7 +157,7 @@ export default class SaleInvoice extends mixin(TenantModel, [
|
|||||||
* @returns {number}
|
* @returns {number}
|
||||||
*/
|
*/
|
||||||
get total() {
|
get total() {
|
||||||
const adjustmentAmount = defaultTo(this.adjustments, 0);
|
const adjustmentAmount = defaultTo(this.adjustment, 0);
|
||||||
const differencies = this.discountAmount + adjustmentAmount;
|
const differencies = this.discountAmount + adjustmentAmount;
|
||||||
|
|
||||||
return this.isInclusiveTax
|
return this.isInclusiveTax
|
||||||
|
|||||||
@@ -118,25 +118,13 @@ export class GetSaleEstimateMailStateTransformer extends SaleEstimateTransfromer
|
|||||||
: 'Discount';
|
: '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.
|
* Retrieves the formatted subtotal of the estimate.
|
||||||
* @param estimate
|
* @param estimate
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
protected subtotalFormatted = (estimate) => {
|
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}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
protected totalFormatted = (estimate: ISaleEstimate): string => {
|
protected totalFormatted = (estimate: ISaleEstimate): string => {
|
||||||
return formatNumber(estimate.total, {
|
return this.formatMoney(estimate.total, {
|
||||||
currencyCode: estimate.currencyCode,
|
currencyCode: estimate.currencyCode,
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@@ -152,7 +152,7 @@ export class SaleEstimateTransfromer extends Transformer {
|
|||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
protected totalLocalFormatted = (estimate: ISaleEstimate): string => {
|
protected totalLocalFormatted = (estimate: ISaleEstimate): string => {
|
||||||
return formatNumber(estimate.totalLocal, {
|
return this.formatMoney(estimate.totalLocal, {
|
||||||
currencyCode: estimate.currencyCode,
|
currencyCode: estimate.currencyCode,
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -284,7 +284,7 @@ export const useReceiptTotal = () => {
|
|||||||
const adjustmentAmount = useReceiptAdjustmentAmount();
|
const adjustmentAmount = useReceiptAdjustmentAmount();
|
||||||
const discountAmount = useReceiptDiscountAmount();
|
const discountAmount = useReceiptDiscountAmount();
|
||||||
|
|
||||||
return subtotal - discountAmount + adjustmentAmount;
|
return subtotal - discountAmount - adjustmentAmount;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user