mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-15 20:30:33 +00:00
feat: Inventory item details report.
feat: Cash flow statement report.
This commit is contained in:
52
server/src/utils/deepdash.ts
Normal file
52
server/src/utils/deepdash.ts
Normal file
@@ -0,0 +1,52 @@
|
||||
import _ from 'lodash';
|
||||
import deepdash from 'deepdash';
|
||||
|
||||
const {
|
||||
condense,
|
||||
condenseDeep,
|
||||
eachDeep,
|
||||
exists,
|
||||
filterDeep,
|
||||
findDeep,
|
||||
findPathDeep,
|
||||
findValueDeep,
|
||||
forEachDeep,
|
||||
index,
|
||||
keysDeep,
|
||||
mapDeep,
|
||||
mapKeysDeep,
|
||||
mapValuesDeep,
|
||||
omitDeep,
|
||||
pathMatches,
|
||||
pathToString,
|
||||
paths,
|
||||
pickDeep,
|
||||
reduceDeep,
|
||||
someDeep,
|
||||
iteratee,
|
||||
} = deepdash(_);
|
||||
|
||||
export {
|
||||
iteratee,
|
||||
condense,
|
||||
condenseDeep,
|
||||
eachDeep,
|
||||
exists,
|
||||
filterDeep,
|
||||
findDeep,
|
||||
findPathDeep,
|
||||
findValueDeep,
|
||||
forEachDeep,
|
||||
index,
|
||||
keysDeep,
|
||||
mapDeep,
|
||||
mapKeysDeep,
|
||||
mapValuesDeep,
|
||||
omitDeep,
|
||||
pathMatches,
|
||||
pathToString,
|
||||
paths,
|
||||
pickDeep,
|
||||
reduceDeep,
|
||||
someDeep,
|
||||
};
|
||||
@@ -51,6 +51,30 @@ const dateRangeCollection = (
|
||||
return collection;
|
||||
};
|
||||
|
||||
const dateRangeFromToCollection = (
|
||||
fromDate,
|
||||
toDate,
|
||||
addType = 'day',
|
||||
increment = 1
|
||||
) => {
|
||||
const collection = [];
|
||||
const momentFromDate = moment(fromDate);
|
||||
const dateFormat = 'YYYY-MM-DD';
|
||||
|
||||
for (
|
||||
let i = momentFromDate;
|
||||
i.isBefore(toDate, addType) || i.isSame(toDate, addType);
|
||||
i.add(increment, `${addType}s`)
|
||||
) {
|
||||
collection.push({
|
||||
fromDate: i.startOf(addType).format(dateFormat),
|
||||
toDate: i.endOf(addType).format(dateFormat),
|
||||
});
|
||||
}
|
||||
return collection;
|
||||
};
|
||||
|
||||
|
||||
const dateRangeFormat = (rangeType) => {
|
||||
switch (rangeType) {
|
||||
case 'year':
|
||||
@@ -329,8 +353,28 @@ var increment = (n) => {
|
||||
};
|
||||
};
|
||||
|
||||
const transformToMapBy = (collection, key) => {
|
||||
return new Map(
|
||||
Object.entries(_.groupBy(collection, key)),
|
||||
);
|
||||
}
|
||||
|
||||
const transformToMapKeyValue = (collection, key) => {
|
||||
return new Map(
|
||||
collection.map((item) => [item[key], item]),
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
const accumSum = (data, callback) => {
|
||||
return data.reduce((acc, _data) => {
|
||||
const amount = callback(_data);
|
||||
return acc + amount;
|
||||
}, 0)
|
||||
}
|
||||
|
||||
export {
|
||||
accumSum,
|
||||
increment,
|
||||
hashPassword,
|
||||
origin,
|
||||
@@ -354,4 +398,7 @@ export {
|
||||
defaultToTransform,
|
||||
transformToMap,
|
||||
transactionIncrement,
|
||||
transformToMapBy,
|
||||
dateRangeFromToCollection,
|
||||
transformToMapKeyValue
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user