Inventory & Warehouse Management
Dokumentasi lengkap sistem inventory dan warehouse management di MStore Backend dengan support multi-warehouse, batch tracking, dan real-time stock movement.π― Overview
Sistem inventory MStore dirancang dengan prinsip:- β Multi-Warehouse: Support distribution center & warehouse per branch
- β Merchant-Scoped: Isolasi data per merchant
- β Movement-Based: Stock derived dari inventory movements
- β Batch Tracking: FIFO/FEFO untuk lot & expiry management
- β Reserved Quantity: Alokasi untuk sales order
- β Real-time Sync: Automatic stock update dari transactions
- β Transfer Management: Inter-warehouse transfer dengan approval
ποΈ Architecture
π Data Model
1. Inventory Master
- β Kolom
stockDIHAPUS - stok dihitung dariwarehouse_stocks - β Merchant-scoped - unique SKU per merchant
- β Multi-type - raw material, finished good, service
2. Warehouses
- Distribution Center (DC): Pusat distribusi, supply ke warehouse lain
- Warehouse: Gudang per branch untuk operasional
3. Warehouse Stocks
- qty_on_hand: Stok fisik tersedia
- qty_reserved: Stok dialokasikan (SO pick/packing)
- Available Stock =
qty_on_hand - qty_reserved
4. Inventory Movements
- Positif (+): Stock IN (purchase, transfer in, production receipt)
- Negatif (-): Stock OUT (sales, transfer out, production issue)
- Atomic: Setiap movement WAJIB update
warehouse_stocks
5. Inventory Batches
- FIFO: First In First Out (default)
- FEFO: First Expired First Out (untuk item dengan expiry)
6. Inventory Transfers
π Movement Flow
Purchase Receipt (Penerimaan Pembelian)
Code Example:Sales Issue (Pengeluaran Penjualan)
Code Example:Inter-Warehouse Transfer
Transfer Flow:- Draft β Requested: User membuat transfer request
- Requested β Approved: Manager/Admin approve
- Approved β In Transit:
- Create movement OUT (
transfer_out, qty negatif) di source warehouse - Reduce
qty_on_handdi source
- Create movement OUT (
- In Transit β Received:
- Create movement IN (
transfer_in, qty positif) di destination warehouse - Increase
qty_on_handdi destination
- Create movement IN (
π¦ Batch Management (FIFO/FEFO)
FIFO Selection
FEFO Selection (First Expired First Out)
π Stock Queries
Get Available Stock per Warehouse
Get Stock per Branch (Aggregate)
Movement History
π§ͺ Testing Scenarios
Scenario 1: Purchase Receipt
Scenario 2: Sales Issue with Insufficient Stock
Scenario 3: Inter-Warehouse Transfer
π‘ Best Practices
DO β
- Selalu gunakan transaction untuk movement + stock update
- Implement FIFO/FEFO untuk batch selection
- Check stock availability sebelum issue
- Log semua movement dengan reference yang jelas
- Use reserved quantity untuk sales order allocation
- Validate warehouse type untuk transfer rules
- Implement approval flow untuk transfer antar warehouse
- Monitor stock level untuk reorder point
DONβT β
- Jangan update
warehouse_stockstanpa create movement - Jangan skip stock availability check
- Jangan allow transfer dari/ke warehouse yang sama
- Jangan hardcode warehouse_id
- Jangan ignore batch expiry date
- Jangan skip transaction untuk atomic operations
- Jangan allow negative stock (kecuali policy khusus)
π Troubleshooting
Problem: Stock Mismatch
Symptoms: Stock di UI tidak match dengan fisik Solution:Problem: Transfer Stuck in In Transit
Symptoms: Transfer tidak bisa di-receive Solution:π Related Documentation
Transaction Flow
Integrasi inventory dengan transaksi POS
Approval Flow
Approval untuk transfer & adjustment
Database Schema
ERD lengkap inventory tables
Need Help? Contact backend team atau check GitHub Issues