card.php 6.6 KB

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