mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-18 13:50:31 +00:00
WIP
This commit is contained in:
@@ -19,8 +19,33 @@ export const fetchBalanceSheet = ({ query }) => {
|
||||
dispatch({
|
||||
type: t.BALANCE_SHEET_STATEMENT_SET,
|
||||
data: response.data,
|
||||
query: query,
|
||||
});
|
||||
resolve(response);
|
||||
}).catch((error) => { reject(error); });
|
||||
});
|
||||
};
|
||||
|
||||
export const fetchTrialBalanceSheet = ({ query }) => {
|
||||
return (dispatch) => new Promise((resolve, reject) => {
|
||||
ApiService.get('/financial_statements/trial_balance_sheet').then((response) => {
|
||||
dispatch({
|
||||
type: t.TRAIL_BALANCE_STATEMENT_SET,
|
||||
data: response.data,
|
||||
});
|
||||
resolve(response.data);
|
||||
}).catch((error) => { reject(error); })
|
||||
})
|
||||
};
|
||||
|
||||
export const fetchProfitLossSheet = ({ query }) => {
|
||||
return (dispatch) => new Promise((resolve, reject) => {
|
||||
ApiService.get('/financial_statements/profit_loss_sheet').then((response) => {
|
||||
dispatch({
|
||||
type: t.PROFIT_LOSS_STATEMENT_SET,
|
||||
data: response.data,
|
||||
});
|
||||
resolve(response.data);
|
||||
}).catch((error) => { reject(error); });
|
||||
})
|
||||
};
|
||||
@@ -1,14 +1,41 @@
|
||||
import { createReducer } from '@reduxjs/toolkit';
|
||||
import t from 'store/types';
|
||||
import {getBalanceSheetIndexByQuery, getTrialBalanceSheetIndex} from './financialStatements.selectors';
|
||||
import { actionComplete } from '@syncfusion/ej2-react-grids';
|
||||
|
||||
const initialState = {
|
||||
balanceSheet: [],
|
||||
balanceSheets: [],
|
||||
trialBalanceSheets: [],
|
||||
generalLedger: [],
|
||||
trialBalance: [],
|
||||
};
|
||||
|
||||
export default createReducer(initialState, {
|
||||
[t.BALANCE_SHEET_STATEMENT_SET]: (state, action) => {
|
||||
state.balanceSheet.push(action.data);
|
||||
const index = getBalanceSheetIndexByQuery(state.balanceSheets, action.query);
|
||||
|
||||
const balanceSheet = {
|
||||
balances: action.data.balance_sheet,
|
||||
columns: Object.values(action.data.columns),
|
||||
query: action.data.query,
|
||||
};
|
||||
if (index !== -1) {
|
||||
state.balanceSheets[index] = balanceSheet;
|
||||
} else {
|
||||
state.balanceSheets.push(balanceSheet);
|
||||
}
|
||||
},
|
||||
|
||||
[t.TRAIL_BALANCE_STATEMENT_SET]: (state, action) => {
|
||||
const index = getTrialBalanceSheetIndex(state.trialBalanceSheets, action.query);
|
||||
|
||||
const trailBalanceSheet = {
|
||||
accounts: action.data.accounts,
|
||||
query: action.data.query,
|
||||
};
|
||||
if (index !== -1) {
|
||||
state.trialBalanceSheets[index] = trailBalanceSheet;
|
||||
} else {
|
||||
state.trailBalanceSheet.push(trailBalanceSheet);
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,91 @@
|
||||
import {getObjectDiff} from 'utils';
|
||||
|
||||
|
||||
// Balance Sheet.
|
||||
export const getBalanceSheetByQuery = (balanceSheets, query) => {
|
||||
return balanceSheets.find(balanceSheet => {
|
||||
return getObjectDiff(query, balanceSheet.query).length === 0;
|
||||
});
|
||||
};
|
||||
|
||||
export const getBalanceSheetIndexByQuery = (balanceSheets, query) => {
|
||||
return balanceSheets.findIndex((balanceSheet) => {
|
||||
return getObjectDiff(query, balanceSheet.query).length === 0;
|
||||
});
|
||||
};
|
||||
|
||||
export const getBalanceSheetByIndex = (balanceSheets, sheetIndex) => {
|
||||
return balanceSheets[sheetIndex];
|
||||
};
|
||||
|
||||
export const getBalanceSheetQuery = (balanceSheets, sheetIndex) => {
|
||||
if (typeof balanceSheets[sheetIndex] === 'object') {
|
||||
return balanceSheets[sheetIndex].query || {};
|
||||
}
|
||||
return {};
|
||||
};
|
||||
|
||||
export const getBalanceSheetAssetsAccounts = (balanceSheets, sheetIndex) => {
|
||||
if (typeof balanceSheets[sheetIndex] === 'object') {
|
||||
return balanceSheets[sheetIndex].balances.assets.accounts || [];
|
||||
}
|
||||
return [];
|
||||
};
|
||||
|
||||
export const getBalanceSheetLiabilitiesAccounts = (balanceSheets, sheetIndex) => {
|
||||
if (typeof balanceSheets[sheetIndex] === 'object') {
|
||||
return balanceSheets[sheetIndex].balances.liabilities_equity.accounts || [];
|
||||
}
|
||||
return [];
|
||||
};
|
||||
|
||||
export const getBalanceSheetColumns = (balanceSheets, sheetIndex) => {
|
||||
if (typeof balanceSheets[sheetIndex] === 'object') {
|
||||
return balanceSheets[sheetIndex].columns;
|
||||
}
|
||||
return [];
|
||||
};
|
||||
|
||||
|
||||
// Trial Balance Sheet.
|
||||
export const getTrialBalanceSheetIndex = (trialBalanceSheets, query) => {
|
||||
return trialBalanceSheets.find((trialBalanceSheet) => {
|
||||
return getObjectDiff(query, trialBalanceSheet.query).length === 0;
|
||||
});
|
||||
};
|
||||
|
||||
export const getTrialBalanceAccounts = (trialBalanceSheets, sheetIndex) => {
|
||||
if (typeof trialBalanceSheets[sheetIndex] === 'object') {
|
||||
return trialBalanceSheets[sheetIndex].accounts;
|
||||
}
|
||||
return [];
|
||||
};
|
||||
|
||||
export const getTrialBalanceQuery = (trialBalanceSheets, sheetIndex) => {
|
||||
if (typeof trialBalanceSheets[sheetIndex] === 'object') {
|
||||
return trialBalanceSheets[sheetIndex].query;
|
||||
}
|
||||
return [];
|
||||
};
|
||||
|
||||
// Profit/Loss Sheet selectors.
|
||||
export const getProfitLossSheetIndex = (profitLossSheets, query) => {
|
||||
return profitLossSheets.find((profitLossSheet) => {
|
||||
return getObjectDiff(query, profitLossSheet.query).length === 0;
|
||||
});
|
||||
}
|
||||
|
||||
export const getProfitLossSheet = (profitLossSheets, index) => {
|
||||
return (typeof profitLossSheets[index] !== 'undefined') ?
|
||||
profitLossSheets[index] : null;
|
||||
};
|
||||
|
||||
export const getProfitLossSheetColumns = (profitLossSheets, index) => {
|
||||
const sheet = getProfitLossSheet(profitLossSheets, index);
|
||||
return (sheet) ? sheet.columns : [];
|
||||
};
|
||||
|
||||
export const getProfitLossSheetAccounts = (profitLossSheets, index) => {
|
||||
const sheet = getProfitLossSheet(profitLossSheets, index);
|
||||
return (sheet) ? sheet.accounts : [];
|
||||
};
|
||||
@@ -3,4 +3,5 @@
|
||||
export default {
|
||||
GENERAL_LEDGER_STATEMENT_SET: 'GENERAL_LEDGER_STATEMENT_SET',
|
||||
BALANCE_SHEET_STATEMENT_SET: 'BALANCE_SHEET_STATEMENT_SET',
|
||||
TRAIL_BALANCE_STATEMENT_SET: 'TRAIL_BALANCE_STATEMENT_SET',
|
||||
}
|
||||
Reference in New Issue
Block a user