Merge pull request #17451 from daraelmin/daraelmin-new-amntbyadhtype

NEW #17292 default subscription amount by adherent type
This commit is contained in:
Laurent Destailleur 2021-05-03 15:32:39 +02:00 committed by GitHub
commit ec544cb20e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 94 additions and 28 deletions

View File

@ -9,7 +9,6 @@
* Copyright (C) 2012 J. Fernando Lagrange <fernando@demo-tic.org> * Copyright (C) 2012 J. Fernando Lagrange <fernando@demo-tic.org>
* Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr> * Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
* Copyright (C) 2020-2021 Frédéric France <frederic.france@netlogic.fr> * Copyright (C) 2020-2021 Frédéric France <frederic.france@netlogic.fr>
* Copyright (C) 2021 Waël Almoman <info@almoman.com>
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -34,7 +33,6 @@
require '../../main.inc.php'; require '../../main.inc.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/member.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/member.lib.php';
require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent_type.class.php';
// Load translation files required by the page // Load translation files required by the page
$langs->loadLangs(array("admin", "members")); $langs->loadLangs(array("admin", "members"));

View File

@ -4,7 +4,7 @@
* Copyright (C) 2009-2017 Regis Houssin <regis.houssin@inodbox.com> * Copyright (C) 2009-2017 Regis Houssin <regis.houssin@inodbox.com>
* Copyright (C) 2016 Charlie Benke <charlie@patas-monkey.com> * Copyright (C) 2016 Charlie Benke <charlie@patas-monkey.com>
* Copyright (C) 2018-2019 Thibault Foucart <support@ptibogxiv.net> * Copyright (C) 2018-2019 Thibault Foucart <support@ptibogxiv.net>
* Copyright (C) 2021 Waël Almoman <info@almoman.com> * Copyright (C) 2021 Waël Almoman <info@almoman.com>
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -89,6 +89,11 @@ class AdherentType extends CommonObject
*/ */
public $subscription; public $subscription;
/**
* @var float amount for subscription
*/
public $amount;
/** @var string Public note */ /** @var string Public note */
public $note; public $note;
@ -361,6 +366,7 @@ class AdherentType extends CommonObject
$sql .= "libelle = '".$this->db->escape($this->label)."',"; $sql .= "libelle = '".$this->db->escape($this->label)."',";
$sql .= "morphy = '".$this->db->escape($this->morphy)."',"; $sql .= "morphy = '".$this->db->escape($this->morphy)."',";
$sql .= "subscription = '".$this->db->escape($this->subscription)."',"; $sql .= "subscription = '".$this->db->escape($this->subscription)."',";
$sql .= "amount = '".$this->db->escape($this->amount)."',";
$sql .= "duration = '".$this->db->escape($this->duration_value.$this->duration_unit)."',"; $sql .= "duration = '".$this->db->escape($this->duration_value.$this->duration_unit)."',";
$sql .= "note = '".$this->db->escape($this->note)."',"; $sql .= "note = '".$this->db->escape($this->note)."',";
$sql .= "vote = ".(integer) $this->db->escape($this->vote).","; $sql .= "vote = ".(integer) $this->db->escape($this->vote).",";
@ -455,7 +461,7 @@ class AdherentType extends CommonObject
{ {
global $langs, $conf; global $langs, $conf;
$sql = "SELECT d.rowid, d.libelle as label, d.morphy, d.statut as status, d.duration, d.subscription, d.mail_valid, d.note, d.vote"; $sql = "SELECT d.rowid, d.libelle as label, d.morphy, d.statut as status, d.duration, d.subscription, d.amount, d.mail_valid, d.note, d.vote";
$sql .= " FROM ".MAIN_DB_PREFIX."adherent_type as d"; $sql .= " FROM ".MAIN_DB_PREFIX."adherent_type as d";
$sql .= " WHERE d.rowid = ".(int) $rowid; $sql .= " WHERE d.rowid = ".(int) $rowid;
@ -475,6 +481,7 @@ class AdherentType extends CommonObject
$this->duration_value = substr($obj->duration, 0, dol_strlen($obj->duration) - 1); $this->duration_value = substr($obj->duration, 0, dol_strlen($obj->duration) - 1);
$this->duration_unit = substr($obj->duration, -1); $this->duration_unit = substr($obj->duration, -1);
$this->subscription = $obj->subscription; $this->subscription = $obj->subscription;
$this->amount = $obj->amount;
$this->mail_valid = $obj->mail_valid; $this->mail_valid = $obj->mail_valid;
$this->note = $obj->note; $this->note = $obj->note;
$this->vote = $obj->vote; $this->vote = $obj->vote;
@ -535,6 +542,45 @@ class AdherentType extends CommonObject
return $adherenttypes; return $adherenttypes;
} }
/**
* Return list of amount by type id
*
* @param int $status Filter on status of type
* @return array List of types of members
*/
public function amountByType($status = null)
{
global $conf, $langs;
$amountbytype = array();
$sql = "SELECT rowid, amount";
$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);
$amountbytype[$obj->rowid] = $obj->amount;
$i++;
}
}
} else {
print $this->db->error();
}
return $amountbytype;
}
/** /**
* Return array of Member objects for member type this->id (or all if this->id not defined) * Return array of Member objects for member type this->id (or all if this->id not defined)
* *

View File

@ -7,6 +7,7 @@
* Copyright (C) 2015 Alexandre Spangaro <aspangaro@open-dsi.fr> * Copyright (C) 2015 Alexandre Spangaro <aspangaro@open-dsi.fr>
* Copyright (C) 2019 Thibault Foucart <support@ptibogxiv.net> * Copyright (C) 2019 Thibault Foucart <support@ptibogxiv.net>
* Copyright (C) 2020 Josep Lluís Amador <joseplluis@lliuretic.cat> * Copyright (C) 2020 Josep Lluís Amador <joseplluis@lliuretic.cat>
* Copyright (C) 2021 Waël Almoman <info@almoman.com>
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -70,6 +71,7 @@ $label = GETPOST("label", "alpha");
$morphy = GETPOST("morphy", "alpha"); $morphy = GETPOST("morphy", "alpha");
$status = GETPOST("status", "int"); $status = GETPOST("status", "int");
$subscription = GETPOST("subscription", "int"); $subscription = GETPOST("subscription", "int");
$amount = price2num(GETPOST('amount', 'alpha'), 'MT');
$duration_value = GETPOST('duration_value', 'int'); $duration_value = GETPOST('duration_value', 'int');
$duration_unit = GETPOST('duration_unit', 'alpha'); $duration_unit = GETPOST('duration_unit', 'alpha');
$vote = GETPOST("vote", "int"); $vote = GETPOST("vote", "int");
@ -114,14 +116,15 @@ if ($cancel) {
if ($action == 'add' && $user->rights->adherent->configurer) { if ($action == 'add' && $user->rights->adherent->configurer) {
$object->label = trim($label); $object->label = trim($label);
$object->morphy = trim($morphy); $object->morphy = trim($morphy);
$object->status = (int) $status; $object->status = (int) $status;
$object->subscription = (int) $subscription; $object->subscription = (int) $subscription;
$object->duration_value = $duration_value; $object->amount = $amount;
$object->duration_unit = $duration_unit; $object->duration_value = $duration_value;
$object->note = trim($comment); $object->duration_unit = $duration_unit;
$object->note = trim($comment);
$object->mail_valid = trim($mail_valid); $object->mail_valid = trim($mail_valid);
$object->vote = (int) $vote; $object->vote = (int) $vote;
// Fill array 'array_options' with data from add form // Fill array 'array_options' with data from add form
$ret = $extrafields->setOptionalsFromPost(null, $object); $ret = $extrafields->setOptionalsFromPost(null, $object);
@ -164,15 +167,16 @@ if ($action == 'update' && $user->rights->adherent->configurer) {
$object->oldcopy = clone $object; $object->oldcopy = clone $object;
$object->label = trim($label); $object->label= trim($label);
$object->morphy = trim($morphy); $object->morphy = trim($morphy);
$object->status = (int) $status; $object->status = (int) $status;
$object->subscription = (int) $subscription; $object->subscription = (int) $subscription;
$object->duration_value = $duration_value; $object->amount = $amount;
$object->duration_unit = $duration_unit; $object->duration_value = $duration_value;
$object->note = trim($comment); $object->duration_unit = $duration_unit;
$object->note = trim($comment);
$object->mail_valid = trim($mail_valid); $object->mail_valid = trim($mail_valid);
$object->vote = (boolean) trim($vote); $object->vote = (boolean) trim($vote);
// Fill array 'array_options' with data from add form // Fill array 'array_options' with data from add form
$ret = $extrafields->setOptionalsFromPost(null, $object); $ret = $extrafields->setOptionalsFromPost(null, $object);
@ -222,7 +226,7 @@ llxHeader('', $langs->trans("MembersTypeSetup"), $help_url);
if (!$rowid && $action != 'create' && $action != 'edit') { if (!$rowid && $action != 'create' && $action != 'edit') {
//print dol_get_fiche_head(''); //print dol_get_fiche_head('');
$sql = "SELECT d.rowid, d.libelle as label, d.subscription, d.vote, d.statut as status, d.morphy"; $sql = "SELECT d.rowid, d.libelle as label, d.subscription, d.amount, d.vote, d.statut as status, d.morphy";
$sql .= " FROM ".MAIN_DB_PREFIX."adherent_type as d"; $sql .= " FROM ".MAIN_DB_PREFIX."adherent_type as d";
$sql .= " WHERE d.entity IN (".getEntity('member_type').")"; $sql .= " WHERE d.entity IN (".getEntity('member_type').")";
@ -268,6 +272,7 @@ if (!$rowid && $action != 'create' && $action != 'edit') {
print '<th>'.$langs->trans("Label").'</th>'; print '<th>'.$langs->trans("Label").'</th>';
print '<th class="center">'.$langs->trans("MembersNature").'</th>'; print '<th class="center">'.$langs->trans("MembersNature").'</th>';
print '<th class="center">'.$langs->trans("SubscriptionRequired").'</th>'; print '<th class="center">'.$langs->trans("SubscriptionRequired").'</th>';
print '<th class="center">'.$langs->trans("Amount").'</th>';
print '<th class="center">'.$langs->trans("VoteAllowed").'</th>'; print '<th class="center">'.$langs->trans("VoteAllowed").'</th>';
print '<th class="center">'.$langs->trans("Status").'</th>'; print '<th class="center">'.$langs->trans("Status").'</th>';
print '<th>&nbsp;</th>'; print '<th>&nbsp;</th>';
@ -283,6 +288,7 @@ if (!$rowid && $action != 'create' && $action != 'edit') {
$membertype->label = $objp->rowid; $membertype->label = $objp->rowid;
$membertype->status = $objp->status; $membertype->status = $objp->status;
$membertype->subscription = $objp->subscription; $membertype->subscription = $objp->subscription;
$membertype->amount = $objp->amount;
print '<tr class="oddeven">'; print '<tr class="oddeven">';
print '<td>'; print '<td>';
@ -300,6 +306,7 @@ if (!$rowid && $action != 'create' && $action != 'edit') {
} }
print '</td>'; print '</td>';
print '<td class="center">'.yn($objp->subscription).'</td>'; print '<td class="center">'.yn($objp->subscription).'</td>';
print '<td class="center">'.price($objp->amount).'</td>';
print '<td class="center">'.yn($objp->vote).'</td>'; print '<td class="center">'.yn($objp->vote).'</td>';
print '<td class="center">'.$membertype->getLibStatut(5).'</td>'; print '<td class="center">'.$membertype->getLibStatut(5).'</td>';
if ($user->rights->adherent->configurer) { if ($user->rights->adherent->configurer) {
@ -358,6 +365,10 @@ if ($action == 'create') {
print $form->selectyesno("subscription", 1, 1); print $form->selectyesno("subscription", 1, 1);
print '</td></tr>'; print '</td></tr>';
print '<tr><td>'.$langs->trans("Amount").'</td><td>';
print '<input name="amount" size="5" value="'.price($amount).'">';
print '</td></tr>';
print '<tr><td>'.$langs->trans("VoteAllowed").'</td><td>'; print '<tr><td>'.$langs->trans("VoteAllowed").'</td><td>';
print $form->selectyesno("vote", GETPOSTISSET("vote") ? GETPOST('vote', 'aZ09') : 1, 1); print $form->selectyesno("vote", GETPOSTISSET("vote") ? GETPOST('vote', 'aZ09') : 1, 1);
print '</td></tr>'; print '</td></tr>';
@ -434,6 +445,10 @@ if ($rowid > 0) {
print yn($object->subscription); print yn($object->subscription);
print '</tr>'; print '</tr>';
print '<tr><td class="titlefield">'.$langs->trans("Amount").'</td><td>';
print price($object->amount);
print '</tr>';
print '<tr><td>'.$langs->trans("VoteAllowed").'</td><td>'; print '<tr><td>'.$langs->trans("VoteAllowed").'</td><td>';
print yn($object->vote); print yn($object->vote);
print '</tr>'; print '</tr>';
@ -496,13 +511,13 @@ if ($rowid > 0) {
$sql = "SELECT d.rowid, d.login, d.firstname, d.lastname, d.societe as company,"; $sql = "SELECT d.rowid, d.login, d.firstname, d.lastname, d.societe as company,";
$sql .= " d.datefin,"; $sql .= " d.datefin,";
$sql .= " d.email, d.fk_adherent_type as type_id, d.morphy, d.statut as status,"; $sql .= " d.email, d.fk_adherent_type as type_id, d.morphy, d.statut as status,";
$sql .= " t.libelle as type, t.subscription"; $sql .= " t.libelle as type, t.subscription, t.amount";
$sql .= " FROM ".MAIN_DB_PREFIX."adherent as d, ".MAIN_DB_PREFIX."adherent_type as t"; $sql .= " FROM ".MAIN_DB_PREFIX."adherent as d, ".MAIN_DB_PREFIX."adherent_type as t";
$sql .= " WHERE d.fk_adherent_type = t.rowid "; $sql .= " WHERE d.fk_adherent_type = t.rowid ";
$sql .= " AND d.entity IN (".getEntity('adherent').")"; $sql .= " AND d.entity IN (".getEntity('adherent').")";
$sql .= " AND t.rowid = ".((int) $object->id); $sql .= " AND t.rowid = ".((int) $object->id);
if ($sall) { if ($sall) {
$sql .= natural_search(array("f.firstname", "d.lastname", "d.societe", "d.email", "d.login", "d.address", "d.town", "d.note_public", "d.note_private"), $sall); $sql .= natural_search(array("d.firstname", "d.lastname", "d.societe", "d.email", "d.login", "d.address", "d.town", "d.note_public", "d.note_private"), $sall);
} }
if ($status != '') { if ($status != '') {
$sql .= natural_search('d.statut', $status, 2); $sql .= natural_search('d.statut', $status, 2);
@ -781,6 +796,10 @@ if ($rowid > 0) {
print $form->selectyesno("subscription", $object->subscription, 1); print $form->selectyesno("subscription", $object->subscription, 1);
print '</td></tr>'; print '</td></tr>';
print '<tr><td>'.$langs->trans("DefineAmountMemberType").'</td><td>';
print '<input name="amount" size="5" value="'.price($object->amount).'">';
print '</td></tr>';
print '<tr><td>'.$langs->trans("VoteAllowed").'</td><td>'; print '<tr><td>'.$langs->trans("VoteAllowed").'</td><td>';
print $form->selectyesno("vote", $object->vote, 1); print $form->selectyesno("vote", $object->vote, 1);
print '</td></tr>'; print '</td></tr>';

View File

@ -467,4 +467,7 @@ create table llx_knowledgemanagement_knowledgerecord_extrafields
tms timestamp, tms timestamp,
fk_object integer NOT NULL, fk_object integer NOT NULL,
import_key varchar(14) -- import key import_key varchar(14) -- import key
) ENGINE=innodb; ) ENGINE=innodb;
-- add default amount by member type
ALTER TABLE llx_adherent_type ADD COLUMN amount DOUBLE(24,8) NULL DEFAULT NULL AFTER subscription;

View File

@ -32,6 +32,7 @@ create table llx_adherent_type
morphy varchar(3) NOT NULL, morphy varchar(3) NOT NULL,
duration varchar(6) DEFAULT NULL, duration varchar(6) DEFAULT NULL,
subscription varchar(3) NOT NULL DEFAULT '1', subscription varchar(3) NOT NULL DEFAULT '1',
amount double(24,8) DEFAULT NULL,
vote varchar(3) NOT NULL DEFAULT '1', vote varchar(3) NOT NULL DEFAULT '1',
note text, note text,
mail_valid text mail_valid text

View File

@ -1444,20 +1444,18 @@ if ($source == 'member' || $source == 'membersubscription') {
print '<tr class="CTableRow'.($var ? '1' : '2').'"><td class="CTableRow'.($var ? '1' : '2').'">'.$langs->trans("LastMemberType"); print '<tr class="CTableRow'.($var ? '1' : '2').'"><td class="CTableRow'.($var ? '1' : '2').'">'.$langs->trans("LastMemberType");
print '</td><td class="CTableRow'.($var ? '1' : '2').'">'.dol_escape_htmltag($member->type); print '</td><td class="CTableRow'.($var ? '1' : '2').'">'.dol_escape_htmltag($member->type);
print "</td></tr>\n"; print "</td></tr>\n";
}
if (!empty($conf->global->MEMBER_SUBSCRIPTION_AMOUNT_BY_TYPE)) { require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent_type.class.php';
$adht = new AdherentType($db);
// Amount by member type // Amount by member type
$amountbytype = array(); // TODO Read the amount of subscription into table of types $amountbytype = $adht->amountByType(1);
// Set the member type // Set the member type
$member->typeid = (int) (GETPOSTISSET("typeid") ? GETPOST("typeid", 'int') : $member->typeid); $member->typeid = (int) (GETPOSTISSET("typeid") ? GETPOST("typeid", 'int') : $member->typeid);
// If we change the type of membership, we set also label of new type // If we change the type of membership, we set also label of new type
$member->type = dol_getIdFromCode($db, $member->typeid, 'adherent_type', 'rowid', 'libelle'); $member->type = dol_getIdFromCode($db, $member->typeid, 'adherent_type', 'rowid', 'libelle');
// Set amount for the subscription // Set amount for the subscription
$amount = (!empty($member->last_subscription_amount)) ? $member->last_subscription_amount : $amountbytype[$member->typeid]; $amount = (!empty($amountbytype[$member->typeid])) ? $amountbytype[$member->typeid] : $member->last_subscription_amount;
// list member type // list member type
require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent_type.class.php';
$adht = new AdherentType($db);
if ( !$action) { if ( !$action) {
$form = new Form($db); // so we can call method selectarray $form = new Form($db); // so we can call method selectarray
print '<tr class="CTableRow'.($var ? '1' : '2').'"><td class="CTableRow'.($var ? '1' : '2').'">'.$langs->trans("NewSubscription"); print '<tr class="CTableRow'.($var ? '1' : '2').'"><td class="CTableRow'.($var ? '1' : '2').'">'.$langs->trans("NewSubscription");

View File

@ -154,6 +154,7 @@ class AdherentTest extends PHPUnit\Framework\TestCase
$localobject->statut=1; $localobject->statut=1;
$localobject->label='Adherent type test'; $localobject->label='Adherent type test';
$localobject->subscription=1; $localobject->subscription=1;
$localobject->amount=0;
$localobject->vote=1; $localobject->vote=1;
$localobject->company='Old company label'; $localobject->company='Old company label';
$result=$localobject->create($user); $result=$localobject->create($user);