dolibarr  16.0.5
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  *
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 
26 require '../../main.inc.php';
27 require_once DOL_DOCUMENT_ROOT.'/core/lib/prelevement.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 
32 // Load translation files required by the page
33 $langs->loadLangs(array("banks", "categories", 'withdrawals', 'bills'));
34 
35 // Get supervariables
36 $id = GETPOST('id', 'int');
37 $ref = GETPOST('ref', 'alpha');
38 
39 $type = GETPOST('type', 'aZ09');
40 
41 // Load variable for pagination
42 $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
43 $sortfield = GETPOST('sortfield', 'aZ09comma');
44 $sortorder = GETPOST('sortorder', 'aZ09comma');
45 $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
46 if (empty($page) || $page == -1) {
47  $page = 0;
48 } // If $page is not defined, or '' or -1
49 $offset = $limit * $page;
50 $pageprev = $page - 1;
51 $pagenext = $page + 1;
52 
53 
54 $object = new BonPrelevement($db);
55 
56 // Load object
57 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
58 
59 // Security check
60 if ($user->socid > 0) {
62 }
63 
64 $type = $object->type;
65 if ($type == 'bank-transfer') {
66  $result = restrictedArea($user, 'paymentbybanktransfer', '', '', '');
67 } else {
68  $result = restrictedArea($user, 'prelevement', '', '', 'bons');
69 }
70 
71 
72 
73 /*
74  * View
75  */
76 
77 llxHeader('', $langs->trans("WithdrawalsReceipts"));
78 
79 if ($id > 0 || $ref) {
80  if ($object->fetch($id, $ref) >= 0) {
81  $head = prelevement_prepare_head($object);
82  print dol_get_fiche_head($head, 'statistics', $langs->trans("WithdrawalsReceipts"), -1, 'payment');
83 
84  $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>';
85 
86  dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref');
87 
88  print '<div class="fichecenter">';
89  print '<div class="underbanner clearboth"></div>';
90  print '<table class="border centpercent tableforfield">'."\n";
91 
92  //print '<tr><td class="titlefieldcreate">'.$langs->trans("Ref").'</td><td>'.$object->getNomUrl(1).'</td></tr>';
93  print '<tr><td class="titlefieldcreate">'.$langs->trans("Date").'</td><td>'.dol_print_date($object->datec, 'day').'</td></tr>';
94  print '<tr><td>'.$langs->trans("Amount").'</td><td><span class="amount">'.price($object->amount).'</span></td></tr>';
95 
96  if ($object->date_trans <> 0) {
97  $muser = new User($db);
98  $muser->fetch($object->user_trans);
99 
100  print '<tr><td>'.$langs->trans("TransData").'</td><td>';
101  print dol_print_date($object->date_trans, 'day');
102  print ' <span class="opacitymedium">'.$langs->trans("By").'</span> '.$muser->getNomUrl(-1).'</td></tr>';
103  print '<tr><td>'.$langs->trans("TransMetod").'</td><td>';
104  print $object->methodes_trans[$object->method_trans];
105  print '</td></tr>';
106  }
107  if ($object->date_credit <> 0) {
108  print '<tr><td>'.$langs->trans('CreditDate').'</td><td>';
109  print dol_print_date($object->date_credit, 'day');
110  print '</td></tr>';
111  }
112 
113  print '</table>';
114 
115  print '<br>';
116 
117  print '<div class="underbanner clearboth"></div>';
118  print '<table class="border centpercent tableforfield">';
119 
120  $acc = new Account($db);
121  $result = $acc->fetch($conf->global->PRELEVEMENT_ID_BANKACCOUNT);
122 
123  print '<tr><td class="titlefieldcreate">';
124  $labelofbankfield = "BankToReceiveWithdraw";
125  if ($object->type == 'bank-transfer') {
126  $labelofbankfield = 'BankToPayCreditTransfer';
127  }
128  print $langs->trans($labelofbankfield);
129  print '</td>';
130  print '<td>';
131  if ($acc->id > 0) {
132  print $acc->getNomUrl(1);
133  }
134  print '</td>';
135  print '</tr>';
136 
137  print '<tr><td class="titlefield">';
138  $labelfororderfield = 'WithdrawalFile';
139  if ($object->type == 'bank-transfer') {
140  $labelfororderfield = 'CreditTransferFile';
141  }
142  print $langs->trans($labelfororderfield).'</td><td>';
143  $relativepath = 'receipts/'.$object->ref.'.xml';
144  $modulepart = 'prelevement';
145  if ($object->type == 'bank-transfer') {
146  $modulepart = 'paymentbybanktransfer';
147  }
148  print '<a data-ajax="false" href="'.DOL_URL_ROOT.'/document.php?type=text/plain&amp;modulepart='.$modulepart.'&amp;file='.urlencode($relativepath).'">'.$relativepath;
149  print img_picto('', 'download', 'class="paddingleft"');
150  print '</a>';
151  print '</td></tr></table>';
152 
153  print '</div>';
154 
155  print dol_get_fiche_end();
156  } else {
157  dol_print_error($db);
158  }
159 
160  /*
161  * Stats
162  */
163  $line = new LignePrelevement($db);
164 
165  $sql = "SELECT sum(pl.amount), pl.statut";
166  $sql .= " FROM ".MAIN_DB_PREFIX."prelevement_lignes as pl";
167  $sql .= " WHERE pl.fk_prelevement_bons = ".((int) $object->id);
168  $sql .= " GROUP BY pl.statut";
169 
170  $resql = $db->query($sql);
171  if ($resql) {
172  $num = $db->num_rows($resql);
173  $i = 0;
174 
175  print load_fiche_titre($langs->trans("StatisticsByLineStatus"), '', '');
176 
177  print"\n<!-- debut table -->\n";
178  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
179  print '<table class="noborder centpercent">';
180  print '<tr class="liste_titre">';
181  print '<td>'.$langs->trans("Status").'</td><td class="right">'.$langs->trans("Amount").'</td><td class="right">%</td></tr>';
182 
183  while ($i < $num) {
184  $row = $db->fetch_row($resql);
185 
186  print '<tr class="oddeven"><td>';
187 
188  print $line->LibStatut($row[1], 1);
189 
190  print '</td>';
191 
192  print '<td class="right"><span class="amount">';
193  print price($row[0]);
194  print '</span></td>';
195 
196  print '<td class="right">';
197  if ($object->amount) {
198  print round($row[0] / $object->amount * 100, 2)." %";
199  }
200  print '</td>';
201 
202  print "</tr>\n";
203 
204 
205  $i++;
206  }
207 
208  print "</table>";
209  print "</div>";
210 
211  $db->free($resql);
212  } else {
213  print $db->error().' '.$sql;
214  }
215 }
216 
217 // End of page
218 llxFooter();
219 $db->close();
restrictedArea
restrictedArea($user, $features, $objectid=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.
Definition: security.lib.php:234
llxFooter
llxFooter()
Empty footer.
Definition: wrapper.php:73
LignePrelevement
Class to manage withdrawals.
Definition: ligneprelevement.class.php:32
load_fiche_titre
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
Definition: functions.lib.php:5204
GETPOST
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Definition: functions.lib.php:484
dol_print_error
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
Definition: functions.lib.php:4844
dol_banner_tab
dol_banner_tab($object, $paramid, $morehtml='', $shownav=1, $fieldid='rowid', $fieldref='ref', $morehtmlref='', $moreparam='', $nodbprefix=0, $morehtmlleft='', $morehtmlstatus='', $onlybanner=0, $morehtmlright='')
Show tab footer of a card.
Definition: functions.lib.php:2046
dol_print_date
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
Definition: functions.lib.php:2514
img_picto
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
Definition: functions.lib.php:3880
BonPrelevement
Class to manage withdrawal receipts.
Definition: bonprelevement.class.php:43
dol_get_fiche_head
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='')
Show tabs of a record.
Definition: functions.lib.php:1822
dol_get_fiche_end
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Definition: functions.lib.php:2018
User
Class to manage Dolibarr users.
Definition: user.class.php:44
GETPOSTISSET
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
Definition: functions.lib.php:386
$resql
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->rights->fournisseur->facture->lire)||(isModEnabled('supplier_invoice') && $user->rights->supplier_invoice->lire)) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
Definition: index.php:742
price
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.
Definition: functions.lib.php:5541
prelevement_prepare_head
prelevement_prepare_head(BonPrelevement $object)
Prepare array with list of tabs.
Definition: prelevement.lib.php:34
accessforbidden
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
Definition: security.lib.php:933
llxHeader
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOCSRFCHECK')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:59
Account
Class to manage bank accounts.
Definition: account.class.php:38