dolibarr  9.0.0
card.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2007-2012 Laurent Destailleur <eldy@users.sourceforge.net>
3  * Copyright (C) 2018 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 <http://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/subscription.class.php';
29 if (! empty($conf->banque->enabled)) {
30  require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
31 }
32 
33 // Load translation files required by the page
34 $langs->loadLangs(array("companies","members","bills","users"));
35 
36 $adh = new Adherent($db);
37 $object = new Subscription($db);
38 $errmsg='';
39 
40 $action=GETPOST("action",'alpha');
41 $rowid=GETPOST("rowid","int")?GETPOST("rowid","int"):GETPOST("id","int");
42 $typeid=GETPOST("typeid","int");
43 $cancel=GETPOST('cancel','alpha');
44 $confirm=GETPOST('confirm');
45 
46 if (! $user->rights->adherent->cotisation->lire)
48 
49 $permissionnote = $user->rights->adherent->cotisation->creer; // Used by the include of actions_setnotes.inc.php
50 $permissiondellink=$user->rights->adherent->cotisation->creer; // Used by the include of actions_dellink.inc.php
51 $permissiontoedit = $user->rights->adherent->cotisation->creer; // Used by the include of actions_lineupdonw.inc.php
52 
53 
54 /*
55  * Actions
56  */
57 
58 if ($cancel) $action='';
59 
60 //include DOL_DOCUMENT_ROOT.'/core/actions_setnotes.inc.php'; // Must be include, not include_once
61 
62 include DOL_DOCUMENT_ROOT.'/core/actions_dellink.inc.php'; // Must be include, not include_once
63 
64 //include DOL_DOCUMENT_ROOT.'/core/actions_lineupdown.inc.php'; // Must be include, not include_once
65 
66 
67 if ($user->rights->adherent->cotisation->creer && $action == 'update' && ! $cancel)
68 {
69  // Charge objet actuel
70  $result=$object->fetch($rowid);
71  if ($result > 0)
72  {
73  $db->begin();
74 
75  $errmsg='';
76 
77  if ($object->fk_bank)
78  {
79  $accountline=new AccountLine($db);
80  $result=$accountline->fetch($object->fk_bank);
81 
82  // If transaction consolidated
83  if ($accountline->rappro)
84  {
85  $errmsg=$langs->trans("SubscriptionLinkedToConciliatedTransaction");
86  }
87  else
88  {
89  $accountline->datev=dol_mktime($_POST['datesubhour'], $_POST['datesubmin'], 0, $_POST['datesubmonth'], $_POST['datesubday'], $_POST['datesubyear']);
90  $accountline->dateo=dol_mktime($_POST['datesubhour'], $_POST['datesubmin'], 0, $_POST['datesubmonth'], $_POST['datesubday'], $_POST['datesubyear']);
91  $accountline->amount=$_POST["amount"];
92  $result=$accountline->update($user);
93  if ($result < 0)
94  {
95  $errmsg=$accountline->error;
96  }
97  }
98  }
99 
100  if (! $errmsg)
101  {
102  // Modifie valeures
103  $object->dateh=dol_mktime($_POST['datesubhour'], $_POST['datesubmin'], 0, $_POST['datesubmonth'], $_POST['datesubday'], $_POST['datesubyear']);
104  $object->datef=dol_mktime($_POST['datesubendhour'], $_POST['datesubendmin'], 0, $_POST['datesubendmonth'], $_POST['datesubendday'], $_POST['datesubendyear']);
105  $object->note=$_POST["note"];
106  $object->amount=$_POST["amount"];
107  //print 'datef='.$object->datef.' '.$_POST['datesubendday'];
108 
109  $result=$object->update($user);
110  if ($result >= 0 && ! count($object->errors))
111  {
112  $db->commit();
113 
114  header("Location: card.php?rowid=".$object->id);
115  exit;
116  }
117  else
118  {
119  $db->rollback();
120 
121  if ($object->error)
122  {
123  $errmsg=$object->error;
124  }
125  else
126  {
127  foreach($object->errors as $error)
128  {
129  if ($errmsg) $errmsg.='<br>';
130  $errmsg.=$error;
131  }
132  }
133  $action='';
134  }
135  }
136  else
137  {
138  $db->rollback();
139  }
140  }
141 }
142 
143 if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->adherent->cotisation->creer)
144 {
145  $result=$object->fetch($rowid);
146  $result=$object->delete($user);
147  if ($result > 0)
148  {
149  header("Location: ".DOL_URL_ROOT."/adherents/card.php?rowid=".$object->fk_adherent);
150  exit;
151  }
152  else
153  {
154  $mesg=$adh->error;
155  }
156 }
157 
158 
159 
160 /*
161  * View
162  */
163 
164 $form = new Form($db);
165 
166 
167 llxHeader('',$langs->trans("SubscriptionCard"),'EN:Module_Foundations|FR:Module_Adh&eacute;rents|ES:M&oacute;dulo_Miembros');
168 
169 
170 dol_htmloutput_errors($errmsg);
171 
172 
173 if ($user->rights->adherent->cotisation->creer && $action == 'edit')
174 {
175  /********************************************
176  *
177  * Subscription card in edit mode
178  *
179  ********************************************/
180 
181  $object->fetch($rowid);
182  $result=$adh->fetch($object->fk_adherent);
183 
184  $head = subscription_prepare_head($object);
185 
186  print '<form name="update" action="'.$_SERVER["PHP_SELF"].'" method="post">';
187  print '<input type="hidden" name="token" value="'.$_SESSION['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  dol_fiche_head($head, 'general', $langs->trans("Subscription"), 0, 'payment');
193 
194  $linkback = '<a href="'.DOL_URL_ROOT.'/adherents/subscription/list.php">'.$langs->trans("BackToList").'</a>';
195 
196  print "\n";
197  print '<table class="border" width="100%">';
198 
199  // Ref
200  print '<tr><td class="titlefieldcreate">'.$langs->trans("Ref").'</td>';
201  print '<td class="valeur" colspan="3">';
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><td class="valeur" colspan="3">'.$adh->getNomUrl(1,0,'subscription').'</td>';
209  print '</tr>';
210 
211  // Date start subscription
212  print '<tr><td>'.$langs->trans("DateSubscription").'</td><td class="valeur" colspan="2">';
213  print $form->selectDate($object->dateh, 'datesub', 1, 1, 0, 'update', 1);
214  print '</td>';
215  print '</tr>';
216 
217  // Date end subscription
218  print '<tr><td>'.$langs->trans("DateEndSubscription").'</td><td class="valeur" colspan="2">';
219  print $form->selectDate($object->datef, 'datesubend', 0, 0, 0, 'update', 1);
220  print '</td>';
221  print '</tr>';
222 
223  // Amount
224  print '<tr><td>'.$langs->trans("Amount").'</td><td class="valeur" colspan="2">';
225  print '<input type="text" class="flat" size="10" name="amount" value="'.price($object->amount).'"></td></tr>';
226 
227  // Label
228  print '<tr><td>'.$langs->trans("Label").'</td><td class="valeur" colspan="2">';
229  print '<input type="text" class="flat" size="60" name="note" value="'.$object->note.'"></td></tr>';
230 
231  // Bank line
232  if (! empty($conf->banque->enabled))
233  {
234  if ($conf->global->ADHERENT_BANK_USE || $object->fk_bank)
235  {
236  print '<tr><td>'.$langs->trans("BankTransactionLine").'</td><td class="valeur" colspan="2">';
237  if ($object->fk_bank)
238  {
239  $bankline=new AccountLine($db);
240  $result=$bankline->fetch($object->fk_bank);
241  print $bankline->getNomUrl(1,0,'showall');
242  }
243  else
244  {
245  print $langs->trans("NoneF");
246  }
247  print '</td></tr>';
248  }
249  }
250 
251  print '</table>';
252 
253  dol_fiche_end();
254 
255  print '<div class="center">';
256  print '<input type="submit" class="button" name="submit" value="'.$langs->trans("Save").'">';
257  print ' &nbsp; &nbsp; &nbsp; ';
258  print '<input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'">';
259  print '</div>';
260 
261  print '</form>';
262  print "\n";
263 }
264 
265 if ($rowid && $action != 'edit')
266 {
267  /********************************************
268  *
269  * Subscription card in view mode
270  *
271  ********************************************/
272 
273  $result=$object->fetch($rowid);
274  $result=$adh->fetch($object->fk_adherent);
275 
276  $head = subscription_prepare_head($object);
277 
278  dol_fiche_head($head, 'general', $langs->trans("Subscription"), -1, 'payment');
279 
280  // Confirmation to delete subscription
281  if ($action == 'delete')
282  {
283  //$formquestion=array();
284  //$formquestion['text']='<b>'.$langs->trans("ThisWillAlsoDeleteBankRecord").'</b>';
285  $text=$langs->trans("ConfirmDeleteSubscription");
286  if (! empty($conf->banque->enabled) && ! empty($conf->global->ADHERENT_BANK_USE)) $text.='<br>'.img_warning().' '.$langs->trans("ThisWillAlsoDeleteBankRecord");
287  print $form->formconfirm($_SERVER["PHP_SELF"]."?rowid=".$object->id,$langs->trans("DeleteSubscription"),$text,"confirm_delete",$formquestion,0,1);
288  }
289 
290  print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
291  print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
292 
293  $linkback = '<a href="'.DOL_URL_ROOT.'/adherents/subscription/list.php">'.$langs->trans("BackToList").'</a>';
294 
295  dol_banner_tab($object, 'rowid', $linkback, 1);
296 
297  print '<div class="fichecenter">';
298 
299  print '<div class="underbanner clearboth"></div>';
300 
301  print '<table class="border" width="100%">';
302 
303  // Member
304  $adh->ref=$adh->getFullName($langs);
305  print '<tr>';
306  print '<td class="titlefield">'.$langs->trans("Member").'</td><td class="valeur">'.$adh->getNomUrl(1,0,'subscription').'</td>';
307  print '</tr>';
308 
309  // Date record
310  /*print '<tr>';
311  print '<td>'.$langs->trans("DateSubscription").'</td><td class="valeur">'.dol_print_date($object->datec,'dayhour').'</td>';
312  print '</tr>';*/
313 
314  // Date subscription
315  print '<tr>';
316  print '<td>'.$langs->trans("DateSubscription").'</td><td class="valeur">'.dol_print_date($object->dateh,'day').'</td>';
317  print '</tr>';
318 
319  // Date end subscription
320  print '<tr>';
321  print '<td>'.$langs->trans("DateEndSubscription").'</td><td class="valeur">'.dol_print_date($object->datef,'day').'</td>';
322  print '</tr>';
323 
324  // Amount
325  print '<tr><td>'.$langs->trans("Amount").'</td><td class="valeur">'.price($object->amount).'</td></tr>';
326 
327  // Amount
328  print '<tr><td>'.$langs->trans("Label").'</td><td class="valeur">'.$object->note.'</td></tr>';
329 
330  // Bank line
331  if (! empty($conf->banque->enabled))
332  {
333  if ($conf->global->ADHERENT_BANK_USE || $object->fk_bank)
334  {
335  print '<tr><td>'.$langs->trans("BankTransactionLine").'</td><td class="valeur">';
336  if ($object->fk_bank)
337  {
338  $bankline=new AccountLine($db);
339  $result=$bankline->fetch($object->fk_bank);
340  print $bankline->getNomUrl(1,0,'showall');
341  }
342  else
343  {
344  print $langs->trans("NoneF");
345  }
346  print '</td></tr>';
347  }
348  }
349 
350  print "</table>\n";
351  print '</div>';
352 
353  print '</form>';
354 
355  dol_fiche_end();
356 
357  /*
358  * Barre d'actions
359  *
360  */
361  print '<div class="tabsAction">';
362 
363  if ($user->rights->adherent->cotisation->creer)
364  {
365  if (! $bankline->rappro)
366  {
367  print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"]."?rowid=".$object->id."&action=edit\">".$langs->trans("Modify")."</a></div>";
368  }
369  else
370  {
371  print '<div class="inline-block divButAction"><a class="butActionRefused" title="'.$langs->trans("BankLineConciliated")."\" href=\"#\">".$langs->trans("Modify")."</a></div>";
372  }
373  }
374 
375  // Supprimer
376  if ($user->rights->adherent->cotisation->creer)
377  {
378  print '<div class="inline-block divButAction"><a class="butActionDelete" href="'.$_SERVER["PHP_SELF"]."?rowid=".$object->id."&action=delete\">".$langs->trans("Delete")."</a></div>\n";
379  }
380 
381  print '</div>';
382 
383 
384  print '<div class="fichecenter"><div class="fichehalfleft">';
385  print '<a name="builddoc"></a>'; // ancre
386 
387  // Documents generes
388  /*
389  $filename = dol_sanitizeFileName($object->ref);
390  $filedir = $conf->facture->dir_output . '/' . dol_sanitizeFileName($object->ref);
391  $urlsource = $_SERVER['PHP_SELF'] . '?facid=' . $object->id;
392  $genallowed = $user->rights->facture->lire;
393  $delallowed = $user->rights->facture->creer;
394 
395  print $formfile->showdocuments('facture', $filename, $filedir, $urlsource, $genallowed, $delallowed, $object->modelpdf, 1, 0, 0, 28, 0, '', '', '', $soc->default_lang);
396  $somethingshown = $formfile->numoffiles;
397  */
398  // Show links to link elements
399  //$linktoelem = $form->showLinkToObjectBlock($object, null, array('subscription'));
400  $somethingshown = $form->showLinkedObjectBlock($object, '');
401 
402  // Show links to link elements
403  /*$linktoelem = $form->showLinkToObjectBlock($object,array('order'));
404  if ($linktoelem) print ($somethingshown?'':'<br>').$linktoelem;
405  */
406 
407  print '</div><div class="fichehalfright"><div class="ficheaddleft">';
408 
409  // List of actions on element
410  /*
411  include_once DOL_DOCUMENT_ROOT . '/core/class/html.formactions.class.php';
412  $formactions = new FormActions($db);
413  $somethingshown = $formactions->showactions($object, 'invoice', $socid, 1);
414  */
415 
416  print '</div></div></div>';
417 }
418 
419 // End of page
420 llxFooter();
421 $db->close();
llxFooter()
Empty footer.
Definition: wrapper.php:56
GETPOST($paramname, $check='none', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
print
Draft customers invoices.
Definition: index.php:91
dol_htmloutput_errors($mesgstring='', $mesgarray=array(), $keepembedded=0)
Print formated error messages to output (Used to show messages on html output).
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm=false, $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
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.
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:262
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
Class to manage generation of HTML components Only common components must be here.
dol_fiche_end($notab=0)
Show tab footer of a card.
Class to manage members of a foundation.
llxHeader()
Empty header.
Definition: wrapper.php:44
if($_POST["cancel"]==$langs->trans("Cancel") &&! $id) if($action=='add' && $_POST["cancel"]<> $langs->trans("Cancel")) if($action=='delete') if($id) $form
Actions.
Definition: card.php:153
Class to manage subscriptions of foundation members.
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='tzserver', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_fiche_head($links=array(), $active='0', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='')
Show tab header of a card.