2
0
forked from Wavyzz/dolibarr

Merge pull request #20686 from Easya-Solutions/new-mass-action-send-last-main-doc

NEW Option MAIL_MASS_ACTION_ADD_LAST_IF_MAIN_DOC_NOT_FOUND to send last document in mass mailing action
This commit is contained in:
Laurent Destailleur
2022-05-04 01:17:20 +02:00
committed by GitHub
4 changed files with 42 additions and 14 deletions

View File

@@ -327,29 +327,51 @@ if (!$error && $massaction == 'confirm_presend') {
// TODO Set subdir to be compatible with multi levels dir trees // TODO Set subdir to be compatible with multi levels dir trees
// $subdir = get_exdir($objectobj->id, 2, 0, 0, $objectobj, $objectobj->element) // $subdir = get_exdir($objectobj->id, 2, 0, 0, $objectobj, $objectobj->element)
$filedir = $uploaddir.'/'.$subdir.dol_sanitizeFileName($objectobj->ref); $filedir = $uploaddir.'/'.$subdir.dol_sanitizeFileName($objectobj->ref);
$file = $filedir.'/'.$filename; $filepath = $filedir.'/'.$filename;
// For supplier invoices, we use the file provided by supplier, not the one we generate // For supplier invoices, we use the file provided by supplier, not the one we generate
if ($objectobj->element == 'invoice_supplier') { if ($objectobj->element == 'invoice_supplier') {
$fileparams = dol_most_recent_file($uploaddir.'/'.get_exdir($objectobj->id, 2, 0, 0, $objectobj, $objectobj->element).$objectobj->ref, preg_quote($objectobj->ref, '/').'([^\-])+'); $fileparams = dol_most_recent_file($uploaddir.'/'.get_exdir($objectobj->id, 2, 0, 0, $objectobj, $objectobj->element).$objectobj->ref, preg_quote($objectobj->ref, '/').'([^\-])+');
$file = $fileparams['fullname']; $filepath = $fileparams['fullname'];
} }
$mime = dol_mimetype($file); // try to find other files generated for this object (last_main_doc)
$filename_found = '';
$filepath_found = '';
$file_check_list = array();
$file_check_list[] = array(
'name' => $filename,
'path' => $filepath,
);
if (!empty($conf->global->MAIL_MASS_ACTION_ADD_LAST_IF_MAIN_DOC_NOT_FOUND) && !empty($objectobj->last_main_doc)) {
$file_check_list[] = array(
'name' => basename($objectobj->last_main_doc),
'path' => DOL_DATA_ROOT . '/' . $objectobj->last_main_doc,
);
}
foreach ($file_check_list as $file_check_arr) {
if (dol_is_file($file_check_arr['path'])) {
$filename_found = $file_check_arr['name'];
$filepath_found = $file_check_arr['path'];
break;
}
}
if (dol_is_file($file)) { if ($filepath_found) {
// Create form object // Create form object
$attachedfilesThirdpartyObj[$thirdpartyid][$objectid] = array( $attachedfilesThirdpartyObj[$thirdpartyid][$objectid] = array(
'paths'=>array($file), 'paths'=>array($filepath_found),
'names'=>array($filename), 'names'=>array($filename_found),
'mimes'=>array($mime) 'mimes'=>array(dol_mimetype($filepath_found))
); );
} else { } else {
$nbignored++; $nbignored++;
$langs->load("errors"); $langs->load("errors");
$resaction .= '<div class="error">'.$langs->trans('ErrorCantReadFile', $file).'</div><br>'; foreach ($file_check_list as $file_check_arr) {
dol_syslog('Failed to read file: '.$file, LOG_WARNING); $resaction .= '<div class="error">'.$langs->trans('ErrorCantReadFile', $file_check_arr['path']).'</div><br>';
continue; dol_syslog('Failed to read file: '.$file_check_arr['path'], LOG_WARNING);
}
continue;
} }
} }

View File

@@ -781,7 +781,11 @@ class FormMail extends Form
} elseif ($this->withmaindocfile == -1) { } elseif ($this->withmaindocfile == -1) {
$out .= '<input type="checkbox" id="addmaindocfile" name="addmaindocfile" value="1" checked="checked" />'; $out .= '<input type="checkbox" id="addmaindocfile" name="addmaindocfile" value="1" checked="checked" />';
} }
$out .= ' <label for="addmaindocfile">'.$langs->trans("JoinMainDoc").'.</label><br>'; if (!empty($conf->global->MAIL_MASS_ACTION_ADD_LAST_IF_MAIN_DOC_NOT_FOUND)) {
$out .= ' <label for="addmaindocfile">'.$langs->trans("JoinMainDocOrLastGenerated").'.</label><br>';
} else {
$out .= ' <label for="addmaindocfile">'.$langs->trans("JoinMainDoc").'.</label><br>';
}
} }
if (is_numeric($this->withfile)) { if (is_numeric($this->withfile)) {

View File

@@ -621,6 +621,7 @@ MonthVeryShort11=N
MonthVeryShort12=D MonthVeryShort12=D
AttachedFiles=Attached files and documents AttachedFiles=Attached files and documents
JoinMainDoc=Join main document JoinMainDoc=Join main document
JoinMainDocOrLastGenerated=Send the main document or the last generated one if not found
DateFormatYYYYMM=YYYY-MM DateFormatYYYYMM=YYYY-MM
DateFormatYYYYMMDD=YYYY-MM-DD DateFormatYYYYMMDD=YYYY-MM-DD
DateFormatYYYYMMDDHHMM=YYYY-MM-DD HH:SS DateFormatYYYYMMDDHHMM=YYYY-MM-DD HH:SS
@@ -1172,4 +1173,4 @@ AddLineOnPosition=Add line on position (at the end if empty)
ConfirmAllocateCommercial=Assign sales representative confirmation ConfirmAllocateCommercial=Assign sales representative confirmation
ConfirmAllocateCommercialQuestion=Are you sure you want to assign the %s selected record(s)? ConfirmAllocateCommercialQuestion=Are you sure you want to assign the %s selected record(s)?
CommercialsAffected=Sales representatives affected CommercialsAffected=Sales representatives affected
CommercialAffected=Sales representative affected CommercialAffected=Sales representative affected

View File

@@ -620,6 +620,7 @@ MonthVeryShort11=N
MonthVeryShort12=D MonthVeryShort12=D
AttachedFiles=Fichiers et documents joints AttachedFiles=Fichiers et documents joints
JoinMainDoc=Joindre le document principal JoinMainDoc=Joindre le document principal
JoinMainDocOrLastGenerated=Joindre le document principal ou le dernier généré s'il n'a pas été trouvé
DateFormatYYYYMM=YYYY-MM DateFormatYYYYMM=YYYY-MM
DateFormatYYYYMMDD=YYYY-MM-DD DateFormatYYYYMMDD=YYYY-MM-DD
DateFormatYYYYMMDDHHMM=YYYY-MM-DD HH:SS DateFormatYYYYMMDDHHMM=YYYY-MM-DD HH:SS