mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-16 04:40:32 +00:00
feat: Receivable aging summary front-end.
This commit is contained in:
@@ -1,18 +1,25 @@
|
||||
import bcrypt from 'bcryptjs';
|
||||
import moment from 'moment';
|
||||
import _ from 'lodash';
|
||||
const { map, isArray, isPlainObject, mapKeys, mapValues } = require('lodash')
|
||||
const { map, isArray, isPlainObject, mapKeys, mapValues } = require('lodash');
|
||||
|
||||
|
||||
const hashPassword = (password) => new Promise((resolve) => {
|
||||
bcrypt.genSalt(10, (error, salt) => {
|
||||
bcrypt.hash(password, salt, (err, hash) => { resolve(hash); });
|
||||
const hashPassword = (password) =>
|
||||
new Promise((resolve) => {
|
||||
bcrypt.genSalt(10, (error, salt) => {
|
||||
bcrypt.hash(password, salt, (err, hash) => {
|
||||
resolve(hash);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
const origin = (request) => `${request.protocol}://${request.hostname}`;
|
||||
|
||||
const dateRangeCollection = (fromDate, toDate, addType = 'day', increment = 1) => {
|
||||
const dateRangeCollection = (
|
||||
fromDate,
|
||||
toDate,
|
||||
addType = 'day',
|
||||
increment = 1
|
||||
) => {
|
||||
const collection = [];
|
||||
const momentFromDate = moment(fromDate);
|
||||
let dateFormat = '';
|
||||
@@ -20,16 +27,21 @@ const dateRangeCollection = (fromDate, toDate, addType = 'day', increment = 1) =
|
||||
switch (addType) {
|
||||
case 'day':
|
||||
default:
|
||||
dateFormat = 'YYYY-MM-DD'; break;
|
||||
dateFormat = 'YYYY-MM-DD';
|
||||
break;
|
||||
case 'month':
|
||||
case 'quarter':
|
||||
dateFormat = 'YYYY-MM'; break;
|
||||
dateFormat = 'YYYY-MM';
|
||||
break;
|
||||
case 'year':
|
||||
dateFormat = 'YYYY'; break;
|
||||
dateFormat = 'YYYY';
|
||||
break;
|
||||
}
|
||||
for (let i = momentFromDate;
|
||||
(i.isBefore(toDate, addType) || i.isSame(toDate, addType));
|
||||
i.add(increment, `${addType}s`)) {
|
||||
for (
|
||||
let i = momentFromDate;
|
||||
i.isBefore(toDate, addType) || i.isSame(toDate, addType);
|
||||
i.add(increment, `${addType}s`)
|
||||
) {
|
||||
collection.push(i.endOf(addType).format(dateFormat));
|
||||
}
|
||||
return collection;
|
||||
@@ -46,55 +58,69 @@ const dateRangeFormat = (rangeType) => {
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
const mapKeysDeep = (obj, cb) => {
|
||||
if (_.isArray(obj)) {
|
||||
return obj.map(innerObj => mapKeysDeep(innerObj, cb));
|
||||
function mapKeysDeep(obj, cb, isRecursive) {
|
||||
if (!obj && !isRecursive) {
|
||||
return {};
|
||||
}
|
||||
else if (_.isObject(obj)) {
|
||||
return _.mapValues(
|
||||
_.mapKeys(obj, cb),
|
||||
val => mapKeysDeep(val, cb),
|
||||
)
|
||||
} else {
|
||||
return obj;
|
||||
if (!isRecursive) {
|
||||
if (
|
||||
typeof obj === 'string' ||
|
||||
typeof obj === 'number' ||
|
||||
typeof obj === 'boolean'
|
||||
) {
|
||||
return {};
|
||||
}
|
||||
}
|
||||
if (Array.isArray(obj)) {
|
||||
return obj.map((item) => mapKeysDeep(item, cb, true));
|
||||
}
|
||||
if (!_.isPlainObject(obj)) {
|
||||
return obj;
|
||||
}
|
||||
const result = _.mapKeys(obj, cb);
|
||||
return _.mapValues(result, (value) => mapKeysDeep(value, cb, true));
|
||||
}
|
||||
|
||||
const mapValuesDeep = (v, callback) => (
|
||||
const mapValuesDeep = (v, callback) =>
|
||||
_.isObject(v)
|
||||
? _.mapValues(v, v => mapValuesDeep(v, callback))
|
||||
: callback(v));
|
||||
|
||||
? _.mapValues(v, (v) => mapValuesDeep(v, callback))
|
||||
: callback(v);
|
||||
|
||||
const promiseSerial = (funcs) => {
|
||||
return funcs.reduce((promise, func) => promise.then((result) => func().then(Array.prototype.concat.bind(result))),
|
||||
Promise.resolve([]));
|
||||
}
|
||||
return funcs.reduce(
|
||||
(promise, func) =>
|
||||
promise.then((result) =>
|
||||
func().then(Array.prototype.concat.bind(result))
|
||||
),
|
||||
Promise.resolve([])
|
||||
);
|
||||
};
|
||||
|
||||
const flatToNestedArray = (data, config = { id: 'id', parentId: 'parent_id' }) => {
|
||||
const flatToNestedArray = (
|
||||
data,
|
||||
config = { id: 'id', parentId: 'parent_id' }
|
||||
) => {
|
||||
const map = {};
|
||||
const nestedArray = [];
|
||||
|
||||
|
||||
data.forEach((item) => {
|
||||
map[item[config.id]] = item;
|
||||
map[item[config.id]].children = [];
|
||||
});
|
||||
|
||||
|
||||
data.forEach((item) => {
|
||||
const parentItemId = item[config.parentId];
|
||||
|
||||
|
||||
if (!item[config.parentId]) {
|
||||
nestedArray.push(item);
|
||||
}
|
||||
if(parentItemId) {
|
||||
if (parentItemId) {
|
||||
map[parentItemId].children.push(item);
|
||||
}
|
||||
});
|
||||
|
||||
return nestedArray;
|
||||
}
|
||||
|
||||
return nestedArray;
|
||||
};
|
||||
|
||||
export {
|
||||
hashPassword,
|
||||
|
||||
Reference in New Issue
Block a user