mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-21 07:10:33 +00:00
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:
@@ -560,6 +560,16 @@ export default class BillsController extends BaseController {
|
|||||||
errors: [{ type: 'ITEM_ENTRY_TAX_RATE_ID_NOT_FOUND', code: 1900 }],
|
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);
|
next(error);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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.
|
* Validates the bill number existance.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -103,6 +103,7 @@ export class EditBill {
|
|||||||
tenantId,
|
tenantId,
|
||||||
billDTO.entries
|
billDTO.entries
|
||||||
);
|
);
|
||||||
|
|
||||||
// Transforms the bill DTO to model object.
|
// Transforms the bill DTO to model object.
|
||||||
const billObj = await this.transformerDTO.billDTOToModel(
|
const billObj = await this.transformerDTO.billDTOToModel(
|
||||||
tenantId,
|
tenantId,
|
||||||
@@ -111,6 +112,11 @@ export class EditBill {
|
|||||||
authorizedUser,
|
authorizedUser,
|
||||||
oldBill
|
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.
|
// Validate landed cost entries that have allocated cost could not be deleted.
|
||||||
await this.entriesService.validateLandedCostEntriesNotDeleted(
|
await this.entriesService.validateLandedCostEntriesNotDeleted(
|
||||||
oldBill.entries,
|
oldBill.entries,
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ export const ERRORS = {
|
|||||||
LANDED_COST_ENTRIES_SHOULD_BE_INVENTORY_ITEMS:
|
LANDED_COST_ENTRIES_SHOULD_BE_INVENTORY_ITEMS:
|
||||||
'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_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 = [];
|
export const DEFAULT_VIEW_COLUMNS = [];
|
||||||
|
|||||||
@@ -9,6 +9,8 @@ export const ERROR = {
|
|||||||
SALE_INVOICE_NO_NOT_UNIQUE: 'SALE_INVOICE_NO_NOT_UNIQUE',
|
SALE_INVOICE_NO_NOT_UNIQUE: 'SALE_INVOICE_NO_NOT_UNIQUE',
|
||||||
SALE_ESTIMATE_IS_ALREADY_CONVERTED_TO_INVOICE:
|
SALE_ESTIMATE_IS_ALREADY_CONVERTED_TO_INVOICE:
|
||||||
'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
|
// Sales Receipts
|
||||||
SALE_RECEIPT_NUMBER_NOT_UNIQUE: 'SALE_RECEIPT_NUMBER_NOT_UNIQUE',
|
SALE_RECEIPT_NUMBER_NOT_UNIQUE: 'SALE_RECEIPT_NUMBER_NOT_UNIQUE',
|
||||||
@@ -17,6 +19,6 @@ export const ERROR = {
|
|||||||
// Bills
|
// Bills
|
||||||
BILL_NUMBER_EXISTS: 'BILL.NUMBER.EXISTS',
|
BILL_NUMBER_EXISTS: 'BILL.NUMBER.EXISTS',
|
||||||
SALE_INVOICE_NO_IS_REQUIRED: 'SALE_INVOICE_NO_IS_REQUIRED',
|
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',
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -67,6 +67,7 @@ export const ERRORS = {
|
|||||||
BILL_NUMBER_EXISTS: 'BILL.NUMBER.EXISTS',
|
BILL_NUMBER_EXISTS: 'BILL.NUMBER.EXISTS',
|
||||||
ENTRIES_ALLOCATED_COST_COULD_NOT_DELETED:
|
ENTRIES_ALLOCATED_COST_COULD_NOT_DELETED:
|
||||||
'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.
|
* 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 = () => {
|
export const useSetPrimaryBranchToForm = () => {
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ export default function PaymentMadeEntriesTable({
|
|||||||
// Formik context.
|
// Formik context.
|
||||||
const {
|
const {
|
||||||
values: { vendor_id },
|
values: { vendor_id },
|
||||||
|
errors,
|
||||||
} = useFormikContext();
|
} = useFormikContext();
|
||||||
|
|
||||||
// Handle update data.
|
// Handle update data.
|
||||||
@@ -63,7 +64,7 @@ export default function PaymentMadeEntriesTable({
|
|||||||
data={entries}
|
data={entries}
|
||||||
spinnerProps={false}
|
spinnerProps={false}
|
||||||
payload={{
|
payload={{
|
||||||
errors: [],
|
errors: errors?.entries || [],
|
||||||
updateData: handleUpdateData,
|
updateData: handleUpdateData,
|
||||||
currencyCode,
|
currencyCode,
|
||||||
}}
|
}}
|
||||||
|
|||||||
@@ -112,6 +112,16 @@ export const transformErrors = (errors, { setErrors }) => {
|
|||||||
intent: Intent.DANGER,
|
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 (
|
if (
|
||||||
errors.some((error) => error.type === ERROR.SALE_INVOICE_NO_IS_REQUIRED)
|
errors.some((error) => error.type === ERROR.SALE_INVOICE_NO_IS_REQUIRED)
|
||||||
) {
|
) {
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ export default function PaymentReceiveItemsTable({
|
|||||||
// Formik context.
|
// Formik context.
|
||||||
const {
|
const {
|
||||||
values: { customer_id },
|
values: { customer_id },
|
||||||
|
errors,
|
||||||
} = useFormikContext();
|
} = useFormikContext();
|
||||||
|
|
||||||
// No results message.
|
// No results message.
|
||||||
@@ -58,7 +59,7 @@ export default function PaymentReceiveItemsTable({
|
|||||||
data={entries}
|
data={entries}
|
||||||
spinnerProps={false}
|
spinnerProps={false}
|
||||||
payload={{
|
payload={{
|
||||||
errors: [],
|
errors: errors?.entries || [],
|
||||||
updateData: handleUpdateData,
|
updateData: handleUpdateData,
|
||||||
currencyCode,
|
currencyCode,
|
||||||
}}
|
}}
|
||||||
|
|||||||
@@ -653,7 +653,9 @@
|
|||||||
"invoice_number_is_not_unqiue": "Invoice number is not unqiue",
|
"invoice_number_is_not_unqiue": "Invoice number is not unqiue",
|
||||||
"sale_receipt_number_not_unique": "Receipt number is not unique",
|
"sale_receipt_number_not_unique": "Receipt number is not unique",
|
||||||
"sale_invoice_number_is_exists": "Sale invoice number is exists",
|
"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_number_exists": "Bill number exists",
|
||||||
|
"bill.total_smaller_than_paid_amount": "The bill total is smaller than the bill paid amount.",
|
||||||
"ok": "Ok!",
|
"ok": "Ok!",
|
||||||
"quantity_cannot_be_zero_or_empty": "Quantity cannot be zero or empty.",
|
"quantity_cannot_be_zero_or_empty": "Quantity cannot be zero or empty.",
|
||||||
"customer_email": "Customer email",
|
"customer_email": "Customer email",
|
||||||
|
|||||||
Reference in New Issue
Block a user