DeclarationTVA/declarationtva_view.php
Frank Cools 7b5aedee81 Replace JavaScript popup with professional Dolibarr-style modal
- Replaced basic JavaScript popup with professional modal dialog
- Added proper header with title and close button
- Added warning icon and better visual hierarchy
- Improved styling with Dolibarr color scheme
- Added escape key support for better UX
- Better button styling and layout
- More professional appearance matching Dolibarr interface
- Enhanced user experience with proper modal behavior
2025-10-06 17:11:58 +02:00

637 lines
25 KiB
PHP

<?php
/**
* DeclarationTVA View Declaration
* French CA-3 VAT Declaration Module for Dolibarr
* MVP Version - 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.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_period.class.php';
// Access control
if (!$user->hasRight("declarationtva", "declarationtva", "read")) {
accessforbidden();
}
// Load language files
$langs->load("declarationtva@declarationtva");
// Get declaration ID
$id = GETPOST('id', 'int');
if (empty($id)) {
accessforbidden();
}
// Initialize objects
$declarationtva = new DeclarationTVA($db, $conf->entity);
$config = new DeclarationTVA_Config($db, $conf->entity);
$period = new DeclarationTVA_Period($db, $conf->entity);
// Handle actions
$action = GETPOST('action', 'alpha');
$token = GETPOST('token', 'alpha');
if ($action == 'recalculate' && $token) {
if ($declarationtva->recalculateCA3Amounts($id)) {
setEventMessages($langs->trans("DeclarationRecalculated"), null, 'mesgs');
} else {
setEventMessages($langs->trans("ErrorRecalculatingDeclaration"), null, 'errors');
}
}
if ($action == 'export_pdf') {
// Load PDF generator
require_once DOL_DOCUMENT_ROOT . '/custom/declarationtva/core/class/declarationtva_pdf.class.php';
$pdf_generator = new DeclarationTVA_PDF($db);
// Generate PDF
$pdf_path = $pdf_generator->generateCA3PDF($id);
if ($pdf_path && file_exists($pdf_path)) {
// Set headers for PDF download
header('Content-Type: application/pdf');
header('Content-Disposition: attachment; filename="CA3_' . $declarationtva->declaration_number . '.pdf"');
header('Content-Length: ' . filesize($pdf_path));
// Output PDF
readfile($pdf_path);
exit;
} else {
setEventMessages($pdf_generator->error ?: $langs->trans("ErrorGeneratingPDF"), null, 'errors');
}
}
if ($action == 'export_pdf_detailed') {
// Load PDF generator
require_once DOL_DOCUMENT_ROOT . '/custom/declarationtva/core/class/declarationtva_pdf.class.php';
$pdf_generator = new DeclarationTVA_PDF($db);
// Generate detailed PDF with breakdown pages
$pdf_path = $pdf_generator->generateDetailedCA3PDF($id);
if ($pdf_path && file_exists($pdf_path)) {
// Set headers for PDF download
header('Content-Type: application/pdf');
header('Content-Disposition: attachment; filename="CA3_Detailed_' . $declarationtva->declaration_number . '.pdf"');
header('Content-Length: ' . filesize($pdf_path));
// Output PDF file
readfile($pdf_path);
exit;
} else {
setEventMessages($pdf_generator->error ?: $langs->trans("ErrorGeneratingDetailedPDF"), null, 'errors');
}
}
if ($action == 'validate' && $token) {
// Validate the declaration
if ($declarationtva->validateDeclaration($id)) {
setEventMessages($langs->trans("DeclarationValidated"), null, 'mesgs');
// Generate and save detailed PDF to Dolibarr documents
require_once DOL_DOCUMENT_ROOT . '/custom/declarationtva/core/class/declarationtva_pdf.class.php';
$pdf_generator = new DeclarationTVA_PDF($db);
$pdf_path = $pdf_generator->generateDetailedCA3PDF($id);
if ($pdf_path && file_exists($pdf_path)) {
// Save PDF to Dolibarr documents
$save_result = $declarationtva->saveValidatedPDF($id, $pdf_path);
if (!$save_result) {
setEventMessages("Warning: Declaration validated but PDF save failed: " . $declarationtva->error, null, 'warnings');
}
} else {
setEventMessages("Warning: Declaration validated but PDF generation failed: " . $pdf_generator->error, null, 'warnings');
}
} else {
setEventMessages($langs->trans("ErrorValidatingDeclaration") . ": " . $declarationtva->error, null, 'errors');
}
}
if ($action == 'unvalidate' && $token) {
// Unvalidate the declaration (for testing purposes)
if ($declarationtva->unvalidateDeclaration($id)) {
setEventMessages($langs->trans("DeclarationUnvalidated"), null, 'mesgs');
} else {
setEventMessages($langs->trans("ErrorUnvalidatingDeclaration") . ": " . $declarationtva->error, null, 'errors');
}
}
// Fetch declaration
if ($declarationtva->fetch($id) < 0) {
setEventMessages($langs->trans("DeclarationNotFound"), null, 'errors');
header("Location: declarationtvaindex.php");
exit;
}
// Use declaration's own dates
$start_date = $declarationtva->start_date;
$end_date = $declarationtva->end_date;
// Page title
$title = $langs->trans("ViewDeclaration") . ' - ' . $declarationtva->declaration_number;
llxHeader('', $title);
// Print page header
print load_fiche_titre($title, '', 'title_accountancy');
// Print declaration details
print '<div class="fiche">';
print '<div class="titre">' . $langs->trans("DeclarationDetails") . '</div>';
print '<table class="noborder centpercent">';
print '<tr>';
print '<td class="fieldrequired">' . $langs->trans("DeclarationNumber") . '</td>';
print '<td>' . $declarationtva->declaration_number . '</td>';
print '</tr>';
print '<tr>';
print '<td>' . $langs->trans("DeclarationName") . '</td>';
print '<td>' . $declarationtva->declaration_name . '</td>';
print '</tr>';
print '<tr>';
print '<td>' . $langs->trans("Period") . '</td>';
print '<td>' . dol_print_date($start_date, 'day') . ' - ' . dol_print_date($end_date, 'day') . '</td>';
print '</tr>';
print '<tr>';
print '<td>' . $langs->trans("Status") . '</td>';
print '<td>' . $langs->trans("Status" . ucfirst($declarationtva->status)) . '</td>';
print '</tr>';
print '<tr>';
print '<td>' . $langs->trans("CreatedDate") . '</td>';
print '<td>' . dol_print_date($declarationtva->created_date, 'dayhour') . '</td>';
print '</tr>';
print '</table>';
print '</div>';
// Print CA-3 amounts (placeholder for now)
print '<div class="fiche">';
print '<div class="titre">' . $langs->trans("CA3Amounts") . '</div>';
print '<table class="noborder centpercent">';
// Get actual CA-3 lines from database
$ca3_lines = $declarationtva->getCA3Lines($id);
// Get CA-3 line definitions for proper descriptions
$ca3_definitions = $config->getCA3LineDefinitions();
// Helper function to format amounts with original values in brackets
function formatAmountWithOriginal($amount, $line_label, $amount_type = 'vat') {
// If amount is zero, show empty field
if ($amount == 0) {
return '';
}
// Parse original amounts from line_label if they exist
if (strpos($line_label, '|ORIGINAL_') !== false) {
$parts = explode('|', $line_label);
$original_info = $parts[1] ?? '';
$pattern = $amount_type == 'base' ? '/ORIGINAL_BASE:([0-9.]+)/' : '/ORIGINAL_VAT:([0-9.]+)/';
if (preg_match($pattern, $original_info, $matches)) {
$original_amount = floatval($matches[1]);
if ($original_amount != $amount) {
return number_format($amount, 0) . ' (' . number_format($original_amount, 2) . ')';
}
}
}
return number_format($amount, 0);
}
// Helper function to format simple amounts (no original values)
function formatAmount($amount) {
// If amount is zero, show empty field
if ($amount == 0) {
return '';
}
return number_format($amount, 0);
}
// Create a lookup array for quick access
$ca3_data = array();
foreach ($ca3_lines as $line) {
$ca3_data[$line['ca3_line']] = $line;
}
// Section A: Opérations imposables
print '<tr class="liste_titre" style="background-color: #1e3a8a !important;">';
print '<td colspan="4"><strong style="text-transform: uppercase; color: #ffffff; font-weight: bold;">A. ' . $langs->trans("CA3SectionA") . '</strong></td>';
print '</tr>';
print '<tr class="liste_titre">';
print '<th>' . $langs->trans("CA3Line") . '</th>';
print '<th colspan="2">' . $langs->trans("Description") . '</th>';
print '<th class="right">' . $langs->trans("Amount") . '</th>';
print '</tr>';
$section_a_lines = array('A1', 'A2', 'A3', 'A4', 'A5', 'E1', 'E2', 'E3', 'E4', 'E5', 'E6', 'F1', 'F2', 'F6', 'F7', 'F8');
foreach ($section_a_lines as $line) {
$data = isset($ca3_data[$line]) ? $ca3_data[$line] : array('line_label' => '', 'vat_amount' => 0);
$description = isset($ca3_definitions[$line]) ? $ca3_definitions[$line]['label'] : $data['line_label'];
print '<tr>';
print '<td style="text-align: center;"><a href="#" onclick="toggleDetails(\'' . $line . '\'); return false;" class="butAction">' . $line . '</a></td>';
print '<td colspan="2">' . $description . '</td>';
print '<td class="right">' . formatAmountWithOriginal($data['vat_amount'], $data['line_label']) . '</td>';
print '</tr>';
// Add dropdown row for account details
print '<tr id="details_' . $line . '" style="display: none;">';
print '<td colspan="4">';
print '<div class="account-details">';
print '<div class="account-details-header">' . $langs->trans("AccountBreakdown") . ' - ' . $line . '</div>';
print '<div class="account-details-content" id="content_' . $line . '">';
print '<div class="loading">' . $langs->trans("Loading") . '...</div>';
print '</div>';
print '</div>';
print '</td>';
print '</tr>';
}
// Section B: TVA due
print '<tr class="liste_titre" style="background-color: #1e3a8a !important;">';
print '<td colspan="4"><strong style="text-transform: uppercase; color: #ffffff; font-weight: bold;">B. ' . $langs->trans("CA3SectionB") . '</strong></td>';
print '</tr>';
// Column headers for lines 08, 09, 9B with base and VAT columns
print '<tr class="liste_titre">';
print '<th>' . $langs->trans("CA3Line") . '</th>';
print '<th>' . $langs->trans("Description") . '</th>';
print '<th class="right">' . $langs->trans("BaseAmount") . '</th>';
print '<th class="right">' . $langs->trans("VATAmount") . '</th>';
print '</tr>';
$base_vat_lines = array('08', '09', '9B');
foreach ($base_vat_lines as $line) {
$data = isset($ca3_data[$line]) ? $ca3_data[$line] : array('line_label' => '', 'base_amount' => 0, 'vat_amount' => 0);
$description = isset($ca3_definitions[$line]) ? $ca3_definitions[$line]['label'] : $data['line_label'];
print '<tr>';
print '<td style="text-align: center;"><a href="#" onclick="toggleDetails(\'' . $line . '\'); return false;" class="butAction">' . $line . '</a></td>';
print '<td>' . $description . '</td>';
print '<td class="right">' . formatAmountWithOriginal($data['base_amount'], $data['line_label'], 'base') . '</td>';
print '<td class="right">' . formatAmountWithOriginal($data['vat_amount'], $data['line_label']) . '</td>';
print '</tr>';
// Add dropdown row for account details
print '<tr id="details_' . $line . '" style="display: none;">';
print '<td colspan="4">';
print '<div class="account-details">';
print '<div class="account-details-header">' . $langs->trans("AccountBreakdown") . ' - ' . $line . '</div>';
print '<div class="account-details-content" id="content_' . $line . '">';
print '<div class="loading">' . $langs->trans("Loading") . '...</div>';
print '</div>';
print '</div>';
print '</td>';
print '</tr>';
}
// Line 16: Subtotal (calculated automatically)
$data = isset($ca3_data['16']) ? $ca3_data['16'] : array('line_label' => '', 'vat_amount' => 0);
print '<tr class="pair" style="background-color: #ffe6e6 !important;">';
print '<td style="background-color: #ffe6e6 !important; text-align: center;"><strong>16</strong></td>';
print '<td colspan="2" style="background-color: #ffe6e6 !important;"><strong>Total de la TVA brute due (lignes 08 à 5B)</strong></td>';
print '<td class="right" style="background-color: #ffe6e6 !important;"><strong>' . formatAmount($data['vat_amount']) . '</strong></td>';
print '</tr>';
// Line 17
$data = isset($ca3_data['17']) ? $ca3_data['17'] : array('line_label' => '', 'vat_amount' => 0);
$description = isset($ca3_definitions['17']) ? $ca3_definitions['17']['label'] : $data['line_label'];
print '<tr>';
print '<td style="text-align: center;"><a href="#" onclick="toggleDetails(\'17\'); return false;" class="butAction">17</a></td>';
print '<td colspan="2">' . $description . '</td>';
print '<td class="right">' . formatAmountWithOriginal($data['vat_amount'], $data['line_label']) . '</td>';
print '</tr>';
// Add dropdown row for account details
print '<tr id="details_17" style="display: none;">';
print '<td colspan="4">';
print '<div class="account-details">';
print '<div class="account-details-header">' . $langs->trans("AccountBreakdown") . ' - 17</div>';
print '<div class="account-details-content" id="content_17">';
print '<div class="loading">' . $langs->trans("Loading") . '...</div>';
print '</div>';
print '</div>';
print '</td>';
print '</tr>';
// Line 18: Monaco operations
$data = isset($ca3_data['18']) ? $ca3_data['18'] : array('line_label' => '', 'vat_amount' => 0);
$description = isset($ca3_definitions['18']) ? $ca3_definitions['18']['label'] : $data['line_label'];
print '<tr>';
print '<td style="text-align: center;"><a href="#" onclick="toggleDetails(\'18\'); return false;" class="butAction">18</a></td>';
print '<td colspan="2">' . $description . '</td>';
print '<td class="right">' . formatAmountWithOriginal($data['vat_amount'], $data['line_label']) . '</td>';
print '</tr>';
// Add dropdown row for account details
print '<tr id="details_18" style="display: none;">';
print '<td colspan="4">';
print '<div class="account-details">';
print '<div class="account-details-header">' . $langs->trans("AccountBreakdown") . ' - 18</div>';
print '<div class="account-details-content" id="content_18">';
print '<div class="loading">' . $langs->trans("Loading") . '...</div>';
print '</div>';
print '</div>';
print '</td>';
print '</tr>';
// Section B sub-section: TVA DÉDUCTIBLE
print '<tr class="liste_titre" style="background-color: #e6f3ff !important;">';
print '<td colspan="4"><strong style="text-transform: uppercase; color: #0066cc;">TVA DÉDUCTIBLE</strong></td>';
print '</tr>';
print '<tr class="liste_titre">';
print '<th>' . $langs->trans("CA3Line") . '</th>';
print '<th colspan="2">' . $langs->trans("Description") . '</th>';
print '<th class="right">' . $langs->trans("Amount") . '</th>';
print '</tr>';
$section_c_lines = array('19', '20', '21', '22');
foreach ($section_c_lines as $line) {
$data = isset($ca3_data[$line]) ? $ca3_data[$line] : array('line_label' => '', 'vat_amount' => 0);
$description = isset($ca3_definitions[$line]) ? $ca3_definitions[$line]['label'] : $data['line_label'];
print '<tr>';
print '<td style="text-align: center;"><a href="#" onclick="toggleDetails(\'' . $line . '\'); return false;" class="butAction">' . $line . '</a></td>';
print '<td colspan="2">' . $description . '</td>';
print '<td class="right">' . formatAmountWithOriginal($data['vat_amount'], $data['line_label']) . '</td>';
print '</tr>';
// Add dropdown row for account details
print '<tr id="details_' . $line . '" style="display: none;">';
print '<td colspan="4">';
print '<div class="account-details">';
print '<div class="account-details-header">' . $langs->trans("AccountBreakdown") . ' - ' . $line . '</div>';
print '<div class="account-details-content" id="content_' . $line . '">';
print '<div class="loading">' . $langs->trans("Loading") . '...</div>';
print '</div>';
print '</div>';
print '</td>';
print '</tr>';
}
// Line 23: Subtotal (calculated automatically)
$data = isset($ca3_data['23']) ? $ca3_data['23'] : array('line_label' => '', 'vat_amount' => 0);
print '<tr class="pair" style="background-color: #ffe6e6 !important;">';
print '<td style="background-color: #ffe6e6 !important; text-align: center;"><strong>23</strong></td>';
print '<td colspan="2" style="background-color: #ffe6e6 !important;"><strong>Total TVA déductible (ligne 19 à 2C)</strong></td>';
print '<td class="right" style="background-color: #ffe6e6 !important;"><strong>' . formatAmount($data['vat_amount']) . '</strong></td>';
print '</tr>';
// Section D: Résultat
print '<tr class="liste_titre" style="background-color: #e6f3ff !important;">';
print '<td colspan="4"><strong style="text-transform: uppercase; color: #0066cc;">D. ' . $langs->trans("CA3SectionD") . '</strong></td>';
print '</tr>';
print '<tr class="liste_titre">';
print '<th>' . $langs->trans("CA3Line") . '</th>';
print '<th colspan="2">' . $langs->trans("Description") . '</th>';
print '<th class="right">' . $langs->trans("Amount") . '</th>';
print '</tr>';
$section_d_lines = array('25', '26', '27', 'TD', '28', '32');
foreach ($section_d_lines as $line) {
$data = isset($ca3_data[$line]) ? $ca3_data[$line] : array('line_label' => '', 'vat_amount' => 0);
// Prioritize database line_label over definitions (for calculated lines)
$description = !empty($data['line_label']) ? $data['line_label'] : (isset($ca3_definitions[$line]) ? $ca3_definitions[$line]['label'] : '');
// Special formatting for line 32 (bold)
$is_line_32 = ($line == '32');
$bold_style = $is_line_32 ? 'font-weight: bold;' : '';
print '<tr style="background-color: #ffe6e6 !important;">';
print '<td style="background-color: #ffe6e6 !important; text-align: center; ' . $bold_style . '"><strong>' . $line . '</strong></td>';
print '<td colspan="2" style="background-color: #ffe6e6 !important; ' . $bold_style . '">' . $description . '</td>';
print '<td class="right" style="background-color: #ffe6e6 !important; ' . $bold_style . '">' . formatAmount($data['vat_amount']) . '</td>';
print '</tr>';
}
// Show message if no data
if (empty($ca3_lines)) {
print '<tr>';
print '<td colspan="3" class="center">' . $langs->trans("NoCA3Data") . '</td>';
print '</tr>';
}
print '</table>';
print '</div>';
// Print actions
print '<div class="fiche">';
print '<div class="titre">' . $langs->trans("Actions") . '</div>';
print '<div class="center">';
// Recalculate button (only for draft status)
if ($declarationtva->status == 'draft') {
print '<a href="' . $_SERVER['PHP_SELF'] . '?id=' . $id . '&action=recalculate&token=' . newToken() . '" class="butAction">' . $langs->trans("Recalculate") . '</a> ';
}
// PDF Export buttons (always available)
print '<a href="' . $_SERVER['PHP_SELF'] . '?id=' . $id . '&action=export_pdf" class="butAction">' . $langs->trans("ExportPDF") . '</a> ';
print '<a href="' . $_SERVER['PHP_SELF'] . '?id=' . $id . '&action=export_pdf_detailed" class="butAction">' . $langs->trans("ExportPDFDetailed") . '</a> ';
if ($declarationtva->status == 'draft') {
// Validation button with confirmation dialog
print '<a href="#" onclick="confirmValidation(' . $id . '); return false;" class="butAction">' . $langs->trans("Validate") . '</a> ';
} elseif ($declarationtva->status == 'validated') {
print '<a href="' . $_SERVER['PHP_SELF'] . '?id=' . $id . '&action=submit" class="butAction">' . $langs->trans("Submit") . '</a> ';
// Add unvalidate button for testing
print '<a href="' . $_SERVER['PHP_SELF'] . '?id=' . $id . '&action=unvalidate&token=' . newToken() . '" class="butAction" style="background-color: #dc3545;" onclick="return confirm(\'' . $langs->trans("ConfirmUnvalidate") . '\')">' . $langs->trans("Unvalidate") . '</a> ';
}
print '<a href="declarationtvaindex.php" class="butAction">' . $langs->trans("BackToList") . '</a>';
print '</div>';
print '</div>';
// Add CSS for dropdown styling
print '<style>
.account-details {
background-color: #f8f9fa;
border: 1px solid #dee2e6;
border-radius: 4px;
margin: 10px 0;
padding: 15px;
}
.account-details-header {
font-weight: bold;
color: #495057;
margin-bottom: 10px;
padding-bottom: 5px;
border-bottom: 1px solid #dee2e6;
}
.account-details-content {
font-size: 0.9em;
}
.account-details table {
width: 100%;
border-collapse: collapse;
margin-top: 10px;
}
.account-details table th,
.account-details table td {
padding: 8px;
text-align: left;
border: 1px solid #dee2e6;
}
.account-details table th {
background-color: #e9ecef;
font-weight: bold;
}
.account-details table tr:nth-child(even) {
background-color: #f8f9fa;
}
.loading {
text-align: center;
color: #6c757d;
font-style: italic;
}
</style>';
// Add JavaScript for dropdown functionality
print '<script>
var loadedDetails = {};
function toggleDetails(line) {
var detailsRow = document.getElementById("details_" + line);
var contentDiv = document.getElementById("content_" + line);
if (detailsRow.style.display === "none") {
// Show the dropdown
detailsRow.style.display = "";
// Load content if not already loaded
if (!loadedDetails[line]) {
loadLineDetails(line);
}
} else {
// Hide the dropdown
detailsRow.style.display = "none";
}
}
function loadLineDetails(line) {
var contentDiv = document.getElementById("content_" + line);
var declarationId = ' . $declarationtva->rowid . ';
// Show loading
contentDiv.innerHTML = "<div class=\"loading\">' . $langs->trans("Loading") . '...</div>";
// Make AJAX request to get line details
var xhr = new XMLHttpRequest();
xhr.open("GET", "declarationtva_line_details_ajax.php?declaration_id=" + declarationId + "&ca3_line=" + line, true);
xhr.onreadystatechange = function() {
if (xhr.readyState === 4 && xhr.status === 200) {
contentDiv.innerHTML = xhr.responseText;
loadedDetails[line] = true;
} else if (xhr.readyState === 4) {
contentDiv.innerHTML = "<div class=\"error\">' . $langs->trans("ErrorLoadingDetails") . '</div>";
}
};
xhr.send();
}
function confirmValidation(declarationId) {
// Create a proper Dolibarr-style modal dialog
var dialog = document.createElement("div");
dialog.id = "validationModal";
dialog.style.cssText = "position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.6); z-index: 10000; display: flex; align-items: center; justify-content: center; font-family: Arial, sans-serif;";
var dialogContent = document.createElement("div");
dialogContent.style.cssText = "background: white; border-radius: 8px; box-shadow: 0 10px 30px rgba(0,0,0,0.3); max-width: 500px; width: 90%; max-height: 90%; overflow: hidden;";
// Header
var header = document.createElement("div");
header.style.cssText = "background: #f8f9fa; padding: 20px; border-bottom: 1px solid #dee2e6; display: flex; align-items: center;";
header.innerHTML = `
<div style="flex: 1;">
<h3 style="margin: 0; color: #495057; font-size: 18px; font-weight: 600;">' . $langs->trans("ConfirmValidation") . '</h3>
</div>
<button onclick="closeValidationModal()" style="background: none; border: none; font-size: 24px; color: #6c757d; cursor: pointer; padding: 0; width: 30px; height: 30px; display: flex; align-items: center; justify-content: center;">&times;</button>
`;
// Body
var body = document.createElement("div");
body.style.cssText = "padding: 20px;";
body.innerHTML = `
<div style="display: flex; align-items: flex-start; margin-bottom: 20px;">
<div style="background: #fff3cd; border: 1px solid #ffeaa7; border-radius: 50%; width: 40px; height: 40px; display: flex; align-items: center; justify-content: center; margin-right: 15px; flex-shrink: 0;">
<span style="color: #856404; font-size: 18px; font-weight: bold;">!</span>
</div>
<div style="flex: 1;">
<p style="margin: 0; color: #495057; line-height: 1.5; font-size: 14px;">' . $langs->trans("ValidationConfirmationMessage") . '</p>
</div>
</div>
`;
// Footer
var footer = document.createElement("div");
footer.style.cssText = "background: #f8f9fa; padding: 15px 20px; border-top: 1px solid #dee2e6; display: flex; justify-content: flex-end; gap: 10px;";
footer.innerHTML = `
<button onclick="closeValidationModal()" style="background: #6c757d; color: white; border: none; padding: 8px 16px; border-radius: 4px; cursor: pointer; font-size: 14px; font-weight: 500;">
' . $langs->trans("Cancel") . '
</button>
<button onclick="proceedValidation(' . $id . ')" style="background: #28a745; color: white; border: none; padding: 8px 16px; border-radius: 4px; cursor: pointer; font-size: 14px; font-weight: 500;">
' . $langs->trans("YesValidate") . '
</button>
`;
dialogContent.appendChild(header);
dialogContent.appendChild(body);
dialogContent.appendChild(footer);
dialog.appendChild(dialogContent);
document.body.appendChild(dialog);
// Add escape key handler
document.addEventListener("keydown", function(e) {
if (e.key === "Escape") {
closeValidationModal();
}
});
}
function closeValidationModal() {
var modal = document.getElementById("validationModal");
if (modal) {
modal.remove();
}
}
function proceedValidation(declarationId) {
// Redirect to validation action
window.location.href = "' . $_SERVER['PHP_SELF'] . '?id=" + declarationId + "&action=validate&token=' . newToken() . '";
}
</script>';
// Print footer
llxFooter();
?>