mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-21 15:20:34 +00:00
feat(InvoiceForm): remove the entries table footer.
This commit is contained in:
@@ -1,8 +1,11 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import intl from 'react-intl-universal';
|
import intl from 'react-intl-universal';
|
||||||
import { Tooltip, Button, Intent, Position } from '@blueprintjs/core';
|
import { MenuItem, Menu, Button, Position } from '@blueprintjs/core';
|
||||||
|
import { Popover2 } from '@blueprintjs/popover2';
|
||||||
|
|
||||||
|
import { Align } from 'common';
|
||||||
import { Hint, Icon, FormattedMessage as T } from 'components';
|
import { Hint, Icon, FormattedMessage as T } from 'components';
|
||||||
import { formattedAmount, safeSumBy } from 'utils';
|
import { formattedAmount } from 'utils';
|
||||||
import {
|
import {
|
||||||
InputGroupCell,
|
InputGroupCell,
|
||||||
MoneyFieldCell,
|
MoneyFieldCell,
|
||||||
@@ -27,60 +30,35 @@ export function ItemHeaderCell() {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Item column footer cell.
|
|
||||||
*/
|
|
||||||
export function ItemFooterCell() {
|
|
||||||
return (
|
|
||||||
<span>
|
|
||||||
<T id={'total'} />
|
|
||||||
</span>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Actions cell renderer component.
|
* Actions cell renderer component.
|
||||||
*/
|
*/
|
||||||
export function ActionsCellRenderer({
|
export function ActionsCellRenderer({
|
||||||
row: { index },
|
row: { index },
|
||||||
column: { id },
|
|
||||||
cell: { value },
|
|
||||||
data,
|
|
||||||
payload: { removeRow },
|
payload: { removeRow },
|
||||||
}) {
|
}) {
|
||||||
const onRemoveRole = () => {
|
const onRemoveRole = () => {
|
||||||
removeRow(index);
|
removeRow(index);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const exampleMenu = (
|
||||||
|
<Menu>
|
||||||
|
<MenuItem onClick={onRemoveRole} text="Remove line" />
|
||||||
|
</Menu>
|
||||||
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Tooltip content={<T id={'remove_the_line'} />} position={Position.LEFT}>
|
<Popover2 content={exampleMenu} placement="left-start">
|
||||||
<Button
|
<Button
|
||||||
icon={<Icon icon={'times-circle'} iconSize={14} />}
|
icon={<Icon icon={'more-13'} iconSize={13} />}
|
||||||
iconSize={14}
|
iconSize={14}
|
||||||
className="m12"
|
className="m12"
|
||||||
intent={Intent.DANGER}
|
minimal={true}
|
||||||
onClick={onRemoveRole}
|
|
||||||
/>
|
/>
|
||||||
</Tooltip>
|
</Popover2>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Quantity total footer cell.
|
|
||||||
*/
|
|
||||||
export function QuantityTotalFooterCell({ rows }) {
|
|
||||||
const quantity = safeSumBy(rows, 'original.quantity');
|
|
||||||
return <span>{quantity}</span>;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Total footer cell.
|
|
||||||
*/
|
|
||||||
export function TotalFooterCell({ payload: { currencyCode }, rows }) {
|
|
||||||
const total = safeSumBy(rows, 'original.amount');
|
|
||||||
return <span>{formattedAmount(total, currencyCode)}</span>;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Total accessor.
|
* Total accessor.
|
||||||
*/
|
*/
|
||||||
@@ -108,26 +86,14 @@ const LandedCostHeaderCell = () => {
|
|||||||
/**
|
/**
|
||||||
* Retrieve editable items entries columns.
|
* Retrieve editable items entries columns.
|
||||||
*/
|
*/
|
||||||
export function useEditableItemsEntriesColumns({
|
export function useEditableItemsEntriesColumns({ landedCost }) {
|
||||||
landedCost,
|
|
||||||
}) {
|
|
||||||
return React.useMemo(
|
return React.useMemo(
|
||||||
() => [
|
() => [
|
||||||
{
|
|
||||||
Header: '#',
|
|
||||||
accessor: 'index',
|
|
||||||
Cell: IndexTableCell,
|
|
||||||
width: 40,
|
|
||||||
disableResizing: true,
|
|
||||||
disableSortBy: true,
|
|
||||||
className: 'index',
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
Header: ItemHeaderCell,
|
Header: ItemHeaderCell,
|
||||||
id: 'item_id',
|
id: 'item_id',
|
||||||
accessor: 'item_id',
|
accessor: 'item_id',
|
||||||
Cell: ItemsListCell,
|
Cell: ItemsListCell,
|
||||||
Footer: ItemFooterCell,
|
|
||||||
disableSortBy: true,
|
disableSortBy: true,
|
||||||
width: 130,
|
width: 130,
|
||||||
className: 'item',
|
className: 'item',
|
||||||
@@ -145,10 +111,9 @@ export function useEditableItemsEntriesColumns({
|
|||||||
Header: intl.get('quantity'),
|
Header: intl.get('quantity'),
|
||||||
accessor: 'quantity',
|
accessor: 'quantity',
|
||||||
Cell: NumericInputCell,
|
Cell: NumericInputCell,
|
||||||
Footer: QuantityTotalFooterCell,
|
|
||||||
disableSortBy: true,
|
disableSortBy: true,
|
||||||
width: 70,
|
width: 70,
|
||||||
className: 'quantity',
|
align: Align.Right,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Header: intl.get('rate'),
|
Header: intl.get('rate'),
|
||||||
@@ -156,7 +121,7 @@ export function useEditableItemsEntriesColumns({
|
|||||||
Cell: MoneyFieldCell,
|
Cell: MoneyFieldCell,
|
||||||
disableSortBy: true,
|
disableSortBy: true,
|
||||||
width: 70,
|
width: 70,
|
||||||
className: 'rate',
|
align: Align.Right,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Header: intl.get('discount'),
|
Header: intl.get('discount'),
|
||||||
@@ -164,16 +129,15 @@ export function useEditableItemsEntriesColumns({
|
|||||||
Cell: PercentFieldCell,
|
Cell: PercentFieldCell,
|
||||||
disableSortBy: true,
|
disableSortBy: true,
|
||||||
width: 60,
|
width: 60,
|
||||||
className: 'discount',
|
align: Align.Right,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Header: intl.get('total'),
|
Header: intl.get('total'),
|
||||||
Footer: TotalFooterCell,
|
|
||||||
accessor: 'amount',
|
accessor: 'amount',
|
||||||
Cell: TotalCell,
|
Cell: TotalCell,
|
||||||
disableSortBy: true,
|
disableSortBy: true,
|
||||||
width: 100,
|
width: 100,
|
||||||
className: 'total',
|
align: Align.Right,
|
||||||
},
|
},
|
||||||
...(landedCost
|
...(landedCost
|
||||||
? [
|
? [
|
||||||
@@ -193,7 +157,6 @@ export function useEditableItemsEntriesColumns({
|
|||||||
Header: '',
|
Header: '',
|
||||||
accessor: 'action',
|
accessor: 'action',
|
||||||
Cell: ActionsCellRenderer,
|
Cell: ActionsCellRenderer,
|
||||||
className: 'actions',
|
|
||||||
disableSortBy: true,
|
disableSortBy: true,
|
||||||
disableResizing: true,
|
disableResizing: true,
|
||||||
width: 45,
|
width: 45,
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
import { useFormikContext } from 'formik';
|
||||||
|
|
||||||
import { BaseCurrency, BaseCurrencyRoot } from 'components';
|
import { BaseCurrency, BaseCurrencyRoot } from 'components';
|
||||||
import { useInvoiceFormContext } from './InvoiceFormProvider';
|
import { useInvoiceFormContext } from './InvoiceFormProvider';
|
||||||
|
|
||||||
@@ -6,15 +8,17 @@ import { useInvoiceFormContext } from './InvoiceFormProvider';
|
|||||||
* Invoice form currency tag.
|
* Invoice form currency tag.
|
||||||
*/
|
*/
|
||||||
export default function InvoiceFormCurrencyTag() {
|
export default function InvoiceFormCurrencyTag() {
|
||||||
const { isForeignCustomer, selectCustomer } = useInvoiceFormContext();
|
const { isForeignCustomer } = useInvoiceFormContext();
|
||||||
|
const {
|
||||||
|
values: { currency_code },
|
||||||
|
} = useFormikContext();
|
||||||
|
|
||||||
if (!isForeignCustomer) {
|
if (!isForeignCustomer) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<BaseCurrencyRoot>
|
<BaseCurrencyRoot>
|
||||||
<BaseCurrency currency={selectCustomer?.currency_code} />
|
<BaseCurrency currency={currency_code} />
|
||||||
</BaseCurrencyRoot>
|
</BaseCurrencyRoot>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import React, { createContext, useState } from 'react';
|
import React, { createContext, useState } from 'react';
|
||||||
import { isEmpty, pick, isEqual, isUndefined } from 'lodash';
|
import { isEmpty, pick } from 'lodash';
|
||||||
import { useLocation } from 'react-router-dom';
|
import { useLocation } from 'react-router-dom';
|
||||||
import { Features } from 'common';
|
import { Features } from 'common';
|
||||||
import { useFeatureCan } from 'hooks/state';
|
import { useFeatureCan } from 'hooks/state';
|
||||||
@@ -94,9 +94,7 @@ function InvoiceFormProvider({ invoiceId, baseCurrency, ...props }) {
|
|||||||
const isFeatureLoading = isWarehouesLoading || isBranchesLoading;
|
const isFeatureLoading = isWarehouesLoading || isBranchesLoading;
|
||||||
|
|
||||||
// Determines whether the foreign customer.
|
// Determines whether the foreign customer.
|
||||||
const isForeignCustomer =
|
const isForeignCustomer = true;
|
||||||
!isEqual(selectCustomer?.currency_code, baseCurrency) &&
|
|
||||||
!isUndefined(selectCustomer?.currency_code);
|
|
||||||
|
|
||||||
const provider = {
|
const provider = {
|
||||||
invoice,
|
invoice,
|
||||||
|
|||||||
Reference in New Issue
Block a user