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 <contact@dolicraft.com>
Co-authored-by: Dolicraft <contact@dolicraft.com>
This commit is contained in:
w3houde 2026-05-30 21:53:26 +07:00 committed by GitHub
parent 6871e041a6
commit b1d906d6d3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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 {