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 ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; // Add totals section print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; if ($declarationtva->vat_credit > 0) { print ''; print ''; print ''; print ''; } print '
' . $langs->trans("DeclarationNumber") . '' . $declarationtva->declaration_number . '
' . $langs->trans("DeclarationName") . '' . $declarationtva->declaration_name . '
' . $langs->trans("Period") . '' . dol_print_date($start_date, 'day') . ' - ' . dol_print_date($end_date, 'day') . '
' . $langs->trans("Status") . '' . $langs->trans("Status" . ucfirst($declarationtva->status)) . '
' . $langs->trans("CreatedDate") . '' . dol_print_date($declarationtva->created_date, 'dayhour') . '
' . $langs->trans("TotalVATCollected") . '' . price($declarationtva->total_vat_collected) . '
' . $langs->trans("TotalVATDeductible") . '' . price($declarationtva->total_vat_deductible) . '
' . $langs->trans("NetVATDue") . '' . price($declarationtva->net_vat_due) . '
' . $langs->trans("VATCredit") . '' . price($declarationtva->vat_credit) . '
'; print '
'; // Print CA-3 amounts (placeholder for now) print '
'; print '
' . $langs->trans("CA3Amounts") . '
'; print ''; print ''; print ''; print ''; print ''; 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 ''; 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 ''; print ''; print ''; print ''; } // Section B: TVA due print ''; print ''; print ''; // Special header for lines 08, 09, 9B with base and VAT columns print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; $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 ''; print ''; print ''; print ''; print ''; print ''; } // Reset to normal layout for line 17 print ''; print ''; print ''; print ''; print ''; $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 ''; print ''; print ''; print ''; print ''; // Section C: TVA déductible print ''; print ''; 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 ''; print ''; print ''; print ''; } // Section D: Résultat print ''; print ''; 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 ''; print ''; print ''; print ''; } // Show message if no data if (empty($ca3_lines)) { print ''; print ''; print ''; } print '
' . $langs->trans("CA3Line") . '' . $langs->trans("Description") . '' . $langs->trans("Amount") . '
A. ' . $langs->trans("CA3SectionA") . '
' . $line . '' . $description . '' . price($data['vat_amount']) . '
B. ' . $langs->trans("CA3SectionB") . '
' . $langs->trans("BaseHTAndVATByRate") . '
' . $langs->trans("CA3Line") . '' . $langs->trans("Description") . '' . $langs->trans("BaseAmount") . '' . $langs->trans("VATAmount") . '
' . $line . '' . $description . '' . price($data['base_amount']) . '' . price($data['vat_amount']) . '
' . $langs->trans("CA3Line") . '' . $langs->trans("Description") . '' . $langs->trans("Amount") . '
17' . $description . '' . price($data['vat_amount']) . '
C. ' . $langs->trans("CA3SectionC") . '
' . $line . '' . $description . '' . price($data['vat_amount']) . '
D. ' . $langs->trans("CA3SectionD") . '
' . $line . '' . $description . '' . price($data['vat_amount']) . '
' . $langs->trans("NoCA3Data") . '
'; print '
'; // Print actions print '
'; print '
' . $langs->trans("Actions") . '
'; print '
'; // Recalculate button (always available) print '' . $langs->trans("Recalculate") . ' '; if ($declarationtva->status == 'draft') { print '' . $langs->trans("Validate") . ' '; } elseif ($declarationtva->status == 'validated') { print '' . $langs->trans("Submit") . ' '; } print '' . $langs->trans("BackToList") . ''; print '
'; print '
'; // Print footer llxFooter(); ?>