card.php 35 KB

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