1 parent
348a8f1811
commit
c05802fc79
3 files changed
+35
-3
No files matched your search
@@ -199,8 +199,22 @@ if ($action === 'validate_transfers') {
|
||||
|
||||
$stmtAcc = $pdo->query("SELECT a.name as acc_name, p.name as owner_name FROM pf_bank_accounts a LEFT JOIN pf_people p ON a.owner_person_id = p.id");
|
||||
$bankAccountsMap = [];
|
||||
|
||||
// Fallback intelligent : on récupère tous les prénoms de la famille
|
||||
$familyNames = $pdo->query("SELECT name FROM pf_people")->fetchAll(PDO::FETCH_COLUMN);
|
||||
|
||||
while ($row = $stmtAcc->fetch(PDO::FETCH_ASSOC)) {
|
||||
$bankAccountsMap['vers ' . $row['acc_name']] = $row['owner_name'];
|
||||
$owner = $row['owner_name'];
|
||||
if (!$owner) {
|
||||
// Si pas de propriétaire explicite, on cherche un prénom dans le nom du compte (ex: "Livret A Alex")
|
||||
foreach ($familyNames as $pName) {
|
||||
if (stripos($row['acc_name'], $pName) !== false) {
|
||||
$owner = $pName;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
$bankAccountsMap['vers ' . $row['acc_name']] = $owner;
|
||||
}
|
||||
|
||||
$stmt = $pdo->prepare("
|
||||
|
||||
@@ -45,6 +45,9 @@ try {
|
||||
$currencySetting = $foyerData['currency'] ?? '€';
|
||||
$csvMapping = !empty($foyerData['csv_mapping']) ? json_decode($foyerData['csv_mapping'], true) : null;
|
||||
|
||||
// 6. Liste des membres (pour assigner un compte bancaire)
|
||||
$people = $pdo->query("SELECT id, name FROM pf_people WHERE is_active = 1 ORDER BY name ASC")->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
echo json_encode([
|
||||
'success' => true,
|
||||
'data' => [
|
||||
@@ -52,6 +55,7 @@ try {
|
||||
'categories' => $categories,
|
||||
'rules' => $rules,
|
||||
'salaries' => $salaries,
|
||||
'people' => $people,
|
||||
'year' => $currentYear,
|
||||
'currency' => $currencySetting,
|
||||
'csv_mapping' => $csvMapping
|
||||
@@ -64,9 +68,10 @@ try {
|
||||
if ($action === 'add_account') {
|
||||
$name = trim($_POST['name'] ?? '');
|
||||
$type = $_POST['type'] ?? 'checking';
|
||||
$owner_id = !empty($_POST['owner_person_id']) ? (int)$_POST['owner_person_id'] : null;
|
||||
if (empty($name)) throw new Exception("Le nom du compte est obligatoire.");
|
||||
$stmt = $pdo->prepare("INSERT INTO pf_bank_accounts (name, account_type, is_default) VALUES (?, ?, 0)");
|
||||
$stmt->execute([$name, $type]);
|
||||
$stmt = $pdo->prepare("INSERT INTO pf_bank_accounts (name, account_type, is_default, owner_person_id) VALUES (?, ?, 0, ?)");
|
||||
$stmt->execute([$name, $type, $owner_id]);
|
||||
echo json_encode(['success' => true]);
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -80,6 +80,9 @@ if (!defined('CURRENCY')) {
|
||||
<option value="checking"><?= tr('bs_type_checking') ?></option>
|
||||
<option value="savings"><?= tr('bs_type_savings') ?></option>
|
||||
</select>
|
||||
<select name="owner_person_id" id="select-account-owner" class="pf-input bs-input-fixed">
|
||||
<option value="">Commun</option>
|
||||
</select>
|
||||
<button type="submit" class="btn btn-secondary"><?= tr('btn_add') ?></button>
|
||||
</form>
|
||||
</div>
|
||||
@@ -253,6 +256,16 @@ async function loadBudgetSettingsData() {
|
||||
try {
|
||||
const response = await pachaFetch('/modules/budget/includes/api/settings.php?action=get_all', { method: 'GET' });
|
||||
if (!response.success) throw new Error(response.error || tr('error_occured'));
|
||||
|
||||
// Alimenter la liste des propriétaires pour les comptes
|
||||
const ownerSelect = document.getElementById('select-account-owner');
|
||||
if (ownerSelect && response.data.people) {
|
||||
ownerSelect.innerHTML = '<option value="">Commun</option>';
|
||||
response.data.people.forEach(p => {
|
||||
ownerSelect.innerHTML += `<option value="${p.id}">${p.name}</option>`;
|
||||
});
|
||||
}
|
||||
|
||||
renderAccounts(response.data.accounts);
|
||||
renderCategories(response.data.categories);
|
||||
populateRuleCategories(response.data.categories);
|
||||
|
||||
Reference in new issue
Block a user