DeclarationTVA/admin/setup_mvp.php
Frank Cools e91f0dc3b0 Fix module permissions for MVP access
Permission System Fixes:
- Uncommented and updated module permissions
- Added proper permission levels: read, write, delete, admin
- Updated permission names from 'myobject' to 'declarationtva'
- Fixed menu permission checks

Permission Levels:
- Read: Access to view declarations and periods
- Write: Create and update declarations
- Delete: Remove declarations and periods
- Admin: Access to configuration and setup

Access Control Updates:
- Updated setup_mvp.php to use correct permission check
- Updated declarationtvaindex.php to use correct permission check
- Menu entries now use proper permission validation

Testing Instructions:
1. Disable and re-enable the module to refresh permissions
2. Go to Home -> Users -> admin user
3. Check DeclarationTVA permissions are enabled
4. Try accessing the configuration page again

The module should now be accessible with proper permissions!
2025-10-02 16:28:27 +02:00

155 lines
5.3 KiB
PHP

<?php
/**
* MVP Setup page for DeclarationTVA module
* Simplified configuration for Phase 1
*/
// 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_lines = array('A1', 'A2', 'B1', 'B2', 'B3', 'B4', '17', '20', '21', '22', '28', '29');
foreach ($ca3_lines as $line) {
$account_code = GETPOST('account_code_' . $line, 'alpha');
$account_label = GETPOST('account_label_' . $line, 'alpha');
$vat_rate = GETPOST('vat_rate_' . $line, 'alpha');
if (!empty($account_code)) {
$config->updateAccountMapping($line, $account_code, $account_label, $vat_rate);
}
}
setEventMessages($langs->trans("ConfigurationUpdated"), null, 'mesgs');
}
// Get current mappings
$mappings = $config->getAllAccountMappings();
$account_mappings = array();
foreach ($mappings as $mapping) {
$account_mappings[$mapping['ca3_line']] = $mapping;
}
// Get available accounting accounts
$accounts = $config->getAccountingAccounts();
$vat_rates = $config->getVATRates();
$ca3_definitions = $config->getCA3LineDefinitions();
// Page title
$title = $langs->trans("DeclarationTVASetup");
llxHeader('', $title);
// Print page header
print load_fiche_titre($title, '', 'title_accountancy');
// 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>';
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("AccountCode") . '</th>';
print '<th>' . $langs->trans("AccountLabel") . '</th>';
print '<th>' . $langs->trans("VATRate") . '</th>';
print '</tr>';
foreach ($ca3_definitions as $line => $definition) {
$mapping = isset($account_mappings[$line]) ? $account_mappings[$line] : array();
print '<tr>';
print '<td><strong>' . $line . '</strong></td>';
print '<td>' . $definition['label'] . '</td>';
print '<td>';
print '<select name="account_code_' . $line . '" class="flat">';
print '<option value="">' . $langs->trans("SelectAccount") . '</option>';
foreach ($accounts as $account) {
$selected = (isset($mapping['account_code']) && $mapping['account_code'] == $account['account_number']) ? 'selected' : '';
print '<option value="' . $account['account_number'] . '" ' . $selected . '>' . $account['account_number'] . ' - ' . $account['label'] . '</option>';
}
print '</select>';
print '</td>';
print '<td><input type="text" name="account_label_' . $line . '" value="' . (isset($mapping['account_label']) ? $mapping['account_label'] : '') . '" class="flat" size="30"></td>';
print '<td>';
print '<select name="vat_rate_' . $line . '" class="flat">';
foreach ($vat_rates as $rate => $label) {
$selected = (isset($mapping['vat_rate']) && $mapping['vat_rate'] == $rate) ? 'selected' : '';
print '<option value="' . $rate . '" ' . $selected . '>' . $label . '</option>';
}
print '</select>';
print '</td>';
print '</tr>';
}
print '</table>';
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
print '<div class="fiche">';
print '<div class="titre">' . $langs->trans("CurrentConfiguration") . '</div>';
if (empty($mappings)) {
print '<div class="info">' . $langs->trans("NoConfigurationFound") . '</div>';
} else {
print '<table class="noborder centpercent">';
print '<tr class="liste_titre">';
print '<th>' . $langs->trans("CA3Line") . '</th>';
print '<th>' . $langs->trans("AccountCode") . '</th>';
print '<th>' . $langs->trans("AccountLabel") . '</th>';
print '<th>' . $langs->trans("VATRate") . '</th>';
print '<th>' . $langs->trans("Status") . '</th>';
print '</tr>';
foreach ($mappings as $mapping) {
print '<tr>';
print '<td><strong>' . $mapping['ca3_line'] . '</strong></td>';
print '<td>' . $mapping['account_code'] . '</td>';
print '<td>' . $mapping['account_label'] . '</td>';
print '<td>' . $mapping['vat_rate'] . '%</td>';
print '<td>' . ($mapping['is_active'] ? $langs->trans("Active") : $langs->trans("Inactive")) . '</td>';
print '</tr>';
}
print '</table>';
}
print '</div>';
// Print footer
llxFooter();
?>