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