# Stock Dashboard - Understanding the Data

## ❓ Why You Saw "14" Instead of "6"

### The Problem:
You have **6 products** in your warehouse stock, but the old dashboard was showing **14 Total Stacks**.

### Why?
The old dashboard was counting **PRODUCT RECORDS** in the database, not **ACTUAL STOCK QUANTITIES**.

**Example:**
- Product A: 5 units in warehouse
- Product B: 3 units in warehouse  
- Product C: 8 units in warehouse

**Old Dashboard (WRONG):**
- Total Stacks: 3 (counted 3 products)

**New Dashboard (CORRECT):**
- Total Stock: 16 units (5 + 3 + 8)

---

## ✅ NEW Dashboard - Now Shows Correct Data!

### What You'll See Now:

#### **Overall Stock Summary:**

```
📊 Description              Quantity
─────────────────────────────────────
Total Stock in Warehouses:     6      ← This is the actual stock count!
🟢 Available Stock (For Sale): 4      ← Products with tosell=1
🔴 Sold Stock (Not For Sale):  2      ← Products with tosell=0
─────────────────────────────────────
Number of Different Products:  3
Total Stock Value:            $XXX
```

#### **If You Filter by Color (e.g., "Red"):**

```
Summary                    Quantity   Percentage
─────────────────────────────────────────────────
Total Stock (Red):            6         100%
🟢 Available Stock:           4         66.7%
🔴 Sold Stock:                2         33.3%
```

---

## 📋 Key Differences

### Old Dashboard (stack_details.php):
❌ Counted **number of product records**
❌ Showed 14 because you have 14 products in database
❌ Did NOT show actual warehouse stock quantities

### New Dashboard (stock_dashboard.php):
✅ Shows **actual stock quantities** from warehouses
✅ Shows 6 because that's the real stock count
✅ Calculates from `product_stock.reel` field
✅ Splits by Available vs Sold status

---

## 🌐 How to Access New Dashboard

**URL:**
```
http://localhost/admin_crm/htdocs/product/stock_dashboard.php
```

**Bookmark this URL** - This is the correct dashboard to use!

---

## 📊 Understanding the Numbers

### Example Scenario:

**You have these products:**

| Product | Color | Stock Qty | Status (For Sale) |
|---------|-------|-----------|-------------------|
| Product A | Red | 5 | Yes ✅ |
| Product B | Red | 3 | Yes ✅ |
| Product C | Red | 2 | No ❌ (Sold) |
| Product D | Blue | 8 | Yes ✅ |
| Product E | Blue | 4 | No ❌ (Sold) |

---

**When NO filter (All Colors):**

```
Total Stock: 22 units (5+3+2+8+4)
🟢 Available: 16 units (5+3+8)
🔴 Sold: 6 units (2+4)
```

**When Filter by "Red":**

```
Total Stock (Red): 10 units (5+3+2)
🟢 Available: 8 units (5+3)
🔴 Sold: 2 units
📊 Percentage: 80% Available, 20% Sold
```

---

## 🎯 What Each Field Means

### **Total Stock in Warehouses**
- Sum of all physical quantities in your warehouses
- Calculated from: `product_stock.reel`
- This is your actual inventory count

### **🟢 Available Stock**
- Stock that is still **available for sale**
- Products where `tosell = 1`
- This is what customers can buy

### **🔴 Sold/Reserved Stock**
- Stock marked as **not for sale**
- Products where `tosell = 0`
- Could be sold, reserved, or discontinued

### **Number of Different Products**
- How many unique products have stock
- Not the quantity, but the variety

### **Total Stock Value**
- Stock quantity × Purchase price (PMP)
- Financial value of your inventory

---

## 💡 How to Use

### **1. Check Total Stock:**
- Open dashboard
- See "Total Stock in Warehouses"
- This is your current inventory

### **2. Check Available Stock:**
- Look at "🟢 Available Stock"
- This is what you can sell

### **3. Filter by Color:**
- Select color from dropdown (e.g., "Red")
- Click Search
- See stock breakdown for that color only

### **4. View Details:**
- Scroll down to see individual products
- Each product shows:
  - Stock quantity
  - Status (On Sale / Sold)
  - Value

---

## 🔄 How to Update Stock

### **To Add/Reduce Stock:**
1. Go to Stock → Stock Movements
2. Create movement (add or remove stock)

### **To Mark as Sold:**
1. Edit the product
2. Set "Status for sale" = No
3. Save

### **To Mark as Available:**
1. Edit the product
2. Set "Status for sale" = Yes
3. Save

---

## 📁 Files

### ✅ **USE THIS:**
- `htdocs/product/stock_dashboard.php` - **NEW** (correct data)

### ❌ **OLD (Don't Use):**
- `htdocs/product/stack_details.php` - OLD (wrong counts)

---

## 🎉 Summary

**The new dashboard now shows:**
- ✅ **Actual stock quantities** (6 units, not 14 products)
- ✅ **Available vs Sold** split
- ✅ **Color filtering** works correctly
- ✅ **Real warehouse data** from product_stock table

**Access:** http://localhost/admin_crm/htdocs/product/stock_dashboard.php

---

**Created:** 2026-04-29
**Updated:** 2026-04-29 (Fixed to show actual stock quantities)
