Initial commit: multi-company financial management system
Root company app (src/, client/) — GL foundation, AR, and AP: - Segmented Chart of Accounts (Sage 300-style), double-entry PostingService with three-layer balance enforcement (app validation, CHECK constraints, deferred DB trigger), gap-free document numbering, RBAC with branch restrictions. - Accounts Receivable: Customers, Invoices, Credit Notes, Receipts with allocation, all posting through PostingService. - Accounts Payable: Suppliers, Supplier Invoices, Debit Notes, Payments with allocation, mirroring AR's posting pattern. - Tax Codes shared between AR and AP. - Company-app login is a token handoff from the Account Manager (RS256, single-use, company-scoped) rather than a local password. - Frontend reskinned to the approved mockup: navy sidebar, dashboard, tree-view Chart of Accounts, Customer/Supplier 360 pages. Account Manager (manager/, manager/client/) — central login gateway: - Password + TOTP 2FA + Google/Microsoft OAuth, company picker, and the RS256 handoff token issuance that the company app verifies. Covered by unit + integration tests against a real Postgres database (GL balance invariants, AR/AP posting correctness and allocation limits, the full handoff exchange including replay/cross-company/expiry/forgery rejection). Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Tq2DbEvzHzs13jDFhLaX44
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
import { Request, Response } from 'express';
|
||||
import { z } from 'zod';
|
||||
import * as glAccountsService from './glAccounts.service';
|
||||
|
||||
const glAccountTypeSchema = z.enum(['ASSET', 'LIABILITY', 'EQUITY', 'INCOME', 'EXPENSE']);
|
||||
const debitCreditSchema = z.enum(['DEBIT', 'CREDIT']);
|
||||
const controlAccountTypeSchema = z.enum(['AR', 'AP', 'STOCK', 'TAX_OUTPUT', 'TAX_INPUT', 'BANK', 'RETAINED_EARNINGS']);
|
||||
|
||||
export const createGLAccountSchema = z.object({
|
||||
accountName: z.string().min(1),
|
||||
accountType: glAccountTypeSchema,
|
||||
normalBalance: debitCreditSchema,
|
||||
isControlAccount: z.boolean().optional(),
|
||||
controlType: controlAccountTypeSchema.optional(),
|
||||
isPostable: z.boolean().optional(),
|
||||
segmentSelections: z
|
||||
.array(z.object({ segmentDefId: z.number().int(), segmentValueId: z.number().int() }))
|
||||
.min(1),
|
||||
});
|
||||
|
||||
export const listGLAccountsQuerySchema = z.object({
|
||||
branchScope: z.string().optional(),
|
||||
accountType: glAccountTypeSchema.optional(),
|
||||
});
|
||||
|
||||
export async function createGLAccountHandler(req: Request, res: Response): Promise<void> {
|
||||
const input = req.body as z.infer<typeof createGLAccountSchema>;
|
||||
res.status(201).json(await glAccountsService.createGLAccount(input));
|
||||
}
|
||||
|
||||
export async function listGLAccountsHandler(req: Request, res: Response): Promise<void> {
|
||||
const { accountType } = req.query as unknown as z.infer<typeof listGLAccountsQuerySchema>;
|
||||
res.json(await glAccountsService.listGLAccounts(req.branchScope!, accountType));
|
||||
}
|
||||
|
||||
export async function getGLAccountHandler(req: Request, res: Response): Promise<void> {
|
||||
const account = await glAccountsService.getGLAccountByCode(req.params.accountCode);
|
||||
if (!account) {
|
||||
res.status(404).json({ error: 'GL account not found' });
|
||||
return;
|
||||
}
|
||||
res.json(account);
|
||||
}
|
||||
Reference in New Issue
Block a user