PageRenderTime 51ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 1ms

/htdocs/don/card.php

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