card.php 35 KB

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