From 5f23c68f8572411ec19fefc0320328cbe3760d8f Mon Sep 17 00:00:00 2001 From: daraelmin Date: Sat, 1 May 2021 20:01:18 +0200 Subject: [PATCH 01/11] Update type.php --- htdocs/adherents/type.php | 53 ++++++++++++++++++++++++++------------- 1 file changed, 36 insertions(+), 17 deletions(-) diff --git a/htdocs/adherents/type.php b/htdocs/adherents/type.php index c9b98784142..707dd7acb7c 100644 --- a/htdocs/adherents/type.php +++ b/htdocs/adherents/type.php @@ -7,6 +7,7 @@ * Copyright (C) 2015 Alexandre Spangaro * Copyright (C) 2019 Thibault Foucart * Copyright (C) 2020 Josep Lluís Amador + * Copyright (C) 2021 Waël Almoman * * 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 @@ -70,6 +71,7 @@ $label = GETPOST("label", "alpha"); $morphy = GETPOST("morphy", "alpha"); $status = GETPOST("status", "int"); $subscription = GETPOST("subscription", "int"); +$amount = price2num(GETPOST('amount', 'alpha'), 'MT'); $duration_value = GETPOST('duration_value', 'int'); $duration_unit = GETPOST('duration_unit', 'alpha'); $vote = GETPOST("vote", "int"); @@ -114,14 +116,15 @@ if ($cancel) { if ($action == 'add' && $user->rights->adherent->configurer) { $object->label = trim($label); - $object->morphy = trim($morphy); - $object->status = (int) $status; - $object->subscription = (int) $subscription; - $object->duration_value = $duration_value; - $object->duration_unit = $duration_unit; - $object->note = trim($comment); + $object->morphy = trim($morphy); + $object->status = (int) $status; + $object->subscription = (int) $subscription; + $object->amount = $amount; + $object->duration_value = $duration_value; + $object->duration_unit = $duration_unit; + $object->note = trim($comment); $object->mail_valid = trim($mail_valid); - $object->vote = (int) $vote; + $object->vote = (int) $vote; // Fill array 'array_options' with data from add form $ret = $extrafields->setOptionalsFromPost(null, $object); @@ -164,15 +167,16 @@ if ($action == 'update' && $user->rights->adherent->configurer) { $object->oldcopy = clone $object; - $object->label = trim($label); - $object->morphy = trim($morphy); - $object->status = (int) $status; + $object->label= trim($label); + $object->morphy = trim($morphy); + $object->status = (int) $status; $object->subscription = (int) $subscription; - $object->duration_value = $duration_value; - $object->duration_unit = $duration_unit; - $object->note = trim($comment); + $object->amount = $amount; + $object->duration_value = $duration_value; + $object->duration_unit = $duration_unit; + $object->note = trim($comment); $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 $ret = $extrafields->setOptionalsFromPost(null, $object); @@ -222,7 +226,7 @@ llxHeader('', $langs->trans("MembersTypeSetup"), $help_url); if (!$rowid && $action != 'create' && $action != 'edit') { //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 .= " WHERE d.entity IN (".getEntity('member_type').")"; @@ -268,6 +272,7 @@ if (!$rowid && $action != 'create' && $action != 'edit') { print ''.$langs->trans("Label").''; print ''.$langs->trans("MembersNature").''; print ''.$langs->trans("SubscriptionRequired").''; + print ''.$langs->trans("Amount").''; print ''.$langs->trans("VoteAllowed").''; print ''.$langs->trans("Status").''; print ' '; @@ -283,6 +288,7 @@ if (!$rowid && $action != 'create' && $action != 'edit') { $membertype->label = $objp->rowid; $membertype->status = $objp->status; $membertype->subscription = $objp->subscription; + $membertype->amount = $objp->amount; print ''; print ''; @@ -300,6 +306,7 @@ if (!$rowid && $action != 'create' && $action != 'edit') { } print ''; print ''.yn($objp->subscription).''; + print ''.price($objp->amount).''; print ''.yn($objp->vote).''; print ''.$membertype->getLibStatut(5).''; if ($user->rights->adherent->configurer) { @@ -358,6 +365,10 @@ if ($action == 'create') { print $form->selectyesno("subscription", 1, 1); print ''; + print ''.$langs->trans("Amount").''; + print ''; + print ''; + print ''.$langs->trans("VoteAllowed").''; print $form->selectyesno("vote", GETPOSTISSET("vote") ? GETPOST('vote', 'aZ09') : 1, 1); print ''; @@ -434,6 +445,10 @@ if ($rowid > 0) { print yn($object->subscription); print ''; + print ''.$langs->trans("Amount").''; + print price($object->amount); + print ''; + print ''.$langs->trans("VoteAllowed").''; print yn($object->vote); print ''; @@ -496,13 +511,13 @@ if ($rowid > 0) { $sql = "SELECT d.rowid, d.login, d.firstname, d.lastname, d.societe as company,"; $sql .= " d.datefin,"; $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 .= " WHERE d.fk_adherent_type = t.rowid "; $sql .= " AND d.entity IN (".getEntity('adherent').")"; $sql .= " AND t.rowid = ".((int) $object->id); 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 != '') { $sql .= natural_search('d.statut', $status, 2); @@ -780,6 +795,10 @@ if ($rowid > 0) { print ''.$langs->trans("SubscriptionRequired").''; print $form->selectyesno("subscription", $object->subscription, 1); print ''; + + print ''.$langs->trans("DefineAmountMemberType").''; + print ''; + print ''; print ''.$langs->trans("VoteAllowed").''; print $form->selectyesno("vote", $object->vote, 1); From 4c3e37681cd5bf2fe443f545db2c880daada24b3 Mon Sep 17 00:00:00 2001 From: daraelmin Date: Sat, 1 May 2021 20:06:15 +0200 Subject: [PATCH 02/11] Update adherent_type.class.php --- .../adherents/class/adherent_type.class.php | 49 ++++++++++++++++++- 1 file changed, 47 insertions(+), 2 deletions(-) diff --git a/htdocs/adherents/class/adherent_type.class.php b/htdocs/adherents/class/adherent_type.class.php index d051c40810b..4924acf5ab6 100644 --- a/htdocs/adherents/class/adherent_type.class.php +++ b/htdocs/adherents/class/adherent_type.class.php @@ -4,7 +4,7 @@ * Copyright (C) 2009-2017 Regis Houssin * Copyright (C) 2016 Charlie Benke * Copyright (C) 2018-2019 Thibault Foucart - * Copyright (C) 2021 Waël Almoman + * Copyright (C) 2021 Waël Almoman * * 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 @@ -88,6 +88,11 @@ class AdherentType extends CommonObject * @var int Subsription required (0 or 1) */ public $subscription; + + /** + * @var float amount for subscription if required + */ + public $amount; /** @var string Public note */ public $note; @@ -361,6 +366,7 @@ class AdherentType extends CommonObject $sql .= "libelle = '".$this->db->escape($this->label)."',"; $sql .= "morphy = '".$this->db->escape($this->morphy)."',"; $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 .= "note = '".$this->db->escape($this->note)."',"; $sql .= "vote = ".(integer) $this->db->escape($this->vote).","; @@ -455,7 +461,7 @@ class AdherentType extends CommonObject { 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 .= " 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_unit = substr($obj->duration, -1); $this->subscription = $obj->subscription; + $this->amount = $obj->amount; $this->mail_valid = $obj->mail_valid; $this->note = $obj->note; $this->vote = $obj->vote; @@ -535,6 +542,44 @@ class AdherentType extends CommonObject 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 amount_by_type($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) * From 5ff60c31e6fa48adfbc859dea846de8b87bc915d Mon Sep 17 00:00:00 2001 From: daraelmin Date: Sat, 1 May 2021 20:08:32 +0200 Subject: [PATCH 03/11] Update 13.0.0-14.0.0.sql --- htdocs/install/mysql/migration/13.0.0-14.0.0.sql | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/htdocs/install/mysql/migration/13.0.0-14.0.0.sql b/htdocs/install/mysql/migration/13.0.0-14.0.0.sql index 8eebe1db211..cda3f4310bb 100644 --- a/htdocs/install/mysql/migration/13.0.0-14.0.0.sql +++ b/htdocs/install/mysql/migration/13.0.0-14.0.0.sql @@ -467,4 +467,7 @@ create table llx_knowledgemanagement_knowledgerecord_extrafields tms timestamp, fk_object integer NOT NULL, import_key varchar(14) -- import key -) ENGINE=innodb; \ No newline at end of file +) ENGINE=innodb; + +-- add default amount by member type +ALTER TABLE llx_adherent_type ADD COLUMN amount DOUBLE(24,8) NULL DEFAULT NULL AFTER subscription; From 8457fef1a2684946094043b43f049a14d8bf5ec4 Mon Sep 17 00:00:00 2001 From: daraelmin Date: Sat, 1 May 2021 20:10:17 +0200 Subject: [PATCH 04/11] Update llx_adherent_type.sql --- htdocs/install/mysql/tables/llx_adherent_type.sql | 1 + 1 file changed, 1 insertion(+) diff --git a/htdocs/install/mysql/tables/llx_adherent_type.sql b/htdocs/install/mysql/tables/llx_adherent_type.sql index bdce18ef0bc..243372c0452 100644 --- a/htdocs/install/mysql/tables/llx_adherent_type.sql +++ b/htdocs/install/mysql/tables/llx_adherent_type.sql @@ -32,6 +32,7 @@ create table llx_adherent_type morphy varchar(3) NOT NULL, duration varchar(6) DEFAULT NULL, subscription varchar(3) NOT NULL DEFAULT '1', + amount double(24,8) DEFAULT NULL, vote varchar(3) NOT NULL DEFAULT '1', note text, mail_valid text From 031d258b328824eb7551af2afbfa9002af06cfa3 Mon Sep 17 00:00:00 2001 From: daraelmin Date: Sat, 1 May 2021 20:17:29 +0200 Subject: [PATCH 05/11] Update newpayment.php --- htdocs/public/payment/newpayment.php | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/htdocs/public/payment/newpayment.php b/htdocs/public/payment/newpayment.php index 8659b3ca8bd..10c929b78e2 100644 --- a/htdocs/public/payment/newpayment.php +++ b/htdocs/public/payment/newpayment.php @@ -1444,20 +1444,18 @@ if ($source == 'member' || $source == 'membersubscription') { print ''.$langs->trans("LastMemberType"); print ''.dol_escape_htmltag($member->type); print "\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 - $amountbytype = array(); // TODO Read the amount of subscription into table of types + $amountbytype = $adht->amount_by_type(1); // Set the member type $member->typeid = (int) (GETPOSTISSET("typeid") ? GETPOST("typeid", 'int') : $member->typeid); // 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'); // 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 - require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent_type.class.php'; - $adht = new AdherentType($db); if ( !$action) { $form = new Form($db); // so we can call method selectarray print ''.$langs->trans("NewSubscription"); From b643af9c03252a333d2a561c8bce03093b837c80 Mon Sep 17 00:00:00 2001 From: daraelmin Date: Sat, 1 May 2021 20:28:47 +0200 Subject: [PATCH 06/11] Remove unused code from reverted pr --- htdocs/adherents/admin/member.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/htdocs/adherents/admin/member.php b/htdocs/adherents/admin/member.php index 62291791fc5..d494b0ab438 100644 --- a/htdocs/adherents/admin/member.php +++ b/htdocs/adherents/admin/member.php @@ -9,8 +9,7 @@ * Copyright (C) 2012 J. Fernando Lagrange * Copyright (C) 2015 Jean-François Ferry * Copyright (C) 2020-2021 Frédéric France - * Copyright (C) 2021 Waël Almoman - * + * * 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 * the Free Software Foundation; either version 3 of the License, or @@ -34,7 +33,6 @@ require '../../main.inc.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.'/adherents/class/adherent_type.class.php'; // Load translation files required by the page $langs->loadLangs(array("admin", "members")); From 832ceb2be376fd7da9ce06624c122d6119e28278 Mon Sep 17 00:00:00 2001 From: stickler-ci Date: Sat, 1 May 2021 18:36:59 +0000 Subject: [PATCH 07/11] Fixing style errors. --- htdocs/adherents/admin/member.php | 2 +- htdocs/adherents/class/adherent_type.class.php | 5 +++-- htdocs/adherents/type.php | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/htdocs/adherents/admin/member.php b/htdocs/adherents/admin/member.php index d494b0ab438..32476f137a8 100644 --- a/htdocs/adherents/admin/member.php +++ b/htdocs/adherents/admin/member.php @@ -9,7 +9,7 @@ * Copyright (C) 2012 J. Fernando Lagrange * Copyright (C) 2015 Jean-François Ferry * Copyright (C) 2020-2021 Frédéric France - * + * * 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 * the Free Software Foundation; either version 3 of the License, or diff --git a/htdocs/adherents/class/adherent_type.class.php b/htdocs/adherents/class/adherent_type.class.php index 4924acf5ab6..505350a9c54 100644 --- a/htdocs/adherents/class/adherent_type.class.php +++ b/htdocs/adherents/class/adherent_type.class.php @@ -88,7 +88,7 @@ class AdherentType extends CommonObject * @var int Subsription required (0 or 1) */ public $subscription; - + /** * @var float amount for subscription if required */ @@ -548,7 +548,8 @@ class AdherentType extends CommonObject * @param int $status Filter on status of type * @return array List of types of members */ - public function amount_by_type($status = null) { + public function amount_by_type($status = null) + { global $conf, $langs; diff --git a/htdocs/adherents/type.php b/htdocs/adherents/type.php index 707dd7acb7c..05d50bed52d 100644 --- a/htdocs/adherents/type.php +++ b/htdocs/adherents/type.php @@ -795,7 +795,7 @@ if ($rowid > 0) { print ''.$langs->trans("SubscriptionRequired").''; print $form->selectyesno("subscription", $object->subscription, 1); print ''; - + print ''.$langs->trans("DefineAmountMemberType").''; print ''; print ''; From 28ba84770997466037b93b4b976484c6042bb96b Mon Sep 17 00:00:00 2001 From: daraelmin Date: Sat, 1 May 2021 20:43:58 +0200 Subject: [PATCH 08/11] camelCase format for method amountByType --- htdocs/adherents/class/adherent_type.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/adherents/class/adherent_type.class.php b/htdocs/adherents/class/adherent_type.class.php index 505350a9c54..9e15934cdb5 100644 --- a/htdocs/adherents/class/adherent_type.class.php +++ b/htdocs/adherents/class/adherent_type.class.php @@ -548,7 +548,7 @@ class AdherentType extends CommonObject * @param int $status Filter on status of type * @return array List of types of members */ - public function amount_by_type($status = null) + public function amountByType($status = null) { global $conf, $langs; From 0610ca89c1ff8e5abf15d7335d85be6972834217 Mon Sep 17 00:00:00 2001 From: daraelmin Date: Sat, 1 May 2021 20:45:57 +0200 Subject: [PATCH 09/11] camelCase for amountByType --- htdocs/public/payment/newpayment.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/public/payment/newpayment.php b/htdocs/public/payment/newpayment.php index 10c929b78e2..7007455791a 100644 --- a/htdocs/public/payment/newpayment.php +++ b/htdocs/public/payment/newpayment.php @@ -1448,7 +1448,7 @@ if ($source == 'member' || $source == 'membersubscription') { require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent_type.class.php'; $adht = new AdherentType($db); // Amount by member type - $amountbytype = $adht->amount_by_type(1); + $amountbytype = $adht->amountByType(1); // Set the member type $member->typeid = (int) (GETPOSTISSET("typeid") ? GETPOST("typeid", 'int') : $member->typeid); // If we change the type of membership, we set also label of new type From 1d05ce4a152a9cccb35b331a92399086af4e33ea Mon Sep 17 00:00:00 2001 From: daraelmin Date: Sat, 1 May 2021 21:40:43 +0200 Subject: [PATCH 10/11] Update comment --- htdocs/adherents/class/adherent_type.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/adherents/class/adherent_type.class.php b/htdocs/adherents/class/adherent_type.class.php index 9e15934cdb5..2ffc1e2c9fd 100644 --- a/htdocs/adherents/class/adherent_type.class.php +++ b/htdocs/adherents/class/adherent_type.class.php @@ -90,7 +90,7 @@ class AdherentType extends CommonObject public $subscription; /** - * @var float amount for subscription if required + * @var float amount for subscription */ public $amount; From f25997b292b09f81285a273235f50bd1f7900be7 Mon Sep 17 00:00:00 2001 From: daraelmin Date: Sat, 1 May 2021 21:42:13 +0200 Subject: [PATCH 11/11] phpunit --- test/phpunit/AdherentTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/test/phpunit/AdherentTest.php b/test/phpunit/AdherentTest.php index d9ba2e267e9..63b55dd37aa 100644 --- a/test/phpunit/AdherentTest.php +++ b/test/phpunit/AdherentTest.php @@ -154,6 +154,7 @@ class AdherentTest extends PHPUnit\Framework\TestCase $localobject->statut=1; $localobject->label='Adherent type test'; $localobject->subscription=1; + $localobject->amount=0; $localobject->vote=1; $localobject->company='Old company label'; $result=$localobject->create($user);