card.php 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. <?php
  2. /* Copyright (C) 2015-2017 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/expensereport/payment/card.php
  19. * \ingroup Expense Report
  20. * \brief Tab payment of an expense report
  21. */
  22. // Load Dolibarr environment
  23. require '../../main.inc.php';
  24. require_once DOL_DOCUMENT_ROOT.'/expensereport/class/expensereport.class.php';
  25. require_once DOL_DOCUMENT_ROOT.'/expensereport/class/paymentexpensereport.class.php';
  26. require_once DOL_DOCUMENT_ROOT.'/core/modules/expensereport/modules_expensereport.php';
  27. require_once DOL_DOCUMENT_ROOT.'/core/lib/expensereport.lib.php';
  28. if (isModEnabled("banque")) {
  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', 'trips'));
  33. $id = GETPOST('rowid') ?GETPOST('rowid', 'int') : GETPOST('id', 'int');
  34. $action = GETPOST('action', 'aZ09');
  35. $confirm = GETPOST('confirm');
  36. // Security check
  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 PaymentExpenseReport($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->expensereport->supprimer) {
  54. $db->begin();
  55. $result = $object->delete($user);
  56. if ($result > 0) {
  57. $db->commit();
  58. header("Location: ".DOL_URL_ROOT."/expensereport/index.php");
  59. exit;
  60. } else {
  61. setEventMessages($object->error, $object->errors, 'errors');
  62. $db->rollback();
  63. }
  64. }
  65. /*
  66. * View
  67. */
  68. llxHeader('', $langs->trans("ExpenseReportPayment"));
  69. $form = new Form($db);
  70. $head = payment_expensereport_prepare_head($object);
  71. print dol_get_fiche_head($head, 'payment', $langs->trans("ExpenseReportPayment"), -1, 'payment');
  72. /*
  73. * Confirm deleting of the payment
  74. */
  75. if ($action == 'delete') {
  76. print $form->formconfirm('card.php?id='.$object->id, $langs->trans("DeletePayment"), $langs->trans("ConfirmDeletePayment"), 'confirm_delete', '', 0, 2);
  77. }
  78. $linkback = '';
  79. // $linkback = '<a href="' . DOL_URL_ROOT . '/expensereport/payment/list.php">' . $langs->trans("BackToList") . '</a>';
  80. dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', '');
  81. print '<div class="fichecenter">';
  82. print '<div class="underbanner clearboth"></div>';
  83. print '<table class="border centpercent">'."\n";
  84. // Date payment
  85. print '<tr><td class="titlefield">'.$langs->trans('Date').'</td><td>'.dol_print_date($object->datep, 'day').'</td></tr>';
  86. // Mode
  87. print '<tr><td>'.$langs->trans('PaymentMode').'</td><td>'.$langs->trans("PaymentType".$object->type_code).'</td></tr>';
  88. // Number
  89. print '<tr><td>'.$langs->trans('Numero').'</td><td>'.dol_escape_htmltag($object->num_payment).'</td></tr>';
  90. // Amount
  91. print '<tr><td>'.$langs->trans('Amount').'</td><td>'.price($object->amount, 0, $outputlangs, 1, -1, -1, $conf->currency).'</td></tr>';
  92. // Note public
  93. print '<tr><td class="tdtop">'.$langs->trans('Note').'</td><td class="valeur sensiblehtmlcontent">'.dol_string_onlythesehtmltags(dol_htmlentitiesbr($object->note_public)).'</td></tr>';
  94. $disable_delete = 0;
  95. // Bank account
  96. if (isModEnabled("banque")) {
  97. if ($object->bank_account) {
  98. $bankline = new AccountLine($db);
  99. $bankline->fetch($object->bank_line);
  100. if ($bankline->rappro) {
  101. $disable_delete = 1;
  102. $title_button = dol_escape_htmltag($langs->transnoentitiesnoconv("CantRemoveConciliatedPayment"));
  103. }
  104. print '<tr>';
  105. print '<td>'.$langs->trans('BankTransactionLine').'</td>';
  106. print '<td colspan="3">';
  107. print $bankline->getNomUrl(1, 0, 'showconciliated');
  108. print '</td>';
  109. print '</tr>';
  110. print '<tr>';
  111. print '<td>'.$langs->trans('BankAccount').'</td>';
  112. print '<td colspan="3">';
  113. $accountstatic = new Account($db);
  114. $accountstatic->fetch($bankline->fk_account);
  115. print $accountstatic->getNomUrl(1);
  116. print '</td>';
  117. print '</tr>';
  118. }
  119. }
  120. print '</table>';
  121. print '</div>';
  122. print dol_get_fiche_end();
  123. /*
  124. * List of expense report paid
  125. */
  126. $sql = 'SELECT er.rowid as eid, er.paid, er.total_ttc, per.amount';
  127. $sql .= ' FROM '.MAIN_DB_PREFIX.'payment_expensereport as per,'.MAIN_DB_PREFIX.'expensereport as er';
  128. $sql .= ' WHERE per.fk_expensereport = er.rowid';
  129. $sql .= ' AND er.entity IN ('.getEntity('expensereport').')';
  130. $sql .= ' AND per.rowid = '.((int) $id);
  131. dol_syslog("expensereport/payment/card.php", LOG_DEBUG);
  132. $resql = $db->query($sql);
  133. if ($resql) {
  134. $num = $db->num_rows($resql);
  135. $i = 0;
  136. $total = 0;
  137. print '<br>';
  138. print '<div class="div-table-responsive">';
  139. print '<table class="noborder centpercent">';
  140. print '<tr class="liste_titre">';
  141. print '<td>'.$langs->trans('ExpenseReport').'</td>';
  142. print '<td class="right">'.$langs->trans('ExpectedToPay').'</td>';
  143. print '<td class="right">'.$langs->trans('PayedByThisPayment').'</td>';
  144. print '<td class="right">'.$langs->trans('RemainderToPay').'</td>';
  145. print '<td class="center">'.$langs->trans('Status').'</td>';
  146. print "</tr>\n";
  147. if ($num > 0) {
  148. while ($i < $num) {
  149. $objp = $db->fetch_object($resql);
  150. print '<tr class="oddeven">';
  151. $expensereport = new ExpenseReport($db);
  152. $expensereport->fetch($objp->eid);
  153. // Expense report
  154. print '<td>';
  155. print $expensereport->getNomUrl(1);
  156. print "</td>\n";
  157. // Expected to pay
  158. print '<td class="right">'.price($objp->total_ttc).'</td>';
  159. // Amount paid
  160. print '<td class="right">'.price($objp->amount).'</td>';
  161. // Remain to pay
  162. print '<td class="right">'.price($objp->total_ttc - $objp->amount).'</td>';
  163. // Status
  164. print '<td class="center">'.$expensereport->getLibStatut(4).'</td>';
  165. print "</tr>\n";
  166. if ($objp->paid == 1) { // If at least one invoice is paid, disable delete
  167. $disable_delete = 2;
  168. $title_button = $langs->trans("CantRemovePaymentWithOneInvoicePaid");
  169. }
  170. $total = $total + $objp->amount;
  171. $i++;
  172. }
  173. }
  174. print "</table>\n";
  175. print '</div>';
  176. $db->free($resql);
  177. } else {
  178. dol_print_error($db);
  179. }
  180. /*
  181. * Actions buttons
  182. */
  183. print '<div class="tabsAction">';
  184. // Delete
  185. if ($action == '') {
  186. if ($user->rights->expensereport->supprimer) {
  187. if (!$disable_delete) {
  188. print dolGetButtonAction($langs->trans("Delete"), '', 'delete', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken(), 'delete', 1);
  189. } else {
  190. print dolGetButtonAction($title_button, $langs->trans("Delete"), 'delete', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken(), 'delete', 0);
  191. }
  192. }
  193. }
  194. print '</div>';
  195. // End of page
  196. llxFooter();
  197. $db->close();