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.
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
<?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]]);
|
||||
Reference in New Issue
Block a user