dolibarr  20.0.0-beta
subscription.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2001-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3  * Copyright (C) 2002-2003 Jean-Louis Bergamo <jlb@j1b.org>
4  * Copyright (C) 2004-2018 Laurent Destailleur <eldy@users.sourceforge.net>
5  * Copyright (C) 2012-2017 Regis Houssin <regis.houssin@inodbox.com>
6  * Copyright (C) 2015-2016 Alexandre Spangaro <aspangaro@open-dsi.fr>
7  * Copyright (C) 2018-2024 Frédéric France <frederic.france@free.fr>
8  * Copyright (C) 2019 Thibault FOUCART <support@ptibogxiv.net>
9  * Copyright (C) 2023 Waël Almoman <info@almoman.com>
10  *
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 3 of the License, or
14  * (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program. If not, see <https://www.gnu.org/licenses/>.
23  */
24 
31 // Load Dolibarr environment
32 require '../main.inc.php';
33 require_once DOL_DOCUMENT_ROOT.'/core/lib/member.lib.php';
34 require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
35 require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
36 require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent_type.class.php';
37 require_once DOL_DOCUMENT_ROOT.'/adherents/class/subscription.class.php';
38 require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
39 require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
40 require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
41 require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingjournal.class.php';
42 
43 $langs->loadLangs(array("companies", "bills", "members", "users", "mails", 'other'));
44 
45 $action = GETPOST('action', 'aZ09');
46 $confirm = GETPOST('confirm', 'alpha');
47 $contextpage = GETPOST('contextpage', 'aZ09');
48 $optioncss = GETPOST('optioncss', 'aZ'); // Option for the css output (always '' except when 'print')
49 
50 $id = GETPOSTINT('rowid') ? GETPOSTINT('rowid') : GETPOSTINT('id');
51 $rowid = $id;
52 $ref = GETPOST('ref', 'alphanohtml');
53 $typeid = GETPOSTINT('typeid');
54 $cancel = GETPOST('cancel');
55 
56 // Load variable for pagination
57 $limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit;
58 $sortfield = GETPOST('sortfield', 'aZ09comma');
59 $sortorder = GETPOST('sortorder', 'aZ09comma');
60 $page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT("page");
61 if (empty($page) || $page == -1) {
62  $page = 0;
63 } // If $page is not defined, or '' or -1
64 $offset = $limit * $page;
65 $pageprev = $page - 1;
66 $pagenext = $page + 1;
67 
68 // Default sort order (if not yet defined by previous GETPOST)
69 if (!$sortfield) {
70  $sortfield = "c.rowid";
71 }
72 if (!$sortorder) {
73  $sortorder = "DESC";
74 }
75 
76 $object = new Adherent($db);
77 $extrafields = new ExtraFields($db);
78 $adht = new AdherentType($db);
79 
80 // fetch optionals attributes and labels
81 $extrafields->fetch_name_optionals_label($object->table_element);
82 
83 $errmsg = '';
84 
85 // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
86 $hookmanager->initHooks(array('subscription'));
87 
88 // PDF
89 $hidedetails = (GETPOSTINT('hidedetails') ? GETPOSTINT('hidedetails') : (getDolGlobalString('MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS') ? 1 : 0));
90 $hidedesc = (GETPOSTINT('hidedesc') ? GETPOSTINT('hidedesc') : (getDolGlobalString('MAIN_GENERATE_DOCUMENTS_HIDE_DESC') ? 1 : 0));
91 $hideref = (GETPOSTINT('hideref') ? GETPOSTINT('hideref') : (getDolGlobalString('MAIN_GENERATE_DOCUMENTS_HIDE_REF') ? 1 : 0));
92 
93 $datefrom = 0;
94 $dateto = 0;
95 $paymentdate = -1;
96 
97 // Fetch object
98 if ($id > 0 || !empty($ref)) {
99  // Load member
100  $result = $object->fetch($id, $ref);
101 
102  // Define variables to know what current user can do on users
103  $canadduser = ($user->admin || $user->hasRight("user", "user", "creer"));
104  // Define variables to know what current user can do on properties of user linked to edited member
105  if ($object->user_id) {
106  // $User is the user who edits, $object->user_id is the id of the related user in the edited member
107  $caneditfielduser = ((($user->id == $object->user_id) && $user->hasRight("user", "self", "creer"))
108  || (($user->id != $object->user_id) && $user->hasRight("user", "user", "creer")));
109  $caneditpassworduser = ((($user->id == $object->user_id) && $user->hasRight("user", "self", "password"))
110  || (($user->id != $object->user_id) && $user->hasRight("user", "user", "password")));
111  }
112 }
113 
114 // Define variables to determine what the current user can do on the members
115 $canaddmember = $user->hasRight('adherent', 'creer');
116 // Define variables to determine what the current user can do on the properties of a member
117 if ($id) {
118  $caneditfieldmember = $user->hasRight('adherent', 'creer');
119 }
120 
121 // Security check
122 $result = restrictedArea($user, 'adherent', $object->id, '', '', 'socid', 'rowid', 0);
123 
124 
125 /*
126  * Actions
127  */
128 
129 $parameters = array();
130 $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action);
131 if ($reshook < 0) {
132  setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
133 }
134 
135 // Create third party from a member
136 if (empty($reshook) && $action == 'confirm_create_thirdparty' && $confirm == 'yes' && $user->hasRight('societe', 'creer')) {
137  if ($result > 0) {
138  // Creation of thirdparty
139  $company = new Societe($db);
140  $result = $company->create_from_member($object, GETPOST('companyname', 'alpha'), GETPOST('companyalias', 'alpha'), GETPOST('customercode', 'alpha'));
141 
142  if ($result < 0) {
143  $langs->load("errors");
144  setEventMessages($company->error, $company->errors, 'errors');
145  } else {
146  $action = 'addsubscription';
147  }
148  } else {
149  setEventMessages($object->error, $object->errors, 'errors');
150  }
151 }
152 
153 if (empty($reshook) && $action == 'setuserid' && ($user->hasRight('user', 'self', 'creer') || $user->hasRight('user', 'user', 'creer'))) {
154  $error = 0;
155  if (!$user->hasRight('user', 'user', 'creer')) { // If can edit only itself user, we can link to itself only
156  if (GETPOSTINT("userid") != $user->id && GETPOSTINT("userid") != $object->user_id) {
157  $error++;
158  setEventMessages($langs->trans("ErrorUserPermissionAllowsToLinksToItselfOnly"), null, 'errors');
159  }
160  }
161 
162  if (!$error) {
163  if (GETPOSTINT("userid") != $object->user_id) { // If link differs from currently in database
164  $result = $object->setUserId(GETPOSTINT("userid"));
165  if ($result < 0) {
166  dol_print_error(null, $object->error);
167  }
168  $action = '';
169  }
170  }
171 }
172 
173 if (empty($reshook) && $action == 'setsocid') {
174  $error = 0;
175  if (!$error) {
176  if (GETPOSTINT('socid') != $object->fk_soc) { // If link differs from currently in database
177  $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."adherent";
178  $sql .= " WHERE fk_soc = '".GETPOSTINT('socid')."'";
179  $resql = $db->query($sql);
180  if ($resql) {
181  $obj = $db->fetch_object($resql);
182  if ($obj && $obj->rowid > 0) {
183  $othermember = new Adherent($db);
184  $othermember->fetch($obj->rowid);
185  $thirdparty = new Societe($db);
186  $thirdparty->fetch(GETPOSTINT('socid'));
187  $error++;
188  setEventMessages($langs->trans("ErrorMemberIsAlreadyLinkedToThisThirdParty", $othermember->getFullName($langs), $othermember->login, $thirdparty->name), null, 'errors');
189  }
190  }
191 
192  if (!$error) {
193  $result = $object->setThirdPartyId(GETPOSTINT('socid'));
194  if ($result < 0) {
195  dol_print_error(null, $object->error);
196  }
197  $action = '';
198  }
199  }
200  }
201 }
202 
203 if ($user->hasRight('adherent', 'cotisation', 'creer') && $action == 'subscription' && !$cancel) {
204  $error = 0;
205 
206  $langs->load("banks");
207 
208  $result = $object->fetch($rowid);
209  $result = $adht->fetch($object->typeid);
210 
211  // Subscription information
212  $datesubscription = 0;
213  $datesubend = 0;
214  $defaultdelay = !empty($adht->duration_value) ? $adht->duration_value : 1;
215  $defaultdelayunit = !empty($adht->duration_unit) ? $adht->duration_unit : 'y';
216  $paymentdate = ''; // Do not use 0 here, default value is '' that means not filled where 0 means 1970-01-01
217  if (GETPOSTINT("reyear") && GETPOSTINT("remonth") && GETPOSTINT("reday")) {
218  $datesubscription = dol_mktime(0, 0, 0, GETPOSTINT("remonth"), GETPOSTINT("reday"), GETPOSTINT("reyear"));
219  }
220  if (GETPOSTINT("endyear") && GETPOSTINT("endmonth") && GETPOSTINT("endday")) {
221  $datesubend = dol_mktime(0, 0, 0, GETPOSTINT("endmonth"), GETPOSTINT("endday"), GETPOSTINT("endyear"));
222  }
223  if (GETPOSTINT("paymentyear") && GETPOSTINT("paymentmonth") && GETPOSTINT("paymentday")) {
224  $paymentdate = dol_mktime(0, 0, 0, GETPOSTINT("paymentmonth"), GETPOSTINT("paymentday"), GETPOSTINT("paymentyear"));
225  }
226  $amount = price2num(GETPOST("subscription", 'alpha')); // Amount of subscription
227  $label = GETPOST("label");
228 
229  // Payment information
230  $accountid = GETPOSTINT("accountid");
231  $operation = GETPOST("operation", "alphanohtml"); // Payment mode
232  $num_chq = GETPOST("num_chq", "alphanohtml");
233  $emetteur_nom = GETPOST("chqemetteur");
234  $emetteur_banque = GETPOST("chqbank");
235  $option = GETPOST("paymentsave");
236  if (empty($option)) {
237  $option = 'none';
238  }
239  $sendalsoemail = GETPOST("sendmail", 'alpha');
240 
241  // Check parameters
242  if (!$datesubscription) {
243  $error++;
244  $langs->load("errors");
245  $errmsg = $langs->trans("ErrorBadDateFormat", $langs->transnoentitiesnoconv("DateSubscription"));
246  setEventMessages($errmsg, null, 'errors');
247  $action = 'addsubscription';
248  }
249  if (GETPOST('end') && !$datesubend) {
250  $error++;
251  $langs->load("errors");
252  $errmsg = $langs->trans("ErrorBadDateFormat", $langs->transnoentitiesnoconv("DateEndSubscription"));
253  setEventMessages($errmsg, null, 'errors');
254  $action = 'addsubscription';
255  }
256  if (!$datesubend) {
257  $datesubend = dol_time_plus_duree(dol_time_plus_duree($datesubscription, $defaultdelay, $defaultdelayunit), -1, 'd');
258  }
259  if (($option == 'bankviainvoice' || $option == 'bankdirect') && !$paymentdate) {
260  $error++;
261  $errmsg = $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("DatePayment"));
262  setEventMessages($errmsg, null, 'errors');
263  $action = 'addsubscription';
264  }
265 
266  // Check if a payment is mandatory or not
267  if ($adht->subscription) { // Member type need subscriptions
268  if (!is_numeric($amount)) {
269  // If field is '' or not a numeric value
270  $errmsg = $langs->trans("ErrorFieldRequired", $langs->transnoentities("Amount"));
271  setEventMessages($errmsg, null, 'errors');
272  $error++;
273  $action = 'addsubscription';
274  } else {
275  // If an amount has been provided, we check also fields that becomes mandatory when amount is not null.
276  if (isModEnabled('bank') && GETPOST("paymentsave") != 'none') {
277  if (GETPOST("subscription")) {
278  if (!GETPOST("label")) {
279  $errmsg = $langs->trans("ErrorFieldRequired", $langs->transnoentities("Label"));
280  setEventMessages($errmsg, null, 'errors');
281  $error++;
282  $action = 'addsubscription';
283  }
284  if (GETPOST("paymentsave") != 'invoiceonly' && !GETPOST("operation")) {
285  $errmsg = $langs->trans("ErrorFieldRequired", $langs->transnoentities("PaymentMode"));
286  setEventMessages($errmsg, null, 'errors');
287  $error++;
288  $action = 'addsubscription';
289  }
290  if (GETPOST("paymentsave") != 'invoiceonly' && !(GETPOSTINT("accountid") > 0)) {
291  $errmsg = $langs->trans("ErrorFieldRequired", $langs->transnoentities("FinancialAccount"));
292  setEventMessages($errmsg, null, 'errors');
293  $error++;
294  $action = 'addsubscription';
295  }
296  } else {
297  if (GETPOSTINT("accountid")) {
298  $errmsg = $langs->trans("ErrorDoNotProvideAccountsIfNullAmount");
299  setEventMessages($errmsg, null, 'errors');
300  $error++;
301  $action = 'addsubscription';
302  }
303  }
304  }
305  }
306  }
307 
308  // Record the subscription then complementary actions
309  if (!$error && $action == 'subscription') {
310  $db->begin();
311 
312  // Create subscription
313  $crowid = $object->subscription($datesubscription, $amount, $accountid, $operation, $label, $num_chq, $emetteur_nom, $emetteur_banque, $datesubend);
314  if ($crowid <= 0) {
315  $error++;
316  $errmsg = $object->error;
317  setEventMessages($object->error, $object->errors, 'errors');
318  }
319 
320  if (!$error) {
321  $result = $object->subscriptionComplementaryActions($crowid, $option, $accountid, $datesubscription, $paymentdate, $operation, $label, $amount, $num_chq, $emetteur_nom, $emetteur_banque);
322  if ($result < 0) {
323  $error++;
324  setEventMessages($object->error, $object->errors, 'errors');
325  } else {
326  // If an invoice was created, it is into $object->invoice
327  }
328  }
329 
330  if (!$error) {
331  $db->commit();
332  } else {
333  $db->rollback();
334  $action = 'addsubscription';
335  }
336 
337  if (!$error) {
338  setEventMessages("SubscriptionRecorded", null, 'mesgs');
339  }
340 
341  // Send email
342  if (!$error) {
343  // Send confirmation Email
344  if ($object->email && $sendalsoemail) { // $object is 'Adherent'
345  $parameters = array(
346  'datesubscription' => $datesubscription,
347  'amount' => $amount,
348  'ccountid' => $accountid,
349  'operation' => $operation,
350  'label' => $label,
351  'num_chq' => $num_chq,
352  'emetteur_nom' => $emetteur_nom,
353  'emetteur_banque' => $emetteur_banque,
354  'datesubend' => $datesubend
355  );
356  $reshook = $hookmanager->executeHooks('sendMail', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
357  if ($reshook < 0) {
358  setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
359  }
360 
361  if (empty($reshook)) {
362  $subject = '';
363  $msg = '';
364 
365  // Send subscription email
366  include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
367  $formmail = new FormMail($db);
368  // Set output language
369  $outputlangs = new Translate('', $conf);
370  $outputlangs->setDefaultLang(empty($object->thirdparty->default_lang) ? $mysoc->default_lang : $object->thirdparty->default_lang);
371  // Load traductions files required by page
372  $outputlangs->loadLangs(array("main", "members"));
373 
374  // Get email content from template
375  $arraydefaultmessage = null;
376  $labeltouse = getDolGlobalString('ADHERENT_EMAIL_TEMPLATE_SUBSCRIPTION');
377 
378  if (!empty($labeltouse)) {
379  $arraydefaultmessage = $formmail->getEMailTemplate($db, 'member', $user, $outputlangs, 0, 1, $labeltouse);
380  }
381 
382  if (!empty($labeltouse) && is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0) {
383  $subject = $arraydefaultmessage->topic;
384  $msg = $arraydefaultmessage->content;
385  }
386 
387  $substitutionarray = getCommonSubstitutionArray($outputlangs, 0, null, $object);
388  complete_substitutions_array($substitutionarray, $outputlangs, $object);
389  $subjecttosend = make_substitutions($subject, $substitutionarray, $outputlangs);
390  $texttosend = make_substitutions(dol_concatdesc($msg, $adht->getMailOnSubscription()), $substitutionarray, $outputlangs);
391 
392  // Attach a file ?
393  $file = '';
394  $listofpaths = array();
395  $listofnames = array();
396  $listofmimes = array();
397  if (is_object($object->invoice) && (!is_object($arraydefaultmessage) || intval($arraydefaultmessage->joinfiles))) {
398  $invoicediroutput = $conf->facture->dir_output;
399  $fileparams = dol_most_recent_file($invoicediroutput.'/'.$object->invoice->ref, preg_quote($object->invoice->ref, '/').'[^\-]+');
400  $file = $fileparams['fullname'];
401 
402  $listofpaths = array($file);
403  $listofnames = array(basename($file));
404  $listofmimes = array(dol_mimetype($file));
405  }
406 
407  $moreinheader = 'X-Dolibarr-Info: send_an_email by adherents/subscription.php'."\r\n";
408 
409  $result = $object->sendEmail($texttosend, $subjecttosend, $listofpaths, $listofmimes, $listofnames, "", "", 0, -1, '', $moreinheader);
410  if ($result < 0) {
411  $errmsg = $object->error;
412  setEventMessages($object->error, $object->errors, 'errors');
413  } else {
414  setEventMessages($langs->trans("EmailSentToMember", $object->email), null, 'mesgs');
415  }
416  }
417  } else {
418  setEventMessages($langs->trans("NoEmailSentToMember"), null, 'mesgs');
419  }
420  }
421 
422  // Clean some POST vars
423  if (!$error) {
424  $accountid = '';
425  $operation = '';
426  $label = '';
427  $num_chq = '';
428  $option = '';
429  }
430  }
431 }
432 
433 
434 
435 /*
436  * View
437  */
438 
439 $form = new Form($db);
440 
441 $now = dol_now();
442 
443 $title = $langs->trans("Member")." - ".$langs->trans("Subscriptions");
444 
445 $help_url = "EN:Module_Foundations|FR:Module_Adh&eacute;rents|ES:M&oacute;dulo_Miembros|DE:Modul_Mitglieder";
446 
447 llxHeader("", $title, $help_url);
448 
449 
450 $param = '';
451 if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
452  $param .= '&contextpage='.urlencode($contextpage);
453 }
454 if ($limit > 0 && $limit != $conf->liste_limit) {
455  $param .= '&limit='.((int) $limit);
456 }
457 $param .= '&id='.$rowid;
458 if ($optioncss != '') {
459  $param .= '&optioncss='.urlencode($optioncss);
460 }
461 // Add $param from extra fields
462 //include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
463 
464 
465 if (! ($object->id > 0)) {
466  $langs->load("errors");
467  print $langs->trans("ErrorRecordNotFound");
468 }
469 
470 /*$res = $object->fetch($rowid);
471  if ($res < 0) {
472  dol_print_error($db, $object->error);
473  exit;
474  }
475 */
476 
477 $adht->fetch($object->typeid);
478 
479 $defaultdelay = !empty($adht->duration_value) ? $adht->duration_value : 1;
480 $defaultdelayunit = !empty($adht->duration_unit) ? $adht->duration_unit : 'y';
481 
483 
484 $rowspan = 10;
485 if (!getDolGlobalString('ADHERENT_LOGIN_NOT_REQUIRED')) {
486  $rowspan++;
487 }
488 if (isModEnabled('societe')) {
489  $rowspan++;
490 }
491 
492 print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
493 print '<input type="hidden" name="token" value="'.newToken().'">';
494 print '<input type="hidden" name="rowid" value="'.$object->id.'">';
495 
496 print dol_get_fiche_head($head, 'subscription', $langs->trans("Member"), -1, 'user');
497 
498 $linkback = '<a href="'.DOL_URL_ROOT.'/adherents/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
499 
500 $morehtmlref = '<a href="'.DOL_URL_ROOT.'/adherents/vcard.php?id='.$object->id.'" class="refid">';
501 $morehtmlref .= img_picto($langs->trans("Download").' '.$langs->trans("VCard"), 'vcard.png', 'class="valignmiddle marginleftonly paddingrightonly"');
502 $morehtmlref .= '</a>';
503 
504 dol_banner_tab($object, 'rowid', $linkback, 1, 'rowid', 'ref', $morehtmlref);
505 
506 print '<div class="fichecenter">';
507 print '<div class="fichehalfleft">';
508 
509 print '<div class="underbanner clearboth"></div>';
510 print '<table class="border centpercent tableforfield">';
511 
512 // Login
513 if (!getDolGlobalString('ADHERENT_LOGIN_NOT_REQUIRED')) {
514  print '<tr><td class="titlefield">'.$langs->trans("Login").' / '.$langs->trans("Id").'</td><td class="valeur">'.dol_escape_htmltag($object->login).'</td></tr>';
515 }
516 
517 // Type
518 print '<tr><td class="titlefield">'.$langs->trans("Type").'</td>';
519 print '<td class="valeur">'.$adht->getNomUrl(1)."</td></tr>\n";
520 
521 // Morphy
522 print '<tr><td>'.$langs->trans("MemberNature").'</td>';
523 print '<td class="valeur" >'.$object->getmorphylib('', 1).'</td>';
524 print '</tr>';
525 
526 // Company
527 print '<tr><td>'.$langs->trans("Company").'</td><td class="valeur">'.dol_escape_htmltag($object->company).'</td></tr>';
528 
529 // Civility
530 print '<tr><td>'.$langs->trans("UserTitle").'</td><td class="valeur">'.$object->getCivilityLabel().'</td>';
531 print '</tr>';
532 
533 // Password
534 if (!getDolGlobalString('ADHERENT_LOGIN_NOT_REQUIRED')) {
535  print '<tr><td>'.$langs->trans("Password").'</td><td>';
536  if ($object->pass) {
537  print preg_replace('/./i', '*', $object->pass);
538  } else {
539  if ($user->admin) {
540  print '<!-- '.$langs->trans("Crypted").': '.$object->pass_indatabase_crypted.' -->';
541  }
542  print '<span class="opacitymedium">'.$langs->trans("Hidden").'</span>';
543  }
544  if (!empty($object->pass_indatabase) && empty($object->user_id)) { // Show warning only for old password still in clear (does not happen anymore)
545  $langs->load("errors");
546  $htmltext = $langs->trans("WarningPasswordSetWithNoAccount");
547  print ' '.$form->textwithpicto('', $htmltext, 1, 'warning');
548  }
549  print '</td></tr>';
550 }
551 
552 // Date end subscription
553 print '<tr><td>'.$langs->trans("SubscriptionEndDate").'</td><td class="valeur">';
554 if ($object->datefin) {
555  print dol_print_date($object->datefin, 'day');
556  if ($object->hasDelay()) {
557  print " ".img_warning($langs->trans("Late"));
558  }
559 } else {
560  if ($object->need_subscription == 0) {
561  print $langs->trans("SubscriptionNotNeeded");
562  } elseif (!$adht->subscription) {
563  print $langs->trans("SubscriptionNotRecorded");
564  if (Adherent::STATUS_VALIDATED == $object->statut) {
565  print " ".img_warning($langs->trans("Late")); // displays delay Pictogram only if not a draft, not excluded and not resiliated
566  }
567  } else {
568  print $langs->trans("SubscriptionNotReceived");
569  if (Adherent::STATUS_VALIDATED == $object->statut) {
570  print " ".img_warning($langs->trans("Late")); // displays delay Pictogram only if not a draft, not excluded and not resiliated
571  }
572  }
573 }
574 print '</td></tr>';
575 
576 print '</table>';
577 
578 print '</div>';
579 
580 print '<div class="fichehalfright">';
581 print '<div class="underbanner clearboth"></div>';
582 
583 print '<table class="border tableforfield centpercent">';
584 
585 // Tags / Categories
586 if (isModEnabled('category') && $user->hasRight('categorie', 'lire')) {
587  print '<tr><td>'.$langs->trans("Categories").'</td>';
588  print '<td colspan="2">';
589  print $form->showCategories($object->id, Categorie::TYPE_MEMBER, 1);
590  print '</td></tr>';
591 }
592 
593 // Birth Date
594 print '<tr><td class="titlefield">'.$langs->trans("DateOfBirth").'</td><td class="valeur">'.dol_print_date($object->birth, 'day').'</td></tr>';
595 
596 // Default language
597 if (getDolGlobalInt('MAIN_MULTILANGS')) {
598  require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
599  print '<tr><td>'.$langs->trans("DefaultLang").'</td><td>';
600  //$s=picto_from_langcode($object->default_lang);
601  //print ($s?$s.' ':'');
602  $langs->load("languages");
603  $labellang = ($object->default_lang ? $langs->trans('Language_'.$object->default_lang) : '');
604  print picto_from_langcode($object->default_lang, 'class="paddingrightonly saturatemedium opacitylow"');
605  print $labellang;
606  print '</td></tr>';
607 }
608 
609 // Public
610 $linkofpubliclist = DOL_MAIN_URL_ROOT.'/public/members/public_list.php'.((isModEnabled('multicompany')) ? '?entity='.$conf->entity : '');
611 print '<tr><td>'.$form->textwithpicto($langs->trans("PublicFile"), $langs->trans("Public", getDolGlobalString('MAIN_INFO_SOCIETE_NOM'), $linkofpubliclist), 1, 'help', '', 0, 3, 'publicfile').'</td><td class="valeur">'.yn($object->public).'</td></tr>';
612 
613 // Other attributes
614 $cols = 2;
615 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
616 
617 // Third party Dolibarr
618 if (isModEnabled('societe')) {
619  print '<tr><td>';
620  print '<table class="nobordernopadding" width="100%"><tr><td>';
621  print $langs->trans("LinkedToDolibarrThirdParty");
622  print '</td>';
623  if ($action != 'editthirdparty' && $user->hasRight('adherent', 'creer')) {
624  print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editthirdparty&token='.newToken().'&rowid='.$object->id.'">'.img_edit($langs->trans('SetLinkToThirdParty'), 1).'</a></td>';
625  }
626  print '</tr></table>';
627  print '</td><td colspan="2" class="valeur">';
628  if ($action == 'editthirdparty') {
629  $htmlname = 'socid';
630  print '<form method="POST" action="'.$_SERVER['PHP_SELF'].'" name="form'.$htmlname.'">';
631  print '<input type="hidden" name="rowid" value="'.$object->id.'">';
632  print '<input type="hidden" name="action" value="set'.$htmlname.'">';
633  print '<input type="hidden" name="token" value="'.newToken().'">';
634  print '<table class="nobordernopadding">';
635  print '<tr><td>';
636  print $form->select_company($object->fk_soc, 'socid', '', 1);
637  print '</td>';
638  print '<td class="left"><input type="submit" class="button button-edit" value="'.$langs->trans("Modify").'"></td>';
639  print '</tr></table></form>';
640  } else {
641  if ($object->fk_soc) {
642  $company = new Societe($db);
643  $result = $company->fetch($object->fk_soc);
644  print $company->getNomUrl(1);
645 
646  // Show link to invoices
647  $tmparray = $company->getOutstandingBills('customer');
648  if (!empty($tmparray['refs'])) {
649  print ' - '.img_picto($langs->trans("Invoices"), 'bill', 'class="paddingright"').'<a href="'.DOL_URL_ROOT.'/compta/facture/list.php?socid='.$object->socid.'">'.$langs->trans("Invoices").' ('.count($tmparray['refs']).')';
650  // TODO Add alert if warning on at least one invoice late
651  print '</a>';
652  }
653  } else {
654  print '<span class="opacitymedium">'.$langs->trans("NoThirdPartyAssociatedToMember").'</span>';
655  }
656  }
657  print '</td></tr>';
658 }
659 
660 // Login Dolibarr - Link to user
661 print '<tr><td>';
662 print '<table class="nobordernopadding" width="100%"><tr><td>';
663 print $langs->trans("LinkedToDolibarrUser");
664 print '</td>';
665 if ($action != 'editlogin' && $user->hasRight('adherent', 'creer')) {
666  print '<td class="right">';
667  if ($user->hasRight("user", "user", "creer")) {
668  print '<a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editlogin&token='.newToken().'&rowid='.$object->id.'">'.img_edit($langs->trans('SetLinkToUser'), 1).'</a>';
669  }
670  print '</td>';
671 }
672 print '</tr></table>';
673 print '</td><td colspan="2" class="valeur">';
674 if ($action == 'editlogin') {
675  $form->form_users($_SERVER['PHP_SELF'].'?rowid='.$object->id, $object->user_id, 'userid', '');
676 } else {
677  if ($object->user_id) {
678  $linkeduser = new User($db);
679  $linkeduser->fetch($object->user_id);
680  print $linkeduser->getNomUrl(-1);
681  } else {
682  print '<span class="opacitymedium">'.$langs->trans("NoDolibarrAccess").'</span>';
683  }
684 }
685 print '</td></tr>';
686 
687 print "</table>\n";
688 
689 print "</div></div>\n";
690 print '<div class="clearboth"></div>';
691 
692 print dol_get_fiche_end();
693 
694 
695 /*
696  * Action bar
697  */
698 
699 // Button to create a new subscription if member no draft (-1) neither resiliated (0) neither excluded (-2)
700 if ($user->hasRight('adherent', 'cotisation', 'creer')) {
701  if ($action != 'addsubscription' && $action != 'create_thirdparty') {
702  print '<div class="tabsAction">';
703 
704  if ($object->statut > 0) {
705  print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?rowid='.$rowid.'&action=addsubscription&token='.newToken().'">'.$langs->trans("AddSubscription")."</a></div>";
706  } else {
707  print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("ValidateBefore")).'">'.$langs->trans("AddSubscription").'</a></div>';
708  }
709 
710  print '</div>';
711  }
712 }
713 
714 /*
715  * List of subscriptions
716  */
717 if ($action != 'addsubscription' && $action != 'create_thirdparty') {
718  $sql = "SELECT d.rowid, d.firstname, d.lastname, d.societe, d.fk_adherent_type as type,";
719  $sql .= " c.rowid as crowid, c.subscription,";
720  $sql .= " c.datec, c.fk_type as cfk_type,";
721  $sql .= " c.dateadh as dateh,";
722  $sql .= " c.datef,";
723  $sql .= " c.fk_bank,";
724  $sql .= " b.rowid as bid,";
725  $sql .= " ba.rowid as baid, ba.label, ba.bank, ba.ref, ba.account_number, ba.fk_accountancy_journal, ba.number, ba.currency_code";
726  $sql .= " FROM ".MAIN_DB_PREFIX."adherent as d, ".MAIN_DB_PREFIX."subscription as c";
727  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."bank as b ON c.fk_bank = b.rowid";
728  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."bank_account as ba ON b.fk_account = ba.rowid";
729  $sql .= " WHERE d.rowid = c.fk_adherent AND d.rowid=".((int) $rowid);
730  $sql .= $db->order($sortfield, $sortorder);
731 
732  $result = $db->query($sql);
733  if ($result) {
734  $subscriptionstatic = new Subscription($db);
735 
736  $num = $db->num_rows($result);
737 
738  print '<table class="noborder centpercent">'."\n";
739 
740  print '<tr class="liste_titre">';
741  print_liste_field_titre('Ref', $_SERVER["PHP_SELF"], 'c.rowid', '', $param, '', $sortfield, $sortorder);
742  print_liste_field_titre('DateCreation', $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, 'center ');
743  print_liste_field_titre('Type', $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, 'center ');
744  print_liste_field_titre('DateStart', $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, 'center ');
745  print_liste_field_titre('DateEnd', $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, 'center ');
746  print_liste_field_titre('Amount', $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, 'right ');
747  if (isModEnabled('bank')) {
748  print_liste_field_titre('Account', $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, 'right ');
749  }
750  print "</tr>\n";
751 
752  $accountstatic = new Account($db);
753  $adh = new Adherent($db);
754  $adht = new AdherentType($db);
755 
756  $i = 0;
757  while ($i < $num) {
758  $objp = $db->fetch_object($result);
759 
760  $adh->id = $objp->rowid;
761  $adh->typeid = $objp->type;
762 
763  $subscriptionstatic->ref = $objp->crowid;
764  $subscriptionstatic->id = $objp->crowid;
765 
766  $typeid = $objp->cfk_type;
767  if ($typeid > 0) {
768  $adht->fetch($typeid);
769  }
770 
771  print '<tr class="oddeven">';
772  print '<td>'.$subscriptionstatic->getNomUrl(1).'</td>';
773  print '<td class="center">'.dol_print_date($db->jdate($objp->datec), 'dayhour')."</td>\n";
774  print '<td class="center">';
775  if ($typeid > 0) {
776  print $adht->getNomUrl(1);
777  }
778  print '</td>';
779  print '<td class="center">'.dol_print_date($db->jdate($objp->dateh), 'day')."</td>\n";
780  print '<td class="center">'.dol_print_date($db->jdate($objp->datef), 'day')."</td>\n";
781  print '<td class="right amount">'.price($objp->subscription).'</td>';
782  if (isModEnabled('bank')) {
783  print '<td class="right">';
784  if ($objp->bid) {
785  $accountstatic->label = $objp->label;
786  $accountstatic->id = $objp->baid;
787  $accountstatic->number = $objp->number;
788  $accountstatic->account_number = $objp->account_number;
789  $accountstatic->currency_code = $objp->currency_code;
790 
791  if (isModEnabled('accounting') && $objp->fk_accountancy_journal > 0) {
792  $accountingjournal = new AccountingJournal($db);
793  $accountingjournal->fetch($objp->fk_accountancy_journal);
794 
795  $accountstatic->accountancy_journal = $accountingjournal->getNomUrl(0, 1, 1, '', 1);
796  }
797 
798  $accountstatic->ref = $objp->ref;
799  print $accountstatic->getNomUrl(1);
800  } else {
801  print '&nbsp;';
802  }
803  print '</td>';
804  }
805  print "</tr>";
806  $i++;
807  }
808 
809  if (empty($num)) {
810  $colspan = 6;
811  if (isModEnabled('bank')) {
812  $colspan++;
813  }
814  print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("None").'</span></td></tr>';
815  }
816 
817  print "</table>";
818  } else {
819  dol_print_error($db);
820  }
821 }
822 
823 
824 if (($action != 'addsubscription' && $action != 'create_thirdparty')) {
825  // Shon online payment link
826  $useonlinepayment = (isModEnabled('paypal') || isModEnabled('stripe') || isModEnabled('paybox'));
827 
828  $parameters = array();
829  $reshook = $hookmanager->executeHooks('doShowOnlinePaymentUrl', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
830  if ($reshook > 0) {
831  if (isset($hookmanager->resArray['showonlinepaymenturl'])) {
832  $useonlinepayment = $hookmanager->resArray['showonlinepaymenturl'];
833  }
834  }
835 
836  if ($useonlinepayment) {
837  print '<br>';
838 
839  require_once DOL_DOCUMENT_ROOT.'/core/lib/payments.lib.php';
840  print showOnlinePaymentUrl('membersubscription', $object->ref);
841  print '<br>';
842  }
843 }
844 
845 /*
846  * Add new subscription form
847  */
848 if (($action == 'addsubscription' || $action == 'create_thirdparty') && $user->hasRight('adherent', 'cotisation', 'creer')) {
849  print '<br>';
850 
851  print load_fiche_titre($langs->trans("NewCotisation"));
852 
853  // Define default choice for complementary actions
854  $bankdirect = 0; // 1 means option by default is write to bank direct with no invoice
855  $invoiceonly = 0; // 1 means option by default is invoice only
856  $bankviainvoice = 0; // 1 means option by default is write to bank via invoice
857  if (GETPOST('paymentsave')) {
858  if (GETPOST('paymentsave') == 'bankdirect') {
859  $bankdirect = 1;
860  }
861  if (GETPOST('paymentsave') == 'invoiceonly') {
862  $invoiceonly = 1;
863  }
864  if (GETPOST('paymentsave') == 'bankviainvoice') {
865  $bankviainvoice = 1;
866  }
867  } else {
868  if (getDolGlobalString('ADHERENT_BANK_USE') == 'bankviainvoice' && isModEnabled('bank') && isModEnabled('societe') && isModEnabled('invoice')) {
869  $bankviainvoice = 1;
870  } elseif (getDolGlobalString('ADHERENT_BANK_USE') == 'bankdirect' && isModEnabled('bank')) {
871  $bankdirect = 1;
872  } elseif (getDolGlobalString('ADHERENT_BANK_USE') == 'invoiceonly' && isModEnabled('bank') && isModEnabled('societe') && isModEnabled('invoice')) {
873  $invoiceonly = 1;
874  }
875  }
876 
877  print "\n\n<!-- Form add subscription -->\n";
878 
879  if ($conf->use_javascript_ajax) {
880  //var_dump($bankdirect.'-'.$bankviainvoice.'-'.$invoiceonly);
881  print "\n".'<script type="text/javascript">';
882  print '$(document).ready(function () {
883  $(".bankswitchclass, .bankswitchclass2").'.(($bankdirect || $bankviainvoice) ? 'show()' : 'hide()').';
884  $("#none, #invoiceonly").click(function() {
885  $(".bankswitchclass").hide();
886  $(".bankswitchclass2").hide();
887  });
888  $("#bankdirect, #bankviainvoice").click(function() {
889  $(".bankswitchclass").show();
890  $(".bankswitchclass2").show();
891  });
892  $("#selectoperation").change(function() {
893  var code = $(this).val();
894  if (code == "CHQ")
895  {
896  $(".fieldrequireddyn").addClass("fieldrequired");
897  if ($("#fieldchqemetteur").val() == "")
898  {
899  $("#fieldchqemetteur").val($("#memberlabel").val());
900  }
901  }
902  else
903  {
904  $(".fieldrequireddyn").removeClass("fieldrequired");
905  }
906  });
907  ';
908  if (GETPOST('paymentsave')) {
909  print '$("#'.GETPOST('paymentsave', 'aZ09').'").prop("checked", true);';
910  }
911  print '});';
912  print '</script>'."\n";
913  }
914 
915 
916  // Confirm create third party
917  if ($action == 'create_thirdparty') {
918  $companyalias = '';
919  $fullname = $object->getFullName($langs);
920 
921  if ($object->morphy == 'mor') {
922  $companyname = $object->company;
923  if (!empty($fullname)) {
924  $companyalias = $fullname;
925  }
926  } else {
927  $companyname = $fullname;
928  if (!empty($object->company)) {
929  $companyalias = $object->company;
930  }
931  }
932 
933  // Create a form array
934  $formquestion = array(
935  array('label' => $langs->trans("NameToCreate"), 'type' => 'text', 'name' => 'companyname', 'value' => $companyname, 'morecss' => 'minwidth300', 'moreattr' => 'maxlength="128"'),
936  array('label' => $langs->trans("AliasNames"), 'type' => 'text', 'name' => 'companyalias', 'value' => $companyalias, 'morecss' => 'minwidth300', 'moreattr' => 'maxlength="128"')
937  );
938  // If customer code was forced to "required", we ask it at creation to avoid error later
939  if (getDolGlobalString('MAIN_COMPANY_CODE_ALWAYS_REQUIRED')) {
940  $tmpcompany = new Societe($db);
941  $tmpcompany->name = $companyname;
942  $tmpcompany->get_codeclient($tmpcompany, 0);
943  $customercode = $tmpcompany->code_client;
944  $formquestion[] = array(
945  'label' => $langs->trans("CustomerCode"),
946  'type' => 'text',
947  'name' => 'customercode',
948  'value' => $customercode,
949  'morecss' => 'minwidth300',
950  'moreattr' => 'maxlength="128"',
951  );
952  }
953  // @todo Add other extrafields mandatory for thirdparty creation
954 
955  print $form->formconfirm($_SERVER["PHP_SELF"]."?rowid=".$object->id, $langs->trans("CreateDolibarrThirdParty"), $langs->trans("ConfirmCreateThirdParty"), "confirm_create_thirdparty", $formquestion, 1);
956  }
957 
958 
959  print '<form name="subscription" method="POST" action="'.$_SERVER["PHP_SELF"].'">';
960  print '<input type="hidden" name="token" value="'.newToken().'">';
961  print '<input type="hidden" name="action" value="subscription">';
962  print '<input type="hidden" name="rowid" value="'.$rowid.'">';
963  print '<input type="hidden" name="memberlabel" id="memberlabel" value="'.dol_escape_htmltag($object->getFullName($langs)).'">';
964  print '<input type="hidden" name="thirdpartylabel" id="thirdpartylabel" value="'.dol_escape_htmltag($object->company).'">';
965 
966  print dol_get_fiche_head('');
967 
968  print '<div class="div-table-responsive">';
969  print '<table class="border centpercent">'."\n";
970  print '<tbody>';
971 
972  // Date payment
973  if (GETPOST('paymentyear') && GETPOST('paymentmonth') && GETPOST('paymentday')) {
974  $paymentdate = dol_mktime(0, 0, 0, GETPOST('paymentmonth'), GETPOST('paymentday'), GETPOST('paymentyear'));
975  }
976 
977  print '<tr>';
978  // Date start subscription
979  $currentyear = dol_print_date($now, "%Y");
980  $currentmonth = dol_print_date($now, "%m");
981  print '<td class="fieldrequired">'.$langs->trans("DateSubscription").'</td><td>';
982  if (GETPOST('reday')) {
983  $datefrom = dol_mktime(0, 0, 0, GETPOSTINT('remonth'), GETPOSTINT('reday'), GETPOSTINT('reyear'));
984  }
985  if (!$datefrom) {
986  $datefrom = $object->datevalid;
987  if (getDolGlobalString('MEMBER_SUBSCRIPTION_START_AFTER')) {
988  $datefrom = dol_time_plus_duree($now, (int) substr(getDolGlobalString('MEMBER_SUBSCRIPTION_START_AFTER'), 0, -1), substr(getDolGlobalString('MEMBER_SUBSCRIPTION_START_AFTER'), -1));
989  } elseif ($object->datefin > 0 && dol_time_plus_duree($object->datefin, $defaultdelay, $defaultdelayunit) > $now) {
990  $datefrom = dol_time_plus_duree($object->datefin, 1, 'd');
991  }
992 
993  if (getDolGlobalString('MEMBER_SUBSCRIPTION_START_FIRST_DAY_OF') === "m") {
994  $datefrom = dol_get_first_day(dol_print_date($datefrom, "%Y"), dol_print_date($datefrom, "%m"));
995  } elseif (getDolGlobalString('MEMBER_SUBSCRIPTION_START_FIRST_DAY_OF') === "Y") {
996  $datefrom = dol_get_first_day(dol_print_date($datefrom, "%Y"));
997  }
998  }
999  print $form->selectDate($datefrom, '', 0, 0, 0, "subscription", 1, 1);
1000  print "</td></tr>";
1001 
1002  // Date end subscription
1003  if (GETPOST('endday')) {
1004  $dateto = dol_mktime(0, 0, 0, GETPOSTINT('endmonth'), GETPOSTINT('endday'), GETPOSTINT('endyear'));
1005  }
1006  if (!$dateto) {
1007  if (getDolGlobalInt('MEMBER_SUBSCRIPTION_SUGGEST_END_OF_MONTH')) {
1008  $dateto = dol_get_last_day(dol_print_date($datefrom, "%Y"), dol_print_date($datefrom, "%m"));
1009  } elseif (getDolGlobalInt('MEMBER_SUBSCRIPTION_SUGGEST_END_OF_YEAR')) {
1010  $dateto = dol_get_last_day(dol_print_date($datefrom, "%Y"));
1011  } else {
1012  $dateto = -1; // By default, no date is suggested
1013  }
1014  }
1015  print '<tr><td>'.$langs->trans("DateEndSubscription").'</td><td>';
1016  print $form->selectDate($dateto, 'end', 0, 0, 0, "subscription", 1, 0);
1017  print "</td></tr>";
1018 
1019  if ($adht->subscription) {
1020  // Amount
1021  print '<tr><td class="fieldrequired">'.$langs->trans("Amount").'</td><td><input type="text" name="subscription" size="6" value="'.(GETPOSTISSET('subscription') ? GETPOST('subscription') : price($adht->amount, 0, '', 0)).'"> '.$langs->trans("Currency".$conf->currency) .'</td></tr>';
1022 
1023  // Label
1024  print '<tr><td>'.$langs->trans("Label").'</td>';
1025  print '<td><input name="label" type="text" size="32" value="';
1026  if (!getDolGlobalString('MEMBER_NO_DEFAULT_LABEL')) {
1027  print $langs->trans("Subscription").' '.dol_print_date(($datefrom ? $datefrom : time()), "%Y");
1028  }
1029  print '"></td></tr>';
1030 
1031  // Complementary action
1032  if ((isModEnabled('bank') || isModEnabled('invoice')) && !getDolGlobalString('ADHERENT_SUBSCRIPTION_HIDECOMPLEMENTARYACTIONS')) {
1033  $company = new Societe($db);
1034  if ($object->socid) {
1035  $result = $company->fetch($object->socid);
1036  }
1037 
1038  // No more action
1039  print '<tr><td class="tdtop fieldrequired">'.$langs->trans('MoreActions');
1040  print '</td>';
1041  print '<td class="line-height-large">';
1042 
1043  print '<input type="radio" class="moreaction" id="none" name="paymentsave" value="none"'.(empty($bankdirect) && empty($invoiceonly) && empty($bankviainvoice) ? ' checked' : '').'>';
1044  print '<label for="none"> '.$langs->trans("None").'</label><br>';
1045  // Add entry into bank account
1046  if (isModEnabled('bank')) {
1047  print '<input type="radio" class="moreaction" id="bankdirect" name="paymentsave" value="bankdirect"'.(!empty($bankdirect) ? ' checked' : '');
1048  print '><label for="bankdirect"> '.$langs->trans("MoreActionBankDirect").'</label><br>';
1049  }
1050  // Add invoice with no payments
1051  if (isModEnabled('societe') && isModEnabled('invoice')) {
1052  print '<input type="radio" class="moreaction" id="invoiceonly" name="paymentsave" value="invoiceonly"'.(!empty($invoiceonly) ? ' checked' : '');
1053  //if (empty($object->fk_soc)) print ' disabled';
1054  print '><label for="invoiceonly"> '.$langs->trans("MoreActionInvoiceOnly");
1055  if ($object->fk_soc) {
1056  print ' ('.$langs->trans("ThirdParty").': '.$company->getNomUrl(1).')';
1057  } else {
1058  print ' (';
1059  if (empty($object->fk_soc)) {
1060  print img_warning($langs->trans("NoThirdPartyAssociatedToMember"));
1061  }
1062  print $langs->trans("NoThirdPartyAssociatedToMember");
1063  print ' - <a href="'.$_SERVER["PHP_SELF"].'?rowid='.$object->id.'&amp;action=create_thirdparty">';
1064  print $langs->trans("CreateDolibarrThirdParty");
1065  print '</a>)';
1066  }
1067  if (!getDolGlobalString('ADHERENT_VAT_FOR_SUBSCRIPTIONS') || getDolGlobalString('ADHERENT_VAT_FOR_SUBSCRIPTIONS') != 'defaultforfoundationcountry') {
1068  print '. <span class="opacitymedium">'.$langs->trans("NoVatOnSubscription", 0).'</span>';
1069  }
1070  if (getDolGlobalString('ADHERENT_PRODUCT_ID_FOR_SUBSCRIPTIONS') && (isModEnabled('product') || isModEnabled('service'))) {
1071  $prodtmp = new Product($db);
1072  $result = $prodtmp->fetch(getDolGlobalString('ADHERENT_PRODUCT_ID_FOR_SUBSCRIPTIONS'));
1073  if ($result < 0) {
1074  setEventMessage($prodtmp->error, 'errors');
1075  }
1076  print '. '.$langs->transnoentitiesnoconv("ADHERENT_PRODUCT_ID_FOR_SUBSCRIPTIONS", $prodtmp->getNomUrl(1)); // must use noentitiesnoconv to avoid to encode html into getNomUrl of product
1077  }
1078  print '</label><br>';
1079  }
1080  // Add invoice with payments
1081  if (isModEnabled('bank') && isModEnabled('societe') && isModEnabled('invoice')) {
1082  print '<input type="radio" class="moreaction" id="bankviainvoice" name="paymentsave" value="bankviainvoice"'.(!empty($bankviainvoice) ? ' checked' : '');
1083  //if (empty($object->fk_soc)) print ' disabled';
1084  print '><label for="bankviainvoice"> '.$langs->trans("MoreActionBankViaInvoice");
1085  if ($object->socid) {
1086  print ' ('.$langs->trans("ThirdParty").': '.$company->getNomUrl(1).')';
1087  } else {
1088  print ' (';
1089  if (empty($object->socid)) {
1090  print img_warning($langs->trans("NoThirdPartyAssociatedToMember"));
1091  }
1092  print $langs->trans("NoThirdPartyAssociatedToMember");
1093  print ' - <a href="'.$_SERVER["PHP_SELF"].'?rowid='.$object->id.'&amp;action=create_thirdparty">';
1094  print $langs->trans("CreateDolibarrThirdParty");
1095  print '</a>)';
1096  }
1097  if (!getDolGlobalString('ADHERENT_VAT_FOR_SUBSCRIPTIONS') || getDolGlobalString('ADHERENT_VAT_FOR_SUBSCRIPTIONS') != 'defaultforfoundationcountry') {
1098  print '. <span class="opacitymedium">'.$langs->trans("NoVatOnSubscription", 0).'</span>';
1099  }
1100  if (getDolGlobalString('ADHERENT_PRODUCT_ID_FOR_SUBSCRIPTIONS') && (isModEnabled('product') || isModEnabled('service'))) {
1101  $prodtmp = new Product($db);
1102  $result = $prodtmp->fetch(getDolGlobalString('ADHERENT_PRODUCT_ID_FOR_SUBSCRIPTIONS'));
1103  if ($result < 0) {
1104  setEventMessage($prodtmp->error, 'errors');
1105  }
1106  print '. '.$langs->transnoentitiesnoconv("ADHERENT_PRODUCT_ID_FOR_SUBSCRIPTIONS", $prodtmp->getNomUrl(1)); // must use noentitiesnoconv to avoid to encode html into getNomUrl of product
1107  }
1108  print '</label><br>';
1109  }
1110  print '</td></tr>';
1111 
1112  // Bank account
1113  print '<tr class="bankswitchclass"><td class="fieldrequired">'.$langs->trans("FinancialAccount").'</td><td>';
1114  print img_picto('', 'bank_account', 'class="pictofixedwidth"');
1115  $form->select_comptes(GETPOST('accountid'), 'accountid', 0, '', 2, '', 0, 'minwidth200');
1116  print "</td></tr>\n";
1117 
1118  // Payment mode
1119  print '<tr class="bankswitchclass"><td class="fieldrequired">'.$langs->trans("PaymentMode").'</td><td>';
1120  print $form->select_types_paiements(GETPOST('operation'), 'operation', '', 2, 1, 0, 0, 1, 'minwidth200', 1);
1121  print "</td></tr>\n";
1122 
1123  // Date of payment
1124  print '<tr class="bankswitchclass"><td class="fieldrequired">'.$langs->trans("DatePayment").'</td><td>';
1125  print $form->selectDate(isset($paymentdate) ? $paymentdate : -1, 'payment', 0, 0, 1, 'subscription', 1, 1);
1126  print "</td></tr>\n";
1127 
1128  print '<tr class="bankswitchclass2"><td>'.$langs->trans('Numero');
1129  print ' <em>('.$langs->trans("ChequeOrTransferNumber").')</em>';
1130  print '</td>';
1131  print '<td><input id="fieldnum_chq" name="num_chq" type="text" size="8" value="'.(!GETPOST('num_chq') ? '' : GETPOST('num_chq')).'"></td></tr>';
1132 
1133  print '<tr class="bankswitchclass2 fieldrequireddyn"><td>'.$langs->trans('CheckTransmitter');
1134  print ' <em>('.$langs->trans("ChequeMaker").')</em>';
1135  print '</td>';
1136  print '<td><input id="fieldchqemetteur" name="chqemetteur" size="32" type="text" value="'.(!GETPOST('chqemetteur') ? '' : GETPOST('chqemetteur')).'"></td></tr>';
1137 
1138  print '<tr class="bankswitchclass2"><td>'.$langs->trans('Bank');
1139  print ' <em>('.$langs->trans("ChequeBank").')</em>';
1140  print '</td>';
1141  print '<td><input id="chqbank" name="chqbank" size="32" type="text" value="'.(!GETPOST('chqbank') ? '' : GETPOST('chqbank')).'"></td></tr>';
1142  }
1143  }
1144 
1145  print '<tr><td></td><td></td></tr>';
1146 
1147  print '<tr><td>'.$langs->trans("SendAcknowledgementByMail").'</td>';
1148  print '<td>';
1149  if (!$object->email) {
1150  print $langs->trans("NoEMail");
1151  } else {
1152  $adht = new AdherentType($db);
1153  $adht->fetch($object->typeid);
1154 
1155  // Send subscription email
1156  $subject = '';
1157  $msg = '';
1158 
1159  // Send subscription email
1160  include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
1161  $formmail = new FormMail($db);
1162  // Set output language
1163  $outputlangs = new Translate('', $conf);
1164  $outputlangs->setDefaultLang(empty($object->thirdparty->default_lang) ? $mysoc->default_lang : $object->thirdparty->default_lang);
1165  // Load traductions files required by page
1166  $outputlangs->loadLangs(array("main", "members"));
1167  // Get email content from template
1168  $arraydefaultmessage = null;
1169  $labeltouse = getDolGlobalString('ADHERENT_EMAIL_TEMPLATE_SUBSCRIPTION');
1170 
1171  if (!empty($labeltouse)) {
1172  $arraydefaultmessage = $formmail->getEMailTemplate($db, 'member', $user, $outputlangs, 0, 1, $labeltouse);
1173  }
1174 
1175  if (!empty($labeltouse) && is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0) {
1176  $subject = $arraydefaultmessage->topic;
1177  $msg = $arraydefaultmessage->content;
1178  }
1179 
1180  $substitutionarray = getCommonSubstitutionArray($outputlangs, 0, null, $object);
1181  complete_substitutions_array($substitutionarray, $outputlangs, $object);
1182  $subjecttosend = make_substitutions($subject, $substitutionarray, $outputlangs);
1183  $texttosend = make_substitutions(dol_concatdesc($msg, $adht->getMailOnSubscription()), $substitutionarray, $outputlangs);
1184 
1185  $tmp = '<input name="sendmail" type="checkbox"'.(GETPOST('sendmail', 'alpha') ? ' checked' : (getDolGlobalString('ADHERENT_DEFAULT_SENDINFOBYMAIL') ? ' checked' : '')).'>';
1186  $helpcontent = '';
1187  $helpcontent .= '<b>'.$langs->trans("MailFrom").'</b>: '.getDolGlobalString('ADHERENT_MAIL_FROM').'<br>'."\n";
1188  $helpcontent .= '<b>'.$langs->trans("MailRecipient").'</b>: '.$object->email.'<br>'."\n";
1189  $helpcontent .= '<b>'.$langs->trans("MailTopic").'</b>:<br>'."\n";
1190  if ($subjecttosend) {
1191  $helpcontent .= $subjecttosend."\n";
1192  } else {
1193  $langs->load("errors");
1194  $helpcontent .= '<span class="error">'.$langs->trans("ErrorModuleSetupNotComplete", $langs->transnoentitiesnoconv("Module310Name")).'</span>'."\n";
1195  }
1196  $helpcontent .= "<br>";
1197  $helpcontent .= '<b>'.$langs->trans("MailText").'</b>:<br>';
1198  if ($texttosend) {
1199  $helpcontent .= dol_htmlentitiesbr($texttosend)."\n";
1200  } else {
1201  $langs->load("errors");
1202  $helpcontent .= '<span class="error">'.$langs->trans("ErrorModuleSetupNotComplete", $langs->transnoentitiesnoconv("Module310Name")).'</span>'."\n";
1203  }
1204  // @phan-suppress-next-line PhanPluginSuspiciousParamOrder
1205  print $form->textwithpicto($tmp, $helpcontent, 1, 'help', '', 0, 2, 'helpemailtosend');
1206  }
1207  print '</td></tr>';
1208  print '</tbody>';
1209  print '</table>';
1210  print '</div>';
1211 
1212  print dol_get_fiche_end();
1213 
1214  print '<div class="center">';
1215  $parameters = array();
1216  $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action);
1217  if (empty($reshook)) {
1218  print '<input type="submit" class="button" name="add" value="'.$langs->trans("AddSubscription").'">';
1219  print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
1220  print '<input type="submit" class="button button-cancel" name="cancel" value="'.$langs->trans("Cancel").'">';
1221  }
1222  print '</div>';
1223 
1224  print '</form>';
1225 
1226  print "\n<!-- End form subscription -->\n\n";
1227 }
1228 
1229 
1230 // End of page
1231 llxFooter();
1232 $db->close();
if($user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition: card.php:58
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:55
llxFooter()
Empty footer.
Definition: wrapper.php:69
Class to manage bank accounts.
Class to manage accounting journals.
Class to manage members of a foundation.
const STATUS_VALIDATED
Validated status.
Class to manage members type.
Class to manage standard extra fields.
Class to manage generation of HTML components Only common components must be here.
Class permettant la generation du formulaire html d'envoi de mail unitaire Usage: $formail = new Form...
Class to manage products or services.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage subscriptions of foundation members.
Class to manage translations.
Class to manage Dolibarr users.
Definition: user.class.php:50
if(isModEnabled('invoice') && $user->hasRight('facture', 'lire')) if((isModEnabled('fournisseur') &&!getDolGlobalString('MAIN_USE_NEW_SUPPLIERMOD') && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') && $user->hasRight('don', 'lire')) if(isModEnabled('tax') && $user->hasRight('tax', 'charges', 'lire')) if(isModEnabled('invoice') &&isModEnabled('order') && $user->hasRight("commande", "lire") &&!getDolGlobalString('WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER')) $sql
Social contributions to pay.
Definition: index.php:745
dol_get_first_day($year, $month=1, $gm=false)
Return GMT time for first day of a month or year.
Definition: date.lib.php:595
dol_time_plus_duree($time, $duration_value, $duration_unit, $ruleforendofmonth=0)
Add a delay to a date.
Definition: date.lib.php:124
dol_get_last_day($year, $month=12, $gm=false)
Return GMT time for last day of a month or year.
Definition: date.lib.php:614
dol_most_recent_file($dir, $regexfilter='', $excludefilter=array('(\.meta|_preview.*\.png)$', '^\.'), $nohook=0, $mode=0)
Return file(s) into a directory (by default most recent)
Definition: files.lib.php:2706
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed information (by default a local PHP server timestamp) Rep...
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
picto_from_langcode($codelang, $moreatt='', $notitlealt=0)
Return img flag of country for a language code or country code.
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
dol_mimetype($file, $default='application/octet-stream', $mode=0)
Return MIME type of a file from its name with extension.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
yn($yesno, $case=1, $color=0)
Return yes or no in current language.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0)
Show tabs of a record.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
setEventMessage($mesgs, $style='mesgs', $noduplicate=0)
Set event message in dol_events session object.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
newToken()
Return the value of token currently saved into session with name 'newtoken'.
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
dol_concatdesc($text1, $text2, $forxml=false, $invert=false)
Concat 2 descriptions with a new line between them (second operand after first one with appropriate n...
complete_substitutions_array(&$substitutionarray, $outputlangs, $object=null, $parameters=null, $callfunc="completesubstitutionarray")
Complete the $substitutionarray with more entries coming from external module that had set the "subst...
make_substitutions($text, $substitutionarray, $outputlangs=null, $converttextinhtmlifnecessary=0)
Make substitution into a text string, replacing keys with vals from $substitutionarray (oldval=>newva...
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
dol_htmlentitiesbr($stringtoencode, $nl2brmode=0, $pagecodefrom='UTF-8', $removelasteolbr=1)
This function is called to encode a string into a HTML string but differs from htmlentities because a...
getCommonSubstitutionArray($outputlangs, $onlykey=0, $exclude=null, $object=null, $include=null)
Return array of possible common substitutions.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
img_edit($titlealt='default', $float=0, $other='')
Show logo edit/modify fiche.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
td amount
Definition: global.inc.php:554
member_prepare_head(Adherent $object)
Return array head with list of tabs to view object information.
Definition: member.lib.php:34
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.