diff --git a/htdocs/adherents/class/adherent.class.php b/htdocs/adherents/class/adherent.class.php
index 5691cd6687b..4fd04a0a9c9 100644
--- a/htdocs/adherents/class/adherent.class.php
+++ b/htdocs/adherents/class/adherent.class.php
@@ -1248,7 +1248,7 @@ class Adherent extends CommonObject
* Insert subscription into database and eventually add links to banks, mailman, etc...
*
* @param int $date Date of effect of subscription
- * @param double $montant Amount of subscription (0 accepted for some members)
+ * @param double $amount Amount of subscription (0 accepted for some members)
* @param int $accountid Id bank account
* @param string $operation Type operation (if Id bank account provided)
* @param string $label Label operation (if Id bank account provided)
@@ -1258,7 +1258,7 @@ class Adherent extends CommonObject
* @param int $datesubend Date end subscription
* @return int rowid of record added, <0 if KO
*/
- function subscription($date, $montant, $accountid=0, $operation='', $label='', $num_chq='', $emetteur_nom='', $emetteur_banque='', $datesubend=0)
+ function subscription($date, $amount, $accountid=0, $operation='', $label='', $num_chq='', $emetteur_nom='', $emetteur_banque='', $datesubend=0)
{
global $conf,$langs,$user;
@@ -1267,7 +1267,7 @@ class Adherent extends CommonObject
$error=0;
// Clean parameters
- if (! $montant) $montant=0;
+ if (! $amount) $amount=0;
$this->db->begin();
@@ -1287,7 +1287,7 @@ class Adherent extends CommonObject
$subscription->fk_adherent=$this->id;
$subscription->dateh=$date; // Date of new subscription
$subscription->datef=$datefin; // End data of new subscription
- $subscription->amount=$montant;
+ $subscription->amount=$amount;
$subscription->note=$label;
$rowid=$subscription->create($user);
@@ -1300,7 +1300,7 @@ class Adherent extends CommonObject
{
// Change properties of object (used by triggers)
$this->last_subscription_date=dol_now();
- $this->last_subscription_amount=$montant;
+ $this->last_subscription_amount=$amount;
$this->last_subscription_date_start=$date;
$this->last_subscription_date_end=$datefin;
}
@@ -1319,11 +1319,303 @@ class Adherent extends CommonObject
else
{
$this->error=$subscription->error;
+ $this->errors=$subscription->errors;
$this->db->rollback();
return -1;
}
}
+
+ /**
+ * 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 string $autocreatethirdparty Auto create new thirdparty if member not linked to a thirdparty.
+ * @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)
+ {
+ global $conf, $langs, $user, $mysoc;
+
+ $error = 0;
+
+ // Insert into bank account directlty (if option choosed for) + link to llx_subscription if option is 'bankdirect'
+ if ($option == 'bankdirect' && $accountid)
+ {
+ require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
+
+ $acct=new Account($this->db);
+ $result=$acct->fetch($accountid);
+
+ $dateop=$paymentdate;
+
+ $insertid=$acct->addline($dateop, $operation, $label, $amount, $num_chq, '', $user, $emetteur_nom, $emetteur_banque);
+ if ($insertid > 0)
+ {
+ $inserturlid=$acct->add_url_line($insertid, $this->id, DOL_URL_ROOT.'/adherents/card.php?rowid=', $this->getFullname($langs), 'member');
+ if ($inserturlid > 0)
+ {
+ // Update table subscription
+ $sql ="UPDATE ".MAIN_DB_PREFIX."subscription SET fk_bank=".$insertid;
+ $sql.=" WHERE rowid=".$subscriptionid;
+
+ dol_syslog("subscription::subscription", LOG_DEBUG);
+ $resql = $this->db->query($sql);
+ if (! $resql)
+ {
+ $error++;
+ $this->error=$this->db->lasterror();
+ $this->errors[]=$this->error;
+ }
+ }
+ else
+ {
+ $error++;
+ $this->error=$acct->error;
+ $this->errors=$acct->errors;
+ }
+ }
+ else
+ {
+ $error++;
+ $this->error=$acct->error;
+ $this->errors=$acct->errors;
+ }
+ }
+
+ // If option choosed, we create invoice
+ if (($option == 'bankviainvoice' && $accountid) || $option == 'invoiceonly')
+ {
+ require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
+ require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/paymentterm.class.php';
+
+ $invoice=new Facture($this->db);
+ $customer=new Societe($this->db);
+
+ if (! $error)
+ {
+ if (! ($this->fk_soc > 0))
+ {
+ if ($autocreatethirdparty)
+ {
+ // Create a linked thirdparty to member
+ $companyalias='';
+ $fullname = $this->getFullName($langs);
+
+ if ($this->morphy == 'mor')
+ {
+ $companyname=$this->societe;
+ if (! empty($fullname)) $companyalias=$fullname;
+ }
+ else
+ {
+ $companyname=$fullname;
+ if (! empty($this->societe)) $companyalias=$this->societe;
+ }
+
+ $result=$customer->create_from_member($this, $companyname, $companyalias);
+ if ($result < 0)
+ {
+ $this->error = $company->error;
+ $this->errors = $company->errors;
+ $error++;
+ }
+ else
+ {
+ $this->fk_soc = $result;
+ }
+ }
+ else
+ {
+ $langs->load("errors");
+ $this->error=$langs->trans("ErrorMemberNotLinkedToAThirpartyLinkOrCreateFirst");
+ $this->errors[]=$this->error;
+ $error++;
+ }
+ }
+ }
+ if (! $error)
+ {
+ $result=$customer->fetch($this->fk_soc);
+ if ($result <= 0)
+ {
+ $this->error=$customer->error;
+ $this->errors=$customer->errors;
+ $error++;
+ }
+ }
+
+ if (! $error)
+ {
+ // Create draft invoice
+ $invoice->type=Facture::TYPE_STANDARD;
+ $invoice->cond_reglement_id=$customer->cond_reglement_id;
+ if (empty($invoice->cond_reglement_id))
+ {
+ $paymenttermstatic=new PaymentTerm($this->db);
+ $invoice->cond_reglement_id=$paymenttermstatic->getDefaultId();
+ if (empty($invoice->cond_reglement_id))
+ {
+ $error++;
+ $this->error='ErrorNoPaymentTermRECEPFound';
+ $this->errors[]=$this->error;
+ }
+ }
+ $invoice->socid=$this->fk_soc;
+ $invoice->date=$datesubscription;
+
+ // Possibility to add external linked objects with hooks
+ $invoice->linked_objects['subscription'] = $subscriptionid;
+ if (! empty($_POST['other_linked_objects']) && is_array($_POST['other_linked_objects']))
+ {
+ $invoice->linked_objects = array_merge($invoice->linked_objects, $_POST['other_linked_objects']);
+ }
+
+ $result=$invoice->create($user);
+ if ($result <= 0)
+ {
+ $this->error=$invoice->error;
+ $this->errors=$invoice->errors;
+ $error++;
+ }
+ }
+
+ if (! $error)
+ {
+ // Add line to draft invoice
+ $idprodsubscription=0;
+ if (! empty($conf->global->ADHERENT_PRODUCT_ID_FOR_SUBSCRIPTIONS) && (! empty($conf->product->enabled) || ! empty($conf->service->enabled))) $idprodsubscription = $conf->global->ADHERENT_PRODUCT_ID_FOR_SUBSCRIPTIONS;
+
+ $vattouse=0;
+ if (isset($conf->global->ADHERENT_VAT_FOR_SUBSCRIPTIONS) && $conf->global->ADHERENT_VAT_FOR_SUBSCRIPTIONS == 'defaultforfoundationcountry')
+ {
+ $vattouse=get_default_tva($mysoc, $mysoc, $idprodsubscription);
+ }
+ //print xx".$vattouse." - ".$mysoc." - ".$customer;exit;
+ $result=$invoice->addline($label,0,1,$vattouse,0,0,$idprodsubscription,0,$datesubscription,$datesubend,0,0,'','TTC',$amount,1);
+ if ($result <= 0)
+ {
+ $this->error=$invoice->error;
+ $this->errors=$invoice->errors;
+ $error++;
+ }
+ }
+
+ if (! $error)
+ {
+ // Validate invoice
+ $result=$invoice->validate($user);
+ if ($result <= 0)
+ {
+ $this->error=$invoice->error;
+ $this->errors=$invoice->errors;
+ $error++;
+ }
+ }
+
+ // Add payment onto invoice
+ if (! $error && $option == 'bankviainvoice' && $accountid)
+ {
+ require_once DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php';
+ require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
+ require_once DOL_DOCUMENT_ROOT.'/core/lib/functions.lib.php';
+
+ $amounts = array();
+ $amounts[$invoice->id] = price2num($amount);
+
+ $paiement = new Paiement($this->db);
+ $paiement->datepaye = $paymentdate;
+ $paiement->amounts = $amounts;
+ $paiement->paiementid = dol_getIdFromCode($this->db,$operation,'c_paiement','code','id',1);
+ $paiement->num_paiement = $num_chq;
+ $paiement->note = $label;
+ $paiement->note_public = $label;
+
+ if (! $error)
+ {
+ // Create payment line for invoice
+ $paiement_id = $paiement->create($user);
+ if (! $paiement_id > 0)
+ {
+ $this->error=$paiement->error;
+ $this->errors=$paiement->errors;
+ $error++;
+ }
+ }
+
+ if (! $error)
+ {
+ // Add transaction into bank account
+ $bank_line_id=$paiement->addPaymentToBank($user,'payment','(SubscriptionPayment)',$accountid,$emetteur_nom,$emetteur_banque);
+ if (! ($bank_line_id > 0))
+ {
+ $this->error=$paiement->error;
+ $this->errors=$paiement->errors;
+ $error++;
+ }
+ }
+
+ if (! $error)
+ {
+ // Update fk_bank into subscription table
+ $sql = 'UPDATE '.MAIN_DB_PREFIX.'subscription SET fk_bank='.$bank_line_id;
+ $sql.= ' WHERE rowid='.$subscriptionid;
+
+ $result = $this->db->query($sql);
+ if (! $result)
+ {
+ $error++;
+ }
+ }
+
+ if (! $error)
+ {
+ // 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)
+ {
+ return -1;
+ }
+ else
+ {
+ return 1;
+ }
+ }
+
+
/**
* Function that validate a member
*
@@ -2155,9 +2447,9 @@ class Adherent extends CommonObject
/**
* Function used to replace a thirdparty id with another one.
*
- * @param DoliDB $db Database handler
- * @param int $origin_id Old thirdparty id
- * @param int $dest_id New thirdparty id
+ * @param DoliDB $db Database handler
+ * @param int $origin_id Old thirdparty id
+ * @param int $dest_id New thirdparty id
* @return bool
*/
public static function replaceThirdparty($db, $origin_id, $dest_id)
diff --git a/htdocs/adherents/subscription.php b/htdocs/adherents/subscription.php
index 8d4b7829925..efb3627ddbf 100644
--- a/htdocs/adherents/subscription.php
+++ b/htdocs/adherents/subscription.php
@@ -118,7 +118,7 @@ if ($action == 'confirm_create_thirdparty' && $confirm == 'yes' && $user->rights
{
if ($result > 0)
{
- // Creation user
+ // Creation of thirdparty
$company = new Societe($db);
$result=$company->create_from_member($object, GETPOST('companyname', 'alpha'), GETPOST('companyalias', 'alpha'));
@@ -203,8 +203,8 @@ if ($user->rights->adherent->cotisation->creer && $action == 'subscription' && !
$langs->load("banks");
- $result=$object->fetch($rowid);
- $result=$adht->fetch($object->typeid);
+ $result = $object->fetch($rowid);
+ $result = $adht->fetch($object->typeid);
// Subscription informations
$datesubscription=0;
@@ -222,7 +222,7 @@ if ($user->rights->adherent->cotisation->creer && $action == 'subscription' && !
{
$paymentdate=dol_mktime(0, 0, 0, $_POST["paymentmonth"], $_POST["paymentday"], $_POST["paymentyear"]);
}
- $subscription=price2num(GETPOST("subscription",'alpha')); // Amount of subscription
+ $amount=price2num(GETPOST("subscription",'alpha')); // Amount of subscription
$label=$_POST["label"];
// Payment informations
@@ -233,6 +233,7 @@ if ($user->rights->adherent->cotisation->creer && $action == 'subscription' && !
$emetteur_banque=$_POST["chqbank"];
$option=$_POST["paymentsave"];
if (empty($option)) $option='none';
+ $sendalsoemail=GETPOST("sendmail",'alpha');
// Check parameters
if (! $datesubscription)
@@ -263,8 +264,6 @@ if ($user->rights->adherent->cotisation->creer && $action == 'subscription' && !
$action='addsubscription';
}
- $amount = price2num(GETPOST("subscription",'alpha'));
-
// Check if a payment is mandatory or not
if (! $error && $adht->subscription) // Member type need subscriptions
{
@@ -284,7 +283,7 @@ if ($user->rights->adherent->cotisation->creer && $action == 'subscription' && !
{
if (! $_POST["label"]) $errmsg=$langs->trans("ErrorFieldRequired",$langs->transnoentities("Label"));
if ($_POST["paymentsave"] != 'invoiceonly' && ! $_POST["operation"]) $errmsg=$langs->trans("ErrorFieldRequired",$langs->transnoentities("PaymentMode"));
- if ($_POST["paymentsave"] != 'invoiceonly' && ! $_POST["accountid"]) $errmsg=$langs->trans("ErrorFieldRequired",$langs->transnoentities("FinancialAccount"));
+ if ($_POST["paymentsave"] != 'invoiceonly' && ! ($_POST["accountid"] > 0)) $errmsg=$langs->trans("ErrorFieldRequired",$langs->transnoentities("FinancialAccount"));
}
else
{
@@ -292,6 +291,7 @@ if ($user->rights->adherent->cotisation->creer && $action == 'subscription' && !
}
if ($errmsg)
{
+ $error++;
setEventMessages($errmsg, null, 'errors');
$action='addsubscription';
}
@@ -299,12 +299,13 @@ if ($user->rights->adherent->cotisation->creer && $action == 'subscription' && !
}
}
+ // Record the subscription then complementary actions
if (! $error && $action=='subscription')
{
$db->begin();
// Create subscription
- $crowid=$object->subscription($datesubscription, $subscription, $accountid, $operation, $label, $num_chq, $emetteur_nom, $emetteur_banque, $datesubend);
+ $crowid=$object->subscription($datesubscription, $amount, $accountid, $operation, $label, $num_chq, $emetteur_nom, $emetteur_banque, $datesubend);
if ($crowid <= 0)
{
$error++;
@@ -314,233 +315,12 @@ if ($user->rights->adherent->cotisation->creer && $action == 'subscription' && !
if (! $error)
{
- // Insert into bank account directlty (if option choosed for) + link to llx_subscription if option is 'bankdirect'
- if ($option == 'bankdirect' && $accountid)
- {
- require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
-
- $acct=new Account($db);
- $result=$acct->fetch($accountid);
-
- $dateop=$paymentdate;
-
- $insertid=$acct->addline($dateop, $operation, $label, $subscription, $num_chq, '', $user, $emetteur_nom, $emetteur_banque);
- if ($insertid > 0)
- {
- $inserturlid=$acct->add_url_line($insertid, $object->id, DOL_URL_ROOT.'/adherents/card.php?rowid=', $object->getFullname($langs), 'member');
- if ($inserturlid > 0)
- {
- // Update table subscription
- $sql ="UPDATE ".MAIN_DB_PREFIX."subscription SET fk_bank=".$insertid;
- $sql.=" WHERE rowid=".$crowid;
-
- dol_syslog("subscription::subscription", LOG_DEBUG);
- $resql = $db->query($sql);
- if (! $resql)
- {
- $error++;
- $errmsg=$db->lasterror();
- setEventMessages($errmsg, null, 'errors');
- }
- }
- else
- {
- $error++;
- $errmsg=$acct->error;
- $errmsgs=$acct->errors;
- setEventMessages($errmsg, $errmsgs, 'errors');
- }
- }
- else
- {
- $error++;
- $errmsg=$acct->error;
- $errmsgs=$acct->errors;
- setEventMessages($errmsg, $errmsgs, 'errors');
- }
- }
-
- // If option choosed, we create invoice
- if (($option == 'bankviainvoice' && $accountid) || $option == 'invoiceonly')
- {
- require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
- require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/paymentterm.class.php';
-
- $invoice=new Facture($db);
- $customer=new Societe($db);
-
- if (! $error)
- {
- if (! ($object->fk_soc > 0))
- {
- $langs->load("errors");
- $errmsg=$langs->trans("ErrorMemberNotLinkedToAThirpartyLinkOrCreateFirst");
- setEventMessages($errmsg, null, 'errors');
- $error++;
- }
- }
- if (! $error)
- {
- $result=$customer->fetch($object->fk_soc);
- if ($result <= 0)
- {
- $errmsg=$customer->error;
- $errmsgs=$acct->errors;
- setEventMessages($errmsg, $errmsgs, 'errors');
- $error++;
- }
- }
-
- if (! $error)
- {
- // Create draft invoice
- $invoice->type= Facture::TYPE_STANDARD;
- $invoice->cond_reglement_id=$customer->cond_reglement_id;
- if (empty($invoice->cond_reglement_id))
- {
- $paymenttermstatic=new PaymentTerm($db);
- $invoice->cond_reglement_id=$paymenttermstatic->getDefaultId();
- if (empty($invoice->cond_reglement_id))
- {
- $error++;
- $errmsg='ErrorNoPaymentTermRECEPFound';
- setEventMessages($errmsg, null, 'errors');
- }
- }
- $invoice->socid=$object->fk_soc;
- $invoice->date=$datesubscription;
-
- // Possibility to add external linked objects with hooks
- $invoice->linked_objects['subscription'] = $crowid;
- if (! empty($_POST['other_linked_objects']) && is_array($_POST['other_linked_objects']))
- {
- $invoice->linked_objects = array_merge($invoice->linked_objects, $_POST['other_linked_objects']);
- }
-
- $result=$invoice->create($user);
- if ($result <= 0)
- {
- $errmsg=$invoice->error;
- $errmsgs=$invoice->errors;
- setEventMessages($errmsg, $errmsgs, 'errors');
- $error++;
- }
- }
-
- if (! $error)
- {
- // Add line to draft invoice
- $idprodsubscription=0;
- if (! empty($conf->global->ADHERENT_PRODUCT_ID_FOR_SUBSCRIPTIONS) && (! empty($conf->product->enabled) || ! empty($conf->service->enabled))) $idprodsubscription = $conf->global->ADHERENT_PRODUCT_ID_FOR_SUBSCRIPTIONS;
-
- $vattouse=0;
- if (isset($conf->global->ADHERENT_VAT_FOR_SUBSCRIPTIONS) && $conf->global->ADHERENT_VAT_FOR_SUBSCRIPTIONS == 'defaultforfoundationcountry')
- {
- $vattouse=get_default_tva($mysoc, $mysoc, $idprodsubscription);
- }
- //print xx".$vattouse." - ".$mysoc." - ".$customer;exit;
- $result=$invoice->addline($label,0,1,$vattouse,0,0,$idprodsubscription,0,$datesubscription,$datesubend,0,0,'','TTC',$subscription,1);
- if ($result <= 0)
- {
- $errmsg=$invoice->error;
- setEventMessages($errmsg, null, 'errors');
- $error++;
- }
- }
-
- if (! $error)
- {
- // Validate invoice
- $result=$invoice->validate($user);
- if ($result <= 0)
- {
- $errmsg=$invoice->error;
- $errmsgs=$invoice->errors;
- setEventMessages($errmsg, $errmsgs, 'errors');
- $error++;
- }
- }
-
- // Add payment onto invoice
- if ($option == 'bankviainvoice' && $accountid)
- {
- require_once DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php';
- require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
- require_once DOL_DOCUMENT_ROOT.'/core/lib/functions.lib.php';
-
- $amounts[$invoice->id] = price2num($subscription);
- $paiement = new Paiement($db);
- $paiement->datepaye = $paymentdate;
- $paiement->amounts = $amounts;
- $paiement->paiementid = dol_getIdFromCode($db,$operation,'c_paiement','code','id',1);
- $paiement->num_paiement = $num_chq;
- $paiement->note = $label;
-
- if (! $error)
- {
- // Create payment line for invoice
- $paiement_id = $paiement->create($user);
- if (! $paiement_id > 0)
- {
- $errmsg=$paiement->error;
- $errmsgs=$paiement->errors;
- setEventMessages($errmsg, $errmsgs, 'errors');
- $error++;
- }
- }
-
- if (! $error)
- {
- // Add transaction into bank account
- $bank_line_id=$paiement->addPaymentToBank($user,'payment','(SubscriptionPayment)',$accountid,$emetteur_nom,$emetteur_banque);
- if (! ($bank_line_id > 0))
- {
- $errmsg=$paiement->error;
- $errmsgs=$paiement->errors;
- setEventMessages($paiement->error, $paiement->errors, 'errors');
- $error++;
- }
- }
-
- if (! $error)
- {
- // Update fk_bank into subscription table
- $sql = 'UPDATE '.MAIN_DB_PREFIX.'subscription SET fk_bank='.$bank_line_id;
- $sql.= ' WHERE rowid='.$crowid;
-
- $result = $db->query($sql);
- if (! $result)
- {
- $error++;
- }
- }
-
- if (! $error)
- {
- // 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);
- }
- }
- }
+ $result = $object->subscriptionComplementaryActions($crowid, $option, $accountid, $datesubscription, $paymentdate, $operation, $label, $amount, $num_chq, $emetteur_nom, $emetteur_banque);
+ if ($result < 0)
+ {
+ $error++;
+ setEventMessages($object->error, $object->errors, 'errors');
+ }
}
if (! $error)
@@ -557,7 +337,7 @@ if ($user->rights->adherent->cotisation->creer && $action == 'subscription' && !
if (! $error)
{
// Send confirmation Email
- if ($object->email && $_POST["sendmail"])
+ if ($object->email && $sendalsoemail)
{
$subjecttosend=$object->makeSubstitution($conf->global->ADHERENT_MAIL_COTIS_SUBJECT);
$texttosend=$object->makeSubstitution($adht->getMailOnSubscription());
@@ -569,7 +349,11 @@ if ($user->rights->adherent->cotisation->creer && $action == 'subscription' && !
setEventMessages($errmsg, null, 'errors');
}
}
+ }
+ // Clean some POST vars
+ if (! $error)
+ {
$_POST["subscription"]='';
$_POST["accountid"]='';
$_POST["operation"]='';
@@ -933,7 +717,7 @@ if ($rowid > 0)
print load_fiche_titre($langs->trans("NewCotisation"));
- // Define default choice to select
+ // Define default choice for complementary actions
$bankdirect=0; // 1 means option by default is write to bank direct with no invoice
$invoiceonly=0; // 1 means option by default is invoice only
$bankviainvoice=0; // 1 means option by default is write to bank via invoice
@@ -944,11 +728,11 @@ if ($rowid > 0)
if (GETPOST('paymentsave') == 'bankviainvoice') $bankviainvoice=1;
}
else
- {
+ {
if (! empty($conf->global->ADHERENT_BANK_USE) && $conf->global->ADHERENT_BANK_USE == 'bankviainvoice' && ! empty($conf->banque->enabled) && ! empty($conf->societe->enabled) && ! empty($conf->facture->enabled)) $bankviainvoice=1;
- else if (! empty($conf->global->ADHERENT_BANK_USE) && $conf->global->ADHERENT_BANK_USE == 'bankdirect' && ! empty($conf->banque->enabled)) $bankdirect=1;
+ else if (! empty($conf->global->ADHERENT_BANK_USE) && $conf->global->ADHERENT_BANK_USE == 'bankdirect' && ! empty($conf->banque->enabled)) $bankdirect=1;
else if (! empty($conf->global->ADHERENT_BANK_USE) && $conf->global->ADHERENT_BANK_USE == 'invoiceonly' && ! empty($conf->banque->enabled) && ! empty($conf->societe->enabled) && ! empty($conf->facture->enabled)) $invoiceonly=1;
- }
+ }
print "\n\n\n";
@@ -1047,15 +831,11 @@ if ($rowid > 0)
}
if (! $datefrom)
{
- if ($object->datefin > 0)
+ $datefrom=$object->datevalid;
+ if ($object->datefin > 0)
{
$datefrom=dol_time_plus_duree($object->datefin,1,'d');
}
- else
- {
- //$datefrom=dol_now();
- $datefrom=$object->datevalid;
- }
}
print $form->select_date($datefrom,'','','','',"subscription",1,1,1);
print "";
@@ -1207,7 +987,7 @@ if ($rowid > 0)
$subjecttosend=$object->makeSubstitution($conf->global->ADHERENT_MAIL_COTIS_SUBJECT);
$texttosend=$object->makeSubstitution($adht->getMailOnSubscription());
- $tmp='global->ADHERENT_DEFAULT_SENDINFOBYMAIL)?' checked':'')).'>';
+ $tmp='global->ADHERENT_DEFAULT_SENDINFOBYMAIL)?' checked':'')).'>';
$helpcontent='';
$helpcontent.=''.$langs->trans("MailFrom").': '.$conf->global->ADHERENT_MAIL_FROM.'
'."\n";
$helpcontent.=''.$langs->trans("MailRecipient").': '.$object->email.'
'."\n";
diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php
index d514bbaf603..c9bc13eefe4 100644
--- a/htdocs/compta/facture/class/facture.class.php
+++ b/htdocs/compta/facture/class/facture.class.php
@@ -239,7 +239,7 @@ class Facture extends CommonInvoice
* @param int $forceduedate 1=Do not recalculate due date from payment condition but force it with value
* @return int <0 if KO, >0 if OK
*/
- function create($user,$notrigger=0,$forceduedate=0)
+ function create(User $user, $notrigger=0, $forceduedate=0)
{
global $langs,$conf,$mysoc,$hookmanager;
$error=0;
@@ -265,13 +265,13 @@ class Facture extends CommonInvoice
$this->multicurrency_tx = 1;
}
- dol_syslog(get_class($this)."::create user=".$user->id);
+ dol_syslog(get_class($this)."::create user=".$user->id." date=".$this->date);
// Check parameters
- if (empty($this->date) || empty($user->id))
+ if (empty($this->date))
{
- $this->error="ErrorBadParameter";
- dol_syslog(get_class($this)."::create Try to create an invoice with an empty parameter (user, date, ...)", LOG_ERR);
+ $this->error="Try to create an invoice with an empty parameter (date)";
+ dol_syslog(get_class($this)."::create ".$this->error, LOG_ERR);
return -3;
}
$soc = new Societe($this->db);
diff --git a/htdocs/public/payment/newpayment.php b/htdocs/public/payment/newpayment.php
index 350a73d3571..37873033535 100644
--- a/htdocs/public/payment/newpayment.php
+++ b/htdocs/public/payment/newpayment.php
@@ -285,10 +285,18 @@ if ($action == 'dopayment')
$desc=GETPOST("desc",'alpha');
$mesg='';
- if (empty($PAYPAL_API_PRICE) || ! is_numeric($PAYPAL_API_PRICE)) $mesg=$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Amount"));
+ if (empty($PAYPAL_API_PRICE) || ! is_numeric($PAYPAL_API_PRICE))
+ {
+ $mesg=$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Amount"));
+ $action='';
+ }
//elseif (empty($EMAIL)) $mesg=$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("YourEMail"));
//elseif (! isValidEMail($EMAIL)) $mesg=$langs->trans("ErrorBadEMail",$EMAIL);
- elseif (! $origfulltag) $mesg=$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("PaymentCode"));
+ elseif (! $origfulltag)
+ {
+ $mesg=$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("PaymentCode"));
+ $action='';
+ }
//var_dump($_POST);
if (empty($mesg))
diff --git a/htdocs/public/payment/paymentok.php b/htdocs/public/payment/paymentok.php
index 7e5413e6509..5e3ba33949c 100644
--- a/htdocs/public/payment/paymentok.php
+++ b/htdocs/public/payment/paymentok.php
@@ -271,21 +271,136 @@ $ispostactionok = 0;
$postactionmessages = array();
if ($ispaymentok)
{
+ // Set permission for the anonymous user
+ $user->rights->societe->creer = 1;
+ $user->rights->facture->creer = 1;
+ $user->rights->adherent->cotisation->creer = 1;
+
if (in_array('MEM', array_keys($tmptag)))
{
+ $defaultdelay=1;
+ $defaultdelayunit='y';
+
// Record subscription
include_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
- $member = new Adherent($db);
- $result = $member->fetch(0, $tmptag['MEM']);
- if ($result)
- {
- if (empty($paymentType)) $paymentType = 'CB';
- $paymentTypeId = dol_getIdFromCode($db, $paymentType,'c_paiement','code','id',1);
+ include_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent_type.class.php';
+ include_once DOL_DOCUMENT_ROOT.'/adherents/class/subscription.class.php';
+ $adht = new AdherentType($db);
+ $object = new Adherent($db);
+ $result1 = $object->fetch(0, $tmptag['MEM']);
+ $result2 = $adht->fetch($object->typeid);
+
+ if ($result1 > 0 && $result2 > 0)
+ {
+ $paymentTypeId = 0;
+ if ($paymentmethod == 'paybox') $paymentTypeId = $conf->global->PAYBOX_PAYMENT_MODE_FOR_PAYMENTS;
+ if ($paymentmethod == 'paypal') $paymentTypeId = $conf->global->PAYPAL_PAYMENT_MODE_FOR_PAYMENTS;
+ if ($paymentmethod == 'stripe') $paymentTypeId = $conf->global->STRIPE_PAYMENT_MODE_FOR_PAYMENTS;
+ if (empty($paymentTypeId))
+ {
+ $paymentType = $_SESSION["paymentType"];
+ if (empty($paymentType)) $paymentType = 'CB';
+ $paymentTypeId = dol_getIdFromCode($db, $paymentType, 'c_paiement', 'code', 'id', 1);
+ }
+
+ $currencyCodeType = $_SESSION['currencyCodeType'];
+
+ // Do action only if $FinalPaymentAmt is set (session variable is cleaned after this page to avoid duplicate actions when page is POST a second time)
if (! empty($FinalPaymentAmt) && $paymentTypeId > 0)
{
+ // Subscription informations
+ $datesubscription=$object->datevalid;
+ if ($object->datefin > 0)
+ {
+ $datesubscription=dol_time_plus_duree($object->datefin,1,'d');
+ }
+ $datesubend=dol_time_plus_duree(dol_time_plus_duree($datesubscription,$defaultdelay,$defaultdelayunit),-1,'d');
+ $paymentdate=$now;
+ $amount = $FinalPaymentAmt;
+ $label='Online subscription '.dol_print_date($now, 'standard');
+ // Payment informations
+ $accountid = 0;
+ if ($paymentmethod == 'paybox') $accountid = $conf->global->PAYBOX_BANK_ACCOUNT_FOR_PAYMENTS;
+ if ($paymentmethod == 'paypal') $accountid = $conf->global->PAYPAL_BANK_ACCOUNT_FOR_PAYMENTS;
+ if ($paymentmethod == 'stripe') $accountid = $conf->global->STRIPE_BANK_ACCOUNT_FOR_PAYMENTS;
+ $operation=$paymentTypeId; // Payment mode
+ $num_chq='';
+ $emetteur_nom='';
+ $emetteur_banque='';
+ // Define default choice for complementary actions
+ $option='';
+ if (! empty($conf->global->ADHERENT_BANK_USE) && $conf->global->ADHERENT_BANK_USE == 'bankviainvoice' && ! empty($conf->banque->enabled) && ! empty($conf->societe->enabled) && ! empty($conf->facture->enabled)) $option='bankviainvoice';
+ else if (! empty($conf->global->ADHERENT_BANK_USE) && $conf->global->ADHERENT_BANK_USE == 'bankdirect' && ! empty($conf->banque->enabled)) $option='bankdirect';
+ else if (! empty($conf->global->ADHERENT_BANK_USE) && $conf->global->ADHERENT_BANK_USE == 'invoiceonly' && ! empty($conf->banque->enabled) && ! empty($conf->societe->enabled) && ! empty($conf->facture->enabled)) $option='invoiceonly';
+ if (empty($option)) $option='none';
+ $sendalsoemail = 1;
+ // Record the subscription then complementary actions
+ $db->begin();
+
+ // Create subscription
+ $crowid=$object->subscription($datesubscription, $amount, $accountid, $operation, $label, $num_chq, $emetteur_nom, $emetteur_banque, $datesubend);
+ if ($crowid <= 0)
+ {
+ $error++;
+ $errmsg=$object->error;
+ $postactionmessages[] = $errmsg;
+ $ispostactionok = -1;
+ }
+ else
+ {
+ $postactionmessages[]='Subscription created';
+ $ispostactionok=1;
+ }
+
+ if (! $error)
+ {
+ $result = $object->subscriptionComplementaryActions($crowid, $option, $accountid, $datesubscription, $paymentdate, $operation, $label, $amount, $num_chq, $emetteur_nom, $emetteur_banque, 1);
+ if ($result < 0)
+ {
+ $error++;
+ $postactionmessages[] = $object->error;
+ $postactionmessages = array_merge($postactionmessages, $object->errors);
+ $ispostactionok = -1;
+ }
+ else
+ {
+ if ($option == 'bankviainvoice') $postactionmessages[] = 'Invoice, payment and bank record created';
+ if ($option == 'bankdirect') $postactionmessages[] = 'Bank record created';
+ if ($option == 'invoiceonly') $postactionmessages[] = 'Invoice recorded';
+ $ispostactionok = 1;
+ }
+ }
+
+ if (! $error)
+ {
+ $db->commit();
+ }
+ else
+ {
+ $db->rollback();
+ }
+
+ // Send email
+ if (! $error)
+ {
+ // Send confirmation Email
+ if ($object->email && $sendalsoemail)
+ {
+ $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);
+ if ($result < 0)
+ {
+ $errmsg=$object->error;
+ $postactionmessages[] = $errmsg;
+ $ispostactionok = -1;
+ }
+ }
+ }
}
else
{
@@ -295,7 +410,7 @@ if ($ispaymentok)
}
else
{
- $postactionmessages[] = 'Member for subscription payed '.$tmptag['MEM'].' was not found';
+ $postactionmessages[] = 'Member '.$tmptag['MEM'].' for subscription payed was not found';
$ispostactionok = -1;
}
}
@@ -322,8 +437,11 @@ if ($ispaymentok)
$currencyCodeType = $_SESSION['currencyCodeType'];
+ // Do action only if $FinalPaymentAmt is set (session variable is cleaned after this page to avoid duplicate actions when page is POST a second time)
if (! empty($FinalPaymentAmt) && $paymentTypeId > 0)
{
+ $db->begin();
+
// Creation of payment line
include_once DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php';
$paiement = new Paiement($db);
@@ -644,6 +762,7 @@ htmlPrintOnlinePaymentFooter($mysoc,$langs,0,$suffix);
unset($_SESSION["FinalPaymentAmt"]);
unset($_SESSION["TRANSACTIONID"]);
+
llxFooter('', 'public');
$db->close();
diff --git a/htdocs/societe/class/societe.class.php b/htdocs/societe/class/societe.class.php
index db614ed833e..94b686c3b35 100644
--- a/htdocs/societe/class/societe.class.php
+++ b/htdocs/societe/class/societe.class.php
@@ -3102,6 +3102,8 @@ class Societe extends CommonObject
{
global $user,$langs;
+ dol_syslog(get_class($this)."::create_from_member", LOG_DEBUG);
+
$name = $socname?$socname:$member->societe;
if (empty($name)) $name=$member->getFullName($langs);
@@ -3134,7 +3136,6 @@ class Societe extends CommonObject
$sql.= " SET fk_soc=".$this->id;
$sql.= " WHERE rowid=".$member->id;
- dol_syslog(get_class($this)."::create_from_member", LOG_DEBUG);
$resql=$this->db->query($sql);
if ($resql)
{