# Zota ERP — Complete System Diagram

A Mermaid flowchart of the whole platform: the multi-tier supply chain spine
(Store → Warehouse → Supplier → Manufacturer), the full ERP each tier runs, the
Tier-A pharma-compliance and Tier-B WMS overlays on the warehouse, and the
cross-cutting platform / finance / HRM / integration layers.

```mermaid
flowchart TB

%% ============================================================
%%  ZOTA ERP — MULTI-TIER PHARMACEUTICAL CHAIN ERP (MySalesERP fork)
%% ============================================================

%% ---------- PLATFORM / SaaS ----------
subgraph PLAT["🏛️ Platform · SaaS Control (Superadmin)"]
  direction TB
  SA["Superadmin<br/>Packages · Subscriptions · Pricing"]
  RBAC["Users · Roles · Permissions<br/>(granular warehouse.* perms)"]
  PAY["Payment Gateways<br/>PesaPal · MyFatoorah"]
  OVS["Cross-Warehouse Oversight<br/>& Management"]
end

%% ---------- CENTRAL MASTERS ----------
subgraph MAST["🗂️ Central Masters (shared across all tiers)"]
  direction TB
  PROD["Products · Variations · Batches"]
  CAT["Categories · Brands · Units"]
  CON["Contacts<br/>Customers / Suppliers"]
  TAX["Tax / GST · Business Locations"]
end

%% ---------- SUPPLY-CHAIN SPINE ----------
subgraph CHAIN["🔗 Multi-Tier Supply-Chain Spine"]
  direction LR
  STORE["🏬 STORE<br/>(Business)"]
  WH["🏭 WAREHOUSE<br/>(Business)"]
  SUP["🚚 SUPPLIER PORTAL<br/>(Business)"]
  TPM["⚗️ THIRD-PARTY MFR<br/>login-less · email"]
end

%% auto-replenishment flow (upstream demand)
STORE -- "low stock → Auto-Requisition" --> AREQ["⚙️ Auto-Requisition Engine"]
AREQ -- "Auto-PO" --> WH
WH -- "Σ store min/max → Auto-PO" --> SUP
SUP -- "Auto-PO (email)" --> TPM

%% fulfilment flow (downstream supply)
WH -- "Sales-Order mirror" --> SOM["Sales Order → POS Bill + Ship"]
SOM -- "dispatch" --> STORE
TPM -- "ship goods" --> SUP
SUP -- "ship goods" --> WH

MAST -. "masters synced" .-> CHAIN
PLAT -. "provisions / governs" .-> CHAIN

%% ---------- FULL ERP RUN BY EACH TIER ----------
subgraph ERP["🧩 Full ERP (run by Store & Warehouse)"]
  direction TB

  subgraph PROC["📦 Procurement"]
    PR["Purchase Requisition"]
    PO["Purchase Order"]
    GRN["Goods Receipt (GRN)"]
    PUR["Purchase"]
    PRET["Purchase Return / Combined"]
    PR --> PO --> GRN --> PUR --> PRET
  end

  subgraph SELL["🛒 Sales & POS"]
    POS["POS Terminal"]
    INV["Invoice / Sell"]
    SO["Sales Order · Quotation"]
    SRET["Sell Return · Shipping"]
    CR["Cash Register · Commission"]
    SO --> INV --> POS --> SRET
    POS --> CR
  end

  subgraph STOCK["📊 Inventory & Stock"]
    OPN["Opening Stock"]
    ADJ["Adjustment · Transfer"]
    BATCH["Batch & Expiry (FEFO)"]
    MTAG["Movement Tags"]
    VAL["Stock Valuation & Ledger"]
    OPN --> BATCH
    ADJ --> VAL
    BATCH --> VAL
    MTAG --> VAL
  end
end

%% ---------- WAREHOUSE OVERLAY: WMS (Tier-B) ----------
subgraph WMS["🏭 Warehouse WMS · Tier-B"]
  direction TB
  BIN["Bin Locations<br/>per-bin × batch sub-ledger"]
  QC["Inbound GRN → QC / Quarantine"]
  DISP["Dispatch · Consignment · POD"]
  CYC["Cycle Counting"]
  REV["Reverse Logistics (returns → TPM)"]
  REB["Inter-Warehouse Rebalancing"]
  QC --> BIN --> DISP
  CYC --> BIN
  REV --> BIN
  REB --> BIN
end

%% ---------- WAREHOUSE/PHARMACY OVERLAY: COMPLIANCE (Tier-A) ----------
subgraph PHARMA["⚕️ Pharma Compliance · Tier-A"]
  direction TB
  TRACE["Batch Traceability & Recall"]
  SCHED["Schedule-Drug Register"]
  LIC["Drug-License Dispatch Guard"]
  COLD["Cold-Chain Log"]
  EINV["E-Invoice / E-Way Bill (>₹50K)"]
  TRACE --> SCHED
  LIC --> DISP
  COLD --> DISP
  EINV --> DISP
end

%% ---------- FINANCE ----------
subgraph FIN["💰 Finance & Accounting"]
  direction TB
  COA["Chart of Accounts · Journals"]
  LED["Ledgers · Reconcile · Budgets"]
  EXP["Payments · Expenses"]
  GSTR["GST / Tax Reports"]
  COA --> LED --> GSTR
  EXP --> LED
end

%% ---------- REPORTS ----------
subgraph REP["📈 Reports & Dashboard"]
  direction TB
  RSPS["Sales / Purchase / Stock"]
  RPL["Profit & Loss · Tax"]
  RPHARM["Pharma Registers"]
  DASH["Unified ERP Dashboard (Highcharts)"]
end

%% ---------- HRM ----------
subgraph HRM["👥 HRM · Essentials"]
  direction TB
  ATT["Attendance · Shifts · Leave"]
  PYR["Payroll · Allowances"]
  TODO["To-Do · Reminders · Docs"]
  TGT["Sales Targets · Messaging"]
end

%% ---------- MODULES / INTEGRATION ----------
subgraph MODS["🔌 Modules & API"]
  direction TB
  API["Connector — REST API"]
  ACC["Accounting Module"]
  ASSET["Asset Management"]
  SPREAD["Spreadsheet"]
  TICKET["Support Ticket"]
end

%% ---------- CROSS-CUTTING WIRING ----------
STORE --> ERP
WH --> ERP
WH --> WMS
WH --> PHARMA

PROC --> STOCK
SELL --> STOCK
STOCK --> FIN
PROC --> FIN
SELL --> FIN

BATCH --> TRACE
BATCH --> BIN
DISP --> SRET
FIN --> REP
STOCK --> REP
PHARMA --> RPHARM

MODS -. "extends" .-> ERP
API -. "external systems" .-> MAST
HRM -. "staff ops" .-> STORE
HRM -. "staff ops" .-> WH

%% ---------- STYLES ----------
classDef plat  fill:#efe9fb,stroke:#8a4fd0,color:#241,font-weight:600;
classDef mast  fill:#e8ecfb,stroke:#3b56c4,color:#182233,font-weight:600;
classDef chain fill:#12203a,stroke:#2f5aa0,color:#ffffff,font-weight:700;
classDef proc  fill:#e2f5f5,stroke:#0e8f8f,color:#0b3b3b;
classDef sales fill:#e7f6ec,stroke:#1a9e4b,color:#0b3b1f;
classDef inv   fill:#fff3d6,stroke:#d69100,color:#5a3d00;
classDef wms   fill:#ffe9d6,stroke:#e2680f,color:#5a2c00;
classDef pharm fill:#fde3e7,stroke:#c8243a,color:#5a0d18;
classDef fin   fill:#e4eefb,stroke:#2563b0,color:#0d2d52;
classDef rep   fill:#eceff4,stroke:#556579,color:#232f3d;
classDef hrm   fill:#fbe4ef,stroke:#c0417a,color:#4d1230;
classDef mod   fill:#f3ead9,stroke:#9a6a2f,color:#3d2a10;
classDef eng   fill:#fff8cf,stroke:#c99700,color:#3d2a00,font-weight:700;

class SA,RBAC,PAY,OVS plat;
class PROD,CAT,CON,TAX mast;
class STORE,WH,SUP,TPM,SOM chain;
class PR,PO,GRN,PUR,PRET proc;
class POS,INV,SO,SRET,CR sales;
class OPN,ADJ,BATCH,MTAG,VAL inv;
class BIN,QC,DISP,CYC,REV,REB wms;
class TRACE,SCHED,LIC,COLD,EINV pharm;
class COA,LED,EXP,GSTR fin;
class RSPS,RPL,RPHARM,DASH rep;
class ATT,PYR,TODO,TGT hrm;
class API,ACC,ASSET,SPREAD,TICKET mod;
class AREQ eng;
```

