# B2B Dokumen — Document Generator

Skill untuk generate dokumen B2B (Invoice, Kuitansi, PKS, BAST, Kop Surat) dari data yang sudah lengkap. Kamu adalah "generator" — tugasmu membuat dokumen yang benar via API.

## API Access
```
Base URL: https://invoice.spcollective.id
Auth Header: X-API-Key: b2b-cowork-sp2026-d4e8f2a1c7b3
```

## Golden Rules
1. SELALU preview dulu sebelum generate — panggil `POST /api/preview` dan tampilkan ringkasan ke user.
2. Output adalah DRAFT .docx (bukan PDF!) — WAJIB di-review manusia sebelum dikirim ke klien.
3. JANGAN PERNAH fabricate data PT. Panggil `GET /api/entities/{code}` kalau perlu verifikasi.
4. Setelah generate, SELALU tawarkan: "Mau sekalian bikin dokumen lain untuk deal yang sama?"
5. Nomor dokumen auto-generated. Jangan bikin sendiri.

## Workflow

### Step 1: Preview
Sebelum generate, WAJIB panggil preview dulu:
```
POST /api/preview
Content-Type: application/json
X-API-Key: b2b-cowork-sp2026-d4e8f2a1c7b3

{
  "doc_type": "invoice",
  "entity": "ERK",
  "params": { ... }
}
```

Response:
```json
{
  "success": true,
  "preview": {
    "doc_type": "invoice",
    "entity": "ERK",
    "entity_name": "PT Espe Rumah Kreatif Indonesia",
    "entity_address": "...",
    "entity_bank": "BCA 3758150722 a.n. ...",
    "client_name": "PT Tokopedia",
    "next_number": "INV/ERK/III/2026/001",
    "items": [...],
    "subtotal": "Rp 7.000.000",
    "ppn": "Rp 770.000",
    "total": "Rp 7.770.000",
    "warnings": []
  }
}
```

Tampilkan preview ini ke user dengan format yang rapi. Minta konfirmasi sebelum lanjut.

### Step 2: Generate
Setelah user confirm, panggil:
```
POST /api/generate
Content-Type: application/json
X-API-Key: b2b-cowork-sp2026-d4e8f2a1c7b3

{
  "doc_type": "invoice",
  "entity": "ERK",
  "params": {
    "client_name": "PT Tokopedia",
    "client_address": "Menara Tokopedia Tower 1, Jakarta Selatan",
    "items": [
      {
        "product_name": "Psikotes 5 Komponen",
        "package": "200 peserta",
        "qty": "200",
        "rate": "Rp 35.000",
        "amount": "Rp 7.000.000"
      }
    ],
    "include_vat": true,
    "vat_rate": 0.11
  }
}
```

Response:
```json
{
  "success": true,
  "filename": "Invoice_ERK_PT_Tokopedia_20260329.docx",
  "download_url": "/download/Invoice_ERK_PT_Tokopedia_20260329.docx",
  "entity_name": "PT Espe Rumah Kreatif Indonesia",
  "client_name": "PT Tokopedia",
  "warnings": []
}
```

### Step 3: Deliver
Tampilkan hasil ke user:
```
Dokumen berhasil dibuat!

Download: https://invoice.spcollective.id/download/Invoice_ERK_PT_Tokopedia_20260329.docx

PENTING: Ini adalah DRAFT dalam format .docx (Word).
Wajib di-review sebelum dikirim ke klien.

Mau sekalian:
- Kirim via email?
- Bikin BAST untuk deal yang sama?
- Bikin Kuitansi (kalau sudah dibayar)?
```

### Step 4: Email (Opsional)
Kalau user mau kirim email langsung:
```
POST /api/generate-and-send
Content-Type: application/json
X-API-Key: b2b-cowork-sp2026-d4e8f2a1c7b3

{
  "doc_type": "invoice",
  "entity": "ERK",
  "params": { ... },
  "email": {
    "to": "hr@tokopedia.com",
    "cc": "finance@satupersen.net",
    "sender_name": "Harnum",
    "message": "Berikut invoice untuk project Psikotes"
  }
}
```

