familyHub/api/bank_set_donation_goal.php
Louis Whittington 6d10cb4726 Implement banking system features and enhancements
- Added banking mode with checking, savings, and charity accounts, including auto-split options for income.
- Introduced banking transaction management, including transfers and charity outflows.
- Updated family settings to allow configuration of banking features and interest rates.
- Enhanced data export functionality to include bank transactions.
- Improved user interface to display banking information and donation goals.
- Updated documentation to reflect new banking features and settings.
2026-03-31 11:03:53 -05:00

51 lines
1.7 KiB
PHP

<?php
require_once __DIR__ . '/../includes/api_bootstrap.php';
require_once __DIR__ . '/../includes/family_settings.php';
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
sendJson(['success' => false, 'error' => 'Method not allowed'], 405);
}
$people = migrateAllPeople(normalizePeopleList(readJsonFile('people.json')));
$actor = requireActivePerson($people);
$settings = loadFamilySettings();
if (empty($settings['banking_enabled'])) {
sendJson(['success' => false, 'error' => 'Banking mode is not enabled'], 400);
}
$body = readJsonBody();
$goalRaw = $body['goal_monthly'] ?? null;
if (!is_numeric($goalRaw)) {
sendJson(['success' => false, 'error' => 'goal_monthly must be numeric'], 400);
}
$goal = round((float) $goalRaw, 2);
if ($goal < 0) {
sendJson(['success' => false, 'error' => 'goal_monthly must be >= 0'], 400);
}
$targetPersonId = trim((string) ($body['person_id'] ?? ''));
$actorId = (string) ($actor['id'] ?? '');
$isHoh = (($actor['role'] ?? '') === ROLE_HEAD) && isHohVerified();
if ($targetPersonId === '') {
$targetPersonId = $actorId;
}
if (!$isHoh && $targetPersonId !== $actorId) {
sendJson(['success' => false, 'error' => 'Only verified Head of household can set goals for others'], 403);
}
$idx = null;
foreach ($people as $i => $p) {
if (($p['id'] ?? '') === $targetPersonId) {
$idx = $i;
break;
}
}
if ($idx === null) {
sendJson(['success' => false, 'error' => 'Person not found'], 404);
}
$people[$idx]['donation_goal_monthly'] = $goal;
if (!writeJsonFile('people.json', $people)) {
sendJson(['success' => false, 'error' => 'Failed to save goal'], 500);
}
sendJson(['success' => true, 'person' => $people[$idx]]);