## Legend

| Layer | Role |
|-------|------|
| 🏛️ Platform · SaaS | Superadmin tenant control, RBAC, gateways, cross-warehouse oversight |
| 🗂️ Central Masters | Products/batches/contacts/tax shared across every tier |
| 🔗 Supply-Chain Spine | Store → Warehouse → Supplier → Third-Party Manufacturer, with auto-replenishment upstream and fulfilment downstream |
| 🧩 Full ERP | Procurement, Sales & POS, Inventory — run by both Store and Warehouse businesses |
| 🏭 Warehouse WMS (Tier-B) | Bins, GRN QC/quarantine, dispatch/POD, cycle count, reverse logistics, rebalancing |
| ⚕️ Pharma Compliance (Tier-A) | Batch traceability/recall, schedule-drug register, drug-license guard, cold-chain, e-invoice/e-way |
| 💰 Finance · 📈 Reports · 👥 HRM · 🔌 Modules | Cross-cutting: accounting, analytics, staff ops, Connector API + add-on modules |

## Key auto-flows
- **Upstream demand:** Store low-stock → Auto-Requisition → Auto-PO to Warehouse → (Σ store min/max) Auto-PO to Supplier → Auto-PO (email) to TPM.
- **Downstream supply:** TPM → Supplier → Warehouse → Sales-Order mirror → POS bill + ship → Store GRN.
- **Compliance gate:** dispatch is guarded by drug-license, cold-chain, and e-invoice/e-way checks before goods leave the warehouse.
