* Copyright (C) 2002-2003 Jean-Louis Bergamo * Copyright (C) 2004-2018 Laurent Destailleur * Copyright (C) 2012-2017 Regis Houssin * Copyright (C) 2015-2024 Alexandre Spangaro * Copyright (C) 2018-2024 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 * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ /** * \file htdocs/adherents/subscription.php * \ingroup member * \brief tab for Adding, editing, deleting a member's memberships */ // Load Dolibarr environment require '../main.inc.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/member.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php'; require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php'; require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent_type.class.php'; require_once DOL_DOCUMENT_ROOT.'/adherents/class/subscription.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php'; require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingjournal.class.php'; $langs->loadLangs(array("companies", "bills", "members", "users", "mails", 'other')); $action = GETPOST('action', 'aZ09'); $confirm = GETPOST('confirm', 'alpha'); $contextpage = GETPOST('contextpage', 'aZ09'); $optioncss = GETPOST('optioncss', 'aZ'); // Option for the css output (always '' except when 'print') $id = GETPOSTINT('rowid') ? GETPOSTINT('rowid') : GETPOSTINT('id'); $rowid = $id; $ref = GETPOST('ref', 'alphanohtml'); $typeid = GETPOSTINT('typeid'); $cancel = GETPOST('cancel'); // Load variable for pagination $limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit; $sortfield = GETPOST('sortfield', 'aZ09comma'); $sortorder = GETPOST('sortorder', 'aZ09comma'); $page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT("page"); if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1 $offset = $limit * $page; $pageprev = $page - 1; $pagenext = $page + 1; // Default sort order (if not yet defined by previous GETPOST) if (!$sortfield) { $sortfield = "c.rowid"; } if (!$sortorder) { $sortorder = "DESC"; } $object = new Adherent($db); $extrafields = new ExtraFields($db); $adht = new AdherentType($db); // fetch optionals attributes and labels $extrafields->fetch_name_optionals_label($object->table_element); $errmsg = ''; // Initialize a technical object to manage hooks of page. Note that conf->hooks_modules contains an array of hook context $hookmanager->initHooks(array('subscription')); // PDF $hidedetails = (GETPOSTINT('hidedetails') ? GETPOSTINT('hidedetails') : (getDolGlobalString('MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS') ? 1 : 0)); $hidedesc = (GETPOSTINT('hidedesc') ? GETPOSTINT('hidedesc') : (getDolGlobalString('MAIN_GENERATE_DOCUMENTS_HIDE_DESC') ? 1 : 0)); $hideref = (GETPOSTINT('hideref') ? GETPOSTINT('hideref') : (getDolGlobalString('MAIN_GENERATE_DOCUMENTS_HIDE_REF') ? 1 : 0)); $datefrom = 0; $dateto = 0; $paymentdate = -1; // Fetch object if ($id > 0 || !empty($ref)) { // Load member $result = $object->fetch($id, $ref); // Define variables to know what current user can do on users $canadduser = ($user->admin || $user->hasRight("user", "user", "creer")); // Define variables to know what current user can do on properties of user linked to edited member if ($object->user_id) { // $User is the user who edits, $object->user_id is the id of the related user in the edited member $caneditfielduser = ((($user->id == $object->user_id) && $user->hasRight("user", "self", "creer")) || (($user->id != $object->user_id) && $user->hasRight("user", "user", "creer"))); $caneditpassworduser = ((($user->id == $object->user_id) && $user->hasRight("user", "self", "password")) || (($user->id != $object->user_id) && $user->hasRight("user", "user", "password"))); } } // Define variables to determine what the current user can do on the members $canaddmember = $user->hasRight('adherent', 'creer'); // Define variables to determine what the current user can do on the properties of a member if ($id) { $caneditfieldmember = $user->hasRight('adherent', 'creer'); } // Security check $result = restrictedArea($user, 'adherent', $object->id, '', '', 'socid', 'rowid', 0); /* * Actions */ $parameters = array(); $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); if ($reshook < 0) { setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); } // Create third party from a member if (empty($reshook) && $action == 'confirm_create_thirdparty' && $confirm == 'yes' && $user->hasRight('societe', 'creer')) { if ($result > 0) { // Creation of thirdparty $company = new Societe($db); $result = $company->create_from_member($object, GETPOST('companyname', 'alpha'), GETPOST('companyalias', 'alpha'), GETPOST('customercode', 'alpha')); if ($result < 0) { $langs->load("errors"); setEventMessages($company->error, $company->errors, 'errors'); } else { $action = 'addsubscription'; } } else { setEventMessages($object->error, $object->errors, 'errors'); } } if (empty($reshook) && $action == 'setuserid' && ($user->hasRight('user', 'self', 'creer') || $user->hasRight('user', 'user', 'creer'))) { $error = 0; if (!$user->hasRight('user', 'user', 'creer')) { // If can edit only itself user, we can link to itself only if (GETPOSTINT("userid") != $user->id && GETPOSTINT("userid") != $object->user_id) { $error++; setEventMessages($langs->trans("ErrorUserPermissionAllowsToLinksToItselfOnly"), null, 'errors'); } } if (!$error) { if (GETPOSTINT("userid") != $object->user_id) { // If link differs from currently in database $result = $object->setUserId(GETPOSTINT("userid")); if ($result < 0) { dol_print_error(null, $object->error); } $action = ''; } } } if (empty($reshook) && $action == 'setsocid') { $error = 0; if (!$error) { if (GETPOSTINT('socid') != $object->fk_soc) { // If link differs from currently in database $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."adherent"; $sql .= " WHERE fk_soc = '".GETPOSTINT('socid')."'"; $resql = $db->query($sql); if ($resql) { $obj = $db->fetch_object($resql); if ($obj && $obj->rowid > 0) { $othermember = new Adherent($db); $othermember->fetch($obj->rowid); $thirdparty = new Societe($db); $thirdparty->fetch(GETPOSTINT('socid')); $error++; setEventMessages($langs->trans("ErrorMemberIsAlreadyLinkedToThisThirdParty", $othermember->getFullName($langs), $othermember->login, $thirdparty->name), null, 'errors'); } } if (!$error) { $result = $object->setThirdPartyId(GETPOSTINT('socid')); if ($result < 0) { dol_print_error(null, $object->error); } $action = ''; } } } } if ($user->hasRight('adherent', 'cotisation', 'creer') && $action == 'subscription' && !$cancel) { $error = 0; $langs->load("banks"); $result = $object->fetch($rowid); $result = $adht->fetch($object->typeid); // Subscription information $datesubscription = 0; $datesubend = 0; $defaultdelay = !empty($adht->duration_value) ? $adht->duration_value : 1; $defaultdelayunit = !empty($adht->duration_unit) ? $adht->duration_unit : 'y'; $paymentdate = ''; // Do not use 0 here, default value is '' that means not filled where 0 means 1970-01-01 if (GETPOSTINT("reyear") && GETPOSTINT("remonth") && GETPOSTINT("reday")) { $datesubscription = dol_mktime(0, 0, 0, GETPOSTINT("remonth"), GETPOSTINT("reday"), GETPOSTINT("reyear")); } if (GETPOSTINT("endyear") && GETPOSTINT("endmonth") && GETPOSTINT("endday")) { $datesubend = dol_mktime(0, 0, 0, GETPOSTINT("endmonth"), GETPOSTINT("endday"), GETPOSTINT("endyear")); } if (GETPOSTINT("paymentyear") && GETPOSTINT("paymentmonth") && GETPOSTINT("paymentday")) { $paymentdate = dol_mktime(0, 0, 0, GETPOSTINT("paymentmonth"), GETPOSTINT("paymentday"), GETPOSTINT("paymentyear")); } $amount = price2num(GETPOST("subscription", 'alpha')); // Amount of subscription $label = GETPOST("label"); // Payment information $accountid = GETPOSTINT("accountid"); $operation = GETPOST("operation", "alphanohtml"); // Payment mode $num_chq = GETPOST("num_chq", "alphanohtml"); $emetteur_nom = GETPOST("chqemetteur"); $emetteur_banque = GETPOST("chqbank"); $option = GETPOST("paymentsave"); if (empty($option)) { $option = 'none'; } $sendalsoemail = GETPOST("sendmail", 'alpha'); // Check parameters if (!$datesubscription) { $error++; $langs->load("errors"); $errmsg = $langs->trans("ErrorBadDateFormat", $langs->transnoentitiesnoconv("DateSubscription")); setEventMessages($errmsg, null, 'errors'); $action = 'addsubscription'; } if (GETPOST('end') && !$datesubend) { $error++; $langs->load("errors"); $errmsg = $langs->trans("ErrorBadDateFormat", $langs->transnoentitiesnoconv("DateEndSubscription")); setEventMessages($errmsg, null, 'errors'); $action = 'addsubscription'; } if (!$datesubend) { $datesubend = dol_time_plus_duree(dol_time_plus_duree($datesubscription, $defaultdelay, $defaultdelayunit), -1, 'd'); } if (($option == 'bankviainvoice' || $option == 'bankdirect') && !$paymentdate) { $error++; $errmsg = $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("DatePayment")); setEventMessages($errmsg, null, 'errors'); $action = 'addsubscription'; } // Check if a payment is mandatory or not if ($adht->subscription) { // Member type need subscriptions if (!is_numeric($amount)) { // If field is '' or not a numeric value $errmsg = $langs->trans("ErrorFieldRequired", $langs->transnoentities("Amount")); setEventMessages($errmsg, null, 'errors'); $error++; $action = 'addsubscription'; } else { // If an amount has been provided, we check also fields that becomes mandatory when amount is not null. if (isModEnabled('bank') && GETPOST("paymentsave") != 'none') { if (GETPOST("subscription")) { if (!GETPOST("label")) { $errmsg = $langs->trans("ErrorFieldRequired", $langs->transnoentities("Label")); setEventMessages($errmsg, null, 'errors'); $error++; $action = 'addsubscription'; } if (GETPOST("paymentsave") != 'invoiceonly' && !GETPOST("operation")) { $errmsg = $langs->trans("ErrorFieldRequired", $langs->transnoentities("PaymentMode")); setEventMessages($errmsg, null, 'errors'); $error++; $action = 'addsubscription'; } if (GETPOST("paymentsave") != 'invoiceonly' && !(GETPOSTINT("accountid") > 0)) { $errmsg = $langs->trans("ErrorFieldRequired", $langs->transnoentities("FinancialAccount")); setEventMessages($errmsg, null, 'errors'); $error++; $action = 'addsubscription'; } } else { if (GETPOSTINT("accountid")) { $errmsg = $langs->trans("ErrorDoNotProvideAccountsIfNullAmount"); setEventMessages($errmsg, null, 'errors'); $error++; $action = 'addsubscription'; } } } } } // Record the subscription then complementary actions if (!$error && $action == 'subscription') { $db->begin(); // Create subscription $crowid = $object->subscription($datesubscription, $amount, $accountid, $operation, $label, $num_chq, $emetteur_nom, $emetteur_banque, $datesubend); if ($crowid <= 0) { $error++; $errmsg = $object->error; setEventMessages($object->error, $object->errors, 'errors'); } if (!$error) { $result = $object->subscriptionComplementaryActions($crowid, $option, $accountid, $datesubscription, $paymentdate, $operation, $label, $amount, $num_chq, $emetteur_nom, $emetteur_banque); if ($result < 0) { $error++; setEventMessages($object->error, $object->errors, 'errors'); } else { // If an invoice was created, it is into $object->invoice } } if (!$error) { $db->commit(); } else { $db->rollback(); $action = 'addsubscription'; } if (!$error) { setEventMessages("SubscriptionRecorded", null, 'mesgs'); } // Send email if (!$error) { // Send confirmation Email if ($object->email && $sendalsoemail) { // $object is 'Adherent' $parameters = array( 'datesubscription' => $datesubscription, 'amount' => $amount, 'ccountid' => $accountid, 'operation' => $operation, 'label' => $label, 'num_chq' => $num_chq, 'emetteur_nom' => $emetteur_nom, 'emetteur_banque' => $emetteur_banque, 'datesubend' => $datesubend ); $reshook = $hookmanager->executeHooks('sendMail', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks if ($reshook < 0) { setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); } if (empty($reshook)) { $subject = ''; $msg = ''; // Send subscription email include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php'; $formmail = new FormMail($db); // Set output language $outputlangs = new Translate('', $conf); $outputlangs->setDefaultLang(empty($object->thirdparty->default_lang) ? $mysoc->default_lang : $object->thirdparty->default_lang); // Load traductions files required by page $outputlangs->loadLangs(array("main", "members")); // Get email content from template $arraydefaultmessage = null; $labeltouse = getDolGlobalString('ADHERENT_EMAIL_TEMPLATE_SUBSCRIPTION'); if (!empty($labeltouse)) { $arraydefaultmessage = $formmail->getEMailTemplate($db, 'member', $user, $outputlangs, 0, 1, $labeltouse); } if (!empty($labeltouse) && is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0) { $subject = $arraydefaultmessage->topic; $msg = $arraydefaultmessage->content; } $substitutionarray = getCommonSubstitutionArray($outputlangs, 0, null, $object); complete_substitutions_array($substitutionarray, $outputlangs, $object); $subjecttosend = make_substitutions($subject, $substitutionarray, $outputlangs); $texttosend = make_substitutions(dol_concatdesc($msg, $adht->getMailOnSubscription()), $substitutionarray, $outputlangs); // Attach a file ? $file = ''; $listofpaths = array(); $listofnames = array(); $listofmimes = array(); if (is_object($object->invoice) && (!is_object($arraydefaultmessage) || intval($arraydefaultmessage->joinfiles))) { $invoicediroutput = $conf->facture->dir_output; $fileparams = dol_most_recent_file($invoicediroutput.'/'.$object->invoice->ref, preg_quote($object->invoice->ref, '/').'[^\-]+'); $file = $fileparams['fullname']; $listofpaths = array($file); $listofnames = array(basename($file)); $listofmimes = array(dol_mimetype($file)); } $moreinheader = 'X-Dolibarr-Info: send_an_email by adherents/subscription.php'."\r\n"; $result = $object->sendEmail($texttosend, $subjecttosend, $listofpaths, $listofmimes, $listofnames, "", "", 0, -1, '', $moreinheader); if ($result < 0) { $errmsg = $object->error; setEventMessages($object->error, $object->errors, 'errors'); } else { setEventMessages($langs->trans("EmailSentToMember", $object->email), null, 'mesgs'); } } } else { setEventMessages($langs->trans("NoEmailSentToMember"), null, 'mesgs'); } } // Clean some POST vars if (!$error) { $accountid = ''; $operation = ''; $label = ''; $num_chq = ''; $option = ''; } } } /* * View */ $form = new Form($db); $now = dol_now(); $title = $langs->trans("Member")." - ".$langs->trans("Subscriptions"); $help_url = "EN:Module_Foundations|FR:Module_Adhérents|ES:Módulo_Miembros|DE:Modul_Mitglieder"; llxHeader('', $title, $help_url, '', 0, 0, '', '', '', 'mod-member page-card_subscription'); $param = ''; if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) { $param .= '&contextpage='.urlencode($contextpage); } if ($limit > 0 && $limit != $conf->liste_limit) { $param .= '&limit='.((int) $limit); } $param .= '&id='.$rowid; if ($optioncss != '') { $param .= '&optioncss='.urlencode($optioncss); } // Add $param from extra fields //include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php'; if (! ($object->id > 0)) { $langs->load("errors"); print $langs->trans("ErrorRecordNotFound"); } /*$res = $object->fetch($rowid); if ($res < 0) { dol_print_error($db, $object->error); exit; } */ $adht->fetch($object->typeid); $defaultdelay = !empty($adht->duration_value) ? $adht->duration_value : 1; $defaultdelayunit = !empty($adht->duration_unit) ? $adht->duration_unit : 'y'; $head = member_prepare_head($object); $rowspan = 10; if (!getDolGlobalString('ADHERENT_LOGIN_NOT_REQUIRED')) { $rowspan++; } if (isModEnabled('societe')) { $rowspan++; } print '
'; print ''; print ''; print dol_get_fiche_head($head, 'subscription', $langs->trans("Member"), -1, 'user'); $linkback = ''.$langs->trans("BackToList").''; $morehtmlref = ''; $morehtmlref .= img_picto($langs->trans("Download").' '.$langs->trans("VCard"), 'vcard.png', 'class="valignmiddle marginleftonly paddingrightonly"'); $morehtmlref .= ''; dol_banner_tab($object, 'rowid', $linkback, 1, 'rowid', 'ref', $morehtmlref); print '
'; print '
'; print '
'; print ''; // Login if (!getDolGlobalString('ADHERENT_LOGIN_NOT_REQUIRED')) { print ''; } // Type print ''; print '\n"; // Morphy print ''; print ''; print ''; // Company print ''; // Civility print ''; print ''; // Password if (!getDolGlobalString('ADHERENT_LOGIN_NOT_REQUIRED')) { print ''; } // Date end subscription print ''; print '
'.$langs->trans("Login").' / '.$langs->trans("Id").''.dol_escape_htmltag($object->login).'
'.$langs->trans("Type").''.$adht->getNomUrl(1)."
'.$langs->trans("MemberNature").''.$object->getmorphylib('', 1).'
'.$langs->trans("Company").''.dol_escape_htmltag($object->company).'
'.$langs->trans("UserTitle").''.$object->getCivilityLabel().'
'.$langs->trans("Password").''; if ($object->pass) { print preg_replace('/./i', '*', $object->pass); } else { if ($user->admin) { print ''; } print ''.$langs->trans("Hidden").''; } if (!empty($object->pass_indatabase) && empty($object->user_id)) { // Show warning only for old password still in clear (does not happen anymore) $langs->load("errors"); $htmltext = $langs->trans("WarningPasswordSetWithNoAccount"); print ' '.$form->textwithpicto('', $htmltext, 1, 'warning'); } print '
'.$langs->trans("SubscriptionEndDate").''; if ($object->datefin) { print dol_print_date($object->datefin, 'day'); if ($object->hasDelay()) { print " ".img_warning($langs->trans("Late")); } } else { if ($object->need_subscription == 0) { print $langs->trans("SubscriptionNotNeeded"); } elseif (!$adht->subscription) { print $langs->trans("SubscriptionNotRecorded"); if (Adherent::STATUS_VALIDATED == $object->statut) { print " ".img_warning($langs->trans("Late")); // displays delay Pictogram only if not a draft, not excluded and not resiliated } } else { print $langs->trans("SubscriptionNotReceived"); if (Adherent::STATUS_VALIDATED == $object->statut) { print " ".img_warning($langs->trans("Late")); // displays delay Pictogram only if not a draft, not excluded and not resiliated } } } print '
'; print '
'; print '
'; print '
'; print ''; // Tags / Categories if (isModEnabled('category') && $user->hasRight('categorie', 'lire')) { print ''; print ''; } // Birth Date print ''; // Default language if (getDolGlobalInt('MAIN_MULTILANGS')) { require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; print ''; } // Public $linkofpubliclist = DOL_MAIN_URL_ROOT.'/public/members/public_list.php'.((isModEnabled('multicompany')) ? '?entity='.$conf->entity : ''); print ''; // Other attributes $cols = 2; include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php'; // Third party Dolibarr if (isModEnabled('societe')) { print ''; } // Login Dolibarr - Link to user print ''; print "
'.$langs->trans("Categories").''; print $form->showCategories($object->id, Categorie::TYPE_MEMBER, 1); print '
'.$langs->trans("DateOfBirth").''.dol_print_date($object->birth, 'day').'
'.$langs->trans("DefaultLang").''; //$s=picto_from_langcode($object->default_lang); //print ($s?$s.' ':''); $langs->load("languages"); $labellang = ($object->default_lang ? $langs->trans('Language_'.$object->default_lang) : ''); print picto_from_langcode($object->default_lang, 'class="paddingrightonly saturatemedium opacitylow"'); print $labellang; print '
'.$form->textwithpicto($langs->trans("PublicFile"), $langs->trans("Public", getDolGlobalString('MAIN_INFO_SOCIETE_NOM'), $linkofpubliclist), 1, 'help', '', 0, 3, 'publicfile').''.yn($object->public).'
'; print ''; if ($action != 'editthirdparty' && $user->hasRight('adherent', 'creer')) { print ''; } print '
'; print $langs->trans("LinkedToDolibarrThirdParty"); print 'id.'">'.img_edit($langs->trans('SetLinkToThirdParty'), 1).'
'; print '
'; if ($action == 'editthirdparty') { $htmlname = 'socid'; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print '
'; print $form->select_company($object->fk_soc, 'socid', '', 1); print '
'; } else { if ($object->fk_soc) { $company = new Societe($db); $result = $company->fetch($object->fk_soc); print $company->getNomUrl(1); // Show link to invoices $tmparray = $company->getOutstandingBills('customer'); if (!empty($tmparray['refs'])) { print ' - '.img_picto($langs->trans("Invoices"), 'bill', 'class="paddingright"').''.$langs->trans("Invoices").' ('.count($tmparray['refs']).')'; // TODO Add alert if warning on at least one invoice late print ''; } } else { print ''.$langs->trans("NoThirdPartyAssociatedToMember").''; } } print '
'; print ''; if ($action != 'editlogin' && $user->hasRight('adherent', 'creer')) { print ''; } print '
'; print $langs->trans("LinkedToDolibarrUser"); print ''; if ($user->hasRight("user", "user", "creer")) { print 'id.'">'.img_edit($langs->trans('SetLinkToUser'), 1).''; } print '
'; print '
'; if ($action == 'editlogin') { $form->form_users($_SERVER['PHP_SELF'].'?rowid='.$object->id, $object->user_id, 'userid', ''); } else { if ($object->user_id) { $linkeduser = new User($db); $linkeduser->fetch($object->user_id); print $linkeduser->getNomUrl(-1); } else { print ''.$langs->trans("NoDolibarrAccess").''; } } print '
\n"; print "
\n"; print '
'; print dol_get_fiche_end(); /* * Action bar */ // Button to create a new subscription if member no draft (-1) neither resiliated (0) neither excluded (-2) if ($user->hasRight('adherent', 'cotisation', 'creer')) { if ($action != 'addsubscription' && $action != 'create_thirdparty') { print '
'; if ($object->statut > 0) { print '"; } else { print ''; } print '
'; } } /* * List of subscriptions */ if ($action != 'addsubscription' && $action != 'create_thirdparty') { $sql = "SELECT d.rowid, d.firstname, d.lastname, d.societe, d.fk_adherent_type as type,"; $sql .= " c.rowid as crowid, c.subscription,"; $sql .= " c.datec, c.fk_type as cfk_type,"; $sql .= " c.dateadh as dateh,"; $sql .= " c.datef,"; $sql .= " c.fk_bank,"; $sql .= " b.rowid as bid,"; $sql .= " ba.rowid as baid, ba.label, ba.bank, ba.ref, ba.account_number, ba.fk_accountancy_journal, ba.number, ba.currency_code"; $sql .= " FROM ".MAIN_DB_PREFIX."adherent as d, ".MAIN_DB_PREFIX."subscription as c"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."bank as b ON c.fk_bank = b.rowid"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."bank_account as ba ON b.fk_account = ba.rowid"; $sql .= " WHERE d.rowid = c.fk_adherent AND d.rowid=".((int) $rowid); $sql .= $db->order($sortfield, $sortorder); $result = $db->query($sql); if ($result) { $subscriptionstatic = new Subscription($db); $num = $db->num_rows($result); print ''."\n"; print ''; print_liste_field_titre('Ref', $_SERVER["PHP_SELF"], 'c.rowid', '', $param, '', $sortfield, $sortorder); print_liste_field_titre('DateCreation', $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, 'center '); print_liste_field_titre('Type', $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, 'center '); print_liste_field_titre('DateStart', $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, 'center '); print_liste_field_titre('DateEnd', $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, 'center '); print_liste_field_titre('Amount', $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, 'right '); if (isModEnabled('bank')) { print_liste_field_titre('Account', $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, 'right '); } print "\n"; $accountstatic = new Account($db); $adh = new Adherent($db); $adht = new AdherentType($db); $i = 0; while ($i < $num) { $objp = $db->fetch_object($result); $adh->id = $objp->rowid; $adh->typeid = $objp->type; $subscriptionstatic->ref = $objp->crowid; $subscriptionstatic->id = $objp->crowid; $typeid = $objp->cfk_type; if ($typeid > 0) { $adht->fetch($typeid); } print ''; print ''; print '\n"; print ''; print '\n"; print '\n"; print ''; if (isModEnabled('bank')) { print ''; } print ""; $i++; } if (empty($num)) { $colspan = 6; if (isModEnabled('bank')) { $colspan++; } print ''; } print "
'.$subscriptionstatic->getNomUrl(1).''.dol_print_date($db->jdate($objp->datec), 'dayhour')."'; if ($typeid > 0) { print $adht->getNomUrl(1); } print ''.dol_print_date($db->jdate($objp->dateh), 'day')."'.dol_print_date($db->jdate($objp->datef), 'day')."'.price($objp->subscription).''; if ($objp->bid) { $accountstatic->label = $objp->label; $accountstatic->id = $objp->baid; $accountstatic->number = $objp->number; $accountstatic->account_number = $objp->account_number; $accountstatic->currency_code = $objp->currency_code; if (isModEnabled('accounting') && $objp->fk_accountancy_journal > 0) { $accountingjournal = new AccountingJournal($db); $accountingjournal->fetch($objp->fk_accountancy_journal); $accountstatic->accountancy_journal = $accountingjournal->getNomUrl(0, 1, 1, '', 1); } $accountstatic->ref = $objp->ref; print $accountstatic->getNomUrl(1); } else { print ' '; } print '
'.$langs->trans("None").'
"; } else { dol_print_error($db); } } if (($action != 'addsubscription' && $action != 'create_thirdparty')) { // Show online payment link // The list can be complete by the hook 'doValidatePayment' executed inside getValidOnlinePaymentMethods() include_once DOL_DOCUMENT_ROOT.'/core/lib/payments.lib.php'; $validpaymentmethod = getValidOnlinePaymentMethods(''); $useonlinepayment = count($validpaymentmethod); if ($useonlinepayment) { print '
'; require_once DOL_DOCUMENT_ROOT.'/core/lib/payments.lib.php'; print showOnlinePaymentUrl('membersubscription', $object->ref); print '
'; } } /* * Add new subscription form */ if (($action == 'addsubscription' || $action == 'create_thirdparty') && $user->hasRight('adherent', 'cotisation', 'creer')) { print '
'; print load_fiche_titre($langs->trans("NewCotisation")); // Define default choice for complementary actions $bankdirect = 0; // 1 means option by default is write to bank direct with no invoice $invoiceonly = 0; // 1 means option by default is invoice only $bankviainvoice = 0; // 1 means option by default is write to bank via invoice if (GETPOST('paymentsave')) { if (GETPOST('paymentsave') == 'bankdirect') { $bankdirect = 1; } if (GETPOST('paymentsave') == 'invoiceonly') { $invoiceonly = 1; } if (GETPOST('paymentsave') == 'bankviainvoice') { $bankviainvoice = 1; } } else { if (getDolGlobalString('ADHERENT_BANK_USE') == 'bankviainvoice' && isModEnabled('bank') && isModEnabled('societe') && isModEnabled('invoice')) { $bankviainvoice = 1; } elseif (getDolGlobalString('ADHERENT_BANK_USE') == 'bankdirect' && isModEnabled('bank')) { $bankdirect = 1; } elseif (getDolGlobalString('ADHERENT_BANK_USE') == 'invoiceonly' && isModEnabled('bank') && isModEnabled('societe') && isModEnabled('invoice')) { $invoiceonly = 1; } } print "\n\n\n"; if ($conf->use_javascript_ajax) { //var_dump($bankdirect.'-'.$bankviainvoice.'-'.$invoiceonly); print "\n".''."\n"; } // Confirm create third party if ($action == 'create_thirdparty') { $companyalias = ''; $fullname = $object->getFullName($langs); if ($object->morphy == 'mor') { $companyname = $object->company; if (!empty($fullname)) { $companyalias = $fullname; } } else { $companyname = $fullname; if (!empty($object->company)) { $companyalias = $object->company; } } // Create a form array $formquestion = array( array('label' => $langs->trans("NameToCreate"), 'type' => 'text', 'name' => 'companyname', 'value' => $companyname, 'morecss' => 'minwidth300', 'moreattr' => 'maxlength="128"'), array('label' => $langs->trans("AliasNames"), 'type' => 'text', 'name' => 'companyalias', 'value' => $companyalias, 'morecss' => 'minwidth300', 'moreattr' => 'maxlength="128"') ); // If customer code was forced to "required", we ask it at creation to avoid error later if (getDolGlobalString('MAIN_COMPANY_CODE_ALWAYS_REQUIRED')) { $tmpcompany = new Societe($db); $tmpcompany->name = $companyname; $tmpcompany->get_codeclient($tmpcompany, 0); $customercode = $tmpcompany->code_client; $formquestion[] = array( 'label' => $langs->trans("CustomerCode"), 'type' => 'text', 'name' => 'customercode', 'value' => $customercode, 'morecss' => 'minwidth300', 'moreattr' => 'maxlength="128"', ); } // @todo Add other extrafields mandatory for thirdparty creation print $form->formconfirm($_SERVER["PHP_SELF"]."?rowid=".$object->id, $langs->trans("CreateDolibarrThirdParty"), $langs->trans("ConfirmCreateThirdParty"), "confirm_create_thirdparty", $formquestion, 1); } print '
'; print ''; print ''; print ''; print ''; print ''; print dol_get_fiche_head(''); print '
'; print ''."\n"; print ''; // Date payment if (GETPOST('paymentyear') && GETPOST('paymentmonth') && GETPOST('paymentday')) { $paymentdate = dol_mktime(0, 0, 0, GETPOST('paymentmonth'), GETPOST('paymentday'), GETPOST('paymentyear')); } print ''; // Date start subscription $currentyear = dol_print_date($now, "%Y"); $currentmonth = dol_print_date($now, "%m"); print '"; // Date end subscription if (GETPOST('endday')) { $dateto = dol_mktime(0, 0, 0, GETPOSTINT('endmonth'), GETPOSTINT('endday'), GETPOSTINT('endyear')); } if (!$dateto) { if (getDolGlobalInt('MEMBER_SUBSCRIPTION_SUGGEST_END_OF_MONTH')) { $dateto = dol_get_last_day((int) dol_print_date($datefrom, "%Y"), (int) dol_print_date($datefrom, "%m")); } elseif (getDolGlobalInt('MEMBER_SUBSCRIPTION_SUGGEST_END_OF_YEAR')) { $dateto = dol_get_last_day((int) dol_print_date($datefrom, "%Y")); } else { $dateto = -1; // By default, no date is suggested } } print '"; if ($adht->subscription) { // Amount print ''; // Label print ''; print ''; // Complementary action if ((isModEnabled('bank') || isModEnabled('invoice')) && !getDolGlobalString('ADHERENT_SUBSCRIPTION_HIDECOMPLEMENTARYACTIONS')) { $company = new Societe($db); if ($object->socid) { $result = $company->fetch($object->socid); } // No more action print ''; print ''; // Bank account print '\n"; // Payment mode print '\n"; // Date of payment print '\n"; print ''; print ''; print ''; print ''; print ''; print ''; } } print ''; print ''; print ''; print ''; print '
'.$langs->trans("DateSubscription").''; if (GETPOST('reday')) { $datefrom = dol_mktime(0, 0, 0, GETPOSTINT('remonth'), GETPOSTINT('reday'), GETPOSTINT('reyear')); } if (!$datefrom) { // Guess the subscription start date $datefrom = $object->datevalid; // By default, the subscription start date is the payment date if (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'); } // Now do a correction of the suggested date if (getDolGlobalString('MEMBER_SUBSCRIPTION_START_FIRST_DAY_OF') === "m") { $datefrom = dol_get_first_day((int) dol_print_date($datefrom, "%Y"), (int) dol_print_date($datefrom, "%m")); } elseif (getDolGlobalString('MEMBER_SUBSCRIPTION_START_FIRST_DAY_OF') === "Y") { $datefrom = dol_get_first_day((int) dol_print_date($datefrom, "%Y")); } } print $form->selectDate($datefrom, '', 0, 0, 0, "subscription", 1, 1); print "
'.$langs->trans("DateEndSubscription").''; print $form->selectDate($dateto, 'end', 0, 0, 0, "subscription", 1, 0); print "
'.$langs->trans("Amount").' '.$langs->trans("Currency".$conf->currency) .'
'.$langs->trans("Label").'
'.$langs->trans('MoreActions'); print ''; print ''; print '
'; // Add entry into bank account if (isModEnabled('bank')) { print '
'; } // Add invoice with no payments if (isModEnabled('societe') && isModEnabled('invoice')) { print 'fk_soc)) print ' disabled'; print '>
'; } // Add invoice with payments if (isModEnabled('bank') && isModEnabled('societe') && isModEnabled('invoice')) { print 'fk_soc)) print ' disabled'; print '>
'; } print '
'.$langs->trans("FinancialAccount").''; print img_picto('', 'bank_account', 'class="pictofixedwidth"'); $form->select_comptes(GETPOST('accountid'), 'accountid', 0, '', 2, '', 0, 'minwidth200'); print "
'.$langs->trans("PaymentMode").''; print $form->select_types_paiements(GETPOST('operation'), 'operation', '', 2, 1, 0, 0, 1, 'minwidth200', 1); print "
'.$langs->trans("DatePayment").''; print $form->selectDate(isset($paymentdate) ? $paymentdate : -1, 'payment', 0, 0, 1, 'subscription', 1, 1); print "
'.$langs->trans('Numero'); print ' ('.$langs->trans("ChequeOrTransferNumber").')'; print '
'.$langs->trans('CheckTransmitter'); print ' ('.$langs->trans("ChequeMaker").')'; print '
'.$langs->trans('Bank'); print ' ('.$langs->trans("ChequeBank").')'; print '
'.$langs->trans("SendAcknowledgementByMail").''; if (!$object->email) { print $langs->trans("NoEMail"); } else { $adht = new AdherentType($db); $adht->fetch($object->typeid); // Send subscription email $subject = ''; $msg = ''; // Send subscription email include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php'; $formmail = new FormMail($db); // Set output language $outputlangs = new Translate('', $conf); $outputlangs->setDefaultLang(empty($object->thirdparty->default_lang) ? $mysoc->default_lang : $object->thirdparty->default_lang); // Load traductions files required by page $outputlangs->loadLangs(array("main", "members")); // Get email content from template $arraydefaultmessage = null; $labeltouse = getDolGlobalString('ADHERENT_EMAIL_TEMPLATE_SUBSCRIPTION'); if (!empty($labeltouse)) { $arraydefaultmessage = $formmail->getEMailTemplate($db, 'member', $user, $outputlangs, 0, 1, $labeltouse); } if (!empty($labeltouse) && is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0) { $subject = $arraydefaultmessage->topic; $msg = $arraydefaultmessage->content; } $substitutionarray = getCommonSubstitutionArray($outputlangs, 0, null, $object); complete_substitutions_array($substitutionarray, $outputlangs, $object); $subjecttosend = make_substitutions($subject, $substitutionarray, $outputlangs); $texttosend = make_substitutions(dol_concatdesc($msg, $adht->getMailOnSubscription()), $substitutionarray, $outputlangs); $tmp = ''; $helpcontent = ''; $helpcontent .= ''.$langs->trans("MailFrom").': '.getDolGlobalString('ADHERENT_MAIL_FROM').'
'."\n"; $helpcontent .= ''.$langs->trans("MailRecipient").': '.$object->email.'
'."\n"; $helpcontent .= ''.$langs->trans("MailTopic").':
'."\n"; if ($subjecttosend) { $helpcontent .= $subjecttosend."\n"; } else { $langs->load("errors"); $helpcontent .= ''.$langs->trans("ErrorModuleSetupNotComplete", $langs->transnoentitiesnoconv("Module310Name")).''."\n"; } $helpcontent .= "
"; $helpcontent .= ''.$langs->trans("MailText").':
'; if ($texttosend) { $helpcontent .= dol_htmlentitiesbr($texttosend)."\n"; } else { $langs->load("errors"); $helpcontent .= ''.$langs->trans("ErrorModuleSetupNotComplete", $langs->transnoentitiesnoconv("Module310Name")).''."\n"; } // @phan-suppress-next-line PhanPluginSuspiciousParamOrder print $form->textwithpicto($tmp, $helpcontent, 1, 'help', '', 0, 2, 'helpemailtosend'); } print '
'; print '
'; print dol_get_fiche_end(); print '
'; $parameters = array(); $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); if (empty($reshook)) { print ''; print '     '; print ''; } print '
'; print '
'; print "\n\n\n"; } // End of page llxFooter(); $db->close();