dolibarr  7.0.0-beta
card.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2001-2002 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3  * Copyright (C) 2004-2017 Laurent Destailleur <eldy@users.sourceforge.net>
4  * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@capnetworks.com>
5  * Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
6  * Copyright (C) 2015-2016 Alexandre Spangaro <aspangaro.dolibarr@gmail.com>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program. If not, see <http://www.gnu.org/licenses/>.
20  */
21 
28 require '../main.inc.php';
29 require_once DOL_DOCUMENT_ROOT.'/core/modules/dons/modules_don.php';
30 require_once DOL_DOCUMENT_ROOT.'/core/lib/donation.lib.php';
31 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
32 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
33 require_once DOL_DOCUMENT_ROOT.'/don/class/don.class.php';
34 require_once DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php';
35 require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
36 if (! empty($conf->projet->enabled))
37 {
38  require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
39  require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
40 }
41 require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
42 
43 $langs->load("companies");
44 $langs->load("donations");
45 $langs->load("bills");
46 
47 $id=GETPOST('rowid')?GETPOST('rowid','int'):GETPOST('id','int');
48 $action=GETPOST('action','alpha');
49 $cancel=GETPOST('cancel','alpha');
50 $amount=GETPOST('amount');
51 $donation_date=dol_mktime(12, 0, 0, GETPOST('remonth'), GETPOST('reday'), GETPOST('reyear'));
52 $projectid = (GETPOST('projectid') ? GETPOST('projectid', 'int') : 0);
53 
54 $object = new Don($db);
55 $extrafields = new ExtraFields($db);
56 
57 // Security check
58 $result = restrictedArea($user, 'don', $id);
59 
60 // fetch optionals attributes and labels
61 $extralabels=$extrafields->fetch_name_optionals_label($object->table_element);
62 
63 // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
64 $hookmanager->initHooks(array('doncard','globalcard'));
65 
66 /*
67  * Actions
68  */
69 
70 $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some
71 if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
72 
73 if ($action == 'update')
74 {
75  if (! empty($cancel))
76  {
77  header("Location: ".$_SERVER['PHP_SELF']."?id=".$id);
78  exit;
79  }
80 
81  $error=0;
82 
83  if (empty($donation_date))
84  {
85  setEventMessages($langs->trans("ErrorFieldRequired", $langs->trans("Date")), null, 'errors');
86  $action = "create";
87  $error++;
88  }
89 
90  if (empty($amount))
91  {
92  setEventMessages($langs->trans("ErrorFieldRequired", $langs->trans("Amount")), null, 'errors');
93  $action = "create";
94  $error++;
95  }
96 
97  if (! $error)
98  {
99  $object->fetch($id);
100 
101  $object->firstname = GETPOST("firstname");
102  $object->lastname = GETPOST("lastname");
103  $object->societe = GETPOST("societe");
104  $object->address = GETPOST("address");
105  $object->amount = price2num(GETPOST("amount"));
106  $object->town = GETPOST("town");
107  $object->zip = GETPOST("zipcode");
108  $object->country_id = GETPOST('country_id', 'int');
109  $object->email = GETPOST("email");
110  $object->date = $donation_date;
111  $object->public = GETPOST("public");
112  $object->fk_project = GETPOST("fk_project");
113  $object->note_private= GETPOST("note_private");
114  $object->note_public = GETPOST("note_public");
115 
116  // Fill array 'array_options' with data from add form
117  $ret = $extrafields->setOptionalsFromPost($extralabels,$object);
118  if ($ret < 0) $error++;
119 
120  if ($object->update($user) > 0)
121  {
122  header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
123  exit;
124  }
125  }
126 }
127 
128 if ($action == 'add')
129 {
130  if (! empty($cancel))
131  {
132  header("Location: index.php");
133  exit;
134  }
135 
136  $error=0;
137 
138  if (empty($donation_date))
139  {
140  setEventMessages($langs->trans("ErrorFieldRequired", $langs->trans("Date")), null, 'errors');
141  $action = "create";
142  $error++;
143  }
144 
145  if (empty($amount))
146  {
147  setEventMessages($langs->trans("ErrorFieldRequired", $langs->trans("Amount")), null, 'errors');
148  $action = "create";
149  $error++;
150  }
151 
152  if (! $error)
153  {
154  $object->firstname = GETPOST("firstname");
155  $object->lastname = GETPOST("lastname");
156  $object->societe = GETPOST("societe");
157  $object->address = GETPOST("address");
158  $object->amount = price2num(GETPOST("amount"));
159  $object->zip = GETPOST("zipcode");
160  $object->town = GETPOST("town");
161  $object->country_id = GETPOST('country_id', 'int');
162  $object->email = GETPOST("email");
163  $object->date = $donation_date;
164  $object->note_private= GETPOST("note_private");
165  $object->note_public = GETPOST("note_public");
166  $object->public = GETPOST("public");
167  $object->fk_project = GETPOST("fk_project");
168 
169  // Fill array 'array_options' with data from add form
170  $ret = $extrafields->setOptionalsFromPost($extralabels,$object);
171  if ($ret < 0) $error++;
172 
173  $res = $object->create($user);
174  if ($res > 0)
175  {
176  header("Location: ".$_SERVER['PHP_SELF'].'?id='.$res);
177  exit;
178  }
179  else
180  {
181  setEventMessages($object->error, $object->errors, 'errors');
182  }
183  }
184 }
185 if ($action == 'confirm_delete' && GETPOST("confirm") == "yes" && $user->rights->don->supprimer)
186 {
187  $object->fetch($id);
188  $result=$object->delete($user);
189  if ($result > 0)
190  {
191  header("Location: index.php");
192  exit;
193  }
194  else
195  {
196  dol_syslog($object->error,LOG_DEBUG);
197  setEventMessages($object->error, $object->errors, 'errors');
198  }
199 }
200 if ($action == 'valid_promesse')
201 {
202  $object->fetch($id);
203  if ($object->valid_promesse($id, $user->id) >= 0)
204  {
205  setEventMessages($langs->trans("DonationValidated", $object->ref), null);
206 
207  header("Location: ".$_SERVER['PHP_SELF']."?id=".$id);
208  exit;
209  }
210  else {
211  setEventMessages($object->error, $object->errors, 'errors');
212  }
213 }
214 if ($action == 'set_cancel')
215 {
216  $object->fetch($id);
217  if ($object->set_cancel($id) >= 0)
218  {
219  header("Location: ".$_SERVER['PHP_SELF']."?id=".$id);
220  exit;
221  }
222  else {
223  setEventMessages($object->error, $object->errors, 'errors');
224  }
225 }
226 if ($action == 'set_paid')
227 {
228  $object->fetch($id);
229  if ($object->set_paid($id, $modepayment) >= 0)
230  {
231  header("Location: ".$_SERVER['PHP_SELF']."?id=".$id);
232  exit;
233  }
234  else {
235  setEventMessages($object->error, $object->errors, 'errors');
236  }
237 }
238 else if ($action == 'classin' && $user->rights->don->creer)
239 {
240  $object->fetch($id);
241  $object->setProject($projectid);
242 }
243 // Remove file in doc form
244 if ($action == 'remove_file')
245 {
246  $object = new Don($db, 0, $_GET['id']);
247  if ($object->fetch($id))
248  {
249  require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
250 
251  $object->fetch_thirdparty();
252 
253  $langs->load("other");
254  $upload_dir = $conf->don->dir_output;
255  $file = $upload_dir . '/' . GETPOST('file');
256  $ret=dol_delete_file($file,0,0,0,$object);
257  if ($ret) setEventMessages($langs->trans("FileWasRemoved", GETPOST('urlfile')), null, 'mesgs');
258  else setEventMessages($langs->trans("ErrorFailToDeleteFile", GETPOST('urlfile')), null, 'errors');
259  $action='';
260  }
261 }
262 
263 /*
264  * Build doc
265  */
266 
267 if ($action == 'builddoc')
268 {
269  $object = new Don($db);
270  $result=$object->fetch($id);
271 
272  // Save last template used to generate document
273  if (GETPOST('model')) $object->setDocModel($user, GETPOST('model','alpha'));
274 
275  // Define output language
276  $outputlangs = $langs;
277  $newlang='';
278  if ($conf->global->MAIN_MULTILANGS && empty($newlang) && ! empty($_REQUEST['lang_id'])) $newlang=$_REQUEST['lang_id'];
279  if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->thirdparty->default_lang;
280  if (! empty($newlang))
281  {
282  $outputlangs = new Translate("",$conf);
283  $outputlangs->setDefaultLang($newlang);
284  }
285  $result=don_create($db, $object->id, '', $object->modelpdf, $outputlangs);
286  if ($result <= 0)
287  {
288  dol_print_error($db,$result);
289  exit;
290  }
291 }
292 
293 
294 /*
295  * View
296  */
297 
298 llxHeader('',$langs->trans("Donation"),'EN:Module_Donations|FR:Module_Dons|ES:M&oacute;dulo_Donaciones');
299 
300 $form=new Form($db);
301 $formfile = new FormFile($db);
302 $formcompany = new FormCompany($db);
303 if (! empty($conf->projet->enabled)) { $formproject = new FormProjets($db); }
304 
305 if ($action == 'create')
306 {
307  print load_fiche_titre($langs->trans("AddDonation"));
308 
309  print '<form name="add" action="' . $_SERVER["PHP_SELF"] . '" method="POST">';
310  print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
311  print '<input type="hidden" name="action" value="add">';
312 
313  dol_fiche_head('');
314 
315  print '<table class="border" width="100%">';
316  print '<tbody>';
317 
318  // Date
319  print '<tr><td class="fieldrequired titlefieldcreate">'.$langs->trans("Date").'</td><td>';
320  $form->select_date($donation_date?$donation_date:-1,'','','','',"add",1,1);
321  print '</td>';
322 
323  // Amount
324  print "<tr>".'<td class="fieldrequired">'.$langs->trans("Amount").'</td><td><input type="text" name="amount" value="'.dol_escape_htmltag(GETPOST("amount")).'" size="10"> '.$langs->trans("Currency".$conf->currency).'</td></tr>';
325 
326  print '<tr><td class="fieldrequired">'.$langs->trans("PublicDonation")."</td><td>";
327  print $form->selectyesno("public",isset($_POST["public"])?$_POST["public"]:1,1);
328  print "</td></tr>\n";
329 
330  print "<tr>".'<td>'.$langs->trans("Company").'</td><td><input type="text" name="societe" value="'.dol_escape_htmltag(GETPOST("societe")).'" class="maxwidth200"></td></tr>';
331  print "<tr>".'<td>'.$langs->trans("Lastname").'</td><td><input type="text" name="lastname" value="'.dol_escape_htmltag(GETPOST("lastname")).'" class="maxwidth200"></td></tr>';
332  print "<tr>".'<td>'.$langs->trans("Firstname").'</td><td><input type="text" name="firstname" value="'.dol_escape_htmltag(GETPOST("firstname")).'" class="maxwidth200"></td></tr>';
333  print "<tr>".'<td>'.$langs->trans("Address").'</td><td>';
334  print '<textarea name="address" wrap="soft" class="quatrevingtpercent" rows="3">'.dol_escape_htmltag(GETPOST("address")).'</textarea></td></tr>';
335 
336  // Zip / Town
337  print '<tr><td>'.$langs->trans("Zip").' / '.$langs->trans("Town").'</td><td>';
338  print $formcompany->select_ziptown((isset($_POST["zipcode"])?$_POST["zipcode"]:$object->zip),'zipcode',array('town','selectcountry_id','state_id'),6);
339  print ' ';
340  print $formcompany->select_ziptown((isset($_POST["town"])?$_POST["town"]:$object->town),'town',array('zipcode','selectcountry_id','state_id'));
341  print '</tr>';
342 
343  // Country
344  print '<tr><td><label for="selectcountry_id">'.$langs->trans('Country').'</label></td><td class="maxwidthonsmartphone">';
345  print $form->select_country(GETPOST('country_id')!=''?GETPOST('country_id'):$object->country_id);
346  if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
347  print '</td></tr>';
348 
349  print "<tr>".'<td>'.$langs->trans("EMail").'</td><td><input type="text" name="email" value="'.dol_escape_htmltag(GETPOST("email")).'" class="maxwidth200"></td></tr>';
350 
351  // Public note
352  print '<tr>';
353  print '<td class="tdtop">' . $langs->trans('NotePublic') . '</td>';
354  print '<td>';
355 
356  $doleditor = new DolEditor('note_public', $note_public, '', 80, 'dolibarr_notes', 'In', 0, false, true, ROWS_3, '90%');
357  print $doleditor->Create(1);
358  print '</td></tr>';
359 
360  // Private note
361  if (empty($user->societe_id)) {
362  print '<tr>';
363  print '<td class="tdtop">' . $langs->trans('NotePrivate') . '</td>';
364  print '<td>';
365 
366  $doleditor = new DolEditor('note_private', $note_private, '', 80, 'dolibarr_notes', 'In', 0, false, true, ROWS_3, '90%');
367  print $doleditor->Create(1);
368  print '</td></tr>';
369  }
370 
371  if (! empty($conf->projet->enabled))
372  {
373  print "<tr><td>".$langs->trans("Project")."</td><td>";
374  $formproject->select_projects(-1, $projectid,'fk_project', 0, 0, 1, 1);
375  print "</td></tr>\n";
376  }
377 
378  // Other attributes
379  $parameters=array();
380  $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
381  print $hookmanager->resPrint;
382  if (empty($reshook) && ! empty($extrafields->attribute_label))
383  {
384  print $object->showOptionals($extrafields,'edit',$parameters);
385  }
386 
387  print '</tbody>';
388  print "</table>\n";
389 
390  dol_fiche_end();
391 
392  print '<div class="center">';
393  print '<input type="submit" class="button" name="save" value="'.dol_escape_htmltag($langs->trans("Save")).'">';
394  print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
395  print '<input type="button" class="button" value="'.dol_escape_htmltag($langs->trans("Cancel")).'" onClick="javascript:history.go(-1)">';
396  print '</div>';
397 
398  print "</form>\n";
399 }
400 
401 
402 /* ************************************************************ */
403 /* */
404 /* Donation card in edit mode */
405 /* */
406 /* ************************************************************ */
407 
408 if (! empty($id) && $action == 'edit')
409 {
410  $result=$object->fetch($id);
411  if ($result < 0) {
412  dol_print_error($db,$object->error); exit;
413  }
414  $result=$object->fetch_optionals($object->id,$extralabels);
415  if ($result < 0) {
416  dol_print_error($db); exit;
417  }
418 
419  $hselected='card';
420  $head = donation_prepare_head($object);
421 
422  print '<form name="update" action="' . $_SERVER["PHP_SELF"] . '" method="POST">';
423  print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
424  print '<input type="hidden" name="action" value="update">';
425  print '<input type="hidden" name="rowid" value="'.$object->id.'">';
426  print '<input type="hidden" name="amount" value="'.$object->amount.'">';
427 
428 
429  dol_fiche_head($head, $hselected, $langs->trans("Donation"), 0, 'generic');
430 
431  print '<table class="border" width="100%">';
432 
433  // Ref
434  print '<tr><td>'.$langs->trans("Ref").'</td><td colspan="2">';
435  print $object->getNomUrl();
436  print '</td>';
437  print '</tr>';
438 
439  // Date
440  print '<tr><td class="titlefieldcreate fieldrequired">'.$langs->trans("Date").'</td><td>';
441  $form->select_date($object->date,'','','','',"update");
442  print '</td>';
443 
444  // Amount
445  if ($object->statut == 0)
446  {
447  print "<tr>".'<td class="fieldrequired">'.$langs->trans("Amount").'</td><td><input type="text" name="amount" size="10" value="'.dol_escape_htmltag($object->amount).'"> '.$langs->trans("Currency".$conf->currency).'</td></tr>';
448  }
449  else
450  {
451  print '<tr><td>'.$langs->trans("Amount").'</td><td>';
452  print price($object->amount,0,$langs,0,0,-1,$conf->currency);
453  print '</td></tr>';
454  }
455 
456  print '<tr><td class="fieldrequired">'.$langs->trans("PublicDonation")."</td><td>";
457  print $form->selectyesno("public",1,1);
458  print "</td>";
459  print "</tr>\n";
460 
461  $langs->load("companies");
462  print '<tr><td>'.$langs->trans("Company").'</td><td><input type="text" name="societe" class="maxwidth200" value="'.dol_escape_htmltag($object->societe).'"></td></tr>';
463  print '<tr><td>'.$langs->trans("Lastname").'</td><td><input type="text" name="lastname" class="maxwidth200" value="'.dol_escape_htmltag($object->lastname).'"></td></tr>';
464  print '<tr><td>'.$langs->trans("Firstname").'</td><td><input type="text" name="firstname" class="maxwidth200" value="'.dol_escape_htmltag($object->firstname).'"></td></tr>';
465  print '<tr><td>'.$langs->trans("Address").'</td><td>';
466  print '<textarea name="address" wrap="soft" class="quatrevingtpercent" rows="'.ROWS_3.'">'.dol_escape_htmltag($object->address).'</textarea></td></tr>';
467 
468  // Zip / Town
469  print '<tr><td>'.$langs->trans("Zip").' / '.$langs->trans("Town").'</td><td>';
470  print $formcompany->select_ziptown((isset($_POST["zipcode"])?$_POST["zipcode"]:$object->zip),'zipcode',array('town','selectcountry_id','state_id'),6);
471  print ' ';
472  print $formcompany->select_ziptown((isset($_POST["town"])?$_POST["town"]:$object->town),'town',array('zipcode','selectcountry_id','state_id'));
473  print '</tr>';
474 
475  // Country
476  print '<tr><td class="titlefieldcreate">'.$langs->trans('Country').'</td><td>';
477  print $form->select_country((!empty($object->country_id)?$object->country_id:$mysoc->country_code),'country_id');
478  if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
479  print '</td></tr>';
480 
481  print "<tr>".'<td>'.$langs->trans("EMail").'</td><td><input type="text" name="email" class="maxwidth200" value="'.dol_escape_htmltag($object->email).'"></td></tr>';
482 
483  print "<tr><td>".$langs->trans("PaymentMode")."</td><td>\n";
484 
485  if ($object->modepaymentid) $selected = $object->modepaymentid;
486  else $selected = '';
487 
488  $form->select_types_paiements($selected, 'modepayment', 'CRDT', 0, 1);
489  print "</td></tr>\n";
490 
491  print "<tr>".'<td>'.$langs->trans("Status").'</td><td>'.$object->getLibStatut(4).'</td></tr>';
492 
493  // Project
494  if (! empty($conf->projet->enabled))
495  {
496  $formproject=new FormProjets($db);
497 
498  $langs->load('projects');
499  print '<tr><td>'.$langs->trans('Project').'</td><td>';
500  $formproject->select_projects(-1, $object->fk_project,'fk_project', 0, 0, 1, 1);
501  print '</td></tr>';
502  }
503 
504  // Other attributes
505  $parameters=array();
506  $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
507  print $hookmanager->resPrint;
508  if (empty($reshook) && ! empty($extrafields->attribute_label))
509  {
510  print $object->showOptionals($extrafields,'edit');
511  }
512 
513  print "</table>\n";
514 
515  dol_fiche_end();
516 
517  print '<div class="center"><input type="submit" class="button" name="save" value="'.$langs->trans("Save").'"> &nbsp; &nbsp; <input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'"></div>';
518 
519  print "</form>\n";
520 }
521 
522 
523 
524 /* ************************************************************ */
525 /* */
526 /* Donation card in view mode */
527 /* */
528 /* ************************************************************ */
529 if (! empty($id) && $action != 'edit')
530 {
531  // Confirmation delete
532  if ($action == 'delete')
533  {
534  $text=$langs->trans("ConfirmDeleteADonation");
535  print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id,$langs->trans("DeleteADonation"),$text,"confirm_delete",'','',1);
536  }
537 
538  $result=$object->fetch($id);
539  if ($result < 0) {
540  dol_print_error($db,$object->error); exit;
541  }
542  $result=$object->fetch_optionals($object->id,$extralabels);
543  if ($result < 0) {
544  dol_print_error($db); exit;
545  }
546 
547  $hselected='card';
548 
549  $head = donation_prepare_head($object);
550  dol_fiche_head($head, $hselected, $langs->trans("Donation"), -1, 'generic');
551 
552  // Print form confirm
553  print $formconfirm;
554 
555  $linkback = '<a href="'.DOL_URL_ROOT.'/don/list.php'.(! empty($socid)?'?socid='.$socid:'').'">'.$langs->trans("BackToList").'</a>';
556 
557  $morehtmlref='<div class="refidno">';
558  // Project
559  if (! empty($conf->projet->enabled))
560  {
561  $langs->load("projects");
562  $morehtmlref.=$langs->trans('Project') . ' ';
563  if ($user->rights->don->creer)
564  {
565  if ($action != 'classify')
566  $morehtmlref.='<a href="' . $_SERVER['PHP_SELF'] . '?action=classify&amp;id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> : ';
567  if ($action == 'classify') {
568  //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
569  $morehtmlref.='<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
570  $morehtmlref.='<input type="hidden" name="action" value="classin">';
571  $morehtmlref.='<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
572  $morehtmlref.=$formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);
573  $morehtmlref.='<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
574  $morehtmlref.='</form>';
575  } else {
576  $morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1);
577  }
578  } else {
579  if (! empty($object->fk_project)) {
580  $proj = new Project($db);
581  $proj->fetch($object->fk_project);
582  $morehtmlref.='<a href="'.DOL_URL_ROOT.'/projet/card.php?id=' . $object->fk_project . '" title="' . $langs->trans('ShowProject') . '">';
583  $morehtmlref.=$proj->ref;
584  $morehtmlref.='</a>';
585  } else {
586  $morehtmlref.='';
587  }
588  }
589  }
590  $morehtmlref.='</div>';
591 
592 
593  dol_banner_tab($object, 'rowid', $linkback, 1, 'rowid', 'ref', $morehtmlref);
594 
595 
596  print '<div class="fichecenter">';
597  print '<div class="fichehalfleft">';
598  print '<div class="underbanner clearboth"></div>';
599 
600  print '<table class="border" width="100%">';
601 
602  // Date
603  print '<tr><td class="titlefield">'.$langs->trans("Date").'</td><td colspan="2">';
604  print dol_print_date($object->date,"day");
605  print "</td>";
606 
607  print '<tr><td>'.$langs->trans("Amount").'</td><td colspan="2">';
608  print price($object->amount,0,$langs,0,0,-1,$conf->currency);
609  print '</td></tr>';
610 
611  print '<tr><td>'.$langs->trans("PublicDonation").'</td><td colspan="2">';
612  print yn($object->public);
613  print '</td></tr>';
614 
615  print '<tr><td>'.$langs->trans("Company").'</td><td colspan="2">'.$object->societe.'</td></tr>';
616  print '<tr><td>'.$langs->trans("Lastname").'</td><td colspan="2">'.$object->lastname.'</td></tr>';
617  print '<tr><td>'.$langs->trans("Firstname").'</td><td colspan="2">'.$object->firstname.'</td></tr>';
618 
619  // Payment mode
620  print "<tr><td>".$langs->trans("PaymentMode")."</td><td>";
621  $form->form_modes_reglement(null, $object->modepaymentid,'none');
622  print "</td></tr>\n";
623 
624  // Other attributes
625  $cols = 2;
626  include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php';
627 
628  print '</table>';
629 
630  print '</div>';
631  print '<div class="fichehalfright">';
632  print '<div class="ficheaddleft">';
633 
634  /*
635  * Payments
636  */
637  $sql = "SELECT p.rowid, p.num_payment, p.datep as dp, p.amount,";
638  $sql.= " c.code as type_code,c.libelle as paiement_type";
639  $sql.= " FROM ".MAIN_DB_PREFIX."payment_donation as p LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as c ON c.entity IN (".getEntity('c_paiement').")";
640  $sql.= ", ".MAIN_DB_PREFIX."don as d";
641  $sql.= " WHERE d.rowid = '".$id."'";
642  $sql.= " AND p.fk_donation = d.rowid";
643  $sql.= " AND d.entity IN (".getEntity('donation').")";
644  $sql.= " AND p.fk_typepayment = c.id";
645  $sql.= " ORDER BY dp";
646 
647  //print $sql;
648  $resql = $db->query($sql);
649  if ($resql)
650  {
651  $num = $db->num_rows($resql);
652  $i = 0; $total = 0;
653  print '<table class="noborder" width="100%">';
654  print '<tr class="liste_titre">';
655  print '<td>'.$langs->trans("RefPayment").'</td>';
656  print '<td>'.$langs->trans("Date").'</td>';
657  print '<td>'.$langs->trans("Type").'</td>';
658  print '<td align="right">'.$langs->trans("Amount").'</td>';
659  print '</tr>';
660 
661  while ($i < $num)
662  {
663  $objp = $db->fetch_object($resql);
664 
665  print '<tr class="oddeven"><td>';
666  print '<a href="'.DOL_URL_ROOT.'/don/payment/card.php?id='.$objp->rowid.'">'.img_object($langs->trans("Payment"),"payment").' '.$objp->rowid.'</a></td>';
667  print '<td>'.dol_print_date($db->jdate($objp->dp),'day')."</td>\n";
668  $labeltype=$langs->trans("PaymentType".$objp->type_code)!=("PaymentType".$objp->type_code)?$langs->trans("PaymentType".$objp->type_code):$objp->paiement_type;
669  print "<td>".$labeltype.' '.$objp->num_payment."</td>\n";
670  print '<td align="right">'.price($objp->amount)."</td>\n";
671  print "</tr>";
672  $totalpaid += $objp->amount;
673  $i++;
674  }
675 
676  if ($object->paid == 0)
677  {
678  print "<tr><td colspan=\"3\" align=\"right\">".$langs->trans("AlreadyPaid")." :</td><td align=\"right\">".price($totalpaid)."</td></tr>\n";
679  print "<tr><td colspan=\"3\" align=\"right\">".$langs->trans("AmountExpected")." :</td><td align=\"right\">".price($object->amount)."</td></tr>\n";
680 
681  $remaintopay = $object->amount - $totalpaid;
682 
683  print "<tr><td colspan=\"3\" align=\"right\">".$langs->trans("RemainderToPay")." :</td>";
684  print '<td align="right"'.($resteapayeraffiche?' class="amountremaintopay"':'').'><b>'.price($remaintopay)."</b></td></tr>\n";
685  }
686  print "</table>";
687  $db->free($resql);
688  }
689  else
690  {
691  dol_print_error($db);
692  }
693 
694  print '</div>';
695  print '</div>';
696  print '</div>';
697 
698  print '<div class="clearboth"></div>';
699 
700  dol_fiche_end();
701 
702  $remaintopay = $object->amount - $totalpaid;
703 
704  // Actions buttons
705 
706  print '<div class="tabsAction">';
707 
708  print '<div class="inline-block divButAction"><a class="butAction" href="' . $_SERVER["PHP_SELF"] . '?action=edit&rowid='.$object->id.'">'.$langs->trans('Modify').'</a></div>';
709 
710  if ($object->statut == 0)
711  {
712  print '<div class="inline-block divButAction"><a class="butAction" href="' . $_SERVER["PHP_SELF"] . '?rowid='.$object->id.'&action=valid_promesse">'.$langs->trans("ValidPromess").'</a></div>';
713  }
714 
715  if (($object->statut == 0 || $object->statut == 1) && $remaintopay == 0 && $object->paid == 0)
716  {
717  print '<div class="inline-block divButAction"><a class="butAction" href="' . $_SERVER["PHP_SELF"] . '?rowid='.$object->id.'&action=set_cancel">'.$langs->trans("ClassifyCanceled")."</a></div>";
718  }
719 
720  // Create payment
721  if ($object->statut == 1 && $object->paid == 0 && $user->rights->don->creer)
722  {
723  if ($remaintopay == 0)
724  {
725  print '<div class="inline-block divButAction"><span class="butActionRefused" title="' . $langs->trans("DisabledBecauseRemainderToPayIsZero") . '">' . $langs->trans('DoPayment') . '</span></div>';
726  }
727  else
728  {
729  print '<div class="inline-block divButAction"><a class="butAction" href="'.DOL_URL_ROOT.'/don/payment/payment.php?rowid=' . $object->id . '&amp;action=create">' . $langs->trans('DoPayment') . '</a></div>';
730  }
731  }
732 
733  // Classify 'paid'
734  if ($object->statut == 1 && round($remaintopay) == 0 && $object->paid == 0 && $user->rights->don->creer)
735  {
736  print '<div class="inline-block divButAction"><a class="butAction" href="' . $_SERVER["PHP_SELF"] . '?rowid='.$object->id.'&action=set_paid">'.$langs->trans("ClassifyPaid")."</a></div>";
737  }
738 
739  // Delete
740  if ($user->rights->don->supprimer)
741  {
742  if ($object->statut == -1 || $object->statut == 0)
743  {
744  print '<div class="inline-block divButAction"><a class="butActionDelete" href="card.php?rowid='.$object->id.'&action=delete">'.$langs->trans("Delete")."</a></div>";
745  }
746  else
747  {
748  print '<div class="inline-block divButAction"><a class="butActionRefused" href="#">'.$langs->trans("Delete")."</a></div>";
749  }
750  }
751  else
752  {
753  print '<div class="inline-block divButAction"><a class="butActionRefused" href="#">'.$langs->trans("Delete")."</a></div>";
754  }
755 
756  print "</div>";
757 
758 
759  print '<div class="fichecenter"><div class="fichehalfleft">';
760 
761  /*
762  * Documents generes
763  */
764  $filename = dol_sanitizeFileName($object->id);
765  $filedir = $conf->don->dir_output . "/" . dol_sanitizeFileName($object->id);
766  $urlsource = $_SERVER['PHP_SELF'].'?rowid='.$object->id;
767  $genallowed = ($object->statut == 2 && ($object->paid == 0 || $user->admin) && $user->rights->don->lire);
768  $delallowed = $user->rights->don->creer;
769 
770  print $formfile->showdocuments('donation',$filename,$filedir,$urlsource,$genallowed,$delallowed,$object->modelpdf);
771 
772  // Show links to link elements
773  $linktoelem = $form->showLinkToObjectBlock($object, null, array('don'));
774  $somethingshown = $form->showLinkedObjectBlock($object, $linktoelem);
775 
776  print '</div><div class="fichehalfright"><div class="ficheaddleft">';
777 
778  print '</div></div></div>';
779 }
780 
781 llxFooter();
782 $db->close();
llxFooter()
Empty footer.
Definition: wrapper.php:58
yn($yesno, $case=1, $color=0)
Return yes or no in current language.
setEventMessages($mesg, $mesgs, $style='mesgs')
Set event messages in dol_events session object.
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_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
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_print_error($db='', $error='', $errors=null)
Affiche message erreur system avec toutes les informations pour faciliter le diagnostic et la remonte...
if(empty($reshook)) $form
View.
Definition: perms.php:103
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields...
GETPOST($paramname, $check='none', $method=0, $filter=NULL, $options=NULL, $noreplace=0)
Return value of a param into GET or POST supervariable.
Class to build HTML component for third parties management Only common components are here...
Class to manage standard extra fields.
Class to manage generation of HTML components Only common components must be here.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1')
Show information for admin users or standard users.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='')
Write log message into outputs.
Class to manage projects.
Class to manage building of HTML components.
dol_fiche_end($notab=0)
Show tab footer of a card.
load_fiche_titre($titre, $morehtmlright='', $picto='title_generic.png', $pictoisfullpath=0, $id=0, $morecssontable='', $morehtmlcenter='')
Load a title with picto.
llxHeader()
Empty header.
Definition: wrapper.php:46
getEntity($element, $shared=1, $forceentity=null)
Get list of entity id to use.
img_object($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
Class to manage translations.
Class to offer components to list and upload files.
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
Class to manage donations.
Definition: don.class.php:35
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if(!empty($conf->fournisseur->enabled)&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->societe->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if(!empty($conf->fournisseur->enabled)&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1013
dol_delete_file($file, $disableglob=0, $nophperrors=0, $nohook=0, $object=null)
Remove a file or several files with a mask.
Definition: files.lib.php:1103
Class to manage a WYSIWYG editor.
donation_prepare_head($object)
Prepare array with list of tabs.
don_create($db, $id, $message, $modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0)
Cree un don sur disque en fonction du modele de DON_ADDON_PDF.
img_edit($titlealt= 'default', $float=0, $other= 'class="pictoedit"')
Show logo editer/modifier fiche.
price2num($amount, $rounding='', $alreadysqlnb=0)
Function that return a number with universal decimal format (decimal separator is '...
restrictedArea($user, $features, $objectid=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $objcanvas=null)
Check permissions of a user to show a page and an object.
$parameters
Actions.
Definition: card.php:112