card.php 31 KB

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