Commit Graph

355 Commits

Author SHA1 Message Date
6f742bda84 Fix reversed account selection logic
- Debit difference: now uses 4455100 credit (not 4456700)
- Credit difference: now uses 4456700 debit (not 4455100)
- Rounding accounts also corrected: 758000 for debit diff, 658000 for credit diff
- Should now match user examples correctly
2025-10-07 14:43:21 +02:00
43e4072a67 Fix rounding entry side for proper balancing
- Debit difference: 758000 credit (not debit) for rounding
- Credit difference: 658000 debit for rounding
- Now matches user examples where debit difference uses 758000 credit
- Should show correct rounding entries in journal table
2025-10-07 14:16:24 +02:00
ad4fbc17a5 Fix difference calculation to match user examples
- Changed difference calculation from (debits - credits) to (credits - debits)
- Now matches user examples where credit difference uses 4455100
- Should eliminate the unwanted 4456700 line in credit scenarios
- 4455100 and 4456700 will never appear together now
2025-10-07 14:12:38 +02:00
34b9864a4e Fix balancing logic to create only one main entry
- Removed duplicate 4455100 entry creation
- Now creates either 4455100 (credit) OR 4456700 (debit), not both
- Added debug logging for total debits/credits to trace calculation
- Should eliminate the unwanted 4455100 line in journal table
2025-10-07 14:07:29 +02:00
240360a393 Fix balancing logic according to user specifications
- Calculate difference between debits and credits
- Main entry: rounded amount on 4455100 (credit) or 4456700 (debit)
- Rounding entry: real difference on 758000 (credit diff) or 658000 (debit diff)
- Simplified logic by removing TD line dependency
- Both VAT debit and credit scenarios now work correctly
2025-10-07 13:21:03 +02:00
ffe8a960e2 Fix VAT credit scenario balancing logic
- Main balancing entry now uses rounded amount (formatAmount) for proper accounting
- Rounding difference goes to 658000/758000 with real value (formatAmountReal)
- Fixed fallback logic to handle both VAT debit and credit scenarios correctly
- VAT credit: rounded amount on 4456700, real difference on 658000
- VAT debit: rounded amount on 4455100, real difference on 758000
2025-10-07 12:44:19 +02:00
ff314d043e Fix rounding calculation to use real values instead of rounded
- Added debugging to TD line query to see why VAT amount is 0
- Fixed fallback logic to use formatAmountReal() instead of formatAmount()
- When TD line has 0 VAT amount, now uses real difference (0.90) instead of rounded (1.00)
- Added logging to track TD line query and results
- Should now show 0.90 instead of 1.00 in rounding entry
2025-10-07 12:35:19 +02:00
c7cfd3e52d Add debugging to rounding calculation to identify why 1.00 instead of 0.90
- Added error_log statements to track total difference and VAT TD amount
- Added logging for remaining difference calculation
- Will help identify why rounding entry shows 1.00 instead of 0.90
- Check error logs after generating PDF to see calculation values
2025-10-07 12:33:05 +02:00
e4a940a1b4 Clarify that rounding entries use real values (not rounded)
- Rounding entries (658000/758000) already use formatAmountReal() for real values
- Added comment to clarify this behavior
- Main balancing entry uses rounded VAT amount from TD line
- Rounding entry uses real difference with decimals
- Ensures proper accounting precision for rounding differences
2025-10-07 12:31:24 +02:00
8054e03026 Fix balancing calculation to use VAT amount from line TD
- Main balancing entry now uses VAT amount from line TD (69 in example)
- Remaining difference (0.90) goes to rounding entry on 758000
- Added getVATAmountFromLineTD method to fetch VAT amount from TD line
- Proper accounting: 69.00 credit on 4455100 + 0.90 credit on 758000
- Fallback to original logic if no TD line found
2025-10-07 12:27:28 +02:00
295f264090 Fix balancing structure to create correct journal entries
- Combined balancing and rounding logic into single method
- Main balancing entry uses correct account: 4456700 for debit, 4455100 for credit
- Separate rounding entry uses 658000/758000 for rounding differences
- Eliminates duplicate entries and ensures proper accounting structure
- Example: 69.00 credit on 4455100 + 0.90 on 758000 instead of two separate lines
2025-10-07 12:14:46 +02:00
4fd0e13198 Clarify balancing entry account selection logic
- Debit balancing entries use 4456700 (TVA à payer)
- Credit balancing entries use 4455100 (TVA à recevoir)
- Account selection based on whether the balancing entry is debit or credit
- Proper French VAT accounting for balancing entries
2025-10-07 12:07:40 +02:00
ea624ba3cb Fix balancing entry account codes for proper VAT accounting
- If difference < 0 (more credits): Use 4456700 (TVA à payer) on debit side
- If difference > 0 (more debits): Use 4455100 (TVA à recevoir) on credit side
- Each account gets its real label from chart of accounts
- Proper French VAT accounting logic for balancing entries
2025-10-07 12:03:31 +02:00
009ad50d65 Improve getAccountLabel with multiple query approaches to find account names
- Added multiple query strategies to handle different database configurations
- Tries with entity filter, without entity filter, and without active filter
- Enhanced debugging to show which query succeeds
- Based on successful patterns from other methods in the codebase
- Should now properly retrieve account names from Dolibarr chart of accounts
2025-10-07 11:59:43 +02:00
61bc28597b Add debugging to getAccountLabel method to diagnose account name issue
- Added error_log statements to track account lookup process
- Removed entity filtering temporarily to test if that's the issue
- Will help identify why account names are not showing from chart of accounts
- Check error logs after generating PDF to see what's happening
2025-10-07 11:59:00 +02:00
8336fff139 Fix getAccountLabel to fetch real account names from Dolibarr chart of accounts
- Removed hardcoded fallback labels that were made up
- Now properly queries accounting_account table for real account labels
- Uses entity filtering and active account filtering
- Falls back to generic 'Compte XXXX' only if account not found
- Journal table now shows actual account names from your chart of accounts
2025-10-07 11:56:59 +02:00
4f82e24e29 Improve balancing entry with real account descriptions and separate rounding
- Added getAccountLabel method to fetch real account descriptions from chart of accounts
- Balancing entry now uses real account description for 4456700
- Balancing amounts are now rounded (no decimals)
- Added getBalancingRoundingEntry method for separate rounding line
- Rounding difference goes to 658000 (debit) or 758000 (credit) with real descriptions
- Improved double-entry bookkeeping with proper account labels and rounding
2025-10-07 11:49:40 +02:00
1a9e610823 Add balancing entry to journal table to ensure debits equal credits
- Added getBalancingEntry method to calculate balancing entry
- Sums all debit amounts and subtracts all credit amounts
- If result < 0: adds debit to 4456700 account
- If result > 0: adds credit to 4456700 account
- Added parseAmount helper method to convert formatted amounts back to floats
- Journal table now automatically balances with calculated entry
- Ensures proper double-entry bookkeeping in OD journal
2025-10-07 11:44:52 +02:00
9a14ab2318 Use declaration_name instead of declaration_number for journal entry labels
- Changed all journal entry labels to use declaration_name field
- Updated getLine8VATAccounts to use declaration_name
- Updated getLine20Accounts to use declaration_name
- Updated getVATResultEntry to use declaration_name
- Updated getRoundingEntry to use declaration_name
- Journal entries now show user-defined names like 'MAI 2025', 'JUIN 2025'
2025-10-07 11:38:28 +02:00
4fc50a32fa Use declaration name as libellé écriture in journal table
- Changed entry labels to use declaration number instead of generic labels
- Updated getLine8VATAccounts to use declaration name
- Updated getLine20Accounts to use declaration name
- Updated getVATResultEntry to use declaration name
- Updated getRoundingEntry to use declaration name
- All journal entries now show the declaration name as the entry label
2025-10-07 11:37:05 +02:00
ee62f2ea13 Filter journal table to show only 445 accounts with real values
- Added filter to show only 445 accounts (VAT accounts) in journal table
- Created formatAmountReal method to display amounts with decimals
- Updated getLine8VATAccounts to filter for 445 accounts and use real values
- Updated getLine20Accounts to filter for 445 accounts and use real values
- Updated VAT result and rounding entries to use real values
- Journal table now shows only VAT accounts with precise amounts
2025-10-07 11:33:17 +02:00
bc953bf5a6 Fix missing account numbers in journal table
- Changed account_number to account_code in getLine8VATAccounts method
- Changed account_number to account_code in getLine20Accounts method
- Account numbers should now display correctly in the journal entry table
- Fixes issue where account codes were showing as empty in the PDF
2025-10-07 11:30:58 +02:00
2debac1ef3 Reorder PDF pages: journal table on page 1, line details on page 2
- Moved journal entry table to page 1 after declaration info
- Line details (Détail de la ligne A1) now start on page 2
- Removed duplicate AddPage() call from addJournalEntryTable
- Added explicit AddPage() call in addDetailPages for page 2 start
- Improved PDF structure for better readability
2025-10-07 11:28:56 +02:00
5256d21389 Add journal entry table to PDF with OD journal entries
- Added addJournalEntryTable method to generate journal entries table
- Table includes columns: Code compte, Libellé compte, Libellé écriture, Débit, Crédit
- Extracts VAT accounts from line 8 (debit side, non-zero only)
- Extracts accounts from line 20 (credit side, non-zero only)
- Adds VAT result on account 4456700 (debit if < 0, credit if >= 0)
- Adds rounding difference on 658000 (if < 0) or 758000 (if > 0)
- Journal table starts on page 2 of the detailed PDF
- Uses proper French accounting terminology and formatting
2025-10-07 11:26:38 +02:00
1aa6cbc705 Bump version to 2.2.0
- Updated module version from 2.1.0 to 2.2.0
- Added comprehensive changelog for version 2.2.0
- Documents all new features: validation workflow, PDF management, secure downloads
- Documents technical improvements: database migration, error handling, UI cleanup
- Documents bug fixes: token validation, PDF detection, path resolution, debug cleanup
- Ready for production deployment
2025-10-06 18:25:14 +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
d357b6d314 Remove non-working submit button from declaration list
- Removed submit button from declaration list actions
- Submit functionality should be handled from detailed view page
- Keeps only working actions: Delete (draft), View (all)
- Simplifies the list interface and removes broken functionality
2025-10-06 18:15:50 +02:00
bc5c9e9fb6 Remove non-working validate button from declaration list
- Removed validate button from declaration list actions
- Validation should only be done from the detailed view page
- Keeps only working actions: Delete (draft), Submit (validated), View
- Simplifies the list interface and avoids broken functionality
2025-10-06 18:15:13 +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
64f5278e2b Simplify token validation in download handler
- Changed from checkToken() to simple token existence check
- checkToken() does not exist in this Dolibarr version
- Now uses same pattern as other files in the module: if (!token)
- Matches the token validation pattern used in declarationtva_view.php
- Should resolve the PHP Fatal error
2025-10-06 18:07:38 +02:00
baecaa3fd6 Fix token validation function in download handler
- Changed from dol_verifyToken() to checkToken()
- dol_verifyToken() doesn't exist in this Dolibarr version
- checkToken() is the correct function for token validation
- Should resolve the PHP Fatal error
2025-10-06 18:06:46 +02:00
2a902d7925 Add secure PDF download handler to bypass Dolibarr file access restrictions
- Created download_pdf.php as secure download handler
- Handles PDF downloads through Dolibarr's security system
- Validates user permissions and declaration status
- Uses proper token validation for security
- Updated declaration list to use download handler instead of direct file links
- Bypasses Dolibarr's file access restrictions
- Provides secure, controlled access to PDF files
2025-10-06 18:06:05 +02:00
00ecb72791 Fix URL construction to add /documents back for download links
- Added /documents back to the URL construction in declaration list
- File is saved in /var/lib/dolibarr/declarationtva/validated/ (no /documents)
- URL should be /dolibarr/documents/declarationtva/validated/ (with /documents)
- This ensures the download links work correctly
- File path and URL path are now properly separated
2025-10-06 18:02:39 +02:00
15d4fb34b6 Fix PDF file paths to remove duplicate /documents
- Changed PDF generation path from /documents/declarationtva/validated/ to /declarationtva/validated/
- Updated hasValidatedDocument() to look in /declarationtva/validated/
- Updated getValidatedPDFPath() to look in /declarationtva/validated/
- This removes the duplicate /documents in the file path
- Files will now be saved in /var/lib/dolibarr/declarationtva/validated/
- URLs will be /dolibarr/documents/declarationtva/validated/ (single /documents)
2025-10-06 18:01:37 +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
c1aa501898 Fix PDF generation to include CA-3 form with details
- Changed generateDetailedCA3PDF to call generateCA3PDF instead of generateDetailedPDF
- generateCA3PDF creates complete PDF with CA-3 form + detailed breakdown pages
- generateDetailedPDF only creates detailed pages without the CA-3 form
- Now generates complete PDF with both CA-3 form and account details
- Copies generated PDF to correct validated directory location
2025-10-06 17:54:53 +02:00
d6de5c6c0b Fix PDF file paths to use /documents/declarationtva/validated/ directory
- Updated generateDetailedCA3PDF to save PDFs in /documents/declarationtva/validated/
- Updated hasValidatedDocument to look in /documents/declarationtva/validated/
- Updated getValidatedPDFPath to look in /documents/declarationtva/validated/
- Removed year/month directory structure
- Should now match the actual file location where PDFs are saved
- URLs should now work correctly
2025-10-06 17:52:22 +02:00
519f5e3be2 Revert PDF URL path fix - keep original /documents/documents/ structure
- Removed the str_replace that was removing /documents/documents/
- The file is actually saved with /documents/documents/ in the path
- URL should match the actual file location
- Should generate URLs like /dolibarr/documents/documents/declarationtva/
2025-10-06 17:50:20 +02:00
4f3ad7fb8a Fix PDF download URL by removing extra /documents path
- Added str_replace to remove /documents/documents/ from path
- Changes /documents/documents/declarationtva/ to /documents/declarationtva/
- Should now generate correct URLs that match actual file locations
- File is at /var/lib/dolibarr/documents/documents/declarationtva/
- URL should be /dolibarr/documents/declarationtva/
2025-10-06 17:48:39 +02:00
ea891e5c31 Fix PDF download URL path construction
- Removed duplicate /documents from URL path
- Changed from DOL_URL_ROOT + /documents + relative_path
- To DOL_URL_ROOT + relative_path
- Should now generate correct URLs like /dolibarr/documents/declarationtva/
- Instead of incorrect /dolibarr/documents/documents/declarationtva/
2025-10-06 17:46:16 +02:00
edfab45d9e Fix PDF icon display issue in declaration list
- Changed from fa-file-pdf-o to fa-file-pdf (more common icon)
- Added inline CSS styling for better visibility
- Added 'PDF' text as fallback if icon doesn't display
- Used red color (#dc3545) for PDF icon to make it stand out
- Added font-weight: bold for better visibility
- Should now show visible PDF download links in declaration list
2025-10-06 17:45:18 +02:00
b305c3d90b Remove debug logging and clean up code
- Removed all error_log debug statements from production code
- Cleaned up hasValidatedDocument method
- Cleaned up declaration list processing
- Code is now production-ready
- PDF detection and generation are working correctly
2025-10-06 17:43:25 +02:00
db0432b502 Add debugging to declaration list query processing
- Added error_log to track each declaration being processed in the list
- Shows declaration ID, status, and number for each row
- Will help identify if declarations are being processed correctly
- Should show what status each declaration has in the list query
2025-10-06 17:41:51 +02:00
6fe9141002 Add debugging to declaration list document detection
- Added error_log statements to track document detection in declaration list
- Logs declaration ID, status, has document result, PDF path, and download URL
- Will help identify why PDF icons are not showing despite successful detection
- Debug info will show what's happening in the list display logic
2025-10-06 17:39:43 +02:00
29f9462f47 Add detailed debugging to hasValidatedDocument method
- Added comprehensive error_log statements to track PDF detection
- Logs declaration ID, number, directory paths, and search patterns
- Shows all PDF files found in the directory
- Will help identify why PDF detection is failing
- Debug info will appear in PHP error logs
2025-10-06 17:38:09 +02:00
b90d5e9199 Fix PDF file pattern matching in document detection
- Updated hasValidatedDocument() to use flexible file pattern matching
- Updated getValidatedPDFPath() with same flexible pattern
- First tries exact pattern: CA3_[declaration_number]_*.pdf
- Falls back to flexible pattern: CA3_*[declaration_number]*.pdf
- Should now detect PDFs with complex filenames like CA3_CA3-2025-05-20251002184011_2025-10-06.pdf
- Declaration list should now show green PDF icons for validated declarations
2025-10-06 17:37:09 +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