card.php 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  1. <?php
  2. /* Copyright (C) 2015-2017 Alexandre Spangaro <aspangaro.dolibarr@gmail.com>
  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 <http://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. require '../../main.inc.php';
  23. require_once DOL_DOCUMENT_ROOT.'/expensereport/class/expensereport.class.php';
  24. require_once DOL_DOCUMENT_ROOT.'/expensereport/class/paymentexpensereport.class.php';
  25. require_once DOL_DOCUMENT_ROOT.'/core/modules/expensereport/modules_expensereport.php';
  26. require_once DOL_DOCUMENT_ROOT.'/core/lib/expensereport.lib.php';
  27. if (! empty($conf->banque->enabled)) require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
  28. $langs->load('bills');
  29. $langs->load('banks');
  30. $langs->load('companies');
  31. $langs->load('trips');
  32. $id=GETPOST('rowid')?GETPOST('rowid','int'):GETPOST('id','int');
  33. $action=GETPOST('action','aZ09');
  34. $confirm=GETPOST('confirm');
  35. // Security check
  36. if ($user->societe_id) $socid=$user->societe_id;
  37. // TODO Add rule to restrict access payment
  38. //$result = restrictedArea($user, 'facture', $id,'');
  39. $object = new PaymentExpenseReport($db);
  40. /*
  41. * Actions
  42. */
  43. // Delete payment
  44. if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->expensereport->supprimer)
  45. {
  46. $db->begin();
  47. $result = $object->delete($user);
  48. if ($result > 0)
  49. {
  50. $db->commit();
  51. header("Location: ".DOL_URL_ROOT."/expensereport/index.php");
  52. exit;
  53. }
  54. else
  55. {
  56. setEventMessages($object->error, $object->errors, 'errors');
  57. $db->rollback();
  58. }
  59. }
  60. // Create payment
  61. if ($action == 'confirm_valide' && $confirm == 'yes' && $user->rights->expensereport->creer)
  62. {
  63. $db->begin();
  64. $result=$object->valide();
  65. if ($result > 0)
  66. {
  67. $db->commit();
  68. $factures=array(); // TODO Get all id of invoices linked to this payment
  69. foreach($factures as $id)
  70. {
  71. $fac = new Facture($db);
  72. $fac->fetch($id);
  73. $outputlangs = $langs;
  74. if (! empty($_REQUEST['lang_id']))
  75. {
  76. $outputlangs = new Translate("",$conf);
  77. $outputlangs->setDefaultLang($_REQUEST['lang_id']);
  78. }
  79. if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
  80. $fac->generateDocument($fac->modelpdf, $outputlangs);
  81. }
  82. }
  83. header('Location: card.php?id='.$object->id);
  84. exit;
  85. }
  86. else
  87. {
  88. setEventMessages($object->error, $object->errors, 'errors');
  89. $db->rollback();
  90. }
  91. }
  92. /*
  93. * View
  94. */
  95. llxHeader('', $langs->trans("ExpenseReportPayment"));
  96. if ($id > 0)
  97. {
  98. $result=$object->fetch($id);
  99. if (! $result) dol_print_error($db,'Failed to get payment id '.$id);
  100. }
  101. $form = new Form($db);
  102. $head = payment_expensereport_prepare_head($object);
  103. dol_fiche_head($head, 'payment', $langs->trans("ExpenseReportPayment"), -1, 'payment');
  104. /*
  105. * Confirm deleting of the payment
  106. */
  107. if ($action == 'delete')
  108. {
  109. print $form->formconfirm('card.php?id='.$object->id, $langs->trans("DeletePayment"), $langs->trans("ConfirmDeletePayment"), 'confirm_delete','',0,2);
  110. }
  111. /*
  112. * Confirm validation of the payment
  113. */
  114. if ($action == 'valide')
  115. {
  116. $facid = $_GET['facid'];
  117. print $form->formconfirm($_SERVER['PHP_SELF'].'?id='.$object->id.'&amp;facid='.$facid, $langs->trans("ValidatePayment"), $langs->trans("ConfirmValidatePayment"), 'confirm_valide','',0,2);
  118. }
  119. $linkback = '';
  120. // $linkback = '<a href="' . DOL_URL_ROOT . '/expensereport/payment/list.php">' . $langs->trans("BackToList") . '</a>';
  121. dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', '');
  122. print '<div class="fichecenter">';
  123. print '<div class="underbanner clearboth"></div>';
  124. print '<table class="border centpercent">'."\n";
  125. // Date payment
  126. print '<tr><td class="titlefield">'.$langs->trans('Date').'</td><td colspan="3">'.dol_print_date($object->datep,'day').'</td></tr>';
  127. // Mode
  128. print '<tr><td>'.$langs->trans('PaymentMode').'</td><td colspan="3">'.$langs->trans("PaymentType".$object->type_code).'</td></tr>';
  129. // Number
  130. print '<tr><td>'.$langs->trans('Numero').'</td><td colspan="3">'.$object->num_payment.'</td></tr>';
  131. // Amount
  132. print '<tr><td>'.$langs->trans('Amount').'</td><td colspan="3">'.price($object->amount, 0, $outputlangs, 1, -1, -1, $conf->currency).'</td></tr>';
  133. // Note
  134. print '<tr><td class="tdtop">'.$langs->trans('Note').'</td><td colspan="3">'.nl2br($object->note).'</td></tr>';
  135. $disable_delete = 0;
  136. // Bank account
  137. if (! empty($conf->banque->enabled))
  138. {
  139. if ($object->bank_account)
  140. {
  141. $bankline=new AccountLine($db);
  142. $bankline->fetch($object->bank_line);
  143. if ($bankline->rappro)
  144. {
  145. $disable_delete = 1;
  146. $title_button = dol_escape_htmltag($langs->transnoentitiesnoconv("CantRemoveConciliatedPayment"));
  147. }
  148. print '<tr>';
  149. print '<td>'.$langs->trans('BankTransactionLine').'</td>';
  150. print '<td colspan="3">';
  151. print $bankline->getNomUrl(1,0,'showconciliated');
  152. print '</td>';
  153. print '</tr>';
  154. print '<tr>';
  155. print '<td>'.$langs->trans('BankAccount').'</td>';
  156. print '<td colspan="3">';
  157. $accountstatic=new Account($db);
  158. $accountstatic->fetch($bankline->fk_account);
  159. print $accountstatic->getNomUrl(1);
  160. print '</td>';
  161. print '</tr>';
  162. }
  163. }
  164. print '</table>';
  165. print '</div>';
  166. dol_fiche_end();
  167. /*
  168. * List of expense report paid
  169. */
  170. $sql = 'SELECT er.rowid as eid, er.paid, er.total_ttc, per.amount';
  171. $sql.= ' FROM '.MAIN_DB_PREFIX.'payment_expensereport as per,'.MAIN_DB_PREFIX.'expensereport as er';
  172. $sql.= ' WHERE per.fk_expensereport = er.rowid';
  173. $sql.= ' AND er.entity IN ('.getEntity('expensereport', 1).')';
  174. $sql.= ' AND per.rowid = '.$id;
  175. dol_syslog("expensereport/payment/card.php", LOG_DEBUG);
  176. $resql=$db->query($sql);
  177. if ($resql)
  178. {
  179. $num = $db->num_rows($resql);
  180. $i = 0;
  181. $total = 0;
  182. print '<br>';
  183. print '<div class="div-table-responsive">';
  184. print '<table class="noborder" width="100%">';
  185. print '<tr class="liste_titre">';
  186. print '<td>'.$langs->trans('ExpenseReport').'</td>';
  187. print '<td align="right">'.$langs->trans('ExpectedToPay').'</td>';
  188. print '<td align="right">'.$langs->trans('PayedByThisPayment').'</td>';
  189. print '<td align="right">'.$langs->trans('RemainderToPay').'</td>';
  190. print '<td align="center">'.$langs->trans('Status').'</td>';
  191. print "</tr>\n";
  192. if ($num > 0)
  193. {
  194. $var=True;
  195. while ($i < $num)
  196. {
  197. $objp = $db->fetch_object($resql);
  198. print '<tr class="oddeven">';
  199. $expensereport=new ExpenseReport($db);
  200. $expensereport->fetch($objp->eid);
  201. // Expense report
  202. print '<td>';
  203. print $expensereport->getNomUrl(1);
  204. print "</td>\n";
  205. // Expected to pay
  206. print '<td align="right">'.price($objp->total_ttc).'</td>';
  207. // Amount paid
  208. print '<td align="right">'.price($objp->amount).'</td>';
  209. // Remain to pay
  210. print '<td align="right">'.price($remaintopay).'</td>';
  211. // Status
  212. print '<td align="center">'.$expensereport->getLibStatut(4,$objp->amount).'</td>';
  213. print "</tr>\n";
  214. if ($objp->paid == 1) // If at least one invoice is paid, disable delete
  215. {
  216. $disable_delete = 1;
  217. }
  218. $total = $total + $objp->amount;
  219. $i++;
  220. }
  221. }
  222. print "</table>\n";
  223. print '</div>';
  224. $db->free($resql);
  225. }
  226. else
  227. {
  228. dol_print_error($db);
  229. }
  230. print '</div>';
  231. /*
  232. * Actions buttons
  233. */
  234. print '<div class="tabsAction">';
  235. if ($action == '')
  236. {
  237. if ($user->rights->expensereport->supprimer)
  238. {
  239. if (! $disable_delete)
  240. {
  241. print '<a class="butActionDelete" href="'.$_SERVER['PHP_SELF'].'?id='.$id.'&amp;action=delete">'.$langs->trans('Delete').'</a>';
  242. }
  243. else
  244. {
  245. print '<a class="butActionRefused" href="#" title="'.dol_escape_htmltag($langs->trans("CantRemovePaymentWithOneInvoicePaid")).'">'.$langs->trans('Delete').'</a>';
  246. }
  247. }
  248. }
  249. print '</div>';
  250. llxFooter();
  251. $db->close();