Fix bad recipient when using mass actions

This commit is contained in:
Laurent Destailleur 2017-08-02 11:39:11 +02:00
parent 71d49f1c6f
commit 33d6903d3f
2 changed files with 62 additions and 30 deletions

View File

@ -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.='<div class="error">'.$langs->trans('ErrorOnlyInvoiceValidatedCanBeSentInMassAction',$object->ref).'</div><br>';
continue; // Payment done or started or canceled
}
if ($objectclass == 'Commande' && $object->statut == Commande::STATUS_DRAFT)
{
$langs->load("errors");
$nbignored++;
$resaction.='<div class="error">'.$langs->trans('ErrorOnlyOrderNotDraftCanBeSentInMassAction',$object->ref).'</div><br>';
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");

View File

@ -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.