Merge pull request #355 from bigcapitalhq/big-126-invalid-bill-payment-amount-on-editing-bill-payment

fix: Invalid bill payment amount on editing bill payment
This commit is contained in:
Ahmed Bouhuolia
2024-02-05 22:39:52 +02:00
committed by GitHub
10 changed files with 60 additions and 4 deletions

View File

@@ -560,6 +560,16 @@ export default class BillsController extends BaseController {
errors: [{ type: 'ITEM_ENTRY_TAX_RATE_ID_NOT_FOUND', code: 1900 }],
});
}
if (error.errorType === 'BILL_AMOUNT_SMALLER_THAN_PAID_AMOUNT') {
return res.boom.badRequest(null, {
errors: [
{
type: 'BILL_AMOUNT_SMALLER_THAN_PAID_AMOUNT',
code: 2000,
},
],
});
}
}
next(error);
}

View File

@@ -21,6 +21,20 @@ export class BillsValidators {
}
}
/**
* Validates the bill amount is bigger than paid amount.
* @param {number} billAmount
* @param {number} paidAmount
*/
public validateBillAmountBiggerPaidAmount(
billAmount: number,
paidAmount: number,
) {
if (billAmount < paidAmount) {
throw new ServiceError(ERRORS.BILL_AMOUNT_SMALLER_THAN_PAID_AMOUNT);
}
}
/**
* Validates the bill number existance.
*/

View File

@@ -103,6 +103,7 @@ export class EditBill {
tenantId,
billDTO.entries
);
// Transforms the bill DTO to model object.
const billObj = await this.transformerDTO.billDTOToModel(
tenantId,
@@ -111,6 +112,11 @@ export class EditBill {
authorizedUser,
oldBill
);
// Validate bill total amount should be bigger than paid amount.
this.validators.validateBillAmountBiggerPaidAmount(
billObj.amount,
oldBill.paymentAmount
);
// Validate landed cost entries that have allocated cost could not be deleted.
await this.entriesService.validateLandedCostEntriesNotDeleted(
oldBill.entries,

View File

@@ -18,6 +18,7 @@ export const ERRORS = {
LANDED_COST_ENTRIES_SHOULD_BE_INVENTORY_ITEMS:
'LANDED_COST_ENTRIES_SHOULD_BE_INVENTORY_ITEMS',
BILL_HAS_APPLIED_TO_VENDOR_CREDIT: 'BILL_HAS_APPLIED_TO_VENDOR_CREDIT',
BILL_AMOUNT_SMALLER_THAN_PAID_AMOUNT: 'BILL_AMOUNT_SMALLER_THAN_PAID_AMOUNT',
};
export const DEFAULT_VIEW_COLUMNS = [];

View File

@@ -9,6 +9,8 @@ export const ERROR = {
SALE_INVOICE_NO_NOT_UNIQUE: 'SALE_INVOICE_NO_NOT_UNIQUE',
SALE_ESTIMATE_IS_ALREADY_CONVERTED_TO_INVOICE:
'SALE_ESTIMATE_IS_ALREADY_CONVERTED_TO_INVOICE',
INVOICE_AMOUNT_SMALLER_THAN_PAYMENT_AMOUNT:
'INVOICE_AMOUNT_SMALLER_THAN_PAYMENT_AMOUNT',
// Sales Receipts
SALE_RECEIPT_NUMBER_NOT_UNIQUE: 'SALE_RECEIPT_NUMBER_NOT_UNIQUE',
@@ -17,6 +19,6 @@ export const ERROR = {
// Bills
BILL_NUMBER_EXISTS: 'BILL.NUMBER.EXISTS',
SALE_INVOICE_NO_IS_REQUIRED: 'SALE_INVOICE_NO_IS_REQUIRED',
ENTRIES_ALLOCATED_COST_COULD_NOT_DELETED:"ENTRIES_ALLOCATED_COST_COULD_NOT_DELETED",
ENTRIES_ALLOCATED_COST_COULD_NOT_DELETED:
'ENTRIES_ALLOCATED_COST_COULD_NOT_DELETED',
};

View File

@@ -67,6 +67,7 @@ export const ERRORS = {
BILL_NUMBER_EXISTS: 'BILL.NUMBER.EXISTS',
ENTRIES_ALLOCATED_COST_COULD_NOT_DELETED:
'ENTRIES_ALLOCATED_COST_COULD_NOT_DELETED',
BILL_AMOUNT_SMALLER_THAN_PAID_AMOUNT: 'BILL_AMOUNT_SMALLER_THAN_PAID_AMOUNT',
};
/**
* Transformes the bill to initial values of edit form.
@@ -200,6 +201,14 @@ export const handleErrors = (errors, { setErrors }) => {
}),
);
}
if (
errors.some((e) => e.type === ERRORS.BILL_AMOUNT_SMALLER_THAN_PAID_AMOUNT)
) {
AppToaster.show({
intent: Intent.DANGER,
message: intl.get('bill.total_smaller_than_paid_amount'),
});
}
};
export const useSetPrimaryBranchToForm = () => {

View File

@@ -30,6 +30,7 @@ export default function PaymentMadeEntriesTable({
// Formik context.
const {
values: { vendor_id },
errors,
} = useFormikContext();
// Handle update data.
@@ -63,7 +64,7 @@ export default function PaymentMadeEntriesTable({
data={entries}
spinnerProps={false}
payload={{
errors: [],
errors: errors?.entries || [],
updateData: handleUpdateData,
currencyCode,
}}

View File

@@ -112,6 +112,16 @@ export const transformErrors = (errors, { setErrors }) => {
intent: Intent.DANGER,
});
}
if (
errors.some(
({ type }) => type === ERROR.INVOICE_AMOUNT_SMALLER_THAN_PAYMENT_AMOUNT,
)
) {
AppToaster.show({
message: intl.get('sale_invoice.total_smaller_than_paid_amount'),
intent: Intent.DANGER,
});
}
if (
errors.some((error) => error.type === ERROR.SALE_INVOICE_NO_IS_REQUIRED)
) {

View File

@@ -28,6 +28,7 @@ export default function PaymentReceiveItemsTable({
// Formik context.
const {
values: { customer_id },
errors,
} = useFormikContext();
// No results message.
@@ -58,7 +59,7 @@ export default function PaymentReceiveItemsTable({
data={entries}
spinnerProps={false}
payload={{
errors: [],
errors: errors?.entries || [],
updateData: handleUpdateData,
currencyCode,
}}

View File

@@ -653,7 +653,9 @@
"invoice_number_is_not_unqiue": "Invoice number is not unqiue",
"sale_receipt_number_not_unique": "Receipt number is not unique",
"sale_invoice_number_is_exists": "Sale invoice number is exists",
"sale_invoice.total_smaller_than_paid_amount": "The invoice total is smaller than the invoice paid amount.",
"bill_number_exists": "Bill number exists",
"bill.total_smaller_than_paid_amount": "The bill total is smaller than the bill paid amount.",
"ok": "Ok!",
"quantity_cannot_be_zero_or_empty": "Quantity cannot be zero or empty.",
"customer_email": "Customer email",