# Quick Guide: Custom Code Text untuk Brand

## 🎯 Tujuan Fitur

Fitur ini memungkinkan Anda **meng-customize text yang tampil di bawah barcode** untuk setiap label, khusus untuk bagian brand/company.

## 📸 Contoh Visual

**Sebelum (Otomatis):**
```
┌────────────────────────┐
│  ||||||||||||||||||||  │ ← Barcode
│  DEXADBS5G002TH26      │ ← Text tanpa spasi
│                        │
│     DEXA * DBS         │ ← Title
└────────────────────────┘
```

**Setelah (Custom):**
```
┌────────────────────────┐
│  ||||||||||||||||||||  │ ← Barcode
│  DEXA DBS 5G002TH26    │ ← Text dengan spasi (custom!)
│                        │
│     DEXA * DBS         │ ← Title
└────────────────────────┘
```

## ⚡ Cara Cepat (3 Langkah)

### 1. Buka Form Label
```
http://localhost/barcode/public/labels/create
```

### 2. Isi Data
- **Company**: DEXA
- **Product**: DBS
- **Item Code**: 5G002TH26
- **Custom Text di Bawah Barcode**: `DEXA DBS 5G002TH26` ← Isi ini!

### 3. Lihat Preview
Preview akan langsung menampilkan custom text Anda!

---

## 💡 Contoh Format Custom

### Format 1: Dengan Spasi
```
Input: DEXA DBS 5G002TH26
Hasil: DEXA DBS 5G002TH26
```

### Format 2: Dengan Dash
```
Input: DEXA-DBS-5G002TH26
Hasil: DEXA-DBS-5G002TH26
```

### Format 3: Dengan Bullet
```
Input: DEXA • DBS • 5G002TH26
Hasil: DEXA • DBS • 5G002TH26
```

### Format 4: Hanya Kode
```
Input: 5G002TH26
Hasil: 5G002TH26
```

### Format 5: Custom Brand
```
Input: DEXA GROUP | DBS | 5G002TH26
Hasil: DEXA GROUP | DBS | 5G002TH26
```

---

## 🔧 Fitur

✅ **Live Preview** - Lihat hasil langsung saat mengetik
✅ **Optional** - Kosongkan untuk format otomatis
✅ **Flexible** - Support semua karakter
✅ **Per Label** - Setiap label bisa beda format
✅ **200 Karakter** - Panjang maksimal

---

## 📋 Field Form

| Field | Required | Max Length | Keterangan |
|-------|----------|------------|------------|
| Company | Ya | 60 | Nama perusahaan/brand |
| Product | Ya | 60 | Kode produk |
| Item Code | Ya | 120 | Kode seri |
| **Custom Text** | **Tidak** | **200** | **Text di bawah barcode** |
| Barcode Value | Tidak | 190 | Isi barcode (otomatis) |
| Title | Tidak | 120 | Judul besar (otomatis) |

---

## 🎨 Use Cases

### Case 1: Brand dengan Multi-Word Company
```
Company: INERTIA UTAMA
Product: ABC
Item Code: 10G123TH50

❌ Format otomatis (susah dibaca):
INERTIAUTAMAABC10G123TH50

✅ Custom dengan spasi:
INERTIA UTAMA ABC 10G123TH50
```

### Case 2: Konsistensi Format Brand
```
Semua produk DEXA menggunakan format:
DEXA <PRODUCT> <CODE>

Contoh:
- DEXA DBS 5G002TH26
- DEXA DBS 5G003TH26
- DEXA ABC 10G100TH50
```

### Case 3: Kode Pendek untuk Label Kecil
```
Untuk label ukuran kecil, tampilkan kode saja:

Custom Text: 5G002TH26

Hasil:
┌──────────────┐
│ |||||||||||||| │
│ 5G002TH26     │
│   DEXA * DBS  │
└──────────────┘
```

---

## ⚙️ Logika Format

```
Prioritas rendering text di bawah barcode:

1. Custom Text (jika diisi)
   ↓
2. Config BARCODE_CODE_TEXT_NO_SPACE=true
   → Tampilkan tanpa spasi
   ↓
3. Format otomatis dengan spasi
   → DEXA DBS 5G002TH26
```

---

## 🧪 Testing

### Test 1: Live Preview
1. Buka form create label
2. Isi Company, Product, Item Code
3. Ketik di "Custom Text di Bawah Barcode"
4. **Preview harus update setelah 0.5 detik**

### Test 2: Save & Print
1. Isi form dengan custom text
2. Klik "Simpan Label"
3. Klik "Cetak"
4. **Text di PDF harus sesuai custom text**

### Test 3: Edit Label
1. Edit label yang ada
2. Isi custom text
3. Save
4. **Custom text harus tersimpan**

### Test 4: Bulk Input
1. Toggle "Bulk Input"
2. Masukkan multiple codes
3. **Semua label menggunakan format yang sama**
   (untuk custom per code, perlu isi manual satu-satu)

---

## 🐛 Troubleshooting

### Preview tidak update
```bash
# Clear cache
php artisan view:clear
php artisan config:clear

# Reload browser dengan Ctrl+F5
```

### Custom text tidak tersimpan
```
Check:
1. Maksimal 200 karakter
2. Database migration sudah jalan
3. Model sudah di-update
```

### Custom text tidak tampil di print
```bash
# Clear view cache
php artisan view:clear

# Restart browser
```

---

## 📊 Database

### Tabel: `labels`

| Kolom | Type | Nullable | Default |
|-------|------|----------|---------|
| id | bigint | No | auto |
| company | varchar(60) | No | - |
| product | varchar(60) | No | - |
| item_code | varchar(120) | No | - |
| barcode_value | varchar(190) | No | - |
| title | varchar(120) | No | - |
| **custom_code_text** | **varchar(200)** | **Yes** | **NULL** |
| barcode_type | varchar(30) | No | code128 |
| qty | int | No | 1 |

---

## 🚀 Migration Status

✅ Migration created: `2026_08_04_040237_add_custom_code_text_to_labels_table.php`
✅ Migration run: SUCCESS
✅ Column added: `custom_code_text`

---

## 📝 Tips

1. **Untuk readability**: Gunakan spasi
2. **Untuk brand consistency**: Set format standar
3. **Untuk label kecil**: Tampilkan kode saja
4. **Untuk multi-brand**: Custom per brand

---

## ✅ Checklist Implementasi

- [x] Database migration
- [x] Model update (fillable + accessor)
- [x] Form field added
- [x] JavaScript live preview
- [x] Controller preview support
- [x] Validation rules
- [x] Documentation

---

## 📚 Dokumentasi Lengkap

Lihat: `FITUR_CUSTOM_CODE_TEXT.md` untuk dokumentasi teknis lengkap.

---

**Status**: ✅ READY FOR USE  
**Version**: 1.0  
**Date**: August 4, 2026
