From 5998999f18741ec3a7c9f439231054e59ef0aa8c Mon Sep 17 00:00:00 2001 From: Yoan Mollard Date: Tue, 28 Jun 2022 02:33:17 +0200 Subject: [PATCH] NEW: Add free membership amounts at the membership type level --- .../adherents/class/adherent_type.class.php | 10 +++++- htdocs/adherents/type.php | 10 +++++- htdocs/core/lib/payments.lib.php | 4 ++- .../install/mysql/migration/15.0.0-16.0.0.sql | 3 +- htdocs/langs/en_US/members.lang | 3 ++ htdocs/langs/fr_FR/members.lang | 3 ++ htdocs/public/members/new.php | 31 ++++++++++++++----- 7 files changed, 52 insertions(+), 12 deletions(-) diff --git a/htdocs/adherents/class/adherent_type.class.php b/htdocs/adherents/class/adherent_type.class.php index 3f857ce827b..38641c8664b 100644 --- a/htdocs/adherents/class/adherent_type.class.php +++ b/htdocs/adherents/class/adherent_type.class.php @@ -94,6 +94,11 @@ class AdherentType extends CommonObject */ public $amount; + /** + * @var int Amount can be choosen by the visitor during subscription (0 or 1) + */ + public $caneditamount; + /** * @var string Public note * @deprecated @@ -380,6 +385,7 @@ class AdherentType extends CommonObject $sql .= "morphy = '".$this->db->escape($this->morphy)."',"; $sql .= "subscription = '".$this->db->escape($this->subscription)."',"; $sql .= "amount = ".((empty($this->amount) && $this->amount == '') ? 'null' : ((float) $this->amount)).","; + $sql .= "caneditamount = '".$this->db->escape($this->caneditamount)."',"; $sql .= "duration = '".$this->db->escape($this->duration_value.$this->duration_unit)."',"; $sql .= "note = '".$this->db->escape($this->note_public)."',"; $sql .= "vote = ".(integer) $this->db->escape($this->vote).","; @@ -474,7 +480,7 @@ class AdherentType extends CommonObject { global $langs, $conf; - $sql = "SELECT d.rowid, d.libelle as label, d.morphy, d.statut as status, d.duration, d.subscription, d.amount, d.mail_valid, d.note as note_public, d.vote"; + $sql = "SELECT d.rowid, d.libelle as label, d.morphy, d.statut as status, d.duration, d.subscription, d.amount, d.caneditamount, d.mail_valid, d.note as note_public, d.vote"; $sql .= " FROM ".MAIN_DB_PREFIX."adherent_type as d"; $sql .= " WHERE d.rowid = ".(int) $rowid; @@ -495,6 +501,7 @@ class AdherentType extends CommonObject $this->duration_unit = substr($obj->duration, -1); $this->subscription = $obj->subscription; $this->amount = $obj->amount; + $this->caneditamount = $obj->caneditamount; $this->mail_valid = $obj->mail_valid; $this->note = $obj->note_public; // deprecated $this->note_public = $obj->note_public; @@ -850,6 +857,7 @@ class AdherentType extends CommonObject $this->note_public = 'This is a public note'; $this->mail_valid = 'This is welcome email'; $this->subscription = 1; + $this->caneditamount = 0; $this->vote = 0; $this->status = 1; diff --git a/htdocs/adherents/type.php b/htdocs/adherents/type.php index bcd6c99afbf..0b54132b5d0 100644 --- a/htdocs/adherents/type.php +++ b/htdocs/adherents/type.php @@ -122,6 +122,7 @@ if ($action == 'add' && $user->rights->adherent->configurer) { $object->status = (int) $status; $object->subscription = (int) $subscription; $object->amount = ($amount == '' ? '' : price2num($amount, 'MT')); + $object->caneditamount = (int) GETPOST("caneditamount", 'int'); $object->duration_value = $duration_value; $object->duration_unit = $duration_unit; $object->note = trim($comment); @@ -229,7 +230,7 @@ llxHeader('', $langs->trans("MembersTypeSetup"), $help_url); if (!$rowid && $action != 'create' && $action != 'edit') { //print dol_get_fiche_head(''); - $sql = "SELECT d.rowid, d.libelle as label, d.subscription, d.amount, d.vote, d.statut as status, d.morphy"; + $sql = "SELECT d.rowid, d.libelle as label, d.subscription, d.amount, d.caneditamount, d.vote, d.statut as status, d.morphy"; $sql .= " FROM ".MAIN_DB_PREFIX."adherent_type as d"; $sql .= " WHERE d.entity IN (".getEntity('member_type').")"; @@ -276,6 +277,7 @@ if (!$rowid && $action != 'create' && $action != 'edit') { print ''.$langs->trans("MembersNature").''; print ''.$langs->trans("SubscriptionRequired").''; print ''.$langs->trans("Amount").''; + print ''.$langs->trans("CanEditAmountShort").''; print ''.$langs->trans("VoteAllowed").''; print ''.$langs->trans("Status").''; print ' '; @@ -292,6 +294,7 @@ if (!$rowid && $action != 'create' && $action != 'edit') { $membertype->status = $objp->status; $membertype->subscription = $objp->subscription; $membertype->amount = $objp->amount; + $membertype->caneditamount = $objp->caneditamount; print ''; print ''; @@ -310,6 +313,7 @@ if (!$rowid && $action != 'create' && $action != 'edit') { print ''; print ''.yn($objp->subscription).''; print ''.(is_null($objp->amount) || $objp->amount === '' ? '' : price($objp->amount)).''; + print ''.yn($objp->caneditamount).''; print ''.yn($objp->vote).''; print ''.$membertype->getLibStatut(5).''; if ($user->rights->adherent->configurer) { @@ -380,6 +384,10 @@ if ($action == 'create') { print ''; print ''; + print ''.$langs->trans("CanEditAmountShort").''; + print $form->selectyesno("caneditamount", 0, 1); + print ''; + print ''.$langs->trans("VoteAllowed").''; print $form->selectyesno("vote", GETPOSTISSET("vote") ? GETPOST('vote', 'aZ09') : 1, 1); print ''; diff --git a/htdocs/core/lib/payments.lib.php b/htdocs/core/lib/payments.lib.php index 2911564adef..c006c4b9c9f 100644 --- a/htdocs/core/lib/payments.lib.php +++ b/htdocs/core/lib/payments.lib.php @@ -318,7 +318,9 @@ function getOnlinePaymentUrl($mode, $type, $ref = '', $amount = '9.99', $freetag } } elseif ($type == 'member' || $type == 'membersubscription') { $newtype = 'member'; - $out = $urltouse.'/public/payment/newpayment.php?source=member&ref='.($mode ? '' : ''); + $out = $urltouse.'/public/payment/newpayment.php?source=member'; + $out .= '&amount='.$amount; + $out .= '&ref='.($mode ? '' : ''); if ($mode == 1) { $out .= 'member_ref'; } diff --git a/htdocs/install/mysql/migration/15.0.0-16.0.0.sql b/htdocs/install/mysql/migration/15.0.0-16.0.0.sql index b57cab5b4eb..c465151f9c2 100644 --- a/htdocs/install/mysql/migration/15.0.0-16.0.0.sql +++ b/htdocs/install/mysql/migration/15.0.0-16.0.0.sql @@ -648,4 +648,5 @@ ALTER TABLE llx_paiement MODIFY COLUMN ext_payment_id varchar(255); ALTER TABLE llx_payment_donation MODIFY COLUMN ext_payment_id varchar(255); ALTER TABLE llx_prelevement_facture_demande MODIFY COLUMN ext_payment_id varchar(255); - +-- Allow users to make subscriptions of any amount during membership subscription +ALTER TABLE llx_adherent_type ADD COLUMN caneditamount varchar(3) DEFAULT 0 AFTER amount; diff --git a/htdocs/langs/en_US/members.lang b/htdocs/langs/en_US/members.lang index fafa1a60400..e552755f705 100644 --- a/htdocs/langs/en_US/members.lang +++ b/htdocs/langs/en_US/members.lang @@ -71,6 +71,9 @@ MemberTypeCanNotBeDeleted=Member type can not be deleted NewSubscription=New contribution NewSubscriptionDesc=This form allows you to record your subscription as a new member of the foundation. If you want to renew your subscription (if already a member), please contact foundation board instead by email %s. Subscription=Contribution +AnyAmountWithAdvisedAmount=Any amount with a recommended amount of %s %s +AnyAmountWithoutAdvisedAmount=Any amount +CanEditAmountShort=Any amount Subscriptions=Contributions SubscriptionLate=Late SubscriptionNotReceived=Contribution never received diff --git a/htdocs/langs/fr_FR/members.lang b/htdocs/langs/fr_FR/members.lang index a6f805daca6..5f67cc681ab 100644 --- a/htdocs/langs/fr_FR/members.lang +++ b/htdocs/langs/fr_FR/members.lang @@ -199,6 +199,9 @@ AmountOfSubscriptions=Montant des cotisations TurnoverOrBudget=Chiffre affaire (pour société) ou Budget (asso ou collectivité) DefaultAmount=Montant par défaut de la cotisation CanEditAmount=Le visiteur peut modifier / choisir le montant de sa cotisation +AnyAmountWithAdvisedAmount=Montant libre avec un montant recommandé de %s %s +AnyAmountWithoutAdvisedAmount=Montant libre +CanEditAmountShort=Montant libre MEMBER_NEWFORM_PAYONLINE=Rediriger sur la page intégrée de paiement en ligne ByProperties=Par nature MembersStatisticsByProperties=Statistiques des adhérents par nature diff --git a/htdocs/public/members/new.php b/htdocs/public/members/new.php index 654fce78ccc..f6957502284 100644 --- a/htdocs/public/members/new.php +++ b/htdocs/public/members/new.php @@ -692,16 +692,31 @@ if (!empty($conf->global->MEMBER_NEWFORM_PAYONLINE)) { // Clean the amount $amount = price2num($amount); - + $adht = new AdherentType($db); + $adht->fetch($typeid); + $caneditamount = $adht->caneditamount; + $showedamount = $amount>0? $amount: 0; // $conf->global->MEMBER_NEWFORM_PAYONLINE is 'paypal', 'paybox' or 'stripe' - print ''.$langs->trans("Subscription").''; - if (!empty($conf->global->MEMBER_NEWFORM_EDITAMOUNT)) { - print ''; - } else { - print ''; - print ''; + print ''.$langs->trans("Subscription"); + if (!empty($conf->global->MEMBER_EXT_URL_SUBSCRIPTION_INFO)) { + print ' - '.$langs->trans("SeeHere").''; + } + print ''; + + if (empty($amount) && !empty($conf->global->MEMBER_NEWFORM_AMOUNT)) { + $amount = $conf->global->MEMBER_NEWFORM_AMOUNT; + } + + if (!empty($conf->global->MEMBER_NEWFORM_EDITAMOUNT) || $caneditamount) { + print ''; + print ' '.$langs->trans("Currency".$conf->currency).' – '; + print $amount>0? $langs->trans("AnyAmountWithAdvisedAmount", $amount, $langs->trans("Currency".$conf->currency)): $langs->trans("AnyAmountWithoutAdvisedAmount"); + print ''; + } else { + print ''; + print ''; + print ' '.$langs->trans("Currency".$conf->currency); } - print ' '.$langs->trans("Currency".$conf->currency); print ''; }