---
title: "ERP Tân Doanh"
url: https://phatdev.net/en/projects/erp-tan-doanh
lang: en
alternate:
  vi: https://phatdev.net/vi/projects/erp-tan-doanh
markdown: https://phatdev.net/en/projects/erp-tan-doanh.md
---

# ERP Tân Doanh

> Internal software for inventory, sales, purchasing, warranty, finance and accounting: an append-only ledger that is reversed, never edited, department-scoped permissions, encrypted backups and weekly restore drills.

- Role: Full-stack · ERP · Accounting
- Status: Internal pilot run
- Technology: Next.js, PostgreSQL, TypeScript, Docker, Playwright
- Docs and changelog: https://phatdev.net/docs/erp-tan-doanh
- All projects: https://phatdev.net/en/projects.md

## Project facts

- Role: Design, development, operations
- Platform: Next.js 16, PostgreSQL 16, Docker
- Scope: Inventory, sales, purchasing, warranty, finance, accounting
- Access: Internal, single sign-on

## Metrics

- 126: business screens
- 120: database migrations
- 60+: tables, ledgers guarded by triggers
- 14: automated browser test suites

## Highlights

- **Write once, reverse never edit**: Stock, cash, obligation and COD ledgers have database triggers that block UPDATE and DELETE. A mistake is fixed with a reversing entry, so every number stays traceable.
- **A closed order lifecycle**: Reservation, dispatch, handover, delivery, COD reconciliation and returns run on one engine; revenue is recognised at successful delivery, with average cost per item and warehouse.
- **Department-scoped permissions**: Permissions are scoped across 6 departments and 4 levels instead of a flat list; delegation needs a reason, an expiry and an approver, and finance actions separate maker from checker.
- **A parallel general ledger**: Journal entries, sales, stock, cash and COD reconciliation, period close and financial statements; running as a draft against the current accounting software before becoming the official ledger.
- **Encrypted backups, restore drills**: Nightly backups plus transaction logs every 30 minutes, encrypted and pushed to a NAS and off-site storage; a restore drill runs weekly and alerts on failure.

## In-depth analysis

ERP Tân Doanh is an app for **inventory, sales, purchasing, warranty, finance and accounting**, built for the Tân Doanh and IGA retail businesses. It is an internal project, in a pilot run and not public.

### The problem
Stock, orders, COD, warranty and ledger figures lived in different places, each calculated its own way. Getting gross margin or carrier receivables meant manual reconciliation, and one wrongly edited old document could skew the numbers with nobody knowing where.

### The solution
One web app, one PostgreSQL database and one rule: **a posted ledger entry is never edited, only reversed**.

#### Inventory and serials
Receipts, issues, transfers and stock counts, scanning by handheld scanner, camera or keyboard. Average cost per item and per warehouse; a warehouse is locked while it is being counted.
#### Sales and COD
Quotes become orders, with stock reservation, dispatch, carrier handover, delivery, COD reconciliation and returns refunded at the discounted price.
#### Purchasing and warranty
Supplier orders, reorder suggestions and receiving against orders. RMA warranty cases link to existing warranty data and compute expiry from the label.
#### Finance and accounting
Cash accounts, receipts and payments, obligations, journal entries, reconciliation and financial statements. Accounting currently runs as a draft in parallel with the existing accounting software.
#### Permissions and data safety
Department-scoped permissions, encrypted backups, weekly restore drills, and business tests that run inside a transaction and roll back so no data is dirtied.

### Status
In an internal pilot with data synced one way from the storefront and warranty systems. Every undecided business rule runs on a pre-selected option listed inside the app, so changing an option changes the reports in a controlled way.

## License

Developed for Tân Doanh.

Source code is not public, all rights reserved. The code of this project is not kept on the web server, so there is no license file to check against.

See the License and credits page: https://phatdev.net/en/licenses.md
