finish budget and kids
This commit is contained in:
+12
-10
@@ -165,16 +165,18 @@ CREATE TABLE IF NOT EXISTS pf_import_rules (
|
|||||||
budget_item_id INT(11) NULL DEFAULT NULL
|
budget_item_id INT(11) NULL DEFAULT NULL
|
||||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS pf_advances (
|
|
||||||
id int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
CREATE TABLE IF NOT EXISTS `pf_advances` (
|
||||||
advance_date date NOT NULL,
|
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||||
payer varchar(50) NOT NULL,
|
`advance_date` date NOT NULL,
|
||||||
description varchar(255) NOT NULL,
|
`payer` varchar(50) NOT NULL,
|
||||||
amount decimal(10,2) DEFAULT 0.00,
|
`description` varchar(255) NOT NULL,
|
||||||
from_savings tinyint(1) DEFAULT 0,
|
`amount` decimal(10,2) DEFAULT 0.00,
|
||||||
is_resolved tinyint(1) DEFAULT 0,
|
`from_savings` tinyint(1) DEFAULT 0,
|
||||||
created_at datetime DEFAULT current_timestamp()
|
`is_resolved` tinyint(1) DEFAULT 0,
|
||||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
`created_at` datetime DEFAULT current_timestamp(),
|
||||||
|
PRIMARY KEY (`id`)
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||||
|
|
||||||
-- ─── Notes / Memo ─────────────────────────────────────────────────────────────
|
-- ─── Notes / Memo ─────────────────────────────────────────────────────────────
|
||||||
CREATE TABLE IF NOT EXISTS pf_notes (
|
CREATE TABLE IF NOT EXISTS pf_notes (
|
||||||
|
|||||||
@@ -156,6 +156,15 @@ return [
|
|||||||
'mod_planka_desc' => 'Gestioneu els vostres projectes en mode Kanban amb Planka.',
|
'mod_planka_desc' => 'Gestioneu els vostres projectes en mode Kanban amb Planka.',
|
||||||
'menu_planka' => 'Planka',
|
'menu_planka' => 'Planka',
|
||||||
|
|
||||||
|
// --- SETTINGS : ENFANTS ---
|
||||||
|
'set_kids_title' => 'Nens de la llar',
|
||||||
|
'set_kids_desc' => 'Gestioneu la llista de nens per associar-los a l\'estalvi, als regals, etc.',
|
||||||
|
'set_add_kid_placeholder' => 'Nom del nen',
|
||||||
|
'set_btn_add_kid' => 'Afegir',
|
||||||
|
'set_err_kid_name' => 'El nom és obligatori.',
|
||||||
|
'set_confirm_del_kid' => 'Vols eliminar aquest nen? (El seu historial financer es conservarà als arxius).',
|
||||||
|
'set_no_kids' => 'Cap nen configurat per a aquesta llar.',
|
||||||
|
|
||||||
// ==========================================
|
// ==========================================
|
||||||
// FAMILY CALENDAR
|
// FAMILY CALENDAR
|
||||||
// ==========================================
|
// ==========================================
|
||||||
@@ -385,6 +394,7 @@ return [
|
|||||||
'cat_fixed' => 'Despeses Fixes',
|
'cat_fixed' => 'Despeses Fixes',
|
||||||
'cat_others' => 'Altres / Imprevistos',
|
'cat_others' => 'Altres / Imprevistos',
|
||||||
'cat_savings' => 'Estalvis',
|
'cat_savings' => 'Estalvis',
|
||||||
|
'budget_tab_kids' => 'Nens',
|
||||||
|
|
||||||
// --- BUDGET : SUIVI ---
|
// --- BUDGET : SUIVI ---
|
||||||
'bud_rem_school' => 'Escola (Resta estimada)',
|
'bud_rem_school' => 'Escola (Resta estimada)',
|
||||||
@@ -565,6 +575,24 @@ return [
|
|||||||
'bud_prev_confirm_copy' => "Vols copiar les dades de %s a %t?\n\n⚠️ Això sobreescriurà tots els valors ja presents per a %t.",
|
'bud_prev_confirm_copy' => "Vols copiar les dades de %s a %t?\n\n⚠️ Això sobreescriurà tots els valors ja presents per a %t.",
|
||||||
'bud_prev_confirm_transfers' => "Confirmes que %p ha fet totes les transferències per a %m?\n\nAixò actualitzarà l'Estalvi automàticament.",
|
'bud_prev_confirm_transfers' => "Confirmes que %p ha fet totes les transferències per a %m?\n\nAixò actualitzarà l'Estalvi automàticament.",
|
||||||
|
|
||||||
|
// --- MODULE BUDGET : AVANCES & TRICOUNT ---
|
||||||
|
'bud_adv_title' => 'Avançaments i Tricount Familiar',
|
||||||
|
'bud_adv_add' => 'Afegir un avançament',
|
||||||
|
'bud_adv_edit' => 'Modificar l\'avançament',
|
||||||
|
'bud_adv_who_paid' => 'Qui ha pagat?',
|
||||||
|
'bud_adv_payer' => 'Pagador',
|
||||||
|
'bud_adv_has_advanced' => '%s ha avançat:',
|
||||||
|
'bud_adv_cc_label' => 'al compte comú',
|
||||||
|
'bud_adv_livret_label' => 'des del seu llibre d\'estalvis',
|
||||||
|
'bud_adv_cc_balance_title' => 'Equilibri del Compte Comú',
|
||||||
|
'bud_adv_owed_to' => 'S\'han de pagar **%s €** a **%s**',
|
||||||
|
'bud_adv_balanced' => 'Els comptes estan perfectament equilibrats!',
|
||||||
|
'bud_adv_saved_badge' => 'Estalvis',
|
||||||
|
'bud_adv_already_saved' => 'Aquests diners provenen d\'un llibre d\'estalvis',
|
||||||
|
'bud_adv_ph_desc' => 'Ex: Compres, Factura d\'electricitat...',
|
||||||
|
'bud_adv_confirm_resolve' => 'Confirmar el reemborsament complet d\'aquest avançament?',
|
||||||
|
'bud_adv_confirm_delete' => 'Eliminar definitivament aquest avançament?',
|
||||||
|
|
||||||
// ==========================================
|
// ==========================================
|
||||||
// CADEAUX (GIFTS)
|
// CADEAUX (GIFTS)
|
||||||
// ==========================================
|
// ==========================================
|
||||||
|
|||||||
@@ -157,6 +157,15 @@ return [
|
|||||||
'mod_planka_desc' => 'Manage your projects in Kanban mode with Planka.',
|
'mod_planka_desc' => 'Manage your projects in Kanban mode with Planka.',
|
||||||
'menu_planka' => 'Planka',
|
'menu_planka' => 'Planka',
|
||||||
|
|
||||||
|
// --- SETTINGS : KIDS ---
|
||||||
|
'set_kids_title' => 'Household Kids',
|
||||||
|
'set_kids_desc' => 'Manage the list of kids to associate them with savings, gifts, etc.',
|
||||||
|
'set_add_kid_placeholder' => 'Kid\'s first name',
|
||||||
|
'set_btn_add_kid' => 'Add',
|
||||||
|
'set_err_kid_name' => 'The first name is required.',
|
||||||
|
'set_confirm_del_kid' => 'Delete this kid? (Their financial history will remain visible in the archives).',
|
||||||
|
'set_no_kids' => 'No kids configured for this household.',
|
||||||
|
|
||||||
// ==========================================
|
// ==========================================
|
||||||
// FAMILY CALENDAR
|
// FAMILY CALENDAR
|
||||||
// ==========================================
|
// ==========================================
|
||||||
@@ -383,6 +392,7 @@ return [
|
|||||||
'cat_fixed' => 'Fixed costs',
|
'cat_fixed' => 'Fixed costs',
|
||||||
'cat_others' => 'Other / Unexpected',
|
'cat_others' => 'Other / Unexpected',
|
||||||
'cat_savings' => 'Savings',
|
'cat_savings' => 'Savings',
|
||||||
|
'budget_tab_kids' => 'Kids',
|
||||||
|
|
||||||
// --- BUDGET: TRACKING ---
|
// --- BUDGET: TRACKING ---
|
||||||
'bud_rem_school' => 'School (estimated remaining)',
|
'bud_rem_school' => 'School (estimated remaining)',
|
||||||
@@ -548,6 +558,30 @@ return [
|
|||||||
'bud_prev_confirm_copy' => "Do you want to copy data from %s to %t?\n\n⚠️ This will overwrite all values already present for %t.",
|
'bud_prev_confirm_copy' => "Do you want to copy data from %s to %t?\n\n⚠️ This will overwrite all values already present for %t.",
|
||||||
'bud_prev_confirm_transfers' => "Confirm that %p has made all their transfers for %m?\n\nThis will automatically update Savings.",
|
'bud_prev_confirm_transfers' => "Confirm that %p has made all their transfers for %m?\n\nThis will automatically update Savings.",
|
||||||
'bud_prev_label_name' => 'Name',
|
'bud_prev_label_name' => 'Name',
|
||||||
|
'bud_adv_title' => 'Advances & Family Tricount',
|
||||||
|
'bud_adv_add' => 'Add an Advance',
|
||||||
|
'bud_adv_edit' => 'Edit Advance',
|
||||||
|
'bud_adv_who_paid' => 'Who paid?',
|
||||||
|
'bud_adv_payer' => 'Payer',
|
||||||
|
'bud_adv_has_advanced' => '%s advanced:',
|
||||||
|
'bud_adv_cc_label' => 'on the joint account',
|
||||||
|
'bud_adv_livret_label' => 'from their savings account',
|
||||||
|
'bud_adv_cc_balance_title' => 'Joint Account Balance',
|
||||||
|
'bud_adv_owed_to' => '<strong>%s €</strong> are owed to <strong>%s</strong>',
|
||||||
|
'bud_adv_balanced' => 'Accounts are perfectly balanced!',
|
||||||
|
'bud_adv_saved_badge' => 'Savings',
|
||||||
|
'bud_adv_already_saved' => 'This money comes from a savings account',
|
||||||
|
'bud_adv_ph_desc' => 'e.g., Groceries, Electricity bill...',
|
||||||
|
'bud_adv_confirm_resolve' => 'Confirm the complete reimbursement of this advance?',
|
||||||
|
'bud_adv_confirm_delete' => 'Permanently delete this advance?',
|
||||||
|
'date' => 'Date',
|
||||||
|
'bud_label_name' => 'Description',
|
||||||
|
'bud_amount' => 'Amount',
|
||||||
|
'actions' => 'Actions',
|
||||||
|
'edit' => 'Edit',
|
||||||
|
'delete' => 'Delete',
|
||||||
|
'btn_cancel' => 'Cancel',
|
||||||
|
'btn_save' => 'Save',
|
||||||
|
|
||||||
// ==========================================
|
// ==========================================
|
||||||
// GIFTS
|
// GIFTS
|
||||||
|
|||||||
@@ -156,6 +156,15 @@ return [
|
|||||||
'mod_planka_desc' => 'Gérez vos projets en mode Kanban avec Planka.',
|
'mod_planka_desc' => 'Gérez vos projets en mode Kanban avec Planka.',
|
||||||
'menu_planka' => 'Planka',
|
'menu_planka' => 'Planka',
|
||||||
|
|
||||||
|
// --- SETTINGS : ENFANTS ---
|
||||||
|
'set_kids_title' => 'Enfants du foyer',
|
||||||
|
'set_kids_desc' => 'Gérez la liste des enfants pour les associer à l\'épargne, aux cadeaux, etc.',
|
||||||
|
'set_add_kid_placeholder' => 'Prénom de l\'enfant',
|
||||||
|
'set_btn_add_kid' => 'Ajouter',
|
||||||
|
'set_err_kid_name' => 'Le prénom est requis.',
|
||||||
|
'set_confirm_del_kid' => 'Supprimer cet enfant ? (Son historique financier restera visible dans les archives).',
|
||||||
|
'set_no_kids' => 'Aucun enfant configuré pour ce foyer.',
|
||||||
|
|
||||||
// ==========================================
|
// ==========================================
|
||||||
// FAMILY CALENDAR
|
// FAMILY CALENDAR
|
||||||
// ==========================================
|
// ==========================================
|
||||||
@@ -385,6 +394,7 @@ return [
|
|||||||
'cat_fixed' => 'Charges Fixes',
|
'cat_fixed' => 'Charges Fixes',
|
||||||
'cat_others' => 'Autres / Imprévus',
|
'cat_others' => 'Autres / Imprévus',
|
||||||
'cat_savings' => 'Épargne',
|
'cat_savings' => 'Épargne',
|
||||||
|
'budget_tab_kids' => 'Enfants',
|
||||||
|
|
||||||
// --- BUDGET : SUIVI ---
|
// --- BUDGET : SUIVI ---
|
||||||
'bud_rem_school' => 'École (Reste estimé)',
|
'bud_rem_school' => 'École (Reste estimé)',
|
||||||
@@ -563,6 +573,22 @@ return [
|
|||||||
'bud_sav_modal_title_add' => 'Saisir un mois',
|
'bud_sav_modal_title_add' => 'Saisir un mois',
|
||||||
'bud_sav_ph_name' => 'Nom (ex: Vacances)',
|
'bud_sav_ph_name' => 'Nom (ex: Vacances)',
|
||||||
'bud_prev_label_name' => 'Nom',
|
'bud_prev_label_name' => 'Nom',
|
||||||
|
'bud_adv_title' => 'Avances & Tricount Familial',
|
||||||
|
'bud_adv_add' => 'Ajouter une avance',
|
||||||
|
'bud_adv_edit' => 'Modifier l\'avance',
|
||||||
|
'bud_adv_who_paid' => 'Qui a payé ?',
|
||||||
|
'bud_adv_payer' => 'Payeur',
|
||||||
|
'bud_adv_has_advanced' => '%s a avancé :',
|
||||||
|
'bud_adv_cc_label' => 'sur le compte commun',
|
||||||
|
'bud_adv_livret_label' => 'depuis son livret d\'épargne',
|
||||||
|
'bud_adv_cc_balance_title' => 'Équilibre du Compte Commun',
|
||||||
|
'bud_adv_owed_to' => '<strong>%s €</strong> sont dus à <strong>%s</strong>',
|
||||||
|
'bud_adv_balanced' => 'Les comptes sont parfaitement équilibrés !',
|
||||||
|
'bud_adv_saved_badge' => 'Épargne',
|
||||||
|
'bud_adv_already_saved' => 'Cet argent provient d\'un livret d\'épargne',
|
||||||
|
'bud_adv_ph_desc' => 'Ex: Courses, Facture Électricité...',
|
||||||
|
'bud_adv_confirm_resolve' => 'Confirmer le remboursement complet de cette avance ?',
|
||||||
|
'bud_adv_confirm_delete' => 'Supprimer définitivement cette avance ?',
|
||||||
|
|
||||||
// ==========================================
|
// ==========================================
|
||||||
// CADEAUX (GIFTS)
|
// CADEAUX (GIFTS)
|
||||||
|
|||||||
+28
@@ -225,6 +225,34 @@ foreach ($families as $f) {
|
|||||||
} catch (\PDOException $e) {
|
} catch (\PDOException $e) {
|
||||||
echo "<span style='color:red'>Erreur : " . $e->getMessage() . "</span></li>";
|
echo "<span style='color:red'>Erreur : " . $e->getMessage() . "</span></li>";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Récupération de toutes les bases de données de familles via la base meta
|
||||||
|
$stmtFamilies = $meta_pdo->query("SELECT id, db_name FROM families WHERE is_active = 1");
|
||||||
|
while ($fam = $stmtFamilies->fetch(PDO::FETCH_ASSOC)) {
|
||||||
|
error_log("Migration de la base familiale : " . $fam['db_name']);
|
||||||
|
|
||||||
|
$fam_dsn = "mysql:host=" . DB_HOST . ";dbname=" . $fam['db_name'] . ";charset=utf8mb4";
|
||||||
|
$fam_pdo = new PDO($fam_dsn, DB_USER, DB_PASS, $options);
|
||||||
|
|
||||||
|
// Injection incrémentale sécurisée
|
||||||
|
$fam_pdo->exec("
|
||||||
|
CREATE TABLE IF NOT EXISTS `pf_advances` (
|
||||||
|
`id` INT AUTO_INCREMENT PRIMARY KEY,
|
||||||
|
`advance_date` DATE NOT NULL,
|
||||||
|
`payer` VARCHAR(100) NOT NULL,
|
||||||
|
`description` VARCHAR(255) NOT NULL,
|
||||||
|
`amount` DECIMAL(10,2) DEFAULT 0.00,
|
||||||
|
`from_savings` TINYINT(1) DEFAULT 0,
|
||||||
|
`is_resolved` TINYINT(1) DEFAULT 0,
|
||||||
|
`created_at` DATETIME DEFAULT CURRENT_TIMESTAMP
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||||
|
");
|
||||||
|
}
|
||||||
|
error_log("✅ Migration de la table pf_advances terminée sur tous les tenants.");
|
||||||
|
} catch (Exception $e) {
|
||||||
|
die("❌ Erreur critique lors de la migration : " . $e->getMessage());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ require __DIR__ . '/../../../../includes/auth.php';
|
|||||||
require __DIR__ . '/../../../../includes/db.php';
|
require __DIR__ . '/../../../../includes/db.php';
|
||||||
require_login();
|
require_login();
|
||||||
|
|
||||||
|
|
||||||
$action = $_POST['action'] ?? '';
|
$action = $_POST['action'] ?? '';
|
||||||
|
|
||||||
// =================================================================
|
// =================================================================
|
||||||
@@ -42,7 +41,7 @@ if ($action === 'save_note') {
|
|||||||
|
|
||||||
// 1. MISE A JOUR TABLEAU SALAIRES (AJAX)
|
// 1. MISE A JOUR TABLEAU SALAIRES (AJAX)
|
||||||
if ($action === 'update_salary_config') {
|
if ($action === 'update_salary_config') {
|
||||||
header('Content-Type: application/json'); // On précise JSON ici
|
header('Content-Type: application/json');
|
||||||
$year = $_POST['year'];
|
$year = $_POST['year'];
|
||||||
$person = $_POST['person'];
|
$person = $_POST['person'];
|
||||||
$field = $_POST['field']; // salary, mensualite, etc.
|
$field = $_POST['field']; // salary, mensualite, etc.
|
||||||
@@ -50,7 +49,10 @@ if ($action === 'update_salary_config') {
|
|||||||
|
|
||||||
// Liste des champs autorisés pour éviter les injections
|
// Liste des champs autorisés pour éviter les injections
|
||||||
$allowed = ['salary', 'mensualite', 'frais_func', 'eco_perso', 'eco_family'];
|
$allowed = ['salary', 'mensualite', 'frais_func', 'eco_perso', 'eco_family'];
|
||||||
if (!in_array($field, $allowed)) { echo json_encode(['error'=>'Champ invalide']); exit; }
|
if (!in_array($field, $allowed)) {
|
||||||
|
echo json_encode(['success' => false, 'error' => 'Champ invalide']);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
$stmt = $pdo->prepare("INSERT INTO pf_salary_config (year, person, $field) VALUES (?, ?, ?) ON DUPLICATE KEY UPDATE $field = VALUES($field)");
|
$stmt = $pdo->prepare("INSERT INTO pf_salary_config (year, person, $field) VALUES (?, ?, ?) ON DUPLICATE KEY UPDATE $field = VALUES($field)");
|
||||||
$stmt->execute([$year, $person, $value]);
|
$stmt->execute([$year, $person, $value]);
|
||||||
@@ -63,7 +65,7 @@ if ($action === 'update_allocation') {
|
|||||||
header('Content-Type: application/json');
|
header('Content-Type: application/json');
|
||||||
$date = $_POST['month_date'];
|
$date = $_POST['month_date'];
|
||||||
$catId = (int)$_POST['cat_id'];
|
$catId = (int)$_POST['cat_id'];
|
||||||
$personId = (int)$_POST['person_id']; // 🟢 Reçoit l'ID de la personne directement !
|
$personId = (int)$_POST['person_id'];
|
||||||
$value = floatval($_POST['value']);
|
$value = floatval($_POST['value']);
|
||||||
|
|
||||||
if ($catId <= 0 || $personId <= 0) {
|
if ($catId <= 0 || $personId <= 0) {
|
||||||
@@ -273,3 +275,90 @@ if ($action === 'validate_transfers') {
|
|||||||
}
|
}
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// =================================================================
|
||||||
|
// 7. GESTION DES AVANCES / TRICOUNT (pf_advances)
|
||||||
|
// =================================================================
|
||||||
|
|
||||||
|
if ($action === 'save_advance') {
|
||||||
|
header('Content-Type: application/json');
|
||||||
|
try {
|
||||||
|
$payer = trim($_POST['payer'] ?? '');
|
||||||
|
$advance_date = $_POST['advance_date'] ?? date('Y-m-d');
|
||||||
|
$description = trim($_POST['description'] ?? '');
|
||||||
|
$amount = abs((float)($_POST['amount'] ?? 0));
|
||||||
|
$from_savings = isset($_POST['from_savings']) ? 1 : 0;
|
||||||
|
|
||||||
|
if (empty($payer) || empty($description) || $amount <= 0) {
|
||||||
|
throw new Exception("Champs obligatoires manquants ou invalides.");
|
||||||
|
}
|
||||||
|
|
||||||
|
$stmt = $pdo->prepare("INSERT INTO pf_advances (advance_date, payer, description, amount, from_savings) VALUES (?, ?, ?, ?, ?)");
|
||||||
|
$stmt->execute([$advance_date, $payer, $description, $amount, $from_savings]);
|
||||||
|
|
||||||
|
echo json_encode(['success' => true]);
|
||||||
|
} catch (Exception $e) {
|
||||||
|
http_response_code(400);
|
||||||
|
echo json_encode(['success' => false, 'error' => $e->getMessage()]);
|
||||||
|
}
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($action === 'update_advance') {
|
||||||
|
header('Content-Type: application/json');
|
||||||
|
try {
|
||||||
|
$id = (int)($_POST['id'] ?? 0);
|
||||||
|
$payer = trim($_POST['payer'] ?? '');
|
||||||
|
$advance_date = $_POST['advance_date'] ?? date('Y-m-d');
|
||||||
|
$description = trim($_POST['description'] ?? '');
|
||||||
|
$amount = abs((float)($_POST['amount'] ?? 0));
|
||||||
|
$from_savings = isset($_POST['from_savings']) ? 1 : 0;
|
||||||
|
|
||||||
|
if ($id <= 0 || empty($payer) || empty($description) || $amount <= 0) {
|
||||||
|
throw new Exception("Paramètres invalides fournis.");
|
||||||
|
}
|
||||||
|
|
||||||
|
$stmt = $pdo->prepare("UPDATE pf_advances SET advance_date = ?, payer = ?, description = ?, amount = ?, from_savings = ? WHERE id = ?");
|
||||||
|
$stmt->execute([$advance_date, $payer, $description, $amount, $from_savings, $id]);
|
||||||
|
|
||||||
|
echo json_encode(['success' => true]);
|
||||||
|
} catch (Exception $e) {
|
||||||
|
http_response_code(400);
|
||||||
|
echo json_encode(['success' => false, 'error' => $e->getMessage()]);
|
||||||
|
}
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($action === 'resolve_advance') {
|
||||||
|
header('Content-Type: application/json');
|
||||||
|
try {
|
||||||
|
$id = (int)($_POST['id'] ?? 0);
|
||||||
|
if ($id <= 0) throw new Exception("ID invalide fourni.");
|
||||||
|
|
||||||
|
$stmt = $pdo->prepare("UPDATE pf_advances SET is_resolved = 1 WHERE id = ?");
|
||||||
|
$stmt->execute([$id]);
|
||||||
|
|
||||||
|
echo json_encode(['success' => true]);
|
||||||
|
} catch (Exception $e) {
|
||||||
|
http_response_code(400);
|
||||||
|
echo json_encode(['success' => false, 'error' => $e->getMessage()]);
|
||||||
|
}
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($action === 'delete_advance') {
|
||||||
|
header('Content-Type: application/json');
|
||||||
|
try {
|
||||||
|
$id = (int)($_POST['id'] ?? 0);
|
||||||
|
if ($id <= 0) throw new Exception("ID invalide.");
|
||||||
|
|
||||||
|
$stmt = $pdo->prepare("DELETE FROM pf_advances WHERE id = ?");
|
||||||
|
$stmt->execute([$id]);
|
||||||
|
|
||||||
|
echo json_encode(['success' => true]);
|
||||||
|
} catch (Exception $e) {
|
||||||
|
http_response_code(400);
|
||||||
|
echo json_encode(['success' => false, 'error' => $e->getMessage()]);
|
||||||
|
}
|
||||||
|
exit;
|
||||||
|
}
|
||||||
@@ -102,6 +102,41 @@ function getTranslatedMonthName($dateString) {
|
|||||||
$y = date('Y', strtotime($dateString));
|
$y = date('Y', strtotime($dateString));
|
||||||
return tr('month_' . $m) . ' ' . $y;
|
return tr('month_' . $m) . ' ' . $y;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// --- 🧠 PREPARATION DATA TRICOUNT / AVANCES ---
|
||||||
|
$stmtAdvancesList = $pdo->query("SELECT * FROM pf_advances WHERE is_resolved = 0 ORDER BY advance_date DESC");
|
||||||
|
$activeAdvances = $stmtAdvancesList->fetchAll(PDO::FETCH_ASSOC);
|
||||||
|
|
||||||
|
$advTotal = [$p1_name => 0, $p2_name => 0];
|
||||||
|
$livretTotal = [$p1_name => 0, $p2_name => 0];
|
||||||
|
|
||||||
|
$labelsCC = [$p1_name => [], $p2_name => []];
|
||||||
|
$labelsLivret = [$p1_name => [], $p2_name => []];
|
||||||
|
|
||||||
|
foreach ($activeAdvances as $adv) {
|
||||||
|
$p = $adv['payer'];
|
||||||
|
$amt = (float)$adv['amount'];
|
||||||
|
$labelStr = htmlspecialchars($adv['description']) . ' (' . number_format($amt, 0, ',', ' ') . '€)';
|
||||||
|
|
||||||
|
if (!isset($advTotal[$p])) {
|
||||||
|
$advTotal[$p] = 0; $livretTotal[$p] = 0;
|
||||||
|
$labelsCC[$p] = []; $labelsLivret[$p] = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($adv['from_savings']) {
|
||||||
|
$livretTotal[$p] += $amt;
|
||||||
|
$labelsLivret[$p][] = $labelStr;
|
||||||
|
} else {
|
||||||
|
$advTotal[$p] += $amt;
|
||||||
|
$labelsCC[$p][] = $labelStr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$balanceDiff = abs(($advTotal[$p1_name] ?? 0) - ($advTotal[$p2_name] ?? 0));
|
||||||
|
$owedTo = '';
|
||||||
|
if (($advTotal[$p1_name] ?? 0) > ($advTotal[$p2_name] ?? 0)) $owedTo = $p1_name;
|
||||||
|
elseif (($advTotal[$p2_name] ?? 0) > ($advTotal[$p1_name] ?? 0)) $owedTo = $p2_name;
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|
||||||
<div class="prev-container" style="--p1-main: <?= $parentMapping[0]['color'] ?>; --p2-main: <?= $parentMapping[1]['color'] ?? '#f59e0b' ?>;">
|
<div class="prev-container" style="--p1-main: <?= $parentMapping[0]['color'] ?>; --p2-main: <?= $parentMapping[1]['color'] ?? '#f59e0b' ?>;">
|
||||||
@@ -288,6 +323,125 @@ function getTranslatedMonthName($dateString) {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div style="margin: 30px 0; background: var(--bg-panel); padding: 24px; border-radius: var(--radius); border: 1px solid var(--border-light); box-shadow: var(--shadow);">
|
||||||
|
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 24px; flex-wrap: wrap; gap: 12px;">
|
||||||
|
<h3 style="margin: 0; font-size: 1.3rem; font-weight: 800;"><?= tr('bud_adv_title') ?></h3>
|
||||||
|
<button type="button" class="pf-btn" onclick="document.getElementById('addAdvanceModal').classList.add('is-active')">
|
||||||
|
+ <?= tr('bud_adv_add') ?>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div style="display: flex; gap: 20px; margin-bottom: 24px; flex-wrap: wrap;">
|
||||||
|
<div style="flex: 1; min-width: 240px; background: rgba(8, 145, 178, 0.06); border: 1px solid rgba(8, 145, 178, 0.2); padding: 18px; border-radius: 12px;">
|
||||||
|
<div style="font-size: 0.85rem; color: #0891b2; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em;"><?= sprintf(tr('bud_adv_has_advanced'), htmlspecialchars($p1_name)) ?></div>
|
||||||
|
<div style="margin-top: 10px;">
|
||||||
|
<div style="display: flex; align-items: baseline; gap: 6px;">
|
||||||
|
<span style="font-size: 1.5rem; font-weight: 800; color: #164e63; font-family: monospace;"><?= number_format($advTotal[$p1_name] ?? 0, 2, ',', ' ') ?> €</span>
|
||||||
|
</div>
|
||||||
|
<small style="color: var(--text-muted); font-size: 0.75rem; font-weight: 500;"><?= tr('bud_adv_cc_label') ?></small>
|
||||||
|
<?php if (!empty($labelsCC[$p1_name])): ?>
|
||||||
|
<div style="font-size: 0.75rem; color: #0e7490; margin-top: 6px; line-height: 1.4; font-style: italic;">
|
||||||
|
<?= implode(', ', $labelsCC[$p1_name]) ?>
|
||||||
|
</div>
|
||||||
|
<?php endif; ?>
|
||||||
|
</div>
|
||||||
|
<?php if(($livretTotal[$p1_name] ?? 0) > 0): ?>
|
||||||
|
<div style="margin-top: 14px; padding-top: 10px; border-top: 1px dashed rgba(8, 145, 178, 0.3);">
|
||||||
|
<div style="font-size: 1.2rem; font-weight: 800; color: #4338ca; font-family: monospace;">+ <?= number_format($livretTotal[$p1_name], 2, ',', ' ') ?> €</div>
|
||||||
|
<small style="color: #4338ca; font-size: 0.75rem; font-weight: 600;"><?= tr('bud_adv_livret_label') ?></small>
|
||||||
|
<?php if (!empty($labelsLivret[$p1_name])): ?>
|
||||||
|
<div style="font-size: 0.75rem; color: #3730a3; margin-top: 4px; line-height: 1.4;">
|
||||||
|
<?= implode(', ', $labelsLivret[$p1_name]) ?>
|
||||||
|
</div>
|
||||||
|
<?php endif; ?>
|
||||||
|
</div>
|
||||||
|
<?php endif; ?>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div style="flex: 1; min-width: 240px; background: rgba(217, 119, 6, 0.06); border: 1px solid rgba(217, 119, 6, 0.2); padding: 18px; border-radius: 12px;">
|
||||||
|
<div style="font-size: 0.85rem; color: #d97706; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em;"><?= sprintf(tr('bud_adv_has_advanced'), htmlspecialchars($p2_name)) ?></div>
|
||||||
|
<div style="margin-top: 10px;">
|
||||||
|
<div style="display: flex; align-items: baseline; gap: 6px;">
|
||||||
|
<span style="font-size: 1.5rem; font-weight: 800; color: #78350f; font-family: monospace;"><?= number_format($advTotal[$p2_name] ?? 0, 2, ',', ' ') ?> €</span>
|
||||||
|
</div>
|
||||||
|
<small style="color: var(--text-muted); font-size: 0.75rem; font-weight: 500;"><?= tr('bud_adv_cc_label') ?></small>
|
||||||
|
<?php if (!empty($labelsCC[$p2_name])): ?>
|
||||||
|
<div style="font-size: 0.75rem; color: #b45309; margin-top: 6px; line-height: 1.4; font-style: italic;">
|
||||||
|
<?= implode(', ', $labelsCC[$p2_name]) ?>
|
||||||
|
</div>
|
||||||
|
<?php endif; ?>
|
||||||
|
</div>
|
||||||
|
<?php if(($livretTotal[$p2_name] ?? 0) > 0): ?>
|
||||||
|
<div style="margin-top: 14px; padding-top: 10px; border-top: 1px dashed rgba(217, 119, 6, 0.3);">
|
||||||
|
<div style="font-size: 1.2rem; font-weight: 800; color: #b45309; font-family: monospace;">+ <?= number_format($livretTotal[$p2_name], 2, ',', ' ') ?> €</div>
|
||||||
|
<small style="color: #b45309; font-size: 0.75rem; font-weight: 600;"><?= tr('bud_adv_livret_label') ?></small>
|
||||||
|
<?php if (!empty($labelsLivret[$p2_name])): ?>
|
||||||
|
<div style="font-size: 0.75rem; color: #92400e; margin-top: 4px; line-height: 1.4;">
|
||||||
|
<?= implode(', ', $labelsLivret[$p2_name]) ?>
|
||||||
|
</div>
|
||||||
|
<?php endif; ?>
|
||||||
|
</div>
|
||||||
|
<?php endif; ?>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div style="flex: 1; min-width: 240px; background: var(--bg-page); border: 1px solid var(--border-light); padding: 18px; border-radius: 12px; display: flex; flex-direction: column; justify-content: center;">
|
||||||
|
<div style="font-size: 0.75rem; color: var(--text-muted); font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 6px;">
|
||||||
|
🏛️ <?= tr('bud_adv_cc_balance_title') ?>
|
||||||
|
</div>
|
||||||
|
<div style="font-size: 1.15rem; font-weight: 800;">
|
||||||
|
<?php if ($balanceDiff > 0.01): ?>
|
||||||
|
<?= sprintf(tr('bud_adv_owed_to'), number_format($balanceDiff, 2, ',', ' '), htmlspecialchars($owedTo)) ?>
|
||||||
|
<?php else: ?>
|
||||||
|
<span style="color: var(--success); font-weight: bold;">✓ <?= tr('bud_adv_balanced') ?></span>
|
||||||
|
<?php endif; ?>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<?php if (!empty($activeAdvances)): ?>
|
||||||
|
<div style="overflow-x:auto;">
|
||||||
|
<table class="pf-table" style="margin: 0; box-shadow: none; border: 1px solid var(--border-light);">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th><?= tr('date') ?></th>
|
||||||
|
<th><?= tr('bud_adv_payer') ?></th>
|
||||||
|
<th><?= tr('bud_label_name') ?></th>
|
||||||
|
<th><?= tr('bud_amount') ?></th>
|
||||||
|
<th style="text-align: right;"><?= tr('actions') ?></th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<?php foreach ($activeAdvances as $adv): ?>
|
||||||
|
<tr>
|
||||||
|
<td style="color: var(--text-muted);"><?= date('d/m/Y', strtotime($adv['advance_date'])) ?></td>
|
||||||
|
<td style="font-weight: 700; color: <?= $adv['payer'] === $p1_name ? '#0891b2' : '#d97706' ?>;"><?= htmlspecialchars($adv['payer']) ?></td>
|
||||||
|
<td>
|
||||||
|
<?= htmlspecialchars($adv['description']) ?>
|
||||||
|
<?php if ($adv['from_savings']): ?>
|
||||||
|
<span style="background: var(--bg-soft); color: var(--primary); font-size: 0.7rem; padding: 2px 6px; border-radius: 4px; margin-left: 6px; font-weight: bold; border: 1px solid rgba(59, 130, 246, 0.2);"><?= tr('bud_adv_saved_badge') ?></span>
|
||||||
|
<?php endif; ?>
|
||||||
|
</td>
|
||||||
|
<td style="font-weight: 700; font-family: monospace;"><?= number_format($adv['amount'], 2, ',', ' ') ?> €</td>
|
||||||
|
<td style="text-align: right; white-space: nowrap;">
|
||||||
|
<button class="btn-icon-action edit" title="<?= tr('edit') ?>"
|
||||||
|
data-id="<?= $adv['id'] ?>"
|
||||||
|
data-payer="<?= htmlspecialchars($adv['payer']) ?>"
|
||||||
|
data-date="<?= $adv['advance_date'] ?>"
|
||||||
|
data-desc="<?= htmlspecialchars($adv['description']) ?>"
|
||||||
|
data-amount="<?= $adv['amount'] ?>"
|
||||||
|
data-savings="<?= $adv['from_savings'] ?>"
|
||||||
|
onclick="triggerEditAdvanceModal(this)">✏️</button>
|
||||||
|
<button class="btn-icon-action delete" title="<?= tr('delete') ?>" onclick="executeDeleteAdvance(<?= $adv['id'] ?>)">🗑️</button>
|
||||||
|
<button class="pf-btn" style="padding: 4px 10px; font-size: 0.8rem; border-radius: 6px; width:auto; height:auto;" onclick="executeResolveAdvance(<?= $adv['id'] ?>)">✓</button>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
<?php endif; ?>
|
||||||
|
</div>
|
||||||
|
|
||||||
<?php
|
<?php
|
||||||
$focusMonth = $months[0];
|
$focusMonth = $months[0];
|
||||||
$targetsOrder = ['vers commune', 'vers L.Pol', 'vers L.Pep', 'vers L.Perso'];
|
$targetsOrder = ['vers commune', 'vers L.Pol', 'vers L.Pep', 'vers L.Perso'];
|
||||||
@@ -365,13 +519,13 @@ function getTranslatedMonthName($dateString) {
|
|||||||
<input type="text" name="name" class="pf-input" required>
|
<input type="text" name="name" class="pf-input" required>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label class="pf-label">Objectif Mensuel (€)</label>
|
<label class="pf-label"><?= tr('bud_prev_monthly_target') ?? 'Objectif Mensuel (€)' ?></label>
|
||||||
<input type="number" step="1" name="target" class="pf-input" placeholder="Ex: 150">
|
<input type="number" step="1" name="target" class="pf-input" placeholder="Ex: 150">
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label class="pf-label">Destination Virement (Optionnel)</label>
|
<label class="pf-label"><?= tr('bud_prev_transfer_dest') ?? 'Destination Virement (Optionnel)' ?></label>
|
||||||
<select name="transfer_dest" class="pf-input">
|
<select name="transfer_dest" class="pf-input">
|
||||||
<option value="" selected>-- Aucune --</option>
|
<option value="" selected>-- <?= tr('bud_prev_none') ?? 'Aucune' ?> --</option>
|
||||||
<option value="vers L.Pol">vers L.Pol</option>
|
<option value="vers L.Pol">vers L.Pol</option>
|
||||||
<option value="vers L.Pep">vers L.Pep</option>
|
<option value="vers L.Pep">vers L.Pep</option>
|
||||||
<option value="vers L.Perso">vers L.Perso</option>
|
<option value="vers L.Perso">vers L.Perso</option>
|
||||||
@@ -409,13 +563,13 @@ function getTranslatedMonthName($dateString) {
|
|||||||
<input type="text" name="name" id="edit_cat_name" class="pf-input" required>
|
<input type="text" name="name" id="edit_cat_name" class="pf-input" required>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label class="pf-label">Objectif Mensuel (€)</label>
|
<label class="pf-label"><?= tr('bud_prev_monthly_target') ?? 'Objectif Mensuel (€)' ?></label>
|
||||||
<input type="number" step="1" name="target" id="edit_cat_target" class="pf-input" placeholder="Ex: 150">
|
<input type="number" step="1" name="target" id="edit_cat_target" class="pf-input" placeholder="Ex: 150">
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label class="pf-label">Destination Virement (Optionnel)</label>
|
<label class="pf-label"><?= tr('bud_prev_transfer_dest') ?? 'Destination Virement (Optionnel)' ?></label>
|
||||||
<select name="transfer_dest" id="edit_cat_transfer_dest" class="pf-input">
|
<select name="transfer_dest" id="edit_cat_transfer_dest" class="pf-input">
|
||||||
<option value="">-- Aucune --</option>
|
<option value="">-- <?= tr('bud_prev_none') ?? 'Aucune' ?> --</option>
|
||||||
<option value="vers L.Pol">vers L.Pol</option>
|
<option value="vers L.Pol">vers L.Pol</option>
|
||||||
<option value="vers L.Pep">vers L.Pep</option>
|
<option value="vers L.Pep">vers L.Pep</option>
|
||||||
<option value="vers L.Perso">vers L.Perso</option>
|
<option value="vers L.Perso">vers L.Perso</option>
|
||||||
@@ -439,6 +593,85 @@ function getTranslatedMonthName($dateString) {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div id="addAdvanceModal" class="pf-modal">
|
||||||
|
<div class="pf-modal-content">
|
||||||
|
<div style="display:flex; justify-content:space-between; align-items:center; margin-bottom:16px;">
|
||||||
|
<h3 class="pf-modal-title" style="margin:0; border:none; padding:0;">+ <?= tr('bud_adv_add') ?></h3>
|
||||||
|
<button type="button" onclick="closeSuiviModal('addAdvanceModal')" style="background:none; border:none; font-size:1.5rem; cursor:pointer; color:var(--text-muted);">×</button>
|
||||||
|
</div>
|
||||||
|
<form action="/modules/budget/includes/api/save-budget.php" method="POST" id="formAddAdvance" onsubmit="handleAdvanceSubmit(event, this)">
|
||||||
|
<input type="hidden" name="action" value="save_advance">
|
||||||
|
<div class="pf-form-group">
|
||||||
|
<label class="pf-label"><?= tr('bud_adv_who_paid') ?></label>
|
||||||
|
<select name="payer" class="pf-input" required>
|
||||||
|
<option value="<?= htmlspecialchars($p1_name) ?>"><?= htmlspecialchars($p1_name) ?></option>
|
||||||
|
<option value="<?= htmlspecialchars($p2_name) ?>"><?= htmlspecialchars($p2_name) ?></option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<div class="pf-form-group">
|
||||||
|
<label class="pf-label"><?= tr('date') ?></label>
|
||||||
|
<input type="date" name="advance_date" class="pf-input" value="<?= date('Y-m-d') ?>" required>
|
||||||
|
</div>
|
||||||
|
<div class="pf-form-group">
|
||||||
|
<label class="pf-label"><?= tr('bud_label_name') ?></label>
|
||||||
|
<input type="text" name="description" class="pf-input" placeholder="<?= tr('bud_adv_ph_desc') ?>" required autocomplete="off">
|
||||||
|
</div>
|
||||||
|
<div class="pf-form-group">
|
||||||
|
<label class="pf-label"><?= tr('bud_amount') ?></label>
|
||||||
|
<input type="number" step="0.01" min="0.01" name="amount" class="pf-input" required>
|
||||||
|
</div>
|
||||||
|
<div class="pf-form-group" style="display:flex; align-items:center; gap:8px; margin-top:10px;">
|
||||||
|
<input type="checkbox" name="from_savings" id="add_from_savings" value="1" class="pf-checkbox-lg">
|
||||||
|
<label for="add_from_savings" style="margin:0; cursor:pointer; font-weight:600; color:var(--primary);"><?= tr('bud_adv_already_saved') ?></label>
|
||||||
|
</div>
|
||||||
|
<div class="modal-footer">
|
||||||
|
<button type="button" onclick="closeSuiviModal('addAdvanceModal')" class="pf-btn btn-secondary"><?= tr('btn_cancel') ?></button>
|
||||||
|
<button type="submit" class="pf-btn"><?= tr('btn_save') ?></button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="editAdvanceModal" class="pf-modal">
|
||||||
|
<div class="pf-modal-content">
|
||||||
|
<div style="display:flex; justify-content:space-between; align-items:center; margin-bottom:16px;">
|
||||||
|
<h3 class="pf-modal-title" style="margin:0; border:none; padding:0;">✏️ <?= tr('bud_adv_edit') ?></h3>
|
||||||
|
<button type="button" onclick="closeSuiviModal('editAdvanceModal')" style="background:none; border:none; font-size:1.5rem; cursor:pointer; color:var(--text-muted);">×</button>
|
||||||
|
</div>
|
||||||
|
<form action="/modules/budget/includes/api/save-budget.php" method="POST" id="formEditAdvance" onsubmit="handleAdvanceSubmit(event, this)">
|
||||||
|
<input type="hidden" name="action" value="update_advance">
|
||||||
|
<input type="hidden" name="id" id="edit_adv_id">
|
||||||
|
<div class="pf-form-group">
|
||||||
|
<label class="pf-label"><?= tr('bud_adv_who_paid') ?></label>
|
||||||
|
<select name="payer" id="edit_adv_payer" class="pf-input" required>
|
||||||
|
<option value="<?= htmlspecialchars($p1_name) ?>"><?= htmlspecialchars($p1_name) ?></option>
|
||||||
|
<option value="<?= htmlspecialchars($p2_name) ?>"><?= htmlspecialchars($p2_name) ?></option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<div class="pf-form-group">
|
||||||
|
<label class="pf-label"><?= tr('date') ?></label>
|
||||||
|
<input type="date" name="advance_date" id="edit_adv_date" class="pf-input" required>
|
||||||
|
</div>
|
||||||
|
<div class="pf-form-group">
|
||||||
|
<label class="pf-label"><?= tr('bud_label_name') ?></label>
|
||||||
|
<input type="text" name="description" id="edit_adv_desc" class="pf-input" required autocomplete="off">
|
||||||
|
</div>
|
||||||
|
<div class="pf-form-group">
|
||||||
|
<label class="pf-label"><?= tr('bud_amount') ?></label>
|
||||||
|
<input type="number" step="0.01" min="0.01" name="amount" id="edit_adv_amount" class="pf-input" required>
|
||||||
|
</div>
|
||||||
|
<div class="pf-form-group" style="display:flex; align-items:center; gap:8px; margin-top:10px;">
|
||||||
|
<input type="checkbox" name="from_savings" id="edit_adv_from_savings" value="1" class="pf-checkbox-lg">
|
||||||
|
<label for="edit_adv_from_savings" style="margin:0; cursor:pointer; font-weight:600; color:var(--primary);"><?= tr('bud_adv_already_saved') ?></label>
|
||||||
|
</div>
|
||||||
|
<div class="modal-footer">
|
||||||
|
<button type="button" onclick="closeSuiviModal('editAdvanceModal')" class="pf-btn btn-secondary"><?= tr('btn_cancel') ?></button>
|
||||||
|
<button type="submit" class="pf-btn"><?= tr('btn_save') ?></button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<button id="fabSumMode" class="pf-fab-sum" onclick="toggleSumMode()">
|
<button id="fabSumMode" class="pf-fab-sum" onclick="toggleSumMode()">
|
||||||
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><path d="M18 4H6a2 2 0 0 0-2 2v12a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V6a2 2 0 0 0-2-2z"></path><line x1="8" y1="12" x2="16" y2="12"></line><line x1="12" y1="8" x2="12" y2="16"></line></svg>
|
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><path d="M18 4H6a2 2 0 0 0-2 2v12a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V6a2 2 0 0 0-2-2z"></path><line x1="8" y1="12" x2="16" y2="12"></line><line x1="12" y1="8" x2="12" y2="16"></line></svg>
|
||||||
</button>
|
</button>
|
||||||
@@ -451,12 +684,17 @@ function getTranslatedMonthName($dateString) {
|
|||||||
|
|
||||||
<script>
|
<script>
|
||||||
window.appLang = document.documentElement.lang === "ca" ? "ca-ES" : "fr-FR";
|
window.appLang = document.documentElement.lang === "ca" ? "ca-ES" : "fr-FR";
|
||||||
|
|
||||||
|
// Dictionnaire I18N injecté proprement depuis PHP
|
||||||
window.I18N = {
|
window.I18N = {
|
||||||
...(window.I18N || {}),
|
...(window.I18N || {}),
|
||||||
'bud_prev_label_name': <?= json_encode(tr('bud_prev_label_name')) ?>,
|
'bud_prev_label_name': <?= json_encode(tr('bud_prev_label_name')) ?>,
|
||||||
'bud_prev_err_no_history': <?= json_encode(tr('bud_prev_err_no_history')) ?>,
|
'bud_prev_err_no_history': <?= json_encode(tr('bud_prev_err_no_history')) ?>,
|
||||||
'bud_prev_confirm_copy': <?= json_encode(tr('bud_prev_confirm_copy')) ?>,
|
'bud_prev_confirm_copy': <?= json_encode(tr('bud_prev_confirm_copy')) ?>,
|
||||||
'bud_prev_confirm_transfers': <?= json_encode(tr('bud_prev_confirm_transfers')) ?>,
|
'bud_prev_confirm_transfers': <?= json_encode(tr('bud_prev_confirm_transfers')) ?>,
|
||||||
|
'bud_prev_confirm_del_line': <?= json_encode(tr('bud_prev_confirm_del_line')) ?>,
|
||||||
|
'bud_adv_confirm_resolve': <?= json_encode(tr('bud_adv_confirm_resolve') ?? 'Confirmer le remboursement ?') ?>,
|
||||||
|
'bud_adv_confirm_delete': <?= json_encode(tr('bud_adv_confirm_delete') ?? 'Supprimer définitivement ?') ?>,
|
||||||
'bud_err_tech': <?= json_encode(tr('bud_err_tech')) ?>
|
'bud_err_tech': <?= json_encode(tr('bud_err_tech')) ?>
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -467,6 +705,8 @@ window.CONFIG.CURRENCY = '<?= defined('CURRENCY') ? CURRENCY : "€" ?>';
|
|||||||
const currentYear = <?= $currentYear ?>;
|
const currentYear = <?= $currentYear ?>;
|
||||||
const months = <?= json_encode($months) ?>;
|
const months = <?= json_encode($months) ?>;
|
||||||
|
|
||||||
|
/* --- LOGIQUE ALLOCATIONS & BUDGET --- */
|
||||||
|
|
||||||
function openEditModal(btn) {
|
function openEditModal(btn) {
|
||||||
document.getElementById('edit_cat_id').value = btn.getAttribute('data-id');
|
document.getElementById('edit_cat_id').value = btn.getAttribute('data-id');
|
||||||
document.getElementById('edit_cat_name').value = btn.getAttribute('data-name');
|
document.getElementById('edit_cat_name').value = btn.getAttribute('data-name');
|
||||||
@@ -486,7 +726,6 @@ function updateSalary(person, input) {
|
|||||||
const ecoF = parseFloat(row.querySelector('[data-field="eco_family"]').value) || 0;
|
const ecoF = parseFloat(row.querySelector('[data-field="eco_family"]').value) || 0;
|
||||||
|
|
||||||
const restant = salary - (mens + frais + ecoP + ecoF);
|
const restant = salary - (mens + frais + ecoP + ecoF);
|
||||||
|
|
||||||
const parentMap = window.CONFIG.parentMapping.find(m => m.name === person);
|
const parentMap = window.CONFIG.parentMapping.find(m => m.name === person);
|
||||||
if(parentMap) {
|
if(parentMap) {
|
||||||
document.getElementById('restant_' + parentMap.css).innerText = Math.round(restant).toLocaleString(window.appLang) + ' €';
|
document.getElementById('restant_' + parentMap.css).innerText = Math.round(restant).toLocaleString(window.appLang) + ' €';
|
||||||
@@ -644,11 +883,14 @@ function updateSummaryTable() {
|
|||||||
function saveData(action, data) {
|
function saveData(action, data) {
|
||||||
const formData = new FormData();
|
const formData = new FormData();
|
||||||
formData.append('action', action);
|
formData.append('action', action);
|
||||||
|
formData.append('ajax', '1'); // <-- Sécurisation pour pachaFetch / backend
|
||||||
for (const key in data) formData.append(key, data[key]);
|
for (const key in data) formData.append(key, data[key]);
|
||||||
fetch('modules/budget/includes/api/save-budget.php', { method: 'POST', body: formData });
|
|
||||||
|
// On utilise fetch ici en mode aveugle pour ne pas bloquer l'UI lors de la frappe rapide
|
||||||
|
fetch('/modules/budget/includes/api/save-budget.php', { method: 'POST', body: formData });
|
||||||
}
|
}
|
||||||
|
|
||||||
function validateTransfers(personCss, month) {
|
async function validateTransfers(personCss, month) {
|
||||||
const parentMap = window.CONFIG.parentMapping.find(m => m.css === personCss);
|
const parentMap = window.CONFIG.parentMapping.find(m => m.css === personCss);
|
||||||
if (!parentMap) return;
|
if (!parentMap) return;
|
||||||
|
|
||||||
@@ -659,30 +901,30 @@ function validateTransfers(personCss, month) {
|
|||||||
formData.append('action', 'validate_transfers');
|
formData.append('action', 'validate_transfers');
|
||||||
formData.append('person_id', parentMap.id);
|
formData.append('person_id', parentMap.id);
|
||||||
formData.append('month_date', month);
|
formData.append('month_date', month);
|
||||||
|
formData.append('ajax', '1');
|
||||||
|
|
||||||
fetch('modules/budget/includes/api/save-budget.php', { method: 'POST', body: formData })
|
try {
|
||||||
.then(r => r.json())
|
const result = await pachaFetch('/modules/budget/includes/api/save-budget.php', { method: 'POST', body: formData });
|
||||||
.then(data => {
|
if(result.success) {
|
||||||
if(data.success) window.location.reload();
|
window.location.reload();
|
||||||
else alert("Erreur: " + data.error);
|
} else {
|
||||||
})
|
alert(window.I18N['bud_err_tech'] + " : " + result.error);
|
||||||
.catch(e => alert(window.I18N['bud_err_tech']));
|
}
|
||||||
|
} catch(e) {
|
||||||
|
alert(window.I18N['bud_err_tech']);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function saveGenericNote(noteType, refId, content) {
|
async function saveGenericNote(noteType, refId, content) {
|
||||||
const formData = new FormData();
|
const formData = new FormData();
|
||||||
formData.append('action', 'save_note');
|
formData.append('action', 'save_note');
|
||||||
formData.append('note_type', noteType);
|
formData.append('note_type', noteType);
|
||||||
formData.append('reference_id', refId);
|
formData.append('reference_id', refId);
|
||||||
formData.append('content', content);
|
formData.append('content', content);
|
||||||
|
formData.append('ajax', '1');
|
||||||
|
|
||||||
fetch('modules/budget/includes/api/save-budget.php', { method: 'POST', body: formData })
|
try {
|
||||||
.then(async r => {
|
const data = await pachaFetch('/modules/budget/includes/api/save-budget.php', { method: 'POST', body: formData });
|
||||||
const text = await r.text();
|
|
||||||
if (!r.ok) throw new Error(`Erreur HTTP ${r.status}`);
|
|
||||||
return JSON.parse(text);
|
|
||||||
})
|
|
||||||
.then(data => {
|
|
||||||
if(data.success) {
|
if(data.success) {
|
||||||
const indicator = document.getElementById('note-save-indicator');
|
const indicator = document.getElementById('note-save-indicator');
|
||||||
if(indicator) {
|
if(indicator) {
|
||||||
@@ -690,12 +932,107 @@ function saveGenericNote(noteType, refId, content) {
|
|||||||
setTimeout(() => indicator.style.opacity = '0', 2000);
|
setTimeout(() => indicator.style.opacity = '0', 2000);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
alert("Erreur: " + data.error);
|
alert(window.I18N['bud_err_tech'] + " : " + data.error);
|
||||||
}
|
}
|
||||||
})
|
} catch(e) {
|
||||||
.catch(e => alert(e.message));
|
alert(window.I18N['bud_err_tech']);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function deleteCategory(id) {
|
||||||
|
if (!confirm(window.I18N['bud_prev_confirm_del_line'])) return;
|
||||||
|
const formData = new FormData();
|
||||||
|
formData.append('action', 'delete_category');
|
||||||
|
formData.append('id', id);
|
||||||
|
formData.append('ajax', '1');
|
||||||
|
try {
|
||||||
|
const result = await pachaFetch('/modules/budget/includes/api/save-budget.php', { method: 'POST', body: formData });
|
||||||
|
if (result.success) window.location.reload();
|
||||||
|
} catch(e) { console.error(e); }
|
||||||
|
}
|
||||||
|
|
||||||
|
/* --- LOGIQUE TRICOUNT / AVANCES --- */
|
||||||
|
|
||||||
|
function closeSuiviModal(modalId) {
|
||||||
|
document.getElementById(modalId).classList.remove('is-active');
|
||||||
|
}
|
||||||
|
|
||||||
|
function openSuiviModal(modalId) {
|
||||||
|
document.getElementById(modalId).classList.add('is-active');
|
||||||
|
}
|
||||||
|
|
||||||
|
function triggerEditAdvanceModal(btn) {
|
||||||
|
document.getElementById('edit_adv_id').value = btn.getAttribute('data-id');
|
||||||
|
document.getElementById('edit_adv_payer').value = btn.getAttribute('data-payer');
|
||||||
|
document.getElementById('edit_adv_date').value = btn.getAttribute('data-date');
|
||||||
|
document.getElementById('edit_adv_desc').value = btn.getAttribute('data-desc');
|
||||||
|
document.getElementById('edit_adv_amount').value = btn.getAttribute('data-amount');
|
||||||
|
document.getElementById('edit_adv_from_savings').checked = (btn.getAttribute('data-savings') === '1');
|
||||||
|
openSuiviModal('editAdvanceModal');
|
||||||
|
}
|
||||||
|
|
||||||
|
async function handleAdvanceSubmit(event, form) {
|
||||||
|
event.preventDefault();
|
||||||
|
const btnSubmit = form.querySelector('button[type="submit"]');
|
||||||
|
const oldText = btnSubmit.innerHTML;
|
||||||
|
btnSubmit.disabled = true;
|
||||||
|
btnSubmit.innerHTML = '...';
|
||||||
|
|
||||||
|
const endpoint = form.getAttribute('action');
|
||||||
|
const formData = new FormData(form);
|
||||||
|
formData.append('ajax', '1'); // <-- Correction de l'erreur d'empty string
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Utilisation robuste de pachaFetch
|
||||||
|
const result = await pachaFetch(endpoint, { method: 'POST', body: formData });
|
||||||
|
|
||||||
|
if (result.success) {
|
||||||
|
window.location.reload();
|
||||||
|
} else {
|
||||||
|
alert((window.I18N['bud_err_tech'] || "Erreur") + " : " + (result.error || "Opération échouée"));
|
||||||
|
btnSubmit.disabled = false;
|
||||||
|
btnSubmit.innerHTML = oldText;
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
console.error("AJAX Error:", err);
|
||||||
|
alert(window.I18N['bud_err_tech'] || "Une erreur technique est survenue.");
|
||||||
|
btnSubmit.disabled = false;
|
||||||
|
btnSubmit.innerHTML = oldText;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function executeResolveAdvance(id) {
|
||||||
|
if (!confirm(window.I18N['bud_adv_confirm_resolve'])) return;
|
||||||
|
const fd = new FormData();
|
||||||
|
fd.append('action', 'resolve_advance');
|
||||||
|
fd.append('id', id);
|
||||||
|
fd.append('ajax', '1');
|
||||||
|
|
||||||
|
try {
|
||||||
|
await pachaFetch('/modules/budget/includes/api/save-budget.php', { method: 'POST', body: fd });
|
||||||
|
window.location.reload();
|
||||||
|
} catch(err) {
|
||||||
|
console.error(err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function executeDeleteAdvance(id) {
|
||||||
|
if (!confirm(window.I18N['bud_adv_confirm_delete'])) return;
|
||||||
|
const fd = new FormData();
|
||||||
|
fd.append('action', 'delete_advance');
|
||||||
|
fd.append('id', id);
|
||||||
|
fd.append('ajax', '1');
|
||||||
|
|
||||||
|
try {
|
||||||
|
await pachaFetch('/modules/budget/includes/api/save-budget.php', { method: 'POST', body: fd });
|
||||||
|
window.location.reload();
|
||||||
|
} catch(err) {
|
||||||
|
console.error(err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* --- LOGIQUE MODE SOMME AUTOMATIQUE --- */
|
||||||
|
|
||||||
let isSumModeActive = false;
|
let isSumModeActive = false;
|
||||||
let selectedElementsForSum = new Set();
|
let selectedElementsForSum = new Set();
|
||||||
|
|
||||||
@@ -730,17 +1067,7 @@ function updateSumResult() {
|
|||||||
document.getElementById('sumResultValue').innerText = Math.round(total).toLocaleString(window.appLang) + ' ' + window.CONFIG.CURRENCY;
|
document.getElementById('sumResultValue').innerText = Math.round(total).toLocaleString(window.appLang) + ' ' + window.CONFIG.CURRENCY;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function deleteCategory(id) {
|
/* --- INITIALISATIONS & ECOUTEURS --- */
|
||||||
if (!confirm(window.I18N['bud_prev_confirm_del_line'])) return;
|
|
||||||
const formData = new FormData();
|
|
||||||
formData.append('action', 'delete_category');
|
|
||||||
formData.append('id', id);
|
|
||||||
formData.append('ajax', '1');
|
|
||||||
try {
|
|
||||||
const result = await pachaFetch('modules/budget/includes/api/save-budget.php', { method: 'POST', body: formData });
|
|
||||||
if (result.success) window.location.reload();
|
|
||||||
} catch(e) { console.error(e); }
|
|
||||||
}
|
|
||||||
|
|
||||||
document.addEventListener('click', function(e) {
|
document.addEventListener('click', function(e) {
|
||||||
if (!isSumModeActive) return;
|
if (!isSumModeActive) return;
|
||||||
@@ -760,6 +1087,7 @@ document.addEventListener('click', function(e) {
|
|||||||
|
|
||||||
document.addEventListener('DOMContentLoaded', recalcAllAllocations);
|
document.addEventListener('DOMContentLoaded', recalcAllAllocations);
|
||||||
|
|
||||||
|
// Soumission standard des modales de catégories avec pachaFetch
|
||||||
document.querySelectorAll('#addCatModal form, #editCatModal form').forEach(form => {
|
document.querySelectorAll('#addCatModal form, #editCatModal form').forEach(form => {
|
||||||
form.addEventListener('submit', async (e) => {
|
form.addEventListener('submit', async (e) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
@@ -769,9 +1097,11 @@ document.querySelectorAll('#addCatModal form, #editCatModal form').forEach(form
|
|||||||
submitBtn.disabled = true;
|
submitBtn.disabled = true;
|
||||||
submitBtn.innerText = '⏳ ...';
|
submitBtn.innerText = '⏳ ...';
|
||||||
const formData = new FormData(form);
|
const formData = new FormData(form);
|
||||||
formData.append('ajax', '1');
|
formData.append('ajax', '1'); // Toujours sécuriser
|
||||||
const actionUrl = form.getAttribute('action');
|
const actionUrl = form.getAttribute('action');
|
||||||
|
|
||||||
const result = await pachaFetch(actionUrl, { method: 'POST', body: formData });
|
const result = await pachaFetch(actionUrl, { method: 'POST', body: formData });
|
||||||
|
|
||||||
if (result.success) {
|
if (result.success) {
|
||||||
form.closest('.pf-modal').style.display = 'none';
|
form.closest('.pf-modal').style.display = 'none';
|
||||||
document.body.classList.remove('no-scroll');
|
document.body.classList.remove('no-scroll');
|
||||||
@@ -780,7 +1110,7 @@ document.querySelectorAll('#addCatModal form, #editCatModal form').forEach(form
|
|||||||
alert((window.I18N['bud_err_tech'] || 'Erreur') + " : " + (result.error || "Inconnue"));
|
alert((window.I18N['bud_err_tech'] || 'Erreur') + " : " + (result.error || "Inconnue"));
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
alert("Une erreur technique est survenue.");
|
alert(window.I18N['bud_err_tech'] || "Une erreur technique est survenue.");
|
||||||
} finally {
|
} finally {
|
||||||
submitBtn.disabled = false;
|
submitBtn.disabled = false;
|
||||||
submitBtn.innerText = originalText;
|
submitBtn.innerText = originalText;
|
||||||
|
|||||||
@@ -1,9 +1,32 @@
|
|||||||
<?php
|
<?php
|
||||||
// modules/budget/views/epargne.php
|
// modules/budget/views/epargne.php
|
||||||
|
|
||||||
$requestedOwner = $_GET['owner'] ?? 'Nens';
|
// --- 🧠 CONFIGURATION AGNOSTIQUE DES MEMBRES (MULTI-TENANT) ---
|
||||||
$ownersToDisplay = ($requestedOwner === 'Nens') ? ['Pol', 'Pep'] : [$requestedOwner];
|
$stmtPeople = $pdo->query("SELECT name, role FROM pf_people ORDER BY id ASC");
|
||||||
|
$familyParents = [];
|
||||||
|
$familyKids = [];
|
||||||
|
|
||||||
|
while ($row = $stmtPeople->fetch(PDO::FETCH_ASSOC)) {
|
||||||
|
$role = strtolower(trim($row['role'] ?? ''));
|
||||||
|
|
||||||
|
if ($role === 'parent') {
|
||||||
|
$familyParents[] = $row['name'];
|
||||||
|
} elseif ($role === 'nounou') {
|
||||||
|
// On ignore la nounou dans l'épargne
|
||||||
|
continue;
|
||||||
|
} else {
|
||||||
|
// Fallback : Si c'est 'enfant', 'user', ou vide, ça va dans l'onglet Enfants
|
||||||
|
$familyKids[] = $row['name'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sécurité anti-page blanche si la BDD est mal configurée
|
||||||
|
if (empty($familyParents)) $familyParents = ['Parent 1', 'Parent 2'];
|
||||||
|
|
||||||
|
$requestedOwner = $_GET['owner'] ?? ($familyParents[0] ?? 'Nens');
|
||||||
|
$ownersToDisplay = ($requestedOwner === 'Nens') ? $familyKids : [$requestedOwner];
|
||||||
|
|
||||||
|
// --- RÉCUPÉRATION CONFIGURATION DES MOIS ---
|
||||||
$cycleConfigs = [];
|
$cycleConfigs = [];
|
||||||
$stmtNotes = $pdo->query("SELECT reference_id, content FROM pf_notes WHERE note_type = 'month_config'");
|
$stmtNotes = $pdo->query("SELECT reference_id, content FROM pf_notes WHERE note_type = 'month_config'");
|
||||||
while ($row = $stmtNotes->fetch(PDO::FETCH_ASSOC)) {
|
while ($row = $stmtNotes->fetch(PDO::FETCH_ASSOC)) {
|
||||||
@@ -14,7 +37,6 @@ while ($row = $stmtNotes->fetch(PDO::FETCH_ASSOC)) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Récupération sécurisée du nom des mois (utilise les clés globales existantes)
|
|
||||||
function getMonthName($dateString) {
|
function getMonthName($dateString) {
|
||||||
$m = date('m', strtotime($dateString));
|
$m = date('m', strtotime($dateString));
|
||||||
$y = date('Y', strtotime($dateString));
|
$y = date('Y', strtotime($dateString));
|
||||||
@@ -25,9 +47,19 @@ function getMonthName($dateString) {
|
|||||||
<div class="budget-view">
|
<div class="budget-view">
|
||||||
<div class="view-header">
|
<div class="view-header">
|
||||||
<div class="owner-tabs">
|
<div class="owner-tabs">
|
||||||
<a href="?tab=epargne&owner=Alex" class="owner-tab <?= $requestedOwner === 'Alex' ? 'active' : '' ?>">Alex</a>
|
<!-- Boucle dynamique sur les parents -->
|
||||||
<a href="?tab=epargne&owner=Laia" class="owner-tab <?= $requestedOwner === 'Laia' ? 'active' : '' ?>">Laia</a>
|
<?php foreach ($familyParents as $p): ?>
|
||||||
<a href="?tab=epargne&owner=Nens" class="owner-tab <?= $requestedOwner === 'Nens' ? 'active' : '' ?>">Nens 👶</a>
|
<a href="?tab=epargne&owner=<?= urlencode($p) ?>" class="owner-tab <?= $requestedOwner === $p ? 'active' : '' ?>">
|
||||||
|
<?= htmlspecialchars($p) ?>
|
||||||
|
</a>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
|
||||||
|
<!-- Onglet Enfants -->
|
||||||
|
<?php if (!empty($familyKids)): ?>
|
||||||
|
<a href="?tab=epargne&owner=Nens" class="owner-tab <?= $requestedOwner === 'Nens' ? 'active' : '' ?>">
|
||||||
|
<?= tr('budget_tab_kids') ?? 'Nens 👶' ?>
|
||||||
|
</a>
|
||||||
|
<?php endif; ?>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -52,10 +84,7 @@ function getMonthName($dateString) {
|
|||||||
sort($allCategories);
|
sort($allCategories);
|
||||||
|
|
||||||
// Définition de la classe couleur selon le propriétaire
|
// Définition de la classe couleur selon le propriétaire
|
||||||
$ownerTextClass = '';
|
$ownerTextClass = 'txt-global';
|
||||||
if ($currentOwner === 'Alex') $ownerTextClass = 'txt-alex';
|
|
||||||
elseif ($currentOwner === 'Laia') $ownerTextClass = 'txt-laia';
|
|
||||||
else $ownerTextClass = 'txt-global'; // Pour Pol et Pep
|
|
||||||
?>
|
?>
|
||||||
|
|
||||||
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 15px; margin-top: <?= ($requestedOwner === 'Nens' && $currentOwner !== 'Pol') ? '40px' : '0' ?>;">
|
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 15px; margin-top: <?= ($requestedOwner === 'Nens' && $currentOwner !== 'Pol') ? '40px' : '0' ?>;">
|
||||||
|
|||||||
@@ -81,18 +81,20 @@ $totalRevenus = 0;
|
|||||||
$realSum = $realTotals[$item['id']];
|
$realSum = $realTotals[$item['id']];
|
||||||
$hasMatchingExpense = true;
|
$hasMatchingExpense = true;
|
||||||
}
|
}
|
||||||
// B. Correspondance par catégorie système (École, Essence, FMCG)
|
// B. Correspondance par catégorie système (Multi-tenant via Mots-clés)
|
||||||
else {
|
else {
|
||||||
$catKey = null;
|
$catKey = null;
|
||||||
if (trim($item['name']) === 'Estimacio escola') $catKey = 'School';
|
if (!empty($item['mapping_keywords'])) {
|
||||||
elseif (trim($item['name']) === 'Estimation gasolina') $catKey = 'Essence';
|
if (stripos($item['mapping_keywords'], 'School') !== false) $catKey = 'School';
|
||||||
elseif (trim($item['name']) === 'Estimacio F&B & beauty') $catKey = 'FMCG';
|
elseif (stripos($item['mapping_keywords'], 'Essence') !== false) $catKey = 'Essence';
|
||||||
|
elseif (stripos($item['mapping_keywords'], 'FMCG') !== false) $catKey = 'FMCG';
|
||||||
|
}
|
||||||
|
|
||||||
if ($catKey && isset($catTotals[$catKey])) {
|
if ($catKey && isset($catTotals[$catKey])) {
|
||||||
$realSum = $catTotals[$catKey];
|
$realSum = $catTotals[$catKey];
|
||||||
$hasMatchingExpense = true;
|
$hasMatchingExpense = true;
|
||||||
}
|
}
|
||||||
// C. Correspondance par mots-clés (seulement sur les dépenses non liées)
|
// C. Correspondance par mots-clés classiques (sur les dépenses non liées)
|
||||||
elseif (!empty($item['mapping_keywords'])) {
|
elseif (!empty($item['mapping_keywords'])) {
|
||||||
$keywords = array_map('trim', explode(',', $item['mapping_keywords']));
|
$keywords = array_map('trim', explode(',', $item['mapping_keywords']));
|
||||||
foreach ($unlinkedExpenses as $uexp) {
|
foreach ($unlinkedExpenses as $uexp) {
|
||||||
|
|||||||
@@ -221,10 +221,15 @@ while ($item = $stmt->fetch(PDO::FETCH_ASSOC)) {
|
|||||||
$pending_charges[] = ['name' => $name, 'amount' => $absAmount];
|
$pending_charges[] = ['name' => $name, 'amount' => $absAmount];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ($name === 'Estimacio F&B & beauty') $budget_fmcg = $amt;
|
if (!empty($item['mapping_keywords'])) {
|
||||||
elseif ($name === 'Estimacio escola') $budget_school = $amt;
|
if (stripos($item['mapping_keywords'], 'FMCG') !== false) $budget_fmcg += $amt;
|
||||||
elseif ($name === 'Estimation gasolina') $budget_essence = $amt;
|
if (stripos($item['mapping_keywords'], 'School') !== false) $budget_school += $amt;
|
||||||
elseif ((int)$item['is_estimate'] === 0 && $item['type'] === 'Mensuel' && $item['category'] === 'expense') { $budget_frais += $absAmount; }
|
if (stripos($item['mapping_keywords'], 'Essence') !== false) $budget_essence += $amt;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((int)$item['is_estimate'] === 0 && $item['type'] === 'Mensuel' && $item['category'] === 'expense') {
|
||||||
|
$budget_frais += $absAmount;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -580,8 +585,13 @@ $monthName = $monthNames[(int)$viewM] . ' ' . $viewY;
|
|||||||
<div class="form-group" id="blockInputSelect" style="margin-bottom:15px; display:none;">
|
<div class="form-group" id="blockInputSelect" style="margin-bottom:15px; display:none;">
|
||||||
<label class="pf-label"><?= tr('bud_beneficiary') ?></label>
|
<label class="pf-label"><?= tr('bud_beneficiary') ?></label>
|
||||||
<select name="label_select" id="schoolSelect" class="pf-input">
|
<select name="label_select" id="schoolSelect" class="pf-input">
|
||||||
<option value="Ecole Pol">Ecole Pol</option>
|
<?php
|
||||||
<option value="Carole">Carole</option>
|
$stmtSchoolLabel = $pdo->query("SELECT name FROM pf_people WHERE role IN ('enfant', 'nounou') OR role IS NULL ORDER BY id ASC");
|
||||||
|
while($k = $stmtSchoolLabel->fetch(PDO::FETCH_ASSOC)) {
|
||||||
|
$pName = htmlspecialchars($k['name']);
|
||||||
|
echo "<option value='{$pName}'>{$pName}</option>";
|
||||||
|
}
|
||||||
|
?>
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
+11
-10
@@ -165,16 +165,17 @@ CREATE TABLE IF NOT EXISTS pf_import_rules (
|
|||||||
budget_item_id INT(11) NULL DEFAULT NULL
|
budget_item_id INT(11) NULL DEFAULT NULL
|
||||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS pf_advances (
|
CREATE TABLE IF NOT EXISTS `pf_advances` (
|
||||||
id int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||||
advance_date date NOT NULL,
|
`advance_date` date NOT NULL,
|
||||||
payer varchar(50) NOT NULL,
|
`payer` varchar(50) NOT NULL,
|
||||||
description varchar(255) NOT NULL,
|
`description` varchar(255) NOT NULL,
|
||||||
amount decimal(10,2) DEFAULT 0.00,
|
`amount` decimal(10,2) DEFAULT 0.00,
|
||||||
from_savings tinyint(1) DEFAULT 0,
|
`from_savings` tinyint(1) DEFAULT 0,
|
||||||
is_resolved tinyint(1) DEFAULT 0,
|
`is_resolved` tinyint(1) DEFAULT 0,
|
||||||
created_at datetime DEFAULT current_timestamp()
|
`created_at` datetime DEFAULT current_timestamp(),
|
||||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
PRIMARY KEY (`id`)
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||||
|
|
||||||
-- ─── Notes / Memo ─────────────────────────────────────────────────────────────
|
-- ─── Notes / Memo ─────────────────────────────────────────────────────────────
|
||||||
CREATE TABLE IF NOT EXISTS pf_notes (
|
CREATE TABLE IF NOT EXISTS pf_notes (
|
||||||
|
|||||||
+142
-4
@@ -31,10 +31,50 @@ CREATE TABLE IF NOT EXISTS user_calendar_integrations (
|
|||||||
// ─── Actions ──────────────────────────────────────────────────────────────────
|
// ─── Actions ──────────────────────────────────────────────────────────────────
|
||||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||||
if (!verify_csrf($_POST['csrf_token'] ?? null)) {
|
if (!verify_csrf($_POST['csrf_token'] ?? null)) {
|
||||||
|
// Fallback JSON pour les requêtes AJAX qui échouent au CSRF
|
||||||
|
if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) === 'xmlhttprequest') {
|
||||||
|
header('Content-Type: application/json');
|
||||||
|
echo json_encode(['success' => false, 'error' => 'Session invalide (CSRF). Rechargez la page.']);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
$error = "Session invalide (CSRF). Rechargez la page.";
|
$error = "Session invalide (CSRF). Rechargez la page.";
|
||||||
} else {
|
} else {
|
||||||
$action = $_POST['action'] ?? '';
|
$action = $_POST['action'] ?? '';
|
||||||
|
|
||||||
|
// 🟢 GESTION AJAX : ENFANTS DU FOYER
|
||||||
|
if ($action === 'add_child') {
|
||||||
|
header('Content-Type: application/json');
|
||||||
|
try {
|
||||||
|
$name = trim($_POST['child_name'] ?? '');
|
||||||
|
if (empty($name)) throw new Exception(tr('set_err_kid_name'));
|
||||||
|
|
||||||
|
require_once __DIR__ . '/includes/db.php';
|
||||||
|
$stmt = $pdo->prepare("INSERT INTO pf_people (name, role) VALUES (?, 'enfant')");
|
||||||
|
$stmt->execute([$name]);
|
||||||
|
|
||||||
|
echo json_encode(['success' => true]);
|
||||||
|
} catch (Exception $e) {
|
||||||
|
echo json_encode(['success' => false, 'error' => $e->getMessage()]);
|
||||||
|
}
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($action === 'delete_child') {
|
||||||
|
header('Content-Type: application/json');
|
||||||
|
try {
|
||||||
|
$id = (int)($_POST['child_id'] ?? 0);
|
||||||
|
if ($id > 0) {
|
||||||
|
require_once __DIR__ . '/includes/db.php';
|
||||||
|
$stmt = $pdo->prepare("DELETE FROM pf_people WHERE id = ? AND role = 'enfant'");
|
||||||
|
$stmt->execute([$id]);
|
||||||
|
}
|
||||||
|
echo json_encode(['success' => true]);
|
||||||
|
} catch (Exception $e) {
|
||||||
|
echo json_encode(['success' => false, 'error' => $e->getMessage()]);
|
||||||
|
}
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
if ($action === 'update_family_info') {
|
if ($action === 'update_family_info') {
|
||||||
require_once __DIR__ . '/includes/db.php';
|
require_once __DIR__ . '/includes/db.php';
|
||||||
|
|
||||||
@@ -258,6 +298,13 @@ if ($family_id && isset($pdo)) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 4. Récupération de la liste des enfants du foyer
|
||||||
|
$kidsList = [];
|
||||||
|
if ($family_id && isset($pdo)) {
|
||||||
|
$stmtKids = $pdo->query("SELECT id, name FROM pf_people WHERE role = 'enfant' ORDER BY id ASC");
|
||||||
|
$kidsList = $stmtKids->fetchAll(PDO::FETCH_ASSOC);
|
||||||
|
}
|
||||||
|
|
||||||
$family = null;
|
$family = null;
|
||||||
$members = [];
|
$members = [];
|
||||||
if ($family_id) {
|
if ($family_id) {
|
||||||
@@ -484,15 +531,16 @@ require __DIR__ . '/header.php';
|
|||||||
$showCurrency = count(array_intersect(['budget', 'holidays', 'gifts', 'garage'], $enabledMods)) > 0;
|
$showCurrency = count(array_intersect(['budget', 'holidays', 'gifts', 'garage'], $enabledMods)) > 0;
|
||||||
$showZone = in_array('calendar', $enabledMods);
|
$showZone = in_array('calendar', $enabledMods);
|
||||||
|
|
||||||
if ($family_id && ($showCurrency || $showZone)):
|
if ($family_id):
|
||||||
$currentCurrency = defined('CURRENCY') ? CURRENCY : '€';
|
$currentCurrency = defined('CURRENCY') ? CURRENCY : '€';
|
||||||
$currentZone = defined('ZONE_SCOLAIRE') ? ZONE_SCOLAIRE : 'C';
|
$currentZone = defined('ZONE_SCOLAIRE') ? ZONE_SCOLAIRE : 'C';
|
||||||
?>
|
?>
|
||||||
<section class="pf-panel-card">
|
<section class="pf-panel-card">
|
||||||
<h2 class="pf-card-h2">👪 Configuration du foyer</h2>
|
<h2 class="pf-card-h2">👪 Configuration du foyer</h2>
|
||||||
<p class="pf-muted-note">Configurez les indicateurs partagés par votre foyer.</p>
|
<p class="pf-muted-note">Configurez les indicateurs et les membres partagés par votre foyer.</p>
|
||||||
|
|
||||||
<form method="post" class="pf-stack-md">
|
<?php if ($showCurrency || $showZone): ?>
|
||||||
|
<form method="post" class="pf-stack-md" style="margin-bottom: 24px;">
|
||||||
<input type="hidden" name="csrf_token" value="<?= htmlspecialchars(csrf_token()) ?>">
|
<input type="hidden" name="csrf_token" value="<?= htmlspecialchars(csrf_token()) ?>">
|
||||||
<input type="hidden" name="action" value="update_family_info">
|
<input type="hidden" name="action" value="update_family_info">
|
||||||
|
|
||||||
@@ -519,8 +567,33 @@ require __DIR__ . '/header.php';
|
|||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<button type="submit" class="pf-btn">Enregistrer les paramètres du foyer</button>
|
<button type="submit" class="pf-btn">Enregistrer les paramètres</button>
|
||||||
</form>
|
</form>
|
||||||
|
<?php endif; ?>
|
||||||
|
|
||||||
|
<div style="border-top: 1px solid var(--border-light); margin: 24px 0;"></div>
|
||||||
|
|
||||||
|
<h3 style="margin-top: 0; font-size: 1.1rem; color: var(--text-main); margin-bottom: 8px;">👶 <?= tr('set_kids_title') ?></h3>
|
||||||
|
<p class="pf-muted-note"><?= tr('set_kids_desc') ?></p>
|
||||||
|
|
||||||
|
<ul class="pf-stack-sm" style="list-style: none; padding: 0; margin-bottom: 20px; margin-top: 15px;">
|
||||||
|
<?php if (empty($kidsList)): ?>
|
||||||
|
<li class="pf-muted-note" style="font-style: italic;"><?= tr('set_no_kids') ?></li>
|
||||||
|
<?php else: ?>
|
||||||
|
<?php foreach ($kidsList as $kid): ?>
|
||||||
|
<li style="display: flex; justify-content: space-between; align-items: center; padding: 10px 14px; background: var(--bg-page); border: 1px solid var(--border-light); border-radius: 8px;">
|
||||||
|
<strong><?= htmlspecialchars($kid['name']) ?></strong>
|
||||||
|
<button type="button" class="btn-icon-action delete" onclick="deleteChild(<?= $kid['id'] ?>)" title="<?= tr('delete') ?>">🗑️</button>
|
||||||
|
</li>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
<?php endif; ?>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<form id="formAddChild" style="display: flex; gap: 10px;">
|
||||||
|
<input type="text" id="newChildName" class="pf-input" placeholder="<?= tr('set_add_kid_placeholder') ?>" required autocomplete="off">
|
||||||
|
<button type="submit" class="pf-btn pf-shrink-0">➕ <?= tr('set_btn_add_kid') ?></button>
|
||||||
|
</form>
|
||||||
|
|
||||||
</section>
|
</section>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
|
|
||||||
@@ -655,6 +728,71 @@ function copyCode() {
|
|||||||
setTimeout(() => msg.classList.remove('is-visible'), 2000);
|
setTimeout(() => msg.classList.remove('is-visible'), 2000);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Injection des traductions dynamiques pour JS
|
||||||
|
window.I18N = {
|
||||||
|
...(window.I18N || {}),
|
||||||
|
'set_confirm_del_kid': "<?= tr('set_confirm_del_kid') ?>",
|
||||||
|
'delete': "<?= tr('delete') ?>",
|
||||||
|
'error_occured': "<?= tr('error_occured') ?>"
|
||||||
|
};
|
||||||
|
|
||||||
|
// Gestion de l'ajout d'enfant
|
||||||
|
const formAddChild = document.getElementById('formAddChild');
|
||||||
|
if (formAddChild) {
|
||||||
|
formAddChild.addEventListener('submit', async (e) => {
|
||||||
|
e.preventDefault();
|
||||||
|
const input = document.getElementById('newChildName');
|
||||||
|
const name = input.value.trim();
|
||||||
|
if (!name) return;
|
||||||
|
|
||||||
|
const btn = e.target.querySelector('button[type="submit"]');
|
||||||
|
const originalText = btn.innerHTML;
|
||||||
|
btn.innerHTML = '...';
|
||||||
|
btn.disabled = true;
|
||||||
|
|
||||||
|
const fd = new FormData();
|
||||||
|
fd.append('action', 'add_child');
|
||||||
|
fd.append('child_name', name);
|
||||||
|
fd.append('csrf_token', window.CSRF_TOKEN); // Important: CSRF
|
||||||
|
|
||||||
|
try {
|
||||||
|
const res = await pachaFetch('settings.php', { method: 'POST', body: fd });
|
||||||
|
if (res.success) {
|
||||||
|
window.location.reload();
|
||||||
|
} else {
|
||||||
|
showToast(res.error || window.I18N['error_occured'], 'error');
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
showToast(window.I18N['error_occured'], 'error');
|
||||||
|
} finally {
|
||||||
|
btn.innerHTML = originalText;
|
||||||
|
btn.disabled = false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Gestion de la suppression d'enfant
|
||||||
|
async function deleteChild(id) {
|
||||||
|
const confirmed = await pachaConfirm(window.I18N['delete'], window.I18N['set_confirm_del_kid']);
|
||||||
|
if (!confirmed) return;
|
||||||
|
|
||||||
|
const fd = new FormData();
|
||||||
|
fd.append('action', 'delete_child');
|
||||||
|
fd.append('child_id', id);
|
||||||
|
fd.append('csrf_token', window.CSRF_TOKEN); // Important: CSRF
|
||||||
|
|
||||||
|
try {
|
||||||
|
const res = await pachaFetch('settings.php', { method: 'POST', body: fd });
|
||||||
|
if (res.success) {
|
||||||
|
window.location.reload();
|
||||||
|
} else {
|
||||||
|
showToast(res.error || window.I18N['error_occured'], 'error');
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
showToast(window.I18N['error_occured'], 'error');
|
||||||
|
}
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<?php require __DIR__ . '/footer.php'; ?>
|
<?php require __DIR__ . '/footer.php'; ?>
|
||||||
Reference in New Issue
Block a user