26 require
'../../main.inc.php';
27 require_once DOL_DOCUMENT_ROOT.
'/adherents/class/adherent.class.php';
28 require_once DOL_DOCUMENT_ROOT.
'/adherents/class/adherent_type.class.php';
29 require_once DOL_DOCUMENT_ROOT.
'/adherents/class/subscription.class.php';
30 require_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/account.class.php';
32 $langs->loadLangs(array(
"members",
"companies"));
34 $action =
GETPOST(
'action',
'aZ09');
35 $massaction =
GETPOST(
'massaction',
'alpha');
36 $confirm =
GETPOST(
'confirm',
'alpha');
37 $toselect =
GETPOST(
'toselect',
'array');
38 $contextpage =
GETPOST(
'contextpage',
'aZ') ?
GETPOST(
'contextpage',
'aZ') :
'subscriptionlist';
41 $search_ref =
GETPOST(
'search_ref',
'alpha');
42 $search_type =
GETPOST(
'search_type',
'alpha');
43 $search_lastname =
GETPOST(
'search_lastname',
'alpha');
44 $search_firstname =
GETPOST(
'search_firstname',
'alpha');
45 $search_login =
GETPOST(
'search_login',
'alpha');
46 $search_note =
GETPOST(
'search_note',
'alpha');
47 $search_account =
GETPOST(
'search_account',
'int');
48 $search_amount =
GETPOST(
'search_amount',
'alpha');
49 $optioncss =
GETPOST(
'optioncss',
'alpha');
52 $date_select =
GETPOST(
"date_select",
'alpha');
54 $limit =
GETPOST(
'limit',
'int') ?
GETPOST(
'limit',
'int') : $conf->liste_limit;
55 $sortfield =
GETPOST(
'sortfield',
'aZ09comma');
56 $sortorder =
GETPOST(
'sortorder',
'aZ09comma');
58 if (empty($page) || $page == -1) {
61 $offset = $limit * $page;
62 $pageprev = $page - 1;
63 $pagenext = $page + 1;
68 $sortfield =
"c.dateadh";
74 $hookmanager->initHooks(array(
'subscriptionlist'));
78 $extrafields->fetch_name_optionals_label($object->table_element);
80 $search_array_options = $extrafields->getOptionalsFromPost($object->table_element,
'',
'search_');
83 $fieldstosearchall = array(
86 'd.ref'=>array(
'label'=>
"Ref",
'checked'=>1),
87 'd.fk_type'=>array(
'label'=>
"Type",
'checked'=>1),
88 'd.lastname'=>array(
'label'=>
"Lastname",
'checked'=>1),
89 'd.firstname'=>array(
'label'=>
"Firstname",
'checked'=>1),
90 'd.login'=>array(
'label'=>
"Login",
'checked'=>1),
91 't.libelle'=>array(
'label'=>
"Label",
'checked'=>1),
92 'd.bank'=>array(
'label'=>
"BankAccount",
'checked'=>1,
'enabled'=>(!empty($conf->banque->enabled))),
95 'c.dateadh'=>array(
'label'=>
"DateSubscription",
'checked'=>1,
'position'=>100),
96 'c.datef'=>array(
'label'=>
"EndSubscription",
'checked'=>1,
'position'=>101),
97 'd.amount'=>array(
'label'=>
"Amount",
'checked'=>1,
'position'=>102),
98 'c.datec'=>array(
'label'=>
"DateCreation",
'checked'=>0,
'position'=>500),
99 'c.tms'=>array(
'label'=>
"DateModificationShort",
'checked'=>0,
'position'=>500),
104 $result =
restrictedArea($user,
'adherent',
'',
'',
'cotisation');
111 if (
GETPOST(
'cancel',
'alpha')) {
112 $action =
'list'; $massaction =
'';
114 if (!
GETPOST(
'confirmmassaction',
'alpha') && $massaction !=
'presend' && $massaction !=
'confirm_presend') {
118 $parameters = array(
'socid'=>isset($socid) ? $socid :
null);
119 $reshook = $hookmanager->executeHooks(
'doActions', $parameters, $object, $action);
124 if (empty($reshook)) {
126 include DOL_DOCUMENT_ROOT.
'/core/actions_changeselectedfields.inc.php';
129 if (
GETPOST(
'button_removefilter_x',
'alpha') ||
GETPOST(
'button_removefilter.x',
'alpha') ||
GETPOST(
'button_removefilter',
'alpha')) {
132 $search_lastname =
"";
133 $search_firstname =
"";
137 $search_account =
"";
139 $search_array_options = array();
151 $accountstatic =
new Account($db);
156 $sql =
"SELECT d.rowid, d.login, d.firstname, d.lastname, d.societe, d.photo, d.statut,";
157 $sql .=
" d.gender, d.email, d.morphy,";
158 $sql .=
" c.rowid as crowid, c.fk_type, c.subscription,";
159 $sql .=
" c.dateadh, c.datef, c.datec as date_creation, c.tms as date_update,";
160 $sql .=
" c.fk_bank as bank, c.note,";
161 $sql .=
" b.fk_account";
162 $sql .=
" FROM ".MAIN_DB_PREFIX.
"adherent as d";
163 $sql .=
" JOIN ".MAIN_DB_PREFIX.
"subscription as c on d.rowid = c.fk_adherent";
164 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"adherent_extrafields as ef on (d.rowid = ef.fk_object)";
165 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"bank as b ON c.fk_bank=b.rowid";
166 $sql .=
" WHERE d.entity IN (".getEntity(
'adherent').
")";
167 if (isset($date_select) && $date_select !=
'') {
168 $sql .=
" AND c.dateadh >= '".((int) $date_select).
"-01-01 00:00:00'";
169 $sql .=
" AND c.dateadh < '".((int) $date_select + 1).
"-01-01 00:00:00'";
172 if (is_numeric($search_ref)) {
173 $sql .=
" AND c.rowid = ".((int) $search_ref);
175 $sql .=
" AND 1 = 2";
181 if ($search_lastname) {
182 $sql .=
natural_search(array(
'd.lastname',
'd.societe'), $search_lastname);
184 if ($search_firstname) {
193 if ($search_account > 0) {
194 $sql .=
" AND b.fk_account = ".((int) $search_account);
196 if ($search_amount) {
201 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_list_search_sql.tpl.php';
204 $parameters = array();
205 $reshook = $hookmanager->executeHooks(
'printFieldListWhere', $parameters);
206 $sql .= $hookmanager->resPrint;
208 $sql .= $db->order($sortfield, $sortorder);
211 $nbtotalofrecords =
'';
212 if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
213 $resql = $db->query($sql);
215 $nbtotalofrecords = $db->num_rows(
$resql);
219 if (($page * $limit) > $nbtotalofrecords) {
225 $sql .= $db->plimit($limit + 1, $offset);
227 $result = $db->query($sql);
233 $num = $db->num_rows($result);
235 $arrayofselected = is_array($toselect) ? $toselect : array();
237 if ($num == 1 && !empty($conf->global->MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE) && $sall) {
238 $obj = $db->fetch_object(
$resql);
240 header(
"Location: ".DOL_URL_ROOT.
'/adherents/subscription/card.php?id='.$id);
244 $help_url =
'EN:Module_Foundations|FR:Module_Adhérents|ES:Módulo_Miembros';
249 $title = $langs->trans(
"ListOfSubscriptions");
250 if (!empty($date_select)) {
251 $title .=
' ('.$langs->trans(
"Year").
' '.$date_select.
')';
255 if (!empty($contextpage) && $contextpage != $_SERVER[
"PHP_SELF"]) {
256 $param .=
'&contextpage='.urlencode($contextpage);
258 if ($limit > 0 && $limit != $conf->liste_limit) {
259 $param .=
'&limit='.urlencode($limit);
262 $param .=
"&statut=".urlencode($statut);
265 $param .=
"&search_type=".urlencode($search_type);
268 $param .=
"&date_select=".urlencode($date_select);
270 if ($search_lastname) {
271 $param .=
"&search_lastname=".urlencode($search_lastname);
274 $param .=
"&search_login=".urlencode($search_login);
276 if ($search_account) {
277 $param .=
"&search_account=".urlencode($search_account);
279 if ($search_amount) {
280 $param .=
"&search_amount=".urlencode($search_amount);
282 if ($optioncss !=
'') {
283 $param .=
'&optioncss='.urlencode($optioncss);
286 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_list_search_param.tpl.php';
289 $arrayofmassactions = array(
294 if (in_array($massaction, array(
'presend',
'predelete'))) {
295 $arrayofmassactions = array();
297 $massactionbutton =
$form->selectMassAction(
'', $arrayofmassactions);
300 if ($user->rights->adherent->cotisation->creer) {
301 $newcardbutton .=
dolGetButtonTitle($langs->trans(
'NewSubscription'),
'',
'fa fa-plus-circle', DOL_URL_ROOT.
'/adherents/list.php?status=-1,1');
304 print
'<form method="POST" id="searchFormList" action="'.$_SERVER[
"PHP_SELF"].
'">';
305 if ($optioncss !=
'') {
306 print
'<input type="hidden" name="optioncss" value="'.$optioncss.
'">';
308 print
'<input type="hidden" name="token" value="'.newToken().
'">';
309 print
'<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
310 print
'<input type="hidden" name="action" value="list">';
311 print
'<input type="hidden" name="sortfield" value="'.$sortfield.
'">';
312 print
'<input type="hidden" name="sortorder" value="'.$sortorder.
'">';
313 print
'<input type="hidden" name="contextpage" value="'.$contextpage.
'">';
314 print
'<input type="hidden" name="date_select" value="'.$date_select.
'">';
316 print_barre_liste($title, $page, $_SERVER[
"PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, $subscription->picto, 0, $newcardbutton,
'', $limit, 0, 0, 1);
318 $topicmail =
"Information";
319 $modelmail =
"subscription";
321 $trackid =
'sub'.$object->id;
322 include DOL_DOCUMENT_ROOT.
'/core/tpl/massactions_pre.tpl.php';
325 foreach ($fieldstosearchall as $key => $val) {
326 $fieldstosearchall[$key] = $langs->trans($val);
328 print
'<div class="divsearchfieldfilter">'.$langs->trans(
"FilterOnInto", $sall).join(
', ', $fieldstosearchall).
'</div>';
333 $varpage = empty($contextpage) ? $_SERVER[
"PHP_SELF"] : $contextpage;
334 $selectedfields =
$form->multiSelectArrayWithCheckbox(
'selectedfields', $arrayfields, $varpage);
335 if ($massactionbutton) {
336 $selectedfields .=
$form->showCheckAddButtons(
'checkforselect', 1);
339 print
'<div class="div-table-responsive">';
340 print
'<table class="tagtable nobottomiftotal liste'.($moreforfilter ?
" listwithfilterbefore" :
"").
'">'.
"\n";
344 print
'<tr class="liste_titre_filter">';
347 if (!empty($conf->global->MAIN_SHOW_TECHNICAL_ID)) {
348 print
'<td class="liste_titre"> </td>';
352 if (!empty($arrayfields[
'd.ref'][
'checked'])) {
353 print
'<td class="liste_titre left">';
354 print
'<input class="flat maxwidth50" type="text" name="search_ref" value="'.dol_escape_htmltag($search_ref).
'"></td>';
358 if (!empty($arrayfields[
'd.fk_type'][
'checked'])) {
359 print
'<td class="liste_titre left">';
360 print
'<input class="flat maxwidth50" type="text" name="search_type" value="'.dol_escape_htmltag($search_type).
'">';
364 if (!empty($arrayfields[
'd.lastname'][
'checked'])) {
365 print
'<td class="liste_titre left">';
366 print
'<input class="flat maxwidth75" type="text" name="search_lastname" value="'.dol_escape_htmltag($search_lastname).
'"></td>';
369 if (!empty($arrayfields[
'd.firstname'][
'checked'])) {
370 print
'<td class="liste_titre left">';
371 print
'<input class="flat maxwidth75" type="text" name="search_firstname" value="'.dol_escape_htmltag($search_firstname).
'"></td>';
374 if (!empty($arrayfields[
'd.login'][
'checked'])) {
375 print
'<td class="liste_titre left">';
376 print
'<input class="flat maxwidth75" type="text" name="search_login" value="'.dol_escape_htmltag($search_login).
'"></td>';
379 if (!empty($arrayfields[
't.libelle'][
'checked'])) {
380 print
'<td class="liste_titre">';
385 if (!empty($arrayfields[
'd.bank'][
'checked'])) {
386 print
'<td class="liste_titre">';
387 $form->select_comptes($search_account,
'search_account', 0,
'', 1,
'', 0,
'maxwidth150');
391 if (!empty($arrayfields[
'c.dateadh'][
'checked'])) {
392 print
'<td class="liste_titre"> </td>';
395 if (!empty($arrayfields[
'c.datef'][
'checked'])) {
396 print
'<td class="liste_titre"> </td>';
399 if (!empty($arrayfields[
'd.amount'][
'checked'])) {
400 print
'<td class="liste_titre right">';
401 print
'<input class="flat" type="text" name="search_amount" value="'.dol_escape_htmltag($search_amount).
'" size="4">';
405 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_list_search_input.tpl.php';
408 $parameters = array(
'arrayfields'=>$arrayfields);
409 $reshook = $hookmanager->executeHooks(
'printFieldListOption', $parameters);
410 print $hookmanager->resPrint;
412 if (!empty($arrayfields[
'c.datec'][
'checked'])) {
413 print
'<td class="liste_titre">';
417 if (!empty($arrayfields[
'c.tms'][
'checked'])) {
418 print
'<td class="liste_titre">';
423 print
'<td class="liste_titre right">';
424 $searchpicto =
$form->showFilterButtons();
431 print
'<tr class="liste_titre">';
432 if (!empty($arrayfields[
'd.ref'][
'checked'])) {
433 print_liste_field_titre($arrayfields[
'd.ref'][
'label'], $_SERVER[
"PHP_SELF"],
"c.rowid", $param,
"",
"", $sortfield, $sortorder);
435 if (!empty($arrayfields[
'd.fk_type'][
'checked'])) {
436 print_liste_field_titre($arrayfields[
'd.fk_type'][
'label'], $_SERVER[
"PHP_SELF"],
"c.fk_type", $param,
"",
"", $sortfield, $sortorder);
438 if (!empty($arrayfields[
'd.lastname'][
'checked'])) {
439 print_liste_field_titre($arrayfields[
'd.lastname'][
'label'], $_SERVER[
"PHP_SELF"],
"d.lastname", $param,
"",
"", $sortfield, $sortorder);
441 if (!empty($arrayfields[
'd.firstname'][
'checked'])) {
442 print_liste_field_titre($arrayfields[
'd.firstname'][
'label'], $_SERVER[
"PHP_SELF"],
"d.firstname", $param,
"",
"", $sortfield, $sortorder);
444 if (!empty($arrayfields[
'd.login'][
'checked'])) {
445 print_liste_field_titre($arrayfields[
'd.login'][
'label'], $_SERVER[
"PHP_SELF"],
"d.login", $param,
"",
"", $sortfield, $sortorder);
447 if (!empty($arrayfields[
't.libelle'][
'checked'])) {
448 print_liste_field_titre($arrayfields[
't.libelle'][
'label'], $_SERVER[
"PHP_SELF"],
"c.note", $param,
"",
'', $sortfield, $sortorder);
450 if (!empty($arrayfields[
'd.bank'][
'checked'])) {
451 print_liste_field_titre($arrayfields[
'd.bank'][
'label'], $_SERVER[
"PHP_SELF"],
"b.fk_account", $param,
"",
"", $sortfield, $sortorder);
453 if (!empty($arrayfields[
'c.dateadh'][
'checked'])) {
454 print_liste_field_titre($arrayfields[
'c.dateadh'][
'label'], $_SERVER[
"PHP_SELF"],
"c.dateadh", $param,
"",
'', $sortfield, $sortorder,
'center nowraponall ');
456 if (!empty($arrayfields[
'c.datef'][
'checked'])) {
457 print_liste_field_titre($arrayfields[
'c.datef'][
'label'], $_SERVER[
"PHP_SELF"],
"c.datef", $param,
"",
'', $sortfield, $sortorder,
'center nowraponall ');
459 if (!empty($arrayfields[
'd.amount'][
'checked'])) {
460 print_liste_field_titre($arrayfields[
'd.amount'][
'label'], $_SERVER[
"PHP_SELF"],
"c.subscription", $param,
"",
'', $sortfield, $sortorder,
'right ');
464 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_list_search_title.tpl.php';
467 $parameters = array(
'arrayfields'=>$arrayfields,
'param'=>$param,
'sortfield'=>$sortfield,
'sortorder'=>$sortorder);
468 $reshook = $hookmanager->executeHooks(
'printFieldListTitle', $parameters);
469 print $hookmanager->resPrint;
470 if (!empty($arrayfields[
'c.datec'][
'checked'])) {
471 print_liste_field_titre($arrayfields[
'c.datec'][
'label'], $_SERVER[
"PHP_SELF"],
"c.datec",
"", $param,
'align="center" class="nowrap"', $sortfield, $sortorder);
473 if (!empty($arrayfields[
'c.tms'][
'checked'])) {
474 print_liste_field_titre($arrayfields[
'c.tms'][
'label'], $_SERVER[
"PHP_SELF"],
"c.tms",
"", $param,
'align="center" class="nowrap"', $sortfield, $sortorder);
476 print_liste_field_titre($selectedfields, $_SERVER[
"PHP_SELF"],
'',
'',
'',
'align="center"', $sortfield, $sortorder,
'maxwidthsearch ');
480 $totalarray = array();
481 $totalarray[
'nbfield'] = 0;
482 while ($i < min($num, $limit)) {
483 $obj = $db->fetch_object($result);
485 $subscription->ref = $obj->crowid;
486 $subscription->id = $obj->crowid;
487 $subscription->dateh = $db->jdate($obj->dateadh);
488 $subscription->datef = $db->jdate($obj->datef);
490 $adherent->lastname = $obj->lastname;
491 $adherent->firstname = $obj->firstname;
492 $adherent->ref = $obj->rowid;
493 $adherent->id = $obj->rowid;
494 $adherent->statut = $obj->statut;
495 $adherent->login = $obj->login;
496 $adherent->photo = $obj->photo;
497 $adherent->gender = $obj->gender;
498 $adherent->morphy = $obj->morphy;
499 $adherent->email = $obj->email;
500 $adherent->typeid = $obj->fk_type;
501 $adherent->datefin = $db->jdate($obj->datef);
503 $typeid = ($obj->fk_type > 0 ? $obj->fk_type : $adherent->typeid);
505 $adht->fetch($typeid);
507 $adherent->need_subscription = $adht->subscription;
509 print
'<tr class="oddeven">';
512 if (!empty($arrayfields[
'd.ref'][
'checked'])) {
513 print
'<td>'.$subscription->getNomUrl(1).
'</td>';
515 $totalarray[
'nbfield']++;
519 if (!empty($arrayfields[
'd.fk_type'][
'checked'])) {
520 print
'<td class="nowraponall">';
522 print $adht->getNomUrl(1);
526 $totalarray[
'nbfield']++;
531 if (!empty($arrayfields[
'd.lastname'][
'checked'])) {
532 print
'<td class="tdoverflowmax150">'.$adherent->getNomUrl(-1, 0,
'card',
'lastname').
'</td>';
534 $totalarray[
'nbfield']++;
538 if (!empty($arrayfields[
'd.firstname'][
'checked'])) {
539 print
'<td class="tdoverflowmax150" title="'.dol_escape_htmltag($adherent->firstname).
'">'.$adherent->firstname.
'</td>';
541 $totalarray[
'nbfield']++;
546 if (!empty($arrayfields[
'd.login'][
'checked'])) {
547 print
'<td class="tdoverflowmax150" title="'.dol_escape_htmltag($adherent->login).
'">'.$adherent->login.
'</td>';
549 $totalarray[
'nbfield']++;
554 if (!empty($arrayfields[
't.libelle'][
'checked'])) {
555 print
'<td class="tdoverflowmax400" title="'.dol_escape_htmltag($obj->note).
'">';
559 $totalarray[
'nbfield']++;
564 if (!empty($arrayfields[
'd.bank'][
'checked'])) {
565 print
'<td class="tdmaxoverflow150">';
566 if ($obj->fk_account > 0) {
567 $accountstatic->id = $obj->fk_account;
568 $accountstatic->fetch($obj->fk_account);
570 print $accountstatic->getNomUrl(1);
574 $totalarray[
'nbfield']++;
579 if (!empty($arrayfields[
'c.dateadh'][
'checked'])) {
580 print
'<td class="center">'.dol_print_date($db->jdate($obj->dateadh),
'day').
"</td>\n";
582 $totalarray[
'nbfield']++;
586 if (!empty($arrayfields[
'c.datef'][
'checked'])) {
587 print
'<td class="center">'.dol_print_date($db->jdate($obj->datef),
'day').
"</td>\n";
589 $totalarray[
'nbfield']++;
593 if (!empty($arrayfields[
'd.amount'][
'checked'])) {
594 print
'<td class="right amount">'.price($obj->subscription).
'</td>';
596 $totalarray[
'nbfield']++;
599 $totalarray[
'pos'][$totalarray[
'nbfield']] =
'd.amount';
601 if (empty($totalarray[
'val'][
'd.amount'])) {
602 $totalarray[
'val'][
'd.amount'] = $obj->subscription;
604 $totalarray[
'val'][
'd.amount'] += $obj->subscription;
608 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_list_print_fields.tpl.php';
610 $parameters = array(
'arrayfields'=>$arrayfields,
'obj'=>$obj,
'i'=>$i,
'totalarray'=>&$totalarray);
611 $reshook = $hookmanager->executeHooks(
'printFieldListValue', $parameters);
612 print $hookmanager->resPrint;
614 if (!empty($arrayfields[
'c.datec'][
'checked'])) {
615 print
'<td class="nowrap center">';
616 print
dol_print_date($db->jdate($obj->date_creation),
'dayhour',
'tzuser');
619 $totalarray[
'nbfield']++;
623 if (!empty($arrayfields[
'c.tms'][
'checked'])) {
624 print
'<td class="nowrap center">';
625 print
dol_print_date($db->jdate($obj->date_update),
'dayhour',
'tzuser');
628 $totalarray[
'nbfield']++;
632 print
'<td class="center">';
633 if ($massactionbutton || $massaction) {
635 if (in_array($obj->crowid, $arrayofselected)) {
638 print
'<input id="cb'.$obj->crowid.
'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->crowid.
'"'.($selected ?
' checked="checked"' :
'').
'>';
642 $totalarray[
'nbfield']++;
650 include DOL_DOCUMENT_ROOT.
'/core/tpl/list_print_total.tpl.php';
656 foreach ($arrayfields as $key => $val) {
657 if (!empty($val[
'checked'])) {
661 print
'<tr><td colspan="'.$colspan.
'" class="opacitymedium">'.$langs->trans(
"NoRecordFound").
'</td></tr>';
666 $parameters = array(
'sql' => $sql);
667 $reshook = $hookmanager->executeHooks(
'printFieldListFooter', $parameters);
668 print $hookmanager->resPrint;