fiche-stat.php 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. <?php
  2. /* Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2005 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2010-2012 Juanjo Menent <jmenent@2byte.es>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  18. */
  19. /**
  20. * \file htdocs/compta/prelevement/fiche-stat.php
  21. * \ingroup prelevement
  22. * \brief Debit order or credit transfer statistics
  23. */
  24. // Load Dolibarr environment
  25. require '../../main.inc.php';
  26. require_once DOL_DOCUMENT_ROOT.'/core/lib/prelevement.lib.php';
  27. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  28. require_once DOL_DOCUMENT_ROOT.'/compta/prelevement/class/bonprelevement.class.php';
  29. require_once DOL_DOCUMENT_ROOT.'/compta/prelevement/class/ligneprelevement.class.php';
  30. require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
  31. // Load translation files required by the page
  32. $langs->loadLangs(array("banks", "categories", 'withdrawals', 'bills'));
  33. // Get supervariables
  34. $id = GETPOST('id', 'int');
  35. $ref = GETPOST('ref', 'alpha');
  36. $type = GETPOST('type', 'aZ09');
  37. // Load variable for pagination
  38. $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
  39. $sortfield = GETPOST('sortfield', 'aZ09comma');
  40. $sortorder = GETPOST('sortorder', 'aZ09comma');
  41. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  42. if (empty($page) || $page == -1) {
  43. $page = 0;
  44. } // If $page is not defined, or '' or -1
  45. $offset = $limit * $page;
  46. $pageprev = $page - 1;
  47. $pagenext = $page + 1;
  48. $object = new BonPrelevement($db);
  49. // Load object
  50. include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not include_once // Must be include, not include_once. Include fetch and fetch_thirdparty but not fetch_optionals
  51. // Security check
  52. if ($user->socid > 0) {
  53. accessforbidden();
  54. }
  55. $type = $object->type;
  56. if ($type == 'bank-transfer') {
  57. $result = restrictedArea($user, 'paymentbybanktransfer', '', '', '');
  58. } else {
  59. $result = restrictedArea($user, 'prelevement', '', '', 'bons');
  60. }
  61. /*
  62. * View
  63. */
  64. $form = new Form($db);
  65. llxHeader('', $langs->trans("WithdrawalsReceipts"));
  66. if ($id > 0 || $ref) {
  67. if ($object->fetch($id, $ref) >= 0) {
  68. $head = prelevement_prepare_head($object);
  69. print dol_get_fiche_head($head, 'statistics', $langs->trans("WithdrawalsReceipts"), -1, 'payment');
  70. $linkback = '<a href="'.DOL_URL_ROOT.'/compta/prelevement/orders_list.php?restore_lastsearch_values=1'.($object->type != 'bank-transfer' ? '' : '&type=bank-transfer').'">'.$langs->trans("BackToList").'</a>';
  71. dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref');
  72. print '<div class="fichecenter">';
  73. print '<div class="underbanner clearboth"></div>';
  74. print '<table class="border centpercent tableforfield">'."\n";
  75. //print '<tr><td class="titlefieldcreate">'.$langs->trans("Ref").'</td><td>'.$object->getNomUrl(1).'</td></tr>';
  76. print '<tr><td class="titlefieldcreate">'.$langs->trans("Date").'</td><td>'.dol_print_date($object->datec, 'day').'</td></tr>';
  77. print '<tr><td>'.$langs->trans("Amount").'</td><td><span class="amount">'.price($object->amount).'</span></td></tr>';
  78. if (!empty($object->date_trans)) {
  79. $muser = new User($db);
  80. $muser->fetch($object->user_trans);
  81. print '<tr><td>'.$langs->trans("TransData").'</td><td>';
  82. print dol_print_date($object->date_trans, 'day');
  83. print ' &nbsp; <span class="opacitymedium">'.$langs->trans("By").'</span> '.$muser->getNomUrl(-1).'</td></tr>';
  84. print '<tr><td>'.$langs->trans("TransMetod").'</td><td>';
  85. print $object->methodes_trans[$object->method_trans];
  86. print '</td></tr>';
  87. }
  88. if (!empty($object->date_credit)) {
  89. print '<tr><td>'.$langs->trans('CreditDate').'</td><td>';
  90. print dol_print_date($object->date_credit, 'day');
  91. print '</td></tr>';
  92. }
  93. print '</table>';
  94. print '<br>';
  95. print '<div class="underbanner clearboth"></div>';
  96. print '<table class="border centpercent tableforfield">';
  97. // Get bank account for the payment
  98. $acc = new Account($db);
  99. $fk_bank_account = $object->fk_bank_account;
  100. if (empty($fk_bank_account)) {
  101. $fk_bank_account = ($object->type == 'bank-transfer' ? getDolGlobalInt('PAYMENTBYBANKTRANSFER_ID_BANKACCOUNT') : getDolGlobalInt('PRELEVEMENT_ID_BANKACCOUNT'));
  102. }
  103. if ($fk_bank_account > 0) {
  104. $result = $acc->fetch($fk_bank_account);
  105. }
  106. $labelofbankfield = "BankToReceiveWithdraw";
  107. if ($object->type == 'bank-transfer') {
  108. $labelofbankfield = 'BankToPayCreditTransfer';
  109. }
  110. print '<tr><td class="titlefieldcreate">';
  111. print $form->textwithpicto($langs->trans("BankAccount"), $langs->trans($labelofbankfield));
  112. print '</td>';
  113. print '<td>';
  114. if ($acc->id > 0) {
  115. print $acc->getNomUrl(1);
  116. }
  117. print '</td>';
  118. print '</tr>';
  119. $modulepart = 'prelevement';
  120. if ($object->type == 'bank-transfer') {
  121. $modulepart = 'paymentbybanktransfer';
  122. }
  123. print '<tr><td class="titlefieldcreate">';
  124. $labelfororderfield = 'WithdrawalFile';
  125. if ($object->type == 'bank-transfer') {
  126. $labelfororderfield = 'CreditTransferFile';
  127. }
  128. print $langs->trans($labelfororderfield).'</td><td>';
  129. if (isModEnabled('multicompany')) {
  130. $labelentity = $conf->entity;
  131. $relativepath = 'receipts/'.$object->ref.'-'.$labelentity.'.xml';
  132. if ($type != 'bank-transfer') {
  133. $dir = $conf->prelevement->dir_output;
  134. } else {
  135. $dir = $conf->paymentbybanktransfer->dir_output;
  136. }
  137. if (!dol_is_file($dir.'/'.$relativepath)) { // For backward compatibility
  138. $relativepath = 'receipts/'.$object->ref.'.xml';
  139. }
  140. } else {
  141. $relativepath = 'receipts/'.$object->ref.'.xml';
  142. }
  143. print '<a data-ajax="false" href="'.DOL_URL_ROOT.'/document.php?type=text/plain&amp;modulepart='.$modulepart.'&amp;file='.urlencode($relativepath).'">'.$relativepath;
  144. print img_picto('', 'download', 'class="paddingleft"');
  145. print '</a>';
  146. print '</td></tr></table>';
  147. print '</div>';
  148. print dol_get_fiche_end();
  149. } else {
  150. dol_print_error($db);
  151. }
  152. /*
  153. * Stats
  154. */
  155. $line = new LignePrelevement($db);
  156. $sql = "SELECT sum(pl.amount), pl.statut";
  157. $sql .= " FROM ".MAIN_DB_PREFIX."prelevement_lignes as pl";
  158. $sql .= " WHERE pl.fk_prelevement_bons = ".((int) $object->id);
  159. $sql .= " GROUP BY pl.statut";
  160. $resql = $db->query($sql);
  161. if ($resql) {
  162. $num = $db->num_rows($resql);
  163. $i = 0;
  164. print load_fiche_titre($langs->trans("StatisticsByLineStatus"), '', '');
  165. print"\n<!-- debut table -->\n";
  166. print '<div class="div-table-responsive-no-min">'; // You can use div-table-responsive-no-min if you dont need reserved height for your table
  167. print '<table class="noborder centpercent">';
  168. print '<tr class="liste_titre">';
  169. print '<td>'.$langs->trans("Status").'</td><td class="right">'.$langs->trans("Amount").'</td><td class="right">%</td></tr>';
  170. while ($i < $num) {
  171. $row = $db->fetch_row($resql);
  172. print '<tr class="oddeven"><td>';
  173. print $line->LibStatut($row[1], 1);
  174. print '</td>';
  175. print '<td class="right"><span class="amount">';
  176. print price($row[0]);
  177. print '</span></td>';
  178. print '<td class="right">';
  179. if ($object->amount) {
  180. print round($row[0] / $object->amount * 100, 2)." %";
  181. }
  182. print '</td>';
  183. print "</tr>\n";
  184. $i++;
  185. }
  186. print "</table>";
  187. print "</div>";
  188. $db->free($resql);
  189. } else {
  190. print $db->error().' '.$sql;
  191. }
  192. }
  193. // End of page
  194. llxFooter();
  195. $db->close();