parent
e7176b6371
commit
1378aefa9c
14 changed files with 93 additions and 35 deletions
|
|
@ -495,6 +495,7 @@ final class SettingsController
|
|||
->query('SELECT id,name FROM ref_dewormers ORDER BY name COLLATE NOCASE')
|
||||
->fetchAll(PDO::FETCH_ASSOC),
|
||||
'settings' => AppSettings::all(),
|
||||
'adoptionFees' => PricingService::adoptionFees(),
|
||||
'saved' => isset($_GET['saved']),
|
||||
'error' => (string) ($_GET['error'] ?? ''),
|
||||
]);
|
||||
|
|
@ -616,19 +617,23 @@ final class SettingsController
|
|||
{
|
||||
self::admin();
|
||||
self::postOnly();
|
||||
AppSettings::save(
|
||||
[
|
||||
'adoption_fee_sterilized' => (string) max(
|
||||
0,
|
||||
min(2000, (int) ($_POST['adoption_fee_sterilized'] ?? 220)),
|
||||
),
|
||||
'adoption_fee_unsterilized' => (string) max(
|
||||
0,
|
||||
min(2000, (int) ($_POST['adoption_fee_unsterilized'] ?? 200)),
|
||||
),
|
||||
],
|
||||
Auth::id(),
|
||||
$submitted = (array) ($_POST['fees'] ?? []);
|
||||
$allowed = array_keys(PricingService::adoptionFees());
|
||||
$stmt = DB::pdo()->prepare(
|
||||
"INSERT INTO adoption_fee_rules(species_code,fee_before_sterilization,fee_after_sterilization,is_free,updated_at) VALUES(?,?,?,?,datetime('now')) ON CONFLICT(species_code) DO UPDATE SET fee_before_sterilization=excluded.fee_before_sterilization,fee_after_sterilization=excluded.fee_after_sterilization,is_free=excluded.is_free,updated_at=datetime('now')",
|
||||
);
|
||||
foreach ($submitted as $species => $values) {
|
||||
$species = SpeciesService::normalize((string) $species);
|
||||
if (!in_array($species, $allowed, true) || !is_array($values)) {
|
||||
continue;
|
||||
}
|
||||
$stmt->execute([
|
||||
$species,
|
||||
max(0, min(2000, (int) ($values['before'] ?? 0))),
|
||||
max(0, min(2000, (int) ($values['after'] ?? 0))),
|
||||
isset($values['free']) ? 1 : 0,
|
||||
]);
|
||||
}
|
||||
AuditService::log('adoption_fees_saved', '/settings/pricing/adoption', 'Tarifs d’adoption modifiés');
|
||||
header('Location: /settings/pricing?saved=1');
|
||||
exit();
|
||||
|
|
|
|||
Loading…
Reference in a new issue