# Enterprise Architecture

```text
Dynamics NAV / BC14
   ├── Items API ───────────────┐
   ├── Vendors API ─────────────┤
   ├── Vendor Items API ────────┤
   ├── Locations API ───────────┤
   ├── Inventory API ───────────┤
   ├── Sales API ───────────────┤
   ├── Purchase History API ────┤
   ├── Open PO API ─────────────┤
   ├── Transfers API ───────────┤
   └── Offers API ──────────────┤
                                 ▼
                         Sync / Staging Layer
                                 ▼
                         MySQL PO_* Database
                                 │
           ┌─────────────────────┼──────────────────────┐
           ▼                     ▼                      ▼
   Forecast Engine      Replenishment Engine       AI Advisor
           │                     │                      │
           └──────────────┬──────┴───────────────┬─────┘
                          ▼                      ▼
                    Transfer Advice       Purchase Advice
                                                  ▼
                                         Vendor Consolidation
                                                  ▼
                                         Auto Draft / Full Auto
                                                  ▼
                                           Approval / Validation
                                                  ▼
                                           Outbound Queue
                                                  ▼
                                        NAV Create PO API
```

## Design principles
- PO system database is operationally independent from NAV.
- NAV remains financial/accounting master and final transaction system.
- No UI query should run against NAV directly.
- All heavy analytics use the PO database.
- Incremental sync, paging, retries, idempotency, audit trail.
- Forecast is item × location × date, not item-only.
- Calendar supports Gregorian + Hijri + events; historical same-Hijri-period comparison.
- Transfer-before-buy logic prevents unnecessary external purchasing.
- Auto PO is controlled per vendor and globally.

## Enterprise Extension v2 — Vendor/Supplier 360

تمت إضافة بوابة مورد منفصلة ومؤمنة. لا يعتمد الوصول على vendor_id مرسل من المتصفح؛ بل يتم اشتقاق المورد من Bearer Token مرتبط بـ `PO_vendor_users`، لذلك لا يستطيع المورد تغيير parameter لرؤية مورد آخر.

الوحدات الجديدة: Vendor 360 Dashboard، Daily Sales by vendor item، Inventory/Quantity Movement Ledger، Open/Overdue PO، PO acknowledgement، ASN، Receipts، Contract Compliance، Budget Control data model، Service Level targets، Item Substitutes، Data Quality Engine، Anomaly Detection، What-if Simulation، Enterprise Control Tower، Notifications.

المزامنة الجديدة بقيت منفصلة حسب Domain: `ERP_INVENTORY_MOVEMENTS` و`ERP_PURCHASE_RECEIPTS` أضيفتا كـ endpoints مستقلة. فشل أي Domain لا يوقف Inventory أو Sales أو Vendor أو PO Sync.
