dolibarr  16.0.5
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 require '../../main.inc.php';
26 require_once DOL_DOCUMENT_ROOT.'/core/lib/member.lib.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 if (!empty($conf->banque->enabled)) {
31  require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
32 }
33 
34 // Load translation files required by the page
35 $langs->loadLangs(array("companies", "members", "bills", "users"));
36 
37 $adh = new Adherent($db);
38 $adht = new AdherentType($db);
39 $object = new Subscription($db);
40 $errmsg = '';
41 
42 $action = GETPOST("action", 'alpha');
43 $rowid = GETPOST("rowid", "int") ? GETPOST("rowid", "int") : GETPOST("id", "int");
44 $typeid = GETPOST("typeid", "int");
45 $cancel = GETPOST('cancel', 'alpha');
46 $confirm = GETPOST('confirm');
47 $note = GETPOST('note', 'alpha');
48 $typeid = (int) GETPOST('typeid', 'int');
49 $amount = price2num(GETPOST('amount', 'alpha'), 'MT');
50 
51 if (empty($user->rights->adherent->cotisation->lire)) {
53 }
54 
55 $permissionnote = $user->rights->adherent->cotisation->creer; // Used by the include of actions_setnotes.inc.php
56 $permissiondellink = $user->rights->adherent->cotisation->creer; // Used by the include of actions_dellink.inc.php
57 $permissiontoedit = $user->rights->adherent->cotisation->creer; // Used by the include of actions_lineupdonw.inc.php
58 
59 $hookmanager->initHooks(array('subscriptioncard', 'globalcard'));
60 
61 // Security check
62 $result = restrictedArea($user, 'subscription', 0); // TODO Check on object id
63 
64 
65 /*
66  * Actions
67  */
68 
69 if ($cancel) {
70  $action = '';
71 }
72 
73 //include DOL_DOCUMENT_ROOT.'/core/actions_setnotes.inc.php'; // Must be include, not include_once
74 
75 include DOL_DOCUMENT_ROOT.'/core/actions_dellink.inc.php'; // Must be include, not include_once
76 
77 //include DOL_DOCUMENT_ROOT.'/core/actions_lineupdown.inc.php'; // Must be include, not include_once
78 
79 
80 if ($user->rights->adherent->cotisation->creer && $action == 'update' && !$cancel) {
81  // Load current object
82  $result = $object->fetch($rowid);
83  if ($result > 0) {
84  $db->begin();
85 
86  $errmsg = '';
87 
88  if ($object->fk_bank) {
89  $accountline = new AccountLine($db);
90  $result = $accountline->fetch($object->fk_bank);
91 
92  // If transaction consolidated
93  if ($accountline->rappro) {
94  $errmsg = $langs->trans("SubscriptionLinkedToConciliatedTransaction");
95  } else {
96  $accountline->datev = dol_mktime(GETPOST('datesubhour', 'int'), GETPOST('datesubmin', 'int'), 0, GETPOST('datesubmonth', 'int'), GETPOST('datesubday', 'int'), GETPOST('datesubyear', 'int'));
97  $accountline->dateo = dol_mktime(GETPOST('datesubhour', 'int'), GETPOST('datesubmin', 'int'), 0, GETPOST('datesubmonth', 'int'), GETPOST('datesubday', 'int'), GETPOST('datesubyear', 'int'));
98  $accountline->amount = $amount;
99  $result = $accountline->update($user);
100  if ($result < 0) {
101  $errmsg = $accountline->error;
102  }
103  }
104  }
105 
106  if (!$errmsg) {
107  // Modify values
108  $object->dateh = dol_mktime(GETPOST('datesubhour', 'int'), GETPOST('datesubmin', 'int'), 0, GETPOST('datesubmonth', 'int'), GETPOST('datesubday', 'int'), GETPOST('datesubyear', 'int'));
109  $object->datef = dol_mktime(GETPOST('datesubendhour', 'int'), GETPOST('datesubendmin', 'int'), 0, GETPOST('datesubendmonth', 'int'), GETPOST('datesubendday', 'int'), GETPOST('datesubendyear', 'int'));
110  $object->fk_type = $typeid;
111  $object->note_public = $note;
112  $object->note_private = $note;
113 
114  $object->amount = $amount;
115 
116  $result = $object->update($user);
117  if ($result >= 0 && !count($object->errors)) {
118  $db->commit();
119 
120  header("Location: card.php?rowid=".$object->id);
121  exit;
122  } else {
123  $db->rollback();
124 
125  if ($object->error) {
126  $errmsg = $object->error;
127  } else {
128  foreach ($object->errors as $error) {
129  if ($errmsg) {
130  $errmsg .= '<br>';
131  }
132  $errmsg .= $error;
133  }
134  }
135  $action = '';
136  }
137  } else {
138  $db->rollback();
139  }
140  }
141 }
142 
143 if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->adherent->cotisation->creer) {
144  $result = $object->fetch($rowid);
145  $result = $object->delete($user);
146  if ($result > 0) {
147  header("Location: ".DOL_URL_ROOT."/adherents/card.php?rowid=".$object->fk_adherent);
148  exit;
149  } else {
150  $mesg = $adh->error;
151  }
152 }
153 
154 
155 
156 /*
157  * View
158  */
159 
160 $form = new Form($db);
161 
162 $help_url = 'EN:Module_Foundations|FR:Module_Adh&eacute;rents|ES:M&oacute;dulo_Miembros';
163 llxHeader('', $langs->trans("SubscriptionCard"), $help_url);
164 
165 
166 dol_htmloutput_errors($errmsg);
167 
168 
169 if ($user->rights->adherent->cotisation->creer && $action == 'edit') {
170  /********************************************
171  *
172  * Subscription card in edit mode
173  *
174  ********************************************/
175 
176  $object->fetch($rowid);
177  $result = $adh->fetch($object->fk_adherent);
178 
179  $head = subscription_prepare_head($object);
180 
181  print '<form name="update" action="'.$_SERVER["PHP_SELF"].'" method="post">';
182  print '<input type="hidden" name="token" value="'.newToken().'">';
183  print "<input type=\"hidden\" name=\"action\" value=\"update\">";
184  print "<input type=\"hidden\" name=\"rowid\" value=\"$rowid\">";
185  print "<input type=\"hidden\" name=\"fk_bank\" value=\"".$object->fk_bank."\">";
186 
187  print dol_get_fiche_head($head, 'general', $langs->trans("Subscription"), 0, 'payment');
188 
189  $linkback = '<a href="'.DOL_URL_ROOT.'/adherents/subscription/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
190 
191  print "\n";
192  print '<table class="border centpercent">';
193 
194  // Ref
195  print '<tr><td class="titlefieldcreate">'.$langs->trans("Ref").'</td>';
196  print '<td class="valeur" colspan="3">';
197  print $form->showrefnav($object, 'rowid', $linkback, 1);
198  print '</td></tr>';
199 
200  // Member
201  $adh->ref = $adh->getFullName($langs);
202  print '<tr>';
203  print '<td>'.$langs->trans("Member").'</td><td class="valeur" colspan="3">'.$adh->getNomUrl(1, 0, 'subscription').'</td>';
204  print '</tr>';
205 
206  // Type
207  print '<tr>';
208  print '<td>'.$langs->trans("Type").'</td><td class="valeur" colspan="3">';
209  print $form->selectarray("typeid", $adht->liste_array(), (GETPOSTISSET("typeid") ? GETPOST("typeid") : $object->fk_type));
210  print'</td></tr>';
211 
212  // Date start subscription
213  print '<tr><td>'.$langs->trans("DateSubscription").'</td><td class="valeur" colspan="2">';
214  print $form->selectDate($object->dateh, 'datesub', 1, 1, 0, 'update', 1);
215  print '</td>';
216  print '</tr>';
217 
218  // Date end subscription
219  print '<tr><td>'.$langs->trans("DateEndSubscription").'</td><td class="valeur" colspan="2">';
220  print $form->selectDate($object->datef, 'datesubend', 0, 0, 0, 'update', 1);
221  print '</td>';
222  print '</tr>';
223 
224  // Amount
225  print '<tr><td>'.$langs->trans("Amount").'</td><td class="valeur" colspan="2">';
226  print '<input type="text" class="flat" size="10" name="amount" value="'.price($object->amount).'"></td></tr>';
227 
228  // Label
229  print '<tr><td>'.$langs->trans("Label").'</td><td class="valeur" colspan="2">';
230  print '<input type="text" class="flat" size="60" name="note" value="'.$object->note.'"></td></tr>';
231 
232  // Bank line
233  if (!empty($conf->banque->enabled) && ($conf->global->ADHERENT_BANK_USE || $object->fk_bank)) {
234  print '<tr><td>'.$langs->trans("BankTransactionLine").'</td><td class="valeur" colspan="2">';
235  if ($object->fk_bank) {
236  $bankline = new AccountLine($db);
237  $result = $bankline->fetch($object->fk_bank);
238  print $bankline->getNomUrl(1, 0, 'showall');
239  } else {
240  print $langs->trans("NoneF");
241  }
242  print '</td></tr>';
243  }
244 
245  print '</table>';
246 
247  print dol_get_fiche_end();
248 
249  print $form->buttonsSaveCancel();
250 
251  print '</form>';
252  print "\n";
253 }
254 
255 if ($rowid && $action != 'edit') {
256  /********************************************
257  *
258  * Subscription card in view mode
259  *
260  ********************************************/
261 
262  $result = $object->fetch($rowid);
263  $result = $adh->fetch($object->fk_adherent);
264 
265  $head = subscription_prepare_head($object);
266 
267  print dol_get_fiche_head($head, 'general', $langs->trans("Subscription"), -1, 'payment');
268 
269  // Confirmation to delete subscription
270  if ($action == 'delete') {
271  //$formquestion=array();
272  //$formquestion['text']='<b>'.$langs->trans("ThisWillAlsoDeleteBankRecord").'</b>';
273  $text = $langs->trans("ConfirmDeleteSubscription");
274  if (!empty($conf->banque->enabled) && !empty($conf->global->ADHERENT_BANK_USE)) {
275  $text .= '<br>'.img_warning().' '.$langs->trans("ThisWillAlsoDeleteBankRecord");
276  }
277  print $form->formconfirm($_SERVER["PHP_SELF"]."?rowid=".$object->id, $langs->trans("DeleteSubscription"), $text, "confirm_delete", $formquestion, 0, 1);
278  }
279 
280  print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
281  print '<input type="hidden" name="token" value="'.newToken().'">';
282 
283  $linkback = '<a href="'.DOL_URL_ROOT.'/adherents/subscription/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
284 
285  dol_banner_tab($object, 'rowid', $linkback, 1);
286 
287  print '<div class="fichecenter">';
288 
289  print '<div class="underbanner clearboth"></div>';
290 
291  print '<table class="border centpercent">';
292 
293  // Member
294  $adh->ref = $adh->getFullName($langs);
295  print '<tr>';
296  print '<td class="titlefield">'.$langs->trans("Member").'</td><td class="valeur">'.$adh->getNomUrl(1, 0, 'subscription').'</td>';
297  print '</tr>';
298 
299  // Type
300  print '<tr>';
301  print '<td class="titlefield">'.$langs->trans("Type").'</td>';
302  print '<td class="valeur">';
303  if ($object->fk_type > 0 || $adh->typeid > 0) {
304  $typeid = ($object->fk_type > 0 ? $object->fk_type : $adh->typeid);
305  $adht->fetch($typeid);
306  print $adht->getNomUrl(1);
307  } else {
308  print $langs->trans("NoType");
309  }
310  print '</td></tr>';
311 
312  // Date subscription
313  print '<tr>';
314  print '<td>'.$langs->trans("DateSubscription").'</td><td class="valeur">'.dol_print_date($object->dateh, 'day').'</td>';
315  print '</tr>';
316 
317  // Date end subscription
318  print '<tr>';
319  print '<td>'.$langs->trans("DateEndSubscription").'</td><td class="valeur">'.dol_print_date($object->datef, 'day').'</td>';
320  print '</tr>';
321 
322  // Amount
323  print '<tr><td>'.$langs->trans("Amount").'</td><td class="valeur">'.price($object->amount).'</td></tr>';
324 
325  // Label
326  print '<tr><td>'.$langs->trans("Label").'</td><td class="valeur">'.$object->note.'</td></tr>';
327 
328  // Bank line
329  if (!empty($conf->banque->enabled) && ($conf->global->ADHERENT_BANK_USE || $object->fk_bank)) {
330  print '<tr><td>'.$langs->trans("BankTransactionLine").'</td><td class="valeur">';
331  if ($object->fk_bank) {
332  $bankline = new AccountLine($db);
333  $result = $bankline->fetch($object->fk_bank);
334  print $bankline->getNomUrl(1, 0, 'showall');
335  } else {
336  print $langs->trans("NoneF");
337  }
338  print '</td></tr>';
339  }
340 
341  print "</table>\n";
342  print '</div>';
343 
344  print '</form>';
345 
346  print dol_get_fiche_end();
347 
348  /*
349  * Action bar
350  */
351  print '<div class="tabsAction">';
352 
353  if ($user->rights->adherent->cotisation->creer) {
354  if (!$bankline->rappro) {
355  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>";
356  } else {
357  print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" title="'.$langs->trans("BankLineConciliated")."\" href=\"#\">".$langs->trans("Modify")."</a></div>";
358  }
359  }
360 
361  // Delete
362  if ($user->rights->adherent->cotisation->creer) {
363  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";
364  }
365 
366  print '</div>';
367 
368 
369  print '<div class="fichecenter"><div class="fichehalfleft">';
370  print '<a name="builddoc"></a>'; // ancre
371 
372  // Generated documents
373  /*
374  $filename = dol_sanitizeFileName($object->ref);
375  $filedir = $conf->facture->dir_output . '/' . dol_sanitizeFileName($object->ref);
376  $urlsource = $_SERVER['PHP_SELF'] . '?facid=' . $object->id;
377  $genallowed = $user->rights->facture->lire;
378  $delallowed = $user->rights->facture->creer;
379 
380  print $formfile->showdocuments('facture', $filename, $filedir, $urlsource, $genallowed, $delallowed, $object->model_pdf, 1, 0, 0, 28, 0, '', '', '', $soc->default_lang);
381  $somethingshown = $formfile->numoffiles;
382  */
383  // Show links to link elements
384  //$linktoelem = $form->showLinkToObjectBlock($object, null, array('subscription'));
385  $somethingshown = $form->showLinkedObjectBlock($object, '');
386 
387  // Show links to link elements
388  /*$linktoelem = $form->showLinkToObjectBlock($object,array('order'));
389  if ($linktoelem) print ($somethingshown?'':'<br>').$linktoelem;
390  */
391 
392  print '</div><div class="fichehalfright">';
393 
394  // List of actions on element
395  /*
396  include_once DOL_DOCUMENT_ROOT . '/core/class/html.formactions.class.php';
397  $formactions = new FormActions($db);
398  $somethingshown = $formactions->showactions($object, $object->element, $socid, 1);
399  */
400 
401  print '</div></div>';
402 }
403 
404 // End of page
405 llxFooter();
406 $db->close();
AdherentType
Class to manage members type.
Definition: adherent_type.class.php:35
restrictedArea
restrictedArea($user, $features, $objectid=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.
Definition: security.lib.php:234
llxFooter
llxFooter()
Empty footer.
Definition: wrapper.php:73
dol_htmloutput_errors
dol_htmloutput_errors($mesgstring='', $mesgarray=array(), $keepembedded=0)
Print formated error messages to output (Used to show messages on html output).
Definition: functions.lib.php:8367
GETPOST
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Definition: functions.lib.php:484
$form
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:142
dol_banner_tab
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.
Definition: functions.lib.php:2046
$help_url
if(GETPOST('button_removefilter_x', 'alpha')||GETPOST('button_removefilter.x', 'alpha')||GETPOST('button_removefilter', 'alpha')) if(GETPOST('button_search_x', 'alpha')||GETPOST('button_search.x', 'alpha')||GETPOST('button_search', 'alpha')) if($action=="save" &&empty($cancel)) $help_url
View.
Definition: agenda.php:116
price2num
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
Definition: functions.lib.php:5661
dol_print_date
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
Definition: functions.lib.php:2514
subscription_prepare_head
subscription_prepare_head(Subscription $object)
Return array head with list of tabs to view object informations.
Definition: member.lib.php:287
Subscription
Class to manage subscriptions of foundation members.
Definition: subscription.class.php:33
Adherent
Class to manage members of a foundation.
Definition: adherent.class.php:46
dol_get_fiche_head
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='')
Show tabs of a record.
Definition: functions.lib.php:1822
newToken
newToken()
Return the value of token currently saved into session with name 'newtoken'.
Definition: functions.lib.php:10878
dol_get_fiche_end
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Definition: functions.lib.php:2018
GETPOSTISSET
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
Definition: functions.lib.php:386
Form
Class to manage generation of HTML components Only common components must be here.
Definition: html.form.class.php:52
AccountLine
Class to manage bank transaction lines.
Definition: account.class.php:1779
price
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.
Definition: functions.lib.php:5541
accessforbidden
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
Definition: security.lib.php:933
dol_mktime
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...
Definition: functions.lib.php:2757
llxHeader
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOCSRFCHECK')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:59