# Testing API Laporan Keuangan

## Setup

1. Jalankan migration dan seeder:
```bash
php artisan migrate:fresh --seed
```

2. Generate API token:
```bash
php artisan api:generate-token admin@masjid.com
```

3. Start server:
```bash
php artisan serve
```

## Token untuk Testing

```
Bearer 1|OlQpsU5YGhzU1WgJDJjmp2Mys5E22RN0A0hzayCJe2d53ac6
```

## Test Endpoints

### 1. Ringkasan Keuangan

**Request:**
```bash
GET http://127.0.0.1:8000/api/v1/masjid/1/laporan/ringkasan
Authorization: Bearer {token}
```

**PowerShell:**
```powershell
Invoke-WebRequest -Uri "http://127.0.0.1:8000/api/v1/masjid/1/laporan/ringkasan" -Headers @{"Authorization"="Bearer 1|OlQpsU5YGhzU1WgJDJjmp2Mys5E22RN0A0hzayCJe2d53ac6"} | Select-Object -ExpandProperty Content
```

**Response:**
```json
{
  "type": "ringkasan_keuangan",
  "data": {
    "periode": "2026-02",
    "total_pemasukan": 5150000,
    "total_pengeluaran": 700000,
    "saldo_akhir": 4450000,
    "jumlah_transaksi": 8
  }
}
```

### 2. List Transaksi

**Request:**
```bash
GET http://127.0.0.1:8000/api/v1/masjid/1/laporan/transaksi?per_page=3
Authorization: Bearer {token}
```

**PowerShell:**
```powershell
Invoke-WebRequest -Uri "http://127.0.0.1:8000/api/v1/masjid/1/laporan/transaksi?per_page=3" -Headers @{"Authorization"="Bearer 1|OlQpsU5YGhzU1WgJDJjmp2Mys5E22RN0A0hzayCJe2d53ac6"} | Select-Object -ExpandProperty Content
```

**Response:**
```json
{
  "type": "list_transaksi",
  "data": [
    {
      "id": 5,
      "tanggal": "2026-02-21",
      "jenis": "pemasukan",
      "kategori": {
        "id": 1,
        "nama": "Infaq Jumat"
      },
      "nominal": 550000,
      "keterangan": "Infaq Jumat minggu ketiga"
    }
  ],
  "meta": {
    "current_page": 1,
    "per_page": 3,
    "total": 13,
    "last_page": 5
  }
}
```

### 3. Detail Transaksi

**Request:**
```bash
GET http://127.0.0.1:8000/api/v1/masjid/1/laporan/transaksi/1
Authorization: Bearer {token}
```

**PowerShell:**
```powershell
Invoke-WebRequest -Uri "http://127.0.0.1:8000/api/v1/masjid/1/laporan/transaksi/1" -Headers @{"Authorization"="Bearer 1|OlQpsU5YGhzU1WgJDJjmp2Mys5E22RN0A0hzayCJe2d53ac6"} | Select-Object -ExpandProperty Content
```

**Response:**
```json
{
  "type": "detail_transaksi",
  "data": {
    "id": 1,
    "tanggal": "2026-02-07",
    "jenis": "pemasukan",
    "kategori": {
      "id": 1,
      "nama": "Infaq Jumat"
    },
    "nominal": 500000,
    "keterangan": "Infaq Jumat minggu pertama",
    "bukti_url": null,
    "dibuat_oleh": "Admin Masjid",
    "dibuat_pada": "2026-02-07T16:36:42+07:00",
    "diperbarui_pada": "2026-02-07T16:36:42+07:00"
  }
}
```

### 4. Rekap Bulanan

**Request:**
```bash
GET http://127.0.0.1:8000/api/v1/masjid/1/laporan/rekap-bulanan?tahun=2026
Authorization: Bearer {token}
```

**PowerShell:**
```powershell
Invoke-WebRequest -Uri "http://127.0.0.1:8000/api/v1/masjid/1/laporan/rekap-bulanan?tahun=2026" -Headers @{"Authorization"="Bearer 1|OlQpsU5YGhzU1WgJDJjmp2Mys5E22RN0A0hzayCJe2d53ac6"} | Select-Object -ExpandProperty Content
```

**Response:**
```json
{
  "type": "rekap_bulanan",
  "data": {
    "tahun": 2026,
    "bulan": [
      {
        "bulan": 1,
        "nama_bulan": "Januari",
        "total_pemasukan": 2930000,
        "total_pengeluaran": 460000,
        "saldo": 2470000
      },
      {
        "bulan": 2,
        "nama_bulan": "Februari",
        "total_pemasukan": 5150000,
        "total_pengeluaran": 700000,
        "saldo": 4450000
      }
    ],
    "total_tahun": {
      "total_pemasukan": 8080000,
      "total_pengeluaran": 1160000,
      "saldo_akhir": 6920000
    }
  }
}
```

