# Stack Details Dashboard - Color-wise Stock & Sales Tracking

## 📊 Overview

A comprehensive dashboard that tracks your product stacks by **COLOR** showing:
- **Total Stacks Count** - All products of each color
- **Sold Stacks** - Products that have been sold (marked as not for sale)
- **Balance Stacks** - Products still available (for sale)
- **Color-wise Filtering** - Filter by specific color to see detailed breakdown

## 🎯 Features

### 1. Color Filter
- Dropdown to select specific color
- Shows all available colors from your products
- Click filter to see color-specific data

### 2. Overall Summary
Shows for selected color (or all colors):
- **Total Stacks** - Count of all products
- **Sold Stacks** - Products with status "Not for Sale" (tosell = 0)
- **Balance Stacks** - Products still "For Sale" (tosell = 1)

### 3. Breakdown by Color (When no filter applied)
Table showing all colors with:
- Color name
- Total stacks for that color
- Sold stacks count
- Balance stacks count
- Percentage of total

### 4. Detailed Product List
Shows each product with:
- Product reference and name
- Color
- Current stock quantity
- Status (On Sale / Sold)
- Selling price

### 5. Sales vs Balance Detail (When color filtered)
Detailed breakdown showing:
- Total count for that color
- Sold count with percentage
- Balance count with percentage
- Visual color indicators (Red = Sold, Green = Balance)

## 🌐 How to Access

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

## 📋 How to Use

### Step 1: Ensure Products Have Color Extrafield

1. Go to **Setup → Products/Services → Extra fields**
2. Make sure you have a `color` extrafield created:
   - **Code:** `color`
   - **Label:** `Color`
   - **Type:** `Varchar (Text)` or `List`
   - **Size:** `255`

### Step 2: Add Colors to Your Products

When creating/editing products:
1. Scroll to **Extra fields** section
2. Enter the color (e.g., "Red", "Blue", "Green", "Black")
3. Save the product

### Step 3: Mark Products as Sold

When a product/stack is sold:
1. Edit the product
2. Set **"Status for sale"** to **No** (tosell = 0)
3. Save

### Step 4: View Stack Details

1. Open the dashboard
2. See overall summary at top
3. **To filter by color:**
   - Select color from dropdown
   - Click Search
   - View detailed breakdown for that color
4. **To see all colors:**
   - Click "Remove Filter"
   - View complete breakdown table

## 📊 Example Usage

### Example: Red Products

**Scenario:**
- You have 6 Red products total
- 2 are sold (tosell = 0)
- 4 are still available (tosell = 1)

**What you'll see:**

**Overall Summary:**
```
Total Stacks:    6
Sold Stacks:     2  (in red)
Balance Stacks:  4  (in green)
```

**Sales vs Balance Detail:**
```
Summary         Count    Percentage
Total Stacks    6        100%
🔴 Sold         2        33.3%
🟢 Balance      4        66.7%
```

**Product List:**
```
Product              Color   Stock   Status      Price
Red Widget A         Red     5       On Sale     $10.00
Red Widget B         Red     0       Sold        $10.00
Red Widget C         Red     3       On Sale     $12.00
Red Widget D         Red     0       Sold        $12.00
Red Widget E         Red     7       On Sale     $15.00
Red Widget F         Red     2       On Sale     $15.00
```

## 🎨 Color Status Indicators

- 🔴 **Red** = Sold Stacks (tosell = 0)
- 🟢 **Green** = Balance/Available Stacks (tosell = 1)

## 📈 Understanding the Data

### How "Sold" is Calculated:
- Products where **Status for sale = No** (tosell = 0)
- This means the product has been sold/discontinued

### How "Balance" is Calculated:
- Products where **Status for sale = Yes** (tosell = 1)
- This means the product is still available for sale

### Stock Quantity:
- Shows actual physical stock from warehouse
- Calculated from product_stock table

## 💡 Tips

1. **Keep colors consistent:** Use the same color names (e.g., always "Red" not sometimes "red" or "RED")

2. **Use color lists:** Consider making the color extrafield a dropdown list with predefined colors

3. **Regular updates:** Update product status (tosell) immediately when items are sold

4. **Filter often:** Use color filter to quickly check specific product lines

5. **Monitor balance:** Check balance stacks regularly to know what's available

## 📁 Files Created

- `htdocs/product/stack_details.php` - Main dashboard file

## 🔧 Requirements

- Dolibarr 18.x or later
- Products module enabled
- Stock module enabled  
- Color extrafield on products
- Admin or product read permissions

## 🎯 Common Use Cases

### 1. Quick Stock Check
- Select color from filter
- Instantly see how many are available vs sold

### 2. Sales Report by Color
- Remove all filters
- See breakdown table with all colors
- Identify which colors sell best

### 3. Inventory Planning
- Check balance stacks
- Know which colors need restocking

### 4. Customer Inquiry
- Customer asks: "Do you have Red in stock?"
- Filter by Red color
- See balance count immediately

---

**Created:** 2026-04-29
**Version:** 1.0
