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(); // Debug: Check if table exists and show structure (simplified) $table_name = MAIN_DB_PREFIX . "declarationtva_account_mappings"; $check_table_sql = "SHOW TABLES LIKE '" . $table_name . "'"; $table_exists = $db->query($check_table_sql); if ($table_exists && $db->num_rows($table_exists) > 0) { // Table exists - check if migration is needed $constraint_check = "SHOW INDEX FROM " . $table_name . " WHERE Key_name = 'uk_mapping_entity_line_account'"; $constraint_result = $db->query($constraint_check); if ($constraint_result && $db->num_rows($constraint_result) > 0) { setEventMessages("Debug: Table structure is correct (supports multiple accounts per line)", null, 'mesgs'); } else { setEventMessages("Debug: Table exists but needs migration - please deactivate and reactivate the module", null, 'warnings'); } } else { setEventMessages("Debug: Table $table_name does NOT exist - please activate the module first", null, 'errors'); } $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 '
| ' . $langs->trans("CA3Line") . ' | '; print '' . $langs->trans("SelectedAccounts") . ' | '; print '' . $langs->trans("AccountCount") . ' | '; print '
|---|---|---|
| ' . $line . ' | '; print '' . implode(', ', $account_codes) . ' | '; print '' . count($account_codes) . ' | '; print '