# CodeIgniter 4 Application Starter

## What is CodeIgniter?

CodeIgniter is a PHP full-stack web framework that is light, fast, flexible and secure.
More information can be found at the [official site](http://codeigniter.com).

This repository holds a composer-installable app starter.
It has been built from the
[development repository](https://github.com/codeigniter4/CodeIgniter4).

More information about the plans for version 4 can be found in [the announcement](http://forum.codeigniter.com/thread-62615.html) on the forums.

The user guide corresponding to this version of the framework can be found
[here](https://codeigniter4.github.io/userguide/).

## Installation & updates

`composer create-project codeigniter4/appstarter` then `composer update` whenever
there is a new release of the framework.

When updating, check the release notes to see if there are any changes you might need to apply
to your `app` folder. The affected files can be copied or merged from
`vendor/codeigniter4/framework/app`.

## Setup

Copy `env` to `.env` and tailor for your app, specifically the baseURL
and any database settings.

## SatuBarisan API Setup

Tambahkan konfigurasi berikut pada file `.env`:

```dotenv
SATUBARISAN_ENABLED=false
SATUBARISAN_BASE_URL="https://example.com/api/v1"
SATUBARISAN_TIMEOUT=10
SATUBARISAN_CLIENT_ID="change-this-client-id"
SATUBARISAN_CLIENT_SECRET="change-this-client-secret"
SATUBARISAN_ENVIRONMENT="sandbox"
SATUBARISAN_TOKEN_SKEW=60
SATUBARISAN_TOKEN_CACHE_PREFIX="satubarisan_token_"
# Deprecated: tidak dipakai lagi
SATUBARISAN_API_KEY=""
SATUBARISAN_BULK_CHUNK=100
```

- Jangan commit `client_secret` asli ke Git.
- Gunakan kredensial sandbox/production sesuai environment pada API SatuBarisan.
- Pastikan server dapat mengakses `https://satubarisan.id`.
- Pastikan ekstensi `curl` dan `openssl` aktif pada environment PHP.

## Important Change with index.php

`index.php` is no longer in the root of the project! It has been moved inside the *public* folder,
for better security and separation of components.

This means that you should configure your web server to "point" to your project's *public* folder, and
not to the project root. A better practice would be to configure a virtual host to point there. A poor practice would be to point your web server to the project root and expect to enter *public/...*, as the rest of your logic and the
framework are exposed.

**Please** read the user guide for a better explanation of how CI4 works!

## Repository Management

We use GitHub issues, in our main repository, to track **BUGS** and to track approved **DEVELOPMENT** work packages.
We use our [forum](http://forum.codeigniter.com) to provide SUPPORT and to discuss
FEATURE REQUESTS.

This repository is a "distribution" one, built by our release preparation script.
Problems with it can be raised on our forum, or as issues in the main repository.

## Server Requirements

PHP version 7.3 or higher is required, with the following extensions installed:

- [intl](http://php.net/manual/en/intl.requirements.php)
- [libcurl](http://php.net/manual/en/curl.requirements.php) if you plan to use the HTTP\CURLRequest library

Additionally, make sure that the following extensions are enabled in your PHP:

- json (enabled by default - don't turn it off)
- [mbstring](http://php.net/manual/en/mbstring.installation.php)
- [mysqlnd](http://php.net/manual/en/mysqlnd.install.php)
- xml (enabled by default - don't turn it off)

## WhatsApp Reminder Iuran Rutin Scheduler
Kirim pengingat Iuran Rutin melalui WhatsApp dapat dilakukan melalui perintah CLI baru berikut:
```
php spark reminder:iuran [--date=YYYY-MM-DD]
```

## WhatsApp Angsuran Reminder Scheduler

Kirim pengingat jatuh tempo pinjaman melalui WhatsApp dapat dilakukan melalui perintah CLI baru berikut:

```
php spark whatsapp:angsuran-reminder [--date=YYYY-MM-DD]
php spark whatsapp:angsuran-reminder date=YYYY-MM-DD
```

- Jalankan tanpa opsi untuk mode otomatis (menggunakan tanggal hari ini dan valid hanya pukul 00:00 WIB).
- Gunakan `--date=2025-12-19`, `date=2025-12-19`, atau format `date 2025-12-19` untuk kebutuhan testing sehingga notifikasi bisa dipicu sesuai skenario yang diinginkan.
- Setiap pesan dikirim dengan jeda 1 detik untuk memenuhi batasan gateway WhatsApp.

Penjadwalan otomatis pukul 00:00 WIB sudah didefinisikan pada `app/Config/Tasks.php`. Pastikan task runner dijalankan terus-menerus dengan cron di server Anda, misalnya:

```
* * * * * cd /path/to/project && php spark tasks:run >> writable/logs/tasks.log 2>&1
```

Task runner akan mengeksekusi `whatsapp:angsuran-reminder` sesuai jadwal, mengambil data dari `view_sisa_angsuran`, dan menyusun pesan dengan format:

```
Yth. [SAPAAN] [NAMA_ANGGOTA]
-----------------------------break-----------------------------
Diberitahukan bahwa angsuran pinjaman sebesar [NOMINAL] akan jatuh tempo pada [DUE_DATE] dari ([TOTAL_ANGSURAN]).
-----------------------------break-----------------------------
Mohon pastikan pembayaran diterima paling lambat pada tanggal tersebut untuk menghindari denda keterlambatan.
-----------------------------break-----------------------------
Untuk opsi penjadwalan dan restrukturisasi, hubungi petugas atau CS [NAMA_KOPERASI]. Terima kasih.
```

`[SAPAAN]` diambil dari `sex_code` (1 = `Sdr.`, 2 = `Sdri`, lainnya `Bapak/Ibu`), nominal & total akan diformat `Rp.1.000.000`, sedangkan `[DUE_DATE]` diformat seperti `21 November 2025`.

## TCPDF PNG iCCP (Docker)

Beberapa file PNG (logo/header) mengandung metadata ICC/iCCP yang tidak valid. Saat TCPDF membaca PNG lewat GD/libpng, warning `iCCP` dapat terangkat menjadi error sehingga proses generate PDF berhenti.

Solusi di project ini:

- semua pemanggilan gambar TCPDF diarahkan ke sanitizer reusable `App\Libraries\TcpdfImageSanitizer`
- PNG akan disanitasi ke cache `writable/cache/tcpdf-images` (strip metadata ICC/iCCP) sebelum dipakai TCPDF
- jika file gambar hilang/rusak, gambar di-skip dan ditulis warning ke log, PDF tetap lanjut dibuat

Tooling Docker untuk sanitasi PNG:

- `imagemagick`
- `pngcrush`
- `optipng`

Rebuild container:

```bash
docker compose build --no-cache
docker compose up -d
```

Verifikasi route PDF:

- `/report/printakumulasi`
- `/report/printrekapakumulasi`
- `/repaccounting/kartubukubesar`
- `/repaccounting/neracasaldo`
- `/repaccounting/labarugi`
- `/repaccounting/neraca`
- `/repaccounting/aruskas`
- `/repaccounting/perubahanmodal`
- `/report/printnominatip`
- `/printreport/printtranspembiayaan`
