Order History Page
Route: /orders
File: app/orders/page.tsx
Page Ka Maqsad
Order History page par shop ki saari past sales/transactions record hoti hain. Purani bills search kar sakte hain, dobara print kar sakte hain, ya galat order delete kar sakte hain (stock wapas restore hoga).
Page Layout
┌─────────────────────────────────────────────────────┐
│ Order History │
├─────────────────────────────────────────────────────┤
│ Search: [Search by invoice number...] │
├─────────────────────────────────────────────────────┤
│ Invoice # | Date | Payment | Amount | Actions │
│ INV-00123 | ... | Cash | ₨45,000| 🖨️ 🗑️ │
│ INV-00122 | ... | Card | ₨12,000| 🖨️ 🗑️ │
└─────────────────────────────────────────────────────┘
Kya Kar Sakte Hain?
| Action | Kaise |
|---|---|
| Saari orders dekhna | Page open — last 100 orders (newest first) |
| Invoice search | Search bar — invoice number se |
| Invoice detail dekhna | 🖨️ Print icon → preview dialog |
| Invoice print | Preview dialog → Print Invoice |
| Order delete | 🗑️ Delete icon → confirm → delete |
Orders Table Columns
| Column | Description |
|---|---|
| Invoice Number | Unique bill ID (e.g. INV-00001) |
| Date | Sale date aur time (MMM dd, yyyy HH:mm) |
| Payment Method | cash / card / mobile payment |
| Total Amount | Bill ka total (currency symbol ke saath) |
| Actions | Print aur Delete buttons |
Search
- Invoice number se search (
ilike— partial match) - Example: "INV-001" se related saari invoices filter
- Search empty → last 100 orders dikhti hain
Print Invoice
Print flow Sales page jaisa hi hai:
- 🖨️ icon click
- Sale items fetch (
sale_items+ product details) - Preview dialog open:
- Shop name, address, phone
- Invoice number + barcode
- Product list with prices
- Total amount
- Print Invoice → browser print window
Delete Order
Confirmation Dialog (Urdu + English)
Kya aap is order ko delete karna chahte hain?
Invoice: INV-00001
Amount: ₨45,000
Note: Stock automatically restore ho jayega.
Delete Process
1. sale_items se products aur quantities fetch
2. Har product ka stock RESTORE (+quantity)
- Pehle RPC: increment_stock try
- Fallback: direct products table update
3. sales record DELETE
- sale_items CASCADE se auto delete
4. Activity log: "Order deleted: INV-00001 - ₨45,000"
5. Products aur sales queries refresh
Important: Order delete karne se stock wapas inventory mein aa jata hai.
Data Limits
- Default: last 100 orders fetch hoti hain
- Sorted by:
created_atdescending (newest first)
Empty States
| Condition | Message |
|---|---|
| Koi order nahi | "No orders yet" |
| Search match nahi | "No orders found" |
| Loading | "Loading orders..." |
Activity Logging
Order delete par log entry:
Action: delete
Entity: order
Description: "Order deleted: INV-00001 - ₨45,000"
Use Cases
| Scenario | Action |
|---|---|
| Customer ne purani bill maangi | Search → Print |
| Galat bill ban gaya | Delete → stock restore → nayi sale |
| Daily sales verify | List browse karein |
| Specific invoice dhundhna | Invoice number search |
Related Pages
- Sales (POS) — nayi sales yahan se create hoti hain
- Dashboard — Recent bills widget → "View all" yahan aata hai
- Inventory — delete par stock yahan restore hota hai