dolibarr 25.0.0-alpha
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-2024 Alexandre Spangaro <aspangaro@open-dsi.fr>
7 * Copyright (C) 2018-2025 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 * Copyright (C) 2024-2026 MDW <mdeweerd@users.noreply.github.com>
11 * Copyright (C) 2026 Jon Bendtsen <jon.bendtsen.github@jonb.dk>
12 *
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 3 of the License, or
16 * (at your option) any later version.
17 *
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License
24 * along with this program. If not, see <https://www.gnu.org/licenses/>.
25 */
26
33// Load Dolibarr environment
34require '../main.inc.php';
44require_once DOL_DOCUMENT_ROOT.'/core/lib/member.lib.php';
45require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
46require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
47require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent_type.class.php';
48require_once DOL_DOCUMENT_ROOT.'/adherents/class/subscription.class.php';
49require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
50require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
51require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingjournal.class.php';
52require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
53require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
54
55$langs->loadLangs(array("companies", "bills", "orders", "members", "users", "mails", 'other'));
56
57$action = GETPOST('action', 'aZ09');
58$confirm = GETPOST('confirm', 'alpha');
59$contextpage = GETPOST('contextpage', 'aZ09');
60$optioncss = GETPOST('optioncss', 'aZ'); // Option for the css output (always '' except when 'print')
61
62$id = GETPOSTINT('rowid') ? GETPOSTINT('rowid') : GETPOSTINT('id');
63$rowid = $id;
64$ref = GETPOST('ref', 'alphanohtml');
65$typeid = GETPOSTINT('typeid');
66$cancel = GETPOST('cancel', 'alpha');
67
68// Load variable for pagination
69$limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit;
70$sortfield = GETPOST('sortfield', 'aZ09comma');
71$sortorder = GETPOST('sortorder', 'aZ09comma');
72$page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT('page');
73if (empty($page) || $page < 0 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha')) {
74 // If $page is not defined, or '' or -1 or if we click on clear filters
75 $page = 0;
76}
77$offset = $limit * $page;
78$pageprev = $page - 1;
79$pagenext = $page + 1;
80
81// Default sort order (if not yet defined by previous GETPOST)
82if (!$sortfield) {
83 $sortfield = "c.rowid";
84}
85if (!$sortorder) {
86 $sortorder = "DESC";
87}
88
89$object = new Adherent($db);
90
91$adht = new AdherentType($db);
92
93// fetch optionals attributes and labels
94$extrafields->fetch_name_optionals_label($object->table_element);
95
96$errmsg = '';
97
98// Initialize a technical object to manage hooks of page. Note that conf->hooks_modules contains an array of hook context
99$hookmanager->initHooks(array('subscription'));
100
101// PDF
102$hidedetails = (GETPOSTINT('hidedetails') ? GETPOSTINT('hidedetails') : (getDolGlobalString('MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS') ? 1 : 0));
103$hidedesc = (GETPOSTINT('hidedesc') ? GETPOSTINT('hidedesc') : (getDolGlobalString('MAIN_GENERATE_DOCUMENTS_HIDE_DESC') ? 1 : 0));
104$hideref = (GETPOSTINT('hideref') ? GETPOSTINT('hideref') : (getDolGlobalString('MAIN_GENERATE_DOCUMENTS_HIDE_REF') ? 1 : 0));
105
106$datefrom = 0;
107$dateto = 0;
108$paymentdate = -1;
109
110// Fetch object
111if ($id > 0 || !empty($ref)) {
112 // Load member
113 $result = $object->fetch($id, $ref);
114
115 // Define variables to know what current user can do on users
116 $canadduser = ($user->admin || $user->hasRight("user", "user", "creer"));
117 // Define variables to know what current user can do on properties of user linked to edited member
118 if ($object->user_id) {
119 // $User is the user who edits, $object->user_id is the id of the related user in the edited member
120 $caneditfielduser = ((($user->id == $object->user_id) && $user->hasRight("user", "self", "creer"))
121 || (($user->id != $object->user_id) && $user->hasRight("user", "user", "creer")));
122 $caneditpassworduser = ((($user->id == $object->user_id) && $user->hasRight("user", "self", "password"))
123 || (($user->id != $object->user_id) && $user->hasRight("user", "user", "password")));
124 }
125}
126
127// Define variables to determine what the current user can do on the members
128$permissiontoaddmember = $user->hasRight('adherent', 'creer');
129$permissiontoeditextra = $permissiontoaddmember;
130if (GETPOST('attribute', 'aZ09') && isset($extrafields->attributes[$object->table_element]['perms'][GETPOST('attribute', 'aZ09')])) {
131 // For action 'update_extras', is there a specific permission set for the attribute to update
132 $permissiontoeditextra = dol_eval((string) $extrafields->attributes[$object->table_element]['perms'][GETPOST('attribute', 'aZ09')]);
133}
134
135// Security check
136$result = restrictedArea($user, 'adherent', $object->id, '', '', 'socid', 'rowid', 0);
137
138// Preserve checkbox selections for linktoobject option
139$invoices_to_link_post = GETPOST('invoices_to_link', 'array:int');
140$orders_to_link_post = GETPOST('orders_to_link', 'array:int');
141$invoicereftolink_post = GETPOST('invoicereftolink', 'alpha');
142$orderreftolink_post = GETPOST('orderreftolink', 'alpha');
143
144/*
145 * Actions
146 */
147
148$parameters = array();
149$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action);
150if ($reshook < 0) {
151 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
152}
153
154if (empty($reshook) && $action == 'update_extras' && $permissiontoeditextra) {
155 $error = 0;
156 $object->oldcopy = dol_clone($object, 2); // @phan-suppress-current-line PhanTypeMismatchProperty
157 $attribute_name = GETPOST('attribute', 'aZ09');
158
159 // Fill array 'array_options' with data from update form
160 $ret = $extrafields->setOptionalsFromPost(null, $object, $attribute_name);
161 if ($ret < 0) {
162 $error++;
163 }
164 if (!$error) {
165 $result = $object->updateExtraField($attribute_name, 'MEMBER_MODIFY');
166 if ($result < 0) {
167 setEventMessages($object->error, $object->errors, 'errors');
168 $error++;
169 }
170 }
171 if ($error) {
172 $action = 'edit_extras';
173 }
174}
175
176// Create third party from a member
177if (empty($reshook) && $action == 'confirm_create_thirdparty' && $confirm == 'yes' && $user->hasRight('societe', 'creer')) {
178 if ($result > 0) {
179 // Creation of thirdparty
180 $company = new Societe($db);
181 $result = $company->create_from_member($object, GETPOST('companyname', 'alpha'), GETPOST('companyalias', 'alpha'), GETPOST('customercode', 'alpha'));
182
183 if ($result < 0) {
184 $langs->load("errors");
185 setEventMessages($company->error, $company->errors, 'errors');
186 } else {
187 $object->socid = $result;
188
189 $action = 'createsubscription';
190 }
191 } else {
192 setEventMessages($object->error, $object->errors, 'errors');
193 }
194}
195
196if (empty($reshook) && $action == 'setuserid' && ($user->hasRight('user', 'self', 'creer') || $user->hasRight('user', 'user', 'creer'))) {
197 $error = 0;
198 if (!$user->hasRight('user', 'user', 'creer')) { // If can edit only itself user, we can link to itself only
199 if (GETPOSTINT("userid") != $user->id && GETPOSTINT("userid") != $object->user_id) {
200 $error++;
201 setEventMessages($langs->trans("ErrorUserPermissionAllowsToLinksToItselfOnly"), null, 'errors');
202 }
203 }
204
205 if (!$error) {
206 if (GETPOSTINT("userid") != $object->user_id) { // If link differs from currently in database
207 $result = $object->setUserId(GETPOSTINT("userid"));
208 if ($result < 0) {
209 dol_print_error(null, $object->error);
210 }
211 $action = '';
212 }
213 }
214}
215
216if (empty($reshook) && $action == 'setsocid' && $permissiontoaddmember) {
217 $error = 0;
218 if (GETPOSTINT('socid') != $object->socid) { // If link differs from currently in database
219 $sql = "SELECT rowid FROM " . MAIN_DB_PREFIX . "adherent";
220 $sql .= " WHERE fk_soc = " . ((int) GETPOSTINT('socid'));
221 $resql = $db->query($sql);
222 if ($resql) {
223 $obj = $db->fetch_object($resql);
224 if ($obj && $obj->rowid > 0) {
225 $othermember = new Adherent($db);
226 $othermember->fetch($obj->rowid);
227 $thirdparty = new Societe($db);
228 $thirdparty->fetch(GETPOSTINT('socid'));
229 $error++;
230 setEventMessages($langs->trans("ErrorMemberIsAlreadyLinkedToThisThirdParty", $othermember->getFullName($langs), $othermember->login, $thirdparty->name), null, 'errors');
231 }
232 }
233
234 if (!$error) {
235 $result = $object->setThirdPartyId(GETPOSTINT('socid'));
236 if ($result < 0) {
237 dol_print_error(null, $object->error);
238 }
239 $action = '';
240 }
241 }
242}
243
244if (empty($reshook) && $user->hasRight('adherent', 'cotisation', 'creer') && $action == 'subscription' && !$cancel) {
245 $error = 0;
246
247 $langs->load("banks");
248
249 $result = $object->fetch($rowid);
250 $result = $adht->fetch($object->typeid);
251
252 // Subscription information
253 $datesubscription = 0;
254 $datesubend = 0;
255 $defaultdelay = !empty($adht->duration_value) ? $adht->duration_value : 1;
256 $defaultdelayunit = !empty($adht->duration_unit) ? $adht->duration_unit : 'y';
257 $paymentdate = ''; // Do not use 0 here, default value is '' that means not filled where 0 means 1970-01-01
258 if (GETPOSTINT("reyear") && GETPOSTINT("remonth") && GETPOSTINT("reday")) {
259 $datesubscription = dol_mktime(0, 0, 0, GETPOSTINT("remonth"), GETPOSTINT("reday"), GETPOSTINT("reyear"));
260 }
261 if (GETPOSTINT("endyear") && GETPOSTINT("endmonth") && GETPOSTINT("endday")) {
262 $datesubend = dol_mktime(0, 0, 0, GETPOSTINT("endmonth"), GETPOSTINT("endday"), GETPOSTINT("endyear"));
263 }
264 if (GETPOSTINT("paymentyear") && GETPOSTINT("paymentmonth") && GETPOSTINT("paymentday")) {
265 $paymentdate = dol_mktime(0, 0, 0, GETPOSTINT("paymentmonth"), GETPOSTINT("paymentday"), GETPOSTINT("paymentyear"));
266 }
267 $amount = price2num(GETPOST("subscription", 'alpha')); // Amount of subscription
268 $label = GETPOST("label");
269
270 // Payment information
271 $accountid = GETPOSTINT("accountid");
272 $operation = GETPOST("operation", "alphanohtml"); // Payment mode
273 $num_chq = GETPOST("num_chq", "alphanohtml");
274 $emetteur_nom = GETPOST("chqemetteur");
275 $emetteur_banque = GETPOST("chqbank");
276 $option = GETPOST("paymentsave");
277 if (empty($option)) {
278 $option = 'none';
279 }
280 $sendalsoemail = GETPOST("sendmail", 'alpha');
281
282 // Check parameters
283 if (!$datesubscription) {
284 $error++;
285 $langs->load("errors");
286 $errmsg = $langs->trans("ErrorBadDateFormat", $langs->transnoentitiesnoconv("DateSubscription"));
287 setEventMessages($errmsg, null, 'errors');
288 $action = 'createsubscription';
289 }
290 if (GETPOST('end') && !$datesubend) {
291 $error++;
292 $langs->load("errors");
293 $errmsg = $langs->trans("ErrorBadDateFormat", $langs->transnoentitiesnoconv("DateEndSubscription"));
294 setEventMessages($errmsg, null, 'errors');
295 $action = 'createsubscription';
296 }
297 if (!$datesubend) {
298 $datesubend = dol_time_plus_duree(dol_time_plus_duree($datesubscription, $defaultdelay, $defaultdelayunit), -1, 'd');
299 }
300 if (($option == 'bankviainvoice' || $option == 'bankdirect') && !$paymentdate) {
301 $error++;
302 $errmsg = $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("DatePayment"));
303 setEventMessages($errmsg, null, 'errors');
304 $action = 'createsubscription';
305 }
306
307 // Check if a payment is mandatory or not
308 if ($adht->subscription) { // Member type need subscriptions
309 if (!is_numeric($amount)) {
310 // If field is '' or not a numeric value
311 $errmsg = $langs->trans("ErrorFieldRequired", $langs->transnoentities("Amount"));
312 setEventMessages($errmsg, null, 'errors');
313 $error++;
314 $action = 'createsubscription';
315 } else {
316 // If an amount has been provided, we check also fields that becomes mandatory when amount is not null.
317 if (isModEnabled('bank') && GETPOST("paymentsave") != 'none' && GETPOST("paymentsave") != 'linktoobject') {
318 if (GETPOST("subscription")) {
319 if (!GETPOST("label")) {
320 $errmsg = $langs->trans("ErrorFieldRequired", $langs->transnoentities("Label"));
321 setEventMessages($errmsg, null, 'errors');
322 $error++;
323 $action = 'createsubscription';
324 }
325 if (GETPOST("paymentsave") != 'invoiceonly' && !GETPOST("operation") && GETPOST("paymentsave") != 'linktoobject') {
326 $errmsg = $langs->trans("ErrorFieldRequired", $langs->transnoentities("PaymentMode"));
327 setEventMessages($errmsg, null, 'errors');
328 $error++;
329 $action = 'createsubscription';
330 }
331 if (GETPOST("paymentsave") != 'invoiceonly' && !(GETPOSTINT("accountid") > 0) && GETPOST("paymentsave") != 'linktoobject') {
332 $errmsg = $langs->trans("ErrorFieldRequired", $langs->transnoentities("FinancialAccount"));
333 setEventMessages($errmsg, null, 'errors');
334 $error++;
335 $action = 'createsubscription';
336 }
337 } else {
338 if (GETPOSTINT("accountid")) {
339 $errmsg = $langs->trans("ErrorDoNotProvideAccountsIfNullAmount");
340 setEventMessages($errmsg, null, 'errors');
341 $error++;
342 $action = 'createsubscription';
343 }
344 }
345 }
346 }
347 }
348
349 // Check if user filled link fields but chose another option than "linktoobject"
350 if ($action == 'subscription' && $option != 'linktoobject' && $user->hasRight('adherent', 'cotisation', 'creer')) {
351 $link_inputs_exist = (!empty($invoices_to_link_post) || !empty($orders_to_link_post) || !empty($invoicereftolink_post) || !empty($orderreftolink_post));
352 if ($link_inputs_exist) {
353 setEventMessages($langs->trans("ErrorLinkFieldsFilledButPaymentSaveNone"), null, 'errors');
354 $error++;
355 $action = 'createsubscription';
356 }
357 }
358 // Validate manual refs before creating subscription (only for linktoobject option)
359 if ($action == 'subscription' && $option == 'linktoobject' && $user->hasRight('adherent', 'cotisation', 'creer')) {
360 if (!empty($invoicereftolink_post)) {
361 $tmpinvoice = new Facture($db);
362 if ($tmpinvoice->fetch(0, $invoicereftolink_post) <= 0) {
363 $error++;
364 setEventMessages($langs->trans("ErrorInvoiceNotFound", $invoicereftolink_post), null, 'errors');
365 $action = 'createsubscription';
366 }
367 unset($tmpinvoice);
368 }
369 if (!empty($orderreftolink_post)) {
370 $tmporder = new Commande($db);
371 if ($tmporder->fetch(0, $orderreftolink_post) <= 0) {
372 $error++;
373 setEventMessages($langs->trans("ErrorOrderNotFound", $orderreftolink_post), null, 'errors');
374 $action = 'createsubscription';
375 }
376 unset($tmporder);
377 }
378 }
379 // Record the subscription then complementary actions
380 if (!$error && $action == 'subscription') { // Test on permission already done
381 $db->begin();
382
383 // Create subscription
384 $crowid = $object->subscription($datesubscription, (float) $amount, $accountid, $operation, $label, $num_chq, $emetteur_nom, $emetteur_banque, $datesubend);
385 if ($crowid <= 0) {
386 $error++;
387 $errmsg = $object->error;
388 setEventMessages($object->error, $object->errors, 'errors');
389 }
390
391 if (!$error) {
392 $result = $object->subscriptionComplementaryActions($crowid, $option, $accountid, $datesubscription, $paymentdate, $operation, $label, (float) $amount, $num_chq, $emetteur_nom, $emetteur_banque);
393 if ($result < 0) {
394 $error++;
395 setEventMessages($object->error, $object->errors, 'errors');
396 } else {
397 // If an invoice was created, it is into $object->invoice
398 }
399 }
400
401 // ===== LINK TO EXISTING OBJECTS =====
402 if ($option == 'linktoobject' && $crowid > 0) {
403 $subscription = new Subscription($db);
404 if ($subscription->fetch($crowid) > 0) {
405 // Get thirdparty of the member for security validation
406 $adhlink = new Adherent($db);
407 $adhlink->fetch($subscription->fk_adherent);
408 $thirdpartyidtolink = $adhlink->fk_soc;
409
410 // Track links created in this request so we skip duplicates
411 // (e.g. object both checked in list and typed as manual ref)
412 $existinglinks = array();
413 $nbcreatedlinks = 0;
414
415 // --- Selected invoices (checkboxes) - must belong to member's thirdparty ---
416 if (!empty($invoices_to_link_post)) {
417 foreach ($invoices_to_link_post as $invoiceid) {
418 $tmpinvoice = new Facture($db);
419 if ($tmpinvoice->fetch($invoiceid) > 0) {
420 if ($tmpinvoice->socid != $thirdpartyidtolink) {
421 setEventMessages($langs->trans("ErrorInvoiceNotLinkedToThirdpartyOfMember", $tmpinvoice->ref), null, 'errors');
422 continue;
423 }
424 if (!empty($existinglinks['facture-'.$tmpinvoice->id])) {
425 continue; // Already linked, skip silently
426 }
427 if ($subscription->add_object_linked('facture', $tmpinvoice->id) > 0) {
428 $nbcreatedlinks++;
429 $existinglinks['facture-'.$tmpinvoice->id] = 1;
430 } else {
431 setEventMessages($subscription->error, $subscription->errors, 'errors');
432 }
433 }
434 unset($tmpinvoice);
435 }
436 }
437
438 // --- Manual invoice ref - allowed to link to any thirdparty ---
439 if (!empty($invoicereftolink_post)) {
440 $tmpinvoice = new Facture($db);
441 if ($tmpinvoice->fetch(0, $invoicereftolink_post) > 0) {
442 if (!empty($existinglinks['facture-'.$tmpinvoice->id])) {
443 setEventMessages($langs->trans("ErrorObjectAlreadyLinked", $tmpinvoice->ref), null, 'warnings');
444 } elseif ($subscription->add_object_linked('facture', $tmpinvoice->id) > 0) {
445 $nbcreatedlinks++;
446 $existinglinks['facture-'.$tmpinvoice->id] = 1;
447 } else {
448 setEventMessages($subscription->error, $subscription->errors, 'errors');
449 }
450 } else {
451 setEventMessages($langs->trans("ErrorInvoiceNotFound", $invoicereftolink_post), null, 'errors');
452 }
453 unset($tmpinvoice);
454 }
455
456 // --- Selected orders (checkboxes) - must belong to member's thirdparty ---
457 if (!empty($orders_to_link_post)) {
458 foreach ($orders_to_link_post as $orderid) {
459 $tmporder = new Commande($db);
460 if ($tmporder->fetch($orderid) > 0) {
461 if ($tmporder->socid != $thirdpartyidtolink) {
462 setEventMessages($langs->trans("ErrorOrderNotLinkedToThirdpartyOfMember", $tmporder->ref), null, 'errors');
463 continue;
464 }
465 if (!empty($existinglinks['commande-'.$tmporder->id])) {
466 continue; // Already linked, skip silently
467 }
468 if ($subscription->add_object_linked('commande', $tmporder->id) > 0) {
469 $nbcreatedlinks++;
470 $existinglinks['commande-'.$tmporder->id] = 1;
471 } else {
472 setEventMessages($subscription->error, $subscription->errors, 'errors');
473 }
474 }
475 unset($tmporder);
476 }
477 }
478
479 // --- Manual order ref - allowed to link to any thirdparty ---
480 if (!empty($orderreftolink_post)) {
481 $tmporder = new Commande($db);
482 if ($tmporder->fetch(0, $orderreftolink_post) > 0) {
483 if (!empty($existinglinks['commande-'.$tmporder->id])) {
484 setEventMessages($langs->trans("ErrorObjectAlreadyLinked", $tmporder->ref), null, 'warnings');
485 } elseif ($subscription->add_object_linked('commande', $tmporder->id) > 0) {
486 $nbcreatedlinks++;
487 $existinglinks['commande-'.$tmporder->id] = 1;
488 } else {
489 setEventMessages($subscription->error, $subscription->errors, 'errors');
490 }
491 } else {
492 setEventMessages($langs->trans("ErrorOrderNotFound", $orderreftolink_post), null, 'errors');
493 }
494 unset($tmporder);
495 }
496
497 if ($nbcreatedlinks > 0) {
498 setEventMessages($langs->trans("XLinksCreated", $nbcreatedlinks), null, 'mesgs');
499 }
500 }
501 unset($subscription);
502 }
503
504 if (!$error) {
505 $db->commit();
506 } else {
507 $db->rollback();
508 $action = 'createsubscription';
509 }
510
511 if (!$error) {
512 setEventMessages("SubscriptionRecorded", null, 'mesgs');
513 }
514
515 // Send email
516 if (!$error) {
517 // Send confirmation Email
518 if ($object->email && $sendalsoemail) { // $object is 'Adherent'
519 $parameters = array(
520 'datesubscription' => $datesubscription,
521 'amount' => $amount,
522 'accountid' => $accountid,
523 'operation' => $operation,
524 'label' => $label,
525 'num_chq' => $num_chq,
526 'emetteur_nom' => $emetteur_nom,
527 'emetteur_banque' => $emetteur_banque,
528 'datesubend' => $datesubend
529 );
530 $reshook = $hookmanager->executeHooks('sendMail', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
531 if ($reshook < 0) {
532 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
533 }
534
535 if (empty($reshook)) {
536 $subject = '';
537 $msg = '';
538
539 // Send subscription email
540 include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
541 $formmail = new FormMail($db);
542 // Set output language
543 $outputlangs = new Translate('', $conf);
544 $outputlangs->setDefaultLang(!empty($object->default_lang) ? $object->default_lang : (empty($object->thirdparty->default_lang) ? $mysoc->default_lang : $object->thirdparty->default_lang));
545 // Load traductions files required by page
546 $outputlangs->loadLangs(array("main", "members"));
547
548 // Get email content from template
549 $arraydefaultmessage = null;
550 $labeltouse = getDolGlobalString('ADHERENT_EMAIL_TEMPLATE_SUBSCRIPTION');
551
552 if (!empty($labeltouse)) {
553 $arraydefaultmessage = $formmail->getEMailTemplate($db, 'member', $user, $outputlangs, 0, 1, $labeltouse);
554 }
555
556 if (!empty($labeltouse) && is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0) {
557 $subject = (string) $arraydefaultmessage->topic;
558 $msg = (string) $arraydefaultmessage->content;
559 }
560
561 $substitutionarray = getCommonSubstitutionArray($outputlangs, 0, null, $object);
562 complete_substitutions_array($substitutionarray, $outputlangs, $object);
563 $subjecttosend = make_substitutions($subject, $substitutionarray, $outputlangs);
564 $texttosend = make_substitutions(dol_concatdesc($msg, $adht->getMailOnSubscription()), $substitutionarray, $outputlangs);
565
566 // Attach a file ?
567 $file = '';
568 $listofpaths = array();
569 $listofnames = array();
570 $listofmimes = array();
571 if (is_object($object->invoice) && (!is_object($arraydefaultmessage) || intval($arraydefaultmessage->joinfiles))) {
572 $invoicediroutput = $conf->facture->dir_output;
573 $fileparams = dol_most_recent_file($invoicediroutput.'/'.$object->invoice->ref, preg_quote($object->invoice->ref, '/').'[^\-]+');
574 $file = $fileparams['fullname'];
575
576 $listofpaths = array($file);
577 $listofnames = array(basename($file));
578 $listofmimes = array(dol_mimetype($file));
579 }
580
581 $moreinheader = 'X-Dolibarr-Info: send_an_email by adherents/subscription.php'."\r\n";
582
583 $result = $object->sendEmail($texttosend, $subjecttosend, $listofpaths, $listofmimes, $listofnames, "", "", 0, -1, '', $moreinheader);
584 if ($result < 0) {
585 $errmsg = $object->error;
586 setEventMessages($object->error, $object->errors, 'errors');
587 } else {
588 setEventMessages($langs->trans("EmailSentToMember", $object->email), null, 'mesgs');
589 }
590 }
591 } else {
592 setEventMessages($langs->trans("NoEmailSentToMember"), null, 'mesgs');
593 }
594 }
595
596 // Clean some POST vars
597 if (!$error) {
598 $accountid = '';
599 $operation = '';
600 $label = '';
601 $num_chq = '';
602 $option = '';
603 }
604 }
605}
606
607
608
609/*
610 * View
611 */
612
613$form = new Form($db);
614
615$now = dol_now();
616
617$title = $langs->trans("Member")." - ".$langs->trans("Subscriptions");
618$help_url = "EN:Module_Foundations|FR:Module_Adh&eacute;rents|ES:M&oacute;dulo_Miembros|DE:Modul_Mitglieder";
619
620llxHeader('', $title, $help_url, '', 0, 0, '', '', '', 'mod-member page-card_subscription');
621
622
623$param = '';
624if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
625 $param .= '&contextpage='.urlencode($contextpage);
626}
627if ($limit > 0 && $limit != $conf->liste_limit) {
628 $param .= '&limit='.((int) $limit);
629}
630$param .= '&id='.$rowid;
631if ($optioncss != '') {
632 $param .= '&optioncss='.urlencode($optioncss);
633}
634// Add $param from extra fields
635//include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
636
637
638if (! ($object->id > 0)) {
639 $langs->load("errors");
640 print $langs->trans("ErrorRecordNotFound");
641}
642
643
644$adht->fetch($object->typeid);
645
646$defaultdelay = !empty($adht->duration_value) ? $adht->duration_value : 1;
647$defaultdelayunit = !empty($adht->duration_unit) ? $adht->duration_unit : 'y';
648
649$head = member_prepare_head($object);
650
651$rowspan = 10;
652if (!getDolGlobalString('ADHERENT_LOGIN_NOT_REQUIRED')) {
653 $rowspan++;
654}
655if (isModEnabled('societe')) {
656 $rowspan++;
657}
658
659print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
660print '<input type="hidden" name="token" value="'.newToken().'">';
661print '<input type="hidden" name="rowid" value="'.$object->id.'">';
662
663print dol_get_fiche_head($head, 'subscription', $langs->trans("Member"), -1, 'user');
664
665$linkback = '<a href="'.dolBuildUrl(DOL_URL_ROOT.'/adherents/list.php', ['restore_lastsearch_values' => 1]).'">'.$langs->trans("BackToList").'</a>';
666
667$morehtmlref = '<a href="'.DOL_URL_ROOT.'/adherents/vcard.php?id='.$object->id.'" class="refid" tabindex="-1">';
668$morehtmlref .= img_picto($langs->trans("Download").' '.$langs->trans("VCard"), 'vcard', 'class="valignmiddle marginleftonly paddingrightonly"');
669$morehtmlref .= '</a>';
670
671dol_banner_tab($object, 'rowid', $linkback, 1, 'rowid', 'ref', $morehtmlref);
672
673print '<div class="fichecenter">';
674print '<div class="fichehalfleft">';
675
676print '<div class="underbanner clearboth"></div>';
677print '<table class="border centpercent tableforfield">';
678
679// Login
680if (!getDolGlobalString('ADHERENT_LOGIN_NOT_REQUIRED')) {
681 print '<tr><td class="titlefieldmiddle">'.$langs->trans("Login").' / '.$langs->trans("Id").'</td><td class="valeur">'.dol_escape_htmltag($object->login).'</td></tr>';
682}
683
684// Type
685print '<tr><td class="titlefieldmiddle">'.$langs->trans("Type").'</td>';
686print '<td class="valeur">'.$adht->getNomUrl(1)."</td></tr>\n";
687
688// Morphy
689print '<tr><td>'.$langs->trans("MemberNature").'</td>';
690print '<td class="valeur" >'.$object->getmorphylib('', 1).'</td>';
691print '</tr>';
692
693// Company
694print '<tr><td>'.$langs->trans("Company").'</td><td class="valeur">'.dol_escape_htmltag($object->company).'</td></tr>';
695
696// Civility
697print '<tr><td>'.$langs->trans("UserTitle").'</td><td class="valeur">'.$object->getCivilityLabel().'</td>';
698print '</tr>';
699
700// Password
701if (!getDolGlobalString('ADHERENT_LOGIN_NOT_REQUIRED')) {
702 print '<tr><td>'.$langs->trans("Password").'</td><td>';
703 if ($object->pass) {
704 print preg_replace('/./i', '*', $object->pass);
705 } else {
706 if ($user->admin) {
707 print '<!-- '.$langs->trans("Crypted").': '.$object->pass_indatabase_crypted.' -->';
708 }
709 print '<span class="opacitymedium">'.$langs->trans("Hidden").'</span>';
710 }
711 if (!empty($object->pass_indatabase) && empty($object->user_id)) { // Show warning only for old password still in clear (does not happen anymore)
712 $langs->load("errors");
713 $htmltext = $langs->trans("WarningPasswordSetWithNoAccount");
714 print ' '.$form->textwithpicto('', $htmltext, 1, 'warning');
715 }
716 print '</td></tr>';
717}
718
719// Date end subscription
720print '<tr><td>'.$langs->trans("SubscriptionEndDate").'</td><td class="valeur">';
721if ($object->datefin) {
722 print dol_print_date($object->datefin, 'day');
723 if ($object->hasDelay()) {
724 print " ".img_warning($langs->trans("Late"));
725 }
726} else {
727 if ($object->need_subscription == 0) {
728 print $langs->trans("SubscriptionNotNeeded");
729 } elseif (!$adht->subscription) {
730 print $langs->trans("SubscriptionNotRecorded");
731 if (Adherent::STATUS_VALIDATED == $object->status) {
732 print " ".img_warning($langs->trans("Late")); // displays delay Pictogram only if not a draft, not excluded and not resiliated
733 }
734 } else {
735 print $langs->trans("SubscriptionNotReceived");
736 if (Adherent::STATUS_VALIDATED == $object->status) {
737 print " ".img_warning($langs->trans("Late")); // displays delay Pictogram only if not a draft, not excluded and not resiliated
738 }
739 }
740}
741print '</td></tr>';
742
743print '</table>';
744
745print '</div>';
746
747print '<div class="fichehalfright">';
748print '<div class="underbanner clearboth"></div>';
749
750print '<table class="border tableforfield centpercent">';
751
752// Tags / Categories
753if (isModEnabled('category') && $user->hasRight('categorie', 'lire')) {
754 print '<tr><td>'.$langs->trans("Categories").'</td>';
755 print '<td colspan="2">';
756 print $form->showCategories($object->id, Categorie::TYPE_MEMBER, 1);
757 print '</td></tr>';
758}
759
760// Birth Date
761print '<tr><td class="titlefieldmiddle">'.$langs->trans("DateOfBirth").'</td><td class="valeur">'.dol_print_date($object->birth, 'day').'</td></tr>';
762
763// Default language
764if (getDolGlobalInt('MAIN_MULTILANGS')) {
765 require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
766 print '<tr><td>'.$langs->trans("DefaultLang").'</td><td>';
767 //$s=picto_from_langcode($object->default_lang);
768 //print ($s?$s.' ':'');
769 $langs->load("languages");
770 $labellang = ($object->default_lang ? $langs->trans('Language_'.$object->default_lang) : '');
771 print picto_from_langcode($object->default_lang, 'class="paddingrightonly saturatemedium opacitylow"');
772 print $labellang;
773 print '</td></tr>';
774}
775
776// Public
777$linkofpubliclist = DOL_MAIN_URL_ROOT.'/public/members/public_list.php'.((isModEnabled('multicompany')) ? '?entity='.$conf->entity : '');
778print '<tr><td>'.$form->textwithpicto($langs->trans("MembershipPublic"), $langs->trans("Public", getDolGlobalString('MAIN_INFO_SOCIETE_NOM'), $linkofpubliclist), 1, 'help', '', 0, 3, 'publicfile').'</td><td class="valeur">'.yn($object->public).'</td></tr>';
779
780// Other attributes
781$cols = 2;
782include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
783
784// Third party Dolibarr
785if (isModEnabled('societe')) {
786 print '<tr><td>';
787 print '<table class="nobordernopadding centpercent"><tr><td>';
788 print $langs->trans("LinkedToDolibarrThirdParty");
789 print '</td>';
790 if ($action != 'editthirdparty' && $user->hasRight('adherent', 'creer')) {
791 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>';
792 }
793 print '</tr></table>';
794 print '</td><td colspan="2" class="valeur">';
795 if ($action == 'editthirdparty') {
796 $htmlname = 'socid';
797 print '<form method="POST" action="'.$_SERVER['PHP_SELF'].'" name="form'.$htmlname.'">';
798 print '<input type="hidden" name="rowid" value="'.$object->id.'">';
799 print '<input type="hidden" name="action" value="set'.$htmlname.'">';
800 print '<input type="hidden" name="token" value="'.newToken().'">';
801 print '<table class="nobordernopadding">';
802 print '<tr><td>';
803 print $form->select_company($object->socid, 'socid', '', 1);
804 print '</td>';
805 print '<td class="left"><input type="submit" class="button button-edit" value="'.$langs->trans("Modify").'"></td>';
806 print '</tr></table></form>';
807 } else {
808 if ($object->socid > 0) {
809 $company = new Societe($db);
810 $result = $company->fetch($object->socid);
811 print $company->getNomUrl(1);
812
813 // Show link to invoices
814 $tmparray = $company->getOutstandingBills('customer');
815 if (!empty($tmparray['refs'])) {
816 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']).')';
817 // TODO Add alert if warning on at least one invoice late
818 print '</a>';
819 }
820 } else {
821 print '<span class="opacitymedium">'.$langs->trans("NoThirdPartyAssociatedToMember").'</span>';
822 }
823 }
824 print '</td></tr>';
825}
826
827// Login Dolibarr - Link to user
828print '<tr><td>';
829print '<table class="nobordernopadding centpercent"><tr><td>';
830print $langs->trans("LinkedToDolibarrUser");
831print '</td>';
832if ($action != 'editlogin' && $user->hasRight('adherent', 'creer')) {
833 print '<td class="right">';
834 if ($user->hasRight("user", "user", "creer")) {
835 print '<a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editlogin&token='.newToken().'&rowid='.$object->id.'">'.img_edit($langs->trans('SetLinkToUser'), 1).'</a>';
836 }
837 print '</td>';
838}
839print '</tr></table>';
840print '</td><td colspan="2" class="valeur">';
841if ($action == 'editlogin') {
842 $form->form_users($_SERVER['PHP_SELF'].'?rowid='.$object->id, (string) $object->user_id, 'userid', array());
843} else {
844 if ($object->user_id) {
845 $linkeduser = new User($db);
846 $linkeduser->fetch($object->user_id);
847 print $linkeduser->getNomUrl(-1);
848 } else {
849 print '<span class="opacitymedium">'.$langs->trans("NoDolibarrAccess").'</span>';
850 }
851}
852print '</td></tr>';
853
854print "</table>\n";
855
856print "</div></div>\n";
857print '<div class="clearboth"></div>';
858
859print dol_get_fiche_end();
860
861
862/*
863 * Action bar
864 */
865
866// Button to create a new subscription if member no draft (-1) neither resiliated (0) neither excluded (-2)
867if ($user->hasRight('adherent', 'cotisation', 'creer')) {
868 if ($action != 'createsubscription' && $action != 'create_thirdparty') {
869 print '<div class="tabsAction">';
870
871 if ($object->status > 0) {
872 print '<div class="inline-block divButAction"><a class="butAction" href="'.dolBuildUrl($_SERVER["PHP_SELF"], ['rowid' => $rowid, 'action' => 'createsubscription'], true).'">'.$langs->trans("AddSubscription")."</a></div>";
873 } else {
874 print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("ValidateBefore")).'">'.$langs->trans("AddSubscription").'</a></div>';
875 }
876
877 print '</div>';
878 }
879}
880
881/*
882 * List of subscriptions
883 */
884if ($action != 'createsubscription' && $action != 'create_thirdparty') {
885 $sql = "SELECT d.rowid, d.firstname, d.lastname, d.societe, d.fk_adherent_type as type,";
886 $sql .= " c.rowid as crowid, c.subscription,";
887 $sql .= " c.datec, c.fk_type as cfk_type,";
888 $sql .= " c.dateadh as dateh, c.note as clabel,";
889 $sql .= " c.datef,";
890 $sql .= " c.fk_bank,";
891 $sql .= " b.rowid as bid,";
892 $sql .= " ba.rowid as baid, ba.label, ba.bank, ba.ref, ba.account_number, ba.fk_accountancy_journal, ba.number, ba.currency_code";
893 $sql .= " FROM ".MAIN_DB_PREFIX."adherent as d, ".MAIN_DB_PREFIX."subscription as c";
894 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."bank as b ON c.fk_bank = b.rowid";
895 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."bank_account as ba ON b.fk_account = ba.rowid";
896 $sql .= " WHERE d.rowid = c.fk_adherent AND d.rowid=".((int) $rowid);
897 $sql .= $db->order($sortfield, $sortorder);
898
899 $result = $db->query($sql);
900 if ($result) {
901 $subscriptionstatic = new Subscription($db);
902
903 $num = $db->num_rows($result);
904
905 print '<div class="div-table-responsive-no-min">';
906 print '<table class="noborder centpercent">'."\n";
907
908 print '<tr class="liste_titre">';
909 print_liste_field_titre('Ref', $_SERVER["PHP_SELF"], 'c.rowid', '', $param, '', $sortfield, $sortorder);
910 print_liste_field_titre('DateCreation', $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, 'center ');
911 print_liste_field_titre('Type', $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, 'center ');
912 print_liste_field_titre('DateStart', $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, 'center ');
913 print_liste_field_titre('DateEnd', $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, 'center ');
914 print_liste_field_titre('Amount', $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, 'right ');
915 print_liste_field_titre('Note', $_SERVER["PHP_SELF"], 'clabel', '', $param, '', $sortfield, $sortorder);
916 if (isModEnabled('bank')) {
917 print_liste_field_titre('Account', $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, 'right ');
918 }
919 print "</tr>\n";
920
921 $accountstatic = new Account($db);
922 $adh = new Adherent($db);
923 $adht = new AdherentType($db);
924
925 $i = 0;
926 while ($i < $num) {
927 $objp = $db->fetch_object($result);
928
929 $adh->id = $objp->rowid;
930 $adh->typeid = $objp->type;
931
932 $subscriptionstatic->ref = $objp->crowid;
933 $subscriptionstatic->id = $objp->crowid;
934 $subscriptionstatic->note_public = $objp->clabel;
935
936 $typeid = $objp->cfk_type;
937 if ($typeid > 0) {
938 $adht->fetch($typeid);
939 }
940
941 print '<tr class="oddeven">';
942 print '<td class="tdoverflowmax150">'.$subscriptionstatic->getNomUrl(1).'</td>';
943 print '<td class="center nowraponall">'.dol_print_date($db->jdate($objp->datec), 'dayhour')."</td>\n";
944 print '<td class="center tdoverflowmax125">';
945 if ($typeid > 0) {
946 print $adht->getNomUrl(1);
947 }
948 print '</td>';
949 print '<td class="center">'.dol_print_date($db->jdate($objp->dateh), 'day')."</td>\n";
950 print '<td class="center">'.dol_print_date($db->jdate($objp->datef), 'day')."</td>\n";
951 print '<td class="right amount">'.price($objp->subscription).'</td>';
952 print '<td class="left">'.$objp->clabel.'</td>';
953 if (isModEnabled('bank')) {
954 print '<td class="tdoverflowmax100 right">';
955 if ($objp->bid) {
956 $accountstatic->label = $objp->label;
957 $accountstatic->id = $objp->baid;
958 $accountstatic->number = $objp->number;
959 $accountstatic->account_number = $objp->account_number;
960 $accountstatic->currency_code = $objp->currency_code;
961
962 if (isModEnabled('accounting') && $objp->fk_accountancy_journal > 0) {
963 $accountingjournal = new AccountingJournal($db);
964 $accountingjournal->fetch($objp->fk_accountancy_journal);
965
966 $accountstatic->accountancy_journal = $accountingjournal->getNomUrl(0, 1, 1, '', 1);
967 }
968
969 $accountstatic->ref = $objp->ref;
970 print $accountstatic->getNomUrl(1);
971 } else {
972 print '&nbsp;';
973 }
974 print '</td>';
975 }
976 print "</tr>";
977 $i++;
978 }
979
980 if (empty($num)) {
981 $colspan = 7;
982 if (isModEnabled('bank')) {
983 $colspan++;
984 }
985 print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("None").'</span></td></tr>';
986 }
987
988 print "</table>";
989 print '</div>';
990 } else {
991 dol_print_error($db);
992 }
993}
994
995
996if (($action != 'createsubscription' && $action != 'create_thirdparty')) {
997 // Show online payment link
998 // The list can be complete by the hook 'doValidatePayment' executed inside getValidOnlinePaymentMethods()
999 include_once DOL_DOCUMENT_ROOT.'/core/lib/payments.lib.php';
1000 $validpaymentmethod = getValidOnlinePaymentMethods('');
1001 $useonlinepayment = count($validpaymentmethod);
1002
1003 if ($useonlinepayment) {
1004 print '<br>';
1005
1006 require_once DOL_DOCUMENT_ROOT.'/core/lib/payments.lib.php';
1007 print showOnlinePaymentUrl('membersubscription', $object->ref);
1008 print '<br>';
1009 }
1010}
1011
1012/*
1013 * Add new subscription form
1014 */
1015if (($action == 'createsubscription' || $action == 'create_thirdparty') && $user->hasRight('adherent', 'cotisation', 'creer')) {
1016 print '<br>';
1017
1018 print load_fiche_titre($langs->trans("NewCotisation"));
1019
1020 // Define default choice for complementary actions
1021 $bankdirect = 0; // 1 means option by default is write to bank direct with no invoice
1022 $invoiceonly = 0; // 1 means option by default is invoice only
1023 $bankviainvoice = 0; // 1 means option by default is write to bank via invoice
1024 if (GETPOST('paymentsave')) {
1025 if (GETPOST('paymentsave') == 'bankdirect') {
1026 $bankdirect = 1;
1027 }
1028 if (GETPOST('paymentsave') == 'invoiceonly') {
1029 $invoiceonly = 1;
1030 }
1031 if (GETPOST('paymentsave') == 'bankviainvoice') {
1032 $bankviainvoice = 1;
1033 }
1034 } else {
1035 if (getDolGlobalString('ADHERENT_BANK_USE') == 'bankviainvoice' && isModEnabled('bank') && isModEnabled('societe') && isModEnabled('invoice')) {
1036 $bankviainvoice = 1;
1037 } elseif (getDolGlobalString('ADHERENT_BANK_USE') == 'bankdirect' && isModEnabled('bank')) {
1038 $bankdirect = 1;
1039 } elseif (getDolGlobalString('ADHERENT_BANK_USE') == 'invoiceonly' && isModEnabled('bank') && isModEnabled('societe') && isModEnabled('invoice')) {
1040 $invoiceonly = 1;
1041 }
1042 }
1043
1044 print "\n\n<!-- Form add subscription -->\n";
1045
1046 if ($conf->use_javascript_ajax) {
1047 //var_dump($bankdirect.'-'.$bankviainvoice.'-'.$invoiceonly);
1048 print "\n".'<script type="text/javascript">';
1049 print '$(document).ready(function () {
1050 $(".bankswitchclass, .bankswitchclass2").'.(($bankdirect || $bankviainvoice) ? 'show()' : 'hide()').';
1051 $(".linkobjectswitchclass").'.(GETPOST('paymentsave', 'aZ09') == 'linktoobject' ? 'show()' : 'hide()').';
1052 $("#none, #invoiceonly").click(function() {
1053 $(".bankswitchclass").hide();
1054 $(".bankswitchclass2").hide();
1055 $(".linkobjectswitchclass").hide();
1056 });
1057 $("#bankdirect, #bankviainvoice").click(function() {
1058 $(".bankswitchclass").show();
1059 $(".bankswitchclass2").show();
1060 $(".linkobjectswitchclass").hide();
1061 });
1062 $("#linktoobject").click(function() {
1063 $(".bankswitchclass").hide();
1064 $(".bankswitchclass2").hide();
1065 $(".linkobjectswitchclass").show();
1066 });
1067 $("#selectoperation").change(function() {
1068 var code = $(this).val();
1069 if (code == "CHQ")
1070 {
1071 $(".fieldrequireddyn").addClass("fieldrequired");
1072 if ($("#fieldchqemetteur").val() == "")
1073 {
1074 $("#fieldchqemetteur").val($("#memberlabel").val());
1075 }
1076 }
1077 else
1078 {
1079 $(".fieldrequireddyn").removeClass("fieldrequired");
1080 }
1081 });
1082 ';
1083 if (GETPOST('paymentsave')) {
1084 print '$("#'.GETPOST('paymentsave', 'aZ09').'").prop("checked", true);';
1085 }
1086 print '});';
1087 print '</script>'."\n";
1088 }
1089
1090
1091 // Confirm create third party
1092 if ($action == 'create_thirdparty') {
1093 $companyalias = '';
1094 $fullname = $object->getFullName($langs);
1095
1096 if ($object->morphy == 'mor') {
1097 $companyname = $object->company;
1098 if (!empty($fullname)) {
1099 $companyalias = $fullname;
1100 }
1101 } else {
1102 $companyname = $fullname;
1103 if (!empty($object->company)) {
1104 $companyalias = $object->company;
1105 }
1106 }
1107
1108 // Create a form array
1109 $formquestion = array(
1110 array('label' => $langs->trans("NameToCreate"), 'type' => 'text', 'name' => 'companyname', 'value' => $companyname, 'morecss' => 'minwidth300', 'moreattr' => 'maxlength="128"'),
1111 array('label' => $langs->trans("AliasNames"), 'type' => 'text', 'name' => 'companyalias', 'value' => $companyalias, 'morecss' => 'minwidth300', 'moreattr' => 'maxlength="128"')
1112 );
1113 // If customer code was forced to "required", we ask it at creation to avoid error later
1114 if (getDolGlobalString('MAIN_COMPANY_CODE_ALWAYS_REQUIRED')) {
1115 $tmpcompany = new Societe($db);
1116 $tmpcompany->name = (string) $companyname;
1117 $tmpcompany->get_codeclient($tmpcompany, 0);
1118 $customercode = $tmpcompany->code_client;
1119 $formquestion[] = array(
1120 'label' => $langs->trans("CustomerCode"),
1121 'type' => 'text',
1122 'name' => 'customercode',
1123 'value' => $customercode,
1124 'morecss' => 'minwidth300',
1125 'moreattr' => 'maxlength="128"',
1126 );
1127 }
1128 // @todo Add other extrafields mandatory for thirdparty creation
1129
1130 print $form->formconfirm($_SERVER["PHP_SELF"]."?rowid=".$object->id, $langs->trans("CreateDolibarrThirdParty"), $langs->trans("ConfirmCreateThirdParty"), "confirm_create_thirdparty", $formquestion, 1);
1131 }
1132
1133
1134 print '<form name="subscription" method="POST" action="'.dolBuildUrl($_SERVER["PHP_SELF"]).'">';
1135 print '<input type="hidden" name="token" value="'.newToken().'">';
1136 print '<input type="hidden" name="action" value="subscription">';
1137 print '<input type="hidden" name="rowid" value="'.$rowid.'">';
1138 print '<input type="hidden" name="memberlabel" id="memberlabel" value="'.dol_escape_htmltag($object->getFullName($langs)).'">';
1139 print '<input type="hidden" name="thirdpartylabel" id="thirdpartylabel" value="'.dol_escape_htmltag($object->company).'">';
1140
1141 print dol_get_fiche_head(array());
1142
1143 print '<div class="div-table-responsive">';
1144 print '<table class="border centpercent">'."\n";
1145 print '<tbody>';
1146
1147 // Date payment
1148 if (GETPOST('paymentyear') && GETPOST('paymentmonth') && GETPOST('paymentday')) {
1149 $paymentdate = dol_mktime(0, 0, 0, GETPOSTINT('paymentmonth'), GETPOSTINT('paymentday'), GETPOSTINT('paymentyear'));
1150 }
1151
1152 // Date start subscription
1153 print '<tr>';
1154 $currentyear = dol_print_date($now, "%Y");
1155 $currentmonth = dol_print_date($now, "%m");
1156 print '<td class="fieldrequired">'.$langs->trans("DateSubscription").'</td><td>';
1157 if (GETPOST('reday')) {
1158 $datefrom = dol_mktime(0, 0, 0, GETPOSTINT('remonth'), GETPOSTINT('reday'), GETPOSTINT('reyear'));
1159 }
1160 if (!$datefrom) {
1161 // Guess the subscription start date
1162 // By default, the subscription start date is the end date of previous membership ($object->datefin) + 1 day, or the date of
1163 // the validation of the member if no previous date exists.
1164 $datefrom = ($object->datefin ? dol_time_plus_duree($object->datefin, 1, 'd') : $object->datevalid);
1165
1166 if (getDolGlobalString('MEMBER_SUBSCRIPTION_START_AFTER')) {
1167 $datefrom = dol_time_plus_duree($now, (int) substr(getDolGlobalString('MEMBER_SUBSCRIPTION_START_AFTER'), 0, -1), substr(getDolGlobalString('MEMBER_SUBSCRIPTION_START_AFTER'), -1));
1168 } elseif ($object->datefin > 0 && dol_time_plus_duree($object->datefin, $defaultdelay, $defaultdelayunit) > $now) {
1169 $datefrom = dol_time_plus_duree($object->datefin, 1, 'd');
1170 }
1171 // Now do a correction of the suggested date
1172 if (getDolGlobalString('MEMBER_SUBSCRIPTION_START_FIRST_DAY_OF') === "m") {
1173 $datefrom = dol_get_first_day((int) dol_print_date($datefrom, "%Y"), (int) dol_print_date($datefrom, "%m"));
1174 } elseif (getDolGlobalString('MEMBER_SUBSCRIPTION_START_FIRST_DAY_OF') === "3m") {
1175 $datefrom = dol_time_plus_duree($object->datefin, -3, 'm');
1176 $datefrom = dol_get_first_day((int) dol_print_date($datefrom, "%Y"), (int) dol_print_date($datefrom, "%m"));
1177 } elseif (getDolGlobalString('MEMBER_SUBSCRIPTION_START_FIRST_DAY_OF') === "Y") {
1178 $datefrom = dol_get_first_day((int) dol_print_date($datefrom, "%Y"));
1179 }
1180 }
1181 print $form->selectDate($datefrom, '', 0, 0, 0, "subscription", 1, 1);
1182 print "</td></tr>";
1183
1184 // Date end subscription
1185 if (GETPOST('endday')) {
1186 $dateto = dol_mktime(0, 0, 0, GETPOSTINT('endmonth'), GETPOSTINT('endday'), GETPOSTINT('endyear'));
1187 }
1188 if (!$dateto) {
1189 if (getDolGlobalInt('MEMBER_SUBSCRIPTION_SUGGEST_END_OF_MONTH')) {
1190 $dateto = dol_get_last_day((int) dol_print_date($datefrom, "%Y"), (int) dol_print_date($datefrom, "%m"));
1191 } elseif (getDolGlobalInt('MEMBER_SUBSCRIPTION_SUGGEST_END_OF_YEAR')) {
1192 $dateto = dol_get_last_day((int) dol_print_date($datefrom, "%Y"));
1193 } else {
1194 $dateto = -1; // By default, no date is suggested
1195 }
1196 }
1197 print '<tr><td>'.$langs->trans("DateEndSubscription").'</td><td>';
1198 print $form->selectDate($dateto, 'end', 0, 0, 0, "subscription", 1, 0);
1199 print "</td></tr>";
1200
1201 if ($adht->subscription) {
1202 // Amount
1203 print '<tr><td class="fieldrequired">'.$langs->trans("Amount").'</td>';
1204 print '<td><input autofocus class="width50" type="text" name="subscription" value="'.(GETPOSTISSET('subscription') ? GETPOST('subscription') : (is_null($adht->amount) ? '' : price($adht->amount, 0, '', 0))).'"> '.$langs->trans("Currency".getDolCurrency()) .'</td></tr>';
1205
1206 // Label
1207 print '<tr><td>'.$langs->trans("Note").'</td>';
1208 print '<td><input name="label" type="text" size="32" value="';
1209 if (!getDolGlobalString('MEMBER_NO_DEFAULT_LABEL')) {
1210 print $langs->trans("Subscription").' '.dol_print_date(($datefrom ? $datefrom : dol_now()), "%Y");
1211 }
1212 print '"></td></tr>';
1213
1214 // Complementary action
1215 if ((isModEnabled('bank') || isModEnabled('invoice')) && !getDolGlobalString('ADHERENT_SUBSCRIPTION_HIDECOMPLEMENTARYACTIONS')) {
1216 $company = new Societe($db);
1217 if ($object->socid) {
1218 $result = $company->fetch($object->socid);
1219 }
1220
1221 // No more action
1222 print '<tr><td class="tdtop fieldrequired">'.$langs->trans('MoreActions');
1223 print '</td>';
1224 print '<td class="line-height-large">';
1225
1226 print '<input type="radio" class="moreaction" id="none" name="paymentsave" value="none"'.(empty($bankdirect) && empty($invoiceonly) && empty($bankviainvoice) ? ' checked' : '').'>';
1227 print '<label for="none"> '.$langs->trans("None").'</label><br>';
1228 // Add entry into bank account
1229 if (isModEnabled('bank')) {
1230 print '<input type="radio" class="moreaction" id="bankdirect" name="paymentsave" value="bankdirect"'.(!empty($bankdirect) ? ' checked' : '');
1231 print '><label for="bankdirect"> '.$langs->trans("MoreActionBankDirect").'</label><br>';
1232 }
1233 // Add invoice with no payments
1234 if (isModEnabled('societe') && isModEnabled('invoice')) {
1235 print '<input type="radio" class="moreaction" id="invoiceonly" name="paymentsave" value="invoiceonly"'.(!empty($invoiceonly) ? ' checked' : '');
1236 //if (empty($object->fk_soc)) print ' disabled';
1237 print '><label for="invoiceonly"> '.$langs->trans("MoreActionInvoiceOnly");
1238 if ($object->socid) {
1239 print ' ('.$langs->trans("ThirdParty").': '.$company->getNomUrl(1).')';
1240 } else {
1241 print ' (';
1242 if (empty($object->socid)) {
1243 print img_warning($langs->trans("NoThirdPartyAssociatedToMember"));
1244 }
1245 print $langs->trans("NoThirdPartyAssociatedToMember");
1246 print ' - <a href="'.$_SERVER["PHP_SELF"].'?rowid='.$object->id.'&action=create_thirdparty&token='.newToken().'">';
1247 print $langs->trans("CreateDolibarrThirdParty");
1248 print '</a>)';
1249 }
1250 if (!getDolGlobalString('ADHERENT_VAT_FOR_SUBSCRIPTIONS') || getDolGlobalString('ADHERENT_VAT_FOR_SUBSCRIPTIONS') != 'defaultforfoundationcountry') {
1251 print '. <span class="opacitymedium">'.$langs->trans("NoVatOnSubscription", 0).'</span>';
1252 }
1253 if (getDolGlobalString('ADHERENT_PRODUCT_ID_FOR_SUBSCRIPTIONS') && (isModEnabled('product') || isModEnabled('service'))) {
1254 $prodtmp = new Product($db);
1255 $result = $prodtmp->fetch(getDolGlobalInt('ADHERENT_PRODUCT_ID_FOR_SUBSCRIPTIONS'));
1256 if ($result < 0) {
1257 setEventMessage($prodtmp->error, 'errors');
1258 }
1259 print '. '.$langs->transnoentitiesnoconv("ADHERENT_PRODUCT_ID_FOR_SUBSCRIPTIONS", $prodtmp->getNomUrl(1)); // must use noentitiesnoconv to avoid to encode html into getNomUrl of product
1260 }
1261 print '</label><br>';
1262 }
1263 // Add invoice with payments
1264 if (isModEnabled('bank') && isModEnabled('societe') && isModEnabled('invoice')) {
1265 print '<input type="radio" class="moreaction" id="bankviainvoice" name="paymentsave" value="bankviainvoice"'.(!empty($bankviainvoice) ? ' checked' : '');
1266 //if (empty($object->socid)) print ' disabled';
1267 print '><label for="bankviainvoice"> '.$langs->trans("MoreActionBankViaInvoice");
1268 if ($object->socid) {
1269 print ' ('.$langs->trans("ThirdParty").': '.$company->getNomUrl(1).')';
1270 } else {
1271 print ' (';
1272 if (empty($object->socid)) {
1273 print img_warning($langs->trans("NoThirdPartyAssociatedToMember"));
1274 }
1275 print $langs->trans("NoThirdPartyAssociatedToMember");
1276 print ' - <a href="'.$_SERVER["PHP_SELF"].'?rowid='.$object->id.'&action=create_thirdparty&token='.newToken().'">';
1277 print $langs->trans("CreateDolibarrThirdParty");
1278 print '</a>)';
1279 }
1280 if (!getDolGlobalString('ADHERENT_VAT_FOR_SUBSCRIPTIONS') || getDolGlobalString('ADHERENT_VAT_FOR_SUBSCRIPTIONS') != 'defaultforfoundationcountry') {
1281 print '. <span class="opacitymedium">'.$langs->trans("NoVatOnSubscription", 0).'</span>';
1282 }
1283 if (getDolGlobalString('ADHERENT_PRODUCT_ID_FOR_SUBSCRIPTIONS') && (isModEnabled('product') || isModEnabled('service'))) {
1284 $prodtmp = new Product($db);
1285 $result = $prodtmp->fetch(getDolGlobalInt('ADHERENT_PRODUCT_ID_FOR_SUBSCRIPTIONS'));
1286 if ($result < 0) {
1287 setEventMessage($prodtmp->error, 'errors');
1288 }
1289 print '. '.$langs->transnoentitiesnoconv("ADHERENT_PRODUCT_ID_FOR_SUBSCRIPTIONS", $prodtmp->getNomUrl(1)); // must use noentitiesnoconv to avoid to encode html into getNomUrl of product
1290 }
1291 print '</label><br>';
1292 }
1293 // ===== START link BLOCK: Link to existing objects =====
1294 if ((isModEnabled('invoice') || isModEnabled('order')) && isModEnabled('societe') && $object->socid > 0) {
1295 print '<input type="radio" class="moreaction" id="linktoobject" name="paymentsave" value="linktoobject">';
1296 print '<label for="linktoobject"> '.$langs->trans("MoreActionLinkToExistingObject").'</label><br>';
1297
1298 // ===== COMMON SETUP FOR BOTH BLOCKS =====
1299 // Show project column only if module enabled and user can read projects
1300 $showproject = (isModEnabled('project') && $user->hasRight('projet', 'lire'));
1301 require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
1302 $projectstatic = new Project($db);
1303
1304 print '<div class="linkobjectswitchclass" style="margin-left: 20px; margin-top: 5px; display:none;">';
1305 // Invoices of the thirdparty, the 5 newest only
1306 // ===== START BLOCK: Invoices =====
1307 if (isModEnabled('invoice') && $user->hasRight('facture', 'lire')) {
1308 $sql_invoices = "SELECT f.rowid, f.fk_projet";
1309 $sql_invoices .= " FROM ".MAIN_DB_PREFIX."facture as f";
1310 $sql_invoices .= " WHERE f.fk_soc = ".((int) $object->socid)." AND f.entity IN (".getEntity('invoice').")";
1311 $sql_invoices .= $db->order("f.datef", "DESC");
1312 // Keep only the 5 latest invoices, the list can be long
1313 $sql_invoices .= $db->plimit(5);
1314
1315 print '<div class="div-table-responsive-no-min">';
1316 print '<table class="noborder allwidth">';
1317 print '<tr class="liste_titre">';
1318 // Block title is placed on the 2 first header cells to save space, so the Ref column has no more title
1319 print '<td colspan="2" class="left">'.$langs->trans("LastBills", 5).'</td>';
1320 print '<td>'.$langs->trans("RefCustomer").'</td>';
1321 if ($showproject) {
1322 print '<td>'.$langs->trans("Project").'</td>';
1323 }
1324 print '<td class="center">'.$langs->trans("Date").'</td>';
1325 print '<td class="right">'.$langs->trans("AmountHT").'</td>';
1326 print '<td class="right">'.$langs->trans("Status").'</td>';
1327 print '</tr>';
1328
1329 $resql_invoices = $db->query($sql_invoices);
1330 if ($resql_invoices) {
1331 $num_invoices = $db->num_rows($resql_invoices);
1332 $invoicestatic = new Facture($db);
1333
1334 $j = 0;
1335 while ($j < $num_invoices) {
1336 $objinv = $db->fetch_object($resql_invoices);
1337 $invoicestatic->fetch($objinv->rowid);
1338
1339 print '<tr class="oddeven">';
1340 print '<td class="center" style="padding: 4px;"><input type="checkbox" name="invoices_to_link[]" value="'.$invoicestatic->id.'" style="width: 14px; height: 14px;"'.(is_array($invoices_to_link_post) && in_array($invoicestatic->id, $invoices_to_link_post) ? ' checked' : '').'></td>';
1341 print '<td class="linkedcol-name tdoverflowmax150">'.$invoicestatic->getNomUrl(1).'</td>';
1342 print '<td class="linkedcol-ref tdoverflowmax150 nopaddingtopimp nopaddingbottomimp" title="'.dol_escape_htmltag($invoicestatic->ref_client).'">';
1343 if ($invoicestatic->ref_client) {
1344 print '<span class="small">'.dol_escape_htmltag($invoicestatic->ref_client).'</span>';
1345 } else {
1346 print '&nbsp;';
1347 }
1348 print '</td>';
1349 if ($showproject) {
1350 $project_label = '&nbsp;';
1351 if (!empty($objinv->fk_projet) && $projectstatic->fetch($objinv->fk_projet) > 0) {
1352 $project_label = $projectstatic->getNomUrl(1);
1353 }
1354 print '<td class="linkedcol-project">'.$project_label.'</td>';
1355 }
1356 print '<td class="linkedcol-date center">'.dol_print_date($invoicestatic->date, 'day').'</td>';
1357 print '<td class="linkedcol-amount right">'.price($invoicestatic->total_ht).'</td>';
1358 print '<td class="linkedcol-statut right">'.$invoicestatic->getLibStatut(3).'</td>';
1359 print '</tr>';
1360 $j++;
1361 }
1362 $colspan = $showproject ? 7 : 6;
1363 if (!$num_invoices) {
1364 print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("None").'</span></td></tr>';
1365 }
1366 } else {
1367 dol_print_error($db);
1368 }
1369
1370 // Footer row - manual ref input
1371 print '<tr class="liste_titre">';
1372 print '<td></td>';
1373 print '<td><input type="text" name="invoicereftolink" placeholder="'.dol_escape_htmltag($langs->trans("Ref")).'" style="width: 95%;" value="'.dol_escape_htmltag($invoicereftolink_post).'"></td>';
1374 print '<td colspan="'.($showproject ? 5 : 4).'"></td>';
1375 print '</tr>';
1376
1377 print '</table>';
1378 print '</div>';
1379 }
1380 // ===== END BLOCK: Invoices =====
1381
1382 // Orders of the thirdparty, the 5 newest only
1383 // ===== START BLOCK: Orders =====
1384 if (isModEnabled('order') && $user->hasRight('commande', 'lire')) {
1385 $sql_orders = "SELECT c.rowid, c.fk_projet";
1386 $sql_orders .= " FROM ".MAIN_DB_PREFIX."commande as c";
1387 $sql_orders .= " WHERE c.fk_soc = ".((int) $object->socid)." AND c.entity IN (".getEntity('commande').")";
1388 $sql_orders .= $db->order("c.date_commande", "DESC");
1389 // Keep only the 5 latest orders, the list can be long
1390 $sql_orders .= $db->plimit(5);
1391
1392 print '<div class="div-table-responsive-no-min">';
1393 print '<table class="noborder allwidth">';
1394 print '<tr class="liste_titre">';
1395 // Block title is placed on the 2 first header cells to save space, so the Ref column has no more title
1396 print '<td colspan="2" class="left">'.$langs->trans("LastOrders", 5).'</td>';
1397 print '<td>'.$langs->trans("RefCustomer").'</td>';
1398 if ($showproject) {
1399 print '<td>'.$langs->trans("Project").'</td>';
1400 }
1401 print '<td class="center">'.$langs->trans("Date").'</td>';
1402 print '<td class="right">'.$langs->trans("AmountHT").'</td>';
1403 print '<td class="right">'.$langs->trans("Status").'</td>';
1404 print '</tr>';
1405
1406 $resql_orders = $db->query($sql_orders);
1407 if ($resql_orders) {
1408 $num_orders = $db->num_rows($resql_orders);
1409 $orderstatic = new Commande($db);
1410
1411 $j = 0;
1412 while ($j < $num_orders) {
1413 $objord = $db->fetch_object($resql_orders);
1414 $orderstatic->fetch($objord->rowid);
1415
1416 print '<tr class="oddeven">';
1417 print '<td class="center" style="padding: 4px;"><input type="checkbox" name="orders_to_link[]" value="'.$orderstatic->id.'" style="width: 14px; height: 14px;"'.(is_array($orders_to_link_post) && in_array($orderstatic->id, $orders_to_link_post) ? ' checked' : '').'></td>';
1418 print '<td class="linkedcol-name tdoverflowmax150">'.$orderstatic->getNomUrl(1).'</td>';
1419 print '<td class="linkedcol-ref tdoverflowmax150 nopaddingtopimp nopaddingbottomimp" title="'.dol_escape_htmltag($orderstatic->ref_client).'">';
1420 if ($orderstatic->ref_client) {
1421 print '<span class="small">'.dol_escape_htmltag($orderstatic->ref_client).'</span>';
1422 } else {
1423 print '&nbsp;';
1424 }
1425 print '</td>';
1426 if ($showproject) {
1427 $project_label = '&nbsp;';
1428 if (!empty($objord->fk_projet) && $projectstatic->fetch($objord->fk_projet) > 0) {
1429 $project_label = $projectstatic->getNomUrl(1);
1430 }
1431 print '<td class="linkedcol-project">'.$project_label.'</td>';
1432 }
1433 print '<td class="linkedcol-date center">'.dol_print_date($orderstatic->date, 'day').'</td>';
1434 print '<td class="linkedcol-amount right">'.price($orderstatic->total_ht).'</td>';
1435 print '<td class="linkedcol-statut right">'.$orderstatic->getLibStatut(3).'</td>';
1436 print '</tr>';
1437 $j++;
1438 }
1439 $colspan = $showproject ? 7 : 6;
1440 if (!$num_orders) {
1441 print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("None").'</span></td></tr>';
1442 }
1443 } else {
1444 dol_print_error($db);
1445 }
1446
1447 // Footer row - manual ref input
1448 print '<tr class="liste_titre">';
1449 print '<td></td>';
1450 print '<td><input type="text" name="orderreftolink" placeholder="'.dol_escape_htmltag($langs->trans("Ref")).'" style="width: 95%;" value="'.dol_escape_htmltag($orderreftolink_post).'"></td>';
1451 print '<td colspan="'.($showproject ? 5 : 4).'"></td>';
1452 print '</tr>';
1453
1454 print '</table>';
1455 print '</div>';
1456 }
1457 // ===== END BLOCK: Orders =====
1458 print '</div>';
1459 }
1460 // ===== END link BLOCK =====
1461 print '</td></tr>';
1462
1463 // Bank account
1464 print '<tr class="bankswitchclass"><td class="fieldrequired">'.$langs->trans("FinancialAccount").'</td><td>';
1465 print img_picto('', 'bank_account', 'class="pictofixedwidth"');
1466 $form->select_comptes(GETPOST('accountid'), 'accountid', 0, '', 2, '', 0, 'minwidth200');
1467 print "</td></tr>\n";
1468
1469 // Payment mode
1470 print '<tr class="bankswitchclass"><td class="fieldrequired">'.$langs->trans("PaymentMode").'</td><td>';
1471 print $form->select_types_paiements(GETPOST('operation'), 'operation', '', 2, 1, 0, 0, 1, 'minwidth200', 1);
1472 print "</td></tr>\n";
1473
1474 // Date of payment
1475 print '<tr class="bankswitchclass"><td class="fieldrequired">'.$langs->trans("DatePayment").'</td><td>';
1476 print $form->selectDate(isset($paymentdate) ? $paymentdate : -1, 'payment', 0, 0, 1, 'subscription', 1, 1);
1477 print "</td></tr>\n";
1478
1479 print '<tr class="bankswitchclass2"><td>'.$langs->trans('Numero');
1480 print ' <em>('.$langs->trans("ChequeOrTransferNumber").')</em>';
1481 print '</td>';
1482 print '<td><input id="fieldnum_chq" name="num_chq" type="text" size="8" value="'.(!GETPOST('num_chq') ? '' : GETPOST('num_chq')).'"></td></tr>';
1483
1484 print '<tr class="bankswitchclass2 fieldrequireddyn"><td>'.$langs->trans('CheckTransmitter');
1485 print ' <em>('.$langs->trans("ChequeMaker").')</em>';
1486 print '</td>';
1487 print '<td><input id="fieldchqemetteur" name="chqemetteur" size="32" type="text" value="'.(!GETPOST('chqemetteur') ? '' : GETPOST('chqemetteur')).'"></td></tr>';
1488
1489 print '<tr class="bankswitchclass2"><td>'.$langs->trans('Bank');
1490 print ' <em>('.$langs->trans("ChequeBank").')</em>';
1491 print '</td>';
1492 print '<td><input id="chqbank" name="chqbank" size="32" type="text" value="'.(!GETPOST('chqbank') ? '' : GETPOST('chqbank')).'"></td></tr>';
1493 }
1494 }
1495
1496 print '<tr><td></td><td></td></tr>';
1497
1498 print '<tr><td>'.$langs->trans("SendAcknowledgementByMail").'</td>';
1499 print '<td>';
1500 if (!$object->email) {
1501 print $langs->trans("NoEMail");
1502 } else {
1503 $adht = new AdherentType($db);
1504 $adht->fetch($object->typeid);
1505
1506 // Send subscription email
1507 $subject = '';
1508 $msg = '';
1509
1510 // Send subscription email
1511 include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
1512 $formmail = new FormMail($db);
1513 // Set output language
1514 $outputlangs = new Translate('', $conf);
1515 $outputlangs->setDefaultLang(!empty($object->default_lang) ? $object->default_lang : (empty($object->thirdparty->default_lang) ? $mysoc->default_lang : $object->thirdparty->default_lang));
1516 // Load traductions files required by page
1517 $outputlangs->loadLangs(array("main", "members"));
1518 // Get email content from template
1519 $arraydefaultmessage = null;
1520 $labeltouse = getDolGlobalString('ADHERENT_EMAIL_TEMPLATE_SUBSCRIPTION');
1521
1522 if (!empty($labeltouse)) {
1523 $arraydefaultmessage = $formmail->getEMailTemplate($db, 'member', $user, $outputlangs, 0, 1, $labeltouse);
1524 }
1525
1526 if (!empty($labeltouse) && is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0) {
1527 $subject = (string) $arraydefaultmessage->topic;
1528 $msg = (string) $arraydefaultmessage->content;
1529 }
1530
1531 $substitutionarray = getCommonSubstitutionArray($outputlangs, 0, null, $object);
1532 complete_substitutions_array($substitutionarray, $outputlangs, $object);
1533 $subjecttosend = make_substitutions($subject, $substitutionarray, $outputlangs);
1534 $texttosend = make_substitutions(dol_concatdesc($msg, $adht->getMailOnSubscription()), $substitutionarray, $outputlangs);
1535
1536 $tmp = '<input name="sendmail" type="checkbox"'.(GETPOST('sendmail', 'alpha') ? ' checked' : (getDolGlobalString('ADHERENT_DEFAULT_SENDINFOBYMAIL') ? ' checked' : '')).'>';
1537 $helpcontent = '';
1538 $helpcontent .= '<b>'.$langs->trans("MailFrom").'</b>: '.getDolGlobalString('ADHERENT_MAIL_FROM', $conf->email_from).'<br>'."\n";
1539 $helpcontent .= '<b>'.$langs->trans("MailRecipient").'</b>: '.$object->email.'<br>'."\n";
1540 $helpcontent .= '<b>'.$langs->trans("MailTopic").'</b>:<br>'."\n";
1541 if ($subjecttosend) {
1542 $helpcontent .= $subjecttosend."\n";
1543 } else {
1544 $langs->load("errors");
1545 $helpcontent .= '<span class="error">'.$langs->trans("ErrorModuleSetupNotComplete", $langs->transnoentitiesnoconv("Module310Name")).'</span>'."\n";
1546 }
1547 $helpcontent .= "<br>";
1548 $helpcontent .= '<b>'.$langs->trans("MailText").'</b>:<br>';
1549 if ($texttosend) {
1550 $helpcontent .= dol_htmlentitiesbr($texttosend)."\n";
1551 } else {
1552 $langs->load("errors");
1553 $helpcontent .= '<span class="error">'.$langs->trans("ErrorModuleSetupNotComplete", $langs->transnoentitiesnoconv("Module310Name")).'</span>'."\n";
1554 }
1555 // @phan-suppress-next-line PhanPluginSuspiciousParamOrder
1556 print $form->textwithpicto($tmp, $helpcontent, 1, 'help', '', 0, 2, 'helpemailtosend');
1557 }
1558 print '</td></tr>';
1559 print '</tbody>';
1560 print '</table>';
1561 print '</div>';
1562
1563 print dol_get_fiche_end();
1564
1565 print '<div class="center">';
1566 $parameters = array();
1567 $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action);
1568 if (empty($reshook)) {
1569 print '<input type="submit" class="button" name="add" value="'.$langs->trans("AddSubscription").'">';
1570 print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
1571 print '<input type="submit" class="button button-cancel" name="cancel" value="'.$langs->trans("Cancel").'">';
1572 }
1573 print '</div>';
1574
1575 print '</form>';
1576
1577 print "\n<!-- End form subscription -->\n\n";
1578}
1579
1580
1581// End of page
1582llxFooter();
1583$db->close();
$id
Support class for third parties, contacts, members, users or resources.
Definition account.php:47
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:91
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:73
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
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 customers orders.
Class to manage invoices.
Class to manage generation of HTML components Only common components must be here.
Class to manage a HTML form to send a unitary email Usage: $formail = new FormMail($db) $formmail->pr...
Class to manage products or services.
Class to manage projects.
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.
global $mysoc
dol_get_first_day($year, $month=1, $gm=false)
Return GMT time for first day of a month or year.
Definition date.lib.php:626
dol_get_last_day($year, $month=12, $gm=false)
Return GMT time for last day of a month or year.
Definition date.lib.php:645
dol_time_plus_duree($time, $duration_value, $duration_unit, $ruleforendofmonth=0, $tz='')
Add a delay to a date.
Definition date.lib.php:127
dol_most_recent_file($dir, $regexfilter='', $excludefilter=array('(\.meta|_preview.*\.png) $', '^\.'), $nohook=0, $mode=0, $limit=0)
Return file(s) into a directory (by default most recent)
dol_now($mode='gmt')
Return date for now.
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...
price2num($amount, $rounding='', $option=0, $currencycode='')
Function that return a number with universal decimal format (decimal separator is '.
dol_mimetype($file, $default='application/octet-stream', $mode=0)
Return MIME type of a file from its name with extension.
dol_eval($s, $returnvalue=1, $hideerrors=1, $onlysimplestring='1')
Replace eval function to add more security.
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.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
newToken()
Return the value of token currently saved into session with name 'newtoken'.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
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...
getDolCurrency()
Return the main currency ('EUR', 'USD', ...)
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...
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_clone($srcobject, $native=2)
Create a clone of instance of object (new instance with same value for each properties) With native =...
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
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...
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
getEntity($element, $shared=1, $currentobject=null)
Get list of entity id to use.
picto_from_langcode($codelang, $moreatt='', $notitlealt=0)
Return img flag of country for a language code or country code.
print_liste_field_titre($name, $file="", $field="", $begin="", $param="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0, $morecssdiv='')
Show tabs of a record.
Definition html.lib.php:542
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Definition html.lib.php:740
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Definition html.lib.php:183
member_prepare_head(Adherent $object)
Return array head with list of tabs to view object information.
print $langs trans('Date')." left Ref Label right Qty right Price right TotalHT right TotalTTC right right right right right right right right right centpercent right TotalHT right n right VAT right n right TotalVAT right n No sujeto a RE IRPF right TotalLT1 right n right TotalLT2 right n right TotalTTC right n takeposcustomercurrency takeposcustomercurrency takeposcustomercurrency takeposcustomercurrency right TotalTTC takeposcustomercurrency right takeposcustomercurrency n right Paid right PaymentTypeShortLIQ right SELECT p pos_change as p datep as p p num_paiement as f pf amount as amount
Definition receipt.php:494
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $nodie=0, $mode='')
Check permissions of a user to show a page and an object.