mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-17 21:30:31 +00:00
BIG-50: fix format number in financial reports.
This commit is contained in:
@@ -20,6 +20,9 @@ import withBalanceSheet from './withBalanceSheet';
|
||||
import withBalanceSheetActions from './withBalanceSheetActions';
|
||||
import { useBalanceSheetContext } from './BalanceSheetProvider';
|
||||
|
||||
/**
|
||||
* Balance sheet - actions bar.
|
||||
*/
|
||||
function BalanceSheetActionsBar({
|
||||
// #withBalanceSheet
|
||||
balanceSheetDrawerFilter,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { omit } from 'lodash';
|
||||
import { transfromToSnakeCase, flatObject } from 'utils';
|
||||
import * as R from 'ramda';
|
||||
import intl from 'react-intl-universal';
|
||||
import { transfromToSnakeCase, flatten } from 'utils';
|
||||
|
||||
export const displayColumnsByOptions = [
|
||||
{ key: 'total', name: intl.get('total'), type: 'total', by: '' },
|
||||
@@ -65,22 +65,46 @@ export const filterAccountsOptions = [
|
||||
},
|
||||
];
|
||||
|
||||
/**
|
||||
* Associate display columns by and type properties to query object.
|
||||
*/
|
||||
export const transformDisplayColumnsType = (form) => {
|
||||
const columnType = displayColumnsByOptions.find(
|
||||
(o) => o.key === form.displayColumnsType,
|
||||
);
|
||||
return {
|
||||
...form,
|
||||
displayColumnsBy: columnType ? columnType.by : '',
|
||||
displayColumnsType: columnType ? columnType.type : 'total',
|
||||
};
|
||||
};
|
||||
|
||||
export const transformFilterFormToQuery = (form) => {
|
||||
const transformed = transfromToSnakeCase({
|
||||
...omit(form, ['accountsFilter']),
|
||||
...transformDisplayColumnsType(form),
|
||||
/**
|
||||
* Associate none zero and none transaction property to query.
|
||||
*/
|
||||
const setNoneZeroTransactions = (form) => {
|
||||
return {
|
||||
...form,
|
||||
noneZero: form.accountsFilter === 'without-zero-balance',
|
||||
noneTransactions: form.accountsFilter === 'with-transactions',
|
||||
});
|
||||
return transformed;
|
||||
};
|
||||
}
|
||||
|
||||
export const transformAccountsFilter = (form) => {
|
||||
return R.compose(
|
||||
R.omit(['accountsFilter']),
|
||||
setNoneZeroTransactions,
|
||||
)(form)
|
||||
}
|
||||
|
||||
/**
|
||||
* Transform filter form to http query.
|
||||
*/
|
||||
export const transformFilterFormToQuery = (form) => {
|
||||
return R.compose(
|
||||
flatten,
|
||||
transfromToSnakeCase,
|
||||
transformAccountsFilter,
|
||||
transformDisplayColumnsType,
|
||||
)(form);
|
||||
};
|
||||
|
||||
@@ -174,7 +174,7 @@ export function formattedAmount(cents, currencyCode = '', props) {
|
||||
const parsedCurrency = {
|
||||
symbol: '',
|
||||
decimal_digits: 0,
|
||||
...currency
|
||||
...currency,
|
||||
};
|
||||
const parsedProps = {
|
||||
noZero: false,
|
||||
@@ -838,3 +838,56 @@ export function highlightText(text, query) {
|
||||
}
|
||||
return tokens;
|
||||
}
|
||||
|
||||
function isBuffer(obj) {
|
||||
return (
|
||||
obj &&
|
||||
obj.constructor &&
|
||||
typeof obj.constructor.isBuffer === 'function' &&
|
||||
obj.constructor.isBuffer(obj)
|
||||
);
|
||||
}
|
||||
|
||||
function keyIdentity(key) {
|
||||
return key;
|
||||
}
|
||||
|
||||
export function flatten(target, opts) {
|
||||
opts = opts || {};
|
||||
|
||||
const delimiter = opts.delimiter || '.';
|
||||
const maxDepth = opts.maxDepth;
|
||||
const transformKey = opts.transformKey || keyIdentity;
|
||||
const output = {};
|
||||
|
||||
function step(object, prev, currentDepth) {
|
||||
currentDepth = currentDepth || 1;
|
||||
Object.keys(object).forEach(function (key) {
|
||||
const value = object[key];
|
||||
const isarray = opts.safe && Array.isArray(value);
|
||||
const type = Object.prototype.toString.call(value);
|
||||
const isbuffer = isBuffer(value);
|
||||
const isobject = type === '[object Object]' || type === '[object Array]';
|
||||
|
||||
const newKey = prev
|
||||
? prev + delimiter + transformKey(key)
|
||||
: transformKey(key);
|
||||
|
||||
if (
|
||||
!isarray &&
|
||||
!isbuffer &&
|
||||
isobject &&
|
||||
Object.keys(value).length &&
|
||||
(!opts.maxDepth || currentDepth < maxDepth)
|
||||
) {
|
||||
return step(value, newKey, currentDepth + 1);
|
||||
}
|
||||
|
||||
output[newKey] = value;
|
||||
});
|
||||
}
|
||||
|
||||
step(target);
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user