1.TSTOCKPOSITION vs TRESERVATION - > how it is connected? Answer: TSTOCKPOSITION = (Stock on hand) TRESERVATION = (Reservation/Booking) ->this connects through TRESERVATION TSTOCKPOSITION (Physical Stock) ↓ RESERVEDQUANTITY (Increase) ↓ TRESERVATION (Reservation Record) CONNECTION LOGIC: UPDATE TSTOCKPOSITION SET RESERVEDQUANTITY = RESERVEDQUANTITY + @Quantity -- need to reserve in stock WHERE OUID = @OUId AND ITEMID = @ItemId AND SKUID = @SKUId AND STOREID = @StoreId AND (QUANTITY - RESERVEDQUANTITY) >= @Quantity -- need to check whether the needed stock is there 2. how the reservation knows the how many stock are ther in position? -- TSTOCKPOSITION haveing total quantity SELECT OUID, ITEMID, SKUID, STOREID, QUANTITY, -- Total physical stock RESERVEDQUANTITY, -- Already reserved (QUANTITY - RESERVEDQUANTITY) AS AVAILABLE -- Available to reserve FROM TSTOCKPOSITION WHERE OUID = -1 AND ITEMID = -1 AND SKUID = -1 AND STOREID = -1; Result: QUANTITY = 8.0000 (Total) RESERVEDQUANTITY = 8.0000 (Already booked) AVAILABLE = 0.0000 (Nothing left to book) 3.Is Position table parent ? No! Neither is parent. They are related but independent tables: TSTOCKPOSITION (Stock Position) ↓ (update) TRESERVATION (Reservation) Not Parent-Child, but Reference relationship Relationship: TSTOCKPOSITION = Tracks physical stock (how many items physically exist) TRESERVATION = Tracks commitments (how many are promised to customers) Think of it like: TSTOCKPOSITION = Bank Account Balance (8,000 rupees) TRESERVATION = Cheques issued (2,000 rupees issued) Available = 8,000 - 2,000 = 6,000 rupees left 4. Is Reservation table final stock ? or Is Position table final stock a? Position table is the source of truth for physical stock. TSTOCKPOSITION = Real physical stock (8 items in warehouse) TRESERVATION = Only shows booked items (2 items booked) Flow: 1.Physical stock enters → TSTOCKPOSITION 2.Customer orders → TRESERVATION (book from stock) 3.Stock decreases in TSTOCKPOSITION (RESERVEDQUANTITY increases) 4.When delivered → ISSUEDQUANTITY increases in TRESERVATION Final stock is TSTOCKPOSITION: Available Stock = QUANTITY - RESERVEDQUANTITY ┌─────────────────────────────────────────────────────────┐ │ STOCK SOURCE FLOW │ ├─────────────────────────────────────────────────────────┤ │ │ │ 1. TSTOCKPOSITION (Physical Stock) │ │ ┌──────────────────────────────────────────┐ │ │ │ OUID=-1, ITEMID=-1, SKUID=-1, STOREID=-1│ │ │ │ QUANTITY = 8.0000 │ │ │ │ RESERVEDQUANTITY = 0.0000 │ │ │ └──────────────────────────────────────────┘ │ │ ↓ │ │ 2. User Requests Reservation │ │ ReservedQuantity = 2.0000 │ │ ↓ │ │ 3. Check Availability │ │ (QUANTITY - RESERVEDQUANTITY) >= 2.0000 │ │ (8 - 0) >= 2 │ │ ↓ │ │ 4. UPDATE TSTOCKPOSITION │ │ RESERVEDQUANTITY = 0 + 2 = 2.0000 │ │ ↓ │ │ 5. INSERT TRESERVATION │ │ STOCKRESERVATIONID = 10 │ │ RESERVEDQUANTITY = 2.0000 │ │ ↓ │ │ Final State: │ │ TSTOCKPOSITION: QUANTITY=8, RESERVED=2, AVAILABLE=6 │ │ TRESERVATION: RESERVED=2, ISSUED=0 │ └─────────────────────────────────────────────────────────┘