From deb9176e21148060829e4ebb7042c978b155b973 Mon Sep 17 00:00:00 2001 From: Hystepik Date: Mon, 29 Jan 2024 15:33:37 +0100 Subject: [PATCH] Close #27777 : new massaction subscription creation --- htdocs/adherents/list.php | 40 +++++++++++++++++++++++++++++++++ htdocs/langs/en_US/members.lang | 7 +++++- 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/htdocs/adherents/list.php b/htdocs/adherents/list.php index 2114f6107c026..93e8a0dfc9520 100644 --- a/htdocs/adherents/list.php +++ b/htdocs/adherents/list.php @@ -335,6 +335,40 @@ } } + // Create external user + if ($action == 'createsubscription' && $confirm == "yes" && $user->hasRight('adherent', 'creer')) { + $tmpmember = new Adherent($db); + $adht = new AdherentType($db); + $error = 0; + $nbcreated = 0; + $db->begin(); + + foreach ($toselect as $id) { + $now = dol_now(); + $tmpmember->fetch($id); + $res = $adht->fetch($tmpmember->typeid); + if ($res > 0) { + $amount = $adht->amount; + $result = $tmpmember->subscription($now, $amount); + if ($result < 0) { + $error++; + } else { + $nbcreated++; + } + } else { + $error++; + } + } + + if (!$error) { + setEventMessages($langs->trans("XSubsriptionCreated", $nbcreated), null, 'mesgs'); + $db->commit(); + } else { + setEventMessages($langs->trans("XSubsriptionError", $error), null, 'mesgs'); + $db->rollback(); + } + } + // Mass actions $objectclass = 'Adherent'; $objectlabel = 'Members'; @@ -706,6 +740,9 @@ if ($user->hasRight('adherent', 'creer') && $user->hasRight('user', 'user', 'creer')) { $arrayofmassactions['createexternaluser'] = img_picto('', 'user', 'class="pictofixedwidth"').$langs->trans("CreateExternalUser"); } +if ($user->hasRight('adherent', 'creer')) { + $arrayofmassactions['createsubscription'] = $langs->trans("CreateSubscription"); +} if (GETPOST('nomassaction', 'int') || in_array($massaction, array('presend', 'predelete', 'preaffecttag'))) { $arrayofmassactions = array(); } @@ -740,6 +777,9 @@ $modelmail = "member"; $objecttmp = new Adherent($db); $trackid = 'mem'.$object->id; +if ($massaction == 'createsubscription') { + print $form->formconfirm($_SERVER["PHP_SELF"], $langs->trans("ConfirmMassSubsriptionCreation"), $langs->trans("ConfirmMassSubsriptionCreationQuestion", count($toselect)), "createsubscription", $formquestion, '', 0, 200, 500, 1); +} include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php'; if ($search_all) { diff --git a/htdocs/langs/en_US/members.lang b/htdocs/langs/en_US/members.lang index 34148bf11e281..a944cd124e0d6 100644 --- a/htdocs/langs/en_US/members.lang +++ b/htdocs/langs/en_US/members.lang @@ -243,4 +243,9 @@ MemberLastname=Member lastname MemberCodeDesc=Member Code, unique for all 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 = -5 days, +1Y = +1 year) -SubscriptionLinkedToConciliatedTransaction=Membership is linked to a conciliated transaction so this modification is not allowed. \ No newline at end of file +SubscriptionLinkedToConciliatedTransaction=Membership is linked to a conciliated transaction so this modification is not allowed. +ConfirmMassSubsriptionCreation=Confirm subscription creation +ConfirmMassSubsriptionCreationQuestion=Are you sure you want to create the %s selected subscription(s)? +XSubsriptionCreated=%s subscription(s) created +XSubsriptionErrors=%s subscription(s) where in error +CreateSubscription=Create subscription \ No newline at end of file