# Saudi Invoice Layout - Automatic Setup (Urdu)

## Automatic Installation - Ek Command Mein!

Maine ek Laravel migration file banayi hai jo **automatically** Saudi invoice layout ko database mein add kar degi.

## Kaise Run Karein

### Sabse Aasan Tareeqa:

1. **Command Prompt ya Terminal open karein**
2. **Apne project folder mein jaaein** (jahan artisan file hai)
3. **Yeh command run karein:**

```bash
php artisan migrate
```

**Bas! Ho gaya!** ✅

## Yeh Command Kya Karega?

Migration automatically yeh sab karega:
- ✅ Database mein Saudi Invoice layout add karega
- ✅ Logo setting enable karega
- ✅ QR code setting enable karega
- ✅ Arabic/English labels set karega
- ✅ Design template set karega (saudi-invoice)
- ✅ QR code fields configure karega
- ✅ Success message dikhayega

## Migration Ke Baad

### Step 1: Check Karein Layout Ban Gaya

**Database mein check karein:**
```sql
SELECT id, name, design FROM invoice_layouts WHERE design = 'saudi-invoice';
```

**Ya UI mein check karein:**
- Settings → Invoice Layouts mein jaaein
- List mein "Saudi Invoice - فاتورة سعودية" dikhega

### Step 2: Location Ko Assign Karein

**Option A: UI Se (Aasan)**
1. Settings → Business Locations
2. Edit button click karein
3. Invoice Layout dropdown se "Saudi Invoice - فاتورة سعودية" select karein
4. Save karein

**Option B: SQL Se (Fast)**
```sql
-- Pehle layout ID nikaalein
SELECT id FROM invoice_layouts WHERE design = 'saudi-invoice';

-- Location ko assign karein (5 ko apni layout ID se replace karein)
UPDATE business_locations SET invoice_layout_id = 5 WHERE id = 1;
```

### Step 3: Logo Upload Karein

1. Settings → Invoice Layouts
2. "Saudi Invoice - فاتورة سعودية" dhundein
3. Edit click karein
4. Logo upload karein (PNG, 200x80px best hai)
5. Save karein

### Step 4: Test Karein

1. POS Pro open karein
2. Test sale complete karein
3. Invoice check karein:
   - ✓ Green colors
   - ✓ Arabic/English text
   - ✓ Logo
   - ✓ QR code
   - ✓ Professional design

## Agar Wapas Karna Ho (Rollback)

Saudi invoice layout delete karne ke liye:

```bash
php artisan migrate:rollback --step=1
```

Yeh command Saudi invoice layout ko database se remove kar dega.

## Troubleshooting

### "Nothing to migrate" Message Aaya?

Matlab migration pehle hi run ho chuka hai. Check karein:

```sql
SELECT * FROM invoice_layouts WHERE design = 'saudi-invoice';
```

Agar result aaya to layout already exist karta hai - seedha Step 2 pe jaaein.

### Migration Fail Ho Gaya?

**Logs check karein:**
```
storage/logs/laravel.log
```

**Common Problems:**

1. **Database connection error**
   - `.env` file check karein
   - Database credentials sahi hain?

2. **Table doesn't exist**
   - Pehle sab migrations run karein: `php artisan migrate`

3. **Duplicate entry**
   - Layout already exist karta hai
   - Rollback karke dobara run karein

### Dobara Run Karna Hai?

1. **Pehle rollback karein:**
```bash
php artisan migrate:rollback --step=1
```

2. **Phir run karein:**
```bash
php artisan migrate
```

## Migration File Kya Karta Hai?

File: `database/migrations/2026_02_27_035546_add_saudi_invoice_layout.php`

**Yeh automatically karta hai:**

