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 '
';
print '
' . $langs->trans("DeclarationDetails") . '
';
print '
';
print '';
print '| ' . $langs->trans("DeclarationNumber") . ' | ';
print '' . $declarationtva->declaration_number . ' | ';
print '
';
print '';
print '| ' . $langs->trans("DeclarationName") . ' | ';
print '' . $declarationtva->declaration_name . ' | ';
print '
';
print '';
print '| ' . $langs->trans("Period") . ' | ';
print '' . dol_print_date($start_date, 'day') . ' - ' . dol_print_date($end_date, 'day') . ' | ';
print '
';
print '';
print '| ' . $langs->trans("Status") . ' | ';
print '' . $langs->trans("Status" . ucfirst($declarationtva->status)) . ' | ';
print '
';
print '';
print '| ' . $langs->trans("CreatedDate") . ' | ';
print '' . dol_print_date($declarationtva->created_date, 'dayhour') . ' | ';
print '
';
// Add totals section
print '';
print '| ' . $langs->trans("TotalVATCollected") . ' | ';
print '' . price($declarationtva->total_vat_collected) . ' | ';
print '
';
print '';
print '| ' . $langs->trans("TotalVATDeductible") . ' | ';
print '' . price($declarationtva->total_vat_deductible) . ' | ';
print '
';
print '';
print '| ' . $langs->trans("NetVATDue") . ' | ';
print '' . price($declarationtva->net_vat_due) . ' | ';
print '
';
if ($declarationtva->vat_credit > 0) {
print '';
print '| ' . $langs->trans("VATCredit") . ' | ';
print '' . price($declarationtva->vat_credit) . ' | ';
print '
';
}
print '
';
print '
';
// Print CA-3 amounts (placeholder for now)
print '';
print '
' . $langs->trans("CA3Amounts") . '
';
print '
';
print '';
print '| ' . $langs->trans("CA3Line") . ' | ';
print '' . $langs->trans("Description") . ' | ';
print '' . $langs->trans("Amount") . ' | ';
print '
';
// Get actual CA-3 lines from database
$ca3_lines = $declarationtva->getCA3Lines($id);
// Get CA-3 line definitions for proper descriptions
$ca3_definitions = $config->getCA3LineDefinitions();
// 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 '';
print '| A. ' . $langs->trans("CA3SectionA") . ' | ';
print '
';
$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 '';
print '| ' . $line . ' | ';
print '' . $description . ' | ';
print '' . price($data['vat_amount']) . ' | ';
print '
';
}
// Section B: TVA due
print '';
print '| B. ' . $langs->trans("CA3SectionB") . ' | ';
print '
';
$section_b_lines = array('08', '09', '9B', '17');
foreach ($section_b_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 '';
print '| ' . $line . ' | ';
print '' . $description . ' | ';
print '' . price($data['vat_amount']) . ' | ';
print '
';
}
// Section C: TVA déductible
print '';
print '| C. ' . $langs->trans("CA3SectionC") . ' | ';
print '
';
$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 '';
print '| ' . $line . ' | ';
print '' . $description . ' | ';
print '' . price($data['vat_amount']) . ' | ';
print '
';
}
// Section D: Résultat
print '';
print '| D. ' . $langs->trans("CA3SectionD") . ' | ';
print '
';
$section_d_lines = array('25', '26', '28', '29');
foreach ($section_d_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 '';
print '| ' . $line . ' | ';
print '' . $description . ' | ';
print '' . price($data['vat_amount']) . ' | ';
print '
';
}
// Show message if no data
if (empty($ca3_lines)) {
print '';
print '| ' . $langs->trans("NoCA3Data") . ' | ';
print '
';
}
print '
';
print '
';
// Print actions
print '';
print '
' . $langs->trans("Actions") . '
';
print '
';
print '
';
// Print footer
llxFooter();
?>