diff --git a/htdocs/adherents/class/adherent.class.php b/htdocs/adherents/class/adherent.class.php
index 78fc662f6b4..20041333ee6 100644
--- a/htdocs/adherents/class/adherent.class.php
+++ b/htdocs/adherents/class/adherent.class.php
@@ -1330,19 +1330,19 @@ class Adherent extends CommonObject
/**
* Do complementary actions after subscription recording.
*
- * @param int $subscriptionid Id of created subscription
- * @param string $option Which action ('bankdirect', 'invoiceonly', ...)
- * @param int $accountid Id bank account
- * @param int $datesubscription Date of subscription
- * @param int $paymentdate Date of payment
- * @param string $operation Code of type of operation (if Id bank account provided). Example 'CB', ...
- * @param string $label Label operation (if Id bank account provided)
- * @param double $amount Amount of subscription (0 accepted for some members)
- * @param string $num_chq Numero cheque (if Id bank account provided)
- * @param string $emetteur_nom Name of cheque writer
- * @param string $emetteur_banque Name of bank of cheque
+ * @param int $subscriptionid Id of created subscription
+ * @param string $option Which action ('bankdirect', 'invoiceonly', ...)
+ * @param int $accountid Id bank account
+ * @param int $datesubscription Date of subscription
+ * @param int $paymentdate Date of payment
+ * @param string $operation Code of type of operation (if Id bank account provided). Example 'CB', ...
+ * @param string $label Label operation (if Id bank account provided)
+ * @param double $amount Amount of subscription (0 accepted for some members)
+ * @param string $num_chq Numero cheque (if Id bank account provided)
+ * @param string $emetteur_nom Name of cheque writer
+ * @param string $emetteur_banque Name of bank of cheque
* @param string $autocreatethirdparty Auto create new thirdparty if member not linked to a thirdparty.
- * @return int <0 if KO, >0 if OK
+ * @return int <0 if KO, >0 if OK
*/
function subscriptionComplementaryActions($subscriptionid, $option, $accountid, $datesubscription, $paymentdate, $operation, $label, $amount, $num_chq, $emetteur_nom='', $emetteur_banque='', $autocreatethirdparty=0)
{
@@ -1350,6 +1350,8 @@ class Adherent extends CommonObject
$error = 0;
+ $this->invoice = null; // This will contains invoice if an invoice is created
+
// Insert into bank account directlty (if option choosed for) + link to llx_subscription if option is 'bankdirect'
if ($option == 'bankdirect' && $accountid)
{
@@ -1489,6 +1491,10 @@ class Adherent extends CommonObject
$this->errors=$invoice->errors;
$error++;
}
+ else
+ {
+ $this->invoice = $invoice;
+ }
}
if (! $error)
@@ -1524,6 +1530,11 @@ class Adherent extends CommonObject
}
}
+ if (! $error)
+ {
+ // TODO Link invoice with subscription ?
+ }
+
// Add payment onto invoice
if (! $error && $option == 'bankviainvoice' && $accountid)
{
@@ -1584,25 +1595,25 @@ class Adherent extends CommonObject
// Set invoice as paid
$invoice->set_paid($user);
}
+ }
- if (! $error)
- {
- // Define output language
- $outputlangs = $langs;
- $newlang = '';
- if ($conf->global->MAIN_MULTILANGS && empty($newlang) && ! empty($_REQUEST['lang_id']))
- $newlang = $_REQUEST['lang_id'];
- if ($conf->global->MAIN_MULTILANGS && empty($newlang))
- $newlang = $customer->default_lang;
- if (! empty($newlang)) {
- $outputlangs = new Translate("", $conf);
- $outputlangs->setDefaultLang($newlang);
- }
- // Generate PDF (whatever is option MAIN_DISABLE_PDF_AUTOUPDATE) so we can include it into email
- //if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE))
-
- $invoice->generateDocument($invoice->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
+ if (! $error)
+ {
+ // Define output language
+ $outputlangs = $langs;
+ $newlang = '';
+ if ($conf->global->MAIN_MULTILANGS && empty($newlang) && ! empty($_REQUEST['lang_id']))
+ $newlang = $_REQUEST['lang_id'];
+ if ($conf->global->MAIN_MULTILANGS && empty($newlang))
+ $newlang = $customer->default_lang;
+ if (! empty($newlang)) {
+ $outputlangs = new Translate("", $conf);
+ $outputlangs->setDefaultLang($newlang);
}
+ // Generate PDF (whatever is option MAIN_DISABLE_PDF_AUTOUPDATE) so we can include it into email
+ //if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE))
+
+ $invoice->generateDocument($invoice->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
}
}
diff --git a/htdocs/adherents/subscription.php b/htdocs/adherents/subscription.php
index 3b200ed526c..9d164307e91 100644
--- a/htdocs/adherents/subscription.php
+++ b/htdocs/adherents/subscription.php
@@ -322,11 +322,15 @@ if ($user->rights->adherent->cotisation->creer && $action == 'subscription' && !
$error++;
setEventMessages($object->error, $object->errors, 'errors');
}
+ else
+ {
+ // If an invoice was created, it is into $object->invoice
+ }
}
if (! $error)
{
- $db->commit();
+// $db->commit();
}
else
{
@@ -334,6 +338,11 @@ if ($user->rights->adherent->cotisation->creer && $action == 'subscription' && !
$action = 'addsubscription';
}
+ if (! $error)
+ {
+ setEventMessages("SubscriptionRecorded", null, 'mesgs');
+ }
+
// Send email
if (! $error)
{
@@ -343,12 +352,36 @@ if ($user->rights->adherent->cotisation->creer && $action == 'subscription' && !
$subjecttosend=$object->makeSubstitution($conf->global->ADHERENT_MAIL_COTIS_SUBJECT);
$texttosend=$object->makeSubstitution($adht->getMailOnSubscription());
- $result=$object->send_an_email($texttosend,$subjecttosend,array(),array(),array(),"","",0,-1);
+ // Attach a file ?
+ $file='';
+ $listofpaths=array();
+ $listofnames=array();
+ $listofmimes=array();
+ if (is_object($object->invoice))
+ {
+ $invoicediroutput = $conf->facture->dir_output;
+ $fileparams = dol_most_recent_file($invoicediroutput . '/' . $object->invoice->ref, preg_quote($object->invoice->ref, '/').'[^\-]+');
+ $file = $fileparams['fullname'];
+
+ $listofpaths=array($file);
+ $listofnames=array(basename($file));
+ $listofmimes=array(dol_mimetype($file));
+ }
+
+ $result=$object->send_an_email($texttosend, $subjecttosend, $listofpaths, $listofnames, $listofmimes, "", "", 0, -1);
if ($result < 0)
{
$errmsg=$object->error;
- setEventMessages($errmsg, null, 'errors');
+ setEventMessages($object->error, $object->errors, 'errors');
}
+ else
+ {
+ setEventMessages($langs->trans("EmailSentToMember", $object->email), null, 'mesgs');
+ }
+ }
+ else
+ {
+ setEventMessages($langs->trans("NoEmailSentToMember"), null, 'mesgs');
}
}
@@ -998,7 +1031,7 @@ if ($rowid > 0)
$helpcontent.=''.$langs->trans("MailText").':
';
$helpcontent.=dol_htmlentitiesbr($texttosend)."\n";
- print $form->textwithpicto($tmp,$helpcontent,1,'help');
+ print $form->textwithpicto($tmp, $helpcontent, 1, 'help', '', 0, 2, 'helpemailtosend');
}
print '';
print '';
diff --git a/htdocs/core/class/html.formmail.class.php b/htdocs/core/class/html.formmail.class.php
index 8aa7f0ce54e..40274b00b76 100644
--- a/htdocs/core/class/html.formmail.class.php
+++ b/htdocs/core/class/html.formmail.class.php
@@ -148,16 +148,19 @@ class FormMail extends Form
* Add a file into the list of attached files (stored in SECTION array)
*
* @param string $path Full absolute path on filesystem of file, including file name
- * @param string $file Only filename
- * @param string $type Mime type
+ * @param string $file Only filename (can be basename($path))
+ * @param string $type Mime type (can be dol_mimetype($file))
* @return void
*/
- function add_attached_files($path,$file,$type)
+ function add_attached_files($path, $file='', $type='')
{
$listofpaths=array();
$listofnames=array();
$listofmimes=array();
+ if (empty($file)) $file=basename($path);
+ if (empty($type)) $type=dol_mimetype($file);
+
$keytoavoidconflict = empty($this->trackid)?'':'-'.$this->trackid; // this->trackid must be defined
if (! empty($_SESSION["listofpaths".$keytoavoidconflict])) $listofpaths=explode(';',$_SESSION["listofpaths".$keytoavoidconflict]);
if (! empty($_SESSION["listofnames".$keytoavoidconflict])) $listofnames=explode(';',$_SESSION["listofnames".$keytoavoidconflict]);
diff --git a/htdocs/langs/en_US/members.lang b/htdocs/langs/en_US/members.lang
index 2a98f700027..bfa338605f2 100644
--- a/htdocs/langs/en_US/members.lang
+++ b/htdocs/langs/en_US/members.lang
@@ -176,4 +176,7 @@ VATToUseForSubscriptions=VAT rate to use for subscriptions
NoVatOnSubscription=No TVA for subscriptions
MEMBER_PAYONLINE_SENDEMAIL=Email to use for email warning when Dolibarr receive a confirmation of a validated payment for a subscription (Example: paymentdone@example.com)
ADHERENT_PRODUCT_ID_FOR_SUBSCRIPTIONS=Product used for subscription line into invoice: %s
-NameOrCompany=Name or company
\ No newline at end of file
+NameOrCompany=Name or company
+SubscriptionRecorded=Subscription recorded
+NoEmailSentToMember=No email sent to member
+EmailSentToMember=Email sent to member at %s
\ No newline at end of file
diff --git a/htdocs/public/payment/paymentok.php b/htdocs/public/payment/paymentok.php
index 83b672604cc..285bf2920eb 100644
--- a/htdocs/public/payment/paymentok.php
+++ b/htdocs/public/payment/paymentok.php
@@ -374,6 +374,8 @@ if ($ispaymentok)
if ($option == 'bankdirect') $postactionmessages[] = 'Bank record created';
if ($option == 'invoiceonly') $postactionmessages[] = 'Invoice recorded';
$ispostactionok = 1;
+
+ // If an invoice was created, it is into $object->invoice
}
}
@@ -395,13 +397,34 @@ if ($ispaymentok)
$subjecttosend=$object->makeSubstitution($conf->global->ADHERENT_MAIL_COTIS_SUBJECT);
$texttosend=$object->makeSubstitution($adht->getMailOnSubscription());
- $result=$object->send_an_email($texttosend,$subjecttosend,array(),array(),array(),"","",0,-1);
+ // Attach a file ?
+ $file='';
+ $listofpaths=array();
+ $listofnames=array();
+ $listofmimes=array();
+ if (is_object($object->invoice))
+ {
+ $invoicediroutput = $conf->facture->dir_output;
+ $fileparams = dol_most_recent_file($invoicediroutput . '/' . $object->invoice->ref, preg_quote($object->invoice->ref, '/').'[^\-]+');
+ $file = $fileparams['fullname'];
+
+ $listofpaths=array($file);
+ $listofnames=array(basename($file));
+ $listofmimes=array(dol_mimetype($file));
+ }
+
+ $result=$object->send_an_email($texttosend, $subjecttosend, $listofpaths, $listofnames, $listofmimes, "", "", 0, -1);
if ($result < 0)
{
$errmsg=$object->error;
$postactionmessages[] = $errmsg;
$ispostactionok = -1;
}
+ else
+ {
+ if ($file) $postactionmessages[] = 'Email sent to member (with invoice document attached)';
+ else $postactionmessages[] = 'Email sent to member (without any attached document)';
+ }
}
}
}
@@ -601,7 +624,7 @@ if ($ispaymentok)
$content="";
if (in_array('MEM', array_keys($tmptag)))
{
- $url=$urlwithroot."/adherents/card_subscriptions.php?rowid=".$tmptag['MEM'];
+ $url=$urlwithroot."/adherents/subscription.php?rowid=".$tmptag['MEM'];
$content.=''.$companylangs->trans("PaymentSubscription")."
\n";
$content.=$companylangs->trans("MemberId").': '.$tmptag['MEM']."
\n";
$content.=$companylangs->trans("Link").': '.$url.''."
\n";
diff --git a/htdocs/public/paypal/paymentok.php b/htdocs/public/paypal/paymentok.php
index 80ec1d8ec2b..d50dd66d903 100644
--- a/htdocs/public/paypal/paymentok.php
+++ b/htdocs/public/paypal/paymentok.php
@@ -212,7 +212,7 @@ if ($PAYPALTOKEN)
if (! empty($tmptag['MEM']))
{
$langs->load("members");
- $url=$urlwithroot."/adherents/card_subscriptions.php?rowid=".$tmptag['MEM'];
+ $url=$urlwithroot."/adherents/subscriptions/card.php?rowid=".$tmptag['MEM'];
$content.=$langs->trans("PaymentSubscription")."
\n";
$content.=$langs->trans("MemberId").': '.$tmptag['MEM']."
\n";
$content.=$langs->trans("Link").': '.$url.''."
\n";