mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-20 23:00:34 +00:00
feat: enhance discount and adjustment validation in Bills and Vendor Credit controllers
This commit is contained in:
@@ -154,6 +154,9 @@ export default class BillsController extends BaseController {
|
|||||||
.default(DiscountType.Amount)
|
.default(DiscountType.Amount)
|
||||||
.isIn([DiscountType.Amount, DiscountType.Percentage]),
|
.isIn([DiscountType.Amount, DiscountType.Percentage]),
|
||||||
check('discount').optional().isDecimal().toFloat(),
|
check('discount').optional().isDecimal().toFloat(),
|
||||||
|
|
||||||
|
// # Adjustment
|
||||||
|
check('adjustment').optional({ nullable: true }).isNumeric().toFloat(),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -196,6 +199,15 @@ export default class BillsController extends BaseController {
|
|||||||
|
|
||||||
check('attachments').isArray().optional(),
|
check('attachments').isArray().optional(),
|
||||||
check('attachments.*.key').exists().isString(),
|
check('attachments.*.key').exists().isString(),
|
||||||
|
|
||||||
|
// # Discount
|
||||||
|
check('discount_type')
|
||||||
|
.default(DiscountType.Amount)
|
||||||
|
.isIn([DiscountType.Amount, DiscountType.Percentage]),
|
||||||
|
check('discount').optional().isDecimal().toFloat(),
|
||||||
|
|
||||||
|
// # Adjustment
|
||||||
|
check('adjustment').optional({ nullable: true }).isNumeric().toFloat(),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import { check, param, query } from 'express-validator';
|
|||||||
import { Service, Inject } from 'typedi';
|
import { Service, Inject } from 'typedi';
|
||||||
import {
|
import {
|
||||||
AbilitySubject,
|
AbilitySubject,
|
||||||
|
DiscountType,
|
||||||
IVendorCreditCreateDTO,
|
IVendorCreditCreateDTO,
|
||||||
IVendorCreditEditDTO,
|
IVendorCreditEditDTO,
|
||||||
VendorCreditAction,
|
VendorCreditAction,
|
||||||
@@ -186,7 +187,10 @@ export default class VendorCreditController 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(),
|
||||||
@@ -229,6 +233,16 @@ export default class VendorCreditController extends BaseController {
|
|||||||
|
|
||||||
check('attachments').isArray().optional(),
|
check('attachments').isArray().optional(),
|
||||||
check('attachments.*.key').exists().isString(),
|
check('attachments.*.key').exists().isString(),
|
||||||
|
|
||||||
|
// 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(),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -73,12 +73,7 @@ export default class VendorCredit extends mixin(TenantModel, [
|
|||||||
* @returns {number}
|
* @returns {number}
|
||||||
*/
|
*/
|
||||||
get total() {
|
get total() {
|
||||||
const discountAmount =
|
return this.subtotal - this.discountAmount - this.adjustment;
|
||||||
this.discountType === DiscountType.Amount
|
|
||||||
? this.discount
|
|
||||||
: this.subtotal * (this.discount / 100);
|
|
||||||
|
|
||||||
return this.subtotal - discountAmount - this.adjustment;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -160,7 +160,7 @@ function EstimateForm({
|
|||||||
overflow: 'hidden',
|
overflow: 'hidden',
|
||||||
display: 'flex',
|
display: 'flex',
|
||||||
flexDirection: 'column',
|
flexDirection: 'column',
|
||||||
flex: 1
|
flex: 1,
|
||||||
})}
|
})}
|
||||||
>
|
>
|
||||||
<PageForm flex={1}>
|
<PageForm flex={1}>
|
||||||
@@ -177,7 +177,7 @@ function EstimateForm({
|
|||||||
</PageForm>
|
</PageForm>
|
||||||
|
|
||||||
{/*------- Dialogs -------*/}
|
{/*------- Dialogs -------*/}
|
||||||
{/* <EstimateFormDialogs /> */}
|
<EstimateFormDialogs />
|
||||||
|
|
||||||
{/*------- Effects -------*/}
|
{/*------- Effects -------*/}
|
||||||
<EstimateIncrementSyncSettingsToForm />
|
<EstimateIncrementSyncSettingsToForm />
|
||||||
|
|||||||
Reference in New Issue
Block a user