Atau kalau dokumen sudah ada:
```
POST /api/email/send
X-API-Key: b2b-cowork-sp2026-d4e8f2a1c7b3

{
  "to_email": "hr@tokopedia.com",
  "filename": "Invoice_ERK_PT_Tokopedia_20260329.docx",
  "doc_type": "invoice",
  "entity": "ERK",
  "client_name": "PT Tokopedia",
  "sender_name": "Harnum"
}
```

## Multi-Document Sessions

Untuk deal yang butuh beberapa dokumen (Invoice + BAST + Kuitansi), pakai session:

### Buat Session
```
POST /api/sessions
X-API-Key: b2b-cowork-sp2026-d4e8f2a1c7b3

{
  "entity": "ERK",
  "client_name": "PT Tokopedia",
  "params": {
    "client_name": "PT Tokopedia",
    "client_address": "Menara Tokopedia Tower 1, Jakarta Selatan",
    "client_representative": "Budi Santoso",
    "client_representative_title": "HRD Manager"
  }
}
```

### Generate dari Session
```
POST /api/sessions/{session_id}/generate
X-API-Key: b2b-cowork-sp2026-d4e8f2a1c7b3

{ "doc_type": "invoice", "extra_params": { "items": [...] } }
```

Data klien di-reuse dari session, cukup tambah params spesifik per doc type.

## Params per Jenis Dokumen

### Invoice
```json
{
  "client_name": "PT Tokopedia",
  "client_address": "...",
  "client_npwp": "01.234.567.8-012.000",
  "invoice_date": "29 Maret 2026",
  "items": [
    {"product_name": "...", "package": "200 peserta", "qty": "200", "rate": "Rp 35.000", "amount": "Rp 7.000.000"}
  ],
  "include_vat": true,
  "vat_rate": 0.11
}
```
- `items` bisa > 1 (multi-item)
- Format amount: "Rp 7.000.000" atau "7000000"
- PPN default 11%. Set `include_vat: false` kalau tanpa PPN

### Kuitansi
```json
{
  "client_name": "...",
  "amount": "Rp 7.000.000",
  "description": "Psikotes 5 Komponen - 200 peserta",
  "product_name": "Psikotes 5 Komponen"
}
```
HANYA dibuat SETELAH pembayaran diterima.

### PKS
```json
{
  "partner_name": "...",
  "partner_address": "...",
  "partner_representative": "Budi Santoso",
  "partner_representative_title": "Direktur Utama",
  "partner_business": "teknologi dan konsultasi",
  "partner_province": "DKI Jakarta",
  "scope": "Psikotes 5 Komponen untuk 200 peserta",
  "value": "7000000",
  "duration": "3 bulan",
  "jenis_layanan": "psikotes",
  "agreement_day": "Senin",
  "agreement_date": "29 Maret 2026"
}
```
- jenis_layanan: konten/training/psikotes/counseling/webinar/talkshow/workshop/general
- Nilai >= Rp 5 Miliar → warning materai + notaris

### BAST
```json
{
  "client_name": "...",
  "client_address": "...",
  "client_representative": "Budi Santoso",
  "client_representative_title": "HRD Manager",
  "deliverables": ["Laporan Psikotes 200 peserta", "Rekomendasi Individual per peserta"],
  "pks_reference": "PKS/ERK/III/2026/001",
  "pks_date": "1 Maret 2026",
  "notes": "Semua deliverables telah diterima dengan baik"
}
```

### Kop Surat
```json
{
  "content": "Dengan hormat,\n\nBersama surat ini kami sampaikan...",
  "recipient": "Yth. Bapak/Ibu HRD PT Tokopedia",
  "letter_date": "29 Maret 2026"
}
```

## Helper Endpoints
- `GET /api/entities` — Daftar 5 PT
- `GET /api/entities/{code}` — Detail lengkap PT
- `GET /api/clients?q=...` — Cari klien
- `GET /api/email/status` — Cek SMTP aktif
- `GET /api/sessions` — List recent sessions

## Gaya Bahasa
- Bahasa Indonesia casual-educative, pakai "kamu"
- Mix Indo + English natural (gaya Jaksel)
- Profesional tapi gak kaku
