mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-17 21:30:31 +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:
@@ -1,17 +1,26 @@
|
||||
// @ts-nocheck
|
||||
import React from 'react';
|
||||
import styled from 'styled-components';
|
||||
import { useFormikContext } from 'formik';
|
||||
import { T, TotalLines, TotalLine, TotalLineTextStyle } from '@/components';
|
||||
import {
|
||||
T,
|
||||
TotalLines,
|
||||
TotalLine,
|
||||
TotalLineBorderStyle,
|
||||
TotalLineTextStyle,
|
||||
} from '@/components';
|
||||
import { useVendorCrditNoteTotals } from './utils';
|
||||
useVendorCreditAdjustmentAmountFormatted,
|
||||
useVendorCreditDiscountAmount,
|
||||
useVendorCreditSubtotalFormatted,
|
||||
useVendorCreditTotalFormatted,
|
||||
} from './utils';
|
||||
import { DiscountTotalLine } from '@/containers/Sales/Invoices/InvoiceForm/DiscountTotalLine';
|
||||
import { AdjustmentTotalLine } from '@/containers/Sales/Invoices/InvoiceForm/AdjustmentTotalLine';
|
||||
|
||||
export function VendorCreditNoteFormFooterRight() {
|
||||
const { formattedSubtotal, formattedTotal } = useVendorCrditNoteTotals();
|
||||
const {
|
||||
values: { currency_code },
|
||||
} = useFormikContext();
|
||||
const totalFormatted = useVendorCreditTotalFormatted();
|
||||
const subtotalFormatted = useVendorCreditSubtotalFormatted();
|
||||
|
||||
const discountAmount = useVendorCreditDiscountAmount();
|
||||
const adjustmentAmount = useVendorCreditAdjustmentAmountFormatted();
|
||||
|
||||
return (
|
||||
<VendorCreditNoteTotalLines
|
||||
@@ -20,12 +29,16 @@ export function VendorCreditNoteFormFooterRight() {
|
||||
>
|
||||
<TotalLine
|
||||
title={<T id={'vendor_credit_form.label.subtotal'} />}
|
||||
value={formattedSubtotal}
|
||||
borderStyle={TotalLineBorderStyle.None}
|
||||
value={subtotalFormatted}
|
||||
/>
|
||||
<DiscountTotalLine
|
||||
currencyCode={currency_code}
|
||||
discountAmount={discountAmount}
|
||||
/>
|
||||
<AdjustmentTotalLine adjustmentAmount={adjustmentAmount} />
|
||||
<TotalLine
|
||||
title={<T id={'vendor_credit_form.label.total'} />}
|
||||
value={formattedTotal}
|
||||
value={totalFormatted}
|
||||
textStyle={TotalLineTextStyle.Bold}
|
||||
/>
|
||||
</VendorCreditNoteTotalLines>
|
||||
|
||||
@@ -11,6 +11,7 @@ import {
|
||||
transactionNumber,
|
||||
orderingLinesIndexes,
|
||||
formattedAmount,
|
||||
toSafeNumber,
|
||||
} from '@/utils';
|
||||
import {
|
||||
updateItemsEntriesTotal,
|
||||
@@ -235,6 +236,19 @@ export const useVendorCreditDiscountAmount = () => {
|
||||
return toSafeNumber(values.discount);
|
||||
};
|
||||
|
||||
/**
|
||||
* Retrieves the vendor credit discount amount formatted.
|
||||
* @returns {string}
|
||||
*/
|
||||
export const useVendorCreditDiscountAmountFormatted = () => {
|
||||
const discountAmount = useVendorCreditDiscountAmount();
|
||||
const {
|
||||
values: { currency_code: currencyCode },
|
||||
} = useFormikContext();
|
||||
|
||||
return formattedAmount(discountAmount, currencyCode);
|
||||
};
|
||||
|
||||
/**
|
||||
* Retrieves the vendor credit adjustment amount.
|
||||
* @returns {number}
|
||||
@@ -245,6 +259,19 @@ export const useVendorCreditAdjustment = () => {
|
||||
return toSafeNumber(values.adjustment);
|
||||
};
|
||||
|
||||
/**
|
||||
* Retrieves the vendor credit adjustment amount formatted.
|
||||
* @returns {string}
|
||||
*/
|
||||
export const useVendorCreditAdjustmentAmountFormatted = () => {
|
||||
const adjustmentAmount = useVendorCreditAdjustment();
|
||||
const {
|
||||
values: { currency_code: currencyCode },
|
||||
} = useFormikContext();
|
||||
|
||||
return formattedAmount(adjustmentAmount, currencyCode);
|
||||
};
|
||||
|
||||
/**
|
||||
* Retrieves the vendor credit total.
|
||||
* @returns {number}
|
||||
@@ -258,12 +285,14 @@ export const useVendorCreditTotal = () => {
|
||||
};
|
||||
|
||||
/**
|
||||
* Retrieves the vendor credit formatted total.
|
||||
* Retrieves the vendor credit total formatted.
|
||||
* @returns {string}
|
||||
*/
|
||||
export const useVendorCreditFormattedTotal = () => {
|
||||
export const useVendorCreditTotalFormatted = () => {
|
||||
const total = useVendorCreditTotal();
|
||||
const currencyCode = useCurrentOrganizationCurrencyCode();
|
||||
const {
|
||||
values: { currency_code: currencyCode },
|
||||
} = useFormikContext();
|
||||
|
||||
return formattedAmount(total, currencyCode);
|
||||
};
|
||||
@@ -279,6 +308,19 @@ export const useVendorCreditFormattedSubtotal = () => {
|
||||
return formattedAmount(subtotal, currencyCode);
|
||||
};
|
||||
|
||||
/**
|
||||
* Retrieves the vendor credit formatted subtotal.
|
||||
* @returns {string}
|
||||
*/
|
||||
export const useVendorCreditSubtotalFormatted = () => {
|
||||
const subtotal = useVendorCreditSubtotal();
|
||||
const {
|
||||
values: { currency_code: currencyCode },
|
||||
} = useFormikContext();
|
||||
|
||||
return formattedAmount(subtotal, currencyCode);
|
||||
};
|
||||
|
||||
/**
|
||||
* Detarmines whether the vendor note has foreign customer.
|
||||
* @returns {boolean}
|
||||
|
||||
Reference in New Issue
Block a user