Commit Graph

44 Commits

Author SHA1 Message Date
99683fab10 Pass user object to submitDeclaration method
- Add user parameter to submitDeclaration method signature
- Pass user object from view file to submitDeclaration method
- Remove redundant global user declaration
- Fixes null user parameter in bookkeeping create method
2025-10-08 21:51:31 +02:00
1aa471e85e Add testing mode for declaration submission
- Temporarily disable status validation to allow re-submission
- Add resetDeclarationStatus() method for testing
- Add reset button for submitted declarations
- Add French language strings for reset functionality
- Allows multiple submission attempts during testing
2025-10-08 21:38:57 +02:00
e34403d3e4 Add confirmation popup for declaration submission
- Add confirmSubmission() JavaScript function with modal dialog
- Include warning about irreversible accounting entry creation
- Add French language strings for confirmation dialog
- Ensure user gets proper confirmation before submission starts
2025-10-08 21:34:38 +02:00
e1253999d8 Implement automatic accounting entry creation for declaration submission
- Add comprehensive accounting integration with OD and bank journal entries
- Create configurable accounting entries toggle in setup
- Implement submission workflow with accounting entry creation
- Add proper error handling and validation
- Support VAT refund threshold logic for account selection
- Integrate with Dolibarr's AccountingBookkeeping class
- Add French language strings for new features
2025-10-08 21:30:33 +02:00
c8376a9ae6 Remove debugging code from validation process
- Removed all debug messages and console logs
- Simplified validation success message to use translation
- Cleaned up verbose debug output
- Production-ready code without debugging clutter
- Maintains error handling but removes debug verbosity
2025-10-06 18:24:01 +02:00
342d315066 Hide PDF export button for validated declarations
- PDF export button now only shows for draft declarations
- Validated declarations should use the PDF download link from the list
- Prevents confusion between export and download functionality
- Maintains clear separation between draft (export) and validated (download) workflows
2025-10-06 18:12:31 +02:00
6e9f620925 Remove separate detailed PDF export button
- Removed 'Export Detailed PDF' button from view page
- Removed export_pdf_detailed action handler
- Detailed export is now integrated into main 'Export PDF' button
- Simplifies UI by having single PDF export option
- Main export now includes both CA-3 form and detailed breakdown pages
2025-10-06 18:11:31 +02:00
ef40e60d6e Replace standard JavaScript confirm with Dolibarr-style modal for unvalidation
- Replaced onclick='return confirm()' with onclick='confirmUnvalidation()'
- Added confirmUnvalidation() JavaScript function with Dolibarr-style modal
- Added closeUnvalidationModal() and proceedUnvalidation() functions
- Modal has red warning styling to indicate destructive action
- Added UnvalidationConfirmationMessage and YesUnvalidate translations
- Modal includes escape key handler and proper styling
- Consistent with validation modal design and behavior
2025-10-06 17:56:47 +02:00
43ffed32bb Improve debug message visibility during validation
- Collect all debug messages in an array instead of showing them individually
- Display all debug info in a single message with line breaks
- Added checkmarks (✓) for success and X marks (✗) for failures
- Messages now persist longer and are easier to read
- All validation steps are now visible in one consolidated message
2025-10-06 17:35:51 +02:00
943f5e6659 Add detailed debugging for PDF generation during validation
- Added step-by-step debug messages to track validation process
- Added file existence verification in generateDetailedCA3PDF
- Added detailed error reporting for PDF generation failures
- Will help identify exactly where PDF generation is failing
- Debug messages will show: validation start, PDF generator load, PDF generation, file existence check
2025-10-06 17:34:16 +02:00
7a3cfd1237 Fix PDF generation and saving path issues
- Modified generateDetailedCA3PDF to save PDFs directly to /documents/declarationtva/YYYY/MM/
- Updated saveValidatedPDF to handle PDFs already in correct location
- Added debugging messages to show PDF generation success/failure
- Fixed path mismatch between PDF generation and document detection
- PDFs should now be properly generated and detected in declaration list
2025-10-06 17:32:08 +02:00
7b5aedee81 Replace JavaScript popup with professional Dolibarr-style modal
- Replaced basic JavaScript popup with professional modal dialog
- Added proper header with title and close button
- Added warning icon and better visual hierarchy
- Improved styling with Dolibarr color scheme
- Added escape key support for better UX
- Better button styling and layout
- More professional appearance matching Dolibarr interface
- Enhanced user experience with proper modal behavior
2025-10-06 17:11:58 +02:00
a95e0782b6 Add unvalidate functionality for testing purposes
- Added unvalidateDeclaration() method to DeclarationTVA class
- Added unvalidate action handler in declarationtva_view.php
- Added red 'Unvalidate' button for validated declarations
- Added confirmation dialog for unvalidate action
- Added French and English language strings
- Allows reverting validated declarations back to draft status
- Useful for testing validation process multiple times
2025-10-06 17:10:49 +02:00
105036adc2 Add comprehensive error handling for validation system
- Enhanced validateDeclaration() with detailed error messages
- Added database table existence checks
- Improved saveValidatedPDF() with try-catch and better error reporting
- Enhanced linkDocumentToDeclaration() with table validation
- Updated hasValidatedDocument() to handle missing tables gracefully
- Added detailed error display in view for debugging
- Better error messages for troubleshooting validation issues
2025-10-06 17:06:36 +02:00
f07f6a7c28 Implement declaration validation with confirmation dialog
Features:
- Add validation confirmation dialog (non-JavaScript popup)
- Remove recalculate button after validation
- Generate and save detailed PDF to Dolibarr documents
- Add document icons in declaration list
- Add status icons (checkmark for validated, edit for draft)
- Create documents linking table
- Add validation language strings (FR/EN)

