mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-18 05:40:31 +00:00
feat: APAgingSummary.
This commit is contained in:
@@ -1,185 +1,266 @@
|
||||
import ApiService from "services/ApiService";
|
||||
import ApiService from 'services/ApiService';
|
||||
import t from 'store/types';
|
||||
|
||||
export const balanceSheetRefresh = (refresh) => {
|
||||
return dispatch => dispatch({
|
||||
type: 'BALANCE_SHEET_REFRESH',
|
||||
payload: { refresh },
|
||||
});
|
||||
return (dispatch) =>
|
||||
dispatch({
|
||||
type: 'BALANCE_SHEET_REFRESH',
|
||||
payload: { refresh },
|
||||
});
|
||||
};
|
||||
|
||||
export const fetchGeneralLedger = ({ query }) => {
|
||||
return (dispatch) => new Promise((resolve, reject) => {
|
||||
dispatch({
|
||||
type: t.GENERAL_LEDGER_SHEET_LOADING,
|
||||
loading: true,
|
||||
});
|
||||
ApiService.get('/financial_statements/general_ledger', { params: query }).then((response) => {
|
||||
dispatch({
|
||||
type: t.GENERAL_LEDGER_STATEMENT_SET,
|
||||
data: response.data,
|
||||
});
|
||||
return (dispatch) =>
|
||||
new Promise((resolve, reject) => {
|
||||
dispatch({
|
||||
type: t.GENERAL_LEDGER_SHEET_LOADING,
|
||||
loading: false,
|
||||
loading: true,
|
||||
});
|
||||
resolve(response);
|
||||
}).catch((error) => { reject(error); });
|
||||
});
|
||||
ApiService.get('/financial_statements/general_ledger', { params: query })
|
||||
.then((response) => {
|
||||
dispatch({
|
||||
type: t.GENERAL_LEDGER_STATEMENT_SET,
|
||||
data: response.data,
|
||||
});
|
||||
dispatch({
|
||||
type: t.GENERAL_LEDGER_SHEET_LOADING,
|
||||
loading: false,
|
||||
});
|
||||
resolve(response);
|
||||
})
|
||||
.catch((error) => {
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
export const refreshGeneralLedgerSheet = (refresh) => {
|
||||
return (dispatch) => dispatch({
|
||||
type: t.GENERAL_LEDGER_REFRESH,
|
||||
payload: { refresh },
|
||||
});
|
||||
return (dispatch) =>
|
||||
dispatch({
|
||||
type: t.GENERAL_LEDGER_REFRESH,
|
||||
payload: { refresh },
|
||||
});
|
||||
};
|
||||
|
||||
export const fetchBalanceSheet = ({ query }) => {
|
||||
return (dispatch) => new Promise((resolve, reject) => {
|
||||
dispatch({
|
||||
type: t.BALANCE_SHEET_LOADING,
|
||||
loading: true,
|
||||
});
|
||||
ApiService.get('/financial_statements/balance_sheet', { params: query }).then((response) => {
|
||||
dispatch({
|
||||
type: t.BALANCE_SHEET_STATEMENT_SET,
|
||||
data: response.data,
|
||||
query: query,
|
||||
});
|
||||
return (dispatch) =>
|
||||
new Promise((resolve, reject) => {
|
||||
dispatch({
|
||||
type: t.BALANCE_SHEET_LOADING,
|
||||
loading: false,
|
||||
loading: true,
|
||||
});
|
||||
dispatch({
|
||||
type: t.SET_DASHBOARD_REQUEST_COMPLETED,
|
||||
});
|
||||
resolve(response);
|
||||
}).catch((error) => { reject(error); });
|
||||
});
|
||||
ApiService.get('/financial_statements/balance_sheet', { params: query })
|
||||
.then((response) => {
|
||||
dispatch({
|
||||
type: t.BALANCE_SHEET_STATEMENT_SET,
|
||||
data: response.data,
|
||||
query: query,
|
||||
});
|
||||
dispatch({
|
||||
type: t.BALANCE_SHEET_LOADING,
|
||||
loading: false,
|
||||
});
|
||||
dispatch({
|
||||
type: t.SET_DASHBOARD_REQUEST_COMPLETED,
|
||||
});
|
||||
resolve(response);
|
||||
})
|
||||
.catch((error) => {
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
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,
|
||||
});
|
||||
return (dispatch) =>
|
||||
new Promise((resolve, reject) => {
|
||||
dispatch({
|
||||
type: t.TRIAL_BALANCE_SHEET_LOADING,
|
||||
loading: false,
|
||||
loading: true,
|
||||
});
|
||||
resolve(response.data);
|
||||
}).catch((error) => { reject(error); })
|
||||
})
|
||||
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);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
export const trialBalanceRefresh = (refresh) => {
|
||||
return (dispatch) => dispatch({
|
||||
type: t.TRIAL_BALANCE_REFRESH,
|
||||
payload: { refresh },
|
||||
});
|
||||
return (dispatch) =>
|
||||
dispatch({
|
||||
type: t.TRIAL_BALANCE_REFRESH,
|
||||
payload: { refresh },
|
||||
});
|
||||
};
|
||||
|
||||
export const fetchProfitLossSheet = ({ query }) => {
|
||||
return (dispatch) => new Promise((resolve, reject) => {
|
||||
dispatch({
|
||||
type: t.PROFIT_LOSS_SHEET_LOADING,
|
||||
loading: true,
|
||||
});
|
||||
ApiService.get('/financial_statements/profit_loss_sheet', { params: query }).then((response) => {
|
||||
dispatch({
|
||||
type: t.PROFIT_LOSS_SHEET_SET,
|
||||
profitLoss: response.data.data,
|
||||
columns: response.data.columns,
|
||||
query: response.data.query,
|
||||
});
|
||||
return (dispatch) =>
|
||||
new Promise((resolve, reject) => {
|
||||
dispatch({
|
||||
type: t.PROFIT_LOSS_SHEET_LOADING,
|
||||
loading: false,
|
||||
loading: true,
|
||||
});
|
||||
resolve(response.data);
|
||||
}).catch((error) => { reject(error); });
|
||||
})
|
||||
ApiService.get('/financial_statements/profit_loss_sheet', {
|
||||
params: query,
|
||||
})
|
||||
.then((response) => {
|
||||
dispatch({
|
||||
type: t.PROFIT_LOSS_SHEET_SET,
|
||||
profitLoss: response.data.data,
|
||||
columns: response.data.columns,
|
||||
query: response.data.query,
|
||||
});
|
||||
dispatch({
|
||||
type: t.PROFIT_LOSS_SHEET_LOADING,
|
||||
loading: false,
|
||||
});
|
||||
resolve(response.data);
|
||||
})
|
||||
.catch((error) => {
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
export const profitLossRefresh = (refresh) => {
|
||||
return dispatch => dispatch({
|
||||
type: t.PROFIT_LOSS_REFRESH,
|
||||
payload: { refresh },
|
||||
});
|
||||
}
|
||||
return (dispatch) =>
|
||||
dispatch({
|
||||
type: t.PROFIT_LOSS_REFRESH,
|
||||
payload: { refresh },
|
||||
});
|
||||
};
|
||||
|
||||
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,
|
||||
});
|
||||
return (dispatch) =>
|
||||
new Promise((resolve, reject) => {
|
||||
dispatch({
|
||||
type: t.JOURNAL_SHEET_LOADING,
|
||||
loading: false,
|
||||
loading: true,
|
||||
});
|
||||
resolve(response.data);
|
||||
}).catch(error => { reject(error); });
|
||||
});
|
||||
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);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
export const refreshJournalSheet = (refresh) => {
|
||||
return dispatch => dispatch({
|
||||
type: t.JOURNAL_SHEET_REFRESH,
|
||||
payload: { refresh },
|
||||
});
|
||||
}
|
||||
return (dispatch) =>
|
||||
dispatch({
|
||||
type: t.JOURNAL_SHEET_REFRESH,
|
||||
payload: { refresh },
|
||||
});
|
||||
};
|
||||
|
||||
export const fetchReceivableAgingSummary = ({ query }) => {
|
||||
return (dispatch) => new Promise((resolve, reject) => {
|
||||
dispatch({
|
||||
type: t.RECEIVABLE_AGING_SUMMARY_LOADING,
|
||||
payload: {
|
||||
loading: true,
|
||||
},
|
||||
});
|
||||
ApiService
|
||||
.get('/financial_statements/receivable_aging_summary', { params: query })
|
||||
.then((response) => {
|
||||
dispatch({
|
||||
type: t.RECEIVABLE_AGING_SUMMARY_SET,
|
||||
payload: {
|
||||
customers: response.data.data.customers,
|
||||
total: response.data.data.total,
|
||||
columns: response.data.columns,
|
||||
query,
|
||||
},
|
||||
});
|
||||
dispatch({
|
||||
type: t.RECEIVABLE_AGING_SUMMARY_LOADING,
|
||||
payload: {
|
||||
loading: false,
|
||||
},
|
||||
});
|
||||
resolve(response);
|
||||
})
|
||||
.catch((error) => {
|
||||
reject(error);
|
||||
return (dispatch) =>
|
||||
new Promise((resolve, reject) => {
|
||||
dispatch({
|
||||
type: t.RECEIVABLE_AGING_SUMMARY_LOADING,
|
||||
payload: {
|
||||
loading: true,
|
||||
},
|
||||
});
|
||||
});
|
||||
}
|
||||
ApiService.get('/financial_statements/receivable_aging_summary', {
|
||||
params: query,
|
||||
})
|
||||
.then((response) => {
|
||||
dispatch({
|
||||
type: t.RECEIVABLE_AGING_SUMMARY_SET,
|
||||
payload: {
|
||||
customers: response.data.data.customers,
|
||||
total: response.data.data.total,
|
||||
columns: response.data.columns,
|
||||
query,
|
||||
},
|
||||
});
|
||||
dispatch({
|
||||
type: t.RECEIVABLE_AGING_SUMMARY_LOADING,
|
||||
payload: {
|
||||
loading: false,
|
||||
},
|
||||
});
|
||||
resolve(response);
|
||||
})
|
||||
.catch((error) => {
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
export const receivableAgingSummaryRefresh = (refresh) => {
|
||||
return (dispatch) => dispatch({
|
||||
type: t.RECEIVABLE_AGING_SUMMARY_REFRESH,
|
||||
payload: { refresh },
|
||||
});
|
||||
}
|
||||
return (dispatch) =>
|
||||
dispatch({
|
||||
type: t.RECEIVABLE_AGING_SUMMARY_REFRESH,
|
||||
payload: { refresh },
|
||||
});
|
||||
};
|
||||
|
||||
export const fetchPayableAginSummary = ({ query }) => {
|
||||
return (dispatch) =>
|
||||
new Promise((resolve, reject) => {
|
||||
dispatch({
|
||||
type: t.PAYABLE_AGING_SUMMARY_LOADING,
|
||||
payload: {
|
||||
loading: true,
|
||||
},
|
||||
});
|
||||
ApiService.get('/financial_statements/payable_aging_summary', {
|
||||
params: query,
|
||||
})
|
||||
.then((response) => {
|
||||
dispatch({
|
||||
type: t.PAYABLE_AGING_SUMMARY_SET,
|
||||
payload: {
|
||||
vendors: response.data.data.vendors,
|
||||
total: response.data.data.total,
|
||||
columns: response.data.columns,
|
||||
query,
|
||||
},
|
||||
});
|
||||
dispatch({
|
||||
type: t.PAYABLE_AGING_SUMMARY_LOADING,
|
||||
payload: {
|
||||
loading: false,
|
||||
},
|
||||
});
|
||||
resolve(response);
|
||||
})
|
||||
.catch((error) => {
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
export const payableAgingSummaryRefresh = (refresh) => {
|
||||
return (dispatch) =>
|
||||
dispatch({
|
||||
type: t.PAYABLE_AGING_SUMMARY_REFRESH,
|
||||
payload: { refresh },
|
||||
});
|
||||
};
|
||||
|
||||
@@ -193,7 +193,7 @@ export const profitLossToTableRowsMapper = (profitLoss) => {
|
||||
total: profitLoss.gross_profit.total,
|
||||
total_periods: profitLoss.gross_profit.total_periods,
|
||||
rowTypes: ['gross_total', 'section_total', 'total'],
|
||||
})
|
||||
});
|
||||
}
|
||||
if (profitLoss.expenses) {
|
||||
results.push({
|
||||
@@ -209,7 +209,7 @@ export const profitLossToTableRowsMapper = (profitLoss) => {
|
||||
},
|
||||
],
|
||||
total_periods: profitLoss.expenses.total_periods,
|
||||
})
|
||||
});
|
||||
}
|
||||
if (profitLoss.operating_profit) {
|
||||
results.push({
|
||||
@@ -217,7 +217,7 @@ export const profitLossToTableRowsMapper = (profitLoss) => {
|
||||
total: profitLoss.operating_profit.total,
|
||||
total_periods: profitLoss.income.total_periods,
|
||||
rowTypes: ['net_operating_total', 'section_total', 'total'],
|
||||
})
|
||||
});
|
||||
}
|
||||
if (profitLoss.other_income) {
|
||||
results.push({
|
||||
@@ -257,7 +257,42 @@ export const profitLossToTableRowsMapper = (profitLoss) => {
|
||||
total: profitLoss.net_income.total,
|
||||
total_periods: profitLoss.net_income.total_periods,
|
||||
rowTypes: ['net_income_total', 'section_total', 'total'],
|
||||
})
|
||||
};
|
||||
});
|
||||
}
|
||||
return results;
|
||||
};
|
||||
|
||||
export const APAgingSummaryTableRowsMapper = (sheet, total) => {
|
||||
const rows = [];
|
||||
|
||||
const mapAging = (agingPeriods) => {
|
||||
return agingPeriods.reduce((acc, aging, index) => {
|
||||
acc[`aging-${index}`] = aging.total.formatted_amount;
|
||||
return acc;
|
||||
}, {});
|
||||
};
|
||||
sheet.vendors.forEach((vendor) => {
|
||||
const agingRow = mapAging(vendor.aging);
|
||||
|
||||
rows.push({
|
||||
rowType: 'vendor',
|
||||
name: vendor.vendor_name,
|
||||
...agingRow,
|
||||
current: vendor.current.formatted_amount,
|
||||
total: vendor.total.formatted_amount,
|
||||
});
|
||||
});
|
||||
if (rows.length <= 0) {
|
||||
return [];
|
||||
}
|
||||
return [
|
||||
...rows,
|
||||
{
|
||||
name: '',
|
||||
rowType: 'total',
|
||||
current: sheet.total.current.formatted_amount,
|
||||
...mapAging(sheet.total.aging),
|
||||
total: sheet.total.total.formatted_amount,
|
||||
},
|
||||
];
|
||||
};
|
||||
|
||||
@@ -6,6 +6,7 @@ import {
|
||||
generalLedgerToTableRows,
|
||||
profitLossToTableRowsMapper,
|
||||
ARAgingSummaryTableRowsMapper,
|
||||
APAgingSummaryTableRowsMapper,
|
||||
mapTrialBalanceSheetToRows,
|
||||
} from './financialStatements.mappers';
|
||||
|
||||
@@ -48,6 +49,13 @@ const initialState = {
|
||||
filter: true,
|
||||
refresh: false,
|
||||
},
|
||||
payableAgingSummary: {
|
||||
sheet: {},
|
||||
loading: false,
|
||||
tableRows: [],
|
||||
filter: true,
|
||||
refresh: false,
|
||||
},
|
||||
};
|
||||
|
||||
const financialStatementFilterToggle = (financialName, statePath) => {
|
||||
@@ -172,7 +180,7 @@ export default createReducer(initialState, {
|
||||
const { refresh } = action.payload;
|
||||
state.receivableAgingSummary.refresh = !!refresh;
|
||||
},
|
||||
[t.RECEIVABLE_AGING_SUMMARY_LOADING]: (state, action) => {
|
||||
[t.RECEIVABLE_AGING_SUMMARY_LOADING]: (state, action) => {
|
||||
const { loading } = action.payload;
|
||||
state.receivableAgingSummary.loading = loading;
|
||||
},
|
||||
@@ -180,4 +188,29 @@ export default createReducer(initialState, {
|
||||
'RECEIVABLE_AGING_SUMMARY',
|
||||
'receivableAgingSummary',
|
||||
),
|
||||
|
||||
[t.PAYABLE_AGING_SUMMARY_SET]: (state, action) => {
|
||||
const { vendors, total, columns, query } = action.payload;
|
||||
|
||||
const receivableSheet = {
|
||||
query,
|
||||
columns,
|
||||
vendors,
|
||||
total,
|
||||
tableRows: APAgingSummaryTableRowsMapper({ vendors, columns, total }),
|
||||
};
|
||||
state.payableAgingSummary.sheet = receivableSheet;
|
||||
},
|
||||
[t.PAYABLE_AGING_SUMMARY_REFRESH]: (state, action) => {
|
||||
const { refresh } = action.payload;
|
||||
state.payableAgingSummary.refresh = !!refresh;
|
||||
},
|
||||
[t.PAYABLE_AGING_SUMMARY_LOADING]: (state, action) => {
|
||||
const { loading } = action.payload;
|
||||
state.payableAgingSummary.loading = loading;
|
||||
},
|
||||
...financialStatementFilterToggle(
|
||||
'PAYABLE_AGING_SUMMARY',
|
||||
'payableAgingSummary',
|
||||
),
|
||||
});
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
|
||||
|
||||
export default {
|
||||
GENERAL_LEDGER_STATEMENT_SET: 'GENERAL_LEDGER_STATEMENT_SET',
|
||||
GENERAL_LEDGER_SHEET_LOADING: 'GENERAL_LEDGER_SHEET_LOADING',
|
||||
@@ -25,4 +23,8 @@ export default {
|
||||
RECEIVABLE_AGING_SUMMARY_SET: 'RECEIVABLE_AGING_SUMMARY_SET',
|
||||
RECEIVABLE_AGING_REFRECH: 'RECEIVABLE_AGING_REFRECH',
|
||||
RECEIVABLE_AGING_SUMMARY_REFRESH: 'RECEIVABLE_AGING_SUMMARY_REFRESH',
|
||||
}
|
||||
|
||||
PAYABLE_AGING_SUMMARY_LOADING: 'PAYABLE_AGING_SUMMARY_LOADING',
|
||||
PAYABLE_AGING_SUMMARY_SET: 'PAYABLE_AGING_SUMMARY_SET',
|
||||
PAYABLE_AGING_SUMMARY_REFRESH: 'PAYABLE_AGING_SUMMARY_REFRESH',
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user