From e58458efc6b18cb1ca3c4ef45b87b9b451edcb0a Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 8 Mar 2026 22:27:57 +0100 Subject: [PATCH] Module BlockedLog can also now be used by tax auditors. --- .../blockedlog/admin/blockedlog_archives.php | 85 +++++++++++++++++-- htdocs/blockedlog/admin/blockedlog_list.php | 4 +- htdocs/blockedlog/admin/documentation.php | 8 +- htdocs/blockedlog/admin/registration.php | 2 +- htdocs/blockedlog/lib/blockedlog.lib.php | 18 +++- 5 files changed, 99 insertions(+), 18 deletions(-) diff --git a/htdocs/blockedlog/admin/blockedlog_archives.php b/htdocs/blockedlog/admin/blockedlog_archives.php index bb9488cfff2..f030c26ae8f 100644 --- a/htdocs/blockedlog/admin/blockedlog_archives.php +++ b/htdocs/blockedlog/admin/blockedlog_archives.php @@ -115,7 +115,7 @@ $block_static = new BlockedLog($db); $block_static->loadTrackedEvents(); // Access Control -if ((!$user->admin && !$user->hasRight('blockedlog', 'read')) || !isModEnabled('blockedlog')) { +if (((!$user->admin && !$user->hasRight('blockedlog', 'read')) || !isModEnabled('blockedlog')) && !userIsTaxAuditor()) { accessforbidden(); } @@ -679,7 +679,7 @@ if ($withtab) { $morehtmlcenter = ''; $registrationnumber = getHashUniqueIdOfRegistration(); -if (!getDolGlobalString("BLOCKEDLOG_FOR_TAX_AUDITOR")) { +if (!userIsTaxAuditor()) { $texttop = ''.$langs->trans("RegistrationNumber").': '.dol_trunc($registrationnumber, 10).''; if (!isRegistrationDataSavedAndPushed()) { $texttop = ''; @@ -696,7 +696,7 @@ print dol_get_fiche_head($head, 'archives', '', -1); //print '

'; print '
'; -if (!getDolGlobalString("BLOCKEDLOG_FOR_TAX_AUDITOR")) { +if (!userIsTaxAuditor()) { print $langs->trans("ArchivesDesc")."
"; } else { print $langs->trans("ArchivesAuditorDesc")."
"; @@ -752,10 +752,10 @@ if ($action == 'check' || $action == 'checkconfirmed') { print $langs->trans("FileHasBeenEncodedWithASecretKeyStartingWith").' : '.$regnumber.'...
'; - if (preg_match('/^'.$regnumber.'/', $secretkey) && !getDolGlobalString("BLOCKEDLOG_FOR_TAX_AUDITOR")) { + if (preg_match('/^'.$regnumber.'/', $secretkey) && !userIsTaxAuditor()) { print 'As this matches the 10 first characters of the full registration number of this instance, we will use the full registration number to control the archive file...'; } else { - if (!getDolGlobalString("BLOCKEDLOG_FOR_TAX_AUDITOR")) { + if (!userIsTaxAuditor()) { print 'This archive file was not generated by this instance.'; print 'The control of authenticity is possible only if you know the full registration number.'; $inputregistrationnumber = ''; @@ -793,6 +793,13 @@ if ($action == 'check' || $action == 'checkconfirmed') { $nbLinesModifiedInExportButKo = 0; $nbLinesModifiedBeforeExport = 0; + $amounthtlifetime = array(); + $amountvatlifetime = array(); + $amountttclifetime = array(); + $amounthtlifetime['BILL_VALIDATE'] = $amounthtlifetime['PAYMENT_CUSTOMER'] = null; + $amountvatlifetime['BILL_VALIDATE'] = $amountvatlifetime['PAYMENT_CUSTOMER'] = null; + $amountttclifetime['BILL_VALIDATE'] = $amountttclifetime['PAYMENT_CUSTOMER'] = null; + $handle = fopen($fullpath, "r"); if ($handle) { $numline = 0; @@ -931,9 +938,33 @@ if ($action == 'check' || $action == 'checkconfirmed') { } } + // Test if line is a summary line if (preg_match('/^SUMMARY /', (string) $line[0])) { // We are on a line for summary information $lineanalyzed = 1; + if (preg_match('/^SUMMARY TURNOVER BILLED/', (string) $line[0])) { + // Do nothing, we recalculate amount from previous lines + } + if (preg_match('/^SUMMARY TURNOVER PAID/', (string) $line[0])) { + // Do nothing, we recalculate amount from previous lines + } + if (preg_match('/^SUMMARY LIFETIME BILLED/', (string) $line[0])) { + // We load data from line + $amountstring = (string) $line[0]; + if (preg_match('/^SUMMARY LIFETIME BILLED[^\d]*\s:\s([\d\.]+)\s[^\d]+\s([\d\.]+)\s[^\d]+\s([\d\.]+)\s[^\d]+/', $amountstring, $reg)) { + $amounthtlifetime['BILL_VALIDATE'] = (float) $reg[1]; + $amountvatlifetime['BILL_VALIDATE'] = (float) $reg[2]; + $amountttclifetime['BILL_VALIDATE'] = (float) $reg[3]; + } + } + if (preg_match('/^SUMMARY LIFETIME PAID/', (string) $line[0])) { + $amountstring = (string) $line[0]; + if (preg_match('/^SUMMARY LIFETIME PAID[^\d]*\s:\s([\d\.]+)/', $amountstring, $reg)) { + $amounthtlifetime['PAYMENT_CUSTOMER'] = (float) $reg[1]; + $amountvatlifetime['PAYMENT_CUSTOMER'] = 0.0; + $amountttclifetime['PAYMENT_CUSTOMER'] = (float) $reg[1]; + } + } } if (preg_match('/END - ([a-z0-9_]+)=([a-z0-9]+) - ([a-z0-9_]+)=([a-z0-9]+)$/', (string) $line[0], $reg)) { @@ -991,7 +1022,7 @@ if ($action == 'check' || $action == 'checkconfirmed') { } print '

