# Inventory API Tests
# Use REST Client extension in VS Code to run these requests

@baseUrl = http://localhost:5000/api
@token = YOUR_AUTH_TOKEN_HERE

### 1. Get Departments
GET {{baseUrl}}/inventory/departments
Authorization: Bearer {{token}}

### 2. List All Inventory Items
GET {{baseUrl}}/inventory/items
Authorization: Bearer {{token}}

### 3. List Inventory Items with Filters
GET {{baseUrl}}/inventory/items?category=STATIONERY&limit=10
Authorization: Bearer {{token}}

### 4. Get Inventory Stats
GET {{baseUrl}}/inventory/stats
Authorization: Bearer {{token}}

### 5. Create Inventory Item
POST {{baseUrl}}/inventory/items
Authorization: Bearer {{token}}
Content-Type: application/json

{
  "name": "Test Item - Marker Pens",
  "code": "TST-001",
  "category": "STATIONERY",
  "description": "Black marker pens for whiteboard",
  "unit": "boxes",
  "quantity": 20,
  "minQuantity": 5,
  "maxQuantity": 50,
  "unitCost": 300,
  "location": "Store Room A",
  "warehouse": "Main Store",
  "department": "ACADEMICS"
}

### 6. Update Inventory Item (replace {itemId} with actual ID)
PATCH {{baseUrl}}/inventory/items/{itemId}
Authorization: Bearer {{token}}
Content-Type: application/json

{
  "quantity": 25,
  "unitCost": 320
}

### 7. Get Single Inventory Item (replace {itemId} with actual ID)
GET {{baseUrl}}/inventory/items/{itemId}
Authorization: Bearer {{token}}

### 8. Create Inventory Transaction
POST {{baseUrl}}/inventory/transactions
Authorization: Bearer {{token}}
Content-Type: application/json

{
  "itemId": "{itemId}",
  "type": "IN",
  "quantity": 10,
  "reason": "New stock received",
  "performedBy": "Admin User"
}

### 9. List Inventory Transactions
GET {{baseUrl}}/inventory/transactions?limit=10
Authorization: Bearer {{token}}

### 10. List Suppliers
GET {{baseUrl}}/inventory/suppliers
Authorization: Bearer {{token}}

### 11. Create Supplier
POST {{baseUrl}}/inventory/suppliers
Authorization: Bearer {{token}}
Content-Type: application/json

{
  "name": "Test Supplier Ltd",
  "contactPerson": "John Test",
  "email": "john@testsupplier.ke",
  "phone": "+254700000000",
  "address": "Test Address, Nairobi",
  "kraPin": "A000000000T",
  "paymentTerms": "Net 30",
  "bankName": "Test Bank",
  "bankAccount": "1234567890",
  "rating": 4.0
}

### 12. Update Supplier (replace {supplierId} with actual ID)
PATCH {{baseUrl}}/inventory/suppliers/{supplierId}
Authorization: Bearer {{token}}
Content-Type: application/json

{
  "rating": 4.5,
  "paymentTerms": "Net 15"
}

### 13. Get Single Supplier (replace {supplierId} with actual ID)
GET {{baseUrl}}/inventory/suppliers/{supplierId}
Authorization: Bearer {{token}}

### 14. Delete Supplier (replace {supplierId} with actual ID)
DELETE {{baseUrl}}/inventory/suppliers/{supplierId}
Authorization: Bearer {{token}}

### 15. List Purchase Orders
GET {{baseUrl}}/inventory/purchase-orders
Authorization: Bearer {{token}}

### 16. List Purchase Orders with Filter
GET {{baseUrl}}/inventory/purchase-orders?status=DRAFT&limit=5
Authorization: Bearer {{token}}

### 17. Create Purchase Order
POST {{baseUrl}}/inventory/purchase-orders
Authorization: Bearer {{token}}
Content-Type: application/json

