# 🎯 Purchase Return - Quick Reference Card

## Stock Operations Quick Guide

```
┌──────────────────────────────────────────────────────┐
│                 STOCK OPERATIONS                      │
├──────────────────────────────────────────────────────┤
│                                                       │
│  CREATE PURCHASE      Stock: ↑ INCREASE              │
│  CREATE RETURN        Stock: ↓ DECREASE              │
│                                                       │
│  EDIT PURCHASE        Old: ↓ New: ↑                  │
│  EDIT RETURN          Old: ↑ New: ↓                  │
│                                                       │
│  DELETE PURCHASE      Stock: ↓ RESTORE               │
│  DELETE RETURN        Stock: ↑ RESTORE               │
│                                                       │
│  PURCHASE → RETURN    Old: ↓ New: ↓ (Double-)        │
│  RETURN → PURCHASE    Old: ↑ New: ↑ (Double+)        │
│                                                       │
└──────────────────────────────────────────────────────┘
```

## Supplier Account Quick Guide

```
┌──────────────────────────────────────────────────────┐
│              SUPPLIER ACCOUNTS                        │
├──────────────────────────────────────────────────────┤
│                                                       │
│  PURCHASE             Credit → Balance ↑             │
│                       (We owe supplier)               │
│                                                       │
│  RETURN               Debit → Balance ↓              │
│                       (Supplier owes us)              │
│                                                       │
│  Balance > 0          We owe supplier                │
│  Balance < 0          Supplier owes us               │
│  Balance = 0          All settled                    │
│                                                       │
└──────────────────────────────────────────────────────┘
```

## Invoice Prefixes

```
┌─────────────────────────────────────────────┐
│  TYPE              PREFIX     EXAMPLE        │
├─────────────────────────────────────────────┤
│  GST               PGST       PGST/2025-26/001│
│  NON-GST           PNGST      PNGST/2025-26/001│
│  IMPORT            PIMP       PIMP/2025-26/001│
│                                              │
│  GST-RETURN        PGSTR      PGSTR/2025-26/001│
│  NON-GST-RETURN    PNGSTR     PNGSTR/2025-26/001│
│  IMPORT-RETURN     PIMPR      PIMPR/2025-26/001│
└─────────────────────────────────────────────┘
```

## Edit Operation Matrix

```
┌────────────────────────────────────────────────────────┐
│  EDIT SCENARIO          STOCK        BALANCE           │
├────────────────────────────────────────────────────────┤
│  Purchase: +Qty         ↑↑           ↑↑ (more credit) │
│  Purchase: -Qty         ↓            ↓  (less credit) │
│  Return: +Qty           ↓↓           ↓↓ (more debit)  │
│  Return: -Qty           ↑            ↑  (less debit)  │
│  Purchase → Return      ↓↓ (x2)      ↓↓ (reverse)     │
│  Return → Purchase      ↑↑ (x2)      ↑↑ (reverse)     │
└────────────────────────────────────────────────────────┘
```

## Delete Operation Matrix

```
┌────────────────────────────────────────────────────────┐
│  DELETE TYPE       STOCK EFFECT      BALANCE EFFECT    │
├────────────────────────────────────────────────────────┤
│  Delete Purchase   ↓ Restore         ↓ Remove Credit  │
│  Delete Return     ↑ Restore         ↑ Remove Debit   │
└────────────────────────────────────────────────────────┘
```

## Example Calculations

### Example 1: Edit Purchase (Increase Qty)
```
Initial: Purchase 10 units @ ₹100 = ₹1,000
Edit to: 20 units @ ₹100 = ₹2,000

Stock:
  Before Edit: 110 (100 + 10)
  Reverse Old: -10 → 100
  Apply New:   +20 → 120 ✅

Balance:
  Before Edit: ₹1,000 (Credit - we owe)
  After Edit:  ₹2,000 (Credit - we owe) ✅
```

### Example 2: Edit Return (Increase Qty)
```
Initial: Return 5 units @ ₹200 = ₹1,000
Edit to: 10 units @ ₹200 = ₹2,000

Stock:
  Before Edit: 95 (100 - 5)
  Reverse Old: +5 → 100
  Apply New:   -10 → 90 ✅

Balance:
  Before Edit: ₹4,000 (was ₹5,000 - ₹1,000 debit)
  After Edit:  ₹3,000 (₹5,000 - ₹2,000 debit) ✅
```

### Example 3: Change Type (Purchase → Return)
```
Initial: Purchase 8 units @ ₹100 = ₹800
Change to: Return 8 units @ ₹100 = ₹800

Stock:
  Before Edit: 108 (100 + 8)
  Reverse Purchase: -8 → 100
  Apply Return: -8 → 92 ✅

Balance:
  Before Edit: ₹800 (Credit - we owe)
  After Edit:  -₹800 (Debit - they owe us) ✅
```

## Quick Test Queries

### Check Stock
```sql
SELECT ItemCode, CurrentStock FROM tblitems WHERE ItemCode = 'ITEM001';
```

### Check Supplier Balance
```sql
SELECT SupplierName, OutstandingBalance FROM tblsuppliers WHERE ID = 1;
```

### Check Recent Returns
```sql
SELECT InvoiceNumber, PurchaseType, FinalAmount 
FROM tblpurchases 
WHERE PurchaseType LIKE '%-PURCHASE-RETURN' 
ORDER BY ID DESC LIMIT 5;
```

### Check Account Entries
```sql
SELECT TransactionType, Amount, Description 
FROM tblsupplier_accounts 
WHERE SupplierID = 1 
ORDER BY ID DESC LIMIT 10;
```

## Visual Indicators

```
┌──────────────────────────────────────────────────┐
│  IN THE SYSTEM:                                   │
│                                                   │
│  Regular Purchase Type:  [Normal Dropdown]        │
│  Return Type:            [Yellow Background] ⚠️   │
│                                                   │
│  Notification: "⚠️ Purchase Return mode activated│
│                 - Stock will be decreased"        │
└──────────────────────────────────────────────────┘
```

## Common Mistakes to Avoid

❌ **DON'T** create return as negative quantity purchase
✅ **DO** use return types (GST-PURCHASE-RETURN, etc.)

❌ **DON'T** manually adjust stock after return
✅ **DO** let system handle stock automatically

❌ **DON'T** worry about supplier negative balance
✅ **DO** understand negative = they owe us / we have credit

## Troubleshooting

### Stock Not Updating?
- Check ProductID is valid
- Check transaction completed (no errors)
- Verify in tblitems.CurrentStock

### Balance Incorrect?
- Check TransactionType (Debit vs Credit)
- Sum all Credits - Debits should = OutstandingBalance
- Run balance verification query

### Edit Not Working?
- Check you're in edit mode (Previous/Next navigation)
- Verify editingPurchaseId is set
- Check browser console for errors

## Remember

> **The Golden Rule:**  
> Always reverse old transaction before applying new one!

> **Stock Rule:**  
> Purchases: IN (+) | Returns: OUT (-)

> **Account Rule:**  
> Purchases: Credit (↑) | Returns: Debit (↓)

---

**Quick Help:** See PURCHASE_RETURN_IMPLEMENTATION.md for full details  
**Version:** 1.0 | **Date:** Nov 4, 2025
