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