Skip to main content

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

Key Points:
  • ❌ Kolom stock DIHAPUS - stok dihitung dari warehouse_stocks
  • βœ… Merchant-scoped - unique SKU per merchant
  • βœ… Multi-type - raw material, finished good, service

2. Warehouses

Warehouse Types:
  • Distribution Center (DC): Pusat distribusi, supply ke warehouse lain
  • Warehouse: Gudang per branch untuk operasional

3. Warehouse Stocks

Key Concepts:
  • qty_on_hand: Stok fisik tersedia
  • qty_reserved: Stok dialokasikan (SO pick/packing)
  • Available Stock = qty_on_hand - qty_reserved

4. Inventory Movements

Movement Rules:
  • 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

Batch Policies:
  • 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:
  1. Draft β†’ Requested: User membuat transfer request
  2. Requested β†’ Approved: Manager/Admin approve
  3. Approved β†’ In Transit:
    • Create movement OUT (transfer_out, qty negatif) di source warehouse
    • Reduce qty_on_hand di source
  4. In Transit β†’ Received:
    • Create movement IN (transfer_in, qty positif) di destination warehouse
    • Increase qty_on_hand di destination
Code Example:

πŸ“¦ 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_stocks tanpa 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:

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