card.php 36 KB

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