Minimum amount and subscription's amount formula description (#37006)
Co-authored-by: Laurent Destailleur <eldy@destailleur.fr>
This commit is contained in:
parent
1e5a12708d
commit
296372cf5f
6 changed files with 338 additions and 79 deletions
|
|
@ -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 @@ class AdherentType extends CommonObject
|
|||
$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 @@ class AdherentType extends CommonObject
|
|||
*/
|
||||
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 @@ class AdherentType extends CommonObject
|
|||
$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 @@ class AdherentType extends CommonObject
|
|||
return $caneditamountbytype;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the array of all minimum amounts per membership type id
|
||||
*
|
||||
* @param int $status Filter on status of type
|
||||
* @return array<int,float> 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<int,float> 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)
|
||||
*
|
||||
|
|
|
|||
|
|
@ -92,13 +92,15 @@ $label = GETPOST("label", "alpha");
|
|||
$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 @@ if ($action == 'add' && $user->hasRight('adherent', 'configurer')) {
|
|||
$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 @@ if ($action == 'update' && $user->hasRight('adherent', 'configurer')) {
|
|||
$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 @@ $totalarray = [
|
|||
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 @@ if (!$rowid && $action != 'create' && $action != 'edit') {
|
|||
print '<th class="center">'.$langs->trans("SubscriptionRequired").'</th>';
|
||||
$totalarray['nbfield']++;
|
||||
}
|
||||
if (!empty($arrayfields['t.caneditamount']['checked'])) {
|
||||
print '<th class="center">'.$langs->trans("CanEditAmountShort").'</th>';
|
||||
$totalarray['nbfield']++;
|
||||
}
|
||||
if (!empty($arrayfields['t.minimumamount']['checked'])) {
|
||||
print '<th class="center">'.$langs->trans("MinimumAmountShort").'</th>';
|
||||
$totalarray['nbfield']++;
|
||||
}
|
||||
if (!empty($arrayfields['t.amount']['checked'])) {
|
||||
print '<th class="center">'.$langs->trans("Amount").'</th>';
|
||||
print '<th class="center">'.$langs->trans("RecommendedAmount").'</th>';
|
||||
$totalarray['nbfield']++;
|
||||
}
|
||||
if (!empty($arrayfields['t.caneditamount']['checked'])) {
|
||||
print '<th class="center">'.$langs->trans("CanEditAmountShort").'</th>';
|
||||
if (!empty($arrayfields['t.amountformuladescription']['checked'])) {
|
||||
print '<th class="center">'.$langs->trans("AmountFormulaDescription").'</th>';
|
||||
$totalarray['nbfield']++;
|
||||
}
|
||||
if (!empty($arrayfields['t.vote']['checked'])) {
|
||||
|
|
@ -424,8 +438,10 @@ if (!$rowid && $action != 'create' && $action != 'edit') {
|
|||
$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 (!$rowid && $action != 'create' && $action != 'edit') {
|
|||
if (!empty($arrayfields['t.subscription']['checked'])) {
|
||||
print '<td class="center">'.yn($objp->subscription).'</td>';
|
||||
}
|
||||
if (!empty($arrayfields['t.caneditamount']['checked'])) {
|
||||
print '<td class="center">'.yn($objp->caneditamount).'</td>';
|
||||
}
|
||||
if (!empty($arrayfields['t.minimumamount']['checked'])) {
|
||||
print '<td class="center">'.price($objp->minimumamount).'</td>';
|
||||
}
|
||||
if (!empty($arrayfields['t.amount']['checked'])) {
|
||||
print '<td class="center">';
|
||||
$amount = (is_null($objp->amount) || $objp->amount === '' ? '' : price($objp->amount));
|
||||
$minimumamount = (is_null($objp->minimumamount) || $objp->minimumamount === '' ? '' : price($objp->minimumamount));
|
||||
print '<span class="amount">'.$amount.'</span>';
|
||||
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 '</td>';
|
||||
}
|
||||
if (!empty($arrayfields['t.caneditamount']['checked'])) {
|
||||
print '<td class="center">'.yn($objp->caneditamount).'</td>';
|
||||
if (!empty($arrayfields['t.amountformuladescription']['checked'])) {
|
||||
print '<td class="center">'.dol_escape_htmltag($objp->amountformuladescription).'</td>';
|
||||
}
|
||||
if (!empty($arrayfields['t.vote']['checked'])) {
|
||||
print '<td class="center">'.yn($objp->vote).'</td>';
|
||||
|
|
@ -573,14 +599,23 @@ if ($action == 'create') {
|
|||
print $form->selectyesno("subscription", 1, 1);
|
||||
print '</td></tr>';
|
||||
|
||||
print '<tr><td>'.$langs->trans("Amount").'</td><td>';
|
||||
print '<input name="amount" size="5" value="'.(GETPOSTISSET('amount') ? GETPOST('amount') : price($amount)).'">';
|
||||
print '</td></tr>';
|
||||
|
||||
print '<tr><td>'.$form->textwithpicto($langs->trans("CanEditAmountShort"), $langs->transnoentities("CanEditAmount")).'</td><td>';
|
||||
print $form->selectyesno("caneditamount", GETPOSTISSET('caneditamount') ? GETPOST('caneditamount') : 0, 1);
|
||||
print '</td></tr>';
|
||||
|
||||
print '<tr><td>'.$langs->trans("MinimumAmountShort").'</td><td>';
|
||||
print '<input name="minimumamount" size="5" value="'.(GETPOSTISSET('minimumamount') ? GETPOST('minimumamount') : price($minimumamount)).'">';
|
||||
print '</td></tr>';
|
||||
|
||||
print '<tr><td>'.$langs->trans("RecommendedAmount").'</td><td>';
|
||||
print '<input name="amount" size="5" value="'.(GETPOSTISSET('amount') ? GETPOST('amount') : price($amount)).'">';
|
||||
print '</td></tr>';
|
||||
|
||||
print '<tr><td class="tdtop">'.$langs->trans("AmountFormulaDescription").'</td><td>';
|
||||
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 '<tr><td>'.$langs->trans("VoteAllowed").'</td><td>';
|
||||
print $form->selectyesno("vote", GETPOSTISSET("vote") ? GETPOST('vote', 'aZ09') : 1, 1);
|
||||
print '</td></tr>';
|
||||
|
|
@ -650,17 +685,29 @@ if ($rowid > 0) {
|
|||
print '</tr>';
|
||||
|
||||
// Amount
|
||||
print '<tr><td class="titlefield">'.$langs->trans("Amount").'</td><td>';
|
||||
print '<tr><td>'.$form->textwithpicto($langs->trans("CanEditAmountShort"), $langs->transnoentities("CanEditAmount")).'</td><td>';
|
||||
print yn($object->caneditamount);
|
||||
print '</td></tr>';
|
||||
|
||||
print '<tr><td class="titlefield">'.$langs->trans("MinimumAmountShort").'</td><td>';
|
||||
$minimumamount = ((is_null($object->minimumamount) || $object->minimumamount === '') ? '' : price($object->minimumamount));
|
||||
print $minimumamount;
|
||||
print '</tr>';
|
||||
|
||||
print '<tr><td class="titlefield">'.$langs->trans("RecommendedAmount").'</td><td>';
|
||||
$amount = ((is_null($object->amount) || $object->amount === '') ? '' : price($object->amount));
|
||||
print '<span class="amount">'.$amount.'</span>';
|
||||
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 '</tr>';
|
||||
|
||||
print '<tr><td>'.$form->textwithpicto($langs->trans("CanEditAmountShort"), $langs->transnoentities("CanEditAmount")).'</td><td>';
|
||||
print yn($object->caneditamount);
|
||||
print '</td></tr>';
|
||||
print '<tr><td class="tdtop">'.$langs->trans("AmountFormulaDescription").'</td><td><div class="longmessagecut">';
|
||||
print dol_string_onlythesehtmltags(dol_htmlentitiesbr($object->amountformuladescription));
|
||||
print "</div></td></tr>";
|
||||
|
||||
print '<tr><td>'.$langs->trans("VoteAllowed").'</td><td>';
|
||||
print yn($object->vote);
|
||||
|
|
@ -1097,15 +1144,28 @@ if ($rowid > 0) {
|
|||
print $form->selectyesno("subscription", $object->subscription, 1);
|
||||
print '</td></tr>';
|
||||
|
||||
print '<tr><td>'.$langs->trans("Amount").'</td><td>';
|
||||
print '<tr><td>'.$form->textwithpicto($langs->trans("CanEditAmountShort"), $langs->transnoentities("CanEditAmountDetail")).'</td><td>';
|
||||
print $form->selectyesno("caneditamount", $object->caneditamount, 1);
|
||||
print '</td></tr>';
|
||||
|
||||
print '<tr><td>'.$langs->trans("MinimumAmountShort").'</td><td>';
|
||||
$minimumamount = ((is_null($object->minimumamount) || $object->minimumamount === '') ? '' : price($object->minimumamount));
|
||||
print '<input name="minimumamount" size="5" value="';
|
||||
print $minimumamount;
|
||||
print '">';
|
||||
print '</td></tr>';
|
||||
|
||||
print '<tr><td>'.$langs->trans("RecommendedAmount").'</td><td>';
|
||||
$amount = ((is_null($object->amount) || $object->amount === '') ? '' : price($object->amount));
|
||||
print '<input name="amount" size="5" value="';
|
||||
print $amount;
|
||||
print '">';
|
||||
print '</td></tr>';
|
||||
|
||||
print '<tr><td>'.$form->textwithpicto($langs->trans("CanEditAmountShort"), $langs->transnoentities("CanEditAmountDetail")).'</td><td>';
|
||||
print $form->selectyesno("caneditamount", $object->caneditamount, 1);
|
||||
print '<tr><td class="tdtop">'.$langs->trans("AmountFormulaDescription").'</td><td>';
|
||||
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 '</td></tr>';
|
||||
|
||||
print '<tr><td>'.$langs->trans("VoteAllowed").'</td><td>';
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -576,7 +576,14 @@ if (empty($reshook) && $action == 'add') { // Test on permission not required he
|
|||
// 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)."<br>\n";
|
||||
}
|
||||
|
||||
if (GETPOST('member_email')) {
|
||||
$urlback .= '&email='.urlencode(GETPOST('member_email'));
|
||||
|
|
@ -992,17 +999,16 @@ if (getDolGlobalString('MEMBER_SKIP_TABLE') || getDolGlobalString('MEMBER_NEWFOR
|
|||
$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
|
||||
|
|
@ -1014,7 +1020,8 @@ if (getDolGlobalString('MEMBER_SKIP_TABLE') || getDolGlobalString('MEMBER_NEWFOR
|
|||
$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);
|
||||
|
|
@ -1030,13 +1037,21 @@ if (getDolGlobalString('MEMBER_SKIP_TABLE') || getDolGlobalString('MEMBER_NEWFOR
|
|||
$amount = getDolGlobalString('MEMBER_NEWFORM_AMOUNT');
|
||||
}
|
||||
|
||||
$amountformuladescription=$amountformuladescriptionbytype[$typeid];
|
||||
if ($caneditamount === "1") {
|
||||
print '<input type="text" name="amount" id="amount" class="flat amount width50" value="'.$showedamount.'">';
|
||||
print '<input type="text" name="amount" id="amounthidden" class="flat amount width50 hidden" disabled value="'.$showedamount.'">';
|
||||
print ' '.$langs->trans("Currency".$conf->currency).'<span class="opacitymedium hideifautoturnover">';
|
||||
if (!getDolGlobalString('MEMBER_NEWFORM_DOLIBARRTURNOVER')) {
|
||||
print ' - ';
|
||||
print $amount > 0 ? $langs->trans("AnyAmountWithAdvisedAmount", price($amount, 0, $langs, 1, -1, -1, $conf->currency)) : $langs->trans("AnyAmountWithoutAdvisedAmount");
|
||||
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 '</span><br/><span id="minimumamount" class="opacitymedium">'.$langs->trans("MinimumAmountShort").' : '.price(max(getDolGlobalInt("MEMBER_MIN_AMOUNT"), $minimumamount), 0, $langs, 1, -1, -1, $conf->currency);
|
||||
}
|
||||
print '</span>';
|
||||
} else {
|
||||
|
|
@ -1050,40 +1065,6 @@ if (getDolGlobalString('MEMBER_SKIP_TABLE') || getDolGlobalString('MEMBER_NEWFOR
|
|||
print '</span>';
|
||||
}
|
||||
print '</td></tr>';
|
||||
|
||||
// Add JS to manage the background of amount depending on type
|
||||
if ($conf->use_javascript_ajax) {
|
||||
print "<script>
|
||||
var amountbytype = $amountbytype_json;
|
||||
var canEditAmount = $caneditamountbytype_json;
|
||||
</script>";
|
||||
|
||||
print '<script>
|
||||
jQuery(function($) {
|
||||
$("#typeid").on("change", function() {
|
||||
console.log("Type of membership changed, we force amount update");
|
||||
let typeId = $(this).val();
|
||||
let amountVal = amountbytype[typeId] || 0;
|
||||
let formattedAmount = parseFloat(amountVal);
|
||||
|
||||
if (canEditAmount[typeId] === "1") {
|
||||
// Editable mode
|
||||
$("#amount").val(formattedAmount).prop("disabled", false).removeClass("hidden");
|
||||
$("#amounthidden").addClass("hidden");
|
||||
$(".hideifautoturnover").removeClass("hidden");
|
||||
} else {
|
||||
// Read-only mode
|
||||
$("#amounthidden").val(formattedAmount).prop("disabled", true).removeClass("hidden");
|
||||
$("#amount").addClass("hidden");
|
||||
$(".hideifautoturnover").addClass("hidden");
|
||||
}
|
||||
});
|
||||
|
||||
// Trigger it once so the amount matches the initial selection
|
||||
$("#typeid").trigger("change");
|
||||
});
|
||||
</script>';
|
||||
}
|
||||
}
|
||||
|
||||
// Display Captcha code if is enabled
|
||||
|
|
@ -1109,6 +1090,126 @@ if (getDolGlobalString('MEMBER_SKIP_TABLE') || getDolGlobalString('MEMBER_NEWFOR
|
|||
}
|
||||
print '</div>';
|
||||
|
||||
// Add JS to manage the background of amount depending on type
|
||||
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);
|
||||
$currencysymbol =$langs->getCurrencySymbol($conf->currency);
|
||||
|
||||
print '<script>
|
||||
jQuery(function($) {
|
||||
// ----- Shared data -----
|
||||
var amountByType = ' . $amountbytype_json . ';
|
||||
var canEditAmountByType = ' . $caneditamountbytype_json . ';
|
||||
var amountFormulaDescriptionByType = ' . $amountformuladescriptionbytype_json . ';
|
||||
var minimumAmountByType = ' . $minimumamountbytype_json . ';
|
||||
var memberMinAmount = ' . getDolGlobalInt("MEMBER_MIN_AMOUNT") . ';
|
||||
var currencySymbol = ' . json_encode($currencysymbol) . ';
|
||||
|
||||
// Translations prepared by PHP
|
||||
var langs = {
|
||||
AnyAmountWithAdvisedAmount: ' . json_encode($langs->trans("AnyAmountWithAdvisedAmount", "__VAL__")) . ',
|
||||
AnyAmountWithoutAdvisedAmount: ' . json_encode($langs->trans("AnyAmountWithoutAdvisedAmount")) . ',
|
||||
MinimumAmountShort: ' . json_encode($langs->trans("MinimumAmountShort", "__VAL__")) . ',
|
||||
trans: function(key, val) {
|
||||
if (!this[key]) return key;
|
||||
return this[key].replace("__VAL__", val || "");
|
||||
}
|
||||
};
|
||||
|
||||
// ----- Helpers -----
|
||||
function getCurrentMin() {
|
||||
let typeId = $("#typeid").val() || 0;
|
||||
let minimumAmount = minimumAmountByType[typeId] || 0;
|
||||
return Math.max(memberMinAmount, minimumAmount);
|
||||
}
|
||||
|
||||
function checkAmount() {
|
||||
let raw = $("#amount").val() || "";
|
||||
let val = parseFloat(raw.replace(",", ".")) || 0;
|
||||
let minimum = getCurrentMin();
|
||||
if (val < minimum) {
|
||||
$("#submitsave").prop("disabled", true);
|
||||
} else {
|
||||
$("#submitsave").prop("disabled", false);
|
||||
}
|
||||
}
|
||||
|
||||
function updateAmountAndTexts() {
|
||||
let typeId = $("#typeid").val();
|
||||
let amountVal = amountByType[typeId] || 0;
|
||||
let formattedAmount = parseFloat(amountVal);
|
||||
let canEdit = canEditAmountByType[typeId] === "1";
|
||||
let amountFormulaDescription = amountFormulaDescriptionByType[typeId] || "";
|
||||
let minimumAmount = minimumAmountByType[typeId] || 0;
|
||||
let minimum = Math.max(memberMinAmount, minimumAmount);
|
||||
|
||||
if (canEdit) {
|
||||
// Editable mode
|
||||
$("#amount").val(formattedAmount).prop("disabled", false).removeClass("hidden");
|
||||
$("#amounthidden").addClass("hidden");
|
||||
$(".hideifautoturnover").removeClass("hidden");
|
||||
|
||||
// Description formula or default text
|
||||
if (amountFormulaDescription.trim() !== "") {
|
||||
$("#amountdescription").html(" - " + amountFormulaDescription);
|
||||
} else {
|
||||
if (amountVal > 0) {
|
||||
$("#amountdescription").html(" - " + langs.trans("AnyAmountWithAdvisedAmount", formattedAmount + " " + currencySymbol));
|
||||
} else {
|
||||
$("#amountdescription").html(" - " + langs.trans("AnyAmountWithoutAdvisedAmount"));
|
||||
}
|
||||
}
|
||||
|
||||
// Minimum amount label
|
||||
if (minimum > 0) {
|
||||
$("#minimumamount")
|
||||
.html(langs.trans("MinimumAmountShort") + " : " + minimum + " " + currencySymbol)
|
||||
.removeClass("hidden");
|
||||
} else {
|
||||
$("#minimumamount").addClass("hidden");
|
||||
}
|
||||
} else {
|
||||
// Read-only mode
|
||||
$("#amounthidden").val(formattedAmount).prop("disabled", true).removeClass("hidden");
|
||||
$("#amount").addClass("hidden");
|
||||
$(".hideifautoturnover").addClass("hidden");
|
||||
|
||||
if (amountVal > 0) {
|
||||
$("#amountdescription").html(" - " + langs.trans("AnyAmountWithAdvisedAmount", formattedAmount + " " + currencySymbol));
|
||||
} else {
|
||||
$("#amountdescription").html(" - " + langs.trans("AnyAmountWithoutAdvisedAmount"));
|
||||
}
|
||||
|
||||
$("#minimumamount").addClass("hidden");
|
||||
}
|
||||
|
||||
// After updating fields, re‑check the amount validity
|
||||
checkAmount();
|
||||
}
|
||||
|
||||
// ----- Bind events -----
|
||||
$("#typeid").on("change", function() {
|
||||
console.log("Type of membership changed, update amount, description and minimum");
|
||||
updateAmountAndTexts();
|
||||
});
|
||||
|
||||
$("#amount").on("keyup change", function() {
|
||||
checkAmount();
|
||||
});
|
||||
});
|
||||
</script>';
|
||||
}
|
||||
|
||||
print "</form>\n";
|
||||
print "<br>";
|
||||
|
|
@ -1145,7 +1246,7 @@ if (getDolGlobalString('MEMBER_SKIP_TABLE') || getDolGlobalString('MEMBER_NEWFOR
|
|||
print '<tr class="liste_titre">';
|
||||
print '<th>'.$langs->trans("Label").'</th>';
|
||||
print '<th class="center">'.$langs->trans("MembershipDuration").'</th>';
|
||||
print '<th class="center">'.$langs->trans("Amount").'</th>';
|
||||
print '<th class="center">'.$langs->trans("RecommendedAmount").'</th>';
|
||||
print '<th class="center">'.$langs->trans("MembersNature").'</th>';
|
||||
if (empty($hidevoteallowed)) {
|
||||
print '<th class="center">'.$langs->trans("VoteAllowed").'</th>';
|
||||
|
|
@ -1162,6 +1263,7 @@ if (getDolGlobalString('MEMBER_SKIP_TABLE') || getDolGlobalString('MEMBER_NEWFOR
|
|||
|
||||
$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 '<tr class="oddeven">';
|
||||
// Label
|
||||
|
|
@ -1177,6 +1279,7 @@ if (getDolGlobalString('MEMBER_SKIP_TABLE') || getDolGlobalString('MEMBER_NEWFOR
|
|||
// 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');
|
||||
|
|
@ -1186,7 +1289,7 @@ if (getDolGlobalString('MEMBER_SKIP_TABLE') || getDolGlobalString('MEMBER_NEWFOR
|
|||
$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;
|
||||
|
||||
|
|
|
|||
|
|
@ -43,7 +43,6 @@ if (!defined('NOIPCHECK')) {
|
|||
if (!defined('NOBROWSERNOTIF')) {
|
||||
define('NOBROWSERNOTIF', '1');
|
||||
}
|
||||
|
||||
if (!defined('XFRAMEOPTIONS_ALLOWALL')) {
|
||||
define('XFRAMEOPTIONS_ALLOWALL', '1');
|
||||
}
|
||||
|
|
@ -605,12 +604,13 @@ if ($ispaymentok) {
|
|||
|
||||
// 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 @@ if ($ispaymentok) {
|
|||
// $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 @@ if ($ispaymentok) {
|
|||
|
||||
// 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');
|
||||
|
|
|
|||
Loading…
Reference in a new issue