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; foreach ($ca3_definitions as $line => $definition) { // Special handling for lines 08, 09, 9B (need both base and VAT accounts) if (in_array($line, array('08', '09', '9B'))) { $base_account_codes = GETPOST('base_account_codes_' . $line, 'array'); $vat_account_codes = GETPOST('vat_account_codes_' . $line, 'array'); // Always process base accounts (even if empty) $result = $config->updateAccountMapping($line . '_BASE', $base_account_codes); if ($result) { $updated_count++; } // Always process VAT accounts (even if empty) $result = $config->updateAccountMapping($line . '_VAT', $vat_account_codes); if ($result) { $updated_count++; } } else { // Normal processing for other lines $account_codes = GETPOST('account_codes_' . $line, 'array'); // Always process account mappings (even if empty) $result = $config->updateAccountMapping($line, $account_codes); if ($result) { $updated_count++; } } } 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(); // Ensure table exists (create if missing) $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) { // Create the table if it doesn't exist $create_table_sql = "CREATE TABLE IF NOT EXISTS `" . $table_name . "` ( `rowid` int(11) NOT NULL AUTO_INCREMENT, `entity` int(11) NOT NULL DEFAULT 1, `ca3_line` varchar(8) NOT NULL COMMENT 'A1, A2, A3, A4, A5, 08, 09, 9B, 17, 20, 21, 22, 25, 26, 28, 29', `account_code` varchar(32) NOT NULL COMMENT 'PCG account code', `account_label` varchar(255) DEFAULT NULL, `vat_rate` decimal(5,2) DEFAULT NULL, `is_active` tinyint(1) DEFAULT 1, `created_date` datetime DEFAULT NULL, PRIMARY KEY (`rowid`), UNIQUE KEY `uk_mapping_entity_line_account` (`entity`, `ca3_line`, `account_code`), KEY `idx_ca3_line` (`ca3_line`), KEY `idx_account_code` (`account_code`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci"; $db->query($create_table_sql); } $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 '