card.php 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. <?php
  2. /* Copyright (C) 2015 Alexandre Spangaro <aspangaro@open-dsi.fr>
  3. * Copyright (C) 2019 Frédéric France <frederic.france@netlogic.fr>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  17. */
  18. /**
  19. * \file htdocs/don/payment/card.php
  20. * \ingroup donations
  21. * \brief Tab payment of a donation
  22. */
  23. // Load Dolibarr environment
  24. require '../../main.inc.php';
  25. require_once DOL_DOCUMENT_ROOT.'/don/class/don.class.php';
  26. require_once DOL_DOCUMENT_ROOT.'/don/class/paymentdonation.class.php';
  27. require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
  28. require_once DOL_DOCUMENT_ROOT.'/core/modules/facture/modules_facture.php';
  29. if (isModEnabled("banque")) {
  30. require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
  31. }
  32. // Load translation files required by the page
  33. $langs->loadLangs(array("bills", "banks", "companies", "donations"));
  34. // Security check
  35. $id = GETPOST('rowid') ? GETPOST('rowid', 'int') : GETPOST('id', 'int');
  36. $action = GETPOST('action', 'aZ09');
  37. $confirm = GETPOST('confirm', 'alpha');
  38. if ($user->socid) {
  39. $socid = $user->socid;
  40. }
  41. // TODO Add rule to restrict access payment
  42. //$result = restrictedArea($user, 'facture', $id,'');
  43. $object = new PaymentDonation($db);
  44. if ($id > 0) {
  45. $result = $object->fetch($id);
  46. if (!$result) {
  47. dol_print_error($db, 'Failed to get payment id '.$id);
  48. }
  49. }
  50. /*
  51. * Actions
  52. */
  53. // Delete payment
  54. if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->don->supprimer) {
  55. $db->begin();
  56. $result = $object->delete($user);
  57. if ($result > 0) {
  58. $db->commit();
  59. header("Location: ".DOL_URL_ROOT."/don/index.php");
  60. exit;
  61. } else {
  62. setEventMessages($object->error, $object->errors, 'errors');
  63. $db->rollback();
  64. }
  65. }
  66. /*
  67. * View
  68. */
  69. llxHeader();
  70. $don = new Don($db);
  71. $form = new Form($db);
  72. $h = 0;
  73. $head = array();
  74. $head[$h][0] = DOL_URL_ROOT.'/don/payment/card.php?id='.$id;
  75. $head[$h][1] = $langs->trans("DonationPayment");
  76. $hselected = $h;
  77. $h++;
  78. print dol_get_fiche_head($head, $hselected, $langs->trans("DonationPayment"), -1, 'payment');
  79. /*
  80. * Confirm deleting of the payment
  81. */
  82. if ($action == 'delete') {
  83. print $form->formconfirm('card.php?id='.$object->id, $langs->trans("DeletePayment"), $langs->trans("ConfirmDeletePayment"), 'confirm_delete', '', 0, 2);
  84. }
  85. dol_banner_tab($object, 'id', '', 1, 'rowid', 'id');
  86. print '<div class="fichecenter">';
  87. print '<div class="underbanner clearboth"></div>';
  88. print '<table class="border centpercent">';
  89. // Date
  90. print '<tr><td class="titlefield">'.$langs->trans('Date').'</td><td>'.dol_print_date($object->datep, 'day').'</td></tr>';
  91. // Mode
  92. print '<tr><td>'.$langs->trans('Mode').'</td><td>'.$langs->trans("PaymentType".$object->type_code).'</td></tr>';
  93. // Number
  94. print '<tr><td>'.$langs->trans('Numero').'</td><td>'.dol_escape_htmltag($object->num_payment).'</td></tr>';
  95. // Amount
  96. print '<tr><td>'.$langs->trans('Amount').'</td><td>'.price($object->amount, 0, $outputlangs, 1, -1, -1, $conf->currency).'</td></tr>';
  97. // Note public
  98. print '<tr><td>'.$langs->trans('Note').'</td><td class="valeur sensiblehtmlcontent">'.dol_string_onlythesehtmltags(dol_htmlcleanlastbr($object->note_public)).'</td></tr>';
  99. // Bank account
  100. if (isModEnabled("banque")) {
  101. if ($object->bank_account) {
  102. $bankline = new AccountLine($db);
  103. $bankline->fetch($object->bank_line);
  104. print '<tr>';
  105. print '<td>'.$langs->trans('BankTransactionLine').'</td>';
  106. print '<td>';
  107. print $bankline->getNomUrl(1, 0, 'showall');
  108. print '</td>';
  109. print '</tr>';
  110. }
  111. }
  112. print '</table>';
  113. /*
  114. * List of donations paid
  115. */
  116. $disable_delete = 0;
  117. $sql = 'SELECT d.rowid as did, d.paid, d.amount as d_amount, pd.amount';
  118. $sql .= ' FROM '.MAIN_DB_PREFIX.'payment_donation as pd,'.MAIN_DB_PREFIX.'don as d';
  119. $sql .= ' WHERE pd.fk_donation = d.rowid';
  120. $sql .= ' AND d.entity = '.$conf->entity;
  121. $sql .= ' AND pd.rowid = '.((int) $id);
  122. dol_syslog("don/payment/card.php", LOG_DEBUG);
  123. $resql = $db->query($sql);
  124. if ($resql) {
  125. $num = $db->num_rows($resql);
  126. $i = 0;
  127. $total = 0;
  128. print '<br><table class="noborder centpercent">';
  129. print '<tr class="liste_titre">';
  130. print '<td>'.$langs->trans('Donation').'</td>';
  131. print '<td class="right">'.$langs->trans('ExpectedToPay').'</td>';
  132. print '<td class="center">'.$langs->trans('Status').'</td>';
  133. print '<td class="right">'.$langs->trans('PayedByThisPayment').'</td>';
  134. print "</tr>\n";
  135. if ($num > 0) {
  136. while ($i < $num) {
  137. $objp = $db->fetch_object($resql);
  138. print '<tr class="oddeven">';
  139. // Ref
  140. print '<td>';
  141. $don->fetch($objp->did);
  142. print $don->getNomUrl(1);
  143. print "</td>\n";
  144. // Expected to pay
  145. print '<td class="right">'.price($objp->d_amount).'</td>';
  146. // Status
  147. print '<td class="center">'.$don->getLibStatut(4).'</td>';
  148. // Amount paid
  149. print '<td class="right">'.price($objp->amount).'</td>';
  150. print "</tr>\n";
  151. if ($objp->paid == 1) {
  152. // If at least one invoice is paid, disable delete
  153. $disable_delete = 1;
  154. }
  155. $total = $total + $objp->amount;
  156. $i++;
  157. }
  158. }
  159. print "</table>\n";
  160. $db->free($resql);
  161. } else {
  162. dol_print_error($db);
  163. }
  164. print '</div>';
  165. print dol_get_fiche_end();
  166. /*
  167. * Actions buttons
  168. */
  169. print '<div class="tabsAction">';
  170. if (empty($action)) {
  171. if ($user->rights->don->supprimer) {
  172. if (!$disable_delete) {
  173. print dolGetButtonAction($langs->trans('Delete'), '', 'delete', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken(), '', 1);
  174. } else {
  175. print dolGetButtonAction($langs->trans("CantRemovePaymentWithOneInvoicePaid"), $langs->trans('Delete'), 'delete', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken(), '', 1);
  176. }
  177. }
  178. }
  179. print '</div>';
  180. llxFooter();
  181. $db->close();