Technical:
- Enhanced validateDeclaration() method with user tracking
- saveValidatedPDF() method for document storage
- hasValidatedDocument() method for icon display
- Custom confirmation dialog with CSS styling
- Database migration for documents table
- Status-based UI changes
2025-10-06 17:03:47 +02:00
9255a39d42 Version 2.1.0: Enhanced PDF Export with Detailed Breakdown Pages
- Added comprehensive PDF export combining CA-3 form with detailed breakdown pages
- Implemented pdftk-based PDF merging that preserves form fields
- Added support for new CA-3 lines (25, 26, 27, TD, 28, 32) with conditional visibility
- Fixed multi-select configuration saving issues
- Enhanced error handling and debugging for PDF generation
- Added French status translation for detailed PDFs
- Optimized page breaks to reduce paper usage
- Improved form field preservation during PDF merging

Technical improvements:
- Better error handling with comprehensive logging
- Modular PDF generation with fallback options
- Fixed pdftk filename conflicts
- Enhanced debugging capabilities
- Status translation without external dependencies
2025-10-06 16:47:02 +02:00
18e5a68b7b Major CA-3 VAT Declaration Module Updates
- Added comprehensive field naming documentation (CA3_FIELD_NAMING.md)
- Implemented PDFTK-based PDF form filling with FDF generation
- Added PDFTK installation guide for Linux/Mac/Windows
- Enhanced PDF generation with company data integration
- Added new CA-3 lines: F1, F2 (intracom acquisitions), E1-E6, F6-F8, line 18
- Updated section structure: merged Section C into Section B as sub-section
- Added lines 19, 20 to TVA DÉDUCTIBLE sub-section
- Updated all field descriptions to match official CA-3 form
- Improved visual hierarchy with dark blue section headers
- Enhanced calculation logic for VAT deductible amounts
- Added comprehensive language translations
- Updated database schema with new fields
- Fixed font settings to use Courier New 9pt for official documents
2025-10-03 13:22:43 +02:00
3116445f60 📄 Add PDF Generation System for CA-3 Declarations
NEW FEATURES:
 PDF Generation Class (DeclarationTVA_PDF)
 Template Management System (Official + Custom)
 PDF Export Button in Declaration View
 Template Upload/Reset in Configuration
 Official CA-3 Template Support (10963*30)

TECHNICAL IMPLEMENTATION:
- core/class/declarationtva_pdf.class.php: Complete PDF generation system
- templates/declarationtva/: Template storage directory
- Template management in admin/setup_mvp.php
- PDF export action in declarationtva_view.php
- Bilingual support (French/English)

