account_statement_document.php 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. <?php
  2. /* Copyright (C) 2003-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2008 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005 Marc Barilley / Ocebo <marc@ocebo.com>
  5. * Copyright (C) 2005-2017 Regis Houssin <regis.houssin@inodbox.com>
  6. * Copyright (C) 2019 Nicolas ZABOURI <info@inovea-conseil.com>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  20. */
  21. /**
  22. * \file htdocs/compta/bank/document.php
  23. * \ingroup banque
  24. * \brief Page de gestion des documents attaches a un compte bancaire
  25. */
  26. require '../../main.inc.php';
  27. require_once DOL_DOCUMENT_ROOT."/core/lib/bank.lib.php";
  28. require_once DOL_DOCUMENT_ROOT."/core/lib/files.lib.php";
  29. require_once DOL_DOCUMENT_ROOT."/core/lib/images.lib.php";
  30. require_once DOL_DOCUMENT_ROOT."/core/class/html.formfile.class.php";
  31. require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
  32. global $conf, $db, $langs;
  33. // Load translation files required by the page
  34. $langs->loadLangs(array('banks', 'companies', 'other'));
  35. $id = (GETPOST('id', 'int') ? GETPOST('id', 'int') : GETPOST('account', 'int'));
  36. $ref = GETPOST('ref', 'alpha');
  37. $action = GETPOST('action', 'aZ09');
  38. $confirm = GETPOST('confirm', 'alpha');
  39. $numref = (GETPOST('num', 'alpha') ? GETPOST('num', 'alpha') : GETPOST('sectionid', 'alpha'));
  40. // Security check
  41. if ($user->socid) {
  42. $action = '';
  43. $socid = $user->socid;
  44. }
  45. if ($user->socid) {
  46. $socid = $user->socid;
  47. }
  48. // Get parameters
  49. $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
  50. $sortfield = GETPOST("sortfield", 'alpha');
  51. $sortorder = GETPOST("sortorder", 'alpha');
  52. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  53. if (empty($page) || $page == -1) {
  54. $page = 0;
  55. }
  56. $offset = $limit * $page;
  57. $pageprev = $page - 1;
  58. $pagenext = $page + 1;
  59. if (!$sortorder) {
  60. $sortorder = "ASC";
  61. }
  62. if (!$sortfield) {
  63. $sortfield = "name";
  64. }
  65. $object = new Account($db);
  66. if ($id > 0 || !empty($ref)) {
  67. $result = $object->fetch($id, $ref);
  68. $account = $object->id; // Force the search field on id of account
  69. }
  70. $result = restrictedArea($user, 'banque', $object->id, 'bank_account', '', '');
  71. // Define number of receipt to show (current, previous or next one ?)
  72. $found = false;
  73. if (GETPOST("rel") == 'prev') {
  74. // Recherche valeur pour num = numero releve precedent
  75. $sql = "SELECT DISTINCT(b.num_releve) as num";
  76. $sql .= " FROM ".MAIN_DB_PREFIX."bank as b";
  77. $sql .= " WHERE b.num_releve < '".$db->escape($numref)."'";
  78. $sql .= " AND b.fk_account = ".((int) $id);
  79. $sql .= " ORDER BY b.num_releve DESC";
  80. dol_syslog("htdocs/compta/bank/releve.php", LOG_DEBUG);
  81. $resql = $db->query($sql);
  82. if ($resql) {
  83. $numrows = $db->num_rows($resql);
  84. if ($numrows > 0) {
  85. $obj = $db->fetch_object($resql);
  86. $numref = $obj->num;
  87. $found = true;
  88. }
  89. }
  90. } elseif (GETPOST("rel") == 'next') {
  91. // Recherche valeur pour num = numero releve precedent
  92. $sql = "SELECT DISTINCT(b.num_releve) as num";
  93. $sql .= " FROM ".MAIN_DB_PREFIX."bank as b";
  94. $sql .= " WHERE b.num_releve > '".$db->escape($numref)."'";
  95. $sql .= " AND b.fk_account = ".((int) $id);
  96. $sql .= " ORDER BY b.num_releve ASC";
  97. dol_syslog("htdocs/compta/bank/releve.php", LOG_DEBUG);
  98. $resql = $db->query($sql);
  99. if ($resql) {
  100. $numrows = $db->num_rows($resql);
  101. if ($numrows > 0) {
  102. $obj = $db->fetch_object($resql);
  103. $numref = $obj->num;
  104. $found = true;
  105. }
  106. }
  107. } else {
  108. // On veut le releve num
  109. $found = true;
  110. }
  111. $permissiontoadd = $user->rights->banque->modifier; // Used by the include of actions_dellink.inc.php
  112. /*
  113. * Actions
  114. */
  115. if (!empty($numref)) {
  116. $object->fetch_thirdparty();
  117. $upload_dir = $conf->bank->dir_output."/".$id."/statement/".dol_sanitizeFileName($numref);
  118. }
  119. $backtopage = $_SERVER['PHP_SELF']."?account=".urlencode($id)."&num=".urlencode($numref);
  120. include DOL_DOCUMENT_ROOT.'/core/actions_linkedfiles.inc.php';
  121. /*
  122. * View
  123. */
  124. $form = new Form($db);
  125. $title = $langs->trans("FinancialAccount").' - '.$langs->trans("Documents");
  126. $helpurl = "";
  127. llxHeader('', $title, $helpurl);
  128. if ($id > 0 || !empty($ref)) {
  129. if ($object->fetch($id, $ref)) {
  130. $upload_dir = $conf->bank->dir_output."/".$id."/statement/".dol_sanitizeFileName($numref);
  131. // Onglets
  132. $head = account_statement_prepare_head($object, $numref);
  133. print dol_get_fiche_head($head, 'document', $langs->trans("AccountStatement"), -1, 'account');
  134. // Build file list
  135. $filearray = dol_dir_list($upload_dir, "files", 0, '', '\.meta$', $sortfield, (strtolower($sortorder) == 'desc' ? SORT_DESC : SORT_ASC), 1);
  136. $totalsize = 0;
  137. foreach ($filearray as $key => $file) {
  138. $totalsize += $file['size'];
  139. }
  140. $morehtmlright = '';
  141. $morehtmlright .= '<div class="pagination"><ul>';
  142. $morehtmlright .= '<li class="pagination"><a class="paginationnext" href="'.$_SERVER["PHP_SELF"].'?rel=prev&amp;num='.$numref.'&amp;ve='.$ve.'&amp;account='.$object->id.'"><i class="fa fa-chevron-left" title="'.dol_escape_htmltag($langs->trans("Previous")).'"></i></a></li>';
  143. $morehtmlright .= '<li class="pagination"><span class="active">'.$langs->trans("AccountStatement")." ".$numref.'</span></li>';
  144. $morehtmlright .= '<li class="pagination"><a class="paginationnext" href="'.$_SERVER["PHP_SELF"].'?rel=next&amp;num='.$numref.'&amp;ve='.$ve.'&amp;account='.$object->id.'"><i class="fa fa-chevron-right" title="'.dol_escape_htmltag($langs->trans("Next")).'"></i></a></li>';
  145. $morehtmlright .= '</ul></div>';
  146. $title = $langs->trans("AccountStatement").' '.$numref.' - '.$langs->trans("BankAccount").' '.$object->getNomUrl(1, 'receipts');
  147. print load_fiche_titre($title, $morehtmlright, '');
  148. print '<div class="fichecenter">';
  149. print '<div class="underbanner clearboth"></div>';
  150. print '<table class="border tableforfield centpercent">';
  151. print '<tr><td class="titlefield">'.$langs->trans("NbOfAttachedFiles").'</td><td colspan="3">'.count($filearray).'</td></tr>';
  152. print '<tr><td>'.$langs->trans("TotalSizeOfAttachedFiles").'</td><td colspan="3">'.dol_print_size($totalsize, 1, 1).'</td></tr>';
  153. print "</table>\n";
  154. print '</div>';
  155. print dol_get_fiche_end();
  156. $modulepart = 'bank';
  157. $permissiontoadd = $user->rights->banque->modifier;
  158. $permtoedit = $user->rights->banque->modifier;
  159. $param = '&id='.$object->id.'&num='.urlencode($numref);
  160. $moreparam = '&num='.urlencode($numref);
  161. $relativepathwithnofile = $id."/statement/".dol_sanitizeFileName($numref)."/";
  162. include DOL_DOCUMENT_ROOT.'/core/tpl/document_actions_post_headers.tpl.php';
  163. } else {
  164. dol_print_error($db);
  165. }
  166. } else {
  167. header('Location: index.php');
  168. exit;
  169. }
  170. // End of page
  171. llxFooter();
  172. $db->close();