card.php 35 KB

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