mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-16 12:50:38 +00:00
feat: enhance discount handling in financial forms
- Implemented discount and adjustment fields in Bill, Credit Note, Estimate, Invoice, and Receipt forms. - Created new components for displaying discount and adjustment totals, improving clarity in financial documents. - Updated utility functions to format discount and adjustment amounts consistently across various forms. - Enhanced user experience by integrating discount functionality into the form context, allowing for better data management and display. This update improves the overall functionality and user experience related to discounts in financial transactions.
This commit is contained in:
@@ -10,6 +10,7 @@ import {
|
||||
repeatValue,
|
||||
transformToForm,
|
||||
formattedAmount,
|
||||
toSafeNumber,
|
||||
} from '@/utils';
|
||||
import { useReceiptFormContext } from './ReceiptFormProvider';
|
||||
import {
|
||||
@@ -63,6 +64,9 @@ export const defaultReceipt = {
|
||||
entries: [...repeatValue(defaultReceiptEntry, MIN_LINES_NUMBER)],
|
||||
attachments: [],
|
||||
pdf_template_id: '',
|
||||
discount: '',
|
||||
discount_type: 'amount',
|
||||
adjustment: '',
|
||||
};
|
||||
|
||||
const ERRORS = {
|
||||
@@ -249,6 +253,76 @@ export const useReceiptTotals = () => {
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* Retrieves the receipt subtotal.
|
||||
* @returns {number}
|
||||
*/
|
||||
export const useReceiptSubtotal = () => {
|
||||
const {
|
||||
values: { entries },
|
||||
} = useFormikContext();
|
||||
|
||||
// Retrieves the invoice entries total.
|
||||
const subtotal = React.useMemo(() => getEntriesTotal(entries), [entries]);
|
||||
|
||||
return subtotal;
|
||||
};
|
||||
|
||||
/**
|
||||
* Retrieves the formatted discount amount.
|
||||
* @returns {string}
|
||||
*/
|
||||
export const useReceiptDiscountAmountFormatted = () => {
|
||||
const { values } = useFormikContext();
|
||||
|
||||
return formattedAmount(values.discount, values.currency_code);
|
||||
};
|
||||
|
||||
/**
|
||||
* Retrieves the receipt adjustment amount.
|
||||
* @returns {number}
|
||||
*/
|
||||
export const useReceiptAdjustmentAmount = () => {
|
||||
const { values } = useFormikContext();
|
||||
const adjustment = toSafeNumber(values.adjustment);
|
||||
|
||||
return adjustment;
|
||||
};
|
||||
|
||||
/**
|
||||
* Retrieves the formatted adjustment amount.
|
||||
* @returns {string}
|
||||
*/
|
||||
export const useReceiptAdjustmentFormatted = () => {
|
||||
const { values } = useFormikContext();
|
||||
const adjustment = useReceiptAdjustmentAmount();
|
||||
|
||||
return formattedAmount(adjustment, values.currency_code);
|
||||
};
|
||||
|
||||
/**
|
||||
* Retrieves the receipt total.
|
||||
* @returns {number}
|
||||
*/
|
||||
export const useReceiptTotal = () => {
|
||||
const subtotal = useReceiptSubtotal();
|
||||
const adjustmentAmount = useReceiptAdjustmentAmount();
|
||||
const discountAmount = useReceiptDiscountAmount();
|
||||
|
||||
return subtotal - discountAmount + adjustmentAmount;
|
||||
};
|
||||
|
||||
/**
|
||||
* Retrieves the formatted receipt total.
|
||||
* @returns {string}
|
||||
*/
|
||||
export const useReceiptTotalFormatted = () => {
|
||||
const total = useReceiptTotal();
|
||||
const { values } = useFormikContext();
|
||||
|
||||
return formattedAmount(total, values.currency_code);
|
||||
};
|
||||
|
||||
/**
|
||||
* Detarmines whether the receipt has foreign customer.
|
||||
* @returns {boolean}
|
||||
|
||||
Reference in New Issue
Block a user