hasRight("declarationtva", "declarationtva", "admin")) { accessforbidden(); } // Load language files $langs->load("declarationtva@declarationtva"); // Initialize objects $config = new DeclarationTVA_Config($db, $conf->entity); $form = new Form($db); // Handle form submission $action = GETPOST('action', 'alpha'); if ($action == 'update_mappings') { $ca3_definitions = $config->getCA3LineDefinitions(); $updated_count = 0; $debug_info = array(); foreach ($ca3_definitions as $line => $definition) { $account_codes = GETPOST('account_codes_' . $line, 'array'); $debug_info[] = "Line $line: " . (is_array($account_codes) ? implode(',', $account_codes) : 'empty'); // Process all lines, even empty ones (to clear mappings) $result = $config->updateAccountMapping($line, $account_codes); if ($result) { $updated_count++; } } // Debug output if (empty($debug_info)) { setEventMessages("Debug: No form data received", null, 'warnings'); } else { setEventMessages("Debug: " . implode(' | ', $debug_info), null, 'warnings'); } if ($updated_count > 0) { setEventMessages($langs->trans("ConfigurationUpdated"), null, 'mesgs'); } else { setEventMessages($langs->trans("NoChangesDetected"), null, 'warnings'); } } // Get current mappings $mappings_by_line = $config->getAccountMappingsByLine(); $accounts = $config->getAccountingAccounts(); $ca3_definitions = $config->getCA3LineDefinitions(); $section_headers = $config->getCA3SectionHeaders(); // Page title $title = $langs->trans("DeclarationTVASetup"); llxHeader('', $title); // Print page header print load_fiche_titre($title, '', 'title_accountancy'); // Print notice information print '
'; print 'Notice 4722 - Summary Table CA3 (3310-CA3-SD)
'; print 'Configuration basée sur la structure officielle la plus récente du formulaire CA-3.'; print '

'; // Print configuration form print '
'; print ''; print ''; print '
'; print '
' . $langs->trans("DeclarationTVAPCGMapping") . '
'; // Group CA-3 lines by section $lines_by_section = array(); foreach ($ca3_definitions as $line => $definition) { $section = $definition['section']; if (!isset($lines_by_section[$section])) { $lines_by_section[$section] = array(); } $lines_by_section[$section][$line] = $definition; } // Print each section foreach ($lines_by_section as $section_code => $lines) { $section_info = $section_headers[$section_code]; // Section header print '
' . $section_info['title'] . '
'; print '
' . $section_info['description'] . '
'; if (isset($section_info['notice'])) { print '
Référence: ' . $section_info['notice'] . '
'; } print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; foreach ($lines as $line => $definition) { $selected_accounts = isset($mappings_by_line[$line]) ? $mappings_by_line[$line] : array(); print ''; print ''; print ''; print ''; print ''; print ''; print ''; } print '
' . $langs->trans("CA3Line") . '' . $langs->trans("LineLabel") . '' . $langs->trans("Description") . '' . $langs->trans("PCGAccounts") . '' . $langs->trans("AccountSelection") . '
' . $line . '' . $definition['label'] . '' . $definition['description'] . '' . $definition['pcg_accounts'] . ''; // Create account options array for Dolibarr multi-select $account_options = array(); foreach ($accounts as $account) { $account_options[$account['account_number']] = $account['account_number'] . ' - ' . $account['label']; } // Use Dolibarr's native multi-select with search functionality print $form->multiselectarray('account_codes_' . $line, $account_options, $selected_accounts, 0, 0, '', 0, '200px'); // Add helper text print '
' . $langs->trans("MultiSelectHelp") . ''; print '
'; print '
'; } print '
' . $langs->trans("Actions") . '
'; print ''; print '
'; print '
'; // Print current configuration summary print '
'; print '
' . $langs->trans("CurrentConfiguration") . '
'; if (empty($mappings_by_line)) { print '
' . $langs->trans("NoConfigurationFound") . '
'; } else { // Group by section for display $mappings_by_section = array(); foreach ($mappings_by_line as $line => $account_codes) { if (isset($ca3_definitions[$line])) { $section = $ca3_definitions[$line]['section']; if (!isset($mappings_by_section[$section])) { $mappings_by_section[$section] = array(); } $mappings_by_section[$section][$line] = $account_codes; } } foreach ($mappings_by_section as $section_code => $section_mappings) { $section_info = $section_headers[$section_code]; print '
' . $section_info['title'] . '
'; print ''; print ''; print ''; print ''; print ''; print ''; foreach ($section_mappings as $line => $account_codes) { print ''; print ''; print ''; print ''; print ''; } print '
' . $langs->trans("CA3Line") . '' . $langs->trans("SelectedAccounts") . '' . $langs->trans("AccountCount") . '
' . $line . '' . implode(', ', $account_codes) . '' . count($account_codes) . '
'; print '
'; } } print '
'; // Print footer llxFooter(); ?> ?>