/htdocs/don/card.php
PHP | 883 lines | 606 code | 136 blank | 141 comment | 131 complexity | ada20de92b061aa7dbaa3f434120d59e MD5 | raw 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 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 24/** 25 * \file htdocs/don/card.php 26 * \ingroup donations 27 * \brief Page of donation card 28 */ 29 30require '../main.inc.php'; 31require_once DOL_DOCUMENT_ROOT.'/core/modules/dons/modules_don.php'; 32require_once DOL_DOCUMENT_ROOT.'/core/lib/donation.lib.php'; 33require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php'; 34require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php'; 35require_once DOL_DOCUMENT_ROOT.'/don/class/don.class.php'; 36require_once DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php'; 37require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; 38require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php'; 39require_once DOL_DOCUMENT_ROOT.'/core/class/html.formmargin.class.php'; 40require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; 41if (!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} 45require_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$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 73if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); 74 75if ($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->transnoentitiesnoconv("Date")), null, 'errors'); 88 $action = "create"; 89 $error++; 90 } 91 92 if (empty($amount)) 93 { 94 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("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(null, $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 131if ($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->transnoentitiesnoconv("Date")), null, 'errors'); 144 $action = "create"; 145 $error++; 146 } 147 148 if (empty($amount)) 149 { 150 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Amount")), null, 'errors'); 151 $action = "create"; 152 $error++; 153 } 154 155 if (!$error) 156 { 157 $object->socid = GETPOST("socid", 'int'); 158 $object->firstname = GETPOST("firstname", 'alpha'); 159 $object->lastname = GETPOST("lastname", 'alpha'); 160 $object->societe = GETPOST("societe", 'alpha'); 161 $object->address = GETPOST("address", 'alpha'); 162 $object->amount = price2num(GETPOST("amount", 'alpha')); 163 $object->zip = GETPOST("zipcode", 'alpha'); 164 $object->town = GETPOST("town", 'alpha'); 165 $object->country_id = GETPOST('country_id', 'int'); 166 $object->email = GETPOST('email', 'alpha'); 167 $object->date = $donation_date; 168 $object->note_private = GETPOST("note_private", 'none'); 169 $object->note_public = GETPOST("note_public", 'none'); 170 $object->public = GETPOST("public", 'alpha'); 171 $object->fk_project = GETPOST("fk_project", 'alpha'); 172 $object->modepaymentid = GETPOST('modepayment', 'int'); 173 174 // Fill array 'array_options' with data from add form 175 $ret = $extrafields->setOptionalsFromPost(null, $object); 176 if ($ret < 0) $error++; 177 178 $res = $object->create($user); 179 if ($res > 0) 180 { 181 header("Location: ".$_SERVER['PHP_SELF'].'?id='.$res); 182 exit; 183 } 184 else 185 { 186 setEventMessages($object->error, $object->errors, 'errors'); 187 } 188 } 189} 190if ($action == 'confirm_delete' && GETPOST("confirm") == "yes" && $user->rights->don->supprimer) 191{ 192 $object->fetch($id); 193 $result = $object->delete($user); 194 if ($result > 0) 195 { 196 header("Location: index.php"); 197 exit; 198 } 199 else 200 { 201 dol_syslog($object->error, LOG_DEBUG); 202 setEventMessages($object->error, $object->errors, 'errors'); 203 } 204} 205if ($action == 'valid_promesse') 206{ 207 $object->fetch($id); 208 if ($object->valid_promesse($id, $user->id) >= 0) 209 { 210 setEventMessages($langs->trans("DonationValidated", $object->ref), null); 211 212 header("Location: ".$_SERVER['PHP_SELF']."?id=".$id); 213 exit; 214 } 215 else { 216 setEventMessages($object->error, $object->errors, 'errors'); 217 } 218} 219if ($action == 'set_cancel') 220{ 221 $object->fetch($id); 222 if ($object->set_cancel($id) >= 0) 223 { 224 header("Location: ".$_SERVER['PHP_SELF']."?id=".$id); 225 exit; 226 } 227 else { 228 setEventMessages($object->error, $object->errors, 'errors'); 229 } 230} 231if ($action == 'set_paid') 232{ 233 $object->fetch($id); 234 if ($object->set_paid($id, $modepayment) >= 0) 235 { 236 header("Location: ".$_SERVER['PHP_SELF']."?id=".$id); 237 exit; 238 } 239 else { 240 setEventMessages($object->error, $object->errors, 'errors'); 241 } 242} 243elseif ($action == 'classin' && $user->rights->don->creer) 244{ 245 $object->fetch($id); 246 $object->setProject($projectid); 247} 248 249// Actions to build doc 250$upload_dir = $conf->don->dir_output; 251$permissiontoadd = $user->rights->don->creer; 252include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php'; 253 254 255// Remove file in doc form 256/*if ($action == 'remove_file') 257{ 258 $object = new Don($db, 0, $_GET['id']); 259 if ($object->fetch($id)) 260 { 261 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; 262 263 $object->fetch_thirdparty(); 264 265 $langs->load("other"); 266 $upload_dir = $conf->don->dir_output; 267 $file = $upload_dir . '/' . GETPOST('file'); 268 $ret=dol_delete_file($file,0,0,0,$object); 269 if ($ret) setEventMessages($langs->trans("FileWasRemoved", GETPOST('urlfile')), null, 'mesgs'); 270 else setEventMessages($langs->trans("ErrorFailToDeleteFile", GETPOST('urlfile')), null, 'errors'); 271 $action=''; 272 } 273} 274*/ 275 276/* 277 * Build doc 278 */ 279/* 280if ($action == 'builddoc') 281{ 282 $object = new Don($db); 283 $result=$object->fetch($id); 284 285 // Save last template used to generate document 286 if (GETPOST('model')) $object->setDocModel($user, GETPOST('model','alpha')); 287 288 // Define output language 289 $outputlangs = $langs; 290 $newlang=''; 291 if ($conf->global->MAIN_MULTILANGS && empty($newlang) && ! empty($_REQUEST['lang_id'])) $newlang=$_REQUEST['lang_id']; 292 if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->thirdparty->default_lang; 293 if (! empty($newlang)) 294 { 295 $outputlangs = new Translate("",$conf); 296 $outputlangs->setDefaultLang($newlang); 297 } 298 $result=don_create($db, $object->id, '', $object->modelpdf, $outputlangs); 299 if ($result <= 0) 300 { 301 dol_print_error($db,$result); 302 exit; 303 } 304} 305*/ 306 307 308/* 309 * View 310 */ 311 312llxHeader('', $langs->trans("Donation"), 'EN:Module_Donations|FR:Module_Dons|ES:Módulo_Donaciones'); 313 314$form = new Form($db); 315$formfile = new FormFile($db); 316$formcompany = new FormCompany($db); 317if (!empty($conf->projet->enabled)) { $formproject = new FormProjets($db); } 318 319if ($action == 'create') 320{ 321 print load_fiche_titre($langs->trans("AddDonation"), '', 'object_donation'); 322 323 print '<form name="add" action="'.$_SERVER["PHP_SELF"].'" method="POST">'; 324 print '<input type="hidden" name="token" value="'.newToken().'">'; 325 print '<input type="hidden" name="action" value="add">'; 326 327 dol_fiche_head(''); 328 329 print '<table class="border centpercent">'; 330 print '<tbody>'; 331 332 // Ref 333 print '<tr><td class="titlefieldcreate fieldrequired">'.$langs->trans('Ref').'</td><td colspan="2">'.$langs->trans('Draft').'</td></tr>'; 334 335 // Company 336 if (!empty($conf->societe->enabled) && !empty($conf->global->DONATION_USE_THIRDPARTIES)) 337 { 338 // Thirdparty 339 print '<td>'.$langs->trans('Customer').'</td>'; 340 if ($soc->id > 0 && !GETPOST('fac_rec', 'alpha')) 341 { 342 print '<td colspan="2">'; 343 print $soc->getNomUrl(1); 344 print '<input type="hidden" name="socid" value="'.$soc->id.'">'; 345 // Outstanding Bill 346 $arrayoutstandingbills = $soc->getOutstandingBills(); 347 $outstandingBills = $arrayoutstandingbills['opened']; 348 print ' ('.$langs->trans('CurrentOutstandingBill').': '; 349 print price($outstandingBills, '', $langs, 0, 0, -1, $conf->currency); 350 if ($soc->outstanding_limit != '') 351 { 352 if ($outstandingBills > $soc->outstanding_limit) print img_warning($langs->trans("OutstandingBillReached")); 353 print ' / '.price($soc->outstanding_limit, '', $langs, 0, 0, -1, $conf->currency); 354 } 355 print ')'; 356 print '</td>'; 357 } 358 else 359 { 360 print '<td colspan="2">'; 361 print $form->select_company($soc->id, 'socid', '(s.client = 1 OR s.client = 3) AND status=1', 'SelectThirdParty', 0, 0, null, 0, 'minwidth300'); 362 // Option to reload page to retrieve customer informations. Note, this clear other input 363 if (!empty($conf->global->RELOAD_PAGE_ON_CUSTOMER_CHANGE)) 364 { 365 print '<script type="text/javascript"> 366 $(document).ready(function() { 367 $("#socid").change(function() { 368 var socid = $(this).val(); 369 var fac_rec = $(\'#fac_rec\').val(); 370 // reload page 371 window.location.href = "'.$_SERVER["PHP_SELF"].'?action=create&socid="+socid+"&fac_rec="+fac_rec; 372 }); 373 }); 374 </script>'; 375 } 376 print ' <a href="'.DOL_URL_ROOT.'/societe/card.php?action=create&client=3&fournisseur=0&backtopage='.urlencode($_SERVER["PHP_SELF"].'?action=create').'"><span class="valignmiddle text-plus-circle">'.$langs->trans("AddThirdParty").'</span><span class="fa fa-plus-circle valignmiddle paddingleft"></span></a>'; 377 print '</td>'; 378 } 379 print '</tr>'."\n"; 380 } 381 382 // Date 383 print '<tr><td class="fieldrequired titlefieldcreate">'.$langs->trans("Date").'</td><td>'; 384 print $form->selectDate($donation_date ? $donation_date : -1, '', '', '', '', "add", 1, 1); 385 print '</td>'; 386 387 // Amount 388 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>'; 389 390 // Public donation 391 print '<tr><td class="fieldrequired">'.$langs->trans("PublicDonation")."</td><td>"; 392 print $form->selectyesno("public", isset($_POST["public"]) ? $_POST["public"] : 1, 1); 393 print "</td></tr>\n"; 394 395 if (empty($conf->societe->enabled) || empty($conf->global->DONATION_USE_THIRDPARTIES)) 396 { 397 print "<tr>".'<td>'.$langs->trans("Company").'</td><td><input type="text" name="societe" value="'.dol_escape_htmltag(GETPOST("societe")).'" class="maxwidth200"></td></tr>'; 398 print "<tr>".'<td>'.$langs->trans("Lastname").'</td><td><input type="text" name="lastname" value="'.dol_escape_htmltag(GETPOST("lastname")).'" class="maxwidth200"></td></tr>'; 399 print "<tr>".'<td>'.$langs->trans("Firstname").'</td><td><input type="text" name="firstname" value="'.dol_escape_htmltag(GETPOST("firstname")).'" class="maxwidth200"></td></tr>'; 400 print "<tr>".'<td>'.$langs->trans("Address").'</td><td>'; 401 print '<textarea name="address" wrap="soft" class="quatrevingtpercent" rows="3">'.dol_escape_htmltag(GETPOST("address", "none"), 0, 1).'</textarea></td></tr>'; 402 403 // Zip / Town 404 print '<tr><td>'.$langs->trans("Zip").' / '.$langs->trans("Town").'</td><td>'; 405 print $formcompany->select_ziptown((isset($_POST["zipcode"]) ? $_POST["zipcode"] : $object->zip), 'zipcode', array('town', 'selectcountry_id', 'state_id'), 6); 406 print ' '; 407 print $formcompany->select_ziptown((isset($_POST["town"]) ? $_POST["town"] : $object->town), 'town', array('zipcode', 'selectcountry_id', 'state_id')); 408 print '</tr>'; 409 410 // Country 411 print '<tr><td><label for="selectcountry_id">'.$langs->trans('Country').'</label></td><td class="maxwidthonsmartphone">'; 412 print $form->select_country(GETPOST('country_id') != '' ?GETPOST('country_id') : $object->country_id); 413 if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1); 414 print '</td></tr>'; 415 416 print "<tr>".'<td>'.$langs->trans("EMail").'</td><td><input type="text" name="email" value="'.dol_escape_htmltag(GETPOST("email")).'" class="maxwidth200"></td></tr>'; 417 } 418 419 // Payment mode 420 print "<tr><td>".$langs->trans("PaymentMode")."</td><td>\n"; 421 $selected = GETPOST('modepayment', 'int'); 422 $form->select_types_paiements($selected, 'modepayment', 'CRDT', 0, 1); 423 print "</td></tr>\n"; 424 425 // Public note 426 print '<tr>'; 427 print '<td class="tdtop">'.$langs->trans('NotePublic').'</td>'; 428 print '<td>'; 429 430 $doleditor = new DolEditor('note_public', $note_public, '', 80, 'dolibarr_notes', 'In', 0, false, true, ROWS_3, '90%'); 431 print $doleditor->Create(1); 432 print '</td></tr>'; 433 434 // Private note 435 if (empty($user->socid)) { 436 print '<tr>'; 437 print '<td class="tdtop">'.$langs->trans('NotePrivate').'</td>'; 438 print '<td>'; 439 440 $doleditor = new DolEditor('note_private', $note_private, '', 80, 'dolibarr_notes', 'In', 0, false, true, ROWS_3, '90%'); 441 print $doleditor->Create(1); 442 print '</td></tr>'; 443 } 444 445 if (!empty($conf->projet->enabled)) 446 { 447 print "<tr><td>".$langs->trans("Project")."</td><td>"; 448 $formproject->select_projects(-1, $projectid, 'fk_project', 0, 0, 1, 1, 0, 0, 0, '', 0, 0, 'maxwidth500'); 449 print "</td></tr>\n"; 450 } 451 452 // Other attributes 453 $parameters = array(); 454 $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook 455 print $hookmanager->resPrint; 456 if (empty($reshook)) 457 { 458 print $object->showOptionals($extrafields, 'edit', $parameters); 459 } 460 461 print '</tbody>'; 462 print "</table>\n"; 463 464 dol_fiche_end(); 465 466 print '<div class="center">'; 467 print '<input type="submit" class="button" name="save" value="'.dol_escape_htmltag($langs->trans("Save")).'">'; 468 print ' '; 469 print '<input type="button" class="button" value="'.dol_escape_htmltag($langs->trans("Cancel")).'" onClick="javascript:history.go(-1)">'; 470 print '</div>'; 471 472 print "</form>\n"; 473} 474 475 476/* ************************************************************ */ 477/* */ 478/* Donation card in edit mode */ 479/* */ 480/* ************************************************************ */ 481 482if (!empty($id) && $action == 'edit') 483{ 484 $result = $object->fetch($id); 485 if ($result < 0) { 486 dol_print_error($db, $object->error); exit; 487 } 488 $result = $object->fetch_optionals(); 489 if ($result < 0) { 490 dol_print_error($db); exit; 491 } 492 493 $hselected = 'card'; 494 $head = donation_prepare_head($object); 495 496 print '<form name="update" action="'.$_SERVER["PHP_SELF"].'" method="POST">'; 497 print '<input type="hidden" name="token" value="'.newToken().'">'; 498 print '<input type="hidden" name="action" value="update">'; 499 print '<input type="hidden" name="rowid" value="'.$object->id.'">'; 500 print '<input type="hidden" name="amount" value="'.$object->amount.'">'; 501 502 503 dol_fiche_head($head, $hselected, $langs->trans("Donation"), 0, 'donation'); 504 505 print '<table class="border centpercent">'; 506 507 // Ref 508 print '<tr><td>'.$langs->trans("Ref").'</td><td colspan="2">'; 509 print $object->getNomUrl(); 510 print '</td>'; 511 print '</tr>'; 512 513 // Date 514 print '<tr><td class="titlefieldcreate fieldrequired">'.$langs->trans("Date").'</td><td>'; 515 print $form->selectDate($object->date, '', '', '', '', "update"); 516 print '</td>'; 517 518 // Amount 519 if ($object->statut == 0) 520 { 521 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>'; 522 } 523 else 524 { 525 print '<tr><td>'.$langs->trans("Amount").'</td><td>'; 526 print price($object->amount, 0, $langs, 0, 0, -1, $conf->currency); 527 print '</td></tr>'; 528 } 529 530 print '<tr><td class="fieldrequired">'.$langs->trans("PublicDonation")."</td><td>"; 531 print $form->selectyesno("public", 1, 1); 532 print "</td>"; 533 print "</tr>\n"; 534 535 if ($object->socid && !empty($conf->societe->enabled) && !empty($conf->global->DONATION_USE_THIRDPARTIES)) { 536 $company = new Societe($db); 537 $result = $company->fetch($object->socid); 538 539 print '<tr><td>'.$langs->trans("LinkedToDolibarrThirdParty").'</td><td colspan="2">'.$company->getNomUrl(1).'</td></tr>'; 540 } else { 541 $langs->load("companies"); 542 print '<tr><td>'.$langs->trans("Company").'</td><td><input type="text" name="societe" class="maxwidth200" value="'.dol_escape_htmltag($object->societe).'"></td></tr>'; 543 print '<tr><td>'.$langs->trans("Lastname").'</td><td><input type="text" name="lastname" class="maxwidth200" value="'.dol_escape_htmltag($object->lastname).'"></td></tr>'; 544 print '<tr><td>'.$langs->trans("Firstname").'</td><td><input type="text" name="firstname" class="maxwidth200" value="'.dol_escape_htmltag($object->firstname).'"></td></tr>'; 545 print '<tr><td>'.$langs->trans("Address").'</td><td>'; 546 print '<textarea name="address" wrap="soft" class="quatrevingtpercent" rows="'.ROWS_3.'">'.dol_escape_htmltag($object->address, 0, 1).'</textarea></td></tr>'; 547 548 // Zip / Town 549 print '<tr><td>'.$langs->trans("Zip").' / '.$langs->trans("Town").'</td><td>'; 550 print $formcompany->select_ziptown((isset($_POST["zipcode"]) ? $_POST["zipcode"] : $object->zip), 'zipcode', array('town', 'selectcountry_id', 'state_id'), 6); 551 print ' '; 552 print $formcompany->select_ziptown((isset($_POST["town"]) ? $_POST["town"] : $object->town), 'town', array('zipcode', 'selectcountry_id', 'state_id')); 553 print '</tr>'; 554 555 // Country 556 print '<tr><td class="titlefieldcreate">'.$langs->trans('Country').'</td><td>'; 557 print $form->select_country((!empty($object->country_id) ? $object->country_id : $mysoc->country_code), 'country_id'); 558 if ($user->admin) { 559 print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1); 560 } 561 print '</td></tr>'; 562 563 print "<tr>".'<td>'.$langs->trans("EMail").'</td><td><input type="text" name="email" class="maxwidth200" value="'.dol_escape_htmltag($object->email).'"></td></tr>'; 564 } 565 // Payment mode 566 print "<tr><td>".$langs->trans("PaymentMode")."</td><td>\n"; 567 if ($object->mode_reglement_id) $selected = $object->mode_reglement_id; 568 else $selected = ''; 569 $form->select_types_paiements($selected, 'modepayment', 'CRDT', 0, 1); 570 print "</td></tr>\n"; 571 572 // Status 573 print "<tr>".'<td>'.$langs->trans("Status").'</td><td>'.$object->getLibStatut(4).'</td></tr>'; 574 575 // Project 576 if (!empty($conf->projet->enabled)) 577 { 578 $formproject = new FormProjets($db); 579 580 $langs->load('projects'); 581 print '<tr><td>'.$langs->trans('Project').'</td><td>'; 582 $formproject->select_projects(-1, $object->fk_project, 'fk_project', 0, 0, 1, 1, 0, 0, 0, '', 0, 0, 'maxwidth500'); 583 print '</td></tr>'; 584 } 585 586 // Other attributes 587 $parameters = array(); 588 $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook 589 print $hookmanager->resPrint; 590 if (empty($reshook)) 591 { 592 print $object->showOptionals($extrafields, 'edit', $parameters); 593 } 594 595 print "</table>\n"; 596 597 dol_fiche_end(); 598 599 print '<div class="center"><input type="submit" class="button" name="save" value="'.$langs->trans("Save").'"> <input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'"></div>'; 600 601 print "</form>\n"; 602} 603 604 605 606/* ************************************************************ */ 607/* */ 608/* Donation card in view mode */ 609/* */ 610/* ************************************************************ */ 611if (!empty($id) && $action != 'edit') 612{ 613 // Confirmation delete 614 if ($action == 'delete') 615 { 616 $text = $langs->trans("ConfirmDeleteADonation"); 617 print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id, $langs->trans("DeleteADonation"), $text, "confirm_delete", '', '', 1); 618 } 619 620 $result = $object->fetch($id); 621 if ($result < 0) { 622 dol_print_error($db, $object->error); exit; 623 } 624 $result = $object->fetch_optionals(); 625 if ($result < 0) { 626 dol_print_error($db); exit; 627 } 628 629 $hselected = 'card'; 630 631 $head = donation_prepare_head($object); 632 dol_fiche_head($head, $hselected, $langs->trans("Donation"), -1, 'donation'); 633 634 // Print form confirm 635 print $formconfirm; 636 637 $linkback = '<a href="'.DOL_URL_ROOT.'/don/list.php'.(!empty($socid) ? '?socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>'; 638 639 $morehtmlref = '<div class="refidno">'; 640 // Project 641 if (!empty($conf->projet->enabled)) 642 { 643 $langs->load("projects"); 644 $morehtmlref .= $langs->trans('Project').' '; 645 if ($user->rights->don->creer) 646 { 647 if ($action != 'classify') { 648 $morehtmlref .= '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=classify&id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> : '; 649 } 650 if ($action == 'classify') { 651 //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1); 652 $morehtmlref .= '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">'; 653 $morehtmlref .= '<input type="hidden" name="action" value="classin">'; 654 $morehtmlref .= '<input type="hidden" name="token" value="'.newToken().'">'; 655 $morehtmlref .= $formproject->select_projects($object->socid, $object->fk_project, 'projectid', 0, 0, 1, 0, 1, 0, 0, '', 1, 0, 'maxwidth500'); 656 $morehtmlref .= '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">'; 657 $morehtmlref .= '</form>'; 658 } else { 659 $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1); 660 } 661 } else { 662 if (!empty($object->fk_project)) { 663 $proj = new Project($db); 664 $proj->fetch($object->fk_project); 665 $morehtmlref .= '<a href="'.DOL_URL_ROOT.'/projet/card.php?id='.$object->fk_project.'" title="'.$langs->trans('ShowProject').'">'; 666 $morehtmlref .= $proj->ref; 667 $morehtmlref .= '</a>'; 668 } else { 669 $morehtmlref .= ''; 670 } 671 } 672 } 673 $morehtmlref .= '</div>'; 674 675 676 dol_banner_tab($object, 'rowid', $linkback, 1, 'rowid', 'ref', $morehtmlref); 677 678 679 print '<div class="fichecenter">'; 680 print '<div class="fichehalfleft">'; 681 print '<div class="underbanner clearboth"></div>'; 682 683 print '<table class="border tableforfield" width="100%">'; 684 685 // Date 686 print '<tr><td class="titlefield">'.$langs->trans("Date").'</td><td colspan="2">'; 687 print dol_print_date($object->date, "day"); 688 print "</td>"; 689 690 print '<tr><td>'.$langs->trans("Amount").'</td><td colspan="2">'; 691 print price($object->amount, 0, $langs, 0, 0, -1, $conf->currency); 692 print '</td></tr>'; 693 694 print '<tr><td>'.$langs->trans("PublicDonation").'</td><td colspan="2">'; 695 print yn($object->public); 696 print '</td></tr>'; 697 698 if ($object->socid) { 699 $company = new Societe($db); 700 $result = $company->fetch($object->socid); 701 702 print '<tr><td>'.$langs->trans("LinkedToDolibarrThirdParty").'</td><td colspan="2">'.$company->getNomUrl(1).'</td></tr>'; 703 } else { 704 print '<tr><td>'.$langs->trans("Company").'</td><td colspan="2">'.$object->societe.'</td></tr>'; 705 print '<tr><td>'.$langs->trans("Lastname").'</td><td colspan="2">'.$object->lastname.'</td></tr>'; 706 print '<tr><td>'.$langs->trans("Firstname").'</td><td colspan="2">'.$object->firstname.'</td></tr>'; 707 } 708 709 // Payment mode 710 print "<tr><td>".$langs->trans("PaymentMode")."</td><td>"; 711 $form->form_modes_reglement(null, $object->mode_reglement_id, 'none'); 712 print "</td></tr>\n"; 713 714 // Other attributes 715 $cols = 2; 716 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php'; 717 718 print '</table>'; 719 720 print '</div>'; 721 print '<div class="fichehalfright">'; 722 print '<div class="ficheaddleft">'; 723 724 /* 725 * Payments 726 */ 727 $sql = "SELECT p.rowid, p.num_payment, p.datep as dp, p.amount,"; 728 $sql .= "c.code as type_code,c.libelle as paiement_type"; 729 $sql .= " FROM ".MAIN_DB_PREFIX."payment_donation as p"; 730 $sql .= ", ".MAIN_DB_PREFIX."c_paiement as c "; 731 $sql .= ", ".MAIN_DB_PREFIX."don as d"; 732 $sql .= " WHERE d.rowid = '".$id."'"; 733 $sql .= " AND p.fk_donation = d.rowid"; 734 $sql .= " AND d.entity IN (".getEntity('donation').")"; 735 $sql .= " AND p.fk_typepayment = c.id"; 736 $sql .= " ORDER BY dp"; 737 738 //print $sql; 739 $resql = $db->query($sql); 740 if ($resql) 741 { 742 $num = $db->num_rows($resql); 743 $i = 0; $total = 0; 744 print '<table class="noborder paymenttable centpercent">'; 745 print '<tr class="liste_titre">'; 746 print '<td>'.$langs->trans("RefPayment").'</td>'; 747 print '<td>'.$langs->trans("Date").'</td>'; 748 print '<td>'.$langs->trans("Type").'</td>'; 749 print '<td class="right">'.$langs->trans("Amount").'</td>'; 750 print '</tr>'; 751 752 while ($i < $num) 753 { 754 $objp = $db->fetch_object($resql); 755 756 print '<tr class="oddeven"><td>'; 757 print '<a href="'.DOL_URL_ROOT.'/don/payment/card.php?id='.$objp->rowid.'">'.img_object($langs->trans("Payment"), "payment").' '.$objp->rowid.'</a></td>'; 758 print '<td>'.dol_print_date($db->jdate($objp->dp), 'day')."</td>\n"; 759 $labeltype = $langs->trans("PaymentType".$objp->type_code) != ("PaymentType".$objp->type_code) ? $langs->trans("PaymentType".$objp->type_code) : $objp->paiement_type; 760 print "<td>".$labeltype.' '.$objp->num_payment."</td>\n"; 761 print '<td class="right">'.price($objp->amount)."</td>\n"; 762 print "</tr>"; 763 $totalpaid += $objp->amount; 764 $i++; 765 } 766 767 if ($object->paid == 0) 768 { 769 print "<tr><td colspan=\"3\" class=\"right\">".$langs->trans("AlreadyPaid")." :</td><td class=\"right\">".price($totalpaid)."</td></tr>\n"; 770 print "<tr><td colspan=\"3\" class=\"right\">".$langs->trans("AmountExpected")." :</td><td class=\"right\">".price($object->amount)."</td></tr>\n"; 771 772 $remaintopay = $object->amount - $totalpaid; 773 774 print "<tr><td colspan=\"3\" class=\"right\">".$langs->trans("RemainderToPay")." :</td>"; 775 print '<td class="right'.($resteapayeraffiche ? ' amountremaintopay' : '').'">'.price($remaintopay)."</td></tr>\n"; 776 } 777 print "</table>"; 778 $db->free($resql); 779 } 780 else 781 { 782 dol_print_error($db); 783 } 784 785 print '</div>'; 786 print '</div>'; 787 print '</div>'; 788 789 print '<div class="clearboth"></div>'; 790 791 dol_fiche_end(); 792 793 $remaintopay = $object->amount - $totalpaid; 794 795 // Actions buttons 796 797 print '<div class="tabsAction">'; 798 799 print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=edit&rowid='.$object->id.'">'.$langs->trans('Modify').'</a></div>'; 800 801 if ($object->statut == 0) 802 { 803 print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?rowid='.$object->id.'&action=valid_promesse">'.$langs->trans("ValidPromess").'</a></div>'; 804 } 805 806 if (($object->statut == 0 || $object->statut == 1) && $totalpaid == 0 && $object->paid == 0) 807 { 808 print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?rowid='.$object->id.'&action=set_cancel">'.$langs->trans("ClassifyCanceled")."</a></div>"; 809 } 810 811 // Create payment 812 if ($object->statut == 1 && $object->paid == 0 && $user->rights->don->creer) 813 { 814 if ($remaintopay == 0) 815 { 816 print '<div class="inline-block divButAction"><span class="butActionRefused classfortooltip" title="'.$langs->trans("DisabledBecauseRemainderToPayIsZero").'">'.$langs->trans('DoPayment').'</span></div>'; 817 } 818 else 819 { 820 print '<div class="inline-block divButAction"><a class="butAction" href="'.DOL_URL_ROOT.'/don/payment/payment.php?rowid='.$object->id.'&action=create">'.$langs->trans('DoPayment').'</a></div>'; 821 } 822 } 823 824 // Classify 'paid' 825 if ($object->statut == 1 && round($remaintopay) == 0 && $object->paid == 0 && $user->rights->don->creer) 826 { 827 print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?rowid='.$object->id.'&action=set_paid">'.$langs->trans("ClassifyPaid")."</a></div>"; 828 } 829 830 // Delete 831 if ($user->rights->don->supprimer) 832 { 833 if ($object->statut == -1 || $object->statut == 0) 834 { 835 print '<div class="inline-block divButAction"><a class="butActionDelete" href="card.php?rowid='.$object->id.'&action=delete">'.$langs->trans("Delete")."</a></div>"; 836 } 837 else 838 { 839 print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" href="#">'.$langs->trans("Delete")."</a></div>"; 840 } 841 } 842 else 843 { 844 print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" href="#">'.$langs->trans("Delete")."</a></div>"; 845 } 846 847 print "</div>"; 848 849 850 print '<div class="fichecenter"><div class="fichehalfleft">'; 851 852 /* 853 * Documents generes 854 */ 855 $filename = dol_sanitizeFileName($object->id); 856 $filedir = $conf->don->dir_output."/".dol_sanitizeFileName($object->id); 857 $urlsource = $_SERVER['PHP_SELF'].'?rowid='.$object->id; 858 $genallowed = (($object->paid == 0 || $user->admin) && $user->rights->don->lire); 859 $delallowed = $user->rights->don->creer; 860 861 print $formfile->showdocuments('donation', $filename, $filedir, $urlsource, $genallowed, $delallowed, $object->modelpdf); 862 863 // Show links to link elements 864 $linktoelem = $form->showLinkToObjectBlock($object, null, array('don')); 865 $somethingshown = $form->showLinkedObjectBlock($object, $linktoelem); 866 867 // Show online payment link 868 $useonlinepayment = (!empty($conf->paypal->enabled) || !empty($conf->stripe->enabled) || !empty($conf->paybox->enabled)); 869 870 if ($useonlinepayment) //$object->statut != Facture::STATUS_DRAFT && 871 { 872 print '<br><!-- Link to pay -->'."\n"; 873 require_once DOL_DOCUMENT_ROOT.'/core/lib/payments.lib.php'; 874 print showOnlinePaymentUrl('donation', $object->ref).'<br>'; 875 } 876 877 print '</div><div class="fichehalfright"><div class="ficheaddleft">'; 878 879 print '</div></div></div>'; 880} 881 882llxFooter(); 883$db->close();