# Item-wise Purchase Report - Quick Reference

## 📍 File Locations

```
UZRS-inventory/
└── PurchaseReports/
    ├── item-wise-purchase-report.php          ← Main report page
    ├── print-item-wise-purchase.php           ← Print view
    ├── ITEM_WISE_PURCHASE_REPORT_README.md   ← Full documentation
    ├── api/
    │   └── get-item-wise-purchases.php        ← API endpoint
    ├── css/
    │   └── item-wise-purchase-report.css      ← Styles
    └── js/
        └── item-wise-purchase-report.js       ← JavaScript logic
```

## 🚀 Quick Start

1. **Access URL:**
   ```
   http://localhost/customized/UZRS-inventory/PurchaseReports/item-wise-purchase-report.php
   ```

2. **Or from Dashboard:**
   - Login to UZRS Inventory
   - Go to Purchase Reports Dashboard
   - Click "Item-wise Purchase Report"

## 📊 What This Report Shows

### Summary Cards (Top Section)
1. **Total Items** - Number of unique items purchased
2. **Qty Purchased** - Total quantity purchased in period
3. **Qty Sold** - Total quantity sold in period
4. **Stock Remaining** - Purchased minus Sold
5. **Purchase Value** - Total money spent on purchases
6. **Sold Value** - Total revenue from sales (after discount + tax)
7. **Stock Value** - Value of remaining inventory
8. **Total Invoices** - Number of purchase bills

### Detail Table (Bottom Section)
For each item, shows:
- Purchase quantity and value
- Sales quantity and value
- Remaining stock and its value
- Average rates for purchase and sales

## 🔍 Filters Available

| Filter | Purpose |
|--------|---------|
| **Date Range** | Select period to analyze |
| **Category** | Filter by product category |
| **Item** | View specific item only |
| **Supplier** | Filter by vendor |
| **Purchase Type** | GST/Non-GST/Import purchases |

## ⚡ Quick Date Filters

Click buttons for instant date selection:
- Today
- Yesterday
- This Week
- Last Week
- This Month ← Default
- Last Month
- This Year
- Custom Range

## 💡 Key Features

### 1. Stock Tracking
- **Green** → Items in stock
- **Yellow** → Out of stock
- **Red** → Oversold (sold more than purchased)

### 2. Sales Rate Calculation
The "Avg Sales Rate" column shows the **final selling price** after:
- ✅ Discount applied
- ✅ Tax applied

This matches the actual revenue received per unit.

### 3. Export Options
- **Excel Export** - Download as .xls file
- **Print View** - Professional print layout (A4 landscape)

## 📋 Common Use Cases

### 1. Check Stock Position
```
Filter: This Month (default)
Look at: Stock Remaining column
```

### 2. Analyze Supplier Performance
```
Filter: Select specific supplier
Date: Last 3 months
Look at: Total purchased vs sold
```

### 3. Category-wise Purchase Analysis
```
Filter: Select category
Date: This Year
Look at: Purchase Value vs Sold Value
```

### 4. Item Movement Report
```
Filter: Select specific item
Date: Custom range (e.g., last 6 months)
Look at: All columns to see complete item history
```

## ⚙️ Technical Details

### Database Query
The report uses:
- `tblpurchases` and `tblpurchases_details` for purchase data
- `tblsales` and `tblsales_details` for sales data
- Joins with items, categories, brands, units, suppliers

### Performance
- Uses indexed fields (ProductCode, dates)
- Prepared statements for security
- Efficient subqueries for sales calculations

### Sales Rate Formula
```sql
AVG(sd.FinalRate)  -- This is after discount and tax
```

The `FinalRate` field in `tblsales_details` contains the actual selling price per unit after all calculations.

## 🐛 Troubleshooting

### Report shows "No data"
- Check date range is correct
- Verify purchases exist in that period
- Clear filters and try again

### Sales data not showing
- Sales are only counted if they're in the same date range
- Check if sales records exist in `tblsales_details`

### Supplier filter not working
- Some suppliers might not have a SupplierCode
- System automatically handles both ID and Code

## 📱 Mobile Access

The report is fully responsive:
- Summary cards stack vertically
- Table scrolls horizontally
- Touch-friendly dropdowns

## 🔐 Security

- Requires active user session
- Session UID checked on every page
- SQL injection protected (prepared statements)
- XSS protected (htmlspecialchars on output)

## 📞 Support Information

If you encounter issues:
1. Check browser console for JavaScript errors
2. Verify database connection in config.php
3. Ensure all table structures match documentation
4. Review ITEM_WISE_PURCHASE_REPORT_README.md for detailed info

---

**Created:** November 2025  
**Version:** 1.0  
**Compatible with:** UZRS Inventory System
