mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-17 13:20:31 +00:00
WIP manual-journals
This commit is contained in:
@@ -2,9 +2,82 @@ import ApiService from 'services/ApiService';
|
||||
import t from 'store/types';
|
||||
|
||||
export const makeJournalEntries = ({ form }) => {
|
||||
return (dispatch) => new Promise((resolve, reject) => {
|
||||
ApiService.post('accounting/make-journal-entries', form).then((response) => {
|
||||
resolve(response);
|
||||
}).catch((error) => { reject(error); });
|
||||
});
|
||||
}
|
||||
return (dispatch) =>
|
||||
new Promise((resolve, reject) => {
|
||||
ApiService.post('accounting/make-journal-entries', form)
|
||||
.then((response) => {
|
||||
resolve(response);
|
||||
})
|
||||
.catch((error) => {
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
export const deleteManualJournal = ({ id }) => {
|
||||
return (dispatch) =>
|
||||
new Promise((resolve, reject) => {
|
||||
ApiService.delete(`accounting/manual-journals/${id}`)
|
||||
.then((response) => {
|
||||
dispatch({
|
||||
type: t.MANUAL_JOURNAL_DELETE,
|
||||
id,
|
||||
});
|
||||
resolve(response);
|
||||
})
|
||||
.catch((error) => {
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
export const fetchManualJournalsTable = ({ query } = {}) => {
|
||||
return (dispatch, getState) =>
|
||||
new Promise((resolve, reject) => {
|
||||
const pageQuery = getState().manual_journals.tableQuery;
|
||||
|
||||
dispatch({
|
||||
type: t.MANUAL_JOURNALS_TABLE_LOADING,
|
||||
loading: true,
|
||||
});
|
||||
ApiService.get('accounting/manual-journals', {
|
||||
params: { ...pageQuery, ...query },
|
||||
})
|
||||
.then((response) => {
|
||||
|
||||
dispatch({
|
||||
type: t.MANUAL_JOURNALS_PAGE_SET,
|
||||
manual_journals: response.data.manualJournals,
|
||||
customViewId: response.data.customViewId,
|
||||
});
|
||||
dispatch({
|
||||
type: t.MANUAL_JOURNALS_ITEMS_SET,
|
||||
manual_journals: response.data.manualJournals,
|
||||
});
|
||||
dispatch({
|
||||
type: t.MANUAL_JOURNALS_TABLE_LOADING,
|
||||
loading: false,
|
||||
});
|
||||
resolve(response);
|
||||
})
|
||||
.catch((error) => {
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
export const fetchManualJournalsDataTable = ({ query }) => {
|
||||
return (dispatch) =>
|
||||
new Promise((resolve, reject) => {
|
||||
ApiService.get('accounting/manual-journals')
|
||||
.then((response) => {
|
||||
dispatch({
|
||||
type: t.MANUAL_JOURNALS_DATA_TABLE,
|
||||
data: response.data,
|
||||
});
|
||||
})
|
||||
.catch((error) => {
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
import t from 'store/types';
|
||||
import { createReducer, combineReducers } from '@reduxjs/toolkit';
|
||||
import { createTableQueryReducers } from 'store/queryReducers';
|
||||
|
||||
const initialState = {
|
||||
manual_journals: {},
|
||||
views: {},
|
||||
manualJournalById: {},
|
||||
dataTableQuery: {},
|
||||
currentViewId: -1,
|
||||
selectedRows: [],
|
||||
loading: false,
|
||||
};
|
||||
|
||||
// MANUAL_JOURNALS
|
||||
const manualJournalsReducer = createReducer(initialState, {
|
||||
[t.MANUAL_JOURNALS_ITEMS_SET]: (state, action) => {
|
||||
const _manual_journals = {};
|
||||
|
||||
action.manual_journals.forEach((manual_journal) => {
|
||||
_manual_journals[manual_journal.id] = manual_journal;
|
||||
});
|
||||
|
||||
state.manual_journals = {
|
||||
...state.manual_journals,
|
||||
..._manual_journals,
|
||||
};
|
||||
},
|
||||
[t.MANUAL_JOURNALS_PAGE_SET]: (state, action) => {
|
||||
const viewId = action.customViewId || -1;
|
||||
const view = state.views[viewId] || {};
|
||||
|
||||
state.views[viewId] = {
|
||||
...view,
|
||||
ids: action.manual_journals.map((i) => i.id),
|
||||
};
|
||||
// state.manual_journals = action.manual_journals;
|
||||
},
|
||||
[t.MANUAL_JOURNALS_TABLE_LOADING]: (state, action) => {
|
||||
state.loading = action.loading;
|
||||
},
|
||||
[t.MANUAL_JOURNALS_SET_CURRENT_VIEW]: (state, action) => {
|
||||
state.currentViewId = action.currentViewId;
|
||||
},
|
||||
});
|
||||
|
||||
export default createTableQueryReducers(
|
||||
'manual_journals',
|
||||
manualJournalsReducer
|
||||
);
|
||||
|
||||
export const getManualJournalById = (state, id) => {
|
||||
return state.manual_journals.manualJournalById[id];
|
||||
};
|
||||
|
||||
14
client/src/store/accounting/accounting.selectors.js
Normal file
14
client/src/store/accounting/accounting.selectors.js
Normal file
@@ -0,0 +1,14 @@
|
||||
import { pickItemsFromIds } from 'store/selectors';
|
||||
|
||||
export const getManualJournals = (state, viewId) => {
|
||||
const manualJournalView = state.manual_journals.views[-1];
|
||||
const manualJournalsItems = state.manual_journals.manual_journals;
|
||||
|
||||
console.log(manualJournalView, 'Message');
|
||||
|
||||
return typeof manualJournalView === 'object' &&
|
||||
manualJournalView.ids &&
|
||||
manualJournalsItems
|
||||
? pickItemsFromIds(manualJournalsItems, manualJournalView.ids) || []
|
||||
: [];
|
||||
};
|
||||
@@ -1,5 +1,10 @@
|
||||
|
||||
|
||||
export default {
|
||||
MAKE_JOURNAL_ENTRIES: 'MAKE_JOURNAL_ENTRIES',
|
||||
}
|
||||
MANUAL_JOURNALS_TABLE_LOADING: 'MANUAL_JOURNALS_TABLE_LOADING',
|
||||
MANUAL_JOURNALS_PAGE_SET: 'MANUAL_JOURNALS_PAGE_SET',
|
||||
MANUAL_JOURNALS_DATA_TABLE: 'MANUAL_JOURNALS_DATA_TABLE',
|
||||
MANUAL_JOURNALS_ITEMS_SET: 'MANUAL_JOURNALS_ITEMS_SET',
|
||||
MANUAL_JOURNALS_SET_CURRENT_VIEW: 'MANUAL_JOURNALS_SET_CURRENT_VIEW',
|
||||
MANUAL_JOURNALS_TABLE_QUERIES_ADD: 'MANUAL_JOURNALS_TABLE_QUERIES_ADD',
|
||||
MANUAL_JOURNAL_DELETE: 'MANUAL_JOURNAL_DELETE',
|
||||
};
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
import {pickItemsFromIds} from 'store/selectors';
|
||||
import { pickItemsFromIds } from 'store/selectors';
|
||||
|
||||
export const getAccountsItems = (state, viewId) => {
|
||||
const accountsView = state.accounts.views[(viewId || -1)];
|
||||
|
||||
const accountsView = state.accounts.views[viewId || -1];
|
||||
const accountsItems = state.accounts.items;
|
||||
|
||||
return (typeof accountsView === 'object')
|
||||
? (pickItemsFromIds(accountsItems, accountsView.ids) || []) : [];
|
||||
}
|
||||
return typeof accountsView === 'object'
|
||||
? pickItemsFromIds(accountsItems, accountsView.ids) || []
|
||||
: [];
|
||||
};
|
||||
|
||||
@@ -11,9 +11,9 @@ import expenses from './expenses/expenses.reducer';
|
||||
import currencies from './currencies/currencies.reducer';
|
||||
import resources from './resources/resources.reducer';
|
||||
import financialStatements from './financialStatement/financialStatements.reducer';
|
||||
import itemCategories from './itemCategories/itemsCateory.reducer';
|
||||
import itemCategories from './itemCategories/itemsCategory.reducer';
|
||||
import settings from './settings/settings.reducer';
|
||||
|
||||
import manual_journals from './accounting/accounting.reducers';
|
||||
export default combineReducers({
|
||||
authentication,
|
||||
dashboard,
|
||||
@@ -28,4 +28,5 @@ export default combineReducers({
|
||||
items,
|
||||
itemCategories,
|
||||
settings,
|
||||
manual_journals,
|
||||
});
|
||||
|
||||
@@ -12,7 +12,7 @@ import users from './users/users.types';
|
||||
import financialStatements from './financialStatement/financialStatements.types';
|
||||
import itemCategories from './itemCategories/itemsCategory.type';
|
||||
import settings from './settings/settings.type';
|
||||
|
||||
import manualJournals from './accounting/accountsing.types';
|
||||
export default {
|
||||
...authentication,
|
||||
...accounts,
|
||||
@@ -27,5 +27,6 @@ export default {
|
||||
...users,
|
||||
...financialStatements,
|
||||
...itemCategories,
|
||||
...settings
|
||||
...settings,
|
||||
...manualJournals
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user