Add separate base and VAT account mappings for lines 08, 09, 9B
Enhanced: - Configuration form now shows separate fields for base and VAT accounts for lines 08, 09, 9B - 'Comptes de base (ventes)' for sales accounts (7xxxx) - 'Comptes de TVA' for VAT accounts (4457xx) - Form processing handles both base_account_codes and vat_account_codes - Calculation logic separates base and VAT amounts for these lines - Base accounts contribute to base_amount, VAT accounts to vat_amount - Account labels show (base) and (VAT) suffixes for clarity
This commit is contained in:
parent
e94d5e07de
commit
8f01229c1a
@ -42,13 +42,35 @@ if ($action == 'update_mappings') {
|
|||||||
|
|
||||||
|
|
||||||
foreach ($ca3_definitions as $line => $definition) {
|
foreach ($ca3_definitions as $line => $definition) {
|
||||||
$account_codes = GETPOST('account_codes_' . $line, 'array');
|
// Special handling for lines 08, 09, 9B (need both base and VAT accounts)
|
||||||
|
if (in_array($line, array('08', '09', '9B'))) {
|
||||||
// Process all lines that have form data
|
$base_account_codes = GETPOST('base_account_codes_' . $line, 'array');
|
||||||
if (isset($_POST['account_codes_' . $line])) {
|
$vat_account_codes = GETPOST('vat_account_codes_' . $line, 'array');
|
||||||
$result = $config->updateAccountMapping($line, $account_codes);
|
|
||||||
if ($result) {
|
// Process base accounts
|
||||||
$updated_count++;
|
if (isset($_POST['base_account_codes_' . $line])) {
|
||||||
|
$result = $config->updateAccountMapping($line . '_BASE', $base_account_codes);
|
||||||
|
if ($result) {
|
||||||
|
$updated_count++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Process VAT accounts
|
||||||
|
if (isset($_POST['vat_account_codes_' . $line])) {
|
||||||
|
$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');
|
||||||
|
|
||||||
|
if (isset($_POST['account_codes_' . $line])) {
|
||||||
|
$result = $config->updateAccountMapping($line, $account_codes);
|
||||||
|
if ($result) {
|
||||||
|
$updated_count++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -157,8 +179,20 @@ foreach ($lines_by_section as $section_code => $lines) {
|
|||||||
$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 with search functionality
|
// Special handling for lines 08, 09, 9B (need both base and VAT accounts)
|
||||||
print $form->multiselectarray('account_codes_' . $line, $account_options, $selected_accounts, 0, 0, '', 0, '200px');
|
if (in_array($line, array('08', '09', '9B'))) {
|
||||||
|
print '<div style="margin-bottom: 10px;">';
|
||||||
|
print '<strong>Comptes de base (ventes):</strong><br>';
|
||||||
|
print $form->multiselectarray('base_account_codes_' . $line, $account_options, $selected_accounts, 0, 0, '', 0, '200px');
|
||||||
|
print '</div>';
|
||||||
|
print '<div>';
|
||||||
|
print '<strong>Comptes de TVA:</strong><br>';
|
||||||
|
print $form->multiselectarray('vat_account_codes_' . $line, $account_options, $selected_accounts, 0, 0, '', 0, '200px');
|
||||||
|
print '</div>';
|
||||||
|
} else {
|
||||||
|
// Normal single selection for other lines
|
||||||
|
print $form->multiselectarray('account_codes_' . $line, $account_options, $selected_accounts, 0, 0, '', 0, '200px');
|
||||||
|
}
|
||||||
print '</td>';
|
print '</td>';
|
||||||
print '</tr>';
|
print '</tr>';
|
||||||
}
|
}
|
||||||
|
|||||||
@ -216,22 +216,43 @@ class DeclarationTVA
|
|||||||
$line_total_amount = 0;
|
$line_total_amount = 0;
|
||||||
$account_labels = array();
|
$account_labels = array();
|
||||||
|
|
||||||
// Sum all accounts for this CA-3 line (if any mappings exist)
|
// Special handling for lines 08, 09, 9B (need separate base and VAT accounts)
|
||||||
if (isset($grouped_mappings[$ca3_line])) {
|
if (in_array($ca3_line, array('08', '09', '9B'))) {
|
||||||
error_log("DeclarationTVA: Processing CA-3 line $ca3_line with " . count($grouped_mappings[$ca3_line]) . " mapped accounts");
|
// Get base accounts (sales)
|
||||||
foreach ($grouped_mappings[$ca3_line] as $mapping) {
|
$base_mappings = isset($grouped_mappings[$ca3_line . '_BASE']) ? $grouped_mappings[$ca3_line . '_BASE'] : array();
|
||||||
error_log("DeclarationTVA: Processing account " . $mapping['account_code'] . " for line $ca3_line");
|
foreach ($base_mappings as $mapping) {
|
||||||
$amounts = $this->getAccountAmounts($mapping['account_code'], $period['start_date'], $period['end_date']);
|
$amounts = $this->getAccountAmounts($mapping['account_code'], $period['start_date'], $period['end_date']);
|
||||||
|
|
||||||
$line_total_base += $amounts['base_amount'];
|
$line_total_base += $amounts['base_amount'];
|
||||||
$line_total_vat += $amounts['vat_amount'];
|
$account_labels[] = $mapping['account_label'] . ' (base)';
|
||||||
$line_total_amount += $amounts['total_amount'];
|
|
||||||
$account_labels[] = $mapping['account_label'];
|
|
||||||
|
|
||||||
error_log("DeclarationTVA: Account " . $mapping['account_code'] . " amounts: base=" . $amounts['base_amount'] . ", vat=" . $amounts['vat_amount']);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get VAT accounts
|
||||||
|
$vat_mappings = isset($grouped_mappings[$ca3_line . '_VAT']) ? $grouped_mappings[$ca3_line . '_VAT'] : array();
|
||||||
|
foreach ($vat_mappings as $mapping) {
|
||||||
|
$amounts = $this->getAccountAmounts($mapping['account_code'], $period['start_date'], $period['end_date']);
|
||||||
|
$line_total_vat += $amounts['vat_amount'];
|
||||||
|
$account_labels[] = $mapping['account_label'] . ' (VAT)';
|
||||||
|
}
|
||||||
|
|
||||||
|
$line_total_amount = $line_total_base + $line_total_vat;
|
||||||
} else {
|
} else {
|
||||||
error_log("DeclarationTVA: No mappings found for CA-3 line $ca3_line");
|
// Normal processing for other lines
|
||||||
|
if (isset($grouped_mappings[$ca3_line])) {
|
||||||
|
error_log("DeclarationTVA: Processing CA-3 line $ca3_line with " . count($grouped_mappings[$ca3_line]) . " mapped accounts");
|
||||||
|
foreach ($grouped_mappings[$ca3_line] as $mapping) {
|
||||||
|
error_log("DeclarationTVA: Processing account " . $mapping['account_code'] . " for line $ca3_line");
|
||||||
|
$amounts = $this->getAccountAmounts($mapping['account_code'], $period['start_date'], $period['end_date']);
|
||||||
|
|
||||||
|
$line_total_base += $amounts['base_amount'];
|
||||||
|
$line_total_vat += $amounts['vat_amount'];
|
||||||
|
$line_total_amount += $amounts['total_amount'];
|
||||||
|
$account_labels[] = $mapping['account_label'];
|
||||||
|
|
||||||
|
error_log("DeclarationTVA: Account " . $mapping['account_code'] . " amounts: base=" . $amounts['base_amount'] . ", vat=" . $amounts['vat_amount']);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
error_log("DeclarationTVA: No mappings found for CA-3 line $ca3_line");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create CA-3 line record with summed amounts (even if zero)
|
// Create CA-3 line record with summed amounts (even if zero)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user