Loading...
Loading...
Compare original and translation side by side
┌─────────────────────────────────────────────────┐
│ USER LAYER (Friendly) │
│ Sales, Purchases, Payments, Inventory, Expenses│
│ → User sees: "Sale #1042 to Customer X: $500" │
└──────────────────────┬──────────────────────────┘
│ auto-posts
┌──────────────────────▼──────────────────────────┐
│ ACCOUNTING ENGINE (Hidden) │
│ Journal Entries, Ledger Postings, Trial Balance│
│ → Engine posts: DR Accounts Receivable $500 │
│ CR Sales Revenue $500 │
└──────────────────────┬──────────────────────────┘
│ aggregates
┌──────────────────────▼──────────────────────────┐
│ REPORTING LAYER (Dual) │
│ User Reports: Sales Summary, Aging, P&L Simple │
│ Accountant Reports: Trial Balance, BS, IS, CF │
└─────────────────────────────────────────────────┘┌─────────────────────────────────────────────────┐
│ USER LAYER (Friendly) │
│ Sales, Purchases, Payments, Inventory, Expenses│
│ → User sees: "Sale #1042 to Customer X: $500" │
└──────────────────────┬──────────────────────────┘
│ auto-posts
┌──────────────────────▼──────────────────────────┐
│ ACCOUNTING ENGINE (Hidden) │
│ Journal Entries, Ledger Postings, Trial Balance│
│ → Engine posts: DR Accounts Receivable $500 │
│ CR Sales Revenue $500 │
└──────────────────────┬──────────────────────────┘
│ aggregates
┌──────────────────────▼──────────────────────────┐
│ REPORTING LAYER (Dual) │
│ User Reports: Sales Summary, Aging, P&L Simple │
│ Accountant Reports: Trial Balance, BS, IS, CF │
└─────────────────────────────────────────────────┘SUM(debits) = SUM(credits) — ALWAYSSUM(debits) = SUM(credits) — 始终成立| Type | Code Range | Normal Balance | Examples |
|---|---|---|---|
| Asset | 1000-1999 | Debit | Cash, Bank, AR, Inventory, Equipment |
| Liability | 2000-2999 | Credit | AP, Loans, Tax Payable, Unearned Revenue |
| Equity | 3000-3999 | Credit | Owner's Equity, Retained Earnings |
| Revenue | 4000-4999 | Credit | Sales, Service Income, Interest Income |
| COGS | 5000-5999 | Debit | Cost of Goods Sold, Direct Materials |
| Expense | 6000-6999 | Debit | Rent, Salaries, Utilities, Marketing |
franchise_idreferences/chart-of-accounts.md| 类型 | 代码范围 | 正常余额方向 | 示例 |
|---|---|---|---|
| 资产 | 1000-1999 | 借方 | 现金、银行存款、应收账款、库存、设备 |
| 负债 | 2000-2999 | 贷方 | 应付账款、贷款、应交税费、预收收入 |
| 所有者权益 | 3000-3999 | 贷方 | 所有者权益、留存收益 |
| 收入 | 4000-4999 | 贷方 | 销售收入、服务收入、利息收入 |
| 销货成本(COGS) | 5000-5999 | 借方 | 销货成本、直接材料 |
| 费用 | 6000-6999 | 借方 | 租金、工资、水电费、营销费用 |
franchise_idreferences/chart-of-accounts.md| User Action | Debit Account | Credit Account |
|---|---|---|
| Record Sale (Invoice) | Accounts Receivable | Sales Revenue |
| Record Sale + Tax | AR + Tax Receivable | Sales Revenue + Tax Payable |
| Receive Payment (Cash) | Cash/Bank | Accounts Receivable |
| Record Purchase | Inventory/Expense | Accounts Payable |
| Pay Supplier | Accounts Payable | Cash/Bank |
| Record Expense | Expense Account | Cash/Bank or AP |
| Inventory Sale (COGS) | Cost of Goods Sold | Inventory |
| Stock Adjustment (+) | Inventory | Inventory Adjustment (Income) |
| Stock Adjustment (-) | Inventory Adjustment (Expense) | Inventory |
| Salary Payment | Salary Expense | Cash/Bank |
| Loan Received | Cash/Bank | Loan Payable |
| Loan Repayment | Loan Payable + Interest Exp | Cash/Bank |
| Depreciation | Depreciation Expense | Accumulated Depreciation |
| Customer Refund | Sales Returns | Cash/Bank or AR |
references/journal-posting-rules.md| 用户操作 | 借方科目 | 贷方科目 |
|---|---|---|
| 记录销售(发票) | 应收账款 | 销售收入 |
| 记录含税销售 | 应收账款+应收税费 | 销售收入+应交税费 |
| 收到付款(现金) | 现金/银行存款 | 应收账款 |
| 记录采购 | 库存/费用 | 应付账款 |
| 支付供应商货款 | 应付账款 | 现金/银行存款 |
| 记录费用 | 费用科目 | 现金/银行存款或应付账款 |
| 库存销售(结转销货成本) | 销货成本 | 库存 |
| 库存调整(+) | 库存 | 库存调整(收入类) |
| 库存调整(-) | 库存调整(费用类) | 库存 |
| 支付工资 | 工资费用 | 现金/银行存款 |
| 收到贷款 | 现金/银行存款 | 应付贷款 |
| 偿还贷款 | 应付贷款+利息费用 | 现金/银行存款 |
| 计提折旧 | 折旧费用 | 累计折旧 |
| 客户退款 | 销售退回 | 现金/银行存款或应收账款 |
references/journal-posting-rules.md1. User clicks "Void" on a transaction (e.g., Sale Invoice #1042)
2. System marks the original transaction as VOIDED (status change)
3. System auto-creates a REVERSING journal entry:
- Same accounts, opposite directions
- Reference: "REVERSAL of JE-{original_id}"
- Same date OR current date (configurable)
4. Original entry + reversal entry net to ZERO
5. All sub-ledger balances update automatically1. 用户点击某笔交易的“冲销”按钮(例如:销售发票#1042)
2. 系统将原交易标记为已冲销(状态变更)
3. 系统自动生成一笔**反转日记账分录**:
- 使用相同科目,方向相反
- 备注:“REVERSAL of JE-{original_id}”
- 日期与原分录相同或使用当前日期(可配置)
4. 原分录与反转分录的净额为零
5. 所有子分类账余额自动更新Original (Sale Invoice #1042):
DR Accounts Receivable 500.00
CR Sales Revenue 500.00
Reversal (Void of #1042):
DR Sales Revenue 500.00
CR Accounts Receivable 500.00
Net effect: ZERO原分录(销售发票#1042):
DR 应收账款 500.00
CR 销售收入 500.00
反转分录(冲销#1042):
DR 销售收入 500.00
CR 应收账款 500.00
净额影响:零references/void-reversal-patterns.mdreferences/void-reversal-patterns.md-- Chart of Accounts
accounts (id, franchise_id, code, name, type, parent_id,
is_active, normal_balance, created_at)
-- Journal Entries (Header)
journal_entries (id, franchise_id, entry_date, reference_type,
reference_id, narration, is_reversal, reversed_entry_id,
posted_by, status, created_at)
-- Journal Entry Lines (Detail)
journal_entry_lines (id, journal_entry_id, account_id,
debit_amount, credit_amount, narration,
franchise_id, created_at)
-- Fiscal Periods
fiscal_periods (id, franchise_id, period_name, start_date,
end_date, status, closed_by, closed_at)
-- Account Balances (Materialized for performance)
account_balances (id, franchise_id, account_id, period_id,
opening_balance, debit_total, credit_total,
closing_balance, updated_at)journal_entry_lines.debit_amountcredit_amountfranchise_idstatusreferences/schema-design.md-- Chart of Accounts
accounts (id, franchise_id, code, name, type, parent_id,
is_active, normal_balance, created_at)
-- Journal Entries (Header)
journal_entries (id, franchise_id, entry_date, reference_type,
reference_id, narration, is_reversal, reversed_entry_id,
posted_by, status, created_at)
-- Journal Entry Lines (Detail)
journal_entry_lines (id, journal_entry_id, account_id,
debit_amount, credit_amount, narration,
franchise_id, created_at)
-- Fiscal Periods
fiscal_periods (id, franchise_id, period_name, start_date,
end_date, status, closed_by, closed_at)
-- Account Balances (Materialized for performance)
account_balances (id, franchise_id, account_id, period_id,
opening_balance, debit_total, credit_total,
closing_balance, updated_at)journal_entry_lines.debit_amountcredit_amountfranchise_idstatusreferences/schema-design.md| Report | What User Sees | Data Source |
|---|---|---|
| Sales Summary | Total sales by period, customer, product | Sales transactions |
| Outstanding Invoices | Who owes what, how old | AR sub-ledger |
| Expense Report | Spending by category | Expense transactions |
| Profit & Loss (Simple) | Revenue minus expenses | Income/expense accounts |
| Cash Position | Money in bank/cash | Cash/bank accounts |
| Inventory Value | Stock on hand with cost | Inventory sub-ledger |
| 报告 | 用户可见内容 | 数据源 |
|---|---|---|
| 销售汇总报告 | 按期间、客户、产品统计的销售总额 | 销售交易数据 |
| 未结清发票报告 | 欠款方及欠款账龄 | 应收账款子分类账 |
| 费用报告 | 按类别统计的支出情况 | 费用交易数据 |
| 简易利润表 | 收入减去费用 | 收入/费用科目 |
| 现金头寸报告 | 银行/现金账户余额 | 现金/银行科目 |
| 库存价值报告 | 现有库存及成本 | 库存子分类账 |
| Report | What It Shows | Source |
|---|---|---|
| Trial Balance | All account balances (DR/CR columns) | General Ledger |
| Balance Sheet | Assets = Liabilities + Equity | GL (type 1-3) |
| Income Statement | Revenue - COGS - Expenses = Net Income | GL (type 4-6) |
| Cash Flow Statement | Operating + Investing + Financing | Cash account entries |
| General Ledger Detail | Every entry per account | Journal entries |
| Journal Register | All journal entries chronologically | Journal entries |
| Aged Receivables | AR aging (30/60/90/120 days) | AR sub-ledger |
| Aged Payables | AP aging | AP sub-ledger |
| Audit Trail | Who posted what, when | Journal entries + audit log |
references/financial-statements.md| 报告 | 展示内容 | 数据源 |
|---|---|---|
| 试算平衡表 | 所有科目的余额(借方/贷方列) | 总分类账 |
| 资产负债表 | 资产=负债+所有者权益 | 总分类账(类型1-3) |
| 利润表 | 收入-销货成本-费用=净利润 | 总分类账(类型4-6) |
| 现金流量表 | 经营活动+投资活动+筹资活动现金流 | 现金账户分录 |
| 总分类账明细 | 每个科目的所有分录 | 日记账分录 |
| 日记账登记簿 | 所有日记账分录的 chronological 记录 | 日记账分录 |
| 应收账款账龄报告 | 应收账款账龄(30/60/90/120天) | 应收账款子分类账 |
| 应付账款账龄报告 | 应付账款账龄 | 应付账款子分类账 |
| 审计追踪报告 | 过账人、过账时间及操作内容 | 日记账分录+审计日志 |
references/financial-statements.mdaccountsjournal_entriesjournal_entry_linesfiscal_periodspostJournalEntry()accountsjournal_entriesjournal_entry_linesfiscal_periodspostJournalEntry()| Area | Skill | How It Applies |
|---|---|---|
| Database schema | | DECIMAL(15,2), indexes, FK constraints |
| API endpoints | | Consistent error responses for failed postings |
| Multi-tenancy | | franchise_id on all tables |
| UI reports | | DataTables for ledger, charts for P&L |
| Mobile reports | | Report screens with tables |
| PDF export | | Financial statement PDFs |
| Security | | Protect financial data, audit trail |
| Auth | | Permission: who can post/void/view reports |
| Inventory link | | COGS posting on stock movements |
| Testing | | Test every posting rule, every reversal |
| Implementation | | Execute accounting phases with TDD |
| Audit | | Verify accounting system completeness |
| 领域 | 技能 | 应用方式 |
|---|---|---|
| 数据库架构 | | 使用DECIMAL(15,2)、索引、外键约束 |
| API端点 | | 为过账失败场景提供一致的错误响应 |
| 多租户 | | 所有表均包含 |
| UI报告 | | 用DataTables展示分类账,用图表展示利润表 |
| 移动端报告 | | 开发带表格的报告界面 |
| PDF导出 | | 生成财务报表PDF |
| 安全 | | 保护财务数据,生成审计追踪 |
| 权限认证 | | 控制谁可以过账/冲销/查看报告 |
| 库存对接 | | 库存变动时自动过账销货成本 |
| 测试 | | 测试每一条过账规则和反转逻辑 |
| 实施规划 | | 用TDD方式执行会计系统各阶段开发 |
| 审计 | | 验证会计系统的完整性 |
| Don't | Do Instead |
|---|---|
| Let users enter journal entries directly | Auto-post from business transactions |
| Use FLOAT for money | Use DECIMAL(15,2) always |
| Delete journal entries | Create reversing entries (void) |
| Skip balance validation | Enforce DR=CR in stored procedure |
| Store calculated balances only | Store individual entries, calculate on demand |
| Mix accounting with business logic | Separate accounting engine as its own service layer |
| Hard-code account codes | Use configurable COA with tenant-specific accounts |
| Skip audit trail | Log every posting with user, timestamp, IP |
| Allow posting to closed periods | Enforce period status check before posting |
| Show debits/credits to end users | Show friendly labels (Income, Payment, etc.) |
| 禁止操作 | 正确做法 |
|---|---|
| 允许用户直接录入日记账分录 | 从业务交易自动过账 |
| 使用FLOAT类型存储金额 | 始终使用DECIMAL(15,2) |
| 删除日记账分录 | 创建反转分录(冲销) |
| 跳过余额验证 | 在存储过程中强制借方=贷方 |
| 仅存储计算后的余额 | 存储单个分录,按需计算余额 |
| 将会计逻辑与业务逻辑混合 | 将会计引擎作为独立服务层分离 |
| 硬编码科目代码 | 使用可配置的COA,支持租户自定义科目 |
| 跳过审计追踪 | 记录每一笔过账的用户、时间戳、IP地址 |
| 允许向已关闭期间过账 | 过账前检查会计期间状态 |
| 向终端用户展示借方/贷方 | 使用友好标签(如收入、付款等) |
SELECT SUM(debit) - SUM(credit) FROM journal_entry_linesSELECT SUM(debit) - SUM(credit) FROM journal_entry_linesreferences/chart-of-accounts.mdreferences/journal-posting-rules.mdreferences/void-reversal-patterns.mdreferences/financial-statements.mdreferences/schema-design.md