mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-18 13:50: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,58 +1,45 @@
|
||||
// @ts-nocheck
|
||||
import React from 'react';
|
||||
import styled from 'styled-components';
|
||||
import { Button } from '@blueprintjs/core';
|
||||
import { useFormikContext } from 'formik';
|
||||
import {
|
||||
T,
|
||||
TotalLines,
|
||||
TotalLine,
|
||||
TotalLineBorderStyle,
|
||||
TotalLineTextStyle,
|
||||
FInputGroup,
|
||||
FFormGroup,
|
||||
FSelect,
|
||||
} from '@/components';
|
||||
import {
|
||||
useCreditNoteAdjustmentFormatted,
|
||||
useCreditNoteDiscountAmountFormatted,
|
||||
useCreditNoteSubtotalFormatted,
|
||||
useCreditNoteTotalFormatted,
|
||||
} from './utils';
|
||||
import { DiscountTotalLine } from '../../Invoices/InvoiceForm/DiscountTotalLine';
|
||||
import { AdjustmentTotalLine } from '../../Invoices/InvoiceForm/AdjustmentTotalLine';
|
||||
|
||||
export function CreditNoteFormFooterRight() {
|
||||
const {
|
||||
values: { currency_code },
|
||||
} = useFormikContext();
|
||||
|
||||
const subtotalFormatted = useCreditNoteSubtotalFormatted();
|
||||
const totalFormatted = useCreditNoteTotalFormatted();
|
||||
const discountAmount = useCreditNoteDiscountAmountFormatted();
|
||||
const adjustmentAmount = useCreditNoteAdjustmentFormatted();
|
||||
|
||||
return (
|
||||
<CreditNoteTotalLines labelColWidth={'180px'} amountColWidth={'180px'}>
|
||||
<TotalLine
|
||||
title={<T id={'credit_note.label_subtotal'} />}
|
||||
value={subtotalFormatted}
|
||||
borderStyle={TotalLineBorderStyle.None}
|
||||
borderStyle={TotalLineBorderStyle.BorderBottom}
|
||||
/>
|
||||
<FFormGroup name={'discount'} label={'Discount'} inline>
|
||||
<FInputGroup
|
||||
name={'discount'}
|
||||
rightElement={
|
||||
<FSelect
|
||||
name={'discount_type'}
|
||||
items={[
|
||||
{ text: 'USD', value: 'amount' },
|
||||
{ text: '%', value: 'percentage' },
|
||||
]}
|
||||
input={({ text }) => (
|
||||
<Button small minimal>
|
||||
{text}
|
||||
</Button>
|
||||
)}
|
||||
filterable={false}
|
||||
/>
|
||||
}
|
||||
/>
|
||||
</FFormGroup>
|
||||
|
||||
<FFormGroup name={'adjustment'} label={'Adjustment'} inline>
|
||||
<FInputGroup name={'adjustment'} />
|
||||
</FFormGroup>
|
||||
|
||||
<DiscountTotalLine
|
||||
currencyCode={currency_code}
|
||||
discountAmount={discountAmount}
|
||||
/>
|
||||
<AdjustmentTotalLine adjustmentAmount={adjustmentAmount} />
|
||||
<TotalLine
|
||||
title={<T id={'credit_note.label_total'} />}
|
||||
value={totalFormatted}
|
||||
|
||||
@@ -196,9 +196,11 @@ export const useCreditNoteSubtotal = () => {
|
||||
*/
|
||||
export const useCreditNoteSubtotalFormatted = () => {
|
||||
const subtotal = useCreditNoteSubtotal();
|
||||
const { currency_code: currencyCode } = useFormikContext();
|
||||
const {
|
||||
values: { currency_code: currencyCode },
|
||||
} = useFormikContext();
|
||||
|
||||
return formattedAmount(subtotal, currencyCode, { money: false });
|
||||
return formattedAmount(subtotal, currencyCode, { money: true });
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -215,6 +217,19 @@ export const useCreditNoteDiscountAmount = () => {
|
||||
: discount;
|
||||
};
|
||||
|
||||
/**
|
||||
* Retrieves the credit note discount amount formatted.
|
||||
* @returns {string}
|
||||
*/
|
||||
export const useCreditNoteDiscountAmountFormatted = () => {
|
||||
const discountAmount = useCreditNoteDiscountAmount();
|
||||
const {
|
||||
values: { currency_code: currencyCode },
|
||||
} = useFormikContext();
|
||||
|
||||
return formattedAmount(discountAmount, currencyCode, { money: true });
|
||||
};
|
||||
|
||||
/**
|
||||
* Retrieves the credit note adjustment amount.
|
||||
* @returns {number}
|
||||
@@ -225,6 +240,19 @@ export const useCreditNoteAdjustmentAmount = () => {
|
||||
return toSafeNumber(values.adjustment);
|
||||
};
|
||||
|
||||
/**
|
||||
* Retrieves the credit note adjustment amount formatted.
|
||||
* @returns {string}
|
||||
*/
|
||||
export const useCreditNoteAdjustmentFormatted = () => {
|
||||
const adjustmentAmount = useCreditNoteAdjustmentAmount();
|
||||
const {
|
||||
values: { currency_code: currencyCode },
|
||||
} = useFormikContext();
|
||||
|
||||
return formattedAmount(adjustmentAmount, currencyCode, { money: true });
|
||||
};
|
||||
|
||||
/**
|
||||
* Retrieves the credit note total.
|
||||
* @returns {number}
|
||||
@@ -243,9 +271,11 @@ export const useCreditNoteTotal = () => {
|
||||
*/
|
||||
export const useCreditNoteTotalFormatted = () => {
|
||||
const total = useCreditNoteTotal();
|
||||
const { currency_code: currencyCode } = useFormikContext();
|
||||
const {
|
||||
values: { currency_code: currencyCode },
|
||||
} = useFormikContext();
|
||||
|
||||
return formattedAmount(total, currencyCode);
|
||||
return formattedAmount(total, currencyCode, { money: true });
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user