From d278909f5bf6fece409f6045536da192df28ccd9 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 10 Feb 2026 19:56:55 +0100 Subject: [PATCH] Debug amount suggested on membership public form --- htdocs/langs/en_US/members.lang | 3 +- htdocs/public/members/new.php | 283 ++++++++++++++++++++++---------- 2 files changed, 197 insertions(+), 89 deletions(-) diff --git a/htdocs/langs/en_US/members.lang b/htdocs/langs/en_US/members.lang index 183a6034344..b624fb505e3 100644 --- a/htdocs/langs/en_US/members.lang +++ b/htdocs/langs/en_US/members.lang @@ -207,8 +207,9 @@ MembershipStatistics=Membership statistics NbOfSubscriptions=Number of memberships AmountOfSubscriptions=Amount collected from membership payments TurnoverOrBudget=Turnover (for a company) or Budget (for a foundation) +AreYouAPreferredPartner=Are you (or plan to be) a %s 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) +MinimumAmount=Minimum amount of membership payment (has priority on any default amounts that is lower) 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/public/members/new.php b/htdocs/public/members/new.php index 48f9230d28a..6a92a3962b3 100644 --- a/htdocs/public/members/new.php +++ b/htdocs/public/members/new.php @@ -62,6 +62,14 @@ define("DOLENTITY", $entity); // Load Dolibarr environment require '../../main.inc.php'; +/** + * @var Conf $conf + * @var DoliDB $db + * @var HookManager $hookmanager + * @var Societe $mysoc + * @var Translate $langs + * @var User $user + */ require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/payments.lib.php'; require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php'; @@ -79,15 +87,6 @@ $errmsg = ''; $num = 0; $error = 0; -/** - * @var Conf $conf - * @var DoliDB $db - * @var HookManager $hookmanager - * @var Societe $mysoc - * @var Translate $langs - * @var User $user - */ - // Load translation files $langs->loadLangs(array("main", "members", "companies", "install", "other", "errors")); @@ -336,11 +335,14 @@ if (empty($reshook) && $action == 'add') { // Test on permission not required he $error++; $errmsg .= $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv('Nature'))."
\n"; } + $lastname = GETPOST("lastname", 'alphanohtml'); $firstname = GETPOST("firstname", 'alphanohtml'); $societe = GETPOST("societe", 'alphanohtml'); $morphy = GETPOST("morphy", 'alphanohtml'); $email = preg_replace('/\s+/', '', GETPOST("member_email", 'aZ09arobase')); + $country_id = getDolGlobalInt("MEMBER_NEWFORM_FORCECOUNTRYCODE", GETPOSTINT('country_id')); + if ($morphy != 'mor' && empty($lastname)) { $error++; $langs->load("errors"); @@ -356,6 +358,11 @@ if (empty($reshook) && $action == 'add') { // Test on permission not required he $langs->load("errors"); setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Company")), null, 'errors'); } + if (empty($country_id)) { + $error++; + $langs->load("errors"); + setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Country")), null, 'errors'); + } if (getDolGlobalString('ADHERENT_MAIL_REQUIRED') && !isValidEmail($email)) { $error++; $langs->load("errors"); @@ -367,8 +374,10 @@ if (empty($reshook) && $action == 'add') { // Test on permission not required he $langs->load("errors"); $errmsg .= $langs->trans("ErrorBadDateFormat")."
\n"; } + + // TODO Add this in a hook if (getDolGlobalString('MEMBER_NEWFORM_DOLIBARRTURNOVER')) { - if (GETPOST("morphy") == 'mor' && GETPOST('budget') <= 0) { + if (GETPOST("morphy") == 'mor' && GETPOSTFLOAT('budget') <= 0) { $error++; $errmsg .= $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("TurnoverOrBudget"))."
\n"; } @@ -661,7 +670,7 @@ if ($action == "subscription") { } // Print form -print '
'."\n"; +print ''."\n"; print ''; print ''; print ''; @@ -685,7 +694,7 @@ if (getDolGlobalString('MEMBER_SKIP_TABLE') || getDolGlobalString('MEMBER_NEWFOR jQuery("#selectcountry_id").change(function() { console.log("We change country, so we reload page"); document.newmember.action.value="create"; - document.newmember.submit(); + jQuery("#newmember").submit(); }); function initfieldrequired() { console.log("initfieldrequired"); @@ -713,7 +722,7 @@ if (getDolGlobalString('MEMBER_SKIP_TABLE') || getDolGlobalString('MEMBER_NEWFOR // Type if (!getDolGlobalString('MEMBER_NEWFORM_FORCETYPE')) { $typeid = GETPOSTINT("typeid"); - print ''.$langs->trans("MemberType").''; + print ''.$langs->trans("MemberType").''; $listetype = $adht->liste_array(1); print img_picto('', $adht->picto, 'class="pictofixedwidth"'); if (count($listetype)) { @@ -721,11 +730,11 @@ if (getDolGlobalString('MEMBER_SKIP_TABLE') || getDolGlobalString('MEMBER_NEWFOR } else { print ''.$langs->trans("NoTypeDefinedGoToSetup").''; } + print ''."\n"; } else { $adht->fetch(getDolGlobalInt('MEMBER_NEWFORM_FORCETYPE')); print ''; } - print ''."\n"; // Moral/Physic attribute $morphys = [ @@ -742,8 +751,10 @@ if (getDolGlobalString('MEMBER_SKIP_TABLE') || getDolGlobalString('MEMBER_NEWFOR } print ''.$langs->trans("MemberNature")."\n"; - print ''; - print ''; + //$disabledphy = ($checkednature == "mor" ? ' disabled="disabled"' : ''); + //$disabledmor = ($checkednature == "phy" ? ' disabled="disabled"' : ''); + print ''; + print ''; // Add JS to manage the background of nature if ($conf->use_javascript_ajax) { @@ -775,7 +786,7 @@ if (getDolGlobalString('MEMBER_SKIP_TABLE') || getDolGlobalString('MEMBER_NEWFOR }); $("#typeid").on("change", function() { - console.log("Type of member is modified"); + console.log("Type of membership is modified"); let morphy = listetype_natures[$(this).val()]; console.log("morphy="+morphy); @@ -789,8 +800,8 @@ if (getDolGlobalString('MEMBER_SKIP_TABLE') || getDolGlobalString('MEMBER_NEWFOR switch (morphy) { case "phy": - $phyInput.prop({disabled: false, checked: true}); - $morInput.prop({disabled: true, checked: false}); + /* $phyInput.prop({disabled: false, checked: true}); + $morInput.prop({disabled: true, checked: false}); */ $span1.addClass("member-individual-back").removeClass("nonature-back"); $span2.removeClass("member-company-back").addClass("nonature-back"); $tdLast.addClass("fieldrequired"); @@ -799,8 +810,8 @@ if (getDolGlobalString('MEMBER_SKIP_TABLE') || getDolGlobalString('MEMBER_NEWFOR break; case "mor": - $phyInput.prop({disabled: true, checked: false}); - $morInput.prop({disabled: false, checked: true}); + /* $phyInput.prop({disabled: true, checked: false}); + $morInput.prop({disabled: false, checked: true}); */ $span2.addClass("member-company-back").removeClass("nonature-back"); $span1.removeClass("member-individual-back").addClass("nonature-back"); $tdCompany.addClass("fieldrequired"); @@ -810,7 +821,8 @@ if (getDolGlobalString('MEMBER_SKIP_TABLE') || getDolGlobalString('MEMBER_NEWFOR default:'; if ($action != "subscription" && !GETPOST('morphy')) { - print ' $phyInput.prop({disabled: false, checked: false}); + print ' + $phyInput.prop({disabled: false, checked: false}); $morInput.prop({disabled: false, checked: false}); $span1.removeClass("member-individual-back").addClass("nonature-back"); $span2.removeClass("member-company-back").addClass("nonature-back");'; @@ -875,10 +887,11 @@ if (getDolGlobalString('MEMBER_SKIP_TABLE') || getDolGlobalString('MEMBER_NEWFOR print $formcompany->select_ziptown(GETPOST('town'), 'town', array('zipcode', 'selectcountry_id', 'state_id'), 0, 1); print ''; - // Country - print ''.$langs->trans('Country').''; - print img_picto('', 'country', 'class="pictofixedwidth paddingright"'); $country_id = GETPOSTINT('country_id'); + + // Country + print ''.$langs->trans('Country').''; + print img_picto('', 'country', 'class="pictofixedwidth paddingright"'); if (!$country_id && getDolGlobalString('MEMBER_NEWFORM_FORCECOUNTRYCODE')) { $country_id = getCountry(getDolGlobalString('MEMBER_NEWFORM_FORCECOUNTRYCODE'), '2', $db, $langs); } @@ -894,7 +907,7 @@ if (getDolGlobalString('MEMBER_SKIP_TABLE') || getDolGlobalString('MEMBER_NEWFOR } } $country_code = getCountry($country_id, '2', $db, $langs); - print $form->select_country($country_id, 'country_id', '', 0, 'minwidth150 maxwidth300 widthcentpercentminusx'); + print $form->select_country($country_id, 'country_id', '', 0, 'minwidth150 maxwidth300 widthcentpercentminusx reposition'); print ''; // State @@ -944,42 +957,165 @@ if (getDolGlobalString('MEMBER_SKIP_TABLE') || getDolGlobalString('MEMBER_NEWFOR print ''; print ''."\n"; - // Add specific fields used by Dolibarr foundation for example - // TODO Move this into generic feature. + + // Define amount by default to suggest + $typeid = getDolGlobalInt('MEMBER_NEWFORM_FORCETYPE', GETPOSTINT('typeid')); + $adht = new AdherentType($db); + $adht->fetch($typeid); + $caneditamount = $adht->caneditamount; + $amountbytype = $adht->amountByType(1); // Load the array of amount per type + var_dump($amountbytype); + foreach ($amountbytype as $k => $v) { + $amount = max(0, (float) $v, (float) getDolGlobalInt("MEMBER_NEWFORM_AMOUNT")); + $amountbytype[$k] = $amount; + } + + $amountbytype_json = json_encode($amountbytype); + $caneditamountbytype = $adht->caneditamountByType(1); // Load the array of caneditamount per type + $caneditamountbytype_json = json_encode($caneditamountbytype); + + + // Set amount for the subscription from the the type and options: + // - First check the amount of the member type. + $amount = empty($amountbytype[$typeid]) ? 0 : $amountbytype[$typeid]; + var_dump($amountbytype); + // - 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'); + } + // - If not set, we accept to have amount defined as parameter (for backward compatibility). + if (empty($amount)) { + $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")); + + // Clean the amount + $amount = price2num($amount); + + + + // Add hook to complete the form + $parameters = array('country_id' => $country_id); + $reshook = $hookmanager->executeHooks('membershipNewSubscriptionPublicForm', $parameters, $object, $action); + if ($reshook < 0) { + setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); + $error++; + } + // TODO Move this into previous hook if (getDolGlobalString('MEMBER_NEWFORM_DOLIBARRTURNOVER')) { - $arraybudget = array('50' => '<= 100 000', '100' => '<= 200 000', '200' => '<= 500 000', '300' => '<= 1 500 000', '600' => '<= 3 000 000', '1000' => '<= 5 000 000', '2000' => '5 000 000+'); - print ''.$langs->trans("TurnoverOrBudget").''; - print $form->selectarray('budget', $arraybudget, GETPOST('budget'), 1); + // Do not set a default amount MEMBER_NEWFORM_AMOUNT if you use MEMBER_NEWFORM_DOLIBARRTURNOVER + $s = $langs->trans("AreYouAPreferredPartner", '{s1}'); + $s = str_replace('{s1}', 'Peferred Partner', $s); + print ''; + print ''; + print ''; + + print ''.$langs->trans("TurnoverOrBudget").''; + + $country_code = dol_getIdFromCode($db, $country_id, 'c_country', 'rowid', 'code'); + if ($country_code === 'FR' && $checkednature === 'mor' && GETPOST('pp')) { + print ''; + } else { + $arraybudget = array('50' => '<= 100 000', '100' => '<= 200 000', '200' => '<= 500 000', '300' => '<= 1 500 000', '600' => '<= 3 000 000', '1000' => '<= 5 000 000', '2000' => '5 000 000+'); + print $form->selectarray('budget', $arraybudget, GETPOSTINT('budget'), 1, 0, '', 0, 0, 0, ''); + } print ' € or $'; print ''; @@ -987,42 +1123,12 @@ if (getDolGlobalString('MEMBER_SKIP_TABLE') || getDolGlobalString('MEMBER_NEWFOR } if (getDolGlobalString('MEMBER_NEWFORM_PAYONLINE')) { // Can be 'all', 'paypal', 'paybox', 'stripe'... - $typeid = getDolGlobalInt('MEMBER_NEWFORM_FORCETYPE', GETPOSTINT('typeid')); - $adht = new AdherentType($db); - $adht->fetch($typeid); - $caneditamount = $adht->caneditamount; - $amountbytype = $adht->amountByType(1); // Load the array of amount per type - foreach ($amountbytype as $k => $v) { - $amount = max(0, (float) $v, (float) getDolGlobalInt("MEMBER_MIN_AMOUNT")); - $amountbytype[$k] = $amount; - } - - $amountbytype_json = json_encode($amountbytype); - $caneditamountbytype = $adht->caneditamountByType(1); // Load the array of caneditamount per type - $caneditamountbytype_json = json_encode($caneditamountbytype); - - - // Set amount for the subscription from the 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 - if (empty($amount) && getDolGlobalString('MEMBER_NEWFORM_AMOUNT')) { - $amount = getDolGlobalString('MEMBER_NEWFORM_AMOUNT'); - } - // - If not set, we accept to have amount defined as parameter (for backward compatibility). - if (empty($amount)) { - $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")); - - // Clean the amount - $amount = price2num($amount); - $showedamount = $amount > 0 ? $amount : 0; - print ''.$langs->trans("Subscription"); if (getDolGlobalString('MEMBER_EXT_URL_SUBSCRIPTION_INFO')) { - print ' - '.$langs->trans("SeeHere").''; + print '
'; + print ''; + print img_picto('', 'url', 'class="pictofixedwidth"').$langs->trans("SeeHere"); + print ''; } print ''; @@ -1030,19 +1136,20 @@ if (getDolGlobalString('MEMBER_SKIP_TABLE') || getDolGlobalString('MEMBER_NEWFOR $amount = getDolGlobalString('MEMBER_NEWFORM_AMOUNT'); } + $showedamount = $amount > 0 ? $amount : 0; if ($caneditamount === "1") { - print ''; - print ''; - print ' '.$langs->trans("Currency".$conf->currency).''; + print ''; + print ''; + print ' '.$langs->getCurrencySymbol($conf->currency).''; if (!getDolGlobalString('MEMBER_NEWFORM_DOLIBARRTURNOVER')) { print ' - '; print $amount > 0 ? $langs->trans("AnyAmountWithAdvisedAmount", price($amount, 0, $langs, 1, -1, -1, $conf->currency)) : $langs->trans("AnyAmountWithoutAdvisedAmount"); } print ''; } else { - print ''; - print ''; - print ' '.$langs->trans("Currency".$conf->currency).'