dolibarr 21.0.0-beta
fiche-stat.php
Go to the documentation of this file.
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 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
27// Load Dolibarr environment
28require '../../main.inc.php';
29require_once DOL_DOCUMENT_ROOT.'/core/lib/prelevement.lib.php';
30require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
31require_once DOL_DOCUMENT_ROOT.'/compta/prelevement/class/bonprelevement.class.php';
32require_once DOL_DOCUMENT_ROOT.'/compta/prelevement/class/ligneprelevement.class.php';
33require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
34
43// Load translation files required by the page
44$langs->loadLangs(array("banks", "categories", 'withdrawals', 'bills'));
45
46// Get supervariables
47$id = GETPOSTINT('id');
48$ref = GETPOST('ref', 'alpha');
49
50$type = GETPOST('type', 'aZ09');
51
52// Load variable for pagination
53$limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit;
54$sortfield = GETPOST('sortfield', 'aZ09comma');
55$sortorder = GETPOST('sortorder', 'aZ09comma');
56$page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT("page");
57if (empty($page) || $page == -1) {
58 $page = 0;
59} // If $page is not defined, or '' or -1
60$offset = $limit * $page;
61$pageprev = $page - 1;
62$pagenext = $page + 1;
63
64
65$object = new BonPrelevement($db);
66
67// Load object
68include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be 'include', not 'include_once'. Include fetch and fetch_thirdparty but not fetch_optionals
69
70// Security check
71if ($user->socid > 0) {
73}
74
75$type = $object->type;
76if ($type == 'bank-transfer') {
77 $result = restrictedArea($user, 'paymentbybanktransfer', '', '', '');
78} else {
79 $result = restrictedArea($user, 'prelevement', '', '', 'bons');
80}
81
82
83
84/*
85 * View
86 */
87
88$form = new Form($db);
89
90llxHeader('', $langs->trans("WithdrawalsReceipts"));
91
92if ($id > 0 || $ref) {
93 if ($object->fetch($id, $ref) >= 0) {
94 $head = prelevement_prepare_head($object);
95 print dol_get_fiche_head($head, 'statistics', $langs->trans("WithdrawalsReceipts"), -1, 'payment');
96
97 $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>';
98
99 dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref');
100
101 print '<div class="fichecenter">';
102 print '<div class="underbanner clearboth"></div>';
103 print '<table class="border centpercent tableforfield">'."\n";
104
105 //print '<tr><td class="titlefieldcreate">'.$langs->trans("Ref").'</td><td>'.$object->getNomUrl(1).'</td></tr>';
106 print '<tr><td class="titlefieldcreate">'.$langs->trans("Date").'</td><td>'.dol_print_date($object->datec, 'day').'</td></tr>';
107 print '<tr><td>'.$langs->trans("Amount").'</td><td><span class="amount">'.price($object->amount).'</span></td></tr>';
108
109 if (!empty($object->date_trans)) {
110 $muser = new User($db);
111 $muser->fetch($object->user_trans);
112
113 print '<tr><td>'.$langs->trans("TransData").'</td><td>';
114 print dol_print_date($object->date_trans, 'day');
115 print ' &nbsp; <span class="opacitymedium">'.$langs->trans("By").'</span> '.$muser->getNomUrl(-1).'</td></tr>';
116 print '<tr><td>'.$langs->trans("TransMetod").'</td><td>';
117 print $object->methodes_trans[$object->method_trans];
118 print '</td></tr>';
119 }
120 if (!empty($object->date_credit)) {
121 print '<tr><td>'.$langs->trans('CreditDate').'</td><td>';
122 print dol_print_date($object->date_credit, 'day');
123 print '</td></tr>';
124 }
125
126 print '</table>';
127
128 print '<br>';
129
130 print '<div class="underbanner clearboth"></div>';
131 print '<table class="border centpercent tableforfield">';
132
133 // Get bank account for the payment
134 $acc = new Account($db);
135 $fk_bank_account = $object->fk_bank_account;
136 if (empty($fk_bank_account)) {
137 $fk_bank_account = ($object->type == 'bank-transfer' ? getDolGlobalInt('PAYMENTBYBANKTRANSFER_ID_BANKACCOUNT') : getDolGlobalInt('PRELEVEMENT_ID_BANKACCOUNT'));
138 }
139 if ($fk_bank_account > 0) {
140 $result = $acc->fetch($fk_bank_account);
141 }
142
143 $labelofbankfield = "BankToReceiveWithdraw";
144 if ($object->type == 'bank-transfer') {
145 $labelofbankfield = 'BankToPayCreditTransfer';
146 }
147
148 print '<tr><td class="titlefieldcreate">';
149 print $form->textwithpicto($langs->trans("BankAccount"), $langs->trans($labelofbankfield));
150 print '</td>';
151 print '<td>';
152 if ($acc->id > 0) {
153 print $acc->getNomUrl(1);
154 }
155 print '</td>';
156 print '</tr>';
157
158 $modulepart = 'prelevement';
159 if ($object->type == 'bank-transfer') {
160 $modulepart = 'paymentbybanktransfer';
161 }
162
163 print '<tr><td class="titlefieldcreate">';
164 $labelfororderfield = 'WithdrawalFile';
165 if ($object->type == 'bank-transfer') {
166 $labelfororderfield = 'CreditTransferFile';
167 }
168 print $langs->trans($labelfororderfield).'</td><td>';
169
170 if (isModEnabled('multicompany')) {
171 $labelentity = $conf->entity;
172 $relativepath = 'receipts/'.$object->ref.'-'.$labelentity.'.xml';
173
174 if ($type != 'bank-transfer') {
175 $dir = $conf->prelevement->dir_output;
176 } else {
177 $dir = $conf->paymentbybanktransfer->dir_output;
178 }
179 if (!dol_is_file($dir.'/'.$relativepath)) { // For backward compatibility
180 $relativepath = 'receipts/'.$object->ref.'.xml';
181 }
182 } else {
183 $relativepath = 'receipts/'.$object->ref.'.xml';
184 }
185
186 print '<a data-ajax="false" href="'.DOL_URL_ROOT.'/document.php?type=text/plain&amp;modulepart='.$modulepart.'&amp;file='.urlencode($relativepath).'">'.$relativepath;
187 print img_picto('', 'download', 'class="paddingleft"');
188 print '</a>';
189 print '</td></tr></table>';
190
191 print '</div>';
192
193 print dol_get_fiche_end();
194 } else {
195 dol_print_error($db);
196 }
197
198 /*
199 * Stats
200 */
201 $line = new LignePrelevement($db);
202
203 $sql = "SELECT sum(pl.amount), pl.statut";
204 $sql .= " FROM ".MAIN_DB_PREFIX."prelevement_lignes as pl";
205 $sql .= " WHERE pl.fk_prelevement_bons = ".((int) $object->id);
206 $sql .= " GROUP BY pl.statut";
207
208 $resql = $db->query($sql);
209 if ($resql) {
210 $num = $db->num_rows($resql);
211 $i = 0;
212
213 print load_fiche_titre($langs->trans("StatisticsByLineStatus"), '', '');
214
215 print"\n<!-- debut table -->\n";
216 print '<div class="div-table-responsive-no-min">'; // You can use div-table-responsive-no-min if you don't need reserved height for your table
217 print '<table class="noborder centpercent">';
218 print '<tr class="liste_titre">';
219 print '<td>'.$langs->trans("Status").'</td><td class="right">'.$langs->trans("Amount").'</td><td class="right">%</td></tr>';
220
221 while ($i < $num) {
222 $row = $db->fetch_row($resql);
223
224 print '<tr class="oddeven"><td>';
225
226 print $line->LibStatut($row[1], 1);
227
228 print '</td>';
229
230 print '<td class="right"><span class="amount">';
231 print price($row[0]);
232 print '</span></td>';
233
234 print '<td class="right">';
235 if ($object->amount) {
236 print round($row[0] / $object->amount * 100, 2)." %";
237 }
238 print '</td>';
239
240 print "</tr>\n";
241
242
243 $i++;
244 }
245
246 print "</table>";
247 print "</div>";
248
249 $db->free($resql);
250 } else {
251 print $db->error().' '.$sql;
252 }
253}
254
255// End of page
256llxFooter();
257$db->close();
$id
Definition account.php:48
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:66
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:71
Class to manage bank accounts.
Class to manage withdrawal receipts.
Class to manage generation of HTML components Only common components must be here.
Class to manage withdrawals.
Class to manage Dolibarr users.
llxFooter()
Footer empty.
Definition document.php:107
dol_is_file($pathoffile)
Return if path is a file.
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
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)
Show tabs of a record.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
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...
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
prelevement_prepare_head(BonPrelevement $object)
Prepare array with list of tabs.
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.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.