dolibarr 24.0.0-beta
account_statement_document.php
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 * Copyright (C) 2024-2026 Frédéric France <frederic.france@free.fr>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 3 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <https://www.gnu.org/licenses/>.
21 */
22
28require '../../main.inc.php';
36require_once DOL_DOCUMENT_ROOT."/core/lib/bank.lib.php";
37require_once DOL_DOCUMENT_ROOT."/core/lib/files.lib.php";
38require_once DOL_DOCUMENT_ROOT."/core/lib/images.lib.php";
39require_once DOL_DOCUMENT_ROOT."/core/class/html.formfile.class.php";
40require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
41
42// Load translation files required by the page
43$langs->loadLangs(array('banks', 'companies', 'other'));
44
45$id = (GETPOSTINT('id') ? GETPOSTINT('id') : GETPOSTINT('account'));
46$ref = GETPOST('ref', 'alpha');
47$action = GETPOST('action', 'aZ09');
48$confirm = GETPOST('confirm', 'alpha');
49$numref = (GETPOST('num', 'alpha') ? GETPOST('num', 'alpha') : GETPOST('sectionid', 'alpha'));
50
51// Security check
52if ($user->socid) {
53 $action = '';
54 $socid = $user->socid;
55}
56if ($user->socid) {
57 $socid = $user->socid;
58}
59
60// Get parameters
61$limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit;
62$sortfield = GETPOST('sortfield', 'aZ09comma');
63$sortorder = GETPOST('sortorder', 'aZ09comma');
64$page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT('page');
65if (empty($page) || $page < 0 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha')) {
66 // If $page is not defined, or '' or -1 or if we click on clear filters
67 $page = 0;
68}
69$offset = $limit * $page;
70$pageprev = $page - 1;
71$pagenext = $page + 1;
72if (!$sortorder) {
73 $sortorder = "ASC";
74}
75if (!$sortfield) {
76 $sortfield = "name";
77}
78
79$object = new Account($db);
80if ($id > 0 || !empty($ref)) {
81 $result = $object->fetch($id, $ref);
82 $account = $object->id; // Force the search field on id of account
83}
84
85$result = restrictedArea($user, 'banque', $object->id, 'bank_account', '', '');
86
87// Define number of receipt to show (current, previous or next one ?)
88$found = false;
89if (GETPOST("rel") == 'prev') {
90 // Searching value for num = previous bank statement number
91 $sql = "SELECT DISTINCT(b.num_releve) as num";
92 $sql .= " FROM ".MAIN_DB_PREFIX."bank as b";
93 $sql .= " WHERE b.num_releve < '".$db->escape($numref)."'";
94 $sql .= " AND b.fk_account = ".((int) $id);
95 $sql .= " ORDER BY b.num_releve DESC";
96
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} elseif (GETPOST("rel") == 'next') {
108 // Searching value for num = next bank statement number
109 $sql = "SELECT DISTINCT(b.num_releve) as num";
110 $sql .= " FROM ".MAIN_DB_PREFIX."bank as b";
111 $sql .= " WHERE b.num_releve > '".$db->escape($numref)."'";
112 $sql .= " AND b.fk_account = ".((int) $id);
113 $sql .= " ORDER BY b.num_releve ASC";
114
115 dol_syslog("htdocs/compta/bank/releve.php", LOG_DEBUG);
116 $resql = $db->query($sql);
117 if ($resql) {
118 $numrows = $db->num_rows($resql);
119 if ($numrows > 0) {
120 $obj = $db->fetch_object($resql);
121 $numref = $obj->num;
122 $found = true;
123 }
124 }
125} else {
126 // we want this statement number
127 $found = true;
128}
129
130$permissiontoadd = $user->hasRight('banque', 'modifier'); // Used by the include of actions_dellink.inc.php
131
132
133/*
134 * Actions
135 */
136
137if (!empty($numref)) {
138 $object->fetch_thirdparty();
139 $upload_dir = $conf->bank->dir_output."/".$id."/statement/".dol_sanitizeFileName($numref);
140}
141$backtopage = $_SERVER['PHP_SELF']."?account=".urlencode((string) ($id))."&num=".urlencode((string) ($numref));
142include DOL_DOCUMENT_ROOT.'/core/actions_linkedfiles.inc.php';
143
144
145/*
146 * View
147 */
148
149$form = new Form($db);
150
151$title = $langs->trans("FinancialAccount").' - '.$langs->trans("Documents");
152$helpurl = "";
153llxHeader('', $title, $helpurl);
154
155if ($id > 0 || !empty($ref)) {
156 if ($object->fetch($id, $ref)) {
157 $upload_dir = $conf->bank->dir_output."/".$id."/statement/".dol_sanitizeFileName($numref);
158
159 // Onglets
160 $head = account_statement_prepare_head($object, $numref);
161 print dol_get_fiche_head($head, 'document', $langs->trans("AccountStatement"), -1, 'account');
162
163
164 // Build file list
165 $filearray = dol_dir_list($upload_dir, "files", 0, '', '\.meta$', $sortfield, (strtolower($sortorder) == 'desc' ? SORT_DESC : SORT_ASC), 1);
166 $totalsize = 0;
167 foreach ($filearray as $key => $file) {
168 $totalsize += $file['size'];
169 }
170
171 $morehtmlright = '';
172 $morehtmlright .= '<div class="pagination"><ul>';
173 $morehtmlright .= '<li class="pagination"><a class="paginationnext" href="'.$_SERVER["PHP_SELF"].'?rel=prev&num='.urlencode($numref).'&account='.$object->id.'"><i class="fa fa-chevron-left" title="'.dol_escape_htmltag($langs->trans("Previous")).'"></i></a></li>';
174 $morehtmlright .= '<li class="pagination"><span class="active">'.$langs->trans("AccountStatement")." ".$numref.'</span></li>';
175 $morehtmlright .= '<li class="pagination"><a class="paginationnext" href="'.$_SERVER["PHP_SELF"].'?rel=next&num='.urlencode($numref).'&account='.$object->id.'"><i class="fa fa-chevron-right" title="'.dol_escape_htmltag($langs->trans("Next")).'"></i></a></li>';
176 $morehtmlright .= '</ul></div>';
177
178 $title = $langs->trans("AccountStatement").' '.$numref.' - '.$langs->trans("BankAccount").' '.$object->getNomUrl(1, 'receipts');
179 print load_fiche_titre($title, $morehtmlright, '');
180
181 print '<div class="fichecenter">';
182 print '<div class="underbanner clearboth"></div>';
183
184 print '<table class="border tableforfield centpercent">';
185 print '<tr><td class="titlefield">'.$langs->trans("NbOfAttachedFiles").'</td><td colspan="3">'.count($filearray).'</td></tr>';
186 print '<tr><td>'.$langs->trans("TotalSizeOfAttachedFiles").'</td><td colspan="3">'.dol_print_size($totalsize, 1, 1).'</td></tr>';
187 print "</table>\n";
188
189 print '</div>';
190
191 print dol_get_fiche_end();
192
193
194 $modulepart = 'bank';
195 $permissiontoadd = $user->hasRight('banque', 'modifier');
196 $permtoedit = $user->hasRight('banque', 'modifier');
197 $param = '&id='.$object->id.'&num='.urlencode($numref);
198 $moreparam = '&num='.urlencode($numref);
199 $relativepathwithnofile = $id."/statement/".dol_sanitizeFileName($numref)."/";
200 include DOL_DOCUMENT_ROOT.'/core/tpl/document_actions_post_headers.tpl.php';
201 } else {
203 }
204} else {
205 header('Location: index.php');
206 exit;
207}
208
209// End of page
210llxFooter();
211$db->close();
$id
Support class for third parties, contacts, members, users or resources.
Definition account.php:47
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:91
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:73
account_statement_prepare_head($object, $num)
Prepare array with list of tabs.
Definition bank.lib.php:281
Class to manage bank accounts.
Class to manage generation of HTML components Only common components must be here.
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $db
API class for accounts.
dol_dir_list($utf8_path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0, $nbsecondsold=0)
Scan a directory and return a list of files/directories.
Definition files.lib.php:64
dol_print_size($size, $shortvalue=0, $shortunit=0)
Return string with formatted size.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0, $morecssdiv='')
Show tabs of a record.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0, $allowdash=0)
Clean a string to use it as a file name.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.