diff --git a/htdocs/adherents/admin/member.php b/htdocs/adherents/admin/member.php index 3d40f8d758b..73770f38905 100644 --- a/htdocs/adherents/admin/member.php +++ b/htdocs/adherents/admin/member.php @@ -33,6 +33,7 @@ require '../../main.inc.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/member.lib.php'; +require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent_type.class.php'; // Load translation files required by the page $langs->loadLangs(array("admin", "members")); @@ -101,11 +102,12 @@ if ($action == 'set_default') { } } elseif ($action == 'updateall') { $db->begin(); - $res1 = $res2 = $res3 = $res4 = $res5 = $res6 = 0; + $res1 = $res2 = $res3 = $res4 = $res5 = $res6 = $res7 = 0; $res1 = dolibarr_set_const($db, 'ADHERENT_LOGIN_NOT_REQUIRED', GETPOST('ADHERENT_LOGIN_NOT_REQUIRED', 'alpha') ? 0 : 1, 'chaine', 0, '', $conf->entity); $res2 = dolibarr_set_const($db, 'ADHERENT_MAIL_REQUIRED', GETPOST('ADHERENT_MAIL_REQUIRED', 'alpha'), 'chaine', 0, '', $conf->entity); $res3 = dolibarr_set_const($db, 'ADHERENT_DEFAULT_SENDINFOBYMAIL', GETPOST('ADHERENT_DEFAULT_SENDINFOBYMAIL', 'alpha'), 'chaine', 0, '', $conf->entity); $res4 = dolibarr_set_const($db, 'ADHERENT_BANK_USE', GETPOST('ADHERENT_BANK_USE', 'alpha'), 'chaine', 0, '', $conf->entity); + $res7 = dolibarr_set_const($db, "MEMBER_SUBSCRIPTION_AMOUNT_BY_TYPE", json_encode(GETPOST('MEMBER_SUBSCRIPTION_AMOUNT_BY_TYPE')), 'array', 0, '', $conf->entity); // Use vat for invoice creation if ($conf->facture->enabled) { $res4 = dolibarr_set_const($db, 'ADHERENT_VAT_FOR_SUBSCRIPTIONS', GETPOST('ADHERENT_VAT_FOR_SUBSCRIPTIONS', 'alpha'), 'chaine', 0, '', $conf->entity); @@ -217,6 +219,18 @@ print ''.$langs->trans("MemberSendInformationByMailByDef print $form->selectyesno('ADHERENT_DEFAULT_SENDINFOBYMAIL', (!empty($conf->global->ADHERENT_DEFAULT_SENDINFOBYMAIL) ? $conf->global->ADHERENT_DEFAULT_SENDINFOBYMAIL : 0), 1); print "\n"; + +// Amount by member type +$adht = new AdherentType($db); +$amountbytype = empty($conf->global->MEMBER_SUBSCRIPTION_AMOUNT_BY_TYPE) ? -1 : json_decode($conf->global->MEMBER_SUBSCRIPTION_AMOUNT_BY_TYPE, true); +print ''.$langs->trans("DefineAmountMemberType").''; +foreach ($adht->liste_array(1) as $typeid => $type){ + print $type .' : '; + print ''; + print '
'; +} +print "\n"; + // Insert subscription into bank account print ''.$langs->trans("MoreActionsOnSubscription").''; $arraychoices = array('0'=>$langs->trans("None")); diff --git a/htdocs/adherents/admin/website.php b/htdocs/adherents/admin/website.php index d4f2df25c0c..8b32e79526d 100644 --- a/htdocs/adherents/admin/website.php +++ b/htdocs/adherents/admin/website.php @@ -177,7 +177,7 @@ if (!empty($conf->global->MEMBER_ENABLE_PUBLIC)) { print $langs->trans("ForceMemberType"); print ''; $listofval = array(); - $listofval += $adht->liste_array(); + $listofval += $adht->liste_array(1); $forcetype = empty($conf->global->MEMBER_NEWFORM_FORCETYPE) ? -1 : $conf->global->MEMBER_NEWFORM_FORCETYPE; print $form->selectarray("MEMBER_NEWFORM_FORCETYPE", $listofval, $forcetype, count($listofval) > 1 ? 1 : 0); print "\n"; diff --git a/htdocs/adherents/class/adherent.class.php b/htdocs/adherents/class/adherent.class.php index 79fef823883..f7a87e9bf0c 100644 --- a/htdocs/adherents/class/adherent.class.php +++ b/htdocs/adherents/class/adherent.class.php @@ -1490,9 +1490,11 @@ class Adherent extends CommonObject * @param string $emetteur_nom Name of cheque writer * @param string $emetteur_banque Name of bank of cheque * @param int $datesubend Date end subscription + * @param int fk_type Member type id + * * @return int rowid of record added, <0 if KO */ - public function subscription($date, $amount, $accountid = 0, $operation = '', $label = '', $num_chq = '', $emetteur_nom = '', $emetteur_banque = '', $datesubend = 0) + public function subscription($date, $amount, $accountid = 0, $operation = '', $label = '', $num_chq = '', $emetteur_nom = '', $emetteur_banque = '', $datesubend = 0, $fk_type = NULL) { global $conf, $langs, $user; @@ -1523,6 +1525,7 @@ class Adherent extends CommonObject $subscription->amount = $amount; $subscription->note = $label; // deprecated $subscription->note_public = $label; + $subscription->fk_type = $fk_type; $rowid = $subscription->create($user); if ($rowid > 0) { diff --git a/htdocs/langs/en_US/members.lang b/htdocs/langs/en_US/members.lang index 31d0790b331..7f36f759bb1 100644 --- a/htdocs/langs/en_US/members.lang +++ b/htdocs/langs/en_US/members.lang @@ -169,6 +169,7 @@ DocForLabels=Generate address sheets SubscriptionPayment=Subscription payment LastSubscriptionDate=Date of latest subscription payment LastSubscriptionAmount=Amount of latest subscription +LastMemberType=Last Member type MembersStatisticsByCountries=Members statistics by country MembersStatisticsByState=Members statistics by state/province MembersStatisticsByTown=Members statistics by town diff --git a/htdocs/langs/fr_FR/members.lang b/htdocs/langs/fr_FR/members.lang index ea52dc21d7a..a541c347adb 100644 --- a/htdocs/langs/fr_FR/members.lang +++ b/htdocs/langs/fr_FR/members.lang @@ -162,6 +162,7 @@ DocForLabels=Génération d'étiquettes d'adresses SubscriptionPayment=Paiement cotisation LastSubscriptionDate=Date de dernière adhésion LastSubscriptionAmount=Montant dernière adhésion +LastMemberType=Ancien type de membre MembersStatisticsByCountries=Statistiques des membres par pays MembersStatisticsByState=Statistiques des membres par département/province/canton MembersStatisticsByTown=Statistiques des membres par ville diff --git a/htdocs/public/payment/newpayment.php b/htdocs/public/payment/newpayment.php index 486223b0293..d55a8add8ea 100644 --- a/htdocs/public/payment/newpayment.php +++ b/htdocs/public/payment/newpayment.php @@ -1437,6 +1437,39 @@ if ($source == 'membersubscription') { $_GET['newamount'] = $member->last_subscription_amount; } } + + if ($member->type) { + // Last member type + print ''.$langs->trans("LastMemberType"); + print ''.dol_escape_htmltag($member->type); + print ""."\n"; + } + + if (!empty($conf->global->MEMBER_SUBSCRIPTION_AMOUNT_BY_TYPE)) { + // Amount by member type + $amountbytype = json_decode($conf->global->MEMBER_SUBSCRIPTION_AMOUNT_BY_TYPE, true); + // Set the member type + $member->typeid = (int)(GETPOSTISSET("typeid") ? GETPOST("typeid", 'int') : $member->typeid); + // If we change the type of membership, we set also label of new type + $member->type = dol_getIdFromCode($db, $member->typeid, 'adherent_type', 'rowid', 'libelle'); + // Set amount for the subscription + $amount = $amountbytype[$member->typeid] ? $amountbytype[$member->typeid] : $member->last_subscription_amount; + // list member type + require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent_type.class.php'; + $adht = new AdherentType($db); + if( !$action){ + $form = new Form($db); // so wecan call method selectarray + print ''.$langs->trans("NewSubscription"); + print ''; + print $form->selectarray("typeid", $adht->liste_array(1) , $member->typeid, 0, 0, 0, 'onchange="window.location.replace(\''.$urlwithroot.'/public/payment/newpayment.php?source='.$source.'&ref='.$ref.'&amount='.$amount.'&typeid=\' + this.value + \'&securekey='.$SECUREKEY.'\');"', 0, 0, 0, '', '', 1); + print ""."\n"; + } elseif ($action == dopayment) { + print ''.$langs->trans("NewMemberType"); + print ''.dol_escape_htmltag($member->type); + print ''; + print ""."\n"; + } + } // Amount print ''.$langs->trans("Amount"); diff --git a/htdocs/public/payment/paymentok.php b/htdocs/public/payment/paymentok.php index 99a97e0c321..bf957d4cf6b 100644 --- a/htdocs/public/payment/paymentok.php +++ b/htdocs/public/payment/paymentok.php @@ -98,10 +98,11 @@ $FULLTAG = GETPOST('FULLTAG'); if (empty($FULLTAG)) { $FULLTAG = GETPOST('fulltag'); } -$source = GETPOST('s', 'alpha') ?GETPOST('s', 'alpha') : GETPOST('source', 'alpha'); +$source = GETPOST('s', 'alpha') ? GETPOST('s', 'alpha') : GETPOST('source', 'alpha'); $ref = GETPOST('ref'); $suffix = GETPOST("suffix", 'aZ09'); +$membertypeid = GETPOST("membertypeid", 'int'); // Detect $paymentmethod @@ -339,7 +340,8 @@ if ($ispaymentok) { $user->rights->facture = new stdClass(); } if (empty($user->rights->adherent)) { - $user->rights->adherent = new stdClass(); $user->rights->adherent->cotisation = new stdClass(); + $user->rights->adherent = new stdClass(); + $user->rights->adherent->cotisation = new stdClass(); } $user->rights->societe->creer = 1; $user->rights->facture->creer = 1; @@ -460,7 +462,7 @@ if ($ispaymentok) { if (!$error) { dol_syslog("Call ->subscription to create subscription", LOG_DEBUG, 0, '_payment'); - $crowid = $object->subscription($datesubscription, $amount, $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, $membertypeid); if ($crowid <= 0) { $error++; $errmsg = $object->error;