Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Minimum amount and subscription's amount formula description
  • Loading branch information
Thatoo committed Dec 14, 2025
commit 96061f57aabe571b7f85f3e7d990a15fdd148e5c
111 changes: 101 additions & 10 deletions htdocs/adherents/class/adherent_type.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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",),
Expand Down Expand Up @@ -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)
*/
public $caneditamount;
/**
* @var string Describe the subscription amount formula to follow
*/
public $amountformuladescription;

/**
* @var string Public note
Expand Down Expand Up @@ -495,9 +507,11 @@ 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 .= "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 .= "caneditamount = ".((int) $this->caneditamount).",";
$sql .= "duration = '".$this->db->escape($this->duration_value.$this->duration_unit)."',";
$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).",";
$sql .= "mail_valid = '".$this->db->escape($this->mail_valid)."'";
Expand Down Expand Up @@ -586,13 +600,14 @@ 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;

dol_syslog("Adherent_type::fetch", LOG_DEBUG);

$resql = $this->db->query($sql);

if ($resql) {
if ($this->db->num_rows($resql)) {
$obj = $this->db->fetch_object($resql);
Expand All @@ -606,8 +621,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->caneditamount = $obj->caneditamount;
$this->minimumamount = $obj->minimumamount;
$this->amount = $obj->amount;
$this->caneditamount = $obj->caneditamount;
$this->amountformuladescription = $obj->amountformuladescription;
$this->mail_valid = $obj->mail_valid;
$this->note = $obj->note_public; // deprecated
$this->note_public = $obj->note_public;
Expand Down Expand Up @@ -782,6 +799,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<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)
*
Expand Down
Loading