dolibarr 18.0.6
card.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2007-2019 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2018-2020 Frédéric France <frederic.france@netlogic.fr>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <https://www.gnu.org/licenses/>.
17 */
18
25// Load Dolibarr environment
26require '../../main.inc.php';
27require_once DOL_DOCUMENT_ROOT.'/core/lib/member.lib.php';
28require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
29require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent_type.class.php';
30require_once DOL_DOCUMENT_ROOT.'/adherents/class/subscription.class.php';
31if (isModEnabled("banque")) {
32 require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
33}
34
35// Load translation files required by the page
36$langs->loadLangs(array("companies", "members", "bills", "users"));
37
38$adh = new Adherent($db);
39$adht = new AdherentType($db);
40$object = new Subscription($db);
41$errmsg = '';
42
43$action = GETPOST("action", 'alpha');
44$rowid = GETPOST("rowid", "int") ? GETPOST("rowid", "int") : GETPOST("id", "int");
45$typeid = GETPOST("typeid", "int");
46$cancel = GETPOST('cancel', 'alpha');
47$confirm = GETPOST('confirm');
48$note = GETPOST('note', 'alpha');
49$typeid = (int) GETPOST('typeid', 'int');
50$amount = price2num(GETPOST('amount', 'alpha'), 'MT');
51
52if (!$user->hasRight('adherent', 'cotisation', 'lire')) {
54}
55
56$permissionnote = $user->hasRight('adherent', 'cotisation', 'creer'); // Used by the include of actions_setnotes.inc.php
57$permissiondellink = $user->hasRight('adherent', 'cotisation', 'creer'); // Used by the include of actions_dellink.inc.php
58$permissiontoedit = $user->hasRight('adherent', 'cotisation', 'creer'); // Used by the include of actions_lineupdonw.inc.php
59
60$hookmanager->initHooks(array('subscriptioncard', 'globalcard'));
61
62// Security check
63$result = restrictedArea($user, 'subscription', 0); // TODO Check on object id
64
65
66/*
67 * Actions
68 */
69
70if ($cancel) {
71 $action = '';
72}
73
74//include DOL_DOCUMENT_ROOT.'/core/actions_setnotes.inc.php'; // Must be include, not include_once
75
76include DOL_DOCUMENT_ROOT.'/core/actions_dellink.inc.php'; // Must be include, not include_once
77
78//include DOL_DOCUMENT_ROOT.'/core/actions_lineupdown.inc.php'; // Must be include, not include_once
79
80
81if ($user->hasRight('adherent', 'cotisation', 'creer') && $action == 'update' && !$cancel) {
82 // Load current object
83 $result = $object->fetch($rowid);
84 if ($result > 0) {
85 $db->begin();
86
87 $errmsg = '';
88
89 if ($object->fk_bank) {
90 $accountline = new AccountLine($db);
91 $result = $accountline->fetch($object->fk_bank);
92
93 // If transaction consolidated
94 if ($accountline->rappro) {
95 $errmsg = $langs->trans("SubscriptionLinkedToConciliatedTransaction");
96 } else {
97 $accountline->datev = dol_mktime(GETPOST('datesubhour', 'int'), GETPOST('datesubmin', 'int'), 0, GETPOST('datesubmonth', 'int'), GETPOST('datesubday', 'int'), GETPOST('datesubyear', 'int'));
98 $accountline->dateo = dol_mktime(GETPOST('datesubhour', 'int'), GETPOST('datesubmin', 'int'), 0, GETPOST('datesubmonth', 'int'), GETPOST('datesubday', 'int'), GETPOST('datesubyear', 'int'));
99 $accountline->amount = $amount;
100 $result = $accountline->update($user);
101 if ($result < 0) {
102 $errmsg = $accountline->error;
103 }
104 }
105 }
106
107 if (!$errmsg) {
108 // Modify values
109 $object->dateh = dol_mktime(GETPOST('datesubhour', 'int'), GETPOST('datesubmin', 'int'), 0, GETPOST('datesubmonth', 'int'), GETPOST('datesubday', 'int'), GETPOST('datesubyear', 'int'));
110 $object->datef = dol_mktime(GETPOST('datesubendhour', 'int'), GETPOST('datesubendmin', 'int'), 0, GETPOST('datesubendmonth', 'int'), GETPOST('datesubendday', 'int'), GETPOST('datesubendyear', 'int'));
111 $object->fk_type = $typeid;
112 $object->note_public = $note;
113 $object->note_private = $note;
114
115 $object->amount = $amount;
116
117 $result = $object->update($user);
118 if ($result >= 0 && !count($object->errors)) {
119 $db->commit();
120
121 header("Location: card.php?rowid=".$object->id);
122 exit;
123 } else {
124 $db->rollback();
125
126 if ($object->error) {
127 $errmsg = $object->error;
128 } else {
129 foreach ($object->errors as $error) {
130 if ($errmsg) {
131 $errmsg .= '<br>';
132 }
133 $errmsg .= $error;
134 }
135 }
136 $action = '';
137 }
138 } else {
139 $db->rollback();
140 }
141 }
142}
143
144if ($action == 'confirm_delete' && $confirm == 'yes' && $user->hasRight('adherent', 'cotisation', 'creer')) {
145 $result = $object->fetch($rowid);
146 $result = $object->delete($user);
147 if ($result > 0) {
148 header("Location: ".DOL_URL_ROOT."/adherents/card.php?rowid=".$object->fk_adherent);
149 exit;
150 } else {
151 $errmesg = $adh->error;
152 }
153}
154
155
156
157/*
158 * View
159 */
160
161$form = new Form($db);
162
163$help_url = 'EN:Module_Foundations|FR:Module_Adh&eacute;rents|ES:M&oacute;dulo_Miembros|DE:Modul_Mitglieder';
164llxHeader('', $langs->trans("SubscriptionCard"), $help_url);
165
166
167dol_htmloutput_errors($errmsg);
168
169
170if ($user->hasRight('adherent', 'cotisation', 'creer') && $action == 'edit') {
171 /********************************************
172 *
173 * Subscription card in edit mode
174 *
175 ********************************************/
176
177 $object->fetch($rowid);
178 $result = $adh->fetch($object->fk_adherent);
179
180 $head = subscription_prepare_head($object);
181
182 print '<form name="update" action="'.$_SERVER["PHP_SELF"].'" method="post">';
183 print '<input type="hidden" name="token" value="'.newToken().'">';
184 print "<input type=\"hidden\" name=\"action\" value=\"update\">";
185 print "<input type=\"hidden\" name=\"rowid\" value=\"$rowid\">";
186 print "<input type=\"hidden\" name=\"fk_bank\" value=\"".$object->fk_bank."\">";
187
188 print dol_get_fiche_head($head, 'general', $langs->trans("Subscription"), 0, 'payment');
189
190 $linkback = '<a href="'.DOL_URL_ROOT.'/adherents/subscription/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
191
192 print "\n";
193 print '<table class="border centpercent">';
194
195 // Ref
196 print '<tr><td class="titlefieldcreate">'.$langs->trans("Ref").'</td>';
197 print '<td class="valeur">';
198 print $form->showrefnav($object, 'rowid', $linkback, 1);
199 print '</td></tr>';
200
201 // Member
202 $adh->ref = $adh->getFullName($langs);
203 print '<tr>';
204 print '<td>'.$langs->trans("Member").'</td>';
205 print '<td class="valeur">'.$adh->getNomUrl(-1, 0, 'subscription').'</td>';
206 print '</tr>';
207
208 // Type
209 print '<tr>';
210 print '<td>'.$langs->trans("Type").'</td>';
211 print '<td class="valeur">';
212 print $form->selectarray("typeid", $adht->liste_array(), (GETPOSTISSET("typeid") ? GETPOST("typeid") : $object->fk_type));
213 print'</td></tr>';
214
215 // Date start subscription
216 print '<tr><td>'.$langs->trans("DateSubscription").'</td>';
217 print '<td class="valeur">';
218 print $form->selectDate($object->dateh, 'datesub', 1, 1, 0, 'update', 1);
219 print '</td>';
220 print '</tr>';
221
222 // Date end subscription
223 print '<tr><td>'.$langs->trans("DateEndSubscription").'</td>';
224 print '<td class="valeur">';
225 print $form->selectDate($object->datef, 'datesubend', 0, 0, 0, 'update', 1);
226 print '</td>';
227 print '</tr>';
228
229 // Amount
230 print '<tr><td>'.$langs->trans("Amount").'</td>';
231 print '<td class="valeur">';
232 print '<input type="text" class="flat width200" name="amount" value="'.price($object->amount).'"></td></tr>';
233
234 // Label
235 print '<tr><td>'.$langs->trans("Label").'</td>';
236 print '<td class="valeur">';
237 print '<input type="text" class="flat" name="note" value="'.$object->note_private.'"></td></tr>';
238
239 // Bank line
240 if (isModEnabled("banque") && (!empty($conf->global->ADHERENT_BANK_USE) || $object->fk_bank)) {
241 print '<tr><td>'.$langs->trans("BankTransactionLine").'</td><td class="valeur">';
242 if ($object->fk_bank) {
243 $bankline = new AccountLine($db);
244 $result = $bankline->fetch($object->fk_bank);
245 print $bankline->getNomUrl(1, 0, 'showall');
246 } else {
247 print $langs->trans("NoneF");
248 }
249 print '</td></tr>';
250 }
251
252 print '</table>';
253
254 print dol_get_fiche_end();
255
256 print $form->buttonsSaveCancel();
257
258 print '</form>';
259 print "\n";
260}
261
262if ($rowid && $action != 'edit') {
263 /********************************************
264 *
265 * Subscription card in view mode
266 *
267 ********************************************/
268
269 $result = $object->fetch($rowid);
270 $result = $adh->fetch($object->fk_adherent);
271
272 $head = subscription_prepare_head($object);
273
274 print dol_get_fiche_head($head, 'general', $langs->trans("Subscription"), -1, 'payment');
275
276 // Confirmation to delete subscription
277 if ($action == 'delete') {
278 $formquestion=array();
279 //$formquestion['text']='<b>'.$langs->trans("ThisWillAlsoDeleteBankRecord").'</b>';
280 $text = $langs->trans("ConfirmDeleteSubscription");
281 if (isModEnabled("banque") && !empty($conf->global->ADHERENT_BANK_USE)) {
282 $text .= '<br>'.img_warning().' '.$langs->trans("ThisWillAlsoDeleteBankRecord");
283 }
284 print $form->formconfirm($_SERVER["PHP_SELF"]."?rowid=".$object->id, $langs->trans("DeleteSubscription"), $text, "confirm_delete", $formquestion, 0, 1);
285 }
286
287 print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
288 print '<input type="hidden" name="token" value="'.newToken().'">';
289
290 $linkback = '<a href="'.DOL_URL_ROOT.'/adherents/subscription/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
291
292 dol_banner_tab($object, 'rowid', $linkback, 1);
293
294 print '<div class="fichecenter">';
295
296 print '<div class="underbanner clearboth"></div>';
297
298 print '<table class="border centpercent tableforfield">';
299
300 // Member
301 $adh->ref = $adh->getFullName($langs);
302 print '<tr>';
303 print '<td class="titlefield">'.$langs->trans("Member").'</td><td class="valeur">'.$adh->getNomUrl(-1, 0, 'subscription').'</td>';
304 print '</tr>';
305
306 // Type
307 print '<tr>';
308 print '<td class="titlefield">'.$langs->trans("Type").'</td>';
309 print '<td class="valeur">';
310 if ($object->fk_type > 0 || $adh->typeid > 0) {
311 $typeid = ($object->fk_type > 0 ? $object->fk_type : $adh->typeid);
312 $adht->fetch($typeid);
313 print $adht->getNomUrl(1);
314 } else {
315 print $langs->trans("NoType");
316 }
317 print '</td></tr>';
318
319 // Date subscription
320 print '<tr>';
321 print '<td>'.$langs->trans("DateSubscription").'</td><td class="valeur">'.dol_print_date($object->dateh, 'day').'</td>';
322 print '</tr>';
323
324 // Date end subscription
325 print '<tr>';
326 print '<td>'.$langs->trans("DateEndSubscription").'</td><td class="valeur">'.dol_print_date($object->datef, 'day').'</td>';
327 print '</tr>';
328
329 // Amount
330 print '<tr><td>'.$langs->trans("Amount").'</td><td class="valeur"><span class="amount">'.price($object->amount).'</span></td></tr>';
331
332 // Label
333 print '<tr><td>'.$langs->trans("Label").'</td><td class="valeur sensiblehtmlcontent">'.dol_string_onlythesehtmltags(dol_htmlentitiesbr($object->note_private)).'</td></tr>';
334
335 // Bank line
336 if (isModEnabled("banque") && (!empty($conf->global->ADHERENT_BANK_USE) || $object->fk_bank)) {
337 print '<tr><td>'.$langs->trans("BankTransactionLine").'</td><td class="valeur">';
338 if ($object->fk_bank) {
339 $bankline = new AccountLine($db);
340 $result = $bankline->fetch($object->fk_bank);
341 print $bankline->getNomUrl(1, 0, 'showall');
342 } else {
343 print $langs->trans("NoneF");
344 }
345 print '</td></tr>';
346 }
347
348 print "</table>\n";
349 print '</div>';
350
351 print '</form>';
352
353 print dol_get_fiche_end();
354
355 /*
356 * Action bar
357 */
358 print '<div class="tabsAction">';
359
360 if ($user->hasRight('adherent', 'cotisation', 'creer')) {
361 if (empty($bankline->rappro) || empty($bankline)) {
362 print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"]."?rowid=".$object->id.'&action=edit&token='.newToken().'">'.$langs->trans("Modify")."</a></div>";
363 } else {
364 print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" title="'.$langs->trans("BankLineConciliated").'" href="#">'.$langs->trans("Modify")."</a></div>";
365 }
366 }
367
368 // Delete
369 if ($user->hasRight('adherent', 'cotisation', 'creer')) {
370 print '<div class="inline-block divButAction"><a class="butActionDelete" href="'.$_SERVER["PHP_SELF"]."?rowid=".$object->id.'&action=delete&token='.newToken().'">'.$langs->trans("Delete")."</a></div>\n";
371 }
372
373 print '</div>';
374
375
376 print '<div class="fichecenter"><div class="fichehalfleft">';
377 print '<a name="builddoc"></a>'; // ancre
378
379 // Generated documents
380 /*
381 $filename = dol_sanitizeFileName($object->ref);
382 $filedir = $conf->facture->dir_output . '/' . dol_sanitizeFileName($object->ref);
383 $urlsource = $_SERVER['PHP_SELF'] . '?facid=' . $object->id;
384 $genallowed = $user->hasRight('facture', 'lire');
385 $delallowed = $user->hasRight('facture', 'creer');
386
387 print $formfile->showdocuments('facture', $filename, $filedir, $urlsource, $genallowed, $delallowed, $object->model_pdf, 1, 0, 0, 28, 0, '', '', '', $soc->default_lang);
388 $somethingshown = $formfile->numoffiles;
389 */
390 // Show links to link elements
391 //$linktoelem = $form->showLinkToObjectBlock($object, null, array('subscription'));
392 $somethingshown = $form->showLinkedObjectBlock($object, '');
393
394 // Show links to link elements
395 /*$linktoelem = $form->showLinkToObjectBlock($object,array('order'));
396 if ($linktoelem) print ($somethingshown?'':'<br>').$linktoelem;
397 */
398
399 print '</div><div class="fichehalfright">';
400
401 // List of actions on element
402 /*
403 include_once DOL_DOCUMENT_ROOT . '/core/class/html.formactions.class.php';
404 $formactions = new FormActions($db);
405 $somethingshown = $formactions->showactions($object, $object->element, $socid, 1);
406 */
407
408 print '</div></div>';
409}
410
411// End of page
412llxFooter();
413$db->close();
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader()
Empty header.
Definition wrapper.php:56
llxFooter()
Empty footer.
Definition wrapper.php:70
Class to manage bank transaction lines.
Class to manage members of a foundation.
Class to manage members type.
Class to manage generation of HTML components Only common components must be here.
Class to manage subscriptions of foundation members.
dol_banner_tab($object, $paramid, $morehtml='', $shownav=1, $fieldid='rowid', $fieldref='ref', $morehtmlref='', $moreparam='', $nodbprefix=0, $morehtmlleft='', $morehtmlstatus='', $onlybanner=0, $morehtmlright='')
Show tab footer of a card.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0)
Show tabs of a record.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_string_onlythesehtmltags($stringtoclean, $cleanalsosomestyles=1, $removeclassattribute=1, $cleanalsojavascript=0, $allowiframe=0, $allowed_tags=array(), $allowlink=0)
Clean a string to keep only desirable HTML tags.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
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...
dol_htmloutput_errors($mesgstring='', $mesgarray=array(), $keepembedded=0)
Print formated error messages to output (Used to show messages on html output).
subscription_prepare_head(Subscription $object)
Return array head with list of tabs to view object informations.
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.