{
  "supplierId": "{supplierId}",
  "poDate": "2024-01-15",
  "expectedDeliveryDate": "2024-01-22",
  "authorizedBy": "Admin User",
  "notes": "Urgent order for stationery",
  "items": [
    {
      "itemName": "A4 Paper Ream",
      "description": "White A4 paper, 80gsm",
      "quantity": 50,
      "unit": "reams",
      "unitPrice": 450
    },
    {
      "itemName": "Pens (Blue)",
      "description": "Ballpoint pens",
      "quantity": 20,
      "unit": "boxes",
      "unitPrice": 250
    }
  ]
}

### 18. Get Single Purchase Order (replace {poId} with actual ID)
GET {{baseUrl}}/inventory/purchase-orders/{poId}
Authorization: Bearer {{token}}

### 19. Update Purchase Order (replace {poId} with actual ID)
PATCH {{baseUrl}}/inventory/purchase-orders/{poId}
Authorization: Bearer {{token}}
Content-Type: application/json

{
  "expectedDeliveryDate": "2024-01-25",
  "notes": "Updated delivery date"
}

### 20. Update Purchase Order Status (replace {poId} with actual ID)
PATCH {{baseUrl}}/inventory/purchase-orders/{poId}/status
Authorization: Bearer {{token}}
Content-Type: application/json

{
  "status": "APPROVED"
}

### 21. Approve Purchase Order (replace {poId} with actual ID)
POST {{baseUrl}}/inventory/purchase-orders/{poId}/approve
Authorization: Bearer {{token}}

### 22. Receive Purchase Order (replace {poId} with actual ID)
POST {{baseUrl}}/inventory/purchase-orders/{poId}/receive
Authorization: Bearer {{token}}
Content-Type: application/json

{
  "items": [
    {
      "purchaseOrderItemId": "{poItemId}",
      "quantityReceived": 50
    }
  ]
}

### 23. Cancel Purchase Order (replace {poId} with actual ID)
POST {{baseUrl}}/inventory/purchase-orders/{poId}/cancel
Authorization: Bearer {{token}}

### 24. Delete Purchase Order (replace {poId} with actual ID)
DELETE {{baseUrl}}/inventory/purchase-orders/{poId}
Authorization: Bearer {{token}}

### 25. Search Inventory Items
GET {{baseUrl}}/inventory/items?search=paper
Authorization: Bearer {{token}}

### 26. Get Low Stock Items
GET {{baseUrl}}/inventory/items?lowStock=true
Authorization: Bearer {{token}}

### 27. Get Items by Department
GET {{baseUrl}}/inventory/items?department=ACADEMICS
Authorization: Bearer {{token}}

### 28. Get Items by Warehouse
GET {{baseUrl}}/inventory/items?warehouse=Main Store
Authorization: Bearer {{token}}

### 29. Export Inventory Items (CSV)
GET {{baseUrl}}/inventory/items?export=csv
Authorization: Bearer {{token}}

### 30. Get Purchase Order Stats
GET {{baseUrl}}/inventory/purchase-orders/stats
Authorization: Bearer {{token}}

# ============================================================
# SUPPLIER INVOICES
# ============================================================

### 31. List All Invoices
GET {{baseUrl}}/inventory/invoices
Authorization: Bearer {{token}}

### 32. List Invoices with Filters
GET {{baseUrl}}/inventory/invoices?status=PENDING&limit=10
Authorization: Bearer {{token}}

### 33. Get Invoice Stats
GET {{baseUrl}}/inventory/invoices/stats
Authorization: Bearer {{token}}

### 34. Create Invoice
POST {{baseUrl}}/inventory/invoices
Authorization: Bearer {{token}}
Content-Type: application/json

{
  "supplierId": "{supplierId}",
  "purchaseOrderId": "{poId}",
  "invoiceDate": "2026-07-15",
  "dueDate": "2026-08-15",
  "notes": "Payment due within 30 days",
  "items": [
    {
      "itemName": "A4 Paper Ream",
      "description": "80gsm White Paper",
      "quantity": 50,
      "unit": "reams",
      "unitPrice": 450
    },
    {
      "itemName": "Whiteboard Markers",
      "description": "Assorted colors",
      "quantity": 100,
      "unit": "pieces",
      "unitPrice": 80
    }
  ]
}

