/htdocs/don/card.php

https://github.com/atm-maximep/dolibarr · PHP · 763 lines · 540 code · 135 blank · 88 comment · 115 complexity · 5470adcfd34af2e0fcc0f9b5eebf2b63 MD5 · raw file

  1. <?php
  2. /* Copyright (C) 2001-2002 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2015 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@capnetworks.com>
  5. * Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
  6. * Copyright (C) 2015 Alexandre Spangaro <alexandre.spangaro@gmail.com>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. */
  21. /**
  22. * \file htdocs/don/card.php
  23. * \ingroup donations
  24. * \brief Page of donation card
  25. */
  26. require '../main.inc.php';
  27. require_once DOL_DOCUMENT_ROOT.'/core/modules/dons/modules_don.php';
  28. require_once DOL_DOCUMENT_ROOT.'/core/lib/donation.lib.php';
  29. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  30. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
  31. require_once DOL_DOCUMENT_ROOT.'/don/class/don.class.php';
  32. require_once DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php';
  33. require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
  34. if (! empty($conf->projet->enabled))
  35. {
  36. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
  37. }
  38. require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
  39. $langs->load("companies");
  40. $langs->load("donations");
  41. $langs->load("bills");
  42. $id=GETPOST('rowid')?GETPOST('rowid','int'):GETPOST('id','int');
  43. $action=GETPOST('action','alpha');
  44. $cancel=GETPOST('cancel');
  45. $amount=GETPOST('amount');
  46. $donation_date=dol_mktime(12, 0, 0, GETPOST('remonth'), GETPOST('reday'), GETPOST('reyear'));
  47. $object = new Don($db);
  48. $extrafields = new ExtraFields($db);
  49. // Security check
  50. $result = restrictedArea($user, 'don', $id);
  51. // fetch optionals attributes and labels
  52. $extralabels=$extrafields->fetch_name_optionals_label($object->table_element);
  53. // Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array
  54. $hookmanager->initHooks(array('doncard','globalcard'));
  55. /*
  56. * Actions
  57. */
  58. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some
  59. if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  60. if ($action == 'update')
  61. {
  62. if (! empty($cancel))
  63. {
  64. header("Location: ".$_SERVER['PHP_SELF']."?id=".$id);
  65. exit;
  66. }
  67. $error=0;
  68. if (empty($donation_date))
  69. {
  70. setEventMessage($langs->trans("ErrorFieldRequired",$langs->trans("Date")), 'errors');
  71. $action = "create";
  72. $error++;
  73. }
  74. if (empty($amount))
  75. {
  76. setEventMessage($langs->trans("ErrorFieldRequired",$langs->trans("Amount")), 'errors');
  77. $action = "create";
  78. $error++;
  79. }
  80. if (! $error)
  81. {
  82. $object->fetch($id);
  83. $object->firstname = GETPOST("firstname");
  84. $object->lastname = GETPOST("lastname");
  85. $object->societe = GETPOST("societe");
  86. $object->address = GETPOST("address");
  87. $object->amount = price2num(GETPOST("amount"));
  88. $object->town = GETPOST("town");
  89. $object->zip = GETPOST("zipcode");
  90. $object->country_id = GETPOST('country_id', 'int');
  91. $object->email = GETPOST("email");
  92. $object->date = $donation_date;
  93. $object->public = GETPOST("public");
  94. $object->fk_projet = GETPOST("fk_projet");
  95. $object->note_private= GETPOST("note_private");
  96. $object->note_public = GETPOST("note_public");
  97. // Fill array 'array_options' with data from add form
  98. $ret = $extrafields->setOptionalsFromPost($extralabels,$object);
  99. if ($ret < 0) $error++;
  100. if ($object->update($user) > 0)
  101. {
  102. header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
  103. exit;
  104. }
  105. }
  106. }
  107. if ($action == 'add')
  108. {
  109. if (! empty($cancel))
  110. {
  111. header("Location: index.php");
  112. exit;
  113. }
  114. $error=0;
  115. if (empty($donation_date))
  116. {
  117. setEventMessage($langs->trans("ErrorFieldRequired",$langs->trans("Date")), 'errors');
  118. $action = "create";
  119. $error++;
  120. }
  121. if (empty($amount))
  122. {
  123. setEventMessage($langs->trans("ErrorFieldRequired",$langs->trans("Amount")), 'errors');
  124. $action = "create";
  125. $error++;
  126. }
  127. if (! $error)
  128. {
  129. $object->firstname = GETPOST("firstname");
  130. $object->lastname = GETPOST("lastname");
  131. $object->societe = GETPOST("societe");
  132. $object->address = GETPOST("address");
  133. $object->amount = price2num(GETPOST("amount"));
  134. $object->zip = GETPOST("zipcode");
  135. $object->town = GETPOST("town");
  136. $object->country_id = GETPOST('country_id', 'int');
  137. $object->email = GETPOST("email");
  138. $object->date = $donation_date;
  139. $object->note_private= GETPOST("note_private");
  140. $object->note_public = GETPOST("note_public");
  141. $object->public = GETPOST("public");
  142. $object->fk_projet = GETPOST("fk_projet");
  143. // Fill array 'array_options' with data from add form
  144. $ret = $extrafields->setOptionalsFromPost($extralabels,$object);
  145. if ($ret < 0) $error++;
  146. if ($object->create($user) > 0)
  147. {
  148. header("Location: index.php");
  149. exit;
  150. }
  151. else
  152. {
  153. setEventMessages($object->error, $object->errors, 'errors');
  154. }
  155. }
  156. }
  157. if ($action == 'confirm_delete' && GETPOST("confirm") == "yes" && $user->rights->don->supprimer)
  158. {
  159. $object->fetch($id);
  160. $result=$object->delete($user);
  161. if ($result > 0)
  162. {
  163. header("Location: index.php");
  164. exit;
  165. }
  166. else
  167. {
  168. dol_syslog($object->error,LOG_DEBUG);
  169. setEventMessage($object->error,'errors');
  170. setEventMessage($object->errors,'errors');
  171. }
  172. }
  173. if ($action == 'valid_promesse')
  174. {
  175. if ($object->valid_promesse($id, $user->id) >= 0)
  176. {
  177. header("Location: ".$_SERVER['PHP_SELF']."?id=".$id);
  178. exit;
  179. }
  180. else {
  181. setEventMessage($object->error, 'errors');
  182. }
  183. }
  184. if ($action == 'set_cancel')
  185. {
  186. if ($object->set_cancel($id) >= 0)
  187. {
  188. header("Location: ".$_SERVER['PHP_SELF']."?id=".$id);
  189. exit;
  190. }
  191. else {
  192. setEventMessage($object->error, 'errors');
  193. }
  194. }
  195. if ($action == 'set_paid')
  196. {
  197. if ($object->set_paid($id, $modepayment) >= 0)
  198. {
  199. header("Location: ".$_SERVER['PHP_SELF']."?id=".$id);
  200. exit;
  201. }
  202. else {
  203. setEventMessage($object->error, 'errors');
  204. }
  205. }
  206. /*
  207. * Build doc
  208. */
  209. if ($action == 'builddoc')
  210. {
  211. $object = new Don($db);
  212. $result=$object->fetch($id);
  213. // Save last template used to generate document
  214. if (GETPOST('model')) $object->setDocModel($user, GETPOST('model','alpha'));
  215. // Define output language
  216. $outputlangs = $langs;
  217. $newlang='';
  218. if ($conf->global->MAIN_MULTILANGS && empty($newlang) && ! empty($_REQUEST['lang_id'])) $newlang=$_REQUEST['lang_id'];
  219. if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang;
  220. if (! empty($newlang))
  221. {
  222. $outputlangs = new Translate("",$conf);
  223. $outputlangs->setDefaultLang($newlang);
  224. }
  225. $result=don_create($db, $object->id, '', $object->modelpdf, $outputlangs);
  226. if ($result <= 0)
  227. {
  228. dol_print_error($db,$result);
  229. exit;
  230. }
  231. }
  232. /*
  233. * View
  234. */
  235. llxHeader('',$langs->trans("Donations"),'EN:Module_Donations|FR:Module_Dons|ES:M&oacute;dulo_Donaciones');
  236. $form=new Form($db);
  237. $formfile = new FormFile($db);
  238. $formcompany = new FormCompany($db);
  239. if ($action == 'create')
  240. {
  241. print_fiche_titre($langs->trans("AddDonation"));
  242. print '<form name="add" action="' . $_SERVER["PHP_SELF"] . '" method="POST">';
  243. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  244. print '<input type="hidden" name="action" value="add">';
  245. dol_fiche_head('');
  246. print '<table class="border" width="100%">';
  247. print '<tbody>';
  248. $nbrows=11;
  249. if (! empty($conf->projet->enabled)) $nbrows++;
  250. // Date
  251. print '<tr><td class="fieldrequired" width="25%">'.$langs->trans("Date").'</td><td>';
  252. $form->select_date($donation_date?$donation_date:-1,'','','','',"add",1,1);
  253. print '</td>';
  254. // Amount
  255. print "<tr>".'<td class="fieldrequired">'.$langs->trans("Amount").'</td><td><input type="text" name="amount" value="'.GETPOST("amount").'" size="10"> '.$langs->trans("Currency".$conf->currency).'</td></tr>';
  256. print '<tr><td class="fieldrequired">'.$langs->trans("PublicDonation")."</td><td>";
  257. print $form->selectyesno("public",isset($_POST["public"])?$_POST["public"]:1,1);
  258. print "</td></tr>\n";
  259. print "<tr>".'<td>'.$langs->trans("Company").'</td><td><input type="text" name="societe" value="'.GETPOST("societe").'" size="40"></td></tr>';
  260. print "<tr>".'<td>'.$langs->trans("Lastname").'</td><td><input type="text" name="lastname" value="'.GETPOST("lastname").'" size="40"></td></tr>';
  261. print "<tr>".'<td>'.$langs->trans("Firstname").'</td><td><input type="text" name="firstname" value="'.GETPOST("firstname").'" size="40"></td></tr>';
  262. print "<tr>".'<td>'.$langs->trans("Address").'</td><td>';
  263. print '<textarea name="address" wrap="soft" cols="40" rows="3">'.GETPOST("address").'</textarea></td></tr>';
  264. // Zip / Town
  265. print '<tr><td>'.$langs->trans("Zip").' / '.$langs->trans("Town").'</td><td>';
  266. print $formcompany->select_ziptown((isset($_POST["zipcode"])?$_POST["zipcode"]:$object->zip),'zipcode',array('town','selectcountry_id','state_id'),6);
  267. print ' ';
  268. print $formcompany->select_ziptown((isset($_POST["town"])?$_POST["town"]:$object->town),'town',array('zipcode','selectcountry_id','state_id'));
  269. print '</tr>';
  270. // Country
  271. print '<tr><td width="25%"><label for="selectcountry_id">'.$langs->trans('Country').'</label></td><td colspan="3" class="maxwidthonsmartphone">';
  272. print $form->select_country(GETPOST('country_id')!=''?GETPOST('country_id'):$object->country_id);
  273. if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
  274. print '</td></tr>';
  275. print "<tr>".'<td>'.$langs->trans("EMail").'</td><td><input type="text" name="email" value="'.GETPOST("email").'" size="40"></td></tr>';
  276. // Public note
  277. print '<tr>';
  278. print '<td class="border" valign="top">' . $langs->trans('NotePublic') . '</td>';
  279. print '<td valign="top" colspan="2">';
  280. $doleditor = new DolEditor('note_public', $note_public, '', 80, 'dolibarr_notes', 'In', 0, false, true, ROWS_3, 70);
  281. print $doleditor->Create(1);
  282. print '</td></tr>';
  283. // Private note
  284. if (empty($user->societe_id)) {
  285. print '<tr>';
  286. print '<td class="border" valign="top">' . $langs->trans('NotePrivate') . '</td>';
  287. print '<td valign="top" colspan="2">';
  288. $doleditor = new DolEditor('note_private', $note_private, '', 80, 'dolibarr_notes', 'In', 0, false, true, ROWS_3, 70);
  289. print $doleditor->Create(1);
  290. print '</td></tr>';
  291. }
  292. if (! empty($conf->projet->enabled))
  293. {
  294. $formproject=new FormProjets($db);
  295. print "<tr><td>".$langs->trans("Project")."</td><td>";
  296. $formproject->select_projects(-1, GETPOST("fk_projet"),'fk_projet', 0, 0, 1, 1);
  297. print "</td></tr>\n";
  298. }
  299. // Other attributes
  300. $parameters=array('colspan' => 3);
  301. $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
  302. if (empty($reshook) && ! empty($extrafields->attribute_label))
  303. {
  304. print $object->showOptionals($extrafields,'edit',$parameters);
  305. }
  306. print '</tbody>';
  307. print "</table>\n";
  308. dol_fiche_end();
  309. print '<div class="center"><input type="submit" class="button" name="save" value="'.$langs->trans("Save").'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'"></div>';
  310. print "</form>\n";
  311. }
  312. /* ************************************************************ */
  313. /* */
  314. /* Donation card in edit mode */
  315. /* */
  316. /* ************************************************************ */
  317. if (! empty($id) && $action == 'edit')
  318. {
  319. $result=$object->fetch($id);
  320. if ($result < 0) {
  321. dol_print_error($db,$object->error); exit;
  322. }
  323. $result=$object->fetch_optionals($object->id,$extralabels);
  324. if ($result < 0) {
  325. dol_print_error($db); exit;
  326. }
  327. $hselected='card';
  328. $head = donation_prepare_head($object);
  329. print '<form name="update" action="' . $_SERVER["PHP_SELF"] . '" method="POST">';
  330. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  331. print '<input type="hidden" name="action" value="update">';
  332. print '<input type="hidden" name="rowid" value="'.$object->id.'">';
  333. print '<input type="hidden" name="amount" value="'.$object->amount.'">';
  334. dol_fiche_head($head, $hselected, $langs->trans("Donation"), 0, 'generic');
  335. print '<table class="border" width="100%">';
  336. // Ref
  337. print "<tr>".'<td>'.$langs->trans("Ref").'</td><td colspan="2">';
  338. print $object->getNomUrl();
  339. print '</td>';
  340. print '</tr>';
  341. $nbrows=12;
  342. if (! empty($conf->projet->enabled)) $nbrows++;
  343. // Date
  344. print "<tr>".'<td width="25%" class="fieldrequired">'.$langs->trans("Date").'</td><td>';
  345. $form->select_date($object->date,'','','','',"update");
  346. print '</td>';
  347. // Amount
  348. if ($object->statut == 0)
  349. {
  350. print "<tr>".'<td class="fieldrequired">'.$langs->trans("Amount").'</td><td><input type="text" name="amount" size="10" value="'.$object->amount.'"> '.$langs->trans("Currency".$conf->currency).'</td></tr>';
  351. }
  352. else
  353. {
  354. print '<tr><td>'.$langs->trans("Amount").'</td><td colspan="2">';
  355. print price($object->amount,0,$langs,0,0,-1,$conf->currency);
  356. print '</td></tr>';
  357. }
  358. print '<tr><td class="fieldrequired">'.$langs->trans("PublicDonation")."</td><td>";
  359. print $form->selectyesno("public",1,1);
  360. print "</td>";
  361. print "</tr>\n";
  362. $langs->load("companies");
  363. print "<tr>".'<td>'.$langs->trans("Company").'</td><td><input type="text" name="societe" size="40" value="'.$object->societe.'"></td></tr>';
  364. print "<tr>".'<td>'.$langs->trans("Lastname").'</td><td><input type="text" name="lastname" size="40" value="'.$object->lastname.'"></td></tr>';
  365. print "<tr>".'<td>'.$langs->trans("Firstname").'</td><td><input type="text" name="firstname" size="40" value="'.$object->firstname.'"></td></tr>';
  366. print "<tr>".'<td>'.$langs->trans("Address").'</td><td>';
  367. print '<textarea name="address" wrap="soft" cols="40" rows="'.ROWS_3.'">'.$object->address.'</textarea></td></tr>';
  368. // Zip / Town
  369. print '<tr><td>'.$langs->trans("Zip").' / '.$langs->trans("Town").'</td><td>';
  370. print $formcompany->select_ziptown((isset($_POST["zipcode"])?$_POST["zipcode"]:$object->zip),'zipcode',array('town','selectcountry_id','state_id'),6);
  371. print ' ';
  372. print $formcompany->select_ziptown((isset($_POST["town"])?$_POST["town"]:$object->town),'town',array('zipcode','selectcountry_id','state_id'));
  373. print '</tr>';
  374. // Country
  375. print '<tr><td width="25%">'.$langs->trans('Country').'</td><td colspan="3">';
  376. print $form->select_country((!empty($object->country_id)?$object->country_id:$mysoc->country_code),'country_id');
  377. if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
  378. print '</td></tr>';
  379. print "<tr>".'<td>'.$langs->trans("EMail").'</td><td><input type="text" name="email" size="40" value="'.$object->email.'"></td></tr>';
  380. print "<tr><td>".$langs->trans("PaymentMode")."</td><td>\n";
  381. if ($object->modepaymentid) $selected = $object->modepaymentid;
  382. else $selected = '';
  383. $form->select_types_paiements($selected, 'modepayment', 'CRDT', 0, 1);
  384. print "</td></tr>\n";
  385. print "<tr>".'<td>'.$langs->trans("Status").'</td><td>'.$object->getLibStatut(4).'</td></tr>';
  386. // Project
  387. if (! empty($conf->projet->enabled))
  388. {
  389. $formproject=new FormProjets($db);
  390. $langs->load('projects');
  391. print '<tr><td>'.$langs->trans('Project').'</td><td>';
  392. $formproject->select_projects(-1, $object->fk_projet,'fk_projet', 0, 0, 1, 1);
  393. print '</td></tr>';
  394. }
  395. // Other attributes
  396. $parameters=array('colspan' => ' colspan="2"');
  397. $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
  398. if (empty($reshook) && ! empty($extrafields->attribute_label))
  399. {
  400. print $object->showOptionals($extrafields,'edit');
  401. }
  402. print "</table>\n";
  403. dol_fiche_end();
  404. 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>';
  405. print "</form>\n";
  406. }
  407. /* ************************************************************ */
  408. /* */
  409. /* Donation card in view mode */
  410. /* */
  411. /* ************************************************************ */
  412. if (! empty($id) && $action != 'edit')
  413. {
  414. // Confirmation delete
  415. if ($action == 'delete')
  416. {
  417. $text=$langs->trans("ConfirmDeleteADonation");
  418. print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id,$langs->trans("DeleteADonation"),$text,"confirm_delete",'','',1);
  419. }
  420. $result=$object->fetch($id);
  421. if ($result < 0) {
  422. dol_print_error($db,$object->error); exit;
  423. }
  424. $result=$object->fetch_optionals($object->id,$extralabels);
  425. if ($result < 0) {
  426. dol_print_error($db); exit;
  427. }
  428. $hselected='card';
  429. $head = donation_prepare_head($object);
  430. dol_fiche_head($head, $hselected, $langs->trans("Donation"), 0, 'generic');
  431. print '<form action="' . $_SERVER["PHP_SELF"] . '" method="POST">';
  432. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  433. print '<table class="border" width="100%">';
  434. $linkback = '<a href="'.DOL_URL_ROOT.'/don/list.php'.(! empty($socid)?'?socid='.$socid:'').'">'.$langs->trans("BackToList").'</a>';
  435. $nbrows=12;
  436. if (! empty($conf->projet->enabled)) $nbrows++;
  437. // Ref
  438. print "<tr>".'<td>'.$langs->trans("Ref").'</td><td colspan="2">';
  439. print $form->showrefnav($object, 'rowid', $linkback, 1, 'rowid', 'ref', '');
  440. print '</td>';
  441. print '</tr>';
  442. // Date
  443. print '<tr><td width="25%">'.$langs->trans("Date").'</td><td colspan="2">';
  444. print dol_print_date($object->date,"day");
  445. print "</td>";
  446. print '<tr><td>'.$langs->trans("Amount").'</td><td colspan="2">';
  447. print price($object->amount,0,$langs,0,0,-1,$conf->currency);
  448. print '</td></tr>';
  449. print '<tr><td>'.$langs->trans("PublicDonation").'</td><td colspan="2">';
  450. print yn($object->public);
  451. print '</td></tr>';
  452. print '<tr><td>'.$langs->trans("Company").'</td><td colspan="2">'.$object->societe.'</td></tr>';
  453. print '<tr><td>'.$langs->trans("Lastname").'</td><td colspan="2">'.$object->lastname.'</td></tr>';
  454. print '<tr><td>'.$langs->trans("Firstname").'</td><td colspan="2">'.$object->firstname.'</td></tr>';
  455. print '<tr><td>'.$langs->trans("Address").'</td><td>'.dol_nl2br($object->address).'</td>';
  456. $rowspan=6;
  457. if (! empty($conf->projet->enabled)) $rowspan++;
  458. print '<td rowspan="'.$rowspan.'" valign="top">';
  459. /*
  460. * Payments
  461. */
  462. $sql = "SELECT p.rowid, p.num_payment, p.datep as dp, p.amount,";
  463. $sql.= "c.code as type_code,c.libelle as paiement_type";
  464. $sql.= " FROM ".MAIN_DB_PREFIX."payment_donation as p";
  465. $sql.= ", ".MAIN_DB_PREFIX."c_paiement as c ";
  466. $sql.= ", ".MAIN_DB_PREFIX."don as d";
  467. $sql.= " WHERE d.rowid = '".$id."'";
  468. $sql.= " AND p.fk_donation = d.rowid";
  469. $sql.= " AND d.entity = ".$conf->entity;
  470. $sql.= " AND p.fk_typepayment = c.id";
  471. $sql.= " ORDER BY dp";
  472. //print $sql;
  473. $resql = $db->query($sql);
  474. if ($resql)
  475. {
  476. $num = $db->num_rows($resql);
  477. $i = 0; $total = 0;
  478. print '<table class="nobordernopadding" width="100%">';
  479. print '<tr class="liste_titre">';
  480. print '<td>'.$langs->trans("RefPayment").'</td>';
  481. print '<td>'.$langs->trans("Date").'</td>';
  482. print '<td>'.$langs->trans("Type").'</td>';
  483. print '<td align="right">'.$langs->trans("Amount").'</td>';
  484. print '<td>&nbsp;</td>';
  485. print '</tr>';
  486. $var=True;
  487. while ($i < $num)
  488. {
  489. $objp = $db->fetch_object($resql);
  490. $var=!$var;
  491. print "<tr ".$bc[$var]."><td>";
  492. print '<a href="'.DOL_URL_ROOT.'/don/payment/card.php?id='.$objp->rowid.'">'.img_object($langs->trans("Payment"),"payment").' '.$objp->rowid.'</a></td>';
  493. print '<td>'.dol_print_date($db->jdate($objp->dp),'day')."</td>\n";
  494. $labeltype=$langs->trans("PaymentType".$object->type_code)!=("PaymentType".$object->type_code)?$langs->trans("PaymentType".$object->type_code):$object->paiement_type;
  495. print "<td>".$labeltype.' '.$object->num_paiement."</td>\n";
  496. print '<td align="right">'.price($objp->amount)."</td><td>&nbsp;".$langs->trans("Currency".$conf->currency)."</td>\n";
  497. print "</tr>";
  498. $totalpaid += $objp->amount;
  499. $i++;
  500. }
  501. if ($object->paid == 0)
  502. {
  503. print "<tr><td colspan=\"2\" align=\"right\">".$langs->trans("AlreadyPaid")." :</td><td align=\"right\"><b>".price($totalpaid)."</b></td><td>&nbsp;".$langs->trans("Currency".$conf->currency)."</td></tr>\n";
  504. print "<tr><td colspan=\"2\" align=\"right\">".$langs->trans("AmountExpected")." :</td><td align=\"right\" bgcolor=\"#d0d0d0\">".price($object->amount)."</td><td bgcolor=\"#d0d0d0\">&nbsp;".$langs->trans("Currency".$conf->currency)."</td></tr>\n";
  505. $remaintopay = $object->amount - $totalpaid;
  506. print "<tr><td colspan=\"2\" align=\"right\">".$langs->trans("RemainderToPay")." :</td>";
  507. print "<td align=\"right\" bgcolor=\"#f0f0f0\"><b>".price($remaintopay)."</b></td><td bgcolor=\"#f0f0f0\">&nbsp;".$langs->trans("Currency".$conf->currency)."</td></tr>\n";
  508. }
  509. print "</table>";
  510. $db->free($resql);
  511. }
  512. else
  513. {
  514. dol_print_error($db);
  515. }
  516. print "</td>";
  517. print "</tr>";
  518. // Zip / Town
  519. print '<tr><td>'.$langs->trans("Zip").' / '.$langs->trans("Town").'</td><td>';
  520. print $object->zip.($object->zip && $object->town?' / ':'').$object->town.'</td></tr>';
  521. // Country
  522. print '<tr><td>'.$langs->trans('Country').'</td><td>';
  523. if (! empty($object->country_code))
  524. {
  525. $img=picto_from_langcode($object->country_code);
  526. print ($img?$img.' ':'');
  527. print $object->country;
  528. }
  529. else
  530. {
  531. print $object->country_olddata;
  532. }
  533. print '</td></tr>';
  534. // EMail
  535. print "<tr>".'<td>'.$langs->trans("EMail").'</td><td>'.dol_print_email($object->email).'</td></tr>';
  536. // Payment mode
  537. print "<tr><td>".$langs->trans("PaymentMode")."</td><td>";
  538. $form->form_modes_reglement(null, $object->modepaymentid,'none');
  539. print "</td></tr>\n";
  540. print "<tr>".'<td>'.$langs->trans("Status").'</td><td>'.$object->getLibStatut(4).'</td></tr>';
  541. // Project
  542. if (! empty($conf->projet->enabled))
  543. {
  544. print '<tr>';
  545. print '<td>'.$langs->trans("Project").'</td>';
  546. print '<td>';
  547. $object->fetch_projet();
  548. print $object->project->getNomUrl(4);
  549. print '</td>';
  550. print '</tr>';
  551. }
  552. // Other attributes
  553. $parameters=array('colspan' => ' colspan="2"');
  554. $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
  555. if (empty($reshook) && ! empty($extrafields->attribute_label))
  556. {
  557. print $object->showOptionals($extrafields);
  558. }
  559. print "</table>\n";
  560. print "</form>\n";
  561. print "</div>";
  562. $remaintopay = $object->amount - $totalpaid;
  563. /**
  564. * Actions buttons
  565. */
  566. print '<div class="tabsAction">';
  567. print '<div class="inline-block divButAction"><a class="butAction" href="' . $_SERVER["PHP_SELF"] . '?action=edit&rowid='.$object->id.'">'.$langs->trans('Modify').'</a></div>';
  568. if ($object->statut == 0)
  569. {
  570. print '<div class="inline-block divButAction"><a class="butAction" href="' . $_SERVER["PHP_SELF"] . '?rowid='.$object->id.'&action=valid_promesse">'.$langs->trans("ValidPromess").'</a></div>';
  571. }
  572. if (($object->statut == 0 || $object->statut == 1) && $remaintopay == 0 && $object->paye == 0)
  573. {
  574. print '<div class="inline-block divButAction"><a class="butAction" href="' . $_SERVER["PHP_SELF"] . '?rowid='.$object->id.'&action=set_cancel">'.$langs->trans("ClassifyCanceled")."</a></div>";
  575. }
  576. // Create payment
  577. if ($object->statut == 1 && $object->paid == 0 && $user->rights->don->creer)
  578. {
  579. if ($remaintopay == 0)
  580. {
  581. print '<div class="inline-block divButAction"><span class="butActionRefused" title="' . $langs->trans("DisabledBecauseRemainderToPayIsZero") . '">' . $langs->trans('DoPayment') . '</span></div>';
  582. }
  583. else
  584. {
  585. 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>';
  586. }
  587. }
  588. // Classify 'paid'
  589. if ($object->statut == 1 && round($remaintopay) == 0 && $object->paid == 0 && $user->rights->don->creer)
  590. {
  591. print '<div class="inline-block divButAction"><a class="butAction" href="' . $_SERVER["PHP_SELF"] . '?rowid='.$object->id.'&action=set_paid">'.$langs->trans("ClassifyPaid")."</a></div>";
  592. }
  593. // Delete
  594. if ($user->rights->don->supprimer)
  595. {
  596. if ($don->statut == -1 || $don->statut == 0)
  597. {
  598. print '<div class="inline-block divButAction"><a class="butActionDelete" href="card.php?rowid='.$don->id.'&action=delete">'.$langs->trans("Delete")."</a></div>";
  599. }
  600. else
  601. {
  602. print '<div class="inline-block divButAction"><a class="butActionDelete butActionRefused" href="#">'.$langs->trans("Delete")."</a></div>";
  603. }
  604. }
  605. else
  606. {
  607. print '<div class="inline-block divButAction"><a class="butActionRefused" href="#">'.$langs->trans("Delete")."</a></div>";
  608. }
  609. print "</div>";
  610. print '<table width="100%"><tr><td width="50%" valign="top">';
  611. /*
  612. * Documents generes
  613. */
  614. $filename=dol_sanitizeFileName($object->id);
  615. $filedir=$conf->don->dir_output . '/' . get_exdir($filename,2,0,1,$object,'donation'). '/'. dol_sanitizeFileName($object->ref);
  616. $urlsource=$_SERVER['PHP_SELF'].'?rowid='.$object->id;
  617. // $genallowed=($fac->statut == 1 && ($fac->paye == 0 || $user->admin) && $user->rights->facture->creer);
  618. // $delallowed=$user->rights->facture->supprimer;
  619. $genallowed=1;
  620. $delallowed=0;
  621. $var=true;
  622. print '<br>';
  623. $formfile->show_documents('donation',$filename,$filedir,$urlsource,$genallowed,$delallowed,$object->modelpdf);
  624. print '</td><td>&nbsp;</td>';
  625. print '</tr></table>';
  626. }
  627. llxFooter();
  628. $db->close();