65 lines
1.9 KiB
PHP
65 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace Config;
|
|
|
|
use CodeIgniter\Config\BaseConfig;
|
|
|
|
class BdsConfig extends BaseConfig
|
|
{
|
|
public bool $installmentReminderEnabled = false;
|
|
|
|
public int $installmentReminderBusinessDays = 5;
|
|
|
|
public bool $installmentReminderFetchOverduePendingUtr = false;
|
|
|
|
public bool $installmentReminderDaily = false;
|
|
|
|
/** @var string[] Lowercase three-letter day abbreviations, e.g. mon, tue */
|
|
public array $installmentReminderDays = [];
|
|
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
|
|
$this->installmentReminderEnabled = $this->envToBool(
|
|
env('bds.installmentReminder.enabled', 'true')
|
|
);
|
|
$this->installmentReminderBusinessDays = max(
|
|
0,
|
|
(int) env('bds.installmentReminder.businessDays', 5)
|
|
);
|
|
$this->installmentReminderFetchOverduePendingUtr = $this->envToBool(
|
|
env('bds.installmentReminder.fetchOverduePendingUtr', 'false')
|
|
);
|
|
$this->installmentReminderDaily = $this->envToBool(
|
|
env('bds.installmentReminder.daily', 'true')
|
|
);
|
|
|
|
$days = env('bds.installmentReminder.days', 'mon,tue,wed,thu,fri');
|
|
$this->installmentReminderDays = array_values(array_filter(array_map(
|
|
static fn (string $day): string => strtolower(substr(trim($day), 0, 3)),
|
|
explode(',', (string) $days)
|
|
)));
|
|
}
|
|
|
|
public function shouldFetchInstallmentRemindersToday(): bool
|
|
{
|
|
if (!$this->installmentReminderEnabled) {
|
|
return false;
|
|
}
|
|
|
|
if ($this->installmentReminderDaily) {
|
|
return true;
|
|
}
|
|
|
|
$today = strtolower(date('D'));
|
|
|
|
return in_array($today, $this->installmentReminderDays, true);
|
|
}
|
|
|
|
private function envToBool(mixed $value): bool
|
|
{
|
|
return in_array(strtolower((string) $value), ['1', 'true', 'yes', 'on'], true);
|
|
}
|
|
}
|