28 require
'../../main.inc.php';
29 require_once DOL_DOCUMENT_ROOT.
'/core/lib/bank.lib.php';
30 require_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/account.class.php';
31 require_once DOL_DOCUMENT_ROOT.
'/core/class/dolgraph.class.php';
34 $langs->loadLangs(array(
'banks',
'categories'));
43 $hookmanager->initHooks(array(
'bankannualreport',
'globalcard'));
46 $fieldvalue = (!empty($id) ? $id : (!empty($ref) ? $ref :
''));
47 $fieldtype = (!empty($ref) ?
'ref' :
'rowid');
49 $socid = $user->socid;
51 $result =
restrictedArea($user,
'banque', $fieldvalue,
'bank_account&bank_account',
'',
'', $fieldtype);
53 $year_start =
GETPOST(
'year_start');
54 $year_current = strftime(
"%Y", time());
56 $year_start = $year_current - 2;
57 $year_end = $year_current;
59 $year_end = $year_start + 2;
72 if ($id > 0 && !preg_match(
'/,/', $id)) {
73 $result = $object->fetch($id);
77 $result = $object->fetch(0, $ref);
82 $totentrees = array();
83 $totsorties = array();
85 $title = $object->ref.
' - '.$langs->trans(
"IOMonthlyReporting");
92 $sql =
"SELECT SUM(b.amount)";
93 $sql .=
", date_format(b.dateo,'%Y-%m') as dm";
94 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank as b";
95 $sql .=
", ".MAIN_DB_PREFIX.
"bank_account as ba";
96 $sql .=
" WHERE b.fk_account = ba.rowid";
97 $sql .=
" AND ba.entity IN (".getEntity(
'bank_account').
")";
98 $sql .=
" AND b.amount >= 0";
100 $sql .=
" AND b.fk_account IN (".$db->sanitize($db->escape($id)).
")";
102 $sql .=
" GROUP BY dm";
104 $resql = $db->query(
$sql);
106 $num = $db->num_rows($resql);
109 $row = $db->fetch_row($resql);
110 $encaiss[$row[1]] = $row[0];
117 $sql =
"SELECT SUM(b.amount)";
118 $sql .=
", date_format(b.dateo,'%Y-%m') as dm";
119 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank as b";
120 $sql .=
", ".MAIN_DB_PREFIX.
"bank_account as ba";
121 $sql .=
" WHERE b.fk_account = ba.rowid";
122 $sql .=
" AND ba.entity IN (".getEntity(
'bank_account').
")";
123 $sql .=
" AND b.amount <= 0";
125 $sql .=
" AND b.fk_account IN (".$db->sanitize($db->escape($id)).
")";
127 $sql .=
" GROUP BY dm";
129 $resql = $db->query(
$sql);
131 $num = $db->num_rows($resql);
134 $row = $db->fetch_row($resql);
135 $decaiss[$row[1]] = -$row[0];
145 print
dol_get_fiche_head($head,
'annual', $langs->trans(
"FinancialAccount"), 0,
'account');
147 $title = $langs->trans(
"FinancialAccount").
" : ".$object->label;
148 $link = ($year_start ?
'<a href="'.$_SERVER[
"PHP_SELF"].
'?account='.$object->id.
'&year_start='.($year_start - 1).
'">'.
img_previous(
'',
'class="valignbottom"').
"</a> ".$langs->trans(
"Year").
' <a href="'.$_SERVER[
"PHP_SELF"].
'?account='.$object->id.
'&year_start='.($year_start + 1).
'">'.
img_next(
'',
'class="valignbottom"').
'</a>' :
'');
150 $linkback =
'<a href="'.DOL_URL_ROOT.
'/compta/bank/list.php?restore_lastsearch_values=1">'.$langs->trans(
"BackToList").
'</a>';
155 if (!preg_match(
'/,/', $id)) {
156 dol_banner_tab($object,
'ref', $linkback, 1,
'ref',
'ref', $morehtmlref,
'', 0,
'',
'', 1);
158 $bankaccount =
new Account($db);
159 $listid = explode(
',', $id);
160 foreach ($listid as $key => $aId) {
161 $bankaccount->fetch($aId);
162 $bankaccount->label = $bankaccount->ref;
163 print $bankaccount->getNomUrl(1);
164 if ($key < (count($listid) - 1)) {
170 print $langs->trans(
"AllAccounts");
179 print
'<div class="div-table-responsive">';
180 print
'<table class="noborder centpercent">';
182 print
'<tr class="liste_titre"><td class="liste_titre">'.$langs->trans(
"Month").
'</td>';
183 for ($annee = $year_start; $annee <= $year_end; $annee++) {
184 print
'<td align="center" width="20%" colspan="2" class="liste_titre borderrightlight">'.$annee.
'</td>';
188 print
'<tr class="liste_titre">';
189 print
'<td class="liste_titre"> </td>';
190 for ($annee = $year_start; $annee <= $year_end; $annee++) {
191 print
'<td class="liste_titre" align="center">'.$langs->trans(
"Debit").
'</td><td class="liste_titre" align="center">'.$langs->trans(
"Credit").
'</td>';
195 for ($annee = $year_start; $annee <= $year_end; $annee++) {
196 $totsorties[$annee] = 0;
197 $totentrees[$annee] = 0;
200 for ($mois = 1; $mois < 13; $mois++) {
201 print
'<tr class="oddeven">';
202 print
"<td>".dol_print_date(
dol_mktime(1, 1, 1, $mois, 1, 2000),
"%B").
"</td>";
204 for ($annee = $year_start; $annee <= $year_end; $annee++) {
205 $case = sprintf(
"%04s-%02s", $annee, $mois);
207 print
'<td class="right" width="10%"> ';
208 if (isset($decaiss[$case]) && $decaiss[$case] > 0) {
209 print
price($decaiss[$case]);
210 $totsorties[$annee] += $decaiss[$case];
214 print
'<td class="right borderrightlight" width="10%"> ';
215 if (isset($encaiss[$case]) && $encaiss[$case] > 0) {
216 print
price($encaiss[$case]);
217 $totentrees[$annee] += $encaiss[$case];
225 print
'<tr class="liste_total"><td><b>'.$langs->trans(
"Total").
"</b></td>";
226 for ($annee = $year_start; $annee <= $year_end; $annee++) {
227 print
'<td class="right nowraponall"><b>'. (isset($totsorties[$annee]) ?
price($totsorties[$annee]) :
'') .
'</b></td>';
228 print
'<td class="right nowraponall"><b>'. (isset($totentrees[$annee]) ?
price($totentrees[$annee]) :
'') .
'</b></td>';
241 $sql =
"SELECT SUM(b.amount) as total";
242 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank as b";
243 $sql .=
", ".MAIN_DB_PREFIX.
"bank_account as ba";
244 $sql .=
" WHERE b.fk_account = ba.rowid";
245 $sql .=
" AND ba.entity IN (".getEntity(
'bank_account').
")";
247 $sql .=
" AND b.fk_account IN (".$db->sanitize($db->escape($id)).
")";
250 $resql = $db->query(
$sql);
252 $obj = $db->fetch_object($resql);
254 $balance = $obj->total;
260 print
'<table class="noborder centpercent">';
263 print
'<tr class="liste_total"><td><b>'.$langs->trans(
"CurrentBalance").
"</b></td>";
264 print
'<td colspan="'.($nbcol).
'" class="right">'.
price($balance).
'</td>';
273 $result =
dol_mkdir($conf->bank->dir_temp);
275 $langs->load(
"errors");
280 $sql =
"SELECT MIN(b.datev) as min, MAX(b.datev) as max";
281 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank as b";
282 $sql .=
", ".MAIN_DB_PREFIX.
"bank_account as ba";
283 $sql .=
" WHERE b.fk_account = ba.rowid";
284 $sql .=
" AND ba.entity IN (".getEntity(
'bank_account').
")";
285 if ($id &&
GETPOST(
"option") !=
'all') {
286 $sql .=
" AND b.fk_account IN (".$db->sanitize($id).
")";
289 $resql = $db->query(
$sql);
291 $num = $db->num_rows($resql);
292 $obj = $db->fetch_object($resql);
293 $min = $db->jdate($obj->min);
294 $max = $db->jdate($obj->max);
298 $log =
"graph.php: min=".$min.
" max=".$max;
303 $tblyear[0] = array();
304 $tblyear[1] = array();
305 $tblyear[2] = array();
307 for ($annee = 0; $annee < 3; $annee++) {
308 $sql =
"SELECT date_format(b.datev,'%m')";
309 $sql .=
", SUM(b.amount)";
310 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank as b";
311 $sql .=
", ".MAIN_DB_PREFIX.
"bank_account as ba";
312 $sql .=
" WHERE b.fk_account = ba.rowid";
313 $sql .=
" AND ba.entity IN (".getEntity(
'bank_account').
")";
314 $sql .=
" AND b.datev >= '".($year - $annee).
"-01-01 00:00:00'";
315 $sql .=
" AND b.datev <= '".($year - $annee).
"-12-31 23:59:59'";
316 $sql .=
" AND b.amount > 0";
317 if ($id &&
GETPOST(
"option") !=
'all') {
318 $sql .=
" AND b.fk_account IN (".$db->sanitize($id).
")";
320 $sql .=
" GROUP BY date_format(b.datev,'%m');";
322 $resql = $db->query(
$sql);
324 $num = $db->num_rows($resql);
327 $row = $db->fetch_row($resql);
328 $tblyear[$annee][$row[0]] = $row[1];
338 $data_year_0 = array();
339 $data_year_1 = array();
340 $data_year_2 = array();
342 for ($i = 0; $i < 12; $i++) {
343 $data_year_0[$i] = isset($tblyear[0][substr(
"0".($i + 1), -2)]) ? $tblyear[0][substr(
"0".($i + 1), -2)] : 0;
344 $data_year_1[$i] = isset($tblyear[1][substr(
"0".($i + 1), -2)]) ? $tblyear[1][substr(
"0".($i + 1), -2)] : 0;
345 $data_year_2[$i] = isset($tblyear[2][substr(
"0".($i + 1), -2)]) ? $tblyear[2][substr(
"0".($i + 1), -2)] : 0;
346 $labels[$i] = $langs->transnoentitiesnoconv(
"MonthVeryShort".sprintf(
"%02d", $i + 1));
351 $file = $conf->bank->dir_temp.
"/credmovement".$id.
"-".$year.
".png";
352 $fileurl = DOL_URL_ROOT.
'/viewimage.php?modulepart=banque_temp&file='.
"/credmovement".$id.
"-".$year.
".png";
353 $title = $langs->transnoentities(
"Credit").
' - '.$langs->transnoentities(
"Year").
': '.($year - 2).
' - '.($year - 1).
" - ".$year;
354 $graph_datas = array();
355 for ($i = 0; $i < 12; $i++) {
356 $graph_datas[$i] = array($labels[$i], $data_year_0[$i], $data_year_1[$i], $data_year_2[$i]);
360 $px1->SetData($graph_datas);
361 $px1->SetLegend(array(($year), ($year - 1), ($year - 2)));
362 $px1->SetLegendWidthMin(180);
363 $px1->SetMaxValue($px1->GetCeilMaxValue() < 0 ? 0 : $px1->GetCeilMaxValue());
364 $px1->SetMinValue($px1->GetFloorMinValue() > 0 ? 0 : $px1->GetFloorMinValue());
365 $px1->SetTitle($title);
366 $px1->SetWidth($WIDTH);
367 $px1->SetHeight($HEIGHT);
368 $px1->SetType(array(
'line',
'line',
'line'));
370 $px1->setBgColor(
'onglet');
371 $px1->setBgColorGrid(array(255, 255, 255));
372 $px1->SetHorizTickIncrement(1);
373 $px1->draw($file, $fileurl);
375 $show1 = $px1->show();
385 $tblyear[0] = array();
386 $tblyear[1] = array();
387 $tblyear[2] = array();
389 for ($annee = 0; $annee < 3; $annee++) {
390 $sql =
"SELECT date_format(b.datev,'%m')";
391 $sql .=
", SUM(b.amount)";
392 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank as b";
393 $sql .=
", ".MAIN_DB_PREFIX.
"bank_account as ba";
394 $sql .=
" WHERE b.fk_account = ba.rowid";
395 $sql .=
" AND ba.entity IN (".getEntity(
'bank_account').
")";
396 $sql .=
" AND b.datev >= '".($year - $annee).
"-01-01 00:00:00'";
397 $sql .=
" AND b.datev <= '".($year - $annee).
"-12-31 23:59:59'";
398 $sql .=
" AND b.amount < 0";
399 if ($id &&
GETPOST(
"option") !=
'all') {
400 $sql .=
" AND b.fk_account IN (".$db->sanitize($id).
")";
402 $sql .=
" GROUP BY date_format(b.datev,'%m');";
404 $resql = $db->query(
$sql);
406 $num = $db->num_rows($resql);
409 $row = $db->fetch_row($resql);
410 $tblyear[$annee][$row[0]] = abs($row[1]);
420 $data_year_0 = array();
421 $data_year_1 = array();
422 $data_year_2 = array();
424 for ($i = 0; $i < 12; $i++) {
425 $data_year_0[$i] = isset($tblyear[0][substr(
"0".($i + 1), -2)]) ? $tblyear[0][substr(
"0".($i + 1), -2)] : 0;
426 $data_year_1[$i] = isset($tblyear[1][substr(
"0".($i + 1), -2)]) ? $tblyear[1][substr(
"0".($i + 1), -2)] : 0;
427 $data_year_2[$i] = isset($tblyear[2][substr(
"0".($i + 1), -2)]) ? $tblyear[2][substr(
"0".($i + 1), -2)] : 0;
428 $labels[$i] = $langs->transnoentitiesnoconv(
"MonthVeryShort".sprintf(
"%02d", $i + 1));
432 $file = $conf->bank->dir_temp.
"/debmovement".$id.
"-".$year.
".png";
433 $fileurl = DOL_URL_ROOT.
'/viewimage.php?modulepart=banque_temp&file='.
"/debmovement".$id.
"-".$year.
".png";
434 $title = $langs->transnoentities(
"Debit").
' - '.$langs->transnoentities(
"Year").
': '.($year - 2).
' - '.($year - 1).
" - ".$year;
435 $graph_datas = array();
436 for ($i = 0; $i < 12; $i++) {
437 $graph_datas[$i] = array($labels[$i], $data_year_0[$i], $data_year_1[$i], $data_year_2[$i]);
441 $px2->SetData($graph_datas);
442 $px2->SetLegend(array(($year), ($year - 1), ($year - 2)));
443 $px2->SetLegendWidthMin(180);
444 $px2->SetMaxValue($px2->GetCeilMaxValue() < 0 ? 0 : $px2->GetCeilMaxValue());
445 $px2->SetMinValue($px2->GetFloorMinValue() > 0 ? 0 : $px2->GetFloorMinValue());
446 $px2->SetTitle($title);
447 $px2->SetWidth($WIDTH);
448 $px2->SetHeight($HEIGHT);
449 $px2->SetType(array(
'line',
'line',
'line'));
451 $px2->setBgColor(
'onglet');
452 $px2->setBgColorGrid(array(255, 255, 255));
453 $px2->SetHorizTickIncrement(1);
454 $px2->draw($file, $fileurl);
456 $show2 = $px2->show();
464 print
'<div class="fichecenter"><div class="fichehalfleft"><div align="center">';
466 print
'</div></div><div class="fichehalfright"><div align="center">';
468 print
'</div></div></div>';
469 print
'<div class="clearboth"></div>';
473 print
"\n</div><br>\n";