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