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