Module BlockedLog can also now be used by tax auditors.

This commit is contained in:
Laurent Destailleur 2026-03-08 22:27:57 +01:00
parent 435935be01
commit e58458efc6
5 changed files with 99 additions and 18 deletions

View file

@ -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 = '<small class="opacitymedium">'.$langs->trans("RegistrationNumber").':</small> <small>'.dol_trunc($registrationnumber, 10).'</small>';
if (!isRegistrationDataSavedAndPushed()) {
$texttop = '';
@ -696,7 +696,7 @@ print dol_get_fiche_head($head, 'archives', '', -1);
//print '<br><br>';
print '<div class="opacitymedium hideonsmartphone justify">';
if (!getDolGlobalString("BLOCKEDLOG_FOR_TAX_AUDITOR")) {
if (!userIsTaxAuditor()) {
print $langs->trans("ArchivesDesc")."<br>";
} else {
print $langs->trans("ArchivesAuditorDesc")."<br>";
@ -752,10 +752,10 @@ if ($action == 'check' || $action == 'checkconfirmed') {
print $langs->trans("FileHasBeenEncodedWithASecretKeyStartingWith").' : '.$regnumber.'...<br>';
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 '<br><br>';
if (!getDolGlobalString("BLOCKEDLOG_FOR_TAX_AUDITOR")) {
if (!userIsTaxAuditor()) {
if ($nbLinesModifiedInExportButKo) {
print img_picto('', 'cross', 'class="error valignmiddle pictofixedwidth"');
print '<b>'.$langs->trans("nbLinesModifiedInExportButKo").'</b>: ';
@ -1049,6 +1080,44 @@ if ($action == 'check' || $action == 'checkconfirmed') {
print '<br>';
}
// 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 '<b>'.dolPrintHTML($langs->trans("LifetimeAmountShort").' '.$langs->trans('log'.$key)).'</b>';
if ($key == 'BILL_VALIDATE') {
print ' <span class="opacitymedium">('.$langs->trans("Turnover").')</span>';
} elseif ($key == 'PAYMENT_CUSTOMER') {
print ' <span class="opacitymedium">('.$langs->trans("TurnoverCollected").')</span>';
}
print ': ';
if ($key == 'PAYMENT_CUSTOMER') {
print '<span class="amount">'.price($totaltoshow, 0, $langs, 1, -1, -1, getDolCurrency()).'</span>';
} else {
print $langs->trans("HT").': ';
print '<span class="amount">'.price($totalhttoshow, 0, $langs, 1, -1, -1, getDolCurrency()).'</span>';
print ' - ';
print $langs->trans("VAT").': ';
print '<span class="amount">'.price($totalvattoshow, 0, $langs, 1, -1, -1, getDolCurrency()).'</span>';
print ' - ';
print $langs->trans("TTC").': ';
print '<span class="amount">'.price($totaltoshow, 0, $langs, 1, -1, -1, getDolCurrency()).'</span>';
}
print '<br>';
}
print '<br>';
$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"))."<br>";
if ($mysoc->country_code == 'FR') {
$htmltext .= '<br>'.$langs->trans("UnalterableLogTool1FR").'<br>';
@ -1145,7 +1214,7 @@ if ($action != 'check' && $action != 'checkconfirmed') {
}
if (!getDolGlobalString("BLOCKEDLOG_FOR_TAX_AUDITOR")) {
if (!userIsTaxAuditor()) {
print '<form method="POST" id="exportArchives" action="'.$_SERVER["PHP_SELF"].'?output=file">';
print '<input type="hidden" name="token" value="'.newToken().'">';
print '<input type="hidden" name="action" value="export">';

View file

@ -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 = '<small class="opacitymedium">'.$langs->trans("RegistrationNumber").':</small> <small>'.dol_trunc($registrationnumber, 10).'</small>';
if (!isRegistrationDataSavedAndPushed()) {
$texttop = '';

View file

@ -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 = '<small class="opacitymedium">'.$langs->trans("RegistrationNumber").':</small> <small>'.dol_trunc($registrationnumber, 10).'</small>';
if ((!isRegistrationDataSavedAndPushed() || !isModEnabled('blockedlog')) && $mode != "forceregistration") {
$texttop = '';
@ -111,7 +111,7 @@ if ($withtab) {
print '<br>';
}
if (!getDolGlobalString("BLOCKEDLOG_FOR_TAX_AUDITOR")) {
if (!userIsTaxAuditor()) {
print '<span class="opacitymedium">'.$langs->trans("BlockedLogDesc")."</span><br>\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");

View file

@ -226,7 +226,7 @@ if (GETPOST('withtab', 'alpha')) {
$morehtmlcenter = '';
$registrationnumber = getHashUniqueIdOfRegistration();
if (!getDolGlobalString("BLOCKEDLOG_FOR_TAX_AUDITOR")) {
if (!userIsTaxAuditor()) {
$texttop = '<small class="opacitymedium">'.$langs->trans("RegistrationNumber").':</small> <small>'.dol_trunc($registrationnumber, 10).'</small>';
if ((!isRegistrationDataSavedAndPushed() || !isModEnabled('blockedlog')) && $mode != "forceregistration") {
$texttop = '';

View file

@ -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);
}