dolibarr  7.0.0-beta
card.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2007-2012 Laurent Destailleur <eldy@users.sourceforge.net>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
24 require '../../main.inc.php';
25 require_once DOL_DOCUMENT_ROOT.'/core/lib/member.lib.php';
26 require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
27 require_once DOL_DOCUMENT_ROOT.'/adherents/class/subscription.class.php';
28 if (! empty($conf->banque->enabled)) {
29  require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
30 }
31 
32 $langs->load("companies");
33 $langs->load("bills");
34 $langs->load("members");
35 $langs->load("users");
36 
37 $adh = new Adherent($db);
38 $object = new Subscription($db);
39 $errmsg='';
40 
41 $action=GETPOST("action",'alpha');
42 $rowid=GETPOST("rowid","int")?GETPOST("rowid","int"):GETPOST("id","int");
43 $typeid=GETPOST("typeid","int");
44 $cancel=GETPOST('cancel','alpha');
45 $confirm=GETPOST('confirm');
46 
47 if (! $user->rights->adherent->cotisation->lire)
49 
50 $permissionnote = $user->rights->adherent->cotisation->creer; // Used by the include of actions_setnotes.inc.php
51 $permissiondellink=$user->rights->adherent->cotisation->creer; // Used by the include of actions_dellink.inc.php
52 $permissiontoedit = $user->rights->adherent->cotisation->creer; // Used by the include of actions_lineupdonw.inc.php
53 
54 
55 /*
56  * Actions
57  */
58 
59 if ($cancel) $action='';
60 
61 //include DOL_DOCUMENT_ROOT.'/core/actions_setnotes.inc.php'; // Must be include, not include_once
62 
63 include DOL_DOCUMENT_ROOT.'/core/actions_dellink.inc.php'; // Must be include, not include_once
64 
65 //include DOL_DOCUMENT_ROOT.'/core/actions_lineupdown.inc.php'; // Must be include, not include_once
66 
67 
68 if ($user->rights->adherent->cotisation->creer && $action == 'update' && ! $cancel)
69 {
70  // Charge objet actuel
71  $result=$object->fetch($rowid);
72  if ($result > 0)
73  {
74  $db->begin();
75 
76  $errmsg='';
77 
78  if ($object->fk_bank)
79  {
80  $accountline=new AccountLine($db);
81  $result=$accountline->fetch($object->fk_bank);
82 
83  // If transaction consolidated
84  if ($accountline->rappro)
85  {
86  $errmsg=$langs->trans("SubscriptionLinkedToConciliatedTransaction");
87  }
88  else
89  {
90  $accountline->datev=dol_mktime($_POST['datesubhour'], $_POST['datesubmin'], 0, $_POST['datesubmonth'], $_POST['datesubday'], $_POST['datesubyear']);
91  $accountline->dateo=dol_mktime($_POST['datesubhour'], $_POST['datesubmin'], 0, $_POST['datesubmonth'], $_POST['datesubday'], $_POST['datesubyear']);
92  $accountline->amount=$_POST["amount"];
93  $result=$accountline->update($user);
94  if ($result < 0)
95  {
96  $errmsg=$accountline->error;
97  }
98  }
99  }
100 
101  if (! $errmsg)
102  {
103  // Modifie valeures
104  $object->dateh=dol_mktime($_POST['datesubhour'], $_POST['datesubmin'], 0, $_POST['datesubmonth'], $_POST['datesubday'], $_POST['datesubyear']);
105  $object->datef=dol_mktime($_POST['datesubendhour'], $_POST['datesubendmin'], 0, $_POST['datesubendmonth'], $_POST['datesubendday'], $_POST['datesubendyear']);
106  $object->note=$_POST["note"];
107  $object->amount=$_POST["amount"];
108  //print 'datef='.$object->datef.' '.$_POST['datesubendday'];
109 
110  $result=$object->update($user);
111  if ($result >= 0 && ! count($object->errors))
112  {
113  $db->commit();
114 
115  header("Location: card.php?rowid=".$object->id);
116  exit;
117  }
118  else
119  {
120  $db->rollback();
121 
122  if ($object->error)
123  {
124  $errmsg=$object->error;
125  }
126  else
127  {
128  foreach($object->errors as $error)
129  {
130  if ($errmsg) $errmsg.='<br>';
131  $errmsg.=$error;
132  }
133  }
134  $action='';
135  }
136  }
137  else
138  {
139  $db->rollback();
140  }
141  }
142 }
143 
144 if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->adherent->cotisation->creer)
145 {
146  $result=$object->fetch($rowid);
147  $result=$object->delete($user);
148  if ($result > 0)
149  {
150  header("Location: ".DOL_URL_ROOT."/adherents/card.php?rowid=".$object->fk_adherent);
151  exit;
152  }
153  else
154  {
155  $mesg=$adh->error;
156  }
157 }
158 
159 
160 
161 /*
162  * View
163  */
164 
165 $form = new Form($db);
166 
167 
168 llxHeader('',$langs->trans("SubscriptionCard"),'EN:Module_Foundations|FR:Module_Adh&eacute;rents|ES:M&oacute;dulo_Miembros');
169 
170 
171 dol_htmloutput_errors($errmsg);
172 
173 
174 if ($user->rights->adherent->cotisation->creer && $action == 'edit')
175 {
176  /********************************************
177  *
178  * Subscription card in edit mode
179  *
180  ********************************************/
181 
182  $object->fetch($rowid);
183  $result=$adh->fetch($object->fk_adherent);
184 
185  $head = subscription_prepare_head($object);
186 
187  print '<form name="update" action="'.$_SERVER["PHP_SELF"].'" method="post">';
188  print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
189  print "<input type=\"hidden\" name=\"action\" value=\"update\">";
190  print "<input type=\"hidden\" name=\"rowid\" value=\"$rowid\">";
191  print "<input type=\"hidden\" name=\"fk_bank\" value=\"".$object->fk_bank."\">";
192 
193  dol_fiche_head($head, 'general', $langs->trans("Subscription"), 0, 'payment');
194 
195  $linkback = '<a href="'.DOL_URL_ROOT.'/adherents/subscription/list.php">'.$langs->trans("BackToList").'</a>';
196 
197  print "\n";
198  print '<table class="border" width="100%">';
199 
200  // Ref
201  print '<tr><td class="titlefieldcreate">'.$langs->trans("Ref").'</td>';
202  print '<td class="valeur" colspan="3">';
203  print $form->showrefnav($object, 'rowid', $linkback, 1);
204  print '</td></tr>';
205 
206  // Member
207  $adh->ref=$adh->getFullName($langs);
208  print '<tr>';
209  print '<td>'.$langs->trans("Member").'</td><td class="valeur" colspan="3">'.$adh->getNomUrl(1,0,'subscription').'</td>';
210  print '</tr>';
211 
212  // Date start subscription
213  print '<tr><td>'.$langs->trans("DateSubscription").'</td><td class="valeur" colspan="2">';
214  $form->select_date($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  $form->select_date($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))
234  {
235  if ($conf->global->ADHERENT_BANK_USE || $object->fk_bank)
236  {
237  print '<tr><td>'.$langs->trans("BankTransactionLine").'</td><td class="valeur" colspan="2">';
238  if ($object->fk_bank)
239  {
240  $bankline=new AccountLine($db);
241  $result=$bankline->fetch($object->fk_bank);
242  print $bankline->getNomUrl(1,0,'showall');
243  }
244  else
245  {
246  print $langs->trans("NoneF");
247  }
248  print '</td></tr>';
249  }
250  }
251 
252  print '</table>';
253 
254  dol_fiche_end();
255 
256  print '<div class="center">';
257  print '<input type="submit" class="button" name="submit" value="'.$langs->trans("Save").'">';
258  print ' &nbsp; &nbsp; &nbsp; ';
259  print '<input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'">';
260  print '</div>';
261 
262  print '</form>';
263  print "\n";
264 }
265 
266 if ($rowid && $action != 'edit')
267 {
268  /********************************************
269  *
270  * Subscription card in view mode
271  *
272  ********************************************/
273 
274  $result=$object->fetch($rowid);
275  $result=$adh->fetch($object->fk_adherent);
276 
277  $head = subscription_prepare_head($object);
278 
279  dol_fiche_head($head, 'general', $langs->trans("Subscription"), -1, 'payment');
280 
281  // Confirmation to delete subscription
282  if ($action == 'delete')
283  {
284  //$formquestion=array();
285  //$formquestion['text']='<b>'.$langs->trans("ThisWillAlsoDeleteBankRecord").'</b>';
286  $text=$langs->trans("ConfirmDeleteSubscription");
287  if (! empty($conf->banque->enabled) && ! empty($conf->global->ADHERENT_BANK_USE)) $text.='<br>'.img_warning().' '.$langs->trans("ThisWillAlsoDeleteBankRecord");
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="'.$_SESSION['newtoken'].'">';
293 
294  $linkback = '<a href="'.DOL_URL_ROOT.'/adherents/subscription/list.php">'.$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" width="100%">';
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  // Date record
311  /*print '<tr>';
312  print '<td>'.$langs->trans("DateSubscription").'</td><td class="valeur">'.dol_print_date($object->datec,'dayhour').'</td>';
313  print '</tr>';*/
314 
315  // Date subscription
316  print '<tr>';
317  print '<td>'.$langs->trans("DateSubscription").'</td><td class="valeur">'.dol_print_date($object->dateh,'day').'</td>';
318  print '</tr>';
319 
320  // Date end subscription
321  print '<tr>';
322  print '<td>'.$langs->trans("DateEndSubscription").'</td><td class="valeur">'.dol_print_date($object->datef,'day').'</td>';
323  print '</tr>';
324 
325  // Amount
326  print '<tr><td>'.$langs->trans("Amount").'</td><td class="valeur">'.price($object->amount).'</td></tr>';
327 
328  // Amount
329  print '<tr><td>'.$langs->trans("Label").'</td><td class="valeur">'.$object->note.'</td></tr>';
330 
331  // Bank line
332  if (! empty($conf->banque->enabled))
333  {
334  if ($conf->global->ADHERENT_BANK_USE || $object->fk_bank)
335  {
336  print '<tr><td>'.$langs->trans("BankTransactionLine").'</td><td class="valeur">';
337  if ($object->fk_bank)
338  {
339  $bankline=new AccountLine($db);
340  $result=$bankline->fetch($object->fk_bank);
341  print $bankline->getNomUrl(1,0,'showall');
342  }
343  else
344  {
345  print $langs->trans("NoneF");
346  }
347  print '</td></tr>';
348  }
349  }
350 
351  print "</table>\n";
352  print '</div>';
353 
354  print '</form>';
355 
356  dol_fiche_end();
357 
358  /*
359  * Barre d'actions
360  *
361  */
362  print '<div class="tabsAction">';
363 
364  if ($user->rights->adherent->cotisation->creer)
365  {
366  if (! $bankline->rappro)
367  {
368  print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"]."?rowid=".$object->id."&action=edit\">".$langs->trans("Modify")."</a></div>";
369  }
370  else
371  {
372  print '<div class="inline-block divButAction"><a class="butActionRefused" title="'.$langs->trans("BankLineConciliated")."\" href=\"#\">".$langs->trans("Modify")."</a></div>";
373  }
374  }
375 
376  // Supprimer
377  if ($user->rights->adherent->cotisation->creer)
378  {
379  print '<div class="inline-block divButAction"><a class="butActionDelete" href="'.$_SERVER["PHP_SELF"]."?rowid=".$object->id."&action=delete\">".$langs->trans("Delete")."</a></div>\n";
380  }
381 
382  print '</div>';
383 
384 
385  print '<div class="fichecenter"><div class="fichehalfleft">';
386  print '<a name="builddoc"></a>'; // ancre
387 
388  // Documents generes
389  /*
390  $filename = dol_sanitizeFileName($object->ref);
391  $filedir = $conf->facture->dir_output . '/' . dol_sanitizeFileName($object->ref);
392  $urlsource = $_SERVER['PHP_SELF'] . '?facid=' . $object->id;
393  $genallowed = $user->rights->facture->lire;
394  $delallowed = $user->rights->facture->creer;
395 
396  print $formfile->showdocuments('facture', $filename, $filedir, $urlsource, $genallowed, $delallowed, $object->modelpdf, 1, 0, 0, 28, 0, '', '', '', $soc->default_lang);
397  $somethingshown = $formfile->numoffiles;
398  */
399  // Show links to link elements
400  //$linktoelem = $form->showLinkToObjectBlock($object, null, array('subscription'));
401  $somethingshown = $form->showLinkedObjectBlock($object, '');
402 
403  // Show links to link elements
404  /*$linktoelem = $form->showLinkToObjectBlock($object,array('order'));
405  if ($linktoelem) print ($somethingshown?'':'<br>').$linktoelem;
406  */
407 
408  print '</div><div class="fichehalfright"><div class="ficheaddleft">';
409 
410  // List of actions on element
411  /*
412  include_once DOL_DOCUMENT_ROOT . '/core/class/html.formactions.class.php';
413  $formactions = new FormActions($db);
414  $somethingshown = $formactions->showactions($object, 'invoice', $socid, 1);
415  */
416 
417  print '</div></div></div>';
418 }
419 
420 
421 llxFooter();
422 
423 $db->close();
llxFooter()
Empty footer.
Definition: wrapper.php:58
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_fiche_head($links=array(), $active='0', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='')
Show tab header 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.
Class to manage bank transaction lines.
if(empty($reshook)) $form
View.
Definition: perms.php:103
dol_htmloutput_errors($mesgstring='', $mesgarray='', $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.
Definition: member.lib.php:260
GETPOST($paramname, $check='none', $method=0, $filter=NULL, $options=NULL, $noreplace=0)
Return value of a param into GET or POST supervariable.
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:46
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).
print
Draft customers invoices.
Definition: index.php:91