From 2992b3e84580c400b9afb401a1c9bb3f4f9253de Mon Sep 17 00:00:00 2001 From: lvessiller Date: Fri, 22 Apr 2022 09:24:23 +0200 Subject: [PATCH 1/3] NEW send last document in mass mailing action --- htdocs/core/actions_massactions.inc.php | 46 ++++++++++++++++++------- 1 file changed, 34 insertions(+), 12 deletions(-) diff --git a/htdocs/core/actions_massactions.inc.php b/htdocs/core/actions_massactions.inc.php index 5ec011f5017..171383d7008 100644 --- a/htdocs/core/actions_massactions.inc.php +++ b/htdocs/core/actions_massactions.inc.php @@ -306,29 +306,51 @@ if (!$error && $massaction == 'confirm_presend') { // TODO Set subdir to be compatible with multi levels dir trees // $subdir = get_exdir($objectobj->id, 2, 0, 0, $objectobj, $objectobj->element) $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 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, '/').'([^\-])+'); - $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($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 $attachedfilesThirdpartyObj[$thirdpartyid][$objectid] = array( - 'paths'=>array($file), - 'names'=>array($filename), - 'mimes'=>array($mime) + 'paths'=>array($filepath_found), + 'names'=>array($filename_found), + 'mimes'=>array(dol_mimetype($filepath_found)) ); } else { - $nbignored++; - $langs->load("errors"); - $resaction .= '
'.$langs->trans('ErrorCantReadFile', $file).'

'; - dol_syslog('Failed to read file: '.$file, LOG_WARNING); - continue; + $nbignored++; + $langs->load("errors"); + foreach ($file_check_list as $file_check_arr) { + $resaction .= '
'.$langs->trans('ErrorCantReadFile', $file_check_arr['path']).'

'; + dol_syslog('Failed to read file: '.$file_check_arr['path'], LOG_WARNING); + } + continue; } } From bcc645ce3873fc3f4b7581154a0c5a99f6f7f443 Mon Sep 17 00:00:00 2001 From: lvessiller Date: Mon, 2 May 2022 10:50:48 +0200 Subject: [PATCH 2/3] NEW const MAIL_MASS_ACTION_ADD_LAST_IF_MAIN_DOC_NOT_FOUND for mailing mass action --- htdocs/core/actions_massactions.inc.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/actions_massactions.inc.php b/htdocs/core/actions_massactions.inc.php index 171383d7008..e8ee88eedc3 100644 --- a/htdocs/core/actions_massactions.inc.php +++ b/htdocs/core/actions_massactions.inc.php @@ -322,7 +322,7 @@ if (!$error && $massaction == 'confirm_presend') { 'name' => $filename, 'path' => $filepath, ); - if (!empty($objectobj->last_main_doc)) { + 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, From 0a48c09a7452538337a6e9318663705f79920619 Mon Sep 17 00:00:00 2001 From: lvessiller Date: Mon, 2 May 2022 11:35:12 +0200 Subject: [PATCH 3/3] NEW last generated doc if main not found for mailing mass action --- htdocs/core/class/html.formmail.class.php | 6 +++++- htdocs/langs/en_US/main.lang | 3 ++- htdocs/langs/fr_FR/main.lang | 1 + 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/htdocs/core/class/html.formmail.class.php b/htdocs/core/class/html.formmail.class.php index 0c9a1b2531a..5998822a704 100644 --- a/htdocs/core/class/html.formmail.class.php +++ b/htdocs/core/class/html.formmail.class.php @@ -781,7 +781,11 @@ class FormMail extends Form } elseif ($this->withmaindocfile == -1) { $out .= ''; } - $out .= '
'; + if (!empty($conf->global->MAIL_MASS_ACTION_ADD_LAST_IF_MAIN_DOC_NOT_FOUND)) { + $out .= '
'; + } else { + $out .= '
'; + } } if (is_numeric($this->withfile)) { diff --git a/htdocs/langs/en_US/main.lang b/htdocs/langs/en_US/main.lang index b39124c7c53..530f3b6af0e 100644 --- a/htdocs/langs/en_US/main.lang +++ b/htdocs/langs/en_US/main.lang @@ -621,6 +621,7 @@ MonthVeryShort11=N MonthVeryShort12=D AttachedFiles=Attached files and documents JoinMainDoc=Join main document +JoinMainDocOrLastGenerated=Send the main document or the last generated one if not found DateFormatYYYYMM=YYYY-MM DateFormatYYYYMMDD=YYYY-MM-DD 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 ConfirmAllocateCommercialQuestion=Are you sure you want to assign the %s selected record(s)? CommercialsAffected=Sales representatives affected -CommercialAffected=Sales representative affected \ No newline at end of file +CommercialAffected=Sales representative affected diff --git a/htdocs/langs/fr_FR/main.lang b/htdocs/langs/fr_FR/main.lang index 12778f337dd..53ff7d545b3 100644 --- a/htdocs/langs/fr_FR/main.lang +++ b/htdocs/langs/fr_FR/main.lang @@ -620,6 +620,7 @@ MonthVeryShort11=N MonthVeryShort12=D AttachedFiles=Fichiers et documents joints 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 DateFormatYYYYMMDD=YYYY-MM-DD DateFormatYYYYMMDDHHMM=YYYY-MM-DD HH:SS