From b1d906d6d386a3d310bae9da4b279b5fbb3db727 Mon Sep 17 00:00:00 2001 From: w3houde Date: Sat, 30 May 2026 21:53:26 +0700 Subject: [PATCH] Fix #37904 Honour subscription end-of-period setting in mass action (#38515) The "Create subscription" mass action on the members list called Adherent::subscription() with no $datesubend argument, which makes the method fall back to "+1 year" regardless of the MEMBER_SUBSCRIPTION_SUGGEST_END_OF_MONTH or MEMBER_SUBSCRIPTION_SUGGEST_END_OF_YEAR global settings. The single subscription form, the API and the public payment return all pass the value computed from these constants and therefore worked as expected. Compute the same end date from the two constants before the loop and forward it as the ninth argument of the method call. Two other callers already pass a value here, so the method signature stays unchanged. Reported by @Basti-Fantasti. Signed-off-by: Dolicraft Co-authored-by: Dolicraft --- htdocs/adherents/list.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/htdocs/adherents/list.php b/htdocs/adherents/list.php index 5c18a3688d1..b672b27f6ee 100644 --- a/htdocs/adherents/list.php +++ b/htdocs/adherents/list.php @@ -363,11 +363,22 @@ if (empty($reshook)) { $nbcreated = 0; $now = dol_now(); $amount = price2num(GETPOST('amount', 'alpha')); + // Honour MEMBER_SUBSCRIPTION_SUGGEST_END_OF_MONTH and + // MEMBER_SUBSCRIPTION_SUGGEST_END_OF_YEAR the same way as the + // single subscription form (adherents/subscription.php), otherwise + // the mass action falls back to a one-year duration in + // Adherent::subscription() and ignores the global setting. + $datesubend = 0; + if (getDolGlobalInt('MEMBER_SUBSCRIPTION_SUGGEST_END_OF_MONTH')) { + $datesubend = dol_get_last_day((int) dol_print_date($now, "%Y"), (int) dol_print_date($now, "%m")); + } elseif (getDolGlobalInt('MEMBER_SUBSCRIPTION_SUGGEST_END_OF_YEAR')) { + $datesubend = dol_get_last_day((int) dol_print_date($now, "%Y")); + } $db->begin(); foreach ($toselect as $id) { $res = $tmpmember->fetch($id); if ($res > 0) { - $result = $tmpmember->subscription($now, $amount); + $result = $tmpmember->subscription($now, $amount, 0, '', '', '', '', '', $datesubend); if ($result < 0) { $error++; } else {