30require
'../../main.inc.php';
31require_once DOL_DOCUMENT_ROOT.
'/core/lib/bank.lib.php';
32require_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/account.class.php';
33require_once DOL_DOCUMENT_ROOT.
'/core/class/dolgraph.class.php';
36$langs->loadLangs(array(
'banks',
'categories'));
45$hookmanager->initHooks(array(
'bankannualreport',
'globalcard'));
48$fieldvalue = (!empty($id) ?
$id : (!empty($ref) ? $ref :
''));
49$fieldtype = (!empty($ref) ?
'ref' :
'rowid');
51 $socid = $user->socid;
53$result =
restrictedArea($user,
'banque', $fieldvalue,
'bank_account&bank_account',
'',
'', $fieldtype);
55$year_start =
GETPOST(
'year_start');
59 $year_start = $year_current - 2;
60 $year_end = $year_current;
62 $year_end = $year_start + 2;
74if ($id > 0 && !preg_match(
'/,/', $id)) {
79 $result =
$object->fetch(0, $ref);
87$title =
$object->ref.
' - '.$langs->trans(
"IOMonthlyReporting");
94$sql =
"SELECT SUM(b.amount)";
95$sql .=
", date_format(b.dateo,'%Y-%m') as dm";
96$sql .=
" FROM ".MAIN_DB_PREFIX.
"bank as b";
97$sql .=
", ".MAIN_DB_PREFIX.
"bank_account as ba";
98$sql .=
" WHERE b.fk_account = ba.rowid";
99$sql .=
" AND ba.entity IN (".getEntity(
'bank_account').
")";
100$sql .=
" AND b.amount >= 0";
102 $sql .=
" AND b.fk_account IN (".$db->sanitize($db->escape($id)).
")";
104$sql .=
" GROUP BY dm";
106$resql = $db->query($sql);
110 $num = $db->num_rows($resql);
113 $row = $db->fetch_row($resql);
114 $encaiss[$row[1]] = $row[0];
121$sql =
"SELECT SUM(b.amount)";
122$sql .=
", date_format(b.dateo,'%Y-%m') as dm";
123$sql .=
" FROM ".MAIN_DB_PREFIX.
"bank as b";
124$sql .=
", ".MAIN_DB_PREFIX.
"bank_account as ba";
125$sql .=
" WHERE b.fk_account = ba.rowid";
126$sql .=
" AND ba.entity IN (".getEntity(
'bank_account').
")";
127$sql .=
" AND b.amount <= 0";
129 $sql .=
" AND b.fk_account IN (".$db->sanitize($db->escape($id)).
")";
131$sql .=
" GROUP BY dm";
133$resql = $db->query($sql);
135 $num = $db->num_rows($resql);
138 $row = $db->fetch_row($resql);
139 $decaiss[$row[1]] = -$row[0];
149print
dol_get_fiche_head($head,
'annual', $langs->trans(
"FinancialAccount"), 0,
'account');
151$title = $langs->trans(
"FinancialAccount").
" : ".
$object->label;
152$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>' :
'');
154$linkback =
'<a href="'.DOL_URL_ROOT.
'/compta/bank/list.php?restore_lastsearch_values=1">'.$langs->trans(
"BackToList").
'</a>';
159 if (!preg_match(
'/,/', $id)) {
160 dol_banner_tab($object,
'ref', $linkback, 1,
'ref',
'ref', $morehtmlref,
'', 0,
'',
'', 1);
162 $bankaccount =
new Account($db);
163 $listid = explode(
',', $id);
164 foreach ($listid as $key => $aId) {
165 $bankaccount->fetch($aId);
166 $bankaccount->label = $bankaccount->ref;
167 print $bankaccount->getNomUrl(1);
168 if ($key < (count($listid) - 1)) {
174 print $langs->trans(
"AllAccounts");
183print
'<div class="div-table-responsive">';
184print
'<table class="noborder centpercent">';
186print
'<tr class="liste_titre"><td class="liste_titre">'.$langs->trans(
"Month").
'</td>';
187for ($annee = $year_start; $annee <= $year_end; $annee++) {
188 print
'<td align="center" width="20%" colspan="2" class="liste_titre borderrightlight">'.$annee.
'</td>';
192print
'<tr class="liste_titre">';
193print
'<td class="liste_titre"> </td>';
194for ($annee = $year_start; $annee <= $year_end; $annee++) {
195 print
'<td class="liste_titre" align="center">'.$langs->trans(
"Debit").
'</td><td class="liste_titre" align="center">'.$langs->trans(
"Credit").
'</td>';
199for ($annee = $year_start; $annee <= $year_end; $annee++) {
200 $totsorties[$annee] = 0;
201 $totentrees[$annee] = 0;
204for ($mois = 1; $mois < 13; $mois++) {
205 print
'<tr class="oddeven">';
206 print
"<td>".dol_print_date(
dol_mktime(1, 1, 1, $mois, 1, 2000),
"%B").
"</td>";
208 for ($annee = $year_start; $annee <= $year_end; $annee++) {
209 $case = sprintf(
"%04d-%02d", $annee, $mois);
211 print
'<td class="right" width="10%"> ';
212 if (isset($decaiss[$case]) && $decaiss[$case] > 0) {
213 print
price($decaiss[$case]);
214 $totsorties[$annee] += $decaiss[$case];
218 print
'<td class="right borderrightlight" width="10%"> ';
219 if (isset($encaiss[$case]) && $encaiss[$case] > 0) {
220 print
price($encaiss[$case]);
221 $totentrees[$annee] += $encaiss[$case];
229print
'<tr class="liste_total"><td><b>'.$langs->trans(
"Total").
"</b></td>";
230for ($annee = $year_start; $annee <= $year_end; $annee++) {
231 print
'<td class="right nowraponall"><b>'. (isset($totsorties[$annee]) ?
price($totsorties[$annee]) :
'') .
'</b></td>';
232 print
'<td class="right nowraponall"><b>'. (isset($totentrees[$annee]) ?
price($totentrees[$annee]) :
'') .
'</b></td>';
245$sql =
"SELECT SUM(b.amount) as total";
246$sql .=
" FROM ".MAIN_DB_PREFIX.
"bank as b";
247$sql .=
", ".MAIN_DB_PREFIX.
"bank_account as ba";
248$sql .=
" WHERE b.fk_account = ba.rowid";
249$sql .=
" AND ba.entity IN (".getEntity(
'bank_account').
")";
251 $sql .=
" AND b.fk_account IN (".$db->sanitize($db->escape($id)).
")";
254$resql = $db->query($sql);
256 $obj = $db->fetch_object($resql);
258 $balance = $obj->total;
264print
'<table class="noborder centpercent">';
267print
'<tr class="liste_total"><td><b>'.$langs->trans(
"CurrentBalance").
"</b></td>";
268print
'<td colspan="'.($nbcol).
'" class="right">'.
price($balance).
'</td>';
277$result =
dol_mkdir($conf->bank->dir_temp);
279 $langs->load(
"errors");
284 $sql =
"SELECT MIN(b.datev) as min, MAX(b.datev) as max";
285 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank as b";
286 $sql .=
", ".MAIN_DB_PREFIX.
"bank_account as ba";
287 $sql .=
" WHERE b.fk_account = ba.rowid";
288 $sql .=
" AND ba.entity IN (".getEntity(
'bank_account').
")";
289 if ($id &&
GETPOST(
"option") !=
'all') {
290 $sql .=
" AND b.fk_account IN (".$db->sanitize($id).
")";
293 $resql = $db->query($sql);
295 $num = $db->num_rows($resql);
296 $obj = $db->fetch_object($resql);
297 $min = $db->jdate($obj->min);
298 $max = $db->jdate($obj->max);
302 $log =
"graph.php: min=".$min.
" max=".$max;
308 '@phan-var-force array<array<string,int|float>> $tblyear';
309 $tblyear[0] = array();
310 $tblyear[1] = array();
311 $tblyear[2] = array();
313 for ($annee = 0; $annee < 3; $annee++) {
314 $sql =
"SELECT date_format(b.datev,'%m')";
315 $sql .=
", SUM(b.amount)";
316 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank as b";
317 $sql .=
", ".MAIN_DB_PREFIX.
"bank_account as ba";
318 $sql .=
" WHERE b.fk_account = ba.rowid";
319 $sql .=
" AND ba.entity IN (".getEntity(
'bank_account').
")";
320 $sql .=
" AND b.datev >= '".($year - $annee).
"-01-01 00:00:00'";
321 $sql .=
" AND b.datev <= '".($year - $annee).
"-12-31 23:59:59'";
322 $sql .=
" AND b.amount > 0";
323 if ($id &&
GETPOST(
"option") !=
'all') {
324 $sql .=
" AND b.fk_account IN (".$db->sanitize($id).
")";
326 $sql .=
" GROUP BY date_format(b.datev,'%m');";
328 $resql = $db->query($sql);
330 $num = $db->num_rows($resql);
333 $row = $db->fetch_row($resql);
334 $tblyear[$annee][$row[0]] = $row[1];
344 $data_year_0 = array();
345 $data_year_1 = array();
346 $data_year_2 = array();
349 for ($i = 0; $i < 12; $i++) {
350 $data_year_0[$i] = isset($tblyear[0][substr(
"0".($i + 1), -2)]) ? $tblyear[0][substr(
"0".($i + 1), -2)] : 0;
351 $data_year_1[$i] = isset($tblyear[1][substr(
"0".($i + 1), -2)]) ? $tblyear[1][substr(
"0".($i + 1), -2)] : 0;
352 $data_year_2[$i] = isset($tblyear[2][substr(
"0".($i + 1), -2)]) ? $tblyear[2][substr(
"0".($i + 1), -2)] : 0;
353 $labels[$i] = $langs->transnoentitiesnoconv(
"MonthVeryShort".sprintf(
"%02d", $i + 1));
358 $file = $conf->bank->dir_temp.
"/credmovement".
$id.
"-".$year.
".png";
359 $fileurl = DOL_URL_ROOT.
'/viewimage.php?modulepart=banque_temp&file='.
"/credmovement".$id.
"-".$year.
".png";
360 $title = $langs->transnoentities(
"Credit").
' - '.$langs->transnoentities(
"Year").
': '.($year - 2).
' - '.($year - 1).
" - ".$year;
361 $graph_datas = array();
362 for ($i = 0; $i < 12; $i++) {
363 $graph_datas[$i] = array($labels[$i], $data_year_0[$i], $data_year_1[$i], $data_year_2[$i]);
367 $px1->SetData($graph_datas);
368 $px1->SetLegend(array(($year), ($year - 1), ($year - 2)));
369 $px1->SetLegendWidthMin(180);
370 $px1->SetMaxValue($px1->GetCeilMaxValue() < 0 ? 0 : $px1->GetCeilMaxValue());
371 $px1->SetMinValue($px1->GetFloorMinValue() > 0 ? 0 : $px1->GetFloorMinValue());
372 $px1->SetTitle($title);
373 $px1->SetWidth($WIDTH);
374 $px1->SetHeight($HEIGHT);
375 $px1->SetType(array(
'line',
'line',
'line'));
377 $px1->setBgColor(
'onglet');
378 $px1->setBgColorGrid(array(255, 255, 255));
379 $px1->SetHorizTickIncrement(1);
380 $px1->draw($file, $fileurl);
382 $show1 = $px1->show();
392 $tblyear[0] = array();
393 $tblyear[1] = array();
394 $tblyear[2] = array();
396 for ($annee = 0; $annee < 3; $annee++) {
397 $sql =
"SELECT date_format(b.datev,'%m')";
398 $sql .=
", SUM(b.amount)";
399 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank as b";
400 $sql .=
", ".MAIN_DB_PREFIX.
"bank_account as ba";
401 $sql .=
" WHERE b.fk_account = ba.rowid";
402 $sql .=
" AND ba.entity IN (".getEntity(
'bank_account').
")";
403 $sql .=
" AND b.datev >= '".($year - $annee).
"-01-01 00:00:00'";
404 $sql .=
" AND b.datev <= '".($year - $annee).
"-12-31 23:59:59'";
405 $sql .=
" AND b.amount < 0";
406 if ($id &&
GETPOST(
"option") !=
'all') {
407 $sql .=
" AND b.fk_account IN (".$db->sanitize($id).
")";
409 $sql .=
" GROUP BY date_format(b.datev,'%m');";
411 $resql = $db->query($sql);
413 $num = $db->num_rows($resql);
416 $row = $db->fetch_row($resql);
417 $tblyear[$annee][$row[0]] = abs($row[1]);
427 $data_year_0 = array();
428 $data_year_1 = array();
429 $data_year_2 = array();
431 for ($i = 0; $i < 12; $i++) {
432 $data_year_0[$i] = isset($tblyear[0][substr(
"0".($i + 1), -2)]) ? $tblyear[0][substr(
"0".($i + 1), -2)] : 0;
433 $data_year_1[$i] = isset($tblyear[1][substr(
"0".($i + 1), -2)]) ? $tblyear[1][substr(
"0".($i + 1), -2)] : 0;
434 $data_year_2[$i] = isset($tblyear[2][substr(
"0".($i + 1), -2)]) ? $tblyear[2][substr(
"0".($i + 1), -2)] : 0;
435 $labels[$i] = $langs->transnoentitiesnoconv(
"MonthVeryShort".sprintf(
"%02d", $i + 1));
439 $file = $conf->bank->dir_temp.
"/debmovement".
$id.
"-".$year.
".png";
440 $fileurl = DOL_URL_ROOT.
'/viewimage.php?modulepart=banque_temp&file='.
"/debmovement".$id.
"-".$year.
".png";
441 $title = $langs->transnoentities(
"Debit").
' - '.$langs->transnoentities(
"Year").
': '.($year - 2).
' - '.($year - 1).
" - ".$year;
442 $graph_datas = array();
443 for ($i = 0; $i < 12; $i++) {
444 $graph_datas[$i] = array($labels[$i], $data_year_0[$i], $data_year_1[$i], $data_year_2[$i]);
448 $px2->SetData($graph_datas);
449 $px2->SetLegend(array(($year), ($year - 1), ($year - 2)));
450 $px2->SetLegendWidthMin(180);
451 $px2->SetMaxValue($px2->GetCeilMaxValue() < 0 ? 0 : $px2->GetCeilMaxValue());
452 $px2->SetMinValue($px2->GetFloorMinValue() > 0 ? 0 : $px2->GetFloorMinValue());
453 $px2->SetTitle($title);
454 $px2->SetWidth($WIDTH);
455 $px2->SetHeight($HEIGHT);
456 $px2->SetType(array(
'line',
'line',
'line'));
458 $px2->setBgColor(
'onglet');
459 $px2->setBgColorGrid(array(255, 255, 255));
460 $px2->SetHorizTickIncrement(1);
461 $px2->draw($file, $fileurl);
463 $show2 = $px2->show();
471 print
'<div class="fichecenter"><div class="fichehalfleft"><div align="center">';
473 print
'</div></div><div class="fichehalfright"><div align="center">';
475 print
'</div></div></div>';
476 print
'<div class="clearboth"></div>';
480print
"\n</div><br>\n";
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
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.
bank_prepare_head(Account $object)
Prepare array with list of tabs.
Class to manage bank accounts.
static getDefaultGraphSizeForStats($direction, $defaultsize='')
getDefaultGraphSizeForStats
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed information (by default a local PHP server timestamp) Rep...
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
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.
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).
img_previous($titlealt='default', $moreatt='')
Show previous logo.
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...
img_next($titlealt='default', $moreatt='')
Show next logo.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
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.