WIP financial statements.

This commit is contained in:
Ahmed Bouhuolia
2020-03-31 16:30:38 +02:00
parent da05239e84
commit 1bf837ae17
26 changed files with 442 additions and 148 deletions

View File

@@ -28,11 +28,19 @@ export const fetchBalanceSheet = ({ query }) => {
export const fetchTrialBalanceSheet = ({ query }) => {
return (dispatch) => new Promise((resolve, reject) => {
dispatch({
type: t.TRIAL_BALANCE_SHEET_LOADING,
loading: true,
});
ApiService.get('/financial_statements/trial_balance_sheet', { params: query }).then((response) => {
dispatch({
type: t.TRAIL_BALANCE_STATEMENT_SET,
data: response.data,
});
dispatch({
type: t.TRIAL_BALANCE_SHEET_LOADING,
loading: false,
});
resolve(response.data);
}).catch((error) => { reject(error); })
})

View File

@@ -2,13 +2,16 @@ import { createReducer } from '@reduxjs/toolkit';
import t from 'store/types';
import {
getBalanceSheetIndexByQuery,
getTrialBalanceSheetIndex,
getFinancialSheetIndexByQuery,
// getFinancialSheetIndexByQuery,
} from './financialStatements.selectors';
const initialState = {
balanceSheets: [],
trialBalanceSheets: [],
trialBalance: {
sheets: [],
loading: false,
},
generalLedger: [],
journalSheets: [],
};
@@ -30,19 +33,22 @@ export default createReducer(initialState, {
},
[t.TRAIL_BALANCE_STATEMENT_SET]: (state, action) => {
const index = getTrialBalanceSheetIndex(state.trialBalanceSheets, action.query);
const index = getFinancialSheetIndexByQuery(state.trialBalance.sheets, action.query);
const trailBalanceSheet = {
accounts: action.data.accounts,
query: action.data.query,
};
if (index !== -1) {
state.trialBalanceSheets[index] = trailBalanceSheet;
state.trialBalance.sheets[index] = trailBalanceSheet;
} else {
state.trailBalanceSheet.push(trailBalanceSheet);
state.trialBalance.sheets.push(trailBalanceSheet);
}
},
[t.TRIAL_BALANCE_SHEET_LOADING]: (state, action) => {
state.trialBalance.loading = !!action.loading;
},
[t.JOURNAL_SHEET_SET]: (state, action) => {
const index = getFinancialSheetIndexByQuery(state.journalSheets, action.query);
console.log(index, 'INDEX');

View File

@@ -4,5 +4,6 @@ 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',
TRIAL_BALANCE_SHEET_LOADING: 'TRIAL_BALANCE_SHEET_LOADING',
JOURNAL_SHEET_SET: 'JOURNAL_SHEET_SET',
}