card.php 36 KB

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