dolibarr  7.0.0-beta
graph.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3  * Copyright (C) 2004-2010 Laurent Destailleur <eldy@users.sourceforge.net>
4  * Copyright (C) 2005-2009 Regis Houssin <regis.houssin@capnetworks.com>
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 <http://www.gnu.org/licenses/>.
18  */
19 
26 require('../../main.inc.php');
27 require_once DOL_DOCUMENT_ROOT.'/core/lib/bank.lib.php';
28 require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
29 require_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
30 
31 $langs->load("banks");
32 $langs->load("categories");
33 
34 $WIDTH=DolGraph::getDefaultGraphSizeForStats('width',768);
35 $HEIGHT=DolGraph::getDefaultGraphSizeForStats('height',200);
36 
37 // Security check
38 if (isset($_GET["account"]) || isset($_GET["ref"]))
39 {
40  $id = isset($_GET["account"])?$_GET["account"]:(isset($_GET["ref"])?$_GET["ref"]:'');
41 }
42 $fieldid = isset($_GET["ref"])?'ref':'rowid';
43 if ($user->societe_id) $socid=$user->societe_id;
44 $result=restrictedArea($user,'banque',$id,'bank_account&bank_account','','',$fieldid);
45 
46 $account=GETPOST("account");
47 $mode='standard';
48 if (GETPOST("mode") == 'showalltime') $mode='showalltime';
49 $error=0;
50 
51 
52 /*
53  * View
54  */
55 
56 $title = $langs->trans("FinancialAccount").' - '.$langs->trans("Graph");
57 $helpurl = "";
58 llxHeader('',$title,$helpurl);
59 
60 $form = new Form($db);
61 
62 $datetime = dol_now();
63 $year = dol_print_date($datetime, "%Y");
64 $month = dol_print_date($datetime, "%m");
65 $day = dol_print_date($datetime, "%d");
66 if (GETPOST("year")) $year=sprintf("%04d",GETPOST("year"));
67 if (GETPOST("month")) $month=sprintf("%02d",GETPOST("month"));
68 
69 
70 $object = new Account($db);
71 if ($_GET["account"] && ! preg_match('/,/',$_GET["account"])) // if for a particular account and not a list
72 {
73  $result=$object->fetch(GETPOST("account", "int"));
74 }
75 if ($_GET["ref"])
76 {
77  $result=$object->fetch(0, GETPOST("ref"));
78  $account=$object->id;
79 }
80 
81 $result=dol_mkdir($conf->bank->dir_temp);
82 if ($result < 0)
83 {
84  $langs->load("errors");
85  $error++;
86  setEventMessages($langs->trans("ErrorFailedToCreateDir"), null, 'errors');
87 }
88 else
89 {
90  // Calcul $min and $max
91  $sql = "SELECT MIN(b.datev) as min, MAX(b.datev) as max";
92  $sql.= " FROM ".MAIN_DB_PREFIX."bank as b";
93  $sql.= ", ".MAIN_DB_PREFIX."bank_account as ba";
94  $sql.= " WHERE b.fk_account = ba.rowid";
95  $sql.= " AND ba.entity IN (".getEntity('bank_account').")";
96  if ($account && $_GET["option"]!='all') $sql.= " AND b.fk_account IN (".$account.")";
97 
98  $resql = $db->query($sql);
99  if ($resql)
100  {
101  $num = $db->num_rows($resql);
102  $obj = $db->fetch_object($resql);
103  $min = $db->jdate($obj->min);
104  $max = $db->jdate($obj->max);
105  }
106  else
107  {
108  dol_print_error($db);
109  }
110  if (empty($min)) $min = dol_now - 3600 * 24;
111 
112  $log="graph.php: min=".$min." max=".$max;
113  dol_syslog($log);
114 
115 
116  // Tableau 1
117 
118  if ($mode == 'standard')
119  {
120  // Loading table $amounts
121  $amounts = array();
122 
123  $monthnext = $month+1;
124  $yearnext = $year;
125  if ($monthnext > 12)
126  {
127  $monthnext=1;
128  $yearnext++;
129  }
130 
131  $sql = "SELECT date_format(b.datev,'%Y%m%d')";
132  $sql.= ", SUM(b.amount)";
133  $sql.= " FROM ".MAIN_DB_PREFIX."bank as b";
134  $sql.= ", ".MAIN_DB_PREFIX."bank_account as ba";
135  $sql.= " WHERE b.fk_account = ba.rowid";
136  $sql.= " AND ba.entity IN (".getEntity('bank_account').")";
137  $sql.= " AND b.datev >= '".$year."-".$month."-01 00:00:00'";
138  $sql.= " AND b.datev < '".$yearnext."-".$monthnext."-01 00:00:00'";
139  if ($account && $_GET["option"]!='all') $sql.= " AND b.fk_account IN (".$account.")";
140  $sql.= " GROUP BY date_format(b.datev,'%Y%m%d')";
141 
142  $resql = $db->query($sql);
143  if ($resql)
144  {
145  $num = $db->num_rows($resql);
146  $i = 0;
147  while ($i < $num)
148  {
149  $row = $db->fetch_row($resql);
150  $amounts[$row[0]] = $row[1];
151  $i++;
152  }
153  $db->free($resql);
154  }
155  else
156  {
157  dol_print_error($db);
158  }
159 
160  // Calculation of $solde before the start of the graph
161  $solde = 0;
162 
163  $sql = "SELECT SUM(b.amount)";
164  $sql.= " FROM ".MAIN_DB_PREFIX."bank as b";
165  $sql.= ", ".MAIN_DB_PREFIX."bank_account as ba";
166  $sql.= " WHERE b.fk_account = ba.rowid";
167  $sql.= " AND ba.entity IN (".getEntity('bank_account').")";
168  $sql.= " AND b.datev < '".$year."-".sprintf("%02s",$month)."-01'";
169  if ($account && $_GET["option"]!='all') $sql.= " AND b.fk_account IN (".$account.")";
170 
171  $resql = $db->query($sql);
172  if ($resql)
173  {
174  $row = $db->fetch_row($resql);
175  $solde = $row[0];
176  $db->free($resql);
177  }
178  else
179  {
180  dol_print_error($db);
181  }
182 
183  // Chargement de labels et datas pour tableau 1
184  $labels = array();
185  $datas = array();
186  $datamin = array();
187 
188  $subtotal = 0;
189  $day = dol_mktime(12,0,0,$month,1,$year);
190  $textdate = strftime("%Y%m%d",$day);
191  $xyear = substr($textdate,0,4);
192  $xday = substr($textdate,6,2);
193  $xmonth = substr($textdate,4,2);
194 
195  $i = 0;
196  while ($xmonth == $month)
197  {
198  $subtotal = $subtotal + (isset($amounts[$textdate]) ? $amounts[$textdate] : 0);
199  if ($day > time())
200  {
201  $datas[$i] = ''; // Valeur speciale permettant de ne pas tracer le graph
202  }
203  else
204  {
205  $datas[$i] = $solde + $subtotal;
206  }
207  $datamin[$i] = $object->min_desired;
208  $dataall[$i] = $object->min_allowed;
209  //$labels[$i] = strftime("%d",$day);
210  $labels[$i] = $xday;
211 
212  $day += 86400;
213  $textdate = strftime("%Y%m%d",$day);
214  $xyear = substr($textdate,0,4);
215  $xday = substr($textdate,6,2);
216  $xmonth = substr($textdate,4,2);
217 
218  $i++;
219  }
220  // If we are the first of month, only $datas[0] is defined to an int value, others are defined to ""
221  // and this may make graph lib report a warning.
222  //$datas[0]=100; KO
223  //$datas[0]=100; $datas[1]=90; OK
224  //var_dump($datas);
225  //exit;
226 
227  // Fabrication tableau 1
228  $file= $conf->bank->dir_temp."/balance".$account."-".$year.$month.".png";
229  $fileurl=DOL_URL_ROOT.'/viewimage.php?modulepart=banque_temp&file='."/balance".$account."-".$year.$month.".png";
230  $title=$langs->transnoentities("Balance").' - '.$langs->transnoentities("Month").': '.$month.' '.$langs->transnoentities("Year").': '.$year;
231  $graph_datas=array();
232  foreach($datas as $i => $val)
233  {
234  $graph_datas[$i]=array(isset($labels[$i])?$labels[$i]:'',$datas[$i]);
235  if ($object->min_desired) array_push($graph_datas[$i],$datamin[$i]);
236  if ($object->min_allowed) array_push($graph_datas[$i],$dataall[$i]);
237  }
238 
239  $px1 = new DolGraph();
240  $px1->SetData($graph_datas);
241  $arraylegends=array($langs->transnoentities("Balance"));
242  if ($object->min_desired) array_push($arraylegends,$langs->transnoentities("BalanceMinimalDesired"));
243  if ($object->min_allowed) array_push($arraylegends,$langs->transnoentities("BalanceMinimalAllowed"));
244  $px1->SetLegend($arraylegends);
245  $px1->SetLegendWidthMin(180);
246  $px1->SetMaxValue($px1->GetCeilMaxValue()<0?0:$px1->GetCeilMaxValue());
247  $px1->SetMinValue($px1->GetFloorMinValue()>0?0:$px1->GetFloorMinValue());
248  $px1->SetTitle($title);
249  $px1->SetWidth($WIDTH);
250  $px1->SetHeight($HEIGHT);
251  $px1->SetType(array('lines','lines','lines'));
252  $px1->setBgColor('onglet');
253  $px1->setBgColorGrid(array(255,255,255));
254  $px1->SetHorizTickIncrement(1);
255  $px1->SetPrecisionY(0);
256  $px1->draw($file,$fileurl);
257 
258  $show1=$px1->show();
259  unset($graph_datas);
260  unset($px1);
261  unset($datas);
262  unset($datamin);
263  unset($dataall);
264  unset($labels);
265  unset($amounts);
266  }
267 
268  // Tableau 2
269 
270  if ($mode == 'standard')
271  {
272  // Loading table $amounts
273  $amounts = array();
274  $sql = "SELECT date_format(b.datev,'%Y%m%d')";
275  $sql.= ", SUM(b.amount)";
276  $sql.= " FROM ".MAIN_DB_PREFIX."bank as b";
277  $sql.= ", ".MAIN_DB_PREFIX."bank_account as ba";
278  $sql.= " WHERE b.fk_account = ba.rowid";
279  $sql.= " AND ba.entity IN (".getEntity('bank_account').")";
280  $sql.= " AND b.datev >= '".$year."-01-01 00:00:00'";
281  $sql.= " AND b.datev <= '".$year."-12-31 23:59:59'";
282  if ($account && $_GET["option"]!='all') $sql.= " AND b.fk_account IN (".$account.")";
283  $sql .= " GROUP BY date_format(b.datev,'%Y%m%d')";
284 
285  $resql = $db->query($sql);
286  if ($resql)
287  {
288  $num = $db->num_rows($resql);
289  $i = 0;
290  while ($i < $num)
291  {
292  $row = $db->fetch_row($resql);
293  $amounts[$row[0]] = $row[1];
294  $i++;
295  }
296  $db->free($resql);
297  }
298  else
299  {
300  dol_print_error($db);
301  }
302 
303  // Calculation of $solde before the start of the graph
304  $solde = 0;
305 
306  $sql = "SELECT SUM(b.amount)";
307  $sql.= " FROM ".MAIN_DB_PREFIX."bank as b";
308  $sql.= ", ".MAIN_DB_PREFIX."bank_account as ba";
309  $sql.= " WHERE b.fk_account = ba.rowid";
310  $sql.= " AND ba.entity IN (".getEntity('bank_account').")";
311  $sql.= " AND b.datev < '".$year."-01-01'";
312  if ($account && $_GET["option"]!='all') $sql.= " AND b.fk_account IN (".$account.")";
313 
314  $resql = $db->query($sql);
315  if ($resql)
316  {
317  $row = $db->fetch_row($resql);
318  $solde = $row[0];
319  $db->free($resql);
320  }
321  else
322  {
323  dol_print_error($db);
324  }
325 
326  // Chargement de labels et datas pour tableau 2
327  $labels = array();
328  $datas = array();
329  $datamin = array();
330  $dataall = array();
331 
332  $subtotal = 0;
333  $now = time();
334  $day = dol_mktime(12,0,0,1,1,$year);
335  $textdate = strftime("%Y%m%d",$day);
336  $xyear = substr($textdate,0,4);
337  $xday = substr($textdate,6,2);
338 
339  $i = 0;
340  while ($xyear == $year && $day <= $datetime)
341  {
342  $subtotal = $subtotal + (isset($amounts[$textdate]) ? $amounts[$textdate] : 0);
343  if ($day > $now)
344  {
345  $datas[$i] = ''; // Valeur speciale permettant de ne pas tracer le graph
346  }
347  else
348  {
349  $datas[$i] = $solde + $subtotal;
350  }
351  $datamin[$i] = $object->min_desired;
352  $dataall[$i] = $object->min_allowed;
353  if ($xday == '15')
354  {
355  $labels[$i] = dol_print_date($day,"%b");
356  }
357  $day += 86400;
358  $textdate = strftime("%Y%m%d",$day);
359  $xyear = substr($textdate,0,4);
360  $xday = substr($textdate,6,2);
361  $i++;
362  }
363 
364  // Fabrication tableau 2
365  $file= $conf->bank->dir_temp."/balance".$account."-".$year.".png";
366  $fileurl=DOL_URL_ROOT.'/viewimage.php?modulepart=banque_temp&file='."/balance".$account."-".$year.".png";
367  $title=$langs->transnoentities("Balance").' - '.$langs->transnoentities("Year").': '.$year;
368  $graph_datas=array();
369  foreach($datas as $i => $val)
370  {
371  $graph_datas[$i]=array(isset($labels[$i])?$labels[$i]:'',$datas[$i]);
372  if ($object->min_desired) array_push($graph_datas[$i],$datamin[$i]);
373  if ($object->min_allowed) array_push($graph_datas[$i],$dataall[$i]);
374  }
375  $px2 = new DolGraph();
376  $px2->SetData($graph_datas);
377  $arraylegends=array($langs->transnoentities("Balance"));
378  if ($object->min_desired) array_push($arraylegends,$langs->transnoentities("BalanceMinimalDesired"));
379  if ($object->min_allowed) array_push($arraylegends,$langs->transnoentities("BalanceMinimalAllowed"));
380  $px2->SetLegend($arraylegends);
381  $px2->SetLegendWidthMin(180);
382  $px2->SetMaxValue($px2->GetCeilMaxValue()<0?0:$px2->GetCeilMaxValue());
383  $px2->SetMinValue($px2->GetFloorMinValue()>0?0:$px2->GetFloorMinValue());
384  $px2->SetTitle($title);
385  $px2->SetWidth($WIDTH);
386  $px2->SetHeight($HEIGHT);
387  $px2->SetType(array('lines','lines','lines'));
388  $px2->setBgColor('onglet');
389  $px2->setBgColorGrid(array(255,255,255));
390  $px2->SetHideXGrid(true);
391  //$px2->SetHorizTickIncrement(30.41); // 30.41 jours/mois en moyenne
392  $px2->SetPrecisionY(0);
393  $px2->draw($file,$fileurl);
394 
395  $show2=$px2->show();
396 
397  unset($px2);
398  unset($graph_datas);
399  unset($datas);
400  unset($datamin);
401  unset($dataall);
402  unset($labels);
403  unset($amounts);
404  }
405 
406  // Tableau 3 - All time line
407 
408  if ($mode == 'showalltime')
409  {
410  // Loading table $amounts
411  $amounts = array();
412 
413  $sql = "SELECT date_format(b.datev,'%Y%m%d')";
414  $sql.= ", SUM(b.amount)";
415  $sql.= " FROM ".MAIN_DB_PREFIX."bank as b";
416  $sql.= ", ".MAIN_DB_PREFIX."bank_account as ba";
417  $sql.= " WHERE b.fk_account = ba.rowid";
418  $sql.= " AND ba.entity IN (".getEntity('bank_account').")";
419  if ($account && $_GET["option"]!='all') $sql.= " AND b.fk_account IN (".$account.")";
420  $sql.= " GROUP BY date_format(b.datev,'%Y%m%d')";
421 
422  $resql = $db->query($sql);
423  if ($resql)
424  {
425  $num = $db->num_rows($resql);
426  $i = 0;
427 
428  while ($i < $num)
429  {
430  $row = $db->fetch_row($resql);
431  $amounts[$row[0]] = $row[1];
432  $i++;
433  }
434  }
435  else
436  {
437  dol_print_error($db);
438  }
439 
440  // Calcul de $solde avant le debut du graphe
441  $solde = 0;
442 
443  // Chargement de labels et datas pour tableau 3
444  $labels = array();
445  $datas = array();
446  $datamin = array();
447  $dataall = array();
448 
449  $subtotal = 0;
450 
451  $day = $min;
452  $textdate=strftime("%Y%m%d",$day);
453  //print "x".$textdate;
454  $i = 0;
455  while ($day <= ($max+86400)) // On va au dela du dernier jour
456  {
457  $subtotal = $subtotal + (isset($amounts[$textdate]) ? $amounts[$textdate] : 0);
458  //print strftime ("%e %d %m %y",$day)." ".$subtotal."\n<br>";
459  if ($day > ($max+86400))
460  {
461  $datas[$i] = ''; // Valeur speciale permettant de ne pas tracer le graph
462  }
463  else
464  {
465  $datas[$i] = '' + $solde + $subtotal;
466  }
467  $datamin[$i] = $object->min_desired;
468  $dataall[$i] = $object->min_allowed;
469  if (substr($textdate,6,2) == '01' || $i == 0)
470  {
471  $labels[$i] = substr($textdate,4,2);
472  }
473 
474  $day += 86400;
475  $textdate=strftime("%Y%m%d",$day);
476  $i++;
477  }
478 
479  // Fabrication tableau 3
480  $file= $conf->bank->dir_temp."/balance".$account.".png";
481  $fileurl=DOL_URL_ROOT.'/viewimage.php?modulepart=banque_temp&file='."/balance".$account.".png";
482  $title=$langs->transnoentities("Balance")." - ".$langs->transnoentities("AllTime");
483  $graph_datas=array();
484  foreach($datas as $i => $val)
485  {
486  $graph_datas[$i]=array(isset($labels[$i])?$labels[$i]:'',$datas[$i]);
487  if ($object->min_desired) array_push($graph_datas[$i],$datamin[$i]);
488  if ($object->min_allowed) array_push($graph_datas[$i],$dataall[$i]);
489  }
490 
491  $px3 = new DolGraph();
492  $px3->SetData($graph_datas);
493  $arraylegends=array($langs->transnoentities("Balance"));
494  if ($object->min_desired) array_push($arraylegends,$langs->transnoentities("BalanceMinimalDesired"));
495  if ($object->min_allowed) array_push($arraylegends,$langs->transnoentities("BalanceMinimalAllowed"));
496  $px3->SetLegend($arraylegends);
497  $px3->SetLegendWidthMin(180);
498  $px3->SetMaxValue($px3->GetCeilMaxValue()<0?0:$px3->GetCeilMaxValue());
499  $px3->SetMinValue($px3->GetFloorMinValue()>0?0:$px3->GetFloorMinValue());
500  $px3->SetTitle($title);
501  $px3->SetWidth($WIDTH);
502  $px3->SetHeight($HEIGHT);
503  $px3->SetType(array('lines','lines','lines'));
504  $px3->setBgColor('onglet');
505  $px3->setBgColorGrid(array(255,255,255));
506  $px3->SetPrecisionY(0);
507  $px3->draw($file,$fileurl);
508 
509  $show3=$px3->show();
510 
511  unset($px3);
512  unset($graph_datas);
513  unset($datas);
514  unset($datamin);
515  unset($dataall);
516  unset($labels);
517  unset($amounts);
518  }
519 
520  // Tableau 4a - Credit/Debit
521 
522  if ($mode == 'standard')
523  {
524  // Chargement du tableau $credits, $debits
525  $credits = array();
526  $debits = array();
527 
528  $monthnext = $month+1;
529  $yearnext = $year;
530  if ($monthnext > 12)
531  {
532  $monthnext=1;
533  $yearnext++;
534  }
535 
536  $sql = "SELECT date_format(b.datev,'%d')";
537  $sql.= ", SUM(b.amount)";
538  $sql .= " FROM ".MAIN_DB_PREFIX."bank as b";
539  $sql.= ", ".MAIN_DB_PREFIX."bank_account as ba";
540  $sql.= " WHERE b.fk_account = ba.rowid";
541  $sql.= " AND ba.entity IN (".getEntity('bank_account').")";
542  $sql.= " AND b.datev >= '".$year."-".$month."-01 00:00:00'";
543  $sql.= " AND b.datev < '".$yearnext."-".$monthnext."-01 00:00:00'";
544  $sql.= " AND b.amount > 0";
545  if ($account && $_GET["option"]!='all') $sql.= " AND b.fk_account IN (".$account.")";
546  $sql.= " GROUP BY date_format(b.datev,'%d')";
547 
548  $resql = $db->query($sql);
549  if ($resql)
550  {
551  $num = $db->num_rows($resql);
552  $i = 0;
553  while ($i < $num)
554  {
555  $row = $db->fetch_row($resql);
556  $credits[$row[0]] = $row[1];
557  $i++;
558  }
559  $db->free($resql);
560  }
561  else
562  {
563  dol_print_error($db);
564  }
565 
566  $monthnext = $month+1;
567  $yearnext = $year;
568  if ($monthnext > 12)
569  {
570  $monthnext=1;
571  $yearnext++;
572  }
573 
574  $sql = "SELECT date_format(b.datev,'%d')";
575  $sql.= ", SUM(b.amount)";
576  $sql .= " FROM ".MAIN_DB_PREFIX."bank as b";
577  $sql.= ", ".MAIN_DB_PREFIX."bank_account as ba";
578  $sql.= " WHERE b.fk_account = ba.rowid";
579  $sql.= " AND ba.entity IN (".getEntity('bank_account').")";
580  $sql.= " AND b.datev >= '".$year."-".$month."-01 00:00:00'";
581  $sql.= " AND b.datev < '".$yearnext."-".$monthnext."-01 00:00:00'";
582  $sql.= " AND b.amount < 0";
583  if ($account && $_GET["option"]!='all') $sql.= " AND b.fk_account IN (".$account.")";
584  $sql .= " GROUP BY date_format(b.datev,'%d')";
585 
586  $resql = $db->query($sql);
587  if ($resql)
588  {
589  while ($row = $db->fetch_row($resql))
590  {
591  $debits[$row[0]] = abs($row[1]);
592  }
593  $db->free($resql);
594  }
595  else
596  {
597  dol_print_error($db);
598  }
599 
600 
601  // Chargement de labels et data_xxx pour tableau 4 Mouvements
602  $labels = array();
603  $data_credit = array();
604  $data_debit = array();
605  for ($i = 0 ; $i < 31 ; $i++)
606  {
607  $data_credit[$i] = isset($credits[substr("0".($i+1),-2)]) ? $credits[substr("0".($i+1),-2)] : 0;
608  $data_debit[$i] = isset($debits[substr("0".($i+1),-2)]) ? $debits[substr("0".($i+1),-2)] : 0;
609  $labels[$i] = sprintf("%02d",$i+1);
610  $datamin[$i] = $object->min_desired;
611  }
612 
613  // Fabrication tableau 4a
614  $file= $conf->bank->dir_temp."/movement".$account."-".$year.$month.".png";
615  $fileurl=DOL_URL_ROOT.'/viewimage.php?modulepart=banque_temp&file='."/movement".$account."-".$year.$month.".png";
616  $title=$langs->transnoentities("BankMovements").' - '.$langs->transnoentities("Month").': '.$month.' '.$langs->transnoentities("Year").': '.$year;
617  $graph_datas=array();
618  foreach($data_credit as $i => $val)
619  {
620  $graph_datas[$i]=array($labels[$i],$data_credit[$i],$data_debit[$i]);
621  }
622  $px4 = new DolGraph();
623  $px4->SetData($graph_datas);
624  $px4->SetLegend(array($langs->transnoentities("Credit"),$langs->transnoentities("Debit")));
625  $px4->SetLegendWidthMin(180);
626  $px4->SetMaxValue($px4->GetCeilMaxValue()<0?0:$px4->GetCeilMaxValue());
627  $px4->SetMinValue($px4->GetFloorMinValue()>0?0:$px4->GetFloorMinValue());
628  $px4->SetTitle($title);
629  $px4->SetWidth($WIDTH);
630  $px4->SetHeight($HEIGHT);
631  $px4->SetType(array('bars','bars'));
632  $px4->SetShading(3);
633  $px4->setBgColor('onglet');
634  $px4->setBgColorGrid(array(255,255,255));
635  $px4->SetHorizTickIncrement(1);
636  $px4->SetPrecisionY(0);
637  $px4->draw($file,$fileurl);
638 
639  $show4=$px4->show();
640 
641  unset($graph_datas);
642  unset($px4);
643  unset($debits);
644  unset($credits);
645  }
646 
647  // Tableau 4b - Credit/Debit
648 
649  if ($mode == 'standard')
650  {
651  // Chargement du tableau $credits, $debits
652  $credits = array();
653  $debits = array();
654  $sql = "SELECT date_format(b.datev,'%m')";
655  $sql.= ", SUM(b.amount)";
656  $sql.= " FROM ".MAIN_DB_PREFIX."bank as b";
657  $sql.= ", ".MAIN_DB_PREFIX."bank_account as ba";
658  $sql.= " WHERE b.fk_account = ba.rowid";
659  $sql.= " AND ba.entity IN (".getEntity('bank_account').")";
660  $sql.= " AND b.datev >= '".$year."-01-01 00:00:00'";
661  $sql.= " AND b.datev <= '".$year."-12-31 23:59:59'";
662  $sql.= " AND b.amount > 0";
663  if ($account && $_GET["option"]!='all') $sql.= " AND b.fk_account IN (".$account.")";
664  $sql .= " GROUP BY date_format(b.datev,'%m');";
665 
666  $resql = $db->query($sql);
667  if ($resql)
668  {
669  $num = $db->num_rows($resql);
670  $i = 0;
671  while ($i < $num)
672  {
673  $row = $db->fetch_row($resql);
674  $credits[$row[0]] = $row[1];
675  $i++;
676  }
677  $db->free($resql);
678  }
679  else
680  {
681  dol_print_error($db);
682  }
683  $sql = "SELECT date_format(b.datev,'%m')";
684  $sql.= ", SUM(b.amount)";
685  $sql.= " FROM ".MAIN_DB_PREFIX."bank as b";
686  $sql.= ", ".MAIN_DB_PREFIX."bank_account as ba";
687  $sql.= " WHERE b.fk_account = ba.rowid";
688  $sql.= " AND ba.entity IN (".getEntity('bank_account').")";
689  $sql.= " AND b.datev >= '".$year."-01-01 00:00:00'";
690  $sql.= " AND b.datev <= '".$year."-12-31 23:59:59'";
691  $sql.= " AND b.amount < 0";
692  if ($account && $_GET["option"]!='all') $sql.= " AND b.fk_account IN (".$account.")";
693  $sql .= " GROUP BY date_format(b.datev,'%m')";
694 
695  $resql = $db->query($sql);
696  if ($resql)
697  {
698  while ($row = $db->fetch_row($resql))
699  {
700  $debits[$row[0]] = abs($row[1]);
701  }
702  $db->free($resql);
703  }
704  else
705  {
706  dol_print_error($db);
707  }
708 
709 
710  // Chargement de labels et data_xxx pour tableau 4 Mouvements
711  $labels = array();
712  $data_credit = array();
713  $data_debit = array();
714  for ($i = 0 ; $i < 12 ; $i++)
715  {
716  $data_credit[$i] = isset($credits[substr("0".($i+1),-2)]) ? $credits[substr("0".($i+1),-2)] : 0;
717  $data_debit[$i] = isset($debits[substr("0".($i+1),-2)]) ? $debits[substr("0".($i+1),-2)] : 0;
718  $labels[$i] = dol_print_date(dol_mktime(12,0,0,$i+1,1,2000),"%b");
719  $datamin[$i] = $object->min_desired;
720  }
721 
722  // Fabrication tableau 4b
723  $file= $conf->bank->dir_temp."/movement".$account."-".$year.".png";
724  $fileurl=DOL_URL_ROOT.'/viewimage.php?modulepart=banque_temp&file='."/movement".$account."-".$year.".png";
725  $title=$langs->transnoentities("BankMovements").' - '.$langs->transnoentities("Year").': '.$year;
726  $graph_datas=array();
727  foreach($data_credit as $i => $val)
728  {
729  $graph_datas[$i]=array($labels[$i],$data_credit[$i],$data_debit[$i]);
730  }
731  $px5 = new DolGraph();
732  $px5->SetData($graph_datas);
733  $px5->SetLegend(array($langs->transnoentities("Credit"),$langs->transnoentities("Debit")));
734  $px5->SetLegendWidthMin(180);
735  $px5->SetMaxValue($px5->GetCeilMaxValue()<0?0:$px5->GetCeilMaxValue());
736  $px5->SetMinValue($px5->GetFloorMinValue()>0?0:$px5->GetFloorMinValue());
737  $px5->SetTitle($title);
738  $px5->SetWidth($WIDTH);
739  $px5->SetHeight($HEIGHT);
740  $px5->SetType(array('bars','bars'));
741  $px5->SetShading(3);
742  $px5->setBgColor('onglet');
743  $px5->setBgColorGrid(array(255,255,255));
744  $px5->SetHorizTickIncrement(1);
745  $px5->SetPrecisionY(0);
746  $px5->draw($file,$fileurl);
747 
748  $show5=$px5->show();
749 
750  unset($graph_datas);
751  unset($px5);
752  unset($debits);
753  unset($credits);
754  }
755 }
756 
757 
758 // Onglets
759 $head=bank_prepare_head($object);
760 dol_fiche_head($head,'graph',$langs->trans("FinancialAccount"),0,'account');
761 
762 
763 $linkback = '<a href="'.DOL_URL_ROOT.'/compta/bank/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
764 
765 if ($account)
766 {
767  if (! preg_match('/,/',$account))
768  {
769  $moreparam='&month='.$month.'&year='.$year.($mode=='showalltime'?'&mode=showalltime':'');
770 
771  if ($_GET["option"]!='all')
772  {
773  $morehtml='<a href="'.$_SERVER["PHP_SELF"].'?account='.$account.'&option=all'.$moreparam.'">'.$langs->trans("ShowAllAccounts").'</a>';
774  dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', '', $moreparam, 0, '', '', 1);
775  }
776  else
777  {
778  $morehtml='<a href="'.$_SERVER["PHP_SELF"].'?account='.$account.$moreparam.'">'.$langs->trans("BackToAccount").'</a>';
779  print $langs->trans("AllAccounts");
780  //print $morehtml;
781  }
782  }
783  else
784  {
785  $bankaccount=new Account($db);
786  $listid=explode(',',$account);
787  foreach($listid as $key => $id)
788  {
789  $bankaccount->fetch($id);
790  $bankaccount->label=$bankaccount->ref;
791  print $bankaccount->getNomUrl(1);
792  if ($key < (count($listid)-1)) print ', ';
793  }
794  }
795 }
796 else
797 {
798  print $langs->trans("AllAccounts");
799 }
800 
801 dol_fiche_end();
802 
803 
804 print '<table class="notopnoleftnoright" width="100%">';
805 
806 // Navigation links
807 print '<tr><td align="right">'.$morehtml.' &nbsp; &nbsp; ';
808 if ($mode == 'showalltime')
809 {
810  print '<a href="'.$_SERVER["PHP_SELF"].'?account='.$account.'">';
811  print $langs->trans("GoBack");
812  print '</a>';
813 }
814 else
815 {
816  print '<a href="'.$_SERVER["PHP_SELF"].'?mode=showalltime&account='.$account.'">';
817  print $langs->trans("ShowAllTimeBalance");
818  print '</a>';
819 }
820 print '<br><br></td></tr>';
821 
822 
823 // Graphs
824 if ($mode == 'standard')
825 {
826  $prevyear=$year; $nextyear=$year;
827  $prevmonth=$month-1;$nextmonth=$month+1;
828  if ($prevmonth < 1) { $prevmonth=12; $prevyear--; }
829  if ($nextmonth > 12) { $nextmonth=1; $nextyear++; }
830 
831  // For month
832  $link="<a href='".$_SERVER["PHP_SELF"]."?account=".$account.($_GET["option"]!='all'?'':'&option=all')."&year=".$prevyear."&month=".$prevmonth."'>".img_previous('', 'class="valignbottom"')."</a> ".$langs->trans("Month")." <a href='".$_SERVER["PHP_SELF"]."?account=".$account."&year=".$nextyear."&month=".$nextmonth."'>".img_next('', 'class="valignbottom"')."</a>";
833  print '<tr><td align="right">'.$link.'</td></tr>';
834 
835  print '<tr><td align="center">';
836  $file = "movement".$account."-".$year.$month.".png";
837  print $show4;
838  print '</td></tr>';
839 
840  print '<tr><td align="center">';
841  print $show1;
842  print '</td></tr>';
843 
844  // For year
845  $prevyear=$year-1;$nextyear=$year+1;
846  $link="<a href='".$_SERVER["PHP_SELF"]."?account=".$account.($_GET["option"]!='all'?'':'&option=all')."&year=".($prevyear)."'>".img_previous('', 'class="valignbottom"')."</a> ".$langs->trans("Year")." <a href='".$_SERVER["PHP_SELF"]."?account=".$account."&year=".($nextyear)."'>".img_next('', 'class="valignbottom"')."</a>";
847  print '<tr><td align="right">'.$link.'</td></tr>';
848 
849  print '<tr><td align="center">';
850  print $show5;
851  print '</td></tr>';
852 
853  print '<tr><td align="center">';
854  print $show2;
855  print '</td></tr>';
856 }
857 
858 if ($mode == 'showalltime')
859 {
860  print '<tr><td align="center">';
861  print $show3;
862  print '</td></tr>';
863 }
864 
865 print '</table>';
866 
867 
868 llxFooter();
869 
870 $db->close();
llxFooter()
Empty footer.
Definition: wrapper.php:58
setEventMessages($mesg, $mesgs, $style='mesgs')
Set event messages in dol_events session object.
bank_prepare_head(Account $object)
Prepare array with list of tabs.
Definition: bank.lib.php:34
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm=false, $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
dol_fiche_head($links=array(), $active='0', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='')
Show tab header of a card.
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.
img_previous($titlealt= 'default', $moreatt='')
Show previous logo.
img_next($titlealt= 'default', $moreatt='')
Show next logo.
dol_print_error($db='', $error='', $errors=null)
Affiche message erreur system avec toutes les informations pour faciliter le diagnostic et la remonte...
if(empty($reshook)) $form
View.
Definition: perms.php:103
Class to manage bank accounts.
GETPOST($paramname, $check='none', $method=0, $filter=NULL, $options=NULL, $noreplace=0)
Return value of a param into GET or POST supervariable.
Class to manage generation of HTML components Only common components must be here.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='')
Write log message into outputs.
static getDefaultGraphSizeForStats($direction, $defaultsize='')
getDefaultGraphSizeForStats
if($_POST["cancel"]==$langs->trans("Cancel")&&!$id) if($action== 'setdatev'&&$user->rights->tax->charges->creer) if($action== 'add'&&$_POST["cancel"]<> $langs->trans("Cancel")) if($action== 'delete') $title
Actions.
Definition: card.php:183
dol_fiche_end($notab=0)
Show tab footer of a card.
llxHeader()
Empty header.
Definition: wrapper.php:46
dol_now($mode='gmt')
Return date for now.
dol_print_date($time, $format='', $tzoutput='tzserver', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
print
Draft customers invoices.
Definition: index.php:91
Class to build graphs.
dol_mkdir($dir, $dataroot='', $newmask=null)
Creation of a directory (this can create recursive subdir)
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if(!empty($conf->fournisseur->enabled)&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->societe->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if(!empty($conf->fournisseur->enabled)&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1013
restrictedArea($user, $features, $objectid=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $objcanvas=null)
Check permissions of a user to show a page and an object.