dolibarr 20.0.0
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("bank")) {
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", "banks"));
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 = GETPOSTINT("rowid") ? GETPOSTINT("rowid") : GETPOSTINT("id");
45$typeid = GETPOSTINT("typeid");
46$cancel = GETPOST('cancel', 'alpha');
47$confirm = GETPOST('confirm');
48$note = GETPOST('note', 'alpha');
49$typeid = GETPOSTINT('typeid');
50$amount = (float) 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 $newdatestart = dol_mktime(GETPOSTINT('datesubhour'), GETPOSTINT('datesubmin'), 0, GETPOSTINT('datesubmonth'), GETPOSTINT('datesubday'), GETPOSTINT('datesubyear'));
90 $newdateend = dol_mktime(GETPOSTINT('datesubendhour'), GETPOSTINT('datesubendmin'), 0, GETPOSTINT('datesubendmonth'), GETPOSTINT('datesubendday'), GETPOSTINT('datesubendyear'));
91
92 if ($object->fk_bank > 0) {
93 $accountline = new AccountLine($db);
94 $result = $accountline->fetch($object->fk_bank);
95
96 // If transaction consolidated
97 if ($accountline->rappro) {
98 $errmsg = $langs->trans("SubscriptionLinkedToConciliatedTransaction");
99 } else {
100 $accountline->datev = $newdatestart;
101 $accountline->dateo = $newdatestart;
102 $accountline->amount = $amount;
103
104 $result = $accountline->update($user);
105 if ($result < 0) {
106 $errmsg = $accountline->error;
107 }
108 }
109 }
110
111 if (!$errmsg) {
112 // Modify values
113 $object->dateh = $newdatestart;
114 $object->datef = $newdateend;
115 $object->fk_type = $typeid;
116 $object->note_public = $note;
117 $object->note_private = $note;
118
119 $object->amount = $amount;
120
121 $result = $object->update($user);
122 if ($result >= 0 && !count($object->errors)) {
123 $db->commit();
124
125 header("Location: card.php?rowid=".$object->id);
126 exit;
127 } else {
128 $db->rollback();
129
130 if ($object->error) {
131 $errmsg = $object->error;
132 } else {
133 foreach ($object->errors as $error) {
134 if ($errmsg) {
135 $errmsg .= '<br>';
136 }
137 $errmsg .= $error;
138 }
139 }
140 $action = '';
141 }
142 } else {
143 $db->rollback();
144 }
145 }
146}
147
148if ($action == 'confirm_delete' && $confirm == 'yes' && $user->hasRight('adherent', 'cotisation', 'creer')) {
149 $result = $object->fetch($rowid);
150 $result = $object->delete($user);
151 if ($result > 0) {
152 header("Location: ".DOL_URL_ROOT."/adherents/card.php?rowid=".$object->fk_adherent);
153 exit;
154 } else {
155 $errmesg = $adh->error;
156 }
157}
158
159
160
161/*
162 * View
163 */
164
165$form = new Form($db);
166
167$help_url = 'EN:Module_Foundations|FR:Module_Adh&eacute;rents|ES:M&oacute;dulo_Miembros|DE:Modul_Mitglieder';
168llxHeader('', $langs->trans("SubscriptionCard"), $help_url);
169
170
171dol_htmloutput_errors($errmsg);
172
173
174if ($user->hasRight('adherent', 'cotisation', 'creer') && $action == 'edit') {
175 /********************************************
176 *
177 * Subscription card in edit mode
178 *
179 ********************************************/
180
181 $object->fetch($rowid);
182 $result = $adh->fetch($object->fk_adherent);
183
185
186 print '<form name="update" action="'.$_SERVER["PHP_SELF"].'" method="post">';
187 print '<input type="hidden" name="token" value="'.newToken().'">';
188 print "<input type=\"hidden\" name=\"action\" value=\"update\">";
189 print "<input type=\"hidden\" name=\"rowid\" value=\"$rowid\">";
190 print "<input type=\"hidden\" name=\"fk_bank\" value=\"".$object->fk_bank."\">";
191
192 print dol_get_fiche_head($head, 'general', $langs->trans("Subscription"), 0, 'payment');
193
194 $linkback = '<a href="'.DOL_URL_ROOT.'/adherents/subscription/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
195
196 print "\n";
197 print '<table class="border centpercent">';
198
199 // Ref
200 print '<tr><td class="titlefieldcreate">'.$langs->trans("Ref").'</td>';
201 print '<td class="valeur">';
202 print $form->showrefnav($object, 'rowid', $linkback, 1);
203 print '</td></tr>';
204
205 // Member
206 $adh->ref = $adh->getFullName($langs);
207 print '<tr>';
208 print '<td>'.$langs->trans("Member").'</td>';
209 print '<td class="valeur">'.$adh->getNomUrl(-1, 0, 'subscription').'</td>';
210 print '</tr>';
211
212 // Type
213 print '<tr>';
214 print '<td>'.$langs->trans("Type").'</td>';
215 print '<td class="valeur">';
216 print $form->selectarray("typeid", $adht->liste_array(), (GETPOSTISSET("typeid") ? GETPOST("typeid") : $object->fk_type));
217 print'</td></tr>';
218
219 // Date start subscription
220 print '<tr><td>'.$langs->trans("DateSubscription").'</td>';
221 print '<td class="valeur">';
222 print $form->selectDate($object->dateh, 'datesub', 1, 1, 0, 'update', 1);
223 print '</td>';
224 print '</tr>';
225
226 // Date end subscription
227 print '<tr><td>'.$langs->trans("DateEndSubscription").'</td>';
228 print '<td class="valeur">';
229 print $form->selectDate($object->datef, 'datesubend', 0, 0, 0, 'update', 1);
230 print '</td>';
231 print '</tr>';
232
233 // Amount
234 print '<tr><td>'.$langs->trans("Amount").'</td>';
235 print '<td class="valeur">';
236 print '<input type="text" class="flat width200" name="amount" value="'.price($object->amount).'"></td></tr>';
237
238 // Label
239 print '<tr><td>'.$langs->trans("Label").'</td>';
240 print '<td class="valeur">';
241 print '<input type="text" class="flat" name="note" value="'.$object->note_public.'"></td></tr>';
242
243 // Bank line
244 if (isModEnabled("bank") && (getDolGlobalString('ADHERENT_BANK_USE') || $object->fk_bank)) {
245 print '<tr><td>'.$langs->trans("BankTransactionLine").'</td><td class="valeur">';
246 if ($object->fk_bank) {
247 $bankline = new AccountLine($db);
248 $result = $bankline->fetch($object->fk_bank);
249 print $bankline->getNomUrl(1, 0, 'showall');
250 } else {
251 print $langs->trans("NoneF");
252 }
253 print '</td></tr>';
254 }
255
256 print '</table>';
257
258 print dol_get_fiche_end();
259
260 print $form->buttonsSaveCancel();
261
262 print '</form>';
263 print "\n";
264}
265
266if ($rowid && $action != 'edit') {
267 /********************************************
268 *
269 * Subscription card in view mode
270 *
271 ********************************************/
272
273 $result = $object->fetch($rowid);
274 $result = $adh->fetch($object->fk_adherent);
275
277
278 print dol_get_fiche_head($head, 'general', $langs->trans("Subscription"), -1, 'payment');
279
280 // Confirmation to delete subscription
281 if ($action == 'delete') {
282 $formquestion=array();
283 //$formquestion['text']='<b>'.$langs->trans("ThisWillAlsoDeleteBankRecord").'</b>';
284 $text = $langs->trans("ConfirmDeleteSubscription");
285 if (isModEnabled("bank") && getDolGlobalString('ADHERENT_BANK_USE')) {
286 $text .= '<br>'.img_warning().' '.$langs->trans("ThisWillAlsoDeleteBankRecord");
287 }
288 print $form->formconfirm($_SERVER["PHP_SELF"]."?rowid=".$object->id, $langs->trans("DeleteSubscription"), $text, "confirm_delete", $formquestion, 0, 1);
289 }
290
291 print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
292 print '<input type="hidden" name="token" value="'.newToken().'">';
293
294 $linkback = '<a href="'.DOL_URL_ROOT.'/adherents/subscription/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
295
296 dol_banner_tab($object, 'rowid', $linkback, 1);
297
298 print '<div class="fichecenter">';
299
300 print '<div class="underbanner clearboth"></div>';
301
302 print '<table class="border centpercent tableforfield">';
303
304 // Member
305 $adh->ref = $adh->getFullName($langs);
306 print '<tr>';
307 print '<td class="titlefield">'.$langs->trans("Member").'</td><td class="valeur">'.$adh->getNomUrl(-1, 0, 'subscription').'</td>';
308 print '</tr>';
309
310 // Type
311 print '<tr>';
312 print '<td class="titlefield">'.$langs->trans("Type").'</td>';
313 print '<td class="valeur">';
314 if ($object->fk_type > 0 || $adh->typeid > 0) {
315 $typeid = ($object->fk_type > 0 ? $object->fk_type : $adh->typeid);
316 $adht->fetch($typeid);
317 print $adht->getNomUrl(1);
318 } else {
319 print $langs->trans("NoType");
320 }
321 print '</td></tr>';
322
323 // Date subscription
324 print '<tr>';
325 print '<td>'.$langs->trans("DateSubscription").'</td><td class="valeur">'.dol_print_date($object->dateh, 'day').'</td>';
326 print '</tr>';
327
328 // Date end subscription
329 print '<tr>';
330 print '<td>'.$langs->trans("DateEndSubscription").'</td><td class="valeur">'.dol_print_date($object->datef, 'day').'</td>';
331 print '</tr>';
332
333 // Amount
334 print '<tr><td>'.$langs->trans("Amount").'</td><td class="valeur"><span class="amount">'.price($object->amount).'</span></td></tr>';
335
336 // Label
337 print '<tr><td>'.$langs->trans("Label").'</td><td class="valeur sensiblehtmlcontent">'.dol_string_onlythesehtmltags(dol_htmlentitiesbr($object->note_public)).'</td></tr>';
338
339 // Bank line
340 if (isModEnabled("bank") && (getDolGlobalString('ADHERENT_BANK_USE') || $object->fk_bank)) {
341 print '<tr><td>'.$langs->trans("BankTransactionLine").'</td><td class="valeur">';
342 if ($object->fk_bank > 0) {
343 $bankline = new AccountLine($db);
344 $result = $bankline->fetch($object->fk_bank);
345 print $bankline->getNomUrl(1, 0, 'showall');
346 } else {
347 print $langs->trans("NoneF");
348 }
349 print '</td></tr>';
350 }
351
352 print "</table>\n";
353 print '</div>';
354
355 print '</form>';
356
357 print dol_get_fiche_end();
358
359 /*
360 * Action bar
361 */
362 print '<div class="tabsAction">';
363
364 if ($user->hasRight('adherent', 'cotisation', 'creer')) {
365 if (empty($bankline->rappro) || empty($bankline)) {
366 print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"]."?rowid=".((int) $object->id).'&action=edit&token='.newToken().'">'.$langs->trans("Modify")."</a></div>";
367 } else {
368 print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" title="'.$langs->trans("BankLineConciliated").'" href="#">'.$langs->trans("Modify")."</a></div>";
369 }
370 }
371
372 // Delete
373 if ($user->hasRight('adherent', 'cotisation', 'creer')) {
374 print '<div class="inline-block divButAction"><a class="butActionDelete" href="'.$_SERVER["PHP_SELF"]."?rowid=".((int) $object->id).'&action=delete&token='.newToken().'">'.$langs->trans("Delete")."</a></div>\n";
375 }
376
377 print '</div>';
378
379
380 print '<div class="fichecenter"><div class="fichehalfleft">';
381 print '<a name="builddoc"></a>'; // ancre
382
383 // Generated documents
384 /*
385 $filename = dol_sanitizeFileName($object->ref);
386 $filedir = $conf->facture->dir_output . '/' . dol_sanitizeFileName($object->ref);
387 $urlsource = $_SERVER['PHP_SELF'] . '?facid=' . $object->id;
388 $genallowed = $user->hasRight('facture', 'lire');
389 $delallowed = $user->hasRight('facture', 'creer');
390
391 print $formfile->showdocuments('facture', $filename, $filedir, $urlsource, $genallowed, $delallowed, $object->model_pdf, 1, 0, 0, 28, 0, '', '', '', $soc->default_lang);
392 $somethingshown = $formfile->numoffiles;
393 */
394 // Show links to link elements
395 //$linktoelem = $form->showLinkToObjectBlock($object, null, array('subscription'));
396 $somethingshown = $form->showLinkedObjectBlock($object, '');
397
398 // Show links to link elements
399 /*$linktoelem = $form->showLinkToObjectBlock($object,array('order'));
400 if ($linktoelem) print ($somethingshown?'':'<br>').$linktoelem;
401 */
402
403 print '</div><div class="fichehalfright">';
404
405 // List of actions on element
406 /*
407 include_once DOL_DOCUMENT_ROOT . '/core/class/html.formactions.class.php';
408 $formactions = new FormActions($db);
409 $somethingshown = $formactions->showactions($object, $object->element, $socid, 1, '', $MAXEVENT);
410 */
411
412 print '</div></div>';
413}
414
415// End of page
416llxFooter();
417$db->close();
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:58
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader()
Empty header.
Definition wrapper.php:55
llxFooter()
Empty footer.
Definition wrapper.php:69
Class to manage bank 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_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...
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
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_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.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
newToken()
Return the value of token currently saved into session with name 'newtoken'.
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...
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
dol_htmloutput_errors($mesgstring='', $mesgarray=array(), $keepembedded=0)
Print formatted 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 information.
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.