TEMPLATE SYSTEM:
- Built-in official template (10963*30)
- Custom template upload capability
- Template validation and version management
- Fallback to official template if custom not available

PDF FEATURES:
- Professional CA-3 layout with all sections
- Company information and declaration details
- Complete CA-3 line data with amounts
- Totals and calculations display
- Downloadable PDF files

This adds professional PDF export functionality to the CA-3 declaration system!
2025-10-03 00:05:03 +02:00
97485b1d98 Fix background color override by Dolibarr CSS using !important
Fixed:
- Added !important to all background-color declarations to override Dolibarr's striped table CSS
- Applied to both <tr> and individual <td> elements for complete coverage
- This ensures the light red background (#ffe6e6) shows on calculated lines despite Dolibarr's pair/impair classes

The !important declaration forces the custom background color to take precedence over Dolibarr's default table styling.
2025-10-02 23:51:15 +02:00
b8615ceba0 Add light red background to calculated lines for better visual distinction
Enhanced:
- Line 16 (Sous-total TVA due): Light red background (#ffe6e6)
- Line 23 (Sous-total TVA déductible): Light red background (#ffe6e6)
- All D-section lines (25, 26, TD, 28, 29): Light red background (#ffe6e6)

This makes calculated/result lines stand out visually from mapped lines, improving user experience and making it clear which lines are automatically calculated vs manually configured.
2025-10-02 23:49:22 +02:00
d5f8039ef5 Remove dropdown functionality for D-section lines (calculated lines)
Fixed:
- Removed clickable links and dropdown panels for lines 25, 26, TD, 28, 29
- These lines are calculated automatically and have no account mappings
- Changed from clickable links to simple bold text for line numbers
- Removed dropdown rows and AJAX loading for D-section
- Kept dropdowns only for mapped lines (A1-A5, 08, 09, 9B, 17, 20, 21, 22)

This makes the interface cleaner and more logical since D-section lines are calculated, not mapped.
2025-10-02 23:46:35 +02:00
f39a7f140a Implement inline dropdown panels for CA-3 line details
Features:
- Replaced separate page with inline dropdown panels
- Click any CA-3 line code to expand/collapse account details
- AJAX loading of account breakdown data
- Professional styling matching Dolibarr UI
- JavaScript toggle functionality with loading states
- Account details table with:
  * Account codes and labels
  * Base amounts, VAT amounts, total amounts
  * Mapping types and totals
  * Summary information
- Removed separate line details page
- Added comprehensive translations for dropdown interface

This provides seamless inline access to account breakdowns without page navigation.
2025-10-02 23:21:09 +02:00
b0934c55d4 Implement clickable CA-3 lines with detailed account breakdown
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.
2025-10-02 23:17:56 +02:00
c73ca2ca48 Display rounded values without decimals and empty fields for zero
Improved:
- All amounts now display as whole numbers without decimals (e.g., 124 instead of 124.00)
- Zero values show as empty fields to avoid confusion
- Original amounts in brackets still show with 2 decimals for precision
- Cleaner display: 124 (123.67) or just 124 or empty field
- Added formatAmount() helper for simple amounts
- Updated formatAmountWithOriginal() to handle zero values
- Much cleaner and less confusing for users
2025-10-02 22:59:36 +02:00
ce88aa69c1 Remove original amounts from subtotals and Section D
Fixed:
- Line 16: Subtotal TVA due - no original amounts (just user reference)
- Line 23: Subtotal TVA déductible - no original amounts (just user reference)
- Section D lines (25, 26, TD, 28, 29): No original amounts (calculated from rounded values)
- Only actual data lines (A1-A5, 08, 09, 9B, 17, 20-22) show original amounts in brackets
- Section D uses rounded values for calculations as required
2025-10-02 22:57:11 +02:00
06b868d71e Add original amounts formatting to lines 16, 17, and 23
Fixed:
- Line 16: Subtotal TVA due (08 + 09 + 9B) now shows original amounts in brackets
- Line 17: Manual entry line now shows original amounts in brackets
- Line 23: Subtotal TVA déductible (20 + 21 + 22) now shows original amounts in brackets
- All subtotal and manual entry lines now have consistent formatting
- Original amounts visible for transparency in all calculated lines
2025-10-02 22:54:58 +02:00
b3f2ac492f Display original amounts in brackets next to rounded amounts
Fixed:
- Store original amounts in line_label with special format
- Parse original amounts in view page helper function
- Display original amounts in brackets: 124 (123.67)
- Handle both base and VAT amounts separately
- Original amounts now visible in amount columns
- Clear transparency for rounding decisions
2025-10-02 22:53:20 +02:00
03e6bafa53 Remove totals from page header
Removed:
- TotalVATCollected from page header
- TotalVATDeductible from page header
- NetVATDue from page header
- VATCredit from page header

The totals are now only shown in the CA-3 table sections where they belong
2025-10-02 22:48:51 +02:00
893de77afc Fix line 25 and TD logic for clear payment/receipt separation
Fixed:
- Line 25: Only shows value if net_vat_due < 0 (VAT credit - we receive money)
- Line TD: Only shows value if net_vat_due > 0 (VAT due - we pay money)
- Clear separation between payment (TD) and receipt (25) scenarios
- Line TD description: 'TVA due (montant à payer)'
- This clearly separates when we need to pay vs receive VAT
2025-10-02 22:47:16 +02:00
7933d3f649 Add line TD for absolute VAT due calculation
Fixed:
- Line 25: TVA brute due (Total VAT collected) - always positive
- Line TD: TVA due (absolute value) - never negative, shows abs(net_vat_due)
- Line TD appears between lines 26 and 28 in Section D
- Line TD shows 'TVA due (valeur absolue)' as description
- This ensures VAT due is never negative, even with VAT credits
2025-10-02 22:44:35 +02:00
39a2414d63 Add line 23 subtotal for Section C
Added:
- Line 23: Subtotal of lines 20, 21, 22 (for user reference)
- calculateLine23() method that sums VAT amounts from lines 20, 21, 22
- Line 23 display in Section C between lines 22 and Section D
- Line 23 shows as 'Sous-total TVA déductible (20 + 21 + 22)' with bold formatting
- Provides subtotal for Section C just like line 16 for Section B
2025-10-02 22:35:58 +02:00
f53485eb9a Add line 16 display in Section B
Fixed:
- Line 16 now appears in Section B between lines 9B and 17
- Line 16 shows as 'Sous-total TVA due (08 + 09 + 9B)' with bold formatting
- Line 16 displays the calculated subtotal amount
- Proper positioning in the CA-3 form structure
2025-10-02 22:34:09 +02:00
8524ff24ae Remove extra header and right-align value column titles
Fixed:
- Removed extra header line above section A
- Right-aligned all value column titles (Amount, Base Amount, VAT Amount)
- Professional look with consistent alignment
- Table now starts directly with section A header
2025-10-02 21:53:48 +02:00
3d5e9b1ca8 Fix table alignment with proper column spanning
Fixed:
- Description column now spans 2 columns (colspan='2') for normal rows
- All section headers span 4 columns (colspan='4')
- Table headers properly aligned with data rows
- Lines 08, 09, 9B: 4 columns (Line | Description | Base HT | VAT)
- All other lines: 3 columns (Line | Description spanning 2 | Amount)
- Table should now be properly aligned and readable
2025-10-02 21:51:28 +02:00
ae7768dd7b Revert to 3-column layout with special base+VAT columns for 08, 09, 9B
Reverted:
- Main table back to 3 columns (Line, Description, Amount)
- Sections A, C, D use normal 3-column layout
- Only lines 08, 09, 9B have special 4-column layout (Line, Description, Base HT, VAT)
- Added special header 'Base HT et TVA par taux' for these lines
- Line 17 uses normal 3-column layout
- Added language translations for new header
2025-10-02 21:48:44 +02:00
337e82b30b Add Base and VAT amounts for fields 08, 09, 9B
Enhanced:
- Updated CA-3 line definitions for 08, 09, 9B to show both base and VAT
- Changed type from 'vat' to 'base_vat' for these fields
- Updated view table to show 5 columns: Line, Description, Base HT, VAT, Total
- Added language translations for new columns
- Fields 08, 09, 9B now display both base amounts and VAT amounts
- Enhanced debugging to show final amounts for each line
2025-10-02 21:44:30 +02:00
6723375a16 Restore CA-3 line descriptions in declaration view
Fixed:
- Added CA-3 line definitions lookup
- Use proper descriptions from configuration
- Fallback to database line_label if definition missing
- All CA-3 lines now show proper descriptions:
  A1: Montant hors TVA des opérations imposables
  A2: Opérations imposables mais ne relevant pas du CA courant
  etc.
2025-10-02 21:25:41 +02:00
877a66057d Restore complete CA-3 table structure with sections
CA-3 Table Structure:
- Section A: Opérations imposables (A1, A2, A3, A4, A5)
- Section B: TVA due (08, 09, 9B, 17)
- Section C: TVA déductible (20, 21, 22)
- Section D: Résultat (25, 26, 28, 29)
- Proper section headers with bold formatting
- All 17 CA-3 lines as per configuration
- Real calculated amounts from database
- Bilingual section titles
2025-10-02 20:54:52 +02:00
213ab61bdd Restore complete declaration view layout with totals
Enhanced Declaration View:
- Restored all declaration fields (number, name, period, status, created date)
- Added totals section with VAT collected, deductible, net due, and credit
- Bold formatting for totals to highlight important amounts
- Added translations for all new fields
- Complete layout with all necessary information
2025-10-02 20:52:59 +02:00
b9725755a2 Fix object initialization order in declaration view
Fixed:
- Moved object initialization before action processing
- Prevents 'Call to a member function on null' error
- recalculateCA3Amounts() now works properly
- Objects are available when action handlers run
2025-10-02 20:51:34 +02:00
14362712a1 Wire recalculate button to show real calculated amounts
Recalculate Button Integration:
- Replaced placeholder CA-3 data with real database queries
- getCA3Lines() now fetches actual calculated amounts
- Shows 'No CA-3 data' message when no calculations exist
- Displays real VAT amounts from database after recalculation
- Added translations for 'No CA-3 data' message

Now the recalculate button will:
1. Trigger calculation engine
2. Query accounting data
3. Display real calculated amounts
4. Show debugging info in error logs
2025-10-02 20:50:12 +02:00
ca363f60e9 Update declaration view page with declaration dates and fix creation date
View Page Updates:
- Use declaration's own start_date and end_date instead of period dates
- Show dates in Period field: 'Start Date - End Date'
- Remove separate DateRange line (redundant)
- Fix created_date property in fetch() method
- Cleaner, more accurate display of declaration information
2025-10-02 20:46:43 +02:00
56ed838601 Implement CA-3 calculation system and recalculate functionality
Calculation System:
- Added getAccountMappings() to retrieve PCG account mappings
- Added createCA3Line() to create CA-3 line records
- Added updateDeclarationTotals() to update declaration totals
- Added recalculateCA3Amounts() for recalculation functionality
- Enhanced getAccountAmounts() to query Dolibarr accounting entries

Recalculate Button:
- Added recalculate button to declaration view page
- Added action handling for recalculate functionality
- Added success/error messages for recalculation
- Added translations for recalculate functionality

The calculation system now:
- Queries actual accounting data from Dolibarr
- Creates detailed CA-3 line records
- Updates declaration totals automatically
- Allows manual recalculation of amounts
2025-10-02 20:42:29 +02:00
c61a964f14 Create declaration creation and view pages
New Pages Added:
- declarationtva_create.php: Complete declaration creation form
- declarationtva_view.php: Declaration details and CA-3 amounts display

Features Implemented:
- Period selection for new declarations
- Declaration naming with helpful examples
- Optional date range override
- Complete CA-3 form structure display
- Status-based action buttons (Validate/Submit)
- Proper error handling and success messages
- Full bilingual support (English/French)

Create Page Features:
- Period dropdown with date ranges
- Declaration name field with help text
- Optional date override
- Configuration reminder with link to setup

View Page Features:
- Complete declaration details
- CA-3 amounts table with all 16 lines
- Status-based actions
- Navigation back to main list

The module now has a complete declaration workflow!
2025-10-02 18:09:04 +02:00