DeclarationTVA/declarationtvaindex.php
Frank Cools 632c77d335 v2.5.1: Enhanced PDF layout with light gray section backgrounds
- Added light gray backgrounds to all section titles in detailed pages
- Enhanced visual hierarchy for better readability
- Improved professional appearance of PDF exports
- Updated module version to 2.5.1
2025-10-08 12:21:26 +02:00

208 lines
8.8 KiB
PHP

<?php
/**
* DeclarationTVA Main Interface
* 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");
// 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');
$declaration_id = GETPOST('declaration_id', 'int');
$period_id = GETPOST('period_id', 'int');
// Process actions
$token = GETPOST('token', 'alpha');
if ($action == 'create_declaration' && $period_id > 0) {
$declaration_id = $declarationtva->createDeclaration($period_id);
if ($declaration_id > 0) {
setEventMessages($langs->trans("DeclarationCreated"), null, 'mesgs');
} else {
setEventMessages($langs->trans("ErrorCreatingDeclaration") . ": " . $declarationtva->error, null, 'errors');
}
} elseif ($action == 'validate_declaration' && $declaration_id > 0 && $token) {
if ($declarationtva->validateDeclaration($declaration_id)) {
setEventMessages($langs->trans("DeclarationValidated"), null, 'mesgs');
} else {
setEventMessages($langs->trans("ErrorValidatingDeclaration"), null, 'errors');
}
} elseif ($action == 'submit_declaration' && $declaration_id > 0 && $token) {
if ($declarationtva->submitDeclaration($declaration_id)) {
setEventMessages($langs->trans("DeclarationSubmitted"), null, 'mesgs');
} else {
setEventMessages($langs->trans("ErrorSubmittingDeclaration"), null, 'errors');
}
} elseif ($action == 'delete_declaration' && $declaration_id > 0 && $token) {
if ($declarationtva->deleteDeclaration($declaration_id)) {
setEventMessages($langs->trans("DeclarationDeleted"), null, 'mesgs');
} else {
setEventMessages($langs->trans("ErrorDeletingDeclaration"), null, 'errors');
}
}
// Get data for display
$declarations = array();
// Get all declarations
$sql = "SELECT d.*, p.period_name, p.start_date as period_start_date, p.end_date as period_end_date
FROM " . MAIN_DB_PREFIX . "declarationtva_declarations d
LEFT JOIN " . MAIN_DB_PREFIX . "declarationtva_periods p ON d.period_id = p.rowid
WHERE d.entity = " . $conf->entity . "
ORDER BY d.created_date DESC";
$result = $db->query($sql);
if ($result) {
while ($obj = $db->fetch_object($result)) {
// Use declaration's own dates
$start_date = $obj->start_date ? $obj->start_date : $obj->period_start_date;
$end_date = $obj->end_date ? $obj->end_date : $obj->period_end_date;
$declarations[] = array(
'rowid' => $obj->rowid,
'declaration_number' => $obj->declaration_number,
'status' => $obj->status,
'total_vat_collected' => $obj->total_vat_collected,
'total_vat_deductible' => $obj->total_vat_deductible,
'net_vat_due' => $obj->net_vat_due,
'vat_credit' => $obj->vat_credit,
'created_date' => $obj->created_date,
'start_date' => $start_date,
'end_date' => $end_date
);
}
}
// Page title
$title = $langs->trans("DeclarationTVAMainInterface");
llxHeader('', $title);
// Print page header with create button
print load_fiche_titre($title, '<a href="declarationtva_create.php" class="butAction">' . $langs->trans("CreateDeclaration") . '</a>');
// Print declarations section
print '<div class="fiche">';
print '<div class="titre">' . $langs->trans("DeclarationTVADeclarations") . '</div>';
if (empty($declarations)) {
print '<div class="info">' . $langs->trans("NoDeclarationsFound") . '</div>';
} else {
print '<table class="noborder centpercent">';
print '<tr class="liste_titre">';
print '<th>' . $langs->trans("DeclarationNumber") . '</th>';
print '<th class="center">' . $langs->trans("Period") . '</th>';
print '<th class="center">' . $langs->trans("Status") . '</th>';
print '<th class="center">' . $langs->trans("NetVATDue") . '</th>';
print '<th class="center">' . $langs->trans("Document") . '</th>';
print '<th class="center">' . $langs->trans("Actions") . '</th>';
print '</tr>';
foreach ($declarations as $d) {
print '<tr>';
print '<td>' . $d['declaration_number'] . '</td>';
print '<td class="center">' . dol_print_date($d['start_date'], 'day') . ' - ' . dol_print_date($d['end_date'], 'day') . '</td>';
// Status with icon
$status_icon = '';
if ($d['status'] == 'validated') {
$status_icon = ' <i class="fa fa-check-circle text-success" title="' . $langs->trans("ValidatedDeclaration") . '"></i>';
} elseif ($d['status'] == 'draft') {
$status_icon = ' <i class="fa fa-edit text-warning" title="' . $langs->trans("DraftDeclaration") . '"></i>';
}
print '<td class="center">' . $langs->trans("Status" . ucfirst($d['status'])) . $status_icon . '</td>';
// Show VAT amount with proper label
// Check if there's a VAT credit (refund) or net VAT due
if ($d['vat_credit'] > 0) {
// VAT refund case
print '<td class="center"><strong style="color: #28a745;">' . price($d['vat_credit']) . '</strong><br><small>' . $langs->trans("VATToReceive") . '</small></td>';
} elseif ($d['net_vat_due'] > 0) {
// VAT due case
print '<td class="center"><strong style="color: #dc3545;">' . price($d['net_vat_due']) . '</strong><br><small>' . $langs->trans("NetVATDue") . '</small></td>';
} else {
// Balanced case
print '<td class="center"><strong>' . price(0) . '</strong><br><small>' . $langs->trans("VATBalanced") . '</small></td>';
}
// Document column
print '<td class="center">';
if ($d['status'] == 'validated') {
// Check if document exists
$has_document = $declarationtva->hasValidatedDocument($d['rowid']);
if ($has_document) {
$pdf_path = $declarationtva->getValidatedPDFPath($d['rowid']);
if ($pdf_path) {
// Create a secure download link through the download handler
$download_url = $_SERVER['PHP_SELF'] . '?action=download_pdf&declaration_id=' . $d['rowid'] . '&token=' . newToken();
print '<a href="download_pdf.php?id=' . $d['rowid'] . '&token=' . newToken() . '" target="_blank" title="' . $langs->trans("DownloadPDF") . '" style="color: #28a745; text-decoration: none; font-weight: bold;">';
print '<i class="fa fa-file-pdf" style="font-size: 16px; color: #dc3545;"></i> PDF';
print '</a>';
} else {
print '<i class="fa fa-file-pdf" style="font-size: 16px; color: #28a745;" title="' . $langs->trans("ValidatedPDFAvailable") . '"></i>';
}
} else {
print '<i class="fa fa-file-o text-muted" title="' . $langs->trans("NoDocument") . '"></i>';
}
} else {
print '<i class="fa fa-minus text-muted"></i>';
}
print '</td>';
print '<td class="center">';
if ($d['status'] == 'draft') {
print '<a href="' . $_SERVER['PHP_SELF'] . '?action=delete_declaration&declaration_id=' . $d['rowid'] . '&token=' . newToken() . '" class="button button-delete" onclick="return confirm(\'' . $langs->trans("ConfirmDeleteDeclaration") . '\')">' . $langs->trans("Delete") . '</a> ';
}
print '<a href="declarationtva_view.php?id=' . $d['rowid'] . '" class="button">' . $langs->trans("View") . '</a>';
print '</td>';
print '</tr>';
}
print '</table>';
}
print '</div>';
// Print configuration section
print '<div class="fiche">';
print '<div class="titre">' . $langs->trans("DeclarationTVAConfiguration") . '</div>';
print '<div class="info">';
print '<a href="admin/setup_mvp.php" class="butAction">' . $langs->trans("ConfigurePCGAccounts") . '</a>';
print '</div>';
print '</div>';
// Print footer
llxFooter();
?>