WIP Financial statements.

This commit is contained in:
Ahmed Bouhuolia
2020-04-03 01:17:17 +02:00
parent cf5f56ae32
commit 4227f2f9a8
40 changed files with 1750 additions and 761 deletions

View File

@@ -48,10 +48,20 @@ export const fetchTrialBalanceSheet = ({ query }) => {
export const fetchProfitLossSheet = ({ query }) => {
return (dispatch) => new Promise((resolve, reject) => {
ApiService.get('/financial_statements/profit_loss_sheet', { params: query }).then((response) => {
dispatch({
type: t.PROFIT_LOSS_SHEET_LOADING,
loading: false,
});
ApiService.get('/financial_statements/profit_loss_sheet').then((response) => {
dispatch({
type: t.PROFIT_LOSS_STATEMENT_SET,
data: response.data,
type: t.PROFIT_LOSS_SHEET_SET,
profitLoss: response.data.profitLoss,
columns: response.data.columns,
query: response.data.query,
});
dispatch({
type: t.PROFIT_LOSS_SHEET_LOADING,
loading: false,
});
resolve(response.data);
}).catch((error) => { reject(error); });
@@ -60,12 +70,20 @@ export const fetchProfitLossSheet = ({ query }) => {
export const fetchJournalSheet = ({ query }) => {
return (dispatch) => new Promise((resolve, reject) => {
dispatch({
type: t.JOURNAL_SHEET_LOADING,
loading: true,
});
ApiService.get('/financial_statements/journal', { params: query }).then((response) => {
dispatch({
type: t.JOURNAL_SHEET_SET,
data: response.data,
query: response.data.query,
});
dispatch({
type: t.JOURNAL_SHEET_LOADING,
loading: false,
});
resolve(response.data);
}).catch(error => { reject(error); });
});

View File

@@ -5,6 +5,7 @@ import {
getFinancialSheetIndexByQuery,
// getFinancialSheetIndexByQuery,
} from './financialStatements.selectors';
import {omit} from 'lodash';
const initialState = {
balanceSheets: [],
@@ -12,10 +13,65 @@ const initialState = {
sheets: [],
loading: false,
},
generalLedger: [],
journalSheets: [],
generalLedger: {
sheets: [],
loading: false,
},
journal: {
sheets: [],
loading: false,
tableRows: [],
},
profitLoss: {
sheets: [],
loading: false,
tableRows: [],
}
};
const mapGeneralLedgerAccountsToRows = (accounts) => {
return accounts.reduce((tableRows, account) => {
const children = [];
children.push({
...account.opening, rowType: 'opening_balance',
});
account.transactions.map((transaction) => {
children.push({
...transaction, ...omit(account, ['transactions']),
rowType: 'transaction'
});
});
children.push({
...account.closing, rowType: 'closing_balance',
});
tableRows.push({
...omit(account, ['transactions']), children,
rowType: 'account_name',
});
return tableRows;
}, []);
}
const mapJournalTableRows = (journal) => {
return journal.reduce((rows, journal) => {
journal.entries.forEach((entry, index) => {
rows.push({
...entry,
rowType: (index === 0) ? 'first_entry' : 'entry'
});
});
rows.push({
credit: journal.credit,
debit: journal.debit,
rowType: 'entries_total',
});
rows.push({
rowType: 'space_entry',
});
return rows;
}, []);
}
export default createReducer(initialState, {
[t.BALANCE_SHEET_STATEMENT_SET]: (state, action) => {
const index = getBalanceSheetIndexByQuery(state.balanceSheets, action.query);
@@ -50,17 +106,55 @@ export default createReducer(initialState, {
},
[t.JOURNAL_SHEET_SET]: (state, action) => {
const index = getFinancialSheetIndexByQuery(state.journalSheets, action.query);
console.log(index, 'INDEX');
const index = getFinancialSheetIndexByQuery(state.journal.sheets, action.query);
const journal = {
query: action.data.query,
journal: action.data.journal,
tableRows: mapJournalTableRows(action.data.journal),
};
if (index !== -1) {
state.journalSheets[index] = journal;
state.journal.sheets[index] = journal;
} else {
state.journalSheets.push(journal);
state.journal.sheets.push(journal);
}
}
},
[t.JOURNAL_SHEET_LOADING]: (state, action) => {
state.journal.loading = !!action.loading;
},
[t.GENERAL_LEDGER_STATEMENT_SET]: (state, action) => {
const index = getFinancialSheetIndexByQuery(state.generalLedger.sheets, action.query);
const generalLedger = {
query: action.data.query,
accounts: action.data.accounts,
tableRows: mapGeneralLedgerAccountsToRows(action.data.accounts),
};
if (index !== -1) {
state.generalLedger.sheets[index] = generalLedger;
} else {
state.generalLedger.sheets.push(generalLedger);
}
},
[t.PROFIT_LOSS_SHEET_SET]: (state, action) => {
const index = getFinancialSheetIndexByQuery(state.profitLoss.sheets, action.query);
const profitLossSheet = {
query: action.query,
profitLoss: action.profitLoss,
columns: action.columns,
};
if (index !== -1) {
state.profitLoss.sheets[index] = profitLossSheet;
} else {
state.profitLoss.sheets.push(profitLossSheet);
}
},
[t.PROFIT_LOSS_SHEET_LOADING]: (state, action) => {
state.profitLoss.loading = !!action.loading;
},
});

View File

@@ -6,4 +6,8 @@ export default {
TRAIL_BALANCE_STATEMENT_SET: 'TRAIL_BALANCE_STATEMENT_SET',
TRIAL_BALANCE_SHEET_LOADING: 'TRIAL_BALANCE_SHEET_LOADING',
JOURNAL_SHEET_SET: 'JOURNAL_SHEET_SET',
JOURNAL_SHEET_LOADING: 'JOURNAL_SHEET_LOADING',
PROFIT_LOSS_SHEET_SET: 'PROFIT_LOSS_SHEET_SET',
PROFIT_LOSS_SHEET_LOADING: 'PROFIT_LOSS_SHEET_LOADING',
}

View File

@@ -11,6 +11,7 @@ import resources from './resources/resource.types';
import users from './users/users.types';
import financialStatements from './financialStatement/financialStatements.types';
import itemCategories from './itemCategories/itemsCategory.type';
export default {
...authentication,
...accounts,