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