From 4fc415a287f014306e5a0bfef217ae9f463fa5fb Mon Sep 17 00:00:00 2001 From: daraelmin Date: Tue, 7 Nov 2023 18:05:36 +0100 Subject: [PATCH] New option to define the start period of a first subscription (#26484) * New option to define the start period of a first subscription add default date of starting (year, month or subscription payment) add delay for subscription period * Update member.php * Fix period for statistique if delay is set --- htdocs/adherents/admin/member.php | 23 ++++++++++++++++++++++- htdocs/adherents/stats/index.php | 5 ++++- htdocs/adherents/subscription.php | 17 +++++++++++------ htdocs/langs/en_US/members.lang | 2 ++ htdocs/langs/fr_FR/members.lang | 2 ++ htdocs/public/payment/paymentok.php | 12 ++++++++++-- 6 files changed, 51 insertions(+), 10 deletions(-) diff --git a/htdocs/adherents/admin/member.php b/htdocs/adherents/admin/member.php index 3f402440c9a..2993006bd91 100644 --- a/htdocs/adherents/admin/member.php +++ b/htdocs/adherents/admin/member.php @@ -9,6 +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) 2023 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 @@ -103,13 +104,15 @@ if ($action == 'set_default') { } } elseif ($action == 'updatemainoptions') { $db->begin(); - $res1 = $res2 = $res3 = $res4 = $res5 = $res6 = $res7 = 0; + $res1 = $res2 = $res3 = $res4 = $res5 = $res6 = $res7 = $res8 = $res9 = 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); $res3 = dolibarr_set_const($db, 'ADHERENT_CREATE_EXTERNAL_USER_LOGIN', GETPOST('ADHERENT_CREATE_EXTERNAL_USER_LOGIN', '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_PUBLIC_ENABLED', GETPOST('MEMBER_PUBLIC_ENABLED', 'alpha'), 'chaine', 0, '', $conf->entity); + $res8 = dolibarr_set_const($db, 'MEMBER_SUBSCRIPTION_START_FIRST_DAY_OF', GETPOST('MEMBER_SUBSCRIPTION_START_FIRST_DAY_OF', 'alpha'), 'chaine', 0, '', $conf->entity); + $res9 = dolibarr_set_const($db, 'MEMBER_SUBSCRIPTION_START_AFTER', GETPOST('MEMBER_SUBSCRIPTION_START_AFTER', 'alpha'), 'chaine', 0, '', $conf->entity); // Use vat for invoice creation if (isModEnabled('facture')) { $res4 = dolibarr_set_const($db, 'ADHERENT_VAT_FOR_SUBSCRIPTIONS', GETPOST('ADHERENT_VAT_FOR_SUBSCRIPTIONS', 'alpha'), 'chaine', 0, '', $conf->entity); @@ -335,6 +338,24 @@ print ''.$langs->trans("Description").''; print ''.$langs->trans("Value").''; print "\n"; +// Start date of new membership +$startpoint[0] = $langs->trans("SubscriptionPayment"); +$startpoint["m"] = $langs->trans("Month"); +$startpoint["Y"] = $langs->trans("Year"); +print ''; +print $langs->trans("MemberSubscriptionStartFirstDayOf"); +print ''; +$startfirstdayof = !getDolGlobalString('MEMBER_SUBSCRIPTION_START_FIRST_DAY_OF') ? 0 : getDolGlobalString('MEMBER_SUBSCRIPTION_START_FIRST_DAY_OF'); +print $form->selectarray("MEMBER_SUBSCRIPTION_START_FIRST_DAY_OF", $startpoint, $startfirstdayof, 0); +print "\n"; + +// Delay to start the new membership ([+/-][0-99][Y/m/d], for instance, with "+4m", the subscription will start in 4 month.) +print ''; +print $langs->trans("MemberSubscriptionStartAfter"); +print ''; +print ''; +print "\n"; + // Mail required for members print ''.$langs->trans("AdherentMailRequired").''; print $form->selectyesno('ADHERENT_MAIL_REQUIRED', (getDolGlobalString('ADHERENT_MAIL_REQUIRED') ? $conf->global->ADHERENT_MAIL_REQUIRED : 0), 1); diff --git a/htdocs/adherents/stats/index.php b/htdocs/adherents/stats/index.php index 2a0993efeb9..d835d1d8eba 100644 --- a/htdocs/adherents/stats/index.php +++ b/htdocs/adherents/stats/index.php @@ -48,8 +48,11 @@ if ($user->socid > 0) { $result = restrictedArea($user, 'adherent', '', '', 'cotisation'); $year = dol_print_date(dol_now('gmt'), "%Y", 'gmt'); -$startyear = $year - (!getDolGlobalString('MAIN_STATS_GRAPHS_SHOW_N_YEARS') ? 2 : max(1, min(10, $conf->global->MAIN_STATS_GRAPHS_SHOW_N_YEARS))); +$startyear = $year - (!getDolGlobalInt('MAIN_STATS_GRAPHS_SHOW_N_YEARS') ? 2 : max(1, min(10, getDolGlobalInt('MAIN_STATS_GRAPHS_SHOW_N_YEARS')))); $endyear = $year; +if (!empty(getDolGlobalString('MEMBER_SUBSCRIPTION_START_AFTER')) ) { + $endyear = dol_print_date(dol_time_plus_duree(dol_now('gmt'), (int) substr(getDolGlobalString('MEMBER_SUBSCRIPTION_START_AFTER'), 0, -1), substr(getDolGlobalString('MEMBER_SUBSCRIPTION_START_AFTER'), -1)), "%Y", 'gmt'); +} // Load translation files required by the page $langs->loadLangs(array("companies", "members")); diff --git a/htdocs/adherents/subscription.php b/htdocs/adherents/subscription.php index b3e2770ecc5..1a679c87830 100644 --- a/htdocs/adherents/subscription.php +++ b/htdocs/adherents/subscription.php @@ -6,6 +6,7 @@ * Copyright (C) 2015-2016 Alexandre Spangaro * Copyright (C) 2018-2023 Frédéric France * Copyright (C) 2019 Thibault FOUCART + * Copyright (C) 2023 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 @@ -53,7 +54,7 @@ $typeid = GETPOST('typeid', 'int'); $cancel = GETPOST('cancel'); // Load variable for pagination -$limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit; +$limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit; $sortfield = GETPOST('sortfield', 'aZ09comma'); $sortorder = GETPOST('sortorder', 'aZ09comma'); $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int'); @@ -960,8 +961,6 @@ if (($action == 'addsubscription' || $action == 'create_thirdparty') && $user->h print ''."\n"; print ''; - $now = dol_now(); - // Date payment if (GETPOST('paymentyear') && GETPOST('paymentmonth') && GETPOST('paymentday')) { $paymentdate = dol_mktime(0, 0, 0, GETPOST('paymentmonth'), GETPOST('paymentday'), GETPOST('paymentyear')); @@ -977,10 +976,16 @@ if (($action == 'addsubscription' || $action == 'create_thirdparty') && $user->h } if (!$datefrom) { $datefrom = $object->datevalid; - if ($object->datefin > 0 && dol_time_plus_duree($object->datefin, $defaultdelay, $defaultdelayunit) > dol_now()) { + if (!empty(getDolGlobalString('MEMBER_SUBSCRIPTION_START_AFTER')) ) { + $datefrom = dol_time_plus_duree($now, (int) substr(getDolGlobalString('MEMBER_SUBSCRIPTION_START_AFTER'), 0, -1), substr(getDolGlobalString('MEMBER_SUBSCRIPTION_START_AFTER'), -1)); + } elseif ($object->datefin > 0 && dol_time_plus_duree($object->datefin, $defaultdelay, $defaultdelayunit) > $now) { $datefrom = dol_time_plus_duree($object->datefin, 1, 'd'); - } else { - $datefrom = dol_get_first_day($currentyear); + } + + if (getDolGlobalString('MEMBER_SUBSCRIPTION_START_FIRST_DAY_OF') === "m") { + $datefrom = dol_get_first_day(dol_print_date($datefrom, "%Y"), dol_print_date($datefrom, "%m")); + } elseif (getDolGlobalString('MEMBER_SUBSCRIPTION_START_FIRST_DAY_OF') === "Y") { + $datefrom = dol_get_first_day(dol_print_date($datefrom, "%Y")); } } print $form->selectDate($datefrom, '', '', '', '', "subscription", 1, 1); diff --git a/htdocs/langs/en_US/members.lang b/htdocs/langs/en_US/members.lang index 277081d7ef3..3829a265546 100644 --- a/htdocs/langs/en_US/members.lang +++ b/htdocs/langs/en_US/members.lang @@ -241,3 +241,5 @@ MemberFirstname=Member firstname MemberLastname=Member lastname MemberCodeDesc=Member Code, unique for all members NoRecordedMembers=No recorded members +MemberSubscriptionStartFirstDayOf=The start date of a membership corresponds to the first day of a +MemberSubscriptionStartAfter=Minimum period before the entry into force of the start date of a subscription except renewals (example +3m = +3 months, -5d = -3 days, +1Y = +1 year) (example: +3m = +3 months, -5d = -3 days, +1Y = +1 year) \ No newline at end of file diff --git a/htdocs/langs/fr_FR/members.lang b/htdocs/langs/fr_FR/members.lang index cb6f3168277..905e2efe8f6 100644 --- a/htdocs/langs/fr_FR/members.lang +++ b/htdocs/langs/fr_FR/members.lang @@ -241,3 +241,5 @@ MemberFirstname=Prénom du membre MemberLastname=Nom de famille du membre MemberCodeDesc=Code membre, unique pour tous les membres NoRecordedMembers=Aucun membre enregistré +MemberSubscriptionStartFirstDayOf=La date de début d'une adhésion correspond au premier jour d'un(e) +MemberSubscriptionStartAfter=Délai minimum avant l'entrée en vigueur de la date de début d'une souscription hors renouvellement (exemple +3m = +3 mois, -5d = -3 jours, +1Y = +1 année) \ No newline at end of file diff --git a/htdocs/public/payment/paymentok.php b/htdocs/public/payment/paymentok.php index 6135c1e6801..57f00ea09f1 100644 --- a/htdocs/public/payment/paymentok.php +++ b/htdocs/public/payment/paymentok.php @@ -2,7 +2,7 @@ /* Copyright (C) 2001-2002 Rodolphe Quiedeville * Copyright (C) 2006-2013 Laurent Destailleur * Copyright (C) 2012 Regis Houssin - * Copyright (C) 2021 Waël Almoman + * Copyright (C) 2021-2023 Waël Almoman * Copyright (C) 2021 Maxime Demarest * Copyright (C) 2021 Dorian Vabre * @@ -522,9 +522,17 @@ if ($ispaymentok) { } // Subscription informations - $datesubscription = $object->datevalid; + $datesubscription = $object->datevalid; // By default, the subscription start date is the payment date if ($object->datefin > 0) { $datesubscription = dol_time_plus_duree($object->datefin, 1, 'd'); + } elseif (getDolGlobalString('MEMBER_SUBSCRIPTION_START_AFTER')) { + $datesubscription = dol_time_plus_duree($now, (int) substr(getDolGlobalString('MEMBER_SUBSCRIPTION_START_AFTER'), 0, -1), substr(getDolGlobalString('MEMBER_SUBSCRIPTION_START_AFTER'), -1)); + } + + if (getDolGlobalString('MEMBER_SUBSCRIPTION_START_FIRST_DAY_OF') === "m") { + $datesubscription = dol_get_first_day(dol_print_date($datesubscription, "%Y"), dol_print_date($datesubscription, "%m")); + } elseif (getDolGlobalString('MEMBER_SUBSCRIPTION_START_FIRST_DAY_OF') === "Y") { + $datesubscription = dol_get_first_day(dol_print_date($datesubscription, "%Y")); } $datesubend = null;