mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-19 22:30:31 +00:00
feat: calculate total amount of form entries.
This commit is contained in:
@@ -10,9 +10,8 @@ export default function PageFormBigNumber({ label, amount, currencyCode }) {
|
|||||||
<div className={classNames(CLASSES.PAGE_FORM_HEADER_BIG_NUMBERS)}>
|
<div className={classNames(CLASSES.PAGE_FORM_HEADER_BIG_NUMBERS)}>
|
||||||
<div class="big-amount">
|
<div class="big-amount">
|
||||||
<span class="big-amount__label">{ label }</span>
|
<span class="big-amount__label">{ label }</span>
|
||||||
|
|
||||||
<h1 class="big-amount__number">
|
<h1 class="big-amount__number">
|
||||||
<Money amount={0} currency={'LYD'} />
|
<Money amount={amount} currency={currencyCode} />
|
||||||
</h1>
|
</h1>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import React, { useState, useMemo, useEffect, useCallback } from 'react';
|
import React, { useState, useMemo, useEffect, useCallback } from 'react';
|
||||||
import { omit } from 'lodash';
|
|
||||||
import { Button, Intent, Position, Tooltip } from '@blueprintjs/core';
|
import { Button, Intent, Position, Tooltip } from '@blueprintjs/core';
|
||||||
import { FormattedMessage as T, useIntl } from 'react-intl';
|
import { FormattedMessage as T, useIntl } from 'react-intl';
|
||||||
import classNames from 'classnames';
|
import classNames from 'classnames';
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
import React from 'react';
|
import React, { useMemo } from 'react';
|
||||||
import classNames from 'classnames';
|
import classNames from 'classnames';
|
||||||
|
import { sumBy } from 'lodash';
|
||||||
|
import { useFormikContext } from 'formik';
|
||||||
|
|
||||||
import { CLASSES } from 'common/classes';
|
import { CLASSES } from 'common/classes';
|
||||||
|
|
||||||
@@ -8,15 +10,21 @@ import { PageFormBigNumber } from 'components';
|
|||||||
|
|
||||||
// Expense form header.
|
// Expense form header.
|
||||||
export default function ExpenseFormHeader() {
|
export default function ExpenseFormHeader() {
|
||||||
|
const { values } = useFormikContext();
|
||||||
|
|
||||||
|
// Calculates the expense entries amount.
|
||||||
|
const totalExpenseAmount = useMemo(() => sumBy(values.categories, 'amount'), [
|
||||||
|
values.categories,
|
||||||
|
]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={classNames(CLASSES.PAGE_FORM_HEADER)}>
|
<div className={classNames(CLASSES.PAGE_FORM_HEADER)}>
|
||||||
<ExpenseFormHeaderFields />
|
<ExpenseFormHeaderFields />
|
||||||
|
|
||||||
<PageFormBigNumber
|
<PageFormBigNumber
|
||||||
label={'Expense Amount'}
|
label={'Expense Amount'}
|
||||||
amount={0}
|
amount={totalExpenseAmount}
|
||||||
currencyCode={'LYD'}
|
currencyCode={'LYD'}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
import React from 'react';
|
import React, { useMemo } from 'react';
|
||||||
import classNames from 'classnames';
|
import classNames from 'classnames';
|
||||||
|
import { sumBy } from 'lodash';
|
||||||
|
import { useFormikContext } from 'formik';
|
||||||
|
|
||||||
import { CLASSES } from 'common/classes';
|
import { CLASSES } from 'common/classes';
|
||||||
|
|
||||||
@@ -10,11 +12,21 @@ import { PageFormBigNumber } from 'components';
|
|||||||
* Fill form header.
|
* Fill form header.
|
||||||
*/
|
*/
|
||||||
export default function BillFormHeader({ onBillNumberChanged }) {
|
export default function BillFormHeader({ onBillNumberChanged }) {
|
||||||
|
const { values } = useFormikContext();
|
||||||
|
|
||||||
|
// Calculate the total due amount of bill entries.
|
||||||
|
const totalDueAmount = useMemo(() => sumBy(values.entries, 'total'), [
|
||||||
|
values.entries,
|
||||||
|
]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={classNames(CLASSES.PAGE_FORM_HEADER)}>
|
<div className={classNames(CLASSES.PAGE_FORM_HEADER)}>
|
||||||
<BillFormHeaderFields onBillNumberChanged={onBillNumberChanged} />
|
<BillFormHeaderFields onBillNumberChanged={onBillNumberChanged} />
|
||||||
|
<PageFormBigNumber
|
||||||
<PageFormBigNumber label={'Due Amount'} amount={0} currencyCode={'LYD'} />
|
label={'Due Amount'}
|
||||||
|
amount={totalDueAmount}
|
||||||
|
currencyCode={'LYD'}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
import React from 'react';
|
import React, { useMemo } from 'react';
|
||||||
import { compose } from 'utils';
|
import { compose } from 'utils';
|
||||||
import classNames from 'classnames';
|
import classNames from 'classnames';
|
||||||
|
import { sumBy } from 'lodash';
|
||||||
|
import { useFormikContext } from 'formik';
|
||||||
|
|
||||||
import { CLASSES } from 'common/classes';
|
import { CLASSES } from 'common/classes';
|
||||||
|
|
||||||
import { PageFormBigNumber } from 'components';
|
import { PageFormBigNumber } from 'components';
|
||||||
@@ -10,17 +13,28 @@ import withDialogActions from 'containers/Dialog/withDialogActions';
|
|||||||
|
|
||||||
import EstimateFormHeaderFields from './EstimateFormHeaderFields';
|
import EstimateFormHeaderFields from './EstimateFormHeaderFields';
|
||||||
|
|
||||||
|
// Estimate form top header.
|
||||||
function EstimateFormHeader({
|
function EstimateFormHeader({
|
||||||
// #ownProps
|
// #ownProps
|
||||||
onEstimateNumberChanged,
|
onEstimateNumberChanged,
|
||||||
}) {
|
}) {
|
||||||
|
const { values } = useFormikContext();
|
||||||
|
|
||||||
|
// Calculate the total due amount of bill entries.
|
||||||
|
const totalDueAmount = useMemo(() => sumBy(values.entries, 'total'), [
|
||||||
|
values.entries,
|
||||||
|
]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={classNames(CLASSES.PAGE_FORM_HEADER)}>
|
<div className={classNames(CLASSES.PAGE_FORM_HEADER)}>
|
||||||
<EstimateFormHeaderFields
|
<EstimateFormHeaderFields
|
||||||
onEstimateNumberChanged={onEstimateNumberChanged}
|
onEstimateNumberChanged={onEstimateNumberChanged}
|
||||||
/>
|
/>
|
||||||
|
<PageFormBigNumber
|
||||||
<PageFormBigNumber label={'Amount'} amount={0} currencyCode={'LYD'} />
|
label={'Amount'}
|
||||||
|
amount={totalDueAmount}
|
||||||
|
currencyCode={'LYD'}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -229,7 +229,7 @@ function InvoiceForm({
|
|||||||
},
|
},
|
||||||
[changePageSubtitle],
|
[changePageSubtitle],
|
||||||
);
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={classNames(
|
<div className={classNames(
|
||||||
CLASSES.PAGE_FORM,
|
CLASSES.PAGE_FORM,
|
||||||
|
|||||||
@@ -1,5 +1,8 @@
|
|||||||
import React from 'react';
|
import React, { useMemo } from 'react';
|
||||||
import classNames from 'classnames';
|
import classNames from 'classnames';
|
||||||
|
import { sumBy } from 'lodash';
|
||||||
|
import { useFormikContext } from 'formik';
|
||||||
|
|
||||||
import { CLASSES } from 'common/classes';
|
import { CLASSES } from 'common/classes';
|
||||||
|
|
||||||
import InvoiceFormHeaderFields from './InvoiceFormHeaderFields';
|
import InvoiceFormHeaderFields from './InvoiceFormHeaderFields';
|
||||||
@@ -12,17 +15,23 @@ export default function InvoiceFormHeader({
|
|||||||
// #ownProps
|
// #ownProps
|
||||||
onInvoiceNumberChanged,
|
onInvoiceNumberChanged,
|
||||||
}) {
|
}) {
|
||||||
|
const { values } = useFormikContext();
|
||||||
|
|
||||||
|
// Calculate the total due amount of invoice entries.
|
||||||
|
const totalDueAmount = useMemo(() => sumBy(values.entries, 'total'), [
|
||||||
|
values.entries,
|
||||||
|
]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={classNames(CLASSES.PAGE_FORM_HEADER)}>
|
<div className={classNames(CLASSES.PAGE_FORM_HEADER)}>
|
||||||
<InvoiceFormHeaderFields
|
<InvoiceFormHeaderFields
|
||||||
onInvoiceNumberChanged={onInvoiceNumberChanged}
|
onInvoiceNumberChanged={onInvoiceNumberChanged}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<PageFormBigNumber
|
<PageFormBigNumber
|
||||||
label={'Due Amount'}
|
label={'Due Amount'}
|
||||||
amount={0}
|
amount={totalDueAmount}
|
||||||
currencyCode={'LYD'}
|
currencyCode={'LYD'}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,28 +1,34 @@
|
|||||||
import React from 'react';
|
import React, { useMemo } from 'react';
|
||||||
import classNames from 'classnames';
|
import classNames from 'classnames';
|
||||||
|
import { sumBy } from 'lodash';
|
||||||
|
import { useFormikContext } from 'formik';
|
||||||
|
|
||||||
import { Money } from 'components';
|
|
||||||
import { CLASSES } from 'common/classes';
|
import { CLASSES } from 'common/classes';
|
||||||
import ReceiptFormHeaderFields from './ReceiptFormHeaderFields';
|
import ReceiptFormHeaderFields from './ReceiptFormHeaderFields';
|
||||||
|
|
||||||
|
import { PageFormBigNumber } from 'components';
|
||||||
|
|
||||||
export default function ReceiptFormHeader({
|
export default function ReceiptFormHeader({
|
||||||
// #ownProps
|
// #ownProps
|
||||||
onReceiptNumberChanged,
|
onReceiptNumberChanged,
|
||||||
}) {
|
}) {
|
||||||
|
const { values } = useFormikContext();
|
||||||
|
|
||||||
|
// Calculate the total due amount of bill entries.
|
||||||
|
const totalDueAmount = useMemo(() => sumBy(values.entries, 'total'), [
|
||||||
|
values.entries,
|
||||||
|
]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={classNames(CLASSES.PAGE_FORM_HEADER)}>
|
<div className={classNames(CLASSES.PAGE_FORM_HEADER)}>
|
||||||
<ReceiptFormHeaderFields
|
<ReceiptFormHeaderFields
|
||||||
onReceiptNumberChanged={onReceiptNumberChanged}
|
onReceiptNumberChanged={onReceiptNumberChanged}
|
||||||
/>
|
/>
|
||||||
|
<PageFormBigNumber
|
||||||
<div className={classNames(CLASSES.PAGE_FORM_HEADER_BIG_NUMBERS)}>
|
label={'Due Amount'}
|
||||||
<div class="big-amount">
|
amount={totalDueAmount}
|
||||||
<span class="big-amount__label">Due Amount</span>
|
currencyCode={'LYD'}
|
||||||
<h1 class="big-amount__number">
|
/>
|
||||||
<Money amount={0} currency={'LYD'} />
|
|
||||||
</h1>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user