1. ✅ Aapki business ID nikalta hai
2. ✅ Naya invoice layout banata hai: "Saudi Invoice - فاتورة سعودية"
3. ✅ Design set karta hai: "saudi-invoice"
4. ✅ Logo display enable karta hai
5. ✅ QR code display enable karta hai
6. ✅ QR code fields set karta hai:
   - business_name (Company name)
   - tax_1 (VAT number)
   - invoice_no (Invoice number)
   - invoice_datetime (Date/time)
   - total_amount (Total amount)
   - customer_name (Customer name)
7. ✅ Bilingual labels set karta hai (Arabic/English)
8. ✅ Invoice heading set karta hai: "فاتورة ضريبية / TAX INVOICE"
9. ✅ Footer text set karta hai (Thank you message)
10. ✅ Success message log karta hai

## Important Commands

```bash
# Migration run karein
php artisan migrate

# Migration status check karein
php artisan migrate:status

# Last migration rollback karein
php artisan migrate:rollback --step=1

# Cache clear karein
php artisan cache:clear
php artisan config:clear
```

## Success Message

Migration successful hone par aapko yeh dikhega:

```
Migrating: 2026_02_27_035546_add_saudi_invoice_layout
✅ Saudi Invoice Layout created successfully!
Layout ID: 5
To use this layout, go to: Settings → Business Locations → Edit → Select 'Saudi Invoice'
Migrated:  2026_02_27_035546_add_saudi_invoice_layout (XX.XXms)
```

## Complete Process (Summary)

### Ek Baar Mein Sab Kuch:

1. **Terminal open karein**
2. **Project folder mein jaaein**
3. **Command run karein:**
   ```bash
   php artisan migrate
   ```
4. **Success message dekh kar confirm karein**
5. **Settings → Invoice Layouts → Edit → Logo upload karein**
6. **Settings → Business Locations → Edit → Layout select karein**
7. **POS Pro se test sale karein**
8. **Invoice check karein**

**Done! Bas 5 minutes mein!** ⚡

## Files Jo Banayi Gayi Hain

- ✅ **Migration:** `database/migrations/2026_02_27_035546_add_saudi_invoice_layout.php`
- ✅ **Template:** `resources/views/sale_pos/receipts/saudi-invoice.blade.php`
- ✅ **Guides:**
  - RUN_SAUDI_MIGRATION.md (English)
  - AUTO_SETUP_URDU.md (Yeh file - Urdu)
  - SAUDI_INVOICE_SETUP.md (Features guide)
  - SAUDI_INVOICE_URDU_GUIDE.md (User guide)

## Checklist

Migration ke baad yeh sab check karein:

- [ ] Migration successfully run hua?
- [ ] Layout database mein add hua?
- [ ] Settings mein "Saudi Invoice" dikh raha hai?
- [ ] Logo upload kiya?
- [ ] Location ko layout assign kiya?
- [ ] Test sale kiya?
- [ ] Invoice mein logo dikh raha hai?
- [ ] QR code dikh raha hai?
- [ ] Colors green hain?
- [ ] Arabic/English text hai?

## Agar Koi Problem Ho

1. **Laravel logs check karein:** `storage/logs/laravel.log`
2. **Database check karein:** phpMyAdmin mein `invoice_layouts` table
3. **Cache clear karein:** `php artisan cache:clear`
4. **Migration status check karein:** `php artisan migrate:status`
5. **Diagnostic tool use karein:** `/sells/{transaction_id}/diagnostic`

## Alternative Method (Agar Migration Nahi Chala)

Agar kisi wajah se migration command nahi chal raha, to:

1. **phpMyAdmin open karein**
2. **`quick_add_saudi_layout.sql` file ka content copy karein**
3. **SQL tab mein paste karke run karein**
4. **Same result milega!**

## Summary

**Sabse Aasan Tareeqa:**
```bash
php artisan migrate
```

**Phir:**
1. Logo upload karein
2. Location assign karein
3. Test karein

**Result:** Professional Saudi invoice ready! 🇸🇦

Enjoy! ✨
