Fixed: - Updated getCA3LineDetails() to handle special cases for lines 08, 09, 9B - These lines have _BASE and _VAT suffixes in the database - Added proper matching logic for both normal lines and special cases - Added debugging to AJAX endpoint and backend method - Added error logging to trace mapping issues This should fix the issue where only A1 works but other lines show no accounts.
129 lines
4.5 KiB
PHP
129 lines
4.5 KiB
PHP
<?php
|
|
/**
|
|
* AJAX endpoint for loading CA-3 line details
|
|
* Returns HTML content for inline dropdown display
|
|
*/
|
|
|
|
// 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';
|
|
} elseif (file_exists('../../../main.inc.php')) {
|
|
$res = @include '../../../main.inc.php';
|
|
} else {
|
|
die("Include of main fails");
|
|
}
|
|
|
|
// Load module classes
|
|
require_once DOL_DOCUMENT_ROOT . '/custom/declarationtva/core/class/declarationtva.class.php';
|
|
require_once DOL_DOCUMENT_ROOT . '/custom/declarationtva/core/class/declarationtva_config.class.php';
|
|
|
|
// Access control
|
|
if (!$user->hasRight("declarationtva", "declarationtva", "read")) {
|
|
http_response_code(403);
|
|
echo "Access denied";
|
|
exit;
|
|
}
|
|
|
|
// Get parameters
|
|
$declaration_id = GETPOST('declaration_id', 'int');
|
|
$ca3_line = GETPOST('ca3_line', 'alpha');
|
|
|
|
// Validate parameters
|
|
if (empty($declaration_id) || empty($ca3_line)) {
|
|
echo '<div class="error">' . $langs->trans("ErrorMissingParameters") . '</div>';
|
|
exit;
|
|
}
|
|
|
|
// Initialize objects
|
|
$declarationtva = new DeclarationTVA($db);
|
|
$config = new DeclarationTVA_Config($db);
|
|
|
|
// Get declaration info
|
|
if (!$declarationtva->fetch($declaration_id)) {
|
|
echo '<div class="error">' . $langs->trans("DeclarationNotFound") . '</div>';
|
|
exit;
|
|
}
|
|
|
|
// Get detailed breakdown
|
|
$line_details = $declarationtva->getCA3LineDetails($declaration_id, $ca3_line);
|
|
|
|
// Debug information
|
|
if (empty($line_details)) {
|
|
echo '<div class="error">' . $langs->trans("NoDataFoundForLine") . '</div>';
|
|
echo '<div class="info">Debug: CA-3 line: ' . $ca3_line . ', Declaration ID: ' . $declaration_id . '</div>';
|
|
exit;
|
|
}
|
|
|
|
// Debug: Show account count
|
|
if (empty($line_details['account_details'])) {
|
|
echo '<div class="info">' . $langs->trans("NoDataFoundForLine") . '</div>';
|
|
echo '<div class="info">Debug: No account details found for line ' . $ca3_line . '</div>';
|
|
exit;
|
|
}
|
|
|
|
// Get CA-3 line definition
|
|
$ca3_definitions = $config->getCA3LineDefinitions();
|
|
$line_definition = isset($ca3_definitions[$ca3_line]) ? $ca3_definitions[$ca3_line] : null;
|
|
|
|
// Display account details table
|
|
echo '<table class="noborder centpercent">';
|
|
echo '<tr class="liste_titre">';
|
|
echo '<th>' . $langs->trans("AccountCode") . '</th>';
|
|
echo '<th>' . $langs->trans("AccountLabel") . '</th>';
|
|
echo '<th class="right">' . $langs->trans("BaseAmount") . '</th>';
|
|
echo '<th class="right">' . $langs->trans("VATAmount") . '</th>';
|
|
echo '<th class="right">' . $langs->trans("TotalAmount") . '</th>';
|
|
echo '<th>' . $langs->trans("MappingType") . '</th>';
|
|
echo '</tr>';
|
|
|
|
$total_base = 0;
|
|
$total_vat = 0;
|
|
$total_amount = 0;
|
|
|
|
foreach ($line_details['account_details'] as $account) {
|
|
$total_base += $account['base_amount'];
|
|
$total_vat += $account['vat_amount'];
|
|
$total_amount += $account['total_amount'];
|
|
|
|
echo '<tr class="oddeven">';
|
|
echo '<td><strong>' . $account['account_code'] . '</strong></td>';
|
|
echo '<td>' . $account['account_label'] . '</td>';
|
|
echo '<td class="right">' . price($account['base_amount']) . '</td>';
|
|
echo '<td class="right">' . price($account['vat_amount']) . '</td>';
|
|
echo '<td class="right">' . price($account['total_amount']) . '</td>';
|
|
echo '<td>' . $account['mapping_type'] . '</td>';
|
|
echo '</tr>';
|
|
}
|
|
|
|
// Totals row
|
|
echo '<tr class="liste_titre">';
|
|
echo '<td colspan="2"><strong>' . $langs->trans("Total") . '</strong></td>';
|
|
echo '<td class="right"><strong>' . price($total_base) . '</strong></td>';
|
|
echo '<td class="right"><strong>' . price($total_vat) . '</strong></td>';
|
|
echo '<td class="right"><strong>' . price($total_amount) . '</strong></td>';
|
|
echo '<td></td>';
|
|
echo '</tr>';
|
|
|
|
echo '</table>';
|
|
|
|
// Additional info if calculated line exists
|
|
if ($line_details['calculated_line']) {
|
|
echo '<div class="info" style="margin-top: 10px;">';
|
|
echo '<strong>' . $langs->trans("Note") . ':</strong> ';
|
|
echo $langs->trans("CalculatedLineNote");
|
|
if (!empty($line_details['calculated_line']->line_label)) {
|
|
echo '<br><em>' . $line_details['calculated_line']->line_label . '</em>';
|
|
}
|
|
echo '</div>';
|
|
}
|
|
|
|
// Summary info
|
|
echo '<div class="info" style="margin-top: 10px;">';
|
|
echo '<strong>' . $langs->trans("Summary") . ':</strong> ';
|
|
echo $langs->trans("AccountCount") . ': ' . $line_details['account_count'] . ' | ';
|
|
echo $langs->trans("Period") . ': ' . dol_print_date($line_details['start_date'], 'day') . ' - ' . dol_print_date($line_details['end_date'], 'day');
|
|
echo '</div>';
|
|
?>
|