mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-17 21:30:31 +00:00
Merge branch 'feature/manual-journals' of https://github.com/abouolia/Ratteb
This commit is contained in:
@@ -1,33 +0,0 @@
|
||||
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); });
|
||||
});
|
||||
};
|
||||
|
||||
export const fetchManualJournal = ({ id }) => {
|
||||
return (dispatch) => new Promise((resolve, reject) => {
|
||||
ApiService.get(`accounting/manual-journals/${id}`).then((response) => {
|
||||
dispatch({
|
||||
type: t.MANUAL_JOURNAL_SET,
|
||||
payload: {
|
||||
id,
|
||||
manualJournal: response.data.manual_journal,
|
||||
}
|
||||
});
|
||||
resolve(response);
|
||||
}).catch((error) => { reject(error); });
|
||||
});
|
||||
};
|
||||
|
||||
export const editManualJournal = ({ form, id }) => {
|
||||
return (dispatch) => new Promise((resolve, reject) => {
|
||||
ApiService.post(`accounting/manual-journals/${id}`, form).then((response) => {
|
||||
resolve(response);
|
||||
}).catch((error) => { reject(error); });
|
||||
});
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
import t from 'store/types';
|
||||
import { createReducer } from '@reduxjs/toolkit';
|
||||
|
||||
const initialState = {
|
||||
manualJournals: {},
|
||||
};
|
||||
|
||||
export default createReducer(initialState, {
|
||||
|
||||
[t.MANUAL_JOURNAL_SET]: (state, action) => {
|
||||
const { id, manualJournal } = action.payload;
|
||||
state.manualJournals[id] = manualJournal;
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
export const getManualJournal = (state, id) => {
|
||||
return state.accounting.manualJournals[id];
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
|
||||
|
||||
export default {
|
||||
MAKE_JOURNAL_ENTRIES: 'MAKE_JOURNAL_ENTRIES',
|
||||
MANUAL_JOURNAL_SET: 'MANUAL_JOURNAL_SET',
|
||||
}
|
||||
@@ -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) || []
|
||||
: [];
|
||||
};
|
||||
|
||||
97
client/src/store/manualJournals/manualJournals.actions.js
Normal file
97
client/src/store/manualJournals/manualJournals.actions.js
Normal file
@@ -0,0 +1,97 @@
|
||||
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); });
|
||||
});
|
||||
};
|
||||
|
||||
export const fetchManualJournal = ({ id }) => {
|
||||
return (dispatch) => new Promise((resolve, reject) => {
|
||||
ApiService.get(`accounting/manual-journals/${id}`).then((response) => {
|
||||
dispatch({
|
||||
type: t.MANUAL_JOURNAL_SET,
|
||||
payload: {
|
||||
id,
|
||||
manualJournal: response.data.manual_journal,
|
||||
},
|
||||
});
|
||||
resolve(response);
|
||||
}).catch((error) => { reject(error); });
|
||||
});
|
||||
};
|
||||
|
||||
export const editManualJournal = ({ form, id }) => {
|
||||
return (dispatch) => new Promise((resolve, reject) => {
|
||||
ApiService.post(`accounting/manual-journals/${id}`, 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_REMOVE,
|
||||
payload: { id },
|
||||
});
|
||||
resolve(response);
|
||||
})
|
||||
.catch((error) => { reject(error); });
|
||||
});
|
||||
};
|
||||
|
||||
export const publishManualJournal = ({ id }) => {
|
||||
return (dispatch) =>
|
||||
new Promise((resolve, reject) => {
|
||||
ApiService.post(`accounting/manual-journals/${id}/publish`)
|
||||
.then((response) => {
|
||||
dispatch({
|
||||
type: t.MANUAL_JOURNAL_PUBLISH,
|
||||
payload: { id },
|
||||
});
|
||||
resolve(response);
|
||||
})
|
||||
.catch((error) => { reject(error); });
|
||||
});
|
||||
}
|
||||
|
||||
export const fetchManualJournalsTable = ({ query } = {}) => {
|
||||
return (dispatch, getState) =>
|
||||
new Promise((resolve, reject) => {
|
||||
const pageQuery = getState().manualJournals.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);
|
||||
});
|
||||
});
|
||||
};
|
||||
68
client/src/store/manualJournals/manualJournals.reducers.js
Normal file
68
client/src/store/manualJournals/manualJournals.reducers.js
Normal file
@@ -0,0 +1,68 @@
|
||||
import t from 'store/types';
|
||||
import { createReducer } from '@reduxjs/toolkit';
|
||||
import { omit } from 'lodash';
|
||||
|
||||
const initialState = {
|
||||
items: {},
|
||||
views: {},
|
||||
loading: false,
|
||||
currentViewId: -1,
|
||||
tableQuery: {},
|
||||
};
|
||||
|
||||
export default createReducer(initialState, {
|
||||
|
||||
[t.MANUAL_JOURNAL_SET]: (state, action) => {
|
||||
const { id, manualJournal } = action.payload;
|
||||
state.items[id] = manualJournal;
|
||||
},
|
||||
|
||||
[t.MANUAL_JOURNAL_PUBLISH]: (state, action) => {
|
||||
const { id } = action.payload;
|
||||
const item = state.items[id] || {};
|
||||
|
||||
state.items[id] = {
|
||||
...item, status: 1,
|
||||
};
|
||||
},
|
||||
|
||||
[t.MANUAL_JOURNALS_ITEMS_SET]: (state, action) => {
|
||||
const _manual_journals = {};
|
||||
|
||||
action.manual_journals.forEach((manual_journal) => {
|
||||
_manual_journals[manual_journal.id] = manual_journal;
|
||||
});
|
||||
state.items = {
|
||||
...state.items,
|
||||
..._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),
|
||||
};
|
||||
},
|
||||
|
||||
[t.MANUAL_JOURNALS_TABLE_LOADING]: (state, action) => {
|
||||
state.loading = action.loading;
|
||||
},
|
||||
|
||||
[t.MANUAL_JOURNALS_SET_CURRENT_VIEW]: (state, action) => {
|
||||
state.currentViewId = action.currentViewId;
|
||||
},
|
||||
|
||||
[t.MANUAL_JOURNAL_REMOVE]: (state, action) => {
|
||||
const { id } = action.payload;
|
||||
state.items = omit(state.items, [id]);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
export const getManualJournal = (state, id) => {
|
||||
return state.manualJournals.items[id];
|
||||
}
|
||||
10
client/src/store/manualJournals/manualJournals.selectors.js
Normal file
10
client/src/store/manualJournals/manualJournals.selectors.js
Normal file
@@ -0,0 +1,10 @@
|
||||
import { pickItemsFromIds } from 'store/selectors';
|
||||
|
||||
export const getManualJournalsItems = (state, viewId) => {
|
||||
const accountsView = state.manualJournals.views[viewId || -1];
|
||||
const accountsItems = state.manualJournals.items;
|
||||
|
||||
return typeof accountsView === 'object'
|
||||
? pickItemsFromIds(accountsItems, accountsView.ids) || []
|
||||
: [];
|
||||
};
|
||||
13
client/src/store/manualJournals/manualJournals.types.js
Normal file
13
client/src/store/manualJournals/manualJournals.types.js
Normal file
@@ -0,0 +1,13 @@
|
||||
export default {
|
||||
MAKE_JOURNAL_ENTRIES: 'MAKE_JOURNAL_ENTRIES',
|
||||
MANUAL_JOURNAL_SET: 'MANUAL_JOURNAL_SET',
|
||||
|
||||
MANUAL_JOURNALS_TABLE_LOADING: 'MANUAL_JOURNALS_TABLE_LOADING',
|
||||
MANUAL_JOURNALS_PAGE_SET: 'MANUAL_JOURNALS_PAGE_SET',
|
||||
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_REMOVE: 'MANUAL_JOURNAL_REMOVE',
|
||||
|
||||
MANUAL_JOURNAL_PUBLISH: 'MANUAL_JOURNAL_PUBLISH',
|
||||
};
|
||||
@@ -11,16 +11,16 @@ 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 accounting from './accounting/accounting.reducers';
|
||||
import manualJournals from './manualJournals/manualJournals.reducers';
|
||||
|
||||
export default combineReducers({
|
||||
authentication,
|
||||
dashboard,
|
||||
users,
|
||||
accounts,
|
||||
accounting,
|
||||
manualJournals,
|
||||
fields,
|
||||
views,
|
||||
expenses,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import authentication from './authentication/authentication.types';
|
||||
import accounts from './accounts/accounts.types';
|
||||
import accounting from './accounting/accounting.types'
|
||||
import accounting from './manualJournals/manualJournals.types'
|
||||
import currencies from './currencies/currencies.types';
|
||||
import customFields from './customFields/customFields.types';
|
||||
import customViews from './customViews/customViews.types';
|
||||
|
||||
Reference in New Issue
Block a user