PageRenderTime 52ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/don/card.php

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