card.php 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  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. require '../../main.inc.php';
  24. require_once DOL_DOCUMENT_ROOT.'/don/class/don.class.php';
  25. require_once DOL_DOCUMENT_ROOT.'/don/class/paymentdonation.class.php';
  26. require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
  27. require_once DOL_DOCUMENT_ROOT.'/core/modules/facture/modules_facture.php';
  28. if (!empty($conf->banque->enabled)) {
  29. require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
  30. }
  31. // Load translation files required by the page
  32. $langs->loadLangs(array("bills", "banks", "companies", "donations"));
  33. // Security check
  34. $id = GETPOST('rowid') ? GETPOST('rowid', 'int') : GETPOST('id', 'int');
  35. $action = GETPOST('action', 'aZ09');
  36. $confirm = GETPOST('confirm', 'alpha');
  37. if ($user->socid) {
  38. $socid = $user->socid;
  39. }
  40. // TODO Add rule to restrict access payment
  41. //$result = restrictedArea($user, 'facture', $id,'');
  42. $object = new PaymentDonation($db);
  43. if ($id > 0) {
  44. $result = $object->fetch($id);
  45. if (!$result) {
  46. dol_print_error($db, 'Failed to get payment id '.$id);
  47. }
  48. }
  49. /*
  50. * Actions
  51. */
  52. // Delete payment
  53. if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->don->supprimer) {
  54. $db->begin();
  55. $result = $object->delete($user);
  56. if ($result > 0) {
  57. $db->commit();
  58. header("Location: ".DOL_URL_ROOT."/don/index.php");
  59. exit;
  60. } else {
  61. setEventMessages($object->error, $object->errors, 'errors');
  62. $db->rollback();
  63. }
  64. }
  65. /*
  66. * View
  67. */
  68. llxHeader();
  69. $don = new Don($db);
  70. $form = new Form($db);
  71. $h = 0;
  72. $head = array();
  73. $head[$h][0] = DOL_URL_ROOT.'/don/payment/card.php?id='.$id;
  74. $head[$h][1] = $langs->trans("DonationPayment");
  75. $hselected = $h;
  76. $h++;
  77. print dol_get_fiche_head($head, $hselected, $langs->trans("DonationPayment"), -1, 'payment');
  78. /*
  79. * Confirm deleting of the payment
  80. */
  81. if ($action == 'delete') {
  82. print $form->formconfirm('card.php?id='.$object->id, $langs->trans("DeletePayment"), $langs->trans("ConfirmDeletePayment"), 'confirm_delete', '', 0, 2);
  83. }
  84. dol_banner_tab($object, 'id', '', 1, 'rowid', 'id');
  85. print '<div class="fichecenter">';
  86. print '<div class="underbanner clearboth"></div>';
  87. print '<table class="border centpercent">';
  88. // Date
  89. print '<tr><td class="titlefield">'.$langs->trans('Date').'</td><td>'.dol_print_date($object->datep, 'day').'</td></tr>';
  90. // Mode
  91. print '<tr><td>'.$langs->trans('Mode').'</td><td>'.$langs->trans("PaymentType".$object->type_code).'</td></tr>';
  92. // Number
  93. print '<tr><td>'.$langs->trans('Numero').'</td><td>'.$object->num_payment.'</td></tr>';
  94. // Amount
  95. print '<tr><td>'.$langs->trans('Amount').'</td><td>'.price($object->amount, 0, $outputlangs, 1, -1, -1, $conf->currency).'</td></tr>';
  96. // Note public
  97. print '<tr><td>'.$langs->trans('Note').'</td><td>'.nl2br($object->note_public).'</td></tr>';
  98. // Bank account
  99. if (!empty($conf->banque->enabled)) {
  100. if ($object->bank_account) {
  101. $bankline = new AccountLine($db);
  102. $bankline->fetch($object->bank_line);
  103. print '<tr>';
  104. print '<td>'.$langs->trans('BankTransactionLine').'</td>';
  105. print '<td>';
  106. print $bankline->getNomUrl(1, 0, 'showall');
  107. print '</td>';
  108. print '</tr>';
  109. }
  110. }
  111. print '</table>';
  112. /*
  113. * List of donations paid
  114. */
  115. $disable_delete = 0;
  116. $sql = 'SELECT d.rowid as did, d.paid, d.amount as d_amount, pd.amount';
  117. $sql .= ' FROM '.MAIN_DB_PREFIX.'payment_donation as pd,'.MAIN_DB_PREFIX.'don as d';
  118. $sql .= ' WHERE pd.fk_donation = d.rowid';
  119. $sql .= ' AND d.entity = '.$conf->entity;
  120. $sql .= ' AND pd.rowid = '.((int) $id);
  121. dol_syslog("don/payment/card.php", LOG_DEBUG);
  122. $resql = $db->query($sql);
  123. if ($resql) {
  124. $num = $db->num_rows($resql);
  125. $i = 0;
  126. $total = 0;
  127. print '<br><table class="noborder centpercent">';
  128. print '<tr class="liste_titre">';
  129. print '<td>'.$langs->trans('Donation').'</td>';
  130. print '<td class="right">'.$langs->trans('ExpectedToPay').'</td>';
  131. print '<td class="center">'.$langs->trans('Status').'</td>';
  132. print '<td class="right">'.$langs->trans('PayedByThisPayment').'</td>';
  133. print "</tr>\n";
  134. if ($num > 0) {
  135. while ($i < $num) {
  136. $objp = $db->fetch_object($resql);
  137. print '<tr class="oddeven">';
  138. // Ref
  139. print '<td>';
  140. $don->fetch($objp->did);
  141. print $don->getNomUrl(1);
  142. print "</td>\n";
  143. // Expected to pay
  144. print '<td class="right">'.price($objp->d_amount).'</td>';
  145. // Status
  146. print '<td class="center">'.$don->getLibStatut(4, $objp->amount).'</td>';
  147. // Amount paid
  148. print '<td class="right">'.price($objp->amount).'</td>';
  149. print "</tr>\n";
  150. if ($objp->paid == 1) {
  151. // If at least one invoice is paid, disable delete
  152. $disable_delete = 1;
  153. }
  154. $total = $total + $objp->amount;
  155. $i++;
  156. }
  157. }
  158. print "</table>\n";
  159. $db->free($resql);
  160. } else {
  161. dol_print_error($db);
  162. }
  163. print '</div>';
  164. print dol_get_fiche_end();
  165. /*
  166. * Actions buttons
  167. */
  168. print '<div class="tabsAction">';
  169. if (empty($action)) {
  170. if ($user->rights->don->supprimer) {
  171. if (!$disable_delete) {
  172. print '<a class="butActionDelete" href="card.php?id='.$object->id.'&amp;action=delete&token='.newToken().'">'.$langs->trans('Delete').'</a>';
  173. } else {
  174. print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("CantRemovePaymentWithOneInvoicePaid")).'">'.$langs->trans('Delete').'</a>';
  175. }
  176. }
  177. }
  178. print '</div>';
  179. llxFooter();
  180. $db->close();