'; - if (!getDolGlobalString("BLOCKEDLOG_FOR_TAX_AUDITOR")) { + if (!userIsTaxAuditor()) { if ($nbLinesModifiedInExportButKo) { print img_picto('', 'cross', 'class="error valignmiddle pictofixedwidth"'); print ''.$langs->trans("nbLinesModifiedInExportButKo").': '; @@ -1049,6 +1080,44 @@ if ($action == 'check' || $action == 'checkconfirmed') { print '
'; } + // Now print the value for lifetime amounts. + $arraykeys = array('BILL_VALIDATE', 'PAYMENT_CUSTOMER'); + foreach ($arraykeys as $key) { + if (is_null($amounthtlifetime[$key])) { // If not entry found, we discard + continue; + } + $totalhttoshow = $amounthtlifetime[$key]; + $totalvattoshow = $amountvatlifetime[$key]; + $totaltoshow = $amountttclifetime[$key]; + + print ''.dolPrintHTML($langs->trans("LifetimeAmountShort").' '.$langs->trans('log'.$key)).''; + if ($key == 'BILL_VALIDATE') { + print ' ('.$langs->trans("Turnover").')'; + } elseif ($key == 'PAYMENT_CUSTOMER') { + print ' ('.$langs->trans("TurnoverCollected").')'; + } + print ': '; + + if ($key == 'PAYMENT_CUSTOMER') { + print ''.price($totaltoshow, 0, $langs, 1, -1, -1, getDolCurrency()).''; + } else { + print $langs->trans("HT").': '; + print ''.price($totalhttoshow, 0, $langs, 1, -1, -1, getDolCurrency()).''; + + print ' - '; + + print $langs->trans("VAT").': '; + print ''.price($totalvattoshow, 0, $langs, 1, -1, -1, getDolCurrency()).''; + + print ' - '; + + print $langs->trans("TTC").': '; + print ''.price($totaltoshow, 0, $langs, 1, -1, -1, getDolCurrency()).''; + } + print '
'; + } + + print '
'; $text = $langs->trans("IfIntegrityAuthenticityIsOkYouCanGetdetailByOpeningTheFile"); @@ -1066,7 +1135,7 @@ if ($action == 'check' || $action == 'checkconfirmed') { if ($action != 'check' && $action != 'checkconfirmed') { $htmltext = ''; - if (!getDolGlobalString("BLOCKEDLOG_FOR_TAX_AUDITOR")) { + if (!userIsTaxAuditor()) { $htmltext .= $langs->trans("UnalterableLogTool2", $langs->transnoentities("Archives"))."
"; if ($mysoc->country_code == 'FR') { $htmltext .= '
'.$langs->trans("UnalterableLogTool1FR").'
'; @@ -1145,7 +1214,7 @@ if ($action != 'check' && $action != 'checkconfirmed') { } - if (!getDolGlobalString("BLOCKEDLOG_FOR_TAX_AUDITOR")) { + if (!userIsTaxAuditor()) { print '
'; print ''; print ''; diff --git a/htdocs/blockedlog/admin/blockedlog_list.php b/htdocs/blockedlog/admin/blockedlog_list.php index eeafa364243..21162a1e919 100644 --- a/htdocs/blockedlog/admin/blockedlog_list.php +++ b/htdocs/blockedlog/admin/blockedlog_list.php @@ -157,7 +157,7 @@ if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x' $search_array_options = array(); } -if (getDolGlobalString("BLOCKEDLOG_FOR_TAX_AUDITOR")) { +if (userIsTaxAuditor()) { // When this hidden option is on, open another tab as the tab by default header("Location: ".DOL_URL_ROOT."/blockedlog/admin/blockedlog_archives.php"); exit; @@ -199,7 +199,7 @@ if (GETPOST('withtab', 'alpha')) { $morehtmlcenter = ''; $registrationnumber = getHashUniqueIdOfRegistration(); -if (!getDolGlobalString("BLOCKEDLOG_FOR_TAX_AUDITOR")) { +if (userIsTaxAuditor()) { $texttop = ''.$langs->trans("RegistrationNumber").': '.dol_trunc($registrationnumber, 10).''; if (!isRegistrationDataSavedAndPushed()) { $texttop = ''; diff --git a/htdocs/blockedlog/admin/documentation.php b/htdocs/blockedlog/admin/documentation.php index cb1699f0d1a..731b5f81eda 100644 --- a/htdocs/blockedlog/admin/documentation.php +++ b/htdocs/blockedlog/admin/documentation.php @@ -54,7 +54,7 @@ $origin = GETPOST('origin'); $mode = GETPOST('mode'); // Access Control -if (!$user->admin) { +if (!$user->admin && !userIsTaxAuditor()) { accessforbidden(); } @@ -95,7 +95,7 @@ if (GETPOST('withtab', 'alpha')) { $morehtmlcenter = ''; $registrationnumber = getHashUniqueIdOfRegistration(); -if (!getDolGlobalString("BLOCKEDLOG_FOR_TAX_AUDITOR")) { +if (!userIsTaxAuditor()) { $texttop = ''.$langs->trans("RegistrationNumber").': '.dol_trunc($registrationnumber, 10).''; if ((!isRegistrationDataSavedAndPushed() || !isModEnabled('blockedlog')) && $mode != "forceregistration") { $texttop = ''; @@ -111,7 +111,7 @@ if ($withtab) { print '
'; } -if (!getDolGlobalString("BLOCKEDLOG_FOR_TAX_AUDITOR")) { +if (!userIsTaxAuditor()) { print ''.$langs->trans("BlockedLogDesc")."
\n"; } @@ -136,7 +136,7 @@ if ($mysoc->country_code == 'FR') { } // Show generic message (for countries that need registration) to explain we need registration to collect data and why -if (in_array($mysoc->country_code, array('FR')) && !getDolGlobalString("BLOCKEDLOG_FOR_TAX_AUDITOR")) { +if (in_array($mysoc->country_code, array('FR')) && !userIsTaxAuditor()) { $organization_for_ping = getDolGlobalString('MAIN_ORGANIZATION_FOR_PING', "Association Dolibarr"); $dataprivacy_url = getDolGlobalString('MAIN_ORGANIZATION_URL_PRIVACY', "https://www.dolibarr.org/legal-privacy-gdpr.php"); diff --git a/htdocs/blockedlog/admin/registration.php b/htdocs/blockedlog/admin/registration.php index 8f5f104332e..74ef659ce2f 100644 --- a/htdocs/blockedlog/admin/registration.php +++ b/htdocs/blockedlog/admin/registration.php @@ -226,7 +226,7 @@ if (GETPOST('withtab', 'alpha')) { $morehtmlcenter = ''; $registrationnumber = getHashUniqueIdOfRegistration(); -if (!getDolGlobalString("BLOCKEDLOG_FOR_TAX_AUDITOR")) { +if (!userIsTaxAuditor()) { $texttop = ''.$langs->trans("RegistrationNumber").': '.dol_trunc($registrationnumber, 10).''; if ((!isRegistrationDataSavedAndPushed() || !isModEnabled('blockedlog')) && $mode != "forceregistration") { $texttop = ''; diff --git a/htdocs/blockedlog/lib/blockedlog.lib.php b/htdocs/blockedlog/lib/blockedlog.lib.php index 940536c0eb6..70c365ab3c7 100644 --- a/htdocs/blockedlog/lib/blockedlog.lib.php +++ b/htdocs/blockedlog/lib/blockedlog.lib.php @@ -58,14 +58,14 @@ function blockedlogadmin_prepare_head($withtabsetup) $h = 0; $head = array(); - if (!getDolGlobalString("BLOCKEDLOG_FOR_TAX_AUDITOR")) { + if (!userIsTaxAuditor()) { $head[$h][0] = DOL_URL_ROOT."/blockedlog/admin/registration.php".$param; $head[$h][1] = $langs->trans("UserRegistration"); $head[$h][2] = 'registration'; $h++; } - if (!getDolGlobalString("BLOCKEDLOG_FOR_TAX_AUDITOR")) { + if (!userIsTaxAuditor()) { $b = new BlockedLog($db); $head[$h][0] = DOL_URL_ROOT."/blockedlog/admin/blockedlog_list.php".$param; $head[$h][1] = $langs->trans("BrowseBlockedLog"); @@ -89,7 +89,7 @@ function blockedlogadmin_prepare_head($withtabsetup) $h++; } - if ($withtabsetup && !getDolGlobalString("BLOCKEDLOG_FOR_TAX_AUDITOR")) { + if ($withtabsetup && !userIsTaxAuditor()) { $head[$h][0] = DOL_URL_ROOT."/blockedlog/admin/blockedlog.php".$param; $head[$h][1] = $langs->trans("TechnicalInformation"); $head[$h][2] = 'technicalinfo'; @@ -452,3 +452,15 @@ function callApiToPushCounter($id, $signature, $test, $previousid, $previoussign return 0; } + +/** + * Return if user is a ta auditor + * + * @return int Return > 0 if user is an external user so must be restricted to archive control feature + */ +function userIsTaxAuditor() +{ + global $user; + + return (getDolGlobalString('BLOCKEDLOG_FOR_TAX_AUDITOR') && $user->socid); +}