# Saudi Invoice Layout - Database Setup (Urdu Guide)

## Aasan Tareeqa (3 Steps)

### Step 1: Database Mein Saudi Layout Add Karein

**phpMyAdmin Use Karein:**

1. **phpMyAdmin open karein** (usually: http://127.0.0.1/phpmyadmin)
2. **Left side se apna database select karein** (jis mein aapka POS data hai)
3. **Upar "SQL" tab click karein**
4. **Neeche diya hua code copy karke paste karein:**

```sql
INSERT INTO invoice_layouts (
    business_id, name, invoice_heading, footer_text, design,
    show_logo, show_business_name, show_location_name,
    show_landmark, show_city, show_state, show_zip_code, show_country,
    show_mobile_number, show_alternate_number, show_email,
    show_tax_1, show_tax_2, show_barcode, show_qr_code,
    qr_code_fields, table_product_label, table_qty_label,
    table_unit_price_label, table_subtotal_label, invoice_no_prefix,
    common_settings, created_at, updated_at
) VALUES (
    1, 'Saudi Invoice', 'فاتورة ضريبية / TAX INVOICE',
    'شكراً لتعاملكم معنا | Thank you for your business',
    'saudi-invoice', 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1,
    '["business_name","tax_1","invoice_no","invoice_datetime","total_amount","customer_name"]',
    'الصنف / Product', 'الكمية / Qty', 'السعر / Price', 'الإجمالي / Total',
    'INV', '{"show_qr_code_label":true}', NOW(), NOW()
);
```

5. **"Go" button click karein**
6. **Success message aayega:** "1 row inserted" ✅

### Step 2: Layout ID Check Karein

Yeh command run karein:

```sql
SELECT id, name, design FROM invoice_layouts WHERE design = 'saudi-invoice';
```

**Result mein aapko milega:**
- id: 5 (ya koi aur number - yeh note kar lein)
- name: Saudi Invoice
- design: saudi-invoice

### Step 3: Location Ko Assign Karein

Apni layout ID (maan lo 5 hai) aur location ID (usually 1) use karke:

```sql
UPDATE business_locations 
SET invoice_layout_id = 5
WHERE id = 1;
```

**Note:** Agar aapke multiple locations hain, to har location ke liye alag se run karein.

## Check Karein Sab Sahi Hai

Yeh commands run karke verify karein:

```sql
-- Invoice layout check karein
SELECT id, name, design, show_logo, show_qr_code 
FROM invoice_layouts 
WHERE design = 'saudi-invoice';

-- Location assignment check karein
SELECT id, name, invoice_layout_id 
FROM business_locations;
```

## Logo Upload Karein

Database setup ke baad:

1. **Browser mein jaaein:** Settings → Invoice Layouts
2. **"Saudi Invoice" dhundein** list mein
3. **"Edit" button click karein**
4. **Logo upload karein:**
   - File choose karein (PNG format best hai)
   - Size: 200x80 pixels recommended
   - Transparent background better hai
5. **"Save" button click karein**

## Test Karein

1. **POS Pro page open karein**
2. **Koi test sale complete karein**
3. **Invoice automatically open hoga**
4. **Check karein:**
   - ✅ Green colors dikh rahe hain?
   - ✅ Arabic aur English text hai?
   - ✅ Logo dikh raha hai? (agar upload kiya ho)
   - ✅ QR code dikh raha hai?
   - ✅ Layout professional hai?

## Agar Problem Ho

### Layout Dropdown Mein Nahi Dikh Raha?

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

Ya page refresh karein (Ctrl+F5)

### Design Apply Nahi Ho Raha?

Check karein design field:
```sql
SELECT id, name, design FROM invoice_layouts;
```

Agar `saudi-invoice` nahi hai, to update karein:
```sql
UPDATE invoice_layouts 
SET design = 'saudi-invoice' 
WHERE name = 'Saudi Invoice';
```

### QR Code Nahi Dikh Raha?

QR settings check karein:
```sql
SELECT show_qr_code, qr_code_fields 
FROM invoice_layouts 
WHERE design = 'saudi-invoice';
```

Agar 0 hai ya NULL hai, to update karein:
```sql
UPDATE invoice_layouts 
SET show_qr_code = 1,
    qr_code_fields = '["business_name","tax_1","invoice_no","invoice_datetime","total_amount","customer_name"]'
WHERE design = 'saudi-invoice';
```

### Logo Nahi Dikh Raha?

1. Check karein logo upload hua hai Settings se
2. File exist karti hai: `public/uploads/invoice_logos/` mein
3. Database mein check karein:
```sql
SELECT logo, show_logo FROM invoice_layouts WHERE design = 'saudi-invoice';
```

## Purana Layout Rakhna Hai?

Agar aap purana layout bhi rakhna chahte hain aur Saudi ko naya add karna chahte hain:

✅ **INSERT command naya layout banata hai** - purana safe rahega
✅ **Settings se switch kar sakte hain** layouts ke beech
✅ **Har location alag layout use kar sakta hai**

Layout switch karne ke liye:
```sql
-- Sab layouts dekhein
SELECT id, name FROM invoice_layouts;

-- Location ko layout assign karein
UPDATE business_locations 
SET invoice_layout_id = LAYOUT_KI_ID
WHERE id = LOCATION_KI_ID;
```

## Purane Layout Ko Saudi Mein Convert Karein

Agar aap existing layout ko hi Saudi design mein convert karna chahte hain:

```sql
-- Apni existing layout update karein (id = 1 ko apni layout id se replace karein)
UPDATE invoice_layouts 
SET design = 'saudi-invoice',
    name = 'Saudi Invoice',
    invoice_heading = 'فاتورة ضريبية / TAX INVOICE',
    footer_text = 'شكراً لتعاملكم معنا | Thank you for your business',
    show_logo = 1,
    show_qr_code = 1,
    show_barcode = 0,
    qr_code_fields = '["business_name","tax_1","invoice_no","invoice_datetime","total_amount","customer_name"]',
    table_product_label = 'الصنف / Product',
    table_qty_label = 'الكمية / Qty',
    table_unit_price_label = 'السعر / Price',
    table_subtotal_label = 'الإجمالي / Total'
WHERE id = 1;
```

## Complete Checklist

Setup karte waqt yeh sab check karein:

- [ ] INSERT SQL command run kiya
- [ ] Layout create ho gaya (SELECT se verify kiya)
- [ ] Location ko layout assign kiya
- [ ] Logo upload kiya Settings se
- [ ] VAT number set kiya (Settings → Business Settings)
- [ ] Test sale kiya
- [ ] Logo check kiya
- [ ] QR code check kiya
- [ ] Colors aur layout verify kiya

## Files Jo Maine Banayi Hain

1. **quick_add_saudi_layout.sql** - Simple INSERT command (yeh use karein)
2. **add_saudi_invoice_layout.sql** - Detailed version with all fields
3. **setup_saudi_invoice.sql** - Existing layout update karne ke liye
4. **SAUDI_LAYOUT_DATABASE_GUIDE.md** - English detailed guide
5. **DATABASE_SETUP_URDU.md** - Yeh file (Urdu guide)

## Quick Reference

**Ek Baar Mein Sab Commands:**

```sql
-- 1. Layout add karein
INSERT INTO invoice_layouts (business_id, name, design, show_logo, show_qr_code, qr_code_fields, created_at, updated_at)
VALUES (1, 'Saudi Invoice', 'saudi-invoice', 1, 1, '["business_name","tax_1","invoice_no","invoice_datetime","total_amount"]', NOW(), NOW());

-- 2. Layout ID dekhein
SELECT id FROM invoice_layouts WHERE design = 'saudi-invoice';

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

-- 4. Verify karein
SELECT * FROM invoice_layouts WHERE design = 'saudi-invoice';
```

## Important Notes

1. **business_id:** Usually 1 hoti hai, agar multiple businesses hain to check karein
2. **location_id:** Usually 1 hoti hai, agar multiple locations hain to sahi ID use karein
3. **Logo:** Upload Settings UI se karein, database mein manually add karne ki zaroorat nahi
4. **QR Code Fields:** Customize kar sakte hain apni zaroorat ke hisaab se

## VAT Number Set Karna

Saudi invoice ke liye VAT number zaroori hai:

1. **Settings → Business Settings** mein jaaein
2. **Tax tab** click karein
3. **Tax Label 1:** "VAT Number" ya "الرقم الضريبي" likhein
4. **Tax Number 1:** Apna 15-digit VAT number enter karein
   - Example: 300000000000003
5. **Save** karein

## Summary

**Teen Aasan Steps:**

1. ✅ **SQL command run karein** (INSERT wala)
2. ✅ **Logo upload karein** (Settings se)
3. ✅ **Test sale karein** (POS Pro se)

**Result:** Professional Saudi-style invoice with logo, QR code, bilingual text! 🇸🇦

Agar koi problem ho to:
- Diagnostic tool use karein: `http://127.0.0.1:8001/sells/{transaction_id}/diagnostic`
- Laravel logs check karein: `storage/logs/laravel.log`
- Yeh guide dobara padhein

**All the best!** ✨
