Updated GL system allows changing account defaults and add/updating journal entries
This commit is contained in:
@@ -5,6 +5,7 @@ const { bookLedger, createBook, deleteBook, ledgerReport, listBooks, updateBook
|
||||
const { exportReport } = require('../services/reportExport');
|
||||
const { rowsFromImport, extensionForUpload } = require('../services/importExport');
|
||||
const glEntries = require('../services/glEntries');
|
||||
const glAccounts = require('../services/glAccounts');
|
||||
|
||||
const upload = multer({ storage: multer.memoryStorage(), limits: { fileSize: 16 * 1024 * 1024 } });
|
||||
const router = express.Router();
|
||||
@@ -49,6 +50,44 @@ router.post('/books/:code/ledger/export', async (req, res) => {
|
||||
return res.send(output.body);
|
||||
});
|
||||
|
||||
// ---- GL chart of accounts + posting defaults (full audit) -------------------
|
||||
|
||||
router.get('/gl-accounts', ledgerReader, (req, res) => {
|
||||
res.json({ accounts: glAccounts.listAccounts(req.companyId), defaults: glAccounts.getDefaults(req.companyId) });
|
||||
});
|
||||
|
||||
router.post('/gl-accounts', ledgerEditor, (req, res, next) => {
|
||||
try {
|
||||
res.status(201).json({ account: glAccounts.createAccount(req.body, req.user.id, req.companyId) });
|
||||
} catch (error) {
|
||||
next(error);
|
||||
}
|
||||
});
|
||||
|
||||
router.put('/gl-accounts/:id', ledgerEditor, (req, res, next) => {
|
||||
try {
|
||||
const account = glAccounts.updateAccount(req.params.id, req.body, req.user.id, req.companyId);
|
||||
if (!account) return res.status(404).json({ error: 'GL account not found' });
|
||||
return res.json({ account });
|
||||
} catch (error) {
|
||||
return next(error);
|
||||
}
|
||||
});
|
||||
|
||||
router.delete('/gl-accounts/:id', ledgerEditor, (req, res) => {
|
||||
if (!glAccounts.deleteAccount(req.params.id, req.user.id, req.companyId)) return res.status(404).json({ error: 'GL account not found' });
|
||||
return res.status(204).end();
|
||||
});
|
||||
|
||||
// GL posting defaults (the fallback accounts the ledgers post to).
|
||||
router.get('/gl-account-defaults', ledgerReader, (req, res) => {
|
||||
res.json({ defaults: glAccounts.getDefaults(req.companyId) });
|
||||
});
|
||||
|
||||
router.put('/gl-account-defaults', ledgerEditor, (req, res) => {
|
||||
res.json({ defaults: glAccounts.saveDefaults(req.body, req.user.id, req.companyId) });
|
||||
});
|
||||
|
||||
// ---- GL journal entries (stored, editable; full audit) ----------------------
|
||||
|
||||
function glFilters(query, code) {
|
||||
|
||||
Reference in New Issue
Block a user