New option amount by member type

This commit is contained in:
daraelmin 2021-04-09 02:23:22 +02:00
parent 2d771704d0
commit f2a49ef72f
7 changed files with 60 additions and 6 deletions

View File

@ -33,6 +33,7 @@
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"));
@ -101,11 +102,12 @@ if ($action == 'set_default') {
}
} elseif ($action == 'updateall') {
$db->begin();
$res1 = $res2 = $res3 = $res4 = $res5 = $res6 = 0;
$res1 = $res2 = $res3 = $res4 = $res5 = $res6 = $res7 = 0;
$res1 = dolibarr_set_const($db, 'ADHERENT_LOGIN_NOT_REQUIRED', GETPOST('ADHERENT_LOGIN_NOT_REQUIRED', 'alpha') ? 0 : 1, 'chaine', 0, '', $conf->entity);
$res2 = dolibarr_set_const($db, 'ADHERENT_MAIL_REQUIRED', GETPOST('ADHERENT_MAIL_REQUIRED', 'alpha'), 'chaine', 0, '', $conf->entity);
$res3 = dolibarr_set_const($db, 'ADHERENT_DEFAULT_SENDINFOBYMAIL', GETPOST('ADHERENT_DEFAULT_SENDINFOBYMAIL', 'alpha'), 'chaine', 0, '', $conf->entity);
$res4 = dolibarr_set_const($db, 'ADHERENT_BANK_USE', GETPOST('ADHERENT_BANK_USE', 'alpha'), 'chaine', 0, '', $conf->entity);
$res7 = dolibarr_set_const($db, "MEMBER_SUBSCRIPTION_AMOUNT_BY_TYPE", json_encode(GETPOST('MEMBER_SUBSCRIPTION_AMOUNT_BY_TYPE')), 'array', 0, '', $conf->entity);
// Use vat for invoice creation
if ($conf->facture->enabled) {
$res4 = dolibarr_set_const($db, 'ADHERENT_VAT_FOR_SUBSCRIPTIONS', GETPOST('ADHERENT_VAT_FOR_SUBSCRIPTIONS', 'alpha'), 'chaine', 0, '', $conf->entity);
@ -217,6 +219,18 @@ print '<tr class="oddeven"><td>'.$langs->trans("MemberSendInformationByMailByDef
print $form->selectyesno('ADHERENT_DEFAULT_SENDINFOBYMAIL', (!empty($conf->global->ADHERENT_DEFAULT_SENDINFOBYMAIL) ? $conf->global->ADHERENT_DEFAULT_SENDINFOBYMAIL : 0), 1);
print "</td></tr>\n";
// Amount by member type
$adht = new AdherentType($db);
$amountbytype = empty($conf->global->MEMBER_SUBSCRIPTION_AMOUNT_BY_TYPE) ? -1 : json_decode($conf->global->MEMBER_SUBSCRIPTION_AMOUNT_BY_TYPE, true);
print '<tr class="oddeven"><td>'.$langs->trans("DefineAmountMemberType").'</td><td>';
foreach ($adht->liste_array(1) as $typeid => $type){
print $type .' : ';
print '<input type="text" id="MEMBER_SUBSCRIPTION_AMOUNT_BY_TYPE['.$typeid.']" name="MEMBER_SUBSCRIPTION_AMOUNT_BY_TYPE['.$typeid.']" " size="5" value="'.(!empty($amountbytype[$typeid]) ? $amountbytype[$typeid] : '').'">';
print '<br />';
}
print "</td></tr>\n";
// Insert subscription into bank account
print '<tr class="oddeven"><td>'.$langs->trans("MoreActionsOnSubscription").'</td>';
$arraychoices = array('0'=>$langs->trans("None"));

View File

@ -177,7 +177,7 @@ if (!empty($conf->global->MEMBER_ENABLE_PUBLIC)) {
print $langs->trans("ForceMemberType");
print '</td><td class="right">';
$listofval = array();
$listofval += $adht->liste_array();
$listofval += $adht->liste_array(1);
$forcetype = empty($conf->global->MEMBER_NEWFORM_FORCETYPE) ? -1 : $conf->global->MEMBER_NEWFORM_FORCETYPE;
print $form->selectarray("MEMBER_NEWFORM_FORCETYPE", $listofval, $forcetype, count($listofval) > 1 ? 1 : 0);
print "</td></tr>\n";

View File

@ -1490,9 +1490,11 @@ class Adherent extends CommonObject
* @param string $emetteur_nom Name of cheque writer
* @param string $emetteur_banque Name of bank of cheque
* @param int $datesubend Date end subscription
* @param int fk_type Member type id
*
* @return int rowid of record added, <0 if KO
*/
public function subscription($date, $amount, $accountid = 0, $operation = '', $label = '', $num_chq = '', $emetteur_nom = '', $emetteur_banque = '', $datesubend = 0)
public function subscription($date, $amount, $accountid = 0, $operation = '', $label = '', $num_chq = '', $emetteur_nom = '', $emetteur_banque = '', $datesubend = 0, $fk_type = NULL)
{
global $conf, $langs, $user;
@ -1523,6 +1525,7 @@ class Adherent extends CommonObject
$subscription->amount = $amount;
$subscription->note = $label; // deprecated
$subscription->note_public = $label;
$subscription->fk_type = $fk_type;
$rowid = $subscription->create($user);
if ($rowid > 0) {

View File

@ -169,6 +169,7 @@ DocForLabels=Generate address sheets
SubscriptionPayment=Subscription payment
LastSubscriptionDate=Date of latest subscription payment
LastSubscriptionAmount=Amount of latest subscription
LastMemberType=Last Member type
MembersStatisticsByCountries=Members statistics by country
MembersStatisticsByState=Members statistics by state/province
MembersStatisticsByTown=Members statistics by town

View File

@ -162,6 +162,7 @@ DocForLabels=Génération d'étiquettes d'adresses
SubscriptionPayment=Paiement cotisation
LastSubscriptionDate=Date de dernière adhésion
LastSubscriptionAmount=Montant dernière adhésion
LastMemberType=Ancien type de membre
MembersStatisticsByCountries=Statistiques des membres par pays
MembersStatisticsByState=Statistiques des membres par département/province/canton
MembersStatisticsByTown=Statistiques des membres par ville

View File

@ -1437,6 +1437,39 @@ if ($source == 'membersubscription') {
$_GET['newamount'] = $member->last_subscription_amount;
}
}
if ($member->type) {
// Last member type
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></tr>"."\n";
}
if (!empty($conf->global->MEMBER_SUBSCRIPTION_AMOUNT_BY_TYPE)) {
// Amount by member type
$amountbytype = json_decode($conf->global->MEMBER_SUBSCRIPTION_AMOUNT_BY_TYPE, true);
// 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 = $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 wecan call method selectarray
print '<tr class="CTableRow'.($var ? '1' : '2').'"><td class="CTableRow'.($var ? '1' : '2').'">'.$langs->trans("NewSubscription");
print '</td><td class="CTableRow'.($var ? '1' : '2').'">';
print $form->selectarray("typeid", $adht->liste_array(1) , $member->typeid, 0, 0, 0, 'onchange="window.location.replace(\''.$urlwithroot.'/public/payment/newpayment.php?source='.$source.'&ref='.$ref.'&amount='.$amount.'&typeid=\' + this.value + \'&securekey='.$SECUREKEY.'\');"', 0, 0, 0, '', '', 1);
print "</td></tr>"."\n";
} elseif ($action == dopayment) {
print '<tr class="CTableRow'.($var ? '1' : '2').'"><td class="CTableRow'.($var ? '1' : '2').'">'.$langs->trans("NewMemberType");
print '</td><td class="CTableRow'.($var ? '1' : '2').'">'.dol_escape_htmltag($member->type);
print '<input type="hidden" name="membertypeid" value="'.$member->typeid.'">';
print "</td></tr>"."\n";
}
}
// Amount
print '<tr class="CTableRow'.($var ? '1' : '2').'"><td class="CTableRow'.($var ? '1' : '2').'">'.$langs->trans("Amount");

View File

@ -98,10 +98,11 @@ $FULLTAG = GETPOST('FULLTAG');
if (empty($FULLTAG)) {
$FULLTAG = GETPOST('fulltag');
}
$source = GETPOST('s', 'alpha') ?GETPOST('s', 'alpha') : GETPOST('source', 'alpha');
$source = GETPOST('s', 'alpha') ? GETPOST('s', 'alpha') : GETPOST('source', 'alpha');
$ref = GETPOST('ref');
$suffix = GETPOST("suffix", 'aZ09');
$membertypeid = GETPOST("membertypeid", 'int');
// Detect $paymentmethod
@ -339,7 +340,8 @@ if ($ispaymentok) {
$user->rights->facture = new stdClass();
}
if (empty($user->rights->adherent)) {
$user->rights->adherent = new stdClass(); $user->rights->adherent->cotisation = new stdClass();
$user->rights->adherent = new stdClass();
$user->rights->adherent->cotisation = new stdClass();
}
$user->rights->societe->creer = 1;
$user->rights->facture->creer = 1;
@ -460,7 +462,7 @@ if ($ispaymentok) {
if (!$error) {
dol_syslog("Call ->subscription to create subscription", LOG_DEBUG, 0, '_payment');
$crowid = $object->subscription($datesubscription, $amount, $accountid, $operation, $label, $num_chq, $emetteur_nom, $emetteur_banque, $datesubend);
$crowid = $object->subscription($datesubscription, $amount, $accountid, $operation, $label, $num_chq, $emetteur_nom, $emetteur_banque, $datesubend, $membertypeid);
if ($crowid <= 0) {
$error++;
$errmsg = $object->error;