### 35. Get Single Invoice (replace {invoiceId} with actual ID)
GET {{baseUrl}}/inventory/invoices/{invoiceId}
Authorization: Bearer {{token}}

### 36. Update Invoice (replace {invoiceId} with actual ID)
PATCH {{baseUrl}}/inventory/invoices/{invoiceId}
Authorization: Bearer {{token}}
Content-Type: application/json

{
  "dueDate": "2026-08-20",
  "notes": "Extended payment terms"
}

### 37. Update Invoice Status (replace {invoiceId} with actual ID)
PATCH {{baseUrl}}/inventory/invoices/{invoiceId}/status
Authorization: Bearer {{token}}
Content-Type: application/json

{
  "status": "PAID"
}

### 38. Record Invoice Payment (replace {invoiceId} with actual ID)
POST {{baseUrl}}/inventory/invoices/{invoiceId}/payment
Authorization: Bearer {{token}}
Content-Type: application/json

{
  "paymentDate": "2026-07-20",
  "amount": 25000,
  "paymentMethod": "Bank Transfer",
  "reference": "TXN123456789",
  "notes": "Partial payment"
}

### 39. Delete Invoice (replace {invoiceId} with actual ID)
DELETE {{baseUrl}}/inventory/invoices/{invoiceId}
Authorization: Bearer {{token}}

### 40. Get Overdue Invoices
GET {{baseUrl}}/inventory/invoices?overdue=true
Authorization: Bearer {{token}}

# ============================================================
# GOODS RECEIVED NOTES (GRN)
# ============================================================

### 41. List All GRNs
GET {{baseUrl}}/inventory/grn
Authorization: Bearer {{token}}

### 42. Get GRN Stats
GET {{baseUrl}}/inventory/grn/stats
Authorization: Bearer {{token}}

### 43. Get Pending Items (Items waiting to be received)
GET {{baseUrl}}/inventory/grn/pending
Authorization: Bearer {{token}}

### 44. Create GRN (Receive Goods)
POST {{baseUrl}}/inventory/grn
Authorization: Bearer {{token}}
Content-Type: application/json

{
  "purchaseOrderId": "{poId}",
  "receiptDate": "2026-07-16",
  "receivedBy": "John Kamau",
  "notes": "All items received in good condition",
  "items": [
    {
      "purchaseOrderItemId": "{poItemId1}",
      "quantityReceived": 50,
      "notes": "Perfect condition"
    },
    {
      "purchaseOrderItemId": "{poItemId2}",
      "quantityReceived": 100,
      "notes": ""
    }
  ]
}

### 45. Get Single GRN (replace {grnId} with actual ID)
GET {{baseUrl}}/inventory/grn/{grnId}
Authorization: Bearer {{token}}

### 46. Update GRN (replace {grnId} with actual ID)
PATCH {{baseUrl}}/inventory/grn/{grnId}
Authorization: Bearer {{token}}
Content-Type: application/json

{
  "receivedBy": "Jane Wanjiku",
  "notes": "Updated notes"
}

### 47. Delete GRN (replace {grnId} with actual ID)
# WARNING: This reverses inventory updates
DELETE {{baseUrl}}/inventory/grn/{grnId}
Authorization: Bearer {{token}}

### 48. List GRNs by Purchase Order
GET {{baseUrl}}/inventory/grn?purchaseOrderId={poId}
Authorization: Bearer {{token}}

### 49. List GRNs by Date Range
GET {{baseUrl}}/inventory/grn?fromDate=2026-07-01&toDate=2026-07-31
Authorization: Bearer {{token}}

### 50. Search GRNs by Number
GET {{baseUrl}}/inventory/grn?search=GRN-2026
Authorization: Bearer {{token}}
