Multi-Select Account Mapping: - Replaced single account dropdown with multi-select field - Users can now select multiple PCG accounts for each CA-3 line - Uses Dolibarr native multi-select style with proper styling - Supports Ctrl/Cmd key for multiple selection Enhanced Configuration Interface: - Multi-select dropdown for each CA-3 line - Account selection from Dolibarr's chart of accounts - Real-time account validation against existing accounts - Better visual layout with proper sizing Technical Updates: - Updated config class to handle multiple account selections - Added method to get account mappings grouped by CA-3 line - Enhanced form submission to process array of account codes - Improved current configuration display Database Handling: - Deactivate existing mappings before adding new ones - Support for multiple accounts per CA-3 line - Proper account code validation - Clean data structure for multi-select support User Experience: - Native Dolibarr multi-select styling - Helper text for multi-selection instructions - Better account display with codes and labels - Improved current configuration summary Language Support: - Added English translations for multi-select interface - Added French translations for multi-select interface - Complete bilingual support for new features The configuration interface now supports multiple PCG account selection using Dolibarr's native multi-select style!
193 lines
6.5 KiB
PHP
193 lines
6.5 KiB
PHP
<?php
|
|
/**
|
|
* MVP Setup page for DeclarationTVA module
|
|
* Multi-select PCG account mapping using Dolibarr native style
|
|
*/
|
|
|
|
// Load Dolibarr environment
|
|
if (file_exists('../../main.inc.php')) {
|
|
$res = @include '../../main.inc.php';
|
|
} elseif (file_exists('../../../main.inc.php')) {
|
|
$res = @include '../../../main.inc.php';
|
|
} else {
|
|
$res = 0;
|
|
}
|
|
|
|
if (!$res) {
|
|
die("Include of main fails");
|
|
}
|
|
|
|
// Load module classes
|
|
require_once DOL_DOCUMENT_ROOT . '/custom/declarationtva/core/class/declarationtva_config.class.php';
|
|
|
|
// Access control
|
|
if (!$user->hasRight("declarationtva", "declarationtva", "admin")) {
|
|
accessforbidden();
|
|
}
|
|
|
|
// Load language files
|
|
$langs->load("declarationtva@declarationtva");
|
|
|
|
// Initialize objects
|
|
$config = new DeclarationTVA_Config($db, $conf->entity);
|
|
|
|
// Handle form submission
|
|
$action = GETPOST('action', 'alpha');
|
|
if ($action == 'update_mappings') {
|
|
$ca3_definitions = $config->getCA3LineDefinitions();
|
|
|
|
foreach ($ca3_definitions as $line => $definition) {
|
|
$account_codes = GETPOST('account_codes_' . $line, 'array');
|
|
|
|
if (!empty($account_codes)) {
|
|
$config->updateAccountMapping($line, $account_codes);
|
|
}
|
|
}
|
|
|
|
setEventMessages($langs->trans("ConfigurationUpdated"), null, 'mesgs');
|
|
}
|
|
|
|
// 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 '<div class="info">';
|
|
print '<strong>Notice 4722 - Summary Table CA3 (3310-CA3-SD)</strong><br>';
|
|
print 'Configuration basée sur la structure officielle la plus récente du formulaire CA-3.';
|
|
print '</div><br>';
|
|
|
|
// Print configuration form
|
|
print '<form method="POST" action="' . $_SERVER['PHP_SELF'] . '">';
|
|
print '<input type="hidden" name="action" value="update_mappings">';
|
|
|
|
print '<div class="fiche">';
|
|
print '<div class="titre">' . $langs->trans("DeclarationTVAPCGMapping") . '</div>';
|
|
|
|
// 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 '<div class="titre">' . $section_info['title'] . '</div>';
|
|
print '<div class="info">' . $section_info['description'] . '</div>';
|
|
if (isset($section_info['notice'])) {
|
|
print '<div class="info"><strong>Référence:</strong> ' . $section_info['notice'] . '</div>';
|
|
}
|
|
|
|
print '<table class="noborder centpercent">';
|
|
print '<tr class="liste_titre">';
|
|
print '<th>' . $langs->trans("CA3Line") . '</th>';
|
|
print '<th>' . $langs->trans("LineLabel") . '</th>';
|
|
print '<th>' . $langs->trans("Description") . '</th>';
|
|
print '<th>' . $langs->trans("PCGAccounts") . '</th>';
|
|
print '<th>' . $langs->trans("AccountSelection") . '</th>';
|
|
print '</tr>';
|
|
|
|
foreach ($lines as $line => $definition) {
|
|
$selected_accounts = isset($mappings_by_line[$line]) ? $mappings_by_line[$line] : array();
|
|
|
|
print '<tr>';
|
|
print '<td><strong>' . $line . '</strong></td>';
|
|
print '<td>' . $definition['label'] . '</td>';
|
|
print '<td><small>' . $definition['description'] . '</small></td>';
|
|
print '<td><small>' . $definition['pcg_accounts'] . '</small></td>';
|
|
print '<td>';
|
|
|
|
// Create multi-select field using Dolibarr style
|
|
$account_options = array();
|
|
foreach ($accounts as $account) {
|
|
$account_options[$account['account_number']] = $account['account_number'] . ' - ' . $account['label'];
|
|
}
|
|
|
|
// Use Dolibarr's native multi-select style
|
|
print '<select name="account_codes_' . $line . '[]" class="flat" multiple size="3" style="min-width: 300px;">';
|
|
foreach ($account_options as $account_code => $account_label) {
|
|
$selected = in_array($account_code, $selected_accounts) ? 'selected' : '';
|
|
print '<option value="' . $account_code . '" ' . $selected . '>' . $account_label . '</option>';
|
|
}
|
|
print '</select>';
|
|
|
|
// Add helper text
|
|
print '<br><small>' . $langs->trans("MultiSelectHelp") . '</small>';
|
|
print '</td>';
|
|
print '</tr>';
|
|
}
|
|
|
|
print '</table>';
|
|
print '<br>';
|
|
}
|
|
|
|
print '<div class="titre">' . $langs->trans("Actions") . '</div>';
|
|
print '<input type="submit" class="button" value="' . $langs->trans("UpdateConfiguration") . '">';
|
|
print '</div>';
|
|
|
|
print '</form>';
|
|
|
|
// Print current configuration summary
|
|
print '<div class="fiche">';
|
|
print '<div class="titre">' . $langs->trans("CurrentConfiguration") . '</div>';
|
|
|
|
if (empty($mappings_by_line)) {
|
|
print '<div class="info">' . $langs->trans("NoConfigurationFound") . '</div>';
|
|
} 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 '<div class="titre">' . $section_info['title'] . '</div>';
|
|
|
|
print '<table class="noborder centpercent">';
|
|
print '<tr class="liste_titre">';
|
|
print '<th>' . $langs->trans("CA3Line") . '</th>';
|
|
print '<th>' . $langs->trans("SelectedAccounts") . '</th>';
|
|
print '<th>' . $langs->trans("AccountCount") . '</th>';
|
|
print '</tr>';
|
|
|
|
foreach ($section_mappings as $line => $account_codes) {
|
|
print '<tr>';
|
|
print '<td><strong>' . $line . '</strong></td>';
|
|
print '<td>' . implode(', ', $account_codes) . '</td>';
|
|
print '<td>' . count($account_codes) . '</td>';
|
|
print '</tr>';
|
|
}
|
|
print '</table>';
|
|
print '<br>';
|
|
}
|
|
}
|
|
|
|
print '</div>';
|
|
|
|
// Print footer
|
|
llxFooter();
|
|
?>
|