diff --git a/htdocs/adherents/class/adherent_type.class.php b/htdocs/adherents/class/adherent_type.class.php index f03d1099c4186..88588ef334951 100644 --- a/htdocs/adherents/class/adherent_type.class.php +++ b/htdocs/adherents/class/adherent_type.class.php @@ -111,8 +111,10 @@ class AdherentType extends CommonObject "rowid" => array("type" => "integer", "label" => "Ref", "enabled" => "1", 'position' => 10, 'notnull' => 1, "visible" => "1",), "libelle" => array("type" => "varchar(50)", "label" => "Label", "enabled" => "1", 'position' => 30, 'notnull' => 1, "visible" => "1", "showoncombobox" => 1), "subscription" => array("type" => "varchar(3)", "label" => "Subscription", "enabled" => "1", 'position' => 35, 'notnull' => 1, "visible" => "1",), - "amount" => array("type" => "double(24,8)", "label" => "Amount", "enabled" => "1", 'position' => 40, 'notnull' => 0, "visible" => "1",), - "caneditamount" => array("type" => "integer", "label" => "Caneditamount", "enabled" => "1", 'position' => 45, 'notnull' => 0, "visible" => "1",), + "caneditamount" => array("type" => "integer", "label" => "Caneditamount", "enabled" => "1", 'position' => 40, 'notnull' => 0, "visible" => "1",), + "minimumamount" => array("type" => "double(24,8)", "label" => "MinimumAmount", "enabled" => "1", 'position' => 42, 'notnull' => 0, "visible" => "1",), + "amount" => array("type" => "double(24,8)", "label" => "Amount", "enabled" => "1", 'position' => 45, 'notnull' => 0, "visible" => "1",), + "amountformuladescription" => array("type" => "longtext", "label" => "AmountFormulaDescription", "enabled" => "1", 'position' => 46, 'notnull' => 0, "visible" => "1",), "vote" => array("type" => "varchar(3)", "label" => "Vote", "enabled" => "1", 'position' => 50, 'notnull' => 1, "visible" => "-1",), "mail_valid" => array("type" => "longtext", "label" => "MailValidation", "enabled" => "1", 'position' => 60, 'notnull' => 0, "visible" => "-3",), "morphy" => array("type" => "varchar(3)", "label" => "MembersNature", "enabled" => "1", 'position' => 65, 'notnull' => 0, "visible" => "1",), @@ -160,15 +162,25 @@ class AdherentType extends CommonObject */ public $subscription; + /** + * @var int Amount can be chosen by the visitor during subscription (0 or 1) + */ + public $caneditamount; + + /** + * @var float|string Minimum Amount for subscription (null or '' means not defined) + */ + public $minimumamount; + /** * @var float|string Amount for subscription (null or '' means not defined) */ public $amount; /** - * @var int Amount can be chosen by the visitor during subscription (0 or 1) + * @var string Describe the subscription amount formula to follow */ - public $caneditamount; + public $amountformuladescription; /** * @var string Public note @@ -495,8 +507,10 @@ public function update($user, $notrigger = 0) $sql .= "libelle = '".$this->db->escape($this->label)."',"; $sql .= "morphy = '".$this->db->escape($this->morphy)."',"; $sql .= "subscription = '".$this->db->escape((string) $this->subscription)."',"; - $sql .= "amount = ".((empty($this->amount) && $this->amount == '') ? "null" : ((float) $this->amount)).","; $sql .= "caneditamount = ".((int) $this->caneditamount).","; + $sql .= "minimumamount = ".((empty($this->minimumamount) && $this->minimumamount == '') ? "null" : ((float) $this->minimumamount)).","; + $sql .= "amount = ".((empty($this->amount) && $this->amount == '') ? "null" : ((float) $this->amount)).","; + $sql .= "amountformuladescription = '".$this->db->escape($this->amountformuladescription)."',"; $sql .= "duration = '".$this->db->escape($this->duration_value.$this->duration_unit)."',"; $sql .= "note = '".$this->db->escape($this->note_public)."',"; $sql .= "vote = ".(int) $this->db->escape((string) $this->vote).","; @@ -586,7 +600,7 @@ public function delete($user) */ public function fetch($rowid) { - $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 = "SELECT d.rowid, d.libelle as label, d.morphy, d.statut as status, d.duration, d.subscription, d.caneditamount, d.minimumamount, d.amount, d.amountformuladescription, 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; @@ -606,8 +620,10 @@ public function fetch($rowid) $this->duration_value = (int) substr($obj->duration, 0, dol_strlen($obj->duration) - 1); $this->duration_unit = substr($obj->duration, -1); $this->subscription = $obj->subscription; - $this->amount = $obj->amount; $this->caneditamount = $obj->caneditamount; + $this->minimumamount = $obj->minimumamount; + $this->amount = $obj->amount; + $this->amountformuladescription = $obj->amountformuladescription; $this->mail_valid = $obj->mail_valid; $this->note = $obj->note_public; // deprecated $this->note_public = $obj->note_public; @@ -782,6 +798,80 @@ public function caneditamountByType($status = null) return $caneditamountbytype; } + /** + * Return the array of all minimum amounts per membership type id + * + * @param int $status Filter on status of type + * @return array Array of membership type + */ + public function minimumAmountByType($status = null) + { + $minimumamountbytype = array(); + + $sql = "SELECT rowid, minimumamount"; + $sql .= " FROM ".MAIN_DB_PREFIX."adherent_type"; + $sql .= " WHERE entity IN (".getEntity('member_type').")"; + if ($status !== null) { + $sql .= " AND statut = ".((int) $status); + } + + $resql = $this->db->query($sql); + if ($resql) { + $nump = $this->db->num_rows($resql); + + if ($nump) { + $i = 0; + while ($i < $nump) { + $obj = $this->db->fetch_object($resql); + + $minimumamountbytype[$obj->rowid] = (float) $obj->minimumamount; + $i++; + } + } + } else { + print $this->db->error(); + } + + return $minimumamountbytype; + } + + /** + * Return the array of all amount formula's descriptions per membership type id + * + * @param int $status Filter on status of type + * @return array Array of membership type + */ + public function amountFormulaDescriptionByType($status = null) + { + $amountformuladescriptionbytype = array(); + + $sql = "SELECT rowid, amountformuladescription"; + $sql .= " FROM ".MAIN_DB_PREFIX."adherent_type"; + $sql .= " WHERE entity IN (".getEntity('member_type').")"; + if ($status !== null) { + $sql .= " AND statut = ".((int) $status); + } + + $resql = $this->db->query($sql); + if ($resql) { + $nump = $this->db->num_rows($resql); + + if ($nump) { + $i = 0; + while ($i < $nump) { + $obj = $this->db->fetch_object($resql); + + $amountformuladescriptionbytype[$obj->rowid] = $obj->amountformuladescription; + $i++; + } + } + } else { + print $this->db->error(); + } + + return $amountformuladescriptionbytype; + } + /** * Return array of Member objects for member type this->id (or all if this->id not defined) * diff --git a/htdocs/adherents/type.php b/htdocs/adherents/type.php index 9d489f3581f15..1546f8ea67c98 100644 --- a/htdocs/adherents/type.php +++ b/htdocs/adherents/type.php @@ -92,13 +92,15 @@ $morphy = GETPOST("morphy", "alpha"); $status = GETPOST("status", "intcomma"); $subscription = GETPOSTINT("subscription"); +$caneditamount = GETPOSTINT("caneditamount"); +$minimumamount = GETPOST('minimumamount', 'alpha'); $amount = GETPOST('amount', 'alpha'); +$amountformuladescription = GETPOST("amountformuladescription", 'restricthtml'); $duration_value = GETPOSTINT('duration_value'); $duration_unit = GETPOST('duration_unit', 'alpha'); $vote = GETPOSTINT("vote"); $comment = GETPOST("comment", 'restricthtml'); $mail_valid = GETPOST("mail_valid", 'restricthtml'); -$caneditamount = GETPOSTINT("caneditamount"); // Initialize a technical object $object = new AdherentType($db); @@ -173,8 +175,10 @@ $object->morphy = trim($morphy); $object->status = (int) $status; $object->subscription = (string) (int) $subscription; - $object->amount = ($amount == '' ? '' : price2num($amount, 'MT')); $object->caneditamount = $caneditamount; + $object->minimumamount = ($minimumamount == '' ? '' : price2num($minimumamount, 'MT')); + $object->amount = ($amount == '' ? '' : price2num($amount, 'MT')); + $object->amountformuladescription = trim($amountformuladescription); $object->duration_value = $duration_value; $object->duration_unit = $duration_unit; $object->note_public = trim($comment); @@ -234,8 +238,10 @@ $object->morphy = trim($morphy); $object->status = (int) $status; $object->subscription = (string) (int) $subscription; - $object->amount = ($amount == '' ? '' : price2num($amount, 'MT')); $object->caneditamount = $caneditamount; + $object->minimumamount = $minimumamount; + $object->amount = ($amount == '' ? '' : price2num($amount, 'MT')); + $object->amountformuladescription = trim($amountformuladescription); $object->duration_value = $duration_value; $object->duration_unit = $duration_unit; $object->note_public = trim($comment); @@ -297,7 +303,7 @@ if (!$rowid && $action != 'create' && $action != 'edit') { //print dol_get_fiche_head([]); - $sql = "SELECT d.rowid, d.libelle as label, d.subscription, d.amount, d.caneditamount, d.vote,"; + $sql = "SELECT d.rowid, d.libelle as label, d.subscription, d.caneditamount, d.minimumamount, d.amount, d.amountformuladescription, d.vote,"; $sql .= " d.statut as status, d.morphy, d.duration,"; $sql .= " d.tms"; $sql .= " FROM ".MAIN_DB_PREFIX."adherent_type as d"; @@ -381,12 +387,20 @@ print ''.$langs->trans("SubscriptionRequired").''; $totalarray['nbfield']++; } + if (!empty($arrayfields['t.caneditamount']['checked'])) { + print ''.$langs->trans("CanEditAmountShort").''; + $totalarray['nbfield']++; + } + if (!empty($arrayfields['t.minimumamount']['checked'])) { + print ''.$langs->trans("MinimumAmountShort").''; + $totalarray['nbfield']++; + } if (!empty($arrayfields['t.amount']['checked'])) { - print ''.$langs->trans("Amount").''; + print ''.$langs->trans("RecommendedAmount").''; $totalarray['nbfield']++; } - if (!empty($arrayfields['t.caneditamount']['checked'])) { - print ''.$langs->trans("CanEditAmountShort").''; + if (!empty($arrayfields['t.amountformuladescription']['checked'])) { + print ''.$langs->trans("AmountFormulaDescription").''; $totalarray['nbfield']++; } if (!empty($arrayfields['t.vote']['checked'])) { @@ -424,8 +438,10 @@ $membertype->label = $objp->rowid; $membertype->status = $objp->status; $membertype->subscription = $objp->subscription; - $membertype->amount = $objp->amount; $membertype->caneditamount = $objp->caneditamount; + $membertype->minimumamount = $objp->minimumamount; + $membertype->amount = $objp->amount; + $membertype->amountformuladescription = $objp->amountformuladescription; if ($mode == 'kanban') { if ($i == 0) { @@ -484,17 +500,27 @@ if (!empty($arrayfields['t.subscription']['checked'])) { print ''.yn($objp->subscription).''; } + if (!empty($arrayfields['t.caneditamount']['checked'])) { + print ''.yn($objp->caneditamount).''; + } + if (!empty($arrayfields['t.minimumamount']['checked'])) { + print ''.price($objp->minimumamount).''; + } if (!empty($arrayfields['t.amount']['checked'])) { print ''; $amount = (is_null($objp->amount) || $objp->amount === '' ? '' : price($objp->amount)); + $minimumamount = (is_null($objp->minimumamount) || $objp->minimumamount === '' ? '' : price($objp->minimumamount)); print ''.$amount.''; if ($amount && $amount < (float) getDolGlobalInt("MEMBER_MIN_AMOUNT")) { print img_warning('Amount lower than minimum of '.price(getDolGlobalInt("MEMBER_MIN_AMOUNT")).' defined in setup'); } + if ($amount && $minimumamount && $amount < $minimumamount) { + print img_warning('Amount lower than minimum of '.price($minimumamount).' defined in setup'); + } print ''; } - if (!empty($arrayfields['t.caneditamount']['checked'])) { - print ''.yn($objp->caneditamount).''; + if (!empty($arrayfields['t.amountformuladescription']['checked'])) { + print ''.dol_escape_htmltag($objp->amountformuladescription).''; } if (!empty($arrayfields['t.vote']['checked'])) { print ''.yn($objp->vote).''; @@ -573,14 +599,23 @@ print $form->selectyesno("subscription", 1, 1); print ''; - print ''.$langs->trans("Amount").''; - print ''; - print ''; - print ''.$form->textwithpicto($langs->trans("CanEditAmountShort"), $langs->transnoentities("CanEditAmount")).''; print $form->selectyesno("caneditamount", GETPOSTISSET('caneditamount') ? GETPOST('caneditamount') : 0, 1); print ''; + print ''.$langs->trans("MinimumAmountShort").''; + print ''; + print ''; + + print ''.$langs->trans("RecommendedAmount").''; + print ''; + print ''; + + print ''.$langs->trans("AmountFormulaDescription").''; + require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; + $doleditor = new DolEditor('amountformuladescription', (GETPOSTISSET('amountformuladescription') ? GETPOST('amountformuladescription', 'restricthtml') : $object->amountformuladescription), '', 100, 'dolibarr_notes', '', false, true, isModEnabled('fckeditor'), 15, '90%'); + $doleditor->Create(); + print ''.$langs->trans("VoteAllowed").''; print $form->selectyesno("vote", GETPOSTISSET("vote") ? GETPOST('vote', 'aZ09') : 1, 1); print ''; @@ -650,17 +685,29 @@ print ''; // Amount - print ''.$langs->trans("Amount").''; + print ''.$form->textwithpicto($langs->trans("CanEditAmountShort"), $langs->transnoentities("CanEditAmount")).''; + print yn($object->caneditamount); + print ''; + + print ''.$langs->trans("MinimumAmountShort").''; + $minimumamount = ((is_null($object->minimumamount) || $object->minimumamount === '') ? '' : price($object->minimumamount)); + print $minimumamount; + print ''; + + print ''.$langs->trans("RecommendedAmount").''; $amount = ((is_null($object->amount) || $object->amount === '') ? '' : price($object->amount)); print ''.$amount.''; if ($amount && $amount < (float) getDolGlobalInt("MEMBER_MIN_AMOUNT")) { print ' '.img_warning('Amount lower than minimum of '.price(getDolGlobalInt("MEMBER_MIN_AMOUNT")).' defined in setup'); } + if ($amount && $minimumamount && $amount < $minimumamount) { + print ' '.img_warning('Amount lower than minimum of '.price($minimumamount).' defined in setup'); + } print ''; - print ''.$form->textwithpicto($langs->trans("CanEditAmountShort"), $langs->transnoentities("CanEditAmount")).''; - print yn($object->caneditamount); - print ''; + print ''.$langs->trans("AmountFormulaDescription").'
'; + print dol_string_onlythesehtmltags(dol_htmlentitiesbr($object->amountformuladescription)); + print "
"; print ''.$langs->trans("VoteAllowed").''; print yn($object->vote); @@ -1097,16 +1144,29 @@ print $form->selectyesno("subscription", $object->subscription, 1); print ''; - print ''.$langs->trans("Amount").''; + print ''.$form->textwithpicto($langs->trans("CanEditAmountShort"), $langs->transnoentities("CanEditAmountDetail")).''; + print $form->selectyesno("caneditamount", $object->caneditamount, 1); + print ''; + + print ''.$langs->trans("MinimumAmountShort").''; + $minimumamount = ((is_null($object->minimumamount) || $object->minimumamount === '') ? '' : price($object->minimumamount)); + print ''; + print ''; + + print ''.$langs->trans("RecommendedAmount").''; $amount = ((is_null($object->amount) || $object->amount === '') ? '' : price($object->amount)); print ''; print ''; - print ''.$form->textwithpicto($langs->trans("CanEditAmountShort"), $langs->transnoentities("CanEditAmountDetail")).''; - print $form->selectyesno("caneditamount", $object->caneditamount, 1); - print ''; + print ''.$langs->trans("AmountFormulaDescription").''; + require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; + $doleditor = new DolEditor('amountformuladescription', $object->amountformuladescription, '', 220, 'dolibarr_notes', '', false, true, isModEnabled('fckeditor'), 15, '90%'); + $doleditor->Create(); + print ""; print ''.$langs->trans("VoteAllowed").''; print $form->selectyesno("vote", $object->vote, 1); diff --git a/htdocs/install/mysql/migration/22.0.0-23.0.0.sql b/htdocs/install/mysql/migration/22.0.0-23.0.0.sql index 44232441c0e9e..60b3073a281e8 100644 --- a/htdocs/install/mysql/migration/22.0.0-23.0.0.sql +++ b/htdocs/install/mysql/migration/22.0.0-23.0.0.sql @@ -397,4 +397,8 @@ ALTER TABLE llx_blockedlog ADD CONSTRAINT fk_linktoref FOREIGN KEY (linktoref) R ALTER TABLE llx_fichinterdet ADD COLUMN special_code integer DEFAULT 0 AFTER fk_parent_line; ALTER TABLE llx_fichinterdet ADD COLUMN product_type integer DEFAULT 0 AFTER special_code; +ALTER TABLE llx_adherent_type ADD COLUMN minimumamount double(24,8) DEFAULT NULL AFTER caneditamount; +ALTER TABLE llx_adherent_type ADD COLUMN amountformuladescription text AFTER minimumamount; + + -- end of migration diff --git a/htdocs/install/mysql/tables/llx_adherent_type.sql b/htdocs/install/mysql/tables/llx_adherent_type.sql index 3473798a6ea9f..1513bab0aacf5 100644 --- a/htdocs/install/mysql/tables/llx_adherent_type.sql +++ b/htdocs/install/mysql/tables/llx_adherent_type.sql @@ -35,6 +35,8 @@ create table llx_adherent_type subscription varchar(3) NOT NULL DEFAULT '1', -- subscription with costs / fee or without / for free amount double(24,8) DEFAULT NULL, -- membership fee caneditamount integer DEFAULT 0, -- can member edit the amount of subscription + minimumamount double(24,8) DEFAULT NULL, -- minimum amount + amountformuladescription text, -- description of the subscription amount formula vote varchar(3) NOT NULL DEFAULT '1', -- entitled to vote note text, -- description / comment mail_valid text -- text for welcome email diff --git a/htdocs/langs/en_US/members.lang b/htdocs/langs/en_US/members.lang index 3005c83e03e95..c556e7c69bbec 100644 --- a/htdocs/langs/en_US/members.lang +++ b/htdocs/langs/en_US/members.lang @@ -209,6 +209,9 @@ AmountOfSubscriptions=Amount collected from membership payments TurnoverOrBudget=Turnover (for a company) or Budget (for a foundation) DefaultAmount=Default amount of membership payment (used only if no amount is defined at member type level) MinimumAmount=Minimum amount of membership payment (has priority on any default amounts) +MinimumAmountShort=Minimum amount +RecommendedAmount=(Recommended) Amount +AmountFormulaDescription=Describe the subscription amount formula CanEditAmount=Membership amount can be defined by the member CanEditAmountDetail=Visitor can choose/edit amount of its contribution regardless of the member type AmountIsLowerToMinimumNotice=The amount is lower than the minimum %s diff --git a/htdocs/langs/fr_FR/members.lang b/htdocs/langs/fr_FR/members.lang index 4d783ccb6cf24..bc2e880e4b9d4 100644 --- a/htdocs/langs/fr_FR/members.lang +++ b/htdocs/langs/fr_FR/members.lang @@ -209,6 +209,9 @@ AmountOfSubscriptions=Montant collecté grâce aux paiements des adhésions TurnoverOrBudget=Chiffre affaire (pour société) ou Budget (asso ou collectivité) DefaultAmount=Montant par défaut du paiement de l'adhésion (utilisé uniquement si aucun montant n'est défini au niveau du type adhérent) MinimumAmount=Montant minimum de paiement de l'adhésion (a priorité sur tout montant par défaut) +MinimumAmountShort=Montant minimum +RecommendedAmount=Montant (Recommendé) +AmountFormulaDescription=Description de la formule de calcul pour le montant CanEditAmount=Le montant de l'adhésion peut être défini par l'adhérent CanEditAmountDetail=Le visiteur peut choisir/modifier le montant de sa contribution quel que soit le type d'adhérent AmountIsLowerToMinimumNotice=Le montant est inférieur au montant minimum de %s diff --git a/htdocs/public/members/new.php b/htdocs/public/members/new.php index 2ddae91637a72..646d51354d6e0 100644 --- a/htdocs/public/members/new.php +++ b/htdocs/public/members/new.php @@ -576,7 +576,14 @@ function llxFooterVierge() // @phan-suppress-current-line PhanRedefineFunction // It is not so important because a test is done on return of payment validation. } - $urlback = getOnlinePaymentUrl(0, 'member', $adh->ref, (float) price2num(GETPOST('amount', 'alpha'), 'MT'), '', 0); + $minimumamountbytype = $adht->minimumamountbytype(1); // Load the array of minimum amount per type + $minimumamount = empty($minimumamountbytype[$adh->typeid]) ? 0 : $minimumamountbytype[$adh->typeid]; + $amount = price2num(GETPOST('amount', 'alpha'), 'MT'); + $urlback = getOnlinePaymentUrl(0, 'member', $adh->ref, (float) $amount, '', 0); + if ($amount < max(getDolGlobalInt("MEMBER_MIN_AMOUNT"), $minimumamount)) { + $error++; + $errmsg .= $langs->trans("MinimumAmountShort")." : ".price(max(getDolGlobalInt("MEMBER_MIN_AMOUNT"), $minimumamount), 0, $langs, 1, -1, -1, $conf->currency)."
\n"; + } if (GETPOST('member_email')) { $urlback .= '&email='.urlencode(GETPOST('member_email')); @@ -995,17 +1002,17 @@ function initturnover() { $adht->fetch($typeid); $caneditamount = $adht->caneditamount; $amountbytype = $adht->amountByType(1); // Load the array of amount per type + $minimumamountbytype = $adht->minimumamountbytype(1); // Load the array of minimum amount per type + foreach ($amountbytype as $k => $v) { - $amount = max(0, (float) $v, (float) getDolGlobalInt("MEMBER_MIN_AMOUNT")); + $amount = max(0, (float) $v, (float) getDolGlobalInt("MEMBER_MIN_AMOUNT"), $minimumamountbytype[$k]); $amountbytype[$k] = $amount; } - $amountbytype_json = json_encode($amountbytype); $caneditamountbytype = $adht->caneditamountByType(1); // Load the array of caneditamount per type - $caneditamountbytype_json = json_encode($caneditamountbytype); - + $amountformuladescriptionbytype = $adht->amountformuladescriptionbytype(1); // Load the array of amount ormula description per type - // Set amount for the subscription from the the type and options: + // Set amount for the subscription from the type and options: // - First check the amount of the member type. $amount = empty($amountbytype[$typeid]) ? 0 : $amountbytype[$typeid]; // - If not found, take the default amount only if the user is authorized to edit it @@ -1017,7 +1024,8 @@ function initturnover() { $amount = (GETPOST('amount') ? price2num(GETPOST('amount', 'alpha'), 'MT', 2) : ''); } // - If a min is set, we take it into account - $amount = max(0, (float) $amount, (float) getDolGlobalInt("MEMBER_MIN_AMOUNT")); + $minimumamount = empty($minimumamountbytype[$typeid]) ? 0 : $minimumamountbytype[$typeid]; + $amount = max(0, (float) $amount, (float) getDolGlobalInt("MEMBER_MIN_AMOUNT"), (float) $minimumamount); // Clean the amount $amount = price2num($amount); @@ -1033,11 +1041,19 @@ function initturnover() { $amount = getDolGlobalString('MEMBER_NEWFORM_AMOUNT'); } + $amountformuladescription=$amountformuladescriptionbytype[$typeid]; if ($caneditamount === "1") { print ''; print ''; - print ' '.$langs->trans("Currency".$conf->currency).' - '; - print $amount > 0 ? $langs->trans("AnyAmountWithAdvisedAmount", price($amount, 0, $langs, 1, -1, -1, $conf->currency)) : $langs->trans("AnyAmountWithoutAdvisedAmount"); + print ' '.$langs->trans("Currency".$conf->currency).' - '; + if (empty($amountformuladescription)) { + print $amount > 0 ? $langs->trans("AnyAmountWithAdvisedAmount", price($amount, 0, $langs, 1, -1, -1, $conf->currency)) : $langs->trans("AnyAmountWithoutAdvisedAmount"); + } else { + print $amountformuladescription; + } + if (getDolGlobalInt("MEMBER_MIN_AMOUNT") > 0 || $minimumamount > 0) { + print '
'.$langs->trans("MinimumAmountShort").' : '.price(max(getDolGlobalInt("MEMBER_MIN_AMOUNT"), $minimumamount), 0, $langs, 1, -1, -1, $conf->currency); + } print ''; } else { print ''; @@ -1047,40 +1063,6 @@ function initturnover() { print '
'; } print ''; - - // Add JS to manage the background of amount depending on type - if ($conf->use_javascript_ajax) { - print ""; - - print ''; - } } // Display Captcha code if is enabled @@ -1106,6 +1088,124 @@ function initturnover() { } print ''; + if ($conf->use_javascript_ajax) { + $typeid = getDolGlobalInt('MEMBER_NEWFORM_FORCETYPE', GETPOSTINT('typeid')); + $adht = new AdherentType($db); + $adht->fetch($typeid); + $caneditamountbytype = $adht->caneditamountByType(1); // Load the array of caneditamount per type + $minimumamountbytype = $adht->minimumamountbytype(1); // Load the array of minimum amount per type + $amountbytype = $adht->amountByType(1); // Load the array of amount per type + $amountformuladescriptionbytype = $adht->amountformuladescriptionbytype(1); // Load the array of amount ormula description per type + // Common PHP → JS variables + $caneditamountbytype_json = json_encode($caneditamountbytype); + $minimumamountbytype_json = json_encode($minimumamountbytype); + $amountbytype_json = json_encode($amountbytype); + $amountformuladescriptionbytype_json = json_encode($amountformuladescriptionbytype); + + print ''; + } print "\n"; print "
"; @@ -1142,7 +1242,7 @@ function initturnover() { print ''; print ''.$langs->trans("Label").''; print ''.$langs->trans("MembershipDuration").''; - print ''.$langs->trans("Amount").''; + print ''.$langs->trans("RecommendedAmount").''; print ''.$langs->trans("MembersNature").''; if (empty($hidevoteallowed)) { print ''.$langs->trans("VoteAllowed").''; @@ -1159,6 +1259,7 @@ function initturnover() { $caneditamount = $objp->caneditamount; $amountbytype = $adht->amountByType(1); // Load the array of amount per type + $minimumamountbytype = $adht->minimumamountbytype(1); // Load the array of amount per type print ''; // Label @@ -1174,6 +1275,7 @@ function initturnover() { // Set amount for the subscription from the the type and options: // - First check the amount of the member type. $amount = empty($amountbytype[$objp->rowid]) ? 0 : $amountbytype[$objp->rowid]; + $minimumamount = empty($minimumamountbytype[$objp->rowid]) ? 0 : $minimumamountbytype[$objp->rowid]; // - If not found, take the default amount only if the user is authorized to edit it if (empty($amount) && getDolGlobalString('MEMBER_NEWFORM_AMOUNT')) { $amount = getDolGlobalString('MEMBER_NEWFORM_AMOUNT'); @@ -1183,7 +1285,7 @@ function initturnover() { $amount = (GETPOST('amount') ? price2num(GETPOST('amount', 'alpha'), 'MT', 2) : ''); } // - If a min is set, we take it into account - $amount = max(0, (float) $amount, (float) getDolGlobalInt("MEMBER_MIN_AMOUNT")); + $amount = max(0, (float) $amount, (float) getDolGlobalInt("MEMBER_MIN_AMOUNT"), (float) $minimumamount); $displayedamount = $amount; diff --git a/htdocs/public/payment/paymentok.php b/htdocs/public/payment/paymentok.php index 9b6616ea551e8..c73afbf4e5b8e 100644 --- a/htdocs/public/payment/paymentok.php +++ b/htdocs/public/payment/paymentok.php @@ -43,7 +43,6 @@ if (!defined('NOBROWSERNOTIF')) { define('NOBROWSERNOTIF', '1'); } - if (!defined('XFRAMEOPTIONS_ALLOWALL')) { define('XFRAMEOPTIONS_ALLOWALL', '1'); } @@ -605,12 +604,13 @@ // 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) { + $typeid = $object->typeid; + $amountbytype = $adht->amountByType(1); // Load the array of amount per type + $minimumamountbytype = $adht->minimumamountbytype(1); // Load the array of minimum amount per type + $minimumamount = empty($minimumamountbytype[$typeid]) ? 0 : $minimumamountbytype[$typeid]; // Security protection: if (empty($adht->caneditamount)) { // If we didn't allow members to choose their membership amount (if the amount is allowed in edit mode, no need to check) if ($object->status == $object::STATUS_DRAFT) { // If the member is not yet validated, we check that the amount is the same as expected. - $typeid = $object->typeid; - $amountbytype = $adht->amountByType(1); // Load the array of amount per type - // Set amount for the subscription: // - First check the amount of the member type. $amountexpected = empty($amountbytype[$typeid]) ? 0 : $amountbytype[$typeid]; @@ -623,7 +623,7 @@ // $amount = (GETPOST('amount') ? price2num(GETPOST('amount', 'alpha'), 'MT', 2) : ''); //} // - If a min is set, we take it into account - $amountexpected = max(0, (float) $amountexpected, (float) getDolGlobalInt("MEMBER_MIN_AMOUNT")); + $amountexpected = max(0, (float) $amountexpected, (float) getDolGlobalInt("MEMBER_MIN_AMOUNT"), (float) $minimumamount); if ($amountexpected && $amountexpected != $FinalPaymentAmt) { $error++; @@ -637,9 +637,9 @@ // Security protection: if (getDolGlobalInt('MEMBER_MIN_AMOUNT')) { - if ($FinalPaymentAmt < getDolGlobalInt('MEMBER_MIN_AMOUNT')) { + if ($FinalPaymentAmt < getDolGlobalInt('MEMBER_MIN_AMOUNT') || $FinalPaymentAmt < $minimumamount) { $error++; - $errmsg = 'Value of FinalPayment ('.$FinalPaymentAmt.') is lower than the minimum allowed (' . getDolGlobalString('MEMBER_MIN_AMOUNT').'). May be a hack to try to pay a different amount ?'; + $errmsg = 'Value of FinalPayment ('.$FinalPaymentAmt.') is lower than the minimum allowed (' . max(getDolGlobalString('MEMBER_MIN_AMOUNT'), $minimumamount).'). May be a hack to try to pay a different amount ?'; $postactionmessages[] = $errmsg; $ispostactionok = -1; dol_syslog("Failed to validate member (amount propagated from payment page is lower than allowed minimum): ".$errmsg, LOG_ERR, 0, '_payment');