Clean code

This commit is contained in:
Laurent Destailleur 2021-11-27 16:19:12 +01:00
parent 2acfba25ee
commit 66d9964861
2 changed files with 17 additions and 13 deletions

View File

@ -543,14 +543,13 @@ class AdherentType extends CommonObject
} }
/** /**
* Return list of amount by type id * Return the array of all amounts per membership type id
* *
* @param int $status Filter on status of type * @param int $status Filter on status of type
* @return array List of types of members * @return array Array of membership type
*/ */
public function amountByType($status = null) public function amountByType($status = null)
{ {
global $conf, $langs; global $conf, $langs;
$amountbytype = array(); $amountbytype = array();
@ -578,6 +577,7 @@ class AdherentType extends CommonObject
} else { } else {
print $this->db->error(); print $this->db->error();
} }
return $amountbytype; return $amountbytype;
} }

View File

@ -730,21 +730,24 @@ if (!empty($conf->global->MEMBER_NEWFORM_DOLIBARRTURNOVER)) {
print '</td></tr>'."\n"; print '</td></tr>'."\n";
} }
if (!empty($conf->global->MEMBER_NEWFORM_AMOUNT) || !empty($conf->global->MEMBER_NEWFORM_PAYONLINE)) { if (!empty($conf->global->MEMBER_NEWFORM_PAYONLINE)) {
// $conf->global->MEMBER_NEWFORM_SHOWAMOUNT is an amount $amount = 0;
$typeid = $conf->global->MEMBER_NEWFORM_FORCETYPE ? $conf->global->MEMBER_NEWFORM_FORCETYPE : GETPOST('typeid', 'int');
// Set amount for the subscription // Set amount for the subscription:
$amountbytype = $adht->amountByType(1); // - First check the amount of the member type.
$amount = !empty($amountbytype[GETPOST('typeid', 'int')]) ? $amountbytype[GETPOST('typeid', 'int')] : (isset($amount) ? $amount : 0); $amountbytype = $adht->amountByType(1); // Load the array of amount per type
$amount = empty($amountbytype[$typeid]) ? (isset($amount) ? $amount : 0) : $amountbytype[$typeid];
if (!empty($conf->global->MEMBER_NEWFORM_AMOUNT)) { // - If not found, take the default amount
if (empty($amount) && !empty($conf->global->MEMBER_NEWFORM_AMOUNT)) {
$amount = $conf->global->MEMBER_NEWFORM_AMOUNT; $amount = $conf->global->MEMBER_NEWFORM_AMOUNT;
} }
// - If not set, we accept ot have amount defined as parameter (for backward compatibility).
if (!empty($conf->global->MEMBER_NEWFORM_PAYONLINE)) { if (empty($amount)) {
$amount = $amount ? $amount : (GETPOST('amount') ? price2num(GETPOST('amount', 'alpha'), 'MT', 2) : $conf->global->MEMBER_NEWFORM_AMOUNT); $amount = (GETPOST('amount') ? price2num(GETPOST('amount', 'alpha'), 'MT', 2) : '');
} }
// Clean the amount
$amount = price2num($amount); $amount = price2num($amount);
// $conf->global->MEMBER_NEWFORM_PAYONLINE is 'paypal', 'paybox' or 'stripe' // $conf->global->MEMBER_NEWFORM_PAYONLINE is 'paypal', 'paybox' or 'stripe'
@ -758,6 +761,7 @@ if (!empty($conf->global->MEMBER_NEWFORM_AMOUNT) || !empty($conf->global->MEMBER
print ' '.$langs->trans("Currency".$conf->currency); print ' '.$langs->trans("Currency".$conf->currency);
print '</td></tr>'; print '</td></tr>';
} }
print "</table>\n"; print "</table>\n";
print dol_get_fiche_end(); print dol_get_fiche_end();