mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-19 14:20:31 +00:00
fix: add credited_amount & calculate remaining.
This commit is contained in:
@@ -2,7 +2,8 @@ import React from 'react';
|
|||||||
import { FastField, useFormikContext } from 'formik';
|
import { FastField, useFormikContext } from 'formik';
|
||||||
import { Classes } from '@blueprintjs/core';
|
import { Classes } from '@blueprintjs/core';
|
||||||
import { T, TotalLines, TotalLine } from 'components';
|
import { T, TotalLines, TotalLine } from 'components';
|
||||||
import { sumBy, subtract } from 'lodash';
|
import { subtract } from 'lodash';
|
||||||
|
import { getEntriesTotal } from 'containers/Entries/utils';
|
||||||
import ReconcileCreditNoteEntriesTable from './ReconcileCreditNoteEntriesTable';
|
import ReconcileCreditNoteEntriesTable from './ReconcileCreditNoteEntriesTable';
|
||||||
import { useReconcileCreditNoteContext } from './ReconcileCreditNoteFormProvider';
|
import { useReconcileCreditNoteContext } from './ReconcileCreditNoteFormProvider';
|
||||||
import { formattedAmount } from 'utils';
|
import { formattedAmount } from 'utils';
|
||||||
@@ -21,11 +22,14 @@ export default function ReconcileCreditNoteFormFields() {
|
|||||||
|
|
||||||
const { values } = useFormikContext();
|
const { values } = useFormikContext();
|
||||||
|
|
||||||
// Calculate the total amount.
|
// Calculate the total amount of credit entries.
|
||||||
const totalAmount = React.useMemo(() => {
|
const totalAmount = React.useMemo(
|
||||||
const total = sumBy(values.entries, 'amount');
|
() => getEntriesTotal(values.entries),
|
||||||
return subtract(credits_remaining, total);
|
[values.entries],
|
||||||
}, [values.entries]);
|
);
|
||||||
|
|
||||||
|
// Calculate the total amount of credit remaining.
|
||||||
|
const creditsRemaining = subtract(credits_remaining, totalAmount);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={Classes.DIALOG_BODY}>
|
<div className={Classes.DIALOG_BODY}>
|
||||||
@@ -64,7 +68,7 @@ export default function ReconcileCreditNoteFormFields() {
|
|||||||
/>
|
/>
|
||||||
<TotalLine
|
<TotalLine
|
||||||
title={<T id={'reconcile_credit_note.dialog.remaining_credits'} />}
|
title={<T id={'reconcile_credit_note.dialog.remaining_credits'} />}
|
||||||
value={formatted_credits_remaining}
|
value={formattedAmount(creditsRemaining, currency_code)}
|
||||||
/>
|
/>
|
||||||
</TotalLines>
|
</TotalLines>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { FastField, useFormikContext } from 'formik';
|
import { FastField, useFormikContext } from 'formik';
|
||||||
import { Classes } from '@blueprintjs/core';
|
import { Classes } from '@blueprintjs/core';
|
||||||
import { sumBy, subtract } from 'lodash';
|
import { subtract } from 'lodash';
|
||||||
|
import { getEntriesTotal } from 'containers/Entries/utils';
|
||||||
import { T, TotalLines, TotalLine } from 'components';
|
import { T, TotalLines, TotalLine } from 'components';
|
||||||
import ReconcileVendorCreditEntriesTable from './ReconcileVendorCreditEntriesTable';
|
import ReconcileVendorCreditEntriesTable from './ReconcileVendorCreditEntriesTable';
|
||||||
import { useReconcileVendorCreditContext } from './ReconcileVendorCreditFormProvider';
|
import { useReconcileVendorCreditContext } from './ReconcileVendorCreditFormProvider';
|
||||||
@@ -18,11 +19,14 @@ export default function ReconcileVendorCreditFormFields() {
|
|||||||
|
|
||||||
const { values } = useFormikContext();
|
const { values } = useFormikContext();
|
||||||
|
|
||||||
// Calculate the total amount.
|
// Calculate the total amount of credit entries.
|
||||||
const totalAmount = React.useMemo(() => {
|
const totalAmount = React.useMemo(
|
||||||
const total = sumBy(values.entries, 'amount');
|
() => getEntriesTotal(values.entries),
|
||||||
return subtract(credits_remaining, total);
|
[values.entries],
|
||||||
}, [values.entries]);
|
);
|
||||||
|
|
||||||
|
// Calculate the total amount of credit remaining.
|
||||||
|
const creditsRemaining = subtract(credits_remaining, totalAmount);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={Classes.DIALOG_BODY}>
|
<div className={Classes.DIALOG_BODY}>
|
||||||
@@ -62,7 +66,7 @@ export default function ReconcileVendorCreditFormFields() {
|
|||||||
title={
|
title={
|
||||||
<T id={'reconcile_vendor_credit.dialog.remaining_credits'} />
|
<T id={'reconcile_vendor_credit.dialog.remaining_credits'} />
|
||||||
}
|
}
|
||||||
value={formatted_credits_remaining}
|
value={formattedAmount(creditsRemaining, currency_code)}
|
||||||
/>
|
/>
|
||||||
</TotalLines>
|
</TotalLines>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -137,7 +137,8 @@ export function StatusAccessor(bill) {
|
|||||||
animate={false}
|
animate={false}
|
||||||
stripes={false}
|
stripes={false}
|
||||||
intent={Intent.PRIMARY}
|
intent={Intent.PRIMARY}
|
||||||
value={calculateStatus(bill.payment_amount, bill.amount)}
|
value={calculateStatus(bill.credited_amount, bill.amount)}
|
||||||
|
// value={calculateStatus(bill.payment_amount, bill.amount)}
|
||||||
/>
|
/>
|
||||||
</If>
|
</If>
|
||||||
</Choose.When>
|
</Choose.When>
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ export const statusAccessor = (row) => {
|
|||||||
animate={false}
|
animate={false}
|
||||||
stripes={false}
|
stripes={false}
|
||||||
intent={Intent.PRIMARY}
|
intent={Intent.PRIMARY}
|
||||||
value={calculateStatus(row.payment_amount, row.balance)}
|
value={calculateStatus(row.credited_amount, row.balance)}
|
||||||
/>
|
/>
|
||||||
</If>
|
</If>
|
||||||
</Choose.When>
|
</Choose.When>
|
||||||
|
|||||||
@@ -1579,7 +1579,7 @@
|
|||||||
"credit_note_opened.are_sure_to_open_this_credit": "Are you sure you want to open this credit note?",
|
"credit_note_opened.are_sure_to_open_this_credit": "Are you sure you want to open this credit note?",
|
||||||
"vendor_credit_opened.alert.success_message": "The vendor credit has been opened successfully",
|
"vendor_credit_opened.alert.success_message": "The vendor credit has been opened successfully",
|
||||||
"vendor_credit_opened.are_sure_to_open_this_credit": "Are you sure you want to open this vendor credit?",
|
"vendor_credit_opened.are_sure_to_open_this_credit": "Are you sure you want to open this vendor credit?",
|
||||||
"reconcile_credit_note.label": "Reconcile credit note with invoices.",
|
"reconcile_credit_note.label": "Reconcile credit note with invoices",
|
||||||
"reconcile_credit_note.dialog.total_amount_to_credit": "Total amount to credit",
|
"reconcile_credit_note.dialog.total_amount_to_credit": "Total amount to credit",
|
||||||
"reconcile_credit_note.dialog.credits_balance": "Credits balance:",
|
"reconcile_credit_note.dialog.credits_balance": "Credits balance:",
|
||||||
"reconcile_credit_note.dialog.remaining_credits": "Remaining credits",
|
"reconcile_credit_note.dialog.remaining_credits": "Remaining credits",
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
.bp3-dialog-body {
|
.bp3-dialog-body {
|
||||||
.footer {
|
.footer {
|
||||||
display: flex;
|
display: flex;
|
||||||
margin-top: 40px;
|
margin-top: 20px;
|
||||||
|
|
||||||
.total_lines {
|
.total_lines {
|
||||||
margin-left: auto;
|
margin-left: auto;
|
||||||
@@ -17,7 +17,7 @@
|
|||||||
.amount,
|
.amount,
|
||||||
.title {
|
.title {
|
||||||
padding: 8px 0px;
|
padding: 8px 0px;
|
||||||
width: 165px;
|
width: 150px;
|
||||||
}
|
}
|
||||||
.amount {
|
.amount {
|
||||||
text-align: right;
|
text-align: right;
|
||||||
|
|||||||
Reference in New Issue
Block a user