Fixed: - Replaced class='right' with style='text-align: right;' for all amount columns - Applied to header, data rows, subtotals, and grand total - This ensures proper right alignment regardless of Dolibarr CSS classes - All monetary values now display consistently right-aligned The inline CSS approach guarantees the alignment works across different Dolibarr themes and configurations.
197 lines
6.7 KiB
PHP
197 lines
6.7 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);
|
|
|
|
if (empty($line_details)) {
|
|
echo '<div class="error">' . $langs->trans("NoDataFoundForLine") . '</div>';
|
|
exit;
|
|
}
|
|
|
|
if (empty($line_details['account_details'])) {
|
|
echo '<div class="info">' . $langs->trans("NoDataFoundForLine") . '</div>';
|
|
exit;
|
|
}
|
|
|
|
// Get CA-3 line definition
|
|
$ca3_definitions = $config->getCA3LineDefinitions();
|
|
$line_definition = isset($ca3_definitions[$ca3_line]) ? $ca3_definitions[$ca3_line] : null;
|
|
|
|
// Group accounts by type for lines 08, 09, 9B
|
|
$base_accounts = array();
|
|
$vat_accounts = array();
|
|
$other_accounts = array();
|
|
|
|
foreach ($line_details['account_details'] as $account) {
|
|
if (strpos($account['mapping_type'], '_BASE') !== false) {
|
|
$base_accounts[] = $account;
|
|
} elseif (strpos($account['mapping_type'], '_VAT') !== false) {
|
|
$vat_accounts[] = $account;
|
|
} else {
|
|
$other_accounts[] = $account;
|
|
}
|
|
}
|
|
|
|
// 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 style="text-align: right;">' . $langs->trans("Amount") . '</th>';
|
|
echo '<th>' . $langs->trans("MappingType") . '</th>';
|
|
echo '</tr>';
|
|
|
|
$total_base_base = 0;
|
|
$total_vat_base = 0;
|
|
$total_amount_base = 0;
|
|
$total_base_vat = 0;
|
|
$total_vat_vat = 0;
|
|
$total_amount_vat = 0;
|
|
$total_base_other = 0;
|
|
$total_vat_other = 0;
|
|
$total_amount_other = 0;
|
|
|
|
// Display BASE accounts first (if any)
|
|
if (!empty($base_accounts)) {
|
|
echo '<tr class="liste_titre">';
|
|
echo '<td colspan="4"><strong>' . $langs->trans("BaseAccounts") . '</strong></td>';
|
|
echo '</tr>';
|
|
|
|
foreach ($base_accounts as $account) {
|
|
$total_base_base += $account['base_amount'];
|
|
$total_vat_base += $account['vat_amount'];
|
|
$total_amount_base += $account['total_amount'];
|
|
|
|
echo '<tr class="oddeven">';
|
|
echo '<td><strong>' . $account['account_code'] . '</strong></td>';
|
|
echo '<td>' . $account['account_label'] . '</td>';
|
|
echo '<td style="text-align: right;">' . price($account['base_amount']) . '</td>';
|
|
echo '<td>' . $account['mapping_type'] . '</td>';
|
|
echo '</tr>';
|
|
}
|
|
|
|
// Subtotal for BASE accounts
|
|
echo '<tr class="liste_titre">';
|
|
echo '<td colspan="2"><strong>' . $langs->trans("SubtotalBaseAccounts") . '</strong></td>';
|
|
echo '<td style="text-align: right;"><strong>' . price($total_base_base) . '</strong></td>';
|
|
echo '<td></td>';
|
|
echo '</tr>';
|
|
}
|
|
|
|
// Display VAT accounts second (if any)
|
|
if (!empty($vat_accounts)) {
|
|
echo '<tr class="liste_titre">';
|
|
echo '<td colspan="4"><strong>' . $langs->trans("VATAccounts") . '</strong></td>';
|
|
echo '</tr>';
|
|
|
|
foreach ($vat_accounts as $account) {
|
|
$total_base_vat += $account['base_amount'];
|
|
$total_vat_vat += $account['vat_amount'];
|
|
$total_amount_vat += $account['total_amount'];
|
|
|
|
echo '<tr class="oddeven">';
|
|
echo '<td><strong>' . $account['account_code'] . '</strong></td>';
|
|
echo '<td>' . $account['account_label'] . '</td>';
|
|
echo '<td style="text-align: right;">' . price($account['vat_amount']) . '</td>';
|
|
echo '<td>' . $account['mapping_type'] . '</td>';
|
|
echo '</tr>';
|
|
}
|
|
|
|
// Subtotal for VAT accounts
|
|
echo '<tr class="liste_titre">';
|
|
echo '<td colspan="2"><strong>' . $langs->trans("SubtotalVATAccounts") . '</strong></td>';
|
|
echo '<td style="text-align: right;"><strong>' . price($total_vat_vat) . '</strong></td>';
|
|
echo '<td></td>';
|
|
echo '</tr>';
|
|
}
|
|
|
|
// Display other accounts (normal lines)
|
|
foreach ($other_accounts as $account) {
|
|
$total_base_other += $account['base_amount'];
|
|
$total_vat_other += $account['vat_amount'];
|
|
$total_amount_other += $account['total_amount'];
|
|
|
|
echo '<tr class="oddeven">';
|
|
echo '<td><strong>' . $account['account_code'] . '</strong></td>';
|
|
echo '<td>' . $account['account_label'] . '</td>';
|
|
echo '<td style="text-align: right;">' . price($account['vat_amount']) . '</td>';
|
|
echo '<td>' . $account['mapping_type'] . '</td>';
|
|
echo '</tr>';
|
|
}
|
|
|
|
// Final totals row
|
|
$final_total_vat = $total_vat_base + $total_vat_vat + $total_vat_other;
|
|
|
|
echo '<tr class="liste_titre">';
|
|
echo '<td colspan="2"><strong>' . $langs->trans("GrandTotal") . '</strong></td>';
|
|
echo '<td style="text-align: right;"><strong>' . price($final_total_vat) . '</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>';
|
|
?>
|