fix: Invalid bill payment amount on editing bill payment

This commit is contained in:
Ahmed Bouhuolia
2024-02-05 22:38:56 +02:00
parent 7b5287ee80
commit 12740223a8
10 changed files with 60 additions and 4 deletions

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",