@@ -168,6 +168,19 @@ try {
|
||||
exit;
|
||||
}
|
||||
|
||||
// SAUVEGARDE DU NOUVEL ORDRE DES CATÉGORIES
|
||||
if (isset($_POST['action']) && $_POST['action'] === 'save_categories_order') {
|
||||
$ids = json_decode($_POST['order'], true);
|
||||
if (is_array($ids)) {
|
||||
$stmt = $pdo->prepare("UPDATE pf_budget_categories SET sort_order = ? WHERE id = ?");
|
||||
foreach ($ids as $index => $id) {
|
||||
$stmt->execute([$index, (int)$id]);
|
||||
}
|
||||
}
|
||||
echo json_encode(['success' => true]);
|
||||
exit;
|
||||
}
|
||||
|
||||
throw new Exception("Action API inconnue.");
|
||||
|
||||
} catch (Exception $e) {
|
||||
|
||||
@@ -305,16 +305,25 @@ function renderCategories(categories) {
|
||||
container.innerHTML = `<em class="text-muted">${tr('bs_empty_categories')}</em>`;
|
||||
return;
|
||||
}
|
||||
|
||||
// Tri JS pour respecter l'ordre au chargement de la modale
|
||||
categories.sort((a, b) => {
|
||||
if (a.type !== b.type) return a.type === 'Income' ? -1 : 1;
|
||||
return (a.sort_order || 0) - (b.sort_order || 0);
|
||||
});
|
||||
|
||||
let html = '';
|
||||
categories.forEach(cat => {
|
||||
let typeLabel = cat.type === 'Income' ? tr('bs_type_income') : cat.type === 'Expense' ? tr('bs_type_expense') : tr('bs_type_savings_cat');
|
||||
html += `
|
||||
<div class="bs-list-item" style="border-left: 4px solid ${cat.color || '#ccc'};">
|
||||
<div class="bs-list-item" data-id="${cat.id}" style="border-left: 4px solid ${cat.color || '#ccc'};">
|
||||
<div>
|
||||
<span style="font-size:1.2rem; margin-right:8px;">${cat.icon || '📌'}</span>
|
||||
<strong>${cat.label}</strong> <small class="text-muted">(${cat.code} — ${typeLabel})</small>
|
||||
</div>
|
||||
<div class="pf-flex-gap-8">
|
||||
<button type="button" class="btn-icon-action" onclick="moveCatUp(this)" title="Monter">⬆️</button>
|
||||
<button type="button" class="btn-icon-action" onclick="moveCatDown(this)" title="Descendre">⬇️</button>
|
||||
<button type="button" class="btn-icon-action delete" onclick="deleteCategory(${cat.id})" title="${tr('btn_delete')}">🗑️</button>
|
||||
</div>
|
||||
</div>`;
|
||||
@@ -322,6 +331,35 @@ function renderCategories(categories) {
|
||||
container.innerHTML = html;
|
||||
}
|
||||
|
||||
// Nouvelles fonctions pour réordonner visuellement et sauvegarder
|
||||
function moveCatUp(btn) {
|
||||
let row = btn.closest('.bs-list-item');
|
||||
if (row.previousElementSibling) {
|
||||
row.parentNode.insertBefore(row, row.previousElementSibling);
|
||||
saveCategoriesOrder();
|
||||
}
|
||||
}
|
||||
|
||||
function moveCatDown(btn) {
|
||||
let row = btn.closest('.bs-list-item');
|
||||
if (row.nextElementSibling) {
|
||||
row.parentNode.insertBefore(row.nextElementSibling, row);
|
||||
saveCategoriesOrder();
|
||||
}
|
||||
}
|
||||
|
||||
async function saveCategoriesOrder() {
|
||||
let ids = Array.from(document.querySelectorAll('#bs-list-categories .bs-list-item')).map(el => el.dataset.id);
|
||||
let fd = new FormData();
|
||||
fd.append('action', 'save_categories_order');
|
||||
fd.append('order', JSON.stringify(ids));
|
||||
try {
|
||||
await pachaFetch('/modules/budget/includes/api/settings.php', { method: 'POST', body: fd });
|
||||
} catch (err) {
|
||||
console.error("Erreur de sauvegarde de l'ordre :", err);
|
||||
}
|
||||
}
|
||||
|
||||
// 3. ONGLET : RÈGLES D'IMPORT
|
||||
function renderRules(rules) {
|
||||
const container = document.getElementById('bs-list-rules');
|
||||
|
||||
@@ -167,7 +167,7 @@ if (isset($_FILES['csv_file']) && $_FILES['csv_file']['error'] == 0) {
|
||||
// ============================================================================
|
||||
|
||||
// --- LECTURE DYNAMIQUE DES CATEGORIES ---
|
||||
$stmtCats = $pdo->query("SELECT * FROM pf_budget_categories ORDER BY type DESC, label ASC");
|
||||
$stmtCats = $pdo->query("SELECT * FROM pf_budget_categories ORDER BY type DESC, sort_order ASC, label ASC");
|
||||
$dbCategories = $stmtCats->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
$categoriesConfig = [];
|
||||
|
||||
Reference in New Issue
Block a user