accounting-engine
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseAccounting Engine
会计引擎
Use When
适用场景
- The product handles money, inventory value, payroll, tax, customer balances, supplier balances, assets, grants, donations, loans, refunds, wallet balances, or financial reporting.
- A SaaS must replace routine bookkeeping in external products such as QuickBooks, Xero, Sage, Pastel, Tally, Zoho Books, or Wave.
- You need architecture, schema, posting rules, tests, documentation, or review findings for ledger-backed business software.
- 产品涉及资金、库存价值、薪资、税务、客户余额、供应商余额、资产、拨款、捐赠、贷款、退款、钱包余额或财务报告。
- SaaS产品需要替代QuickBooks、Xero、Sage、Pastel、Tally、Zoho Books或Wave等外部产品中的日常簿记工作。
- 你需要基于分类账的业务软件的架构、schema、过账规则、测试、文档或评审结果。
Do Not Use When
不适用场景
- The task is only financial analysis or projections without software architecture; use or the business-plan finance skills.
accounting-finance-controller - The system only displays imported accounting reports and does not create business events or postings.
- A jurisdiction requires a licensed accountant, auditor, or tax practitioner to exercise professional judgement; design the system support, but do not claim the software replaces that judgement.
- 任务仅为财务分析或预测,不涉及软件架构;请使用或商业计划财务相关技能。
accounting-finance-controller - 系统仅展示导入的会计报表,不生成业务事件或过账记录。
- 司法管辖区要求持牌会计师、审计师或税务从业者行使专业判断;设计系统提供支持,但不得声称软件可替代该判断。
Hard Rules
硬性规则
- NEVER let a business module write directly to ,
gl_entries,journal_lines, or any ledger table.journal_entries - ALWAYS write ledger records through one service: or the project-equivalent single posting service.
LedgerPostingService::post(JournalEntry $entry) - NEVER update, delete, or soft-delete posted journal lines. Corrections are reversing journals linked to the original entry.
- NEVER store authoritative balances that cannot be rebuilt from journal lines. Materialized balances are caches with a documented rebuild command.
- NEVER hardcode account codes in business logic. Use account mappings resolved at posting time.
- NEVER use LIFO for IFRS or IFRS for SMEs tenants.
- MUST reject posting when required account mappings are missing, inactive, cross-tenant, or not valid for the source document.
- 绝对禁止业务模块直接写入、
gl_entries、journal_lines或任何分类账表。journal_entries - 必须通过单一服务写入分类账记录:或项目等效的单一过账服务。
LedgerPostingService::post(JournalEntry $entry) - 绝对禁止更新、删除或软删除已过账的日记账分录。更正需通过关联原分录的冲销日记账完成。
- 绝对禁止存储无法从日记账分录重建的权威余额。物化余额为缓存,并需附带可重建的文档化命令。
- 绝对禁止在业务逻辑中硬编码科目代码。使用过账时解析的科目映射。
- 对于采用IFRS或IFRS for SMEs的租户,绝对禁止使用LIFO(后进先出)法。
- 当所需科目映射缺失、失效、跨租户或对源文档无效时,必须拒绝过账。
Canonical Architecture
标准架构
Business modules emit events. A mapper turns events into balanced value objects. The posting service validates and writes the entry atomically. Reports, subledgers, balances, tax schedules, and dashboards are deterministic projections of the ledger.
JournalEntrytext
Sales / Stock / Payroll / Assets / Payments / Grants
-> business event
-> account resolver and posting-rule mapper
-> JournalEntry value object
-> LedgerPostingService::post()
-> append-only journal_entries + journal_lines
-> reports, subledgers, tax schedules, dashboards业务模块触发事件。映射器将事件转换为平衡的值对象。过账服务原子性地验证并写入该分录。报表、子分类账、余额、税表和仪表盘均为分类账的确定性投影。
JournalEntrytext
Sales / Stock / Payroll / Assets / Payments / Grants
-> business event
-> account resolver and posting-rule mapper
-> JournalEntry value object
-> LedgerPostingService::post()
-> append-only journal_entries + journal_lines
-> reports, subledgers, tax schedules, dashboardsRequired Model
必备模型
Core tables:
chart_of_accountsaccount_mappingsjournal_entriesjournal_linesaccounting_periodsposting_rule_versionsaccounting_integrity_runsaccounting_audit_log
Every accounting table MUST carry , unless the product is explicitly single-tenant. If legacy files use , treat it as a project-specific tenant alias and document the mapping.
tenant_idfranchise_id核心表:
chart_of_accountsaccount_mappingsjournal_entriesjournal_linesaccounting_periodsposting_rule_versionsaccounting_integrity_runsaccounting_audit_log
除非产品明确为单租户,否则所有会计表必须包含。如果遗留文件使用,需将其视为项目特定的租户别名,并记录映射关系。
tenant_idfranchise_idPosting Service Contract
过账服务契约
php
<?php
declare(strict_types=1);
final readonly class JournalEntry
{
public function __construct(
public int $tenantId,
public string $idempotencyKey,
public DateTimeImmutable $entryDate,
public string $sourceType,
public string $sourceId,
public string $description,
/** @var list<JournalLine> */
public array $lines,
public ?int $reversesJournalId = null,
) {}
}
final readonly class JournalLine
{
public function __construct(
public int $accountId,
public string $currency,
public string $debitMinor,
public string $creditMinor,
public array $dimensions = [],
) {}
}
interface LedgerPostingService
{
public function post(JournalEntry $entry): PostedJournal;
}The service validates tenant scope, account status, open period, debit-credit equality, currency policy, idempotency, source document state, and mapping completeness before insert.
php
<?php
declare(strict_types=1);
final readonly class JournalEntry
{
public function __construct(
public int $tenantId,
public string $idempotencyKey,
public DateTimeImmutable $entryDate,
public string $sourceType,
public string $sourceId,
public string $description,
/** @var list<JournalLine> */
public array $lines,
public ?int $reversesJournalId = null,
) {}
}
final readonly class JournalLine
{
public function __construct(
public int $accountId,
public string $currency,
public string $debitMinor,
public string $creditMinor,
public array $dimensions = [],
) {}
}
interface LedgerPostingService
{
public function post(JournalEntry $entry): PostedJournal;
}该服务在插入前会验证租户范围、科目状态、期间是否开放、借贷相等性、货币政策、幂等性、源文档状态及映射完整性。
Integrity Checks
完整性检查
Run these per tenant and per accounting period from day one:
- Debits equal credits per .
journal_entry_id - Trial balance total debits equal total credits.
- AR control account equals customer-tagged journal line balance.
- AP control account equals supplier-tagged journal line balance.
- Inventory control account equals stock-on-hand value by item/location/cost layer.
- Fixed asset control account equals asset-register cost less disposals.
- Payroll liability accounts equal unpaid statutory and employee deductions.
- No journal exists in a locked period unless it is a permitted reopening workflow with approval evidence.
- No ledger table has rows written outside the posting service.
- Materialized balances rebuild to the same values as stored cache rows.
从项目启动第一天起,需按租户和会计周期运行以下检查:
- 每个对应的借方等于贷方。
journal_entry_id - 试算表总借方等于总贷方。
- 应收账款控制科目等于带客户标记的日记账分录余额。
- 应付账款控制科目等于带供应商标记的日记账分录余额。
- 库存控制科目等于按商品/位置/成本层计算的在手库存价值。
- 固定资产控制科目等于资产登记成本减去处置额。
- 薪资负债科目等于未支付的法定及员工扣款。
- 锁定期间内不得存在日记账,除非是经批准的重新开启流程并附有审批凭证。
- 所有分类账表的记录均需通过过账服务写入,不得直接写入。
- 物化余额重建后的值需与存储的缓存记录一致。
User Experience Principle
用户体验原则
Non-accountants record business actions: , , , , , , . The system posts accounting behind the scenes. Accountant-facing roles get journals, CoA, mappings, period close, manual journal, and report exports.
Record SaleReceive PaymentBuy StockRun PayrollRecord Asset PurchaseReceive GrantClose Month非会计人员记录业务操作:、、、、、、。系统在后台自动完成会计过账。面向会计人员的角色可查看日记账、CoA(科目表)、映射、期间结账、手动日记账及报表导出。
记录销售接收付款采购库存运行薪资记录资产采购接收拨款月结Companion Skills
配套技能
- for IFRS-aligned industry templates.
chart-of-accounts-templates - for IAS 2 stock valuation and COGS flows.
inventory-costing - for PAYE/NSSF/LST payroll journal shapes.
payroll-postings-uganda - for IAS 16 asset lifecycle.
fixed-assets-and-depreciation - for IAS 21 currency handling.
multicurrency-and-fx - ,
multi-tenant-saas-architecture, andapi-design-firstfor platform integration.advanced-testing-strategy
- :IFRS合规的行业模板。
chart-of-accounts-templates - :IAS 2库存估值及销货成本流程。
inventory-costing - :PAYE/NSSF/LST薪资日记账格式。
payroll-postings-uganda - :IAS 16资产生命周期管理。
fixed-assets-and-depreciation - :IAS 21货币处理。
multicurrency-and-fx - 、
multi-tenant-saas-architecture和api-design-first:平台集成相关。advanced-testing-strategy
References
参考资料
references/posting-engine-contract.mdreferences/integrity-invariants.md
references/posting-engine-contract.mdreferences/integrity-invariants.md