### 5. Saldo Terkini

**Request:**
```bash
GET http://127.0.0.1:8000/api/v1/masjid/1/laporan/saldo
Authorization: Bearer {token}
```

**PowerShell:**
```powershell
Invoke-WebRequest -Uri "http://127.0.0.1:8000/api/v1/masjid/1/laporan/saldo" -Headers @{"Authorization"="Bearer 1|OlQpsU5YGhzU1WgJDJjmp2Mys5E22RN0A0hzayCJe2d53ac6"} | Select-Object -ExpandProperty Content
```

**Response:**
```json
{
  "type": "saldo_terkini",
  "data": {
    "saldo_kas": 6500000,
    "saldo_bank": 15000000,
    "total_saldo": 21500000,
    "terakhir_diperbarui": "2026-02-07T16:36:40+07:00"
  }
}
```

### 6. List Kategori

**Request:**
```bash
GET http://127.0.0.1:8000/api/v1/masjid/1/laporan/kategori
Authorization: Bearer {token}
```

**PowerShell:**
```powershell
Invoke-WebRequest -Uri "http://127.0.0.1:8000/api/v1/masjid/1/laporan/kategori" -Headers @{"Authorization"="Bearer 1|OlQpsU5YGhzU1WgJDJjmp2Mys5E22RN0A0hzayCJe2d53ac6"} | Select-Object -ExpandProperty Content
```

**Response:**
```json
{
  "type": "list_kategori",
  "data": [
    {
      "id": 5,
      "nama": "Air",
      "jenis": "pengeluaran",
      "total_transaksi": 2,
      "total_nominal": 290000
    },
    {
      "id": 2,
      "nama": "Donasi",
      "jenis": "pemasukan",
      "total_transaksi": 2,
      "total_nominal": 3000000
    }
  ]
}
```

### 7. Export Laporan (Bonus)

**Request:**
```bash
GET http://127.0.0.1:8000/api/v1/masjid/1/laporan/export?format=pdf&tanggal_mulai=2026-02-01&tanggal_selesai=2026-02-28
Authorization: Bearer {token}
```

**PowerShell:**
```powershell
Invoke-WebRequest -Uri "http://127.0.0.1:8000/api/v1/masjid/1/laporan/export?format=pdf&tanggal_mulai=2026-02-01&tanggal_selesai=2026-02-28" -Headers @{"Authorization"="Bearer 1|OlQpsU5YGhzU1WgJDJjmp2Mys5E22RN0A0hzayCJe2d53ac6"} | Select-Object -ExpandProperty Content
```

## Test dengan Filter

### Filter by Jenis
```powershell
Invoke-WebRequest -Uri "http://127.0.0.1:8000/api/v1/masjid/1/laporan/transaksi?jenis=pemasukan" -Headers @{"Authorization"="Bearer 1|OlQpsU5YGhzU1WgJDJjmp2Mys5E22RN0A0hzayCJe2d53ac6"} | Select-Object -ExpandProperty Content
```

### Filter by Kategori
```powershell
Invoke-WebRequest -Uri "http://127.0.0.1:8000/api/v1/masjid/1/laporan/transaksi?kategori_id=1" -Headers @{"Authorization"="Bearer 1|OlQpsU5YGhzU1WgJDJjmp2Mys5E22RN0A0hzayCJe2d53ac6"} | Select-Object -ExpandProperty Content
```

### Filter by Date Range
```powershell
Invoke-WebRequest -Uri "http://127.0.0.1:8000/api/v1/masjid/1/laporan/transaksi?tanggal_mulai=2026-02-01&tanggal_selesai=2026-02-10" -Headers @{"Authorization"="Bearer 1|OlQpsU5YGhzU1WgJDJjmp2Mys5E22RN0A0hzayCJe2d53ac6"} | Select-Object -ExpandProperty Content
```

## Status Testing

✅ Ringkasan Keuangan - WORKING
✅ List Transaksi - WORKING
✅ Detail Transaksi - WORKING
✅ Rekap Bulanan - WORKING
✅ Saldo Terkini - WORKING
✅ List Kategori - WORKING
✅ Export Laporan - WORKING (simulasi)

## Database Sample

- 1 Masjid: "Masjid Al-Ikhlas"
- 6 Kategori: 3 pemasukan, 3 pengeluaran
- 13 Transaksi: 8 di Februari 2026, 5 di Januari 2026
- Total Pemasukan 2026: Rp 8.080.000
- Total Pengeluaran 2026: Rp 1.160.000
