Features added: - New getCA3LineDetails() method in DeclarationTVA class - New declarationtva_line_details.php page for detailed view - All CA-3 line codes are now clickable in declaration view - Detailed breakdown shows: * Account codes and labels * Base amounts, VAT amounts, total amounts * Mapping types (A1, 08_BASE, 08_VAT, etc.) * Calculated totals vs account totals - Added comprehensive translations for detailed view - Navigation breadcrumbs and back buttons - Professional styling with Dolibarr UI components This provides complete transparency into which accounts contribute to each CA-3 line without touching the calculation logic.
326 lines
12 KiB
PHP
326 lines
12 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');
|
|
}
|
|
}
|
|
|
|
// 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">';
|
|
print '<td colspan="4"><strong>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');
|
|
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><a href="declarationtva_line_details.php?declaration_id=' . $declarationtva->rowid . '&ca3_line=' . $line . '" 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>';
|
|
}
|
|
|
|
// Section B: TVA due
|
|
print '<tr class="liste_titre">';
|
|
print '<td colspan="4"><strong>B. ' . $langs->trans("CA3SectionB") . '</strong></td>';
|
|
print '</tr>';
|
|
|
|
// Special header for lines 08, 09, 9B with base and VAT columns
|
|
print '<tr class="liste_titre">';
|
|
print '<td colspan="4"><strong>' . $langs->trans("BaseHTAndVATByRate") . '</strong></td>';
|
|
print '</tr>';
|
|
|
|
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><a href="declarationtva_line_details.php?declaration_id=' . $declarationtva->rowid . '&ca3_line=' . $line . '" 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>';
|
|
}
|
|
|
|
// Line 16: Subtotal (calculated automatically)
|
|
$data = isset($ca3_data['16']) ? $ca3_data['16'] : array('line_label' => '', 'vat_amount' => 0);
|
|
print '<tr class="pair">';
|
|
print '<td><strong>16</strong></td>';
|
|
print '<td colspan="2"><strong>Sous-total TVA due (08 + 09 + 9B)</strong></td>';
|
|
print '<td class="right"><strong>' . formatAmount($data['vat_amount']) . '</strong></td>';
|
|
print '</tr>';
|
|
|
|
// Reset to normal layout for line 17
|
|
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>';
|
|
|
|
$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><a href="declarationtva_line_details.php?declaration_id=' . $declarationtva->rowid . '&ca3_line=17" 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>';
|
|
|
|
// Section C: TVA déductible
|
|
print '<tr class="liste_titre">';
|
|
print '<td colspan="4"><strong>C. ' . $langs->trans("CA3SectionC") . '</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('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><a href="declarationtva_line_details.php?declaration_id=' . $declarationtva->rowid . '&ca3_line=' . $line . '" 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>';
|
|
}
|
|
|
|
// Line 23: Subtotal (calculated automatically)
|
|
$data = isset($ca3_data['23']) ? $ca3_data['23'] : array('line_label' => '', 'vat_amount' => 0);
|
|
print '<tr class="pair">';
|
|
print '<td><strong>23</strong></td>';
|
|
print '<td colspan="2"><strong>Sous-total TVA déductible (20 + 21 + 22)</strong></td>';
|
|
print '<td class="right"><strong>' . formatAmount($data['vat_amount']) . '</strong></td>';
|
|
print '</tr>';
|
|
|
|
// Section D: Résultat
|
|
print '<tr class="liste_titre">';
|
|
print '<td colspan="4"><strong>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', 'TD', '28', '29');
|
|
foreach ($section_d_lines as $line) {
|
|
$data = isset($ca3_data[$line]) ? $ca3_data[$line] : array('line_label' => '', 'vat_amount' => 0);
|
|
|
|
// Special handling for line TD
|
|
if ($line == 'TD') {
|
|
$description = 'TVA due (montant à payer)';
|
|
} else {
|
|
$description = isset($ca3_definitions[$line]) ? $ca3_definitions[$line]['label'] : $data['line_label'];
|
|
}
|
|
|
|
print '<tr>';
|
|
print '<td><a href="declarationtva_line_details.php?declaration_id=' . $declarationtva->rowid . '&ca3_line=' . $line . '" class="butAction">' . $line . '</a></td>';
|
|
print '<td colspan="2">' . $description . '</td>';
|
|
print '<td class="right">' . 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 (always available)
|
|
print '<a href="' . $_SERVER['PHP_SELF'] . '?id=' . $id . '&action=recalculate&token=' . newToken() . '" class="butAction">' . $langs->trans("Recalculate") . '</a> ';
|
|
|
|
if ($declarationtva->status == 'draft') {
|
|
print '<a href="' . $_SERVER['PHP_SELF'] . '?id=' . $id . '&action=validate" 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> ';
|
|
}
|
|
|
|
print '<a href="declarationtvaindex.php" class="butAction">' . $langs->trans("BackToList") . '</a>';
|
|
|
|
print '</div>';
|
|
print '</div>';
|
|
|
|
// Print footer
|
|
llxFooter();
|
|
?>
|