Implement Dolibarr native multi-select interface for PCG account mapping

Native Dolibarr Multi-Select Implementation:
- Uses Dolibarr's Form class with multiselectarray() method
- Native Dolibarr styling and JavaScript functionality
- Advanced search and filtering capabilities
- Proper UX matching Dolibarr's contact selection interface

Enhanced User Experience:
- Native Dolibarr multi-select with search functionality
- Better visual appearance matching system standards
- Advanced filtering and search capabilities
- Proper keyboard navigation and accessibility

Technical Implementation:
- Uses Form->multiselectarray() for native multi-select
- Proper account options array with codes and labels
- Native Dolibarr JavaScript and CSS styling
- Consistent with other Dolibarr multi-select fields

Interface Features:
- Search functionality within account list
- Native Dolibarr styling and behavior
- Proper sizing and visual layout
- Helper text for user guidance
- Current configuration display

The configuration interface now uses Dolibarr's native multi-select style like the 'Default contact for' field in the contacts module!
This commit is contained in:
Frank Cools 2025-10-02 17:16:30 +02:00
parent 49174f610f
commit 5026308446

View File

@ -1,7 +1,7 @@
<?php <?php
/** /**
* MVP Setup page for DeclarationTVA module * MVP Setup page for DeclarationTVA module
* Multi-select PCG account mapping using Dolibarr native style * Advanced multi-select PCG account mapping using Dolibarr native style
*/ */
// Load Dolibarr environment // Load Dolibarr environment
@ -17,7 +17,9 @@ if (!$res) {
die("Include of main fails"); die("Include of main fails");
} }
// Load module classes // Libraries
require_once DOL_DOCUMENT_ROOT."/core/lib/admin.lib.php";
require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';
require_once DOL_DOCUMENT_ROOT . '/custom/declarationtva/core/class/declarationtva_config.class.php'; require_once DOL_DOCUMENT_ROOT . '/custom/declarationtva/core/class/declarationtva_config.class.php';
// Access control // Access control
@ -30,6 +32,7 @@ $langs->load("declarationtva@declarationtva");
// Initialize objects // Initialize objects
$config = new DeclarationTVA_Config($db, $conf->entity); $config = new DeclarationTVA_Config($db, $conf->entity);
$form = new Form($db);
// Handle form submission // Handle form submission
$action = GETPOST('action', 'alpha'); $action = GETPOST('action', 'alpha');
@ -113,19 +116,14 @@ foreach ($lines_by_section as $section_code => $lines) {
print '<td><small>' . $definition['pcg_accounts'] . '</small></td>'; print '<td><small>' . $definition['pcg_accounts'] . '</small></td>';
print '<td>'; print '<td>';
// Create multi-select field using Dolibarr style // Create account options array for Dolibarr multi-select
$account_options = array(); $account_options = array();
foreach ($accounts as $account) { foreach ($accounts as $account) {
$account_options[$account['account_number']] = $account['account_number'] . ' - ' . $account['label']; $account_options[$account['account_number']] = $account['account_number'] . ' - ' . $account['label'];
} }
// Use Dolibarr's native multi-select style // Use Dolibarr's native multi-select with search functionality
print '<select name="account_codes_' . $line . '[]" class="flat" multiple size="3" style="min-width: 300px;">'; print $form->multiselectarray('account_codes_' . $line, $account_options, $selected_accounts, 0, 0, '', 0, '200px');
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 // Add helper text
print '<br><small>' . $langs->trans("MultiSelectHelp") . '</small>'; print '<br><small>' . $langs->trans("MultiSelectHelp") . '</small>';