diff --git a/htdocs/core/actions_massactions.inc.php b/htdocs/core/actions_massactions.inc.php index 5313b79dc04..0d4a6c6d80c 100644 --- a/htdocs/core/actions_massactions.inc.php +++ b/htdocs/core/actions_massactions.inc.php @@ -90,6 +90,8 @@ if (! $error && $massaction == 'confirm_presend') } //var_dump($listofobjectthirdparties);exit; + + // Loop on each thirdparty foreach ($listofobjectthirdparties as $thirdpartyid) { $result = $thirdparty->fetch($thirdpartyid); @@ -99,62 +101,90 @@ if (! $error && $massaction == 'confirm_presend') exit; } - // Define recipient $sendto and $sendtocc + $sendto=''; + $sendtocc=''; + $sendtobcc=''; + $sendtoid = array(); + + // Define $sendto + $receiver=$_POST['receiver']; + if (! is_array($receiver)) + { + if ($receiver == '-1') $receiver=array(); + else $receiver=array($receiver); + } + $tmparray=array(); if (trim($_POST['sendto'])) { - // Recipient is provided into free text - $sendto = trim($_POST['sendto']); - $sendtoid = 0; + // Recipients are provided into free text + $tmparray[] = trim($_POST['sendto']); } - elseif ($_POST['receiver'] != '-1') + if (count($receiver)>0) { - // Recipient was provided from combo list - if ($_POST['receiver'] == 'thirdparty') // Id of third party - { - $sendto = $thirdparty->email; - $sendtoid = 0; - } - else // Id du contact - { - $sendto = $thirdparty->contact_get_property((int) $_POST['receiver'],'email'); - $sendtoid = $_POST['receiver']; - } + foreach($receiver as $key=>$val) + { + // Recipient was provided from combo list + if ($val == 'thirdparty') // Id of third party + { + $tmparray[] = $thirdparty->name.' <'.$thirdparty->email.'>'; + } + elseif ($val) // Id du contact + { + $tmparray[] = $thirdparty->contact_get_property((int) $val,'email'); + $sendtoid[] = $val; + } + } } + $sendto=implode(',',$tmparray); + + // Define $sendtocc + $receivercc=$_POST['receivercc']; + if (! is_array($receivercc)) + { + if ($receivercc == '-1') $receivercc=array(); + else $receivercc=array($receivercc); + } + $tmparray=array(); if (trim($_POST['sendtocc'])) { - $sendtocc = trim($_POST['sendtocc']); + $tmparray[] = trim($_POST['sendtocc']); } - elseif ($_POST['receivercc'] != '-1') + if (count($receivercc) > 0) { - // Recipient was provided from combo list - if ($_POST['receivercc'] == 'thirdparty') // Id of third party - { - $sendtocc = $thirdparty->email; - } - else // Id du contact - { - $sendtocc = $thirdparty->contact_get_property((int) $_POST['receivercc'],'email'); - } + foreach($receivercc as $key=>$val) + { + // Recipient was provided from combo list + if ($val == 'thirdparty') // Id of third party + { + $tmparray[] = $thirdparty->name.' <'.$thirdparty->email.'>'; + } + elseif ($val) // Id du contact + { + $tmparray[] = $thirdparty->contact_get_property((int) $val,'email'); + //$sendtoid[] = $val; TODO Add also id of contact in CC ? + } + } } + $sendtocc=implode(',',$tmparray); - //var_dump($listofobjectref[$thirdpartyid]); // Array of invoice for this thirdparty - + //var_dump($listofobjectref);exit; $attachedfiles=array('paths'=>array(), 'names'=>array(), 'mimes'=>array()); $listofqualifiedinvoice=array(); $listofqualifiedref=array(); foreach($listofobjectref[$thirdpartyid] as $objectid => $object) { - //var_dump($object); //var_dump($thirdpartyid.' - '.$objectid.' - '.$object->statut); if ($objectclass == 'Facture' && $object->statut != Facture::STATUS_VALIDATED) { + $langs->load("errors"); $nbignored++; $resaction.='
'.$langs->trans('ErrorOnlyInvoiceValidatedCanBeSentInMassAction',$object->ref).'

'; continue; // Payment done or started or canceled } if ($objectclass == 'Commande' && $object->statut == Commande::STATUS_DRAFT) { + $langs->load("errors"); $nbignored++; $resaction.='
'.$langs->trans('ErrorOnlyOrderNotDraftCanBeSentInMassAction',$object->ref).'

'; continue; @@ -208,6 +238,7 @@ if (! $error && $massaction == 'confirm_presend') //var_dump($listofqualifiedref); } + // Loop on each qualified invoice of the thirdparty if (count($listofqualifiedinvoice) > 0) { $langs->load("commercial"); diff --git a/htdocs/langs/en_US/errors.lang b/htdocs/langs/en_US/errors.lang index ac982973ef3..b03b8ad37bb 100644 --- a/htdocs/langs/en_US/errors.lang +++ b/htdocs/langs/en_US/errors.lang @@ -194,6 +194,7 @@ ErrorDuplicateTrigger=Error, duplicate trigger name %s. Already loaded from %s. ErrorNoWarehouseDefined=Error, no warehouses defined. ErrorBadLinkSourceSetButBadValueForRef=The link you use is not valid. A 'source' for payment is defined, but value for 'ref' is not valid. ErrorTooManyErrorsProcessStopped=Too many errors. Process was stopped. +ErrorOnlyInvoiceValidatedCanBeSentInMassAction=Only validated invoices can be sent using the "Send by email" mass action. # Warnings WarningPasswordSetWithNoAccount=A password was set for this member. However, no user account was created. So this password is stored but can't be used to login to Dolibarr. It may be used by an external module/interface but if you don't need to define any login nor password for a member, you can disable option "Manage a login for each member" from Member module setup. If you need to manage a login but don't need any password, you can keep this field empty to avoid this warning. Note: Email can also be used as a login if the member is linked to a user.