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 == 'validate' && $token) { // Validate the declaration if ($declarationtva->validateDeclaration($id)) { // 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($langs->trans("DeclarationValidated"), null, 'mesgs'); } } 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'); } } if ($action == 'submit' && $token) { // Submit the declaration (create accounting entries and update status) if ($declarationtva->submitDeclaration($id)) { setEventMessages($langs->trans("DeclarationSubmitted"), null, 'mesgs'); } else { setEventMessages($langs->trans("ErrorSubmittingDeclaration") . ": " . $declarationtva->error, null, 'errors'); } } if ($action == 'reset_status' && $token) { // Reset declaration status to validated (for testing purposes) if ($declarationtva->resetDeclarationStatus($id)) { setEventMessages($langs->trans("DeclarationStatusReset"), null, 'mesgs'); } else { setEventMessages($langs->trans("ErrorResettingDeclarationStatus") . ": " . $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 '
| ' . $langs->trans("DeclarationNumber") . ' | '; print '' . $declarationtva->declaration_number . ' | '; print '
| ' . $langs->trans("DeclarationName") . ' | '; print '' . $declarationtva->declaration_name . ' | '; print '
| ' . $langs->trans("Period") . ' | '; print '' . dol_print_date($start_date, 'day') . ' - ' . dol_print_date($end_date, 'day') . ' | '; print '
| ' . $langs->trans("Status") . ' | '; print '' . $langs->trans("Status" . ucfirst($declarationtva->status)) . ' | '; print '
| ' . $langs->trans("CreatedDate") . ' | '; print '' . dol_print_date($declarationtva->created_date, 'dayhour') . ' | '; print '
| A. ' . $langs->trans("CA3SectionA") . ' | '; print '|||
| ' . $langs->trans("CA3Line") . ' | '; print '' . $langs->trans("Description") . ' | '; print '' . $langs->trans("Amount") . ' | '; print '|
|---|---|---|---|
| ' . $line . ' | '; print '' . $description . ' | '; print '' . formatAmountWithOriginal($data['vat_amount'], $data['line_label']) . ' | '; print '|
| B. ' . $langs->trans("CA3SectionB") . ' | '; print '|||
| ' . $langs->trans("CA3Line") . ' | '; print '' . $langs->trans("Description") . ' | '; print '' . $langs->trans("BaseAmount") . ' | '; print '' . $langs->trans("VATAmount") . ' | '; print '
| ' . $line . ' | '; print '' . $description . ' | '; print '' . formatAmountWithOriginal($data['base_amount'], $data['line_label'], 'base') . ' | '; print '' . formatAmountWithOriginal($data['vat_amount'], $data['line_label']) . ' | '; print '
| 16 | '; print 'Total de la TVA brute due (lignes 08 à 5B) | '; print '' . formatAmount($data['vat_amount']) . ' | '; print '|
| 17 | '; print '' . $description . ' | '; print '' . formatAmountWithOriginal($data['vat_amount'], $data['line_label']) . ' | '; print '|
| 18 | '; print '' . $description . ' | '; print '' . formatAmountWithOriginal($data['vat_amount'], $data['line_label']) . ' | '; print '|
| TVA DÉDUCTIBLE | '; print '|||
| ' . $langs->trans("CA3Line") . ' | '; print '' . $langs->trans("Description") . ' | '; print '' . $langs->trans("Amount") . ' | '; print '|
| ' . $line . ' | '; print '' . $description . ' | '; print '' . formatAmountWithOriginal($data['vat_amount'], $data['line_label']) . ' | '; print '|
| 23 | '; print 'Total TVA déductible (ligne 19 à 2C) | '; print '' . formatAmount($data['vat_amount']) . ' | '; print '|
| D. ' . $langs->trans("CA3SectionD") . ' | '; print '|||
| ' . $langs->trans("CA3Line") . ' | '; print '' . $langs->trans("Description") . ' | '; print '' . $langs->trans("Amount") . ' | '; print '|
| ' . $line . ' | '; print '' . $description . ' | '; print '' . formatAmount($data['vat_amount']) . ' | '; print '|
| ' . $langs->trans("NoCA3Data") . ' | '; print '|||