# Stock Update Fix Plan

## Task: Fix stock not updating after sale

### Issues Identified:
1. Product field uses product NAME (string) - case-sensitive lookup could fail
2. Sales Dashboard Edit form uses text input instead of dropdown
3. No fallback stock decrement in controller if observer fails
4. No stock restoration when sales/invoices are deleted

### Fixes Implemented:
- [x] 1. SalesDashboardController store() - Added direct stock decrement with case-insensitive product lookup
- [x] 2. SalesDashboardController update() - Added stock restoration for old product AND decrement for new product with case-insensitive lookup
- [x] 3. SalesDashboard edit view - Changed product text input to dropdown
- [x] 4. InvoiceController store() - Added direct stock decrement as backup
- [x] 5. InvoiceController destroy() - Added stock restoration before delete
- [x] 6. SalesDashboardController destroy() - Added stock restoration before delete with case-insensitive lookup

### Completed:
All fixes have been applied to ensure stock updates properly after sales.
