30require
'../../main.inc.php';
38require_once DOL_DOCUMENT_ROOT.
'/core/lib/bank.lib.php';
39require_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/account.class.php';
40require_once DOL_DOCUMENT_ROOT.
'/core/class/dolgraph.class.php';
43$langs->loadLangs(array(
'banks',
'categories'));
52$hookmanager->initHooks(array(
'bankannualreport',
'globalcard'));
55$fieldvalue = (!empty($id) ?
$id : (!empty($ref) ? $ref :
''));
56$fieldtype = (!empty($ref) ?
'ref' :
'rowid');
58 $socid = $user->socid;
60$result =
restrictedArea($user,
'banque', $fieldvalue,
'bank_account&bank_account',
'',
'', $fieldtype);
62$year_start =
GETPOST(
'year_start');
66 $year_start = $year_current - 2;
67 $year_end = $year_current;
69 $year_end = $year_start + 2;
80if ($id > 0 && !preg_match(
'/,/', $id)) {
81 $result =
$object->fetch((
int) $id);
85 $result =
$object->fetch(0, $ref);
93$title =
$object->ref.
' - '.$langs->trans(
"IOMonthlyReporting");
100$sql =
"SELECT SUM(b.amount)";
101$sql .=
", date_format(b.dateo,'%Y-%m') as dm";
102$sql .=
" FROM ".MAIN_DB_PREFIX.
"bank as b";
103$sql .=
", ".MAIN_DB_PREFIX.
"bank_account as ba";
104$sql .=
" WHERE b.fk_account = ba.rowid";
105$sql .=
" AND ba.entity IN (".getEntity(
'bank_account').
")";
106$sql .=
" AND b.amount >= 0";
108 $sql .=
" AND b.fk_account IN (".$db->sanitize(
$db->escape($id)).
")";
110$sql .=
" GROUP BY dm";
112$resql =
$db->query($sql);
116 $num =
$db->num_rows($resql);
119 $row =
$db->fetch_row($resql);
120 $encaiss[$row[1]] = $row[0];
127$sql =
"SELECT SUM(b.amount)";
128$sql .=
", date_format(b.dateo,'%Y-%m') as dm";
129$sql .=
" FROM ".MAIN_DB_PREFIX.
"bank as b";
130$sql .=
", ".MAIN_DB_PREFIX.
"bank_account as ba";
131$sql .=
" WHERE b.fk_account = ba.rowid";
132$sql .=
" AND ba.entity IN (".getEntity(
'bank_account').
")";
133$sql .=
" AND b.amount <= 0";
135 $sql .=
" AND b.fk_account IN (".$db->sanitize(
$db->escape($id)).
")";
137$sql .=
" GROUP BY dm";
139$resql =
$db->query($sql);
141 $num =
$db->num_rows($resql);
144 $row =
$db->fetch_row($resql);
145 $decaiss[$row[1]] = -$row[0];
155print
dol_get_fiche_head($head,
'annual', $langs->trans(
"FinancialAccount"), 0,
'account');
157$title = $langs->trans(
"FinancialAccount").
" : ".
$object->label;
158$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>' :
'');
160$linkback =
'<a href="'.DOL_URL_ROOT.
'/compta/bank/list.php?restore_lastsearch_values=1">'.$langs->trans(
"BackToList").
'</a>';
165 if (!preg_match(
'/,/', $id)) {
166 dol_banner_tab($object,
'ref', $linkback, 1,
'ref',
'ref', $morehtmlref,
'', 0,
'',
'', 1);
169 $listid = explode(
',', $id);
170 foreach ($listid as $key => $aId) {
171 $bankaccount->fetch((
int) $aId);
172 $bankaccount->label = $bankaccount->ref;
173 print $bankaccount->getNomUrl(1);
174 if ($key < (count($listid) - 1)) {
180 print $langs->trans(
"AllAccounts");
191print
'<div class="div-table-responsive">';
192print
'<table class="noborder centpercent">';
194print
'<tr class="liste_titre"><td class="liste_titre borderrightlight">'.$langs->trans(
"Month").
'</td>';
195for ($annee = $year_start; $annee <= $year_end; $annee++) {
196 print
'<td width="20%" colspan="2" class="liste_titre borderrightlight center">'.$annee.
'</td>';
200print
'<tr class="liste_titre">';
201print
'<td class="liste_titre borderrightlight"> </td>';
202for ($annee = $year_start; $annee <= $year_end; $annee++) {
203 print
'<td class="liste_titre center">'.$langs->trans(
"Debit").
'</td><td class="liste_titre center borderrightlight">'.$langs->trans(
"Credit").
'</td>';
207for ($annee = $year_start; $annee <= $year_end; $annee++) {
208 $totsorties[$annee] = 0;
209 $totentrees[$annee] = 0;
212for ($mois = 1; $mois < 13; $mois++) {
213 print
'<tr class="oddeven">';
214 print
'<td class="borderrightlight">'.dol_print_date(
dol_mktime(1, 1, 1, $mois, 1, 2000),
"%B").
"</td>";
216 for ($annee = $year_start; $annee <= $year_end; $annee++) {
217 $case = sprintf(
"%04d-%02d", $annee, $mois);
219 print
'<td class="right" width="10%"> ';
220 if (isset($decaiss[$case]) && $decaiss[$case] > 0) {
221 print
price($decaiss[$case]);
222 $totsorties[$annee] += $decaiss[$case];
226 print
'<td class="right borderrightlight" width="10%"> ';
227 if (isset($encaiss[$case]) && $encaiss[$case] > 0) {
228 print
price($encaiss[$case]);
229 $totentrees[$annee] += $encaiss[$case];
237print
'<tr class="liste_total"><td class="borderrightlight liste_total"><b>'.$langs->trans(
"Total").
"</b></td>";
238for ($annee = $year_start; $annee <= $year_end; $annee++) {
239 print
'<td class="right nowraponall liste_total"><b>'. (isset($totsorties[$annee]) ?
price($totsorties[$annee]) :
'') .
'</b></td>';
240 print
'<td class="right nowraponall liste_total borderrightlight"><b>'. (isset($totentrees[$annee]) ?
price($totentrees[$annee]) :
'') .
'</b></td>';
253$sql =
"SELECT SUM(b.amount) as total";
254$sql .=
" FROM ".MAIN_DB_PREFIX.
"bank as b";
255$sql .=
", ".MAIN_DB_PREFIX.
"bank_account as ba";
256$sql .=
" WHERE b.fk_account = ba.rowid";
257$sql .=
" AND ba.entity IN (".getEntity(
'bank_account').
")";
259 $sql .=
" AND b.fk_account IN (".$db->sanitize(
$db->escape($id)).
")";
262$resql =
$db->query($sql);
264 $obj =
$db->fetch_object($resql);
266 $balance = $obj->total;
272print
'<table class="noborder centpercent">';
275print
'<tr class="liste_total"><td><b>'.$langs->trans(
"CurrentBalance").
"</b></td>";
276print
'<td colspan="'.($nbcol).
'" class="right">'.
price($balance).
'</td>';
287 $langs->load(
"errors");
292 $sql =
"SELECT MIN(b.datev) as min, MAX(b.datev) as max";
293 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank as b";
294 $sql .=
", ".MAIN_DB_PREFIX.
"bank_account as ba";
295 $sql .=
" WHERE b.fk_account = ba.rowid";
296 $sql .=
" AND ba.entity IN (".getEntity(
'bank_account').
")";
297 if ($id &&
GETPOST(
"option") !=
'all') {
298 $sql .=
" AND b.fk_account IN (".$db->sanitize($id).
")";
301 $resql =
$db->query($sql);
303 $num =
$db->num_rows($resql);
304 $obj =
$db->fetch_object($resql);
305 $min =
$db->jdate($obj->min);
306 $max =
$db->jdate($obj->max);
307 $log =
"graph.php: min=".$min.
" max=".$max;
316 '@phan-var-force array<array<string,int|float>> $tblyear';
317 $tblyear[0] = array();
318 $tblyear[1] = array();
319 $tblyear[2] = array();
321 for ($annee = 0; $annee < 3; $annee++) {
322 $sql =
"SELECT date_format(b.datev, '%m')";
323 $sql .=
", SUM(b.amount)";
324 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank as b";
325 $sql .=
", ".MAIN_DB_PREFIX.
"bank_account as ba";
326 $sql .=
" WHERE b.fk_account = ba.rowid";
327 $sql .=
" AND ba.entity IN (".getEntity(
'bank_account').
")";
328 $sql .=
" AND b.datev >= '".($year - $annee).
"-01-01 00:00:00'";
329 $sql .=
" AND b.datev <= '".($year - $annee).
"-12-31 23:59:59'";
330 $sql .=
" AND b.amount > 0";
331 if ($id &&
GETPOST(
"option") !=
'all') {
332 $sql .=
" AND b.fk_account IN (".$db->sanitize($id).
")";
334 $sql .=
" GROUP BY date_format(b.datev, '%m');";
336 $resql =
$db->query($sql);
338 $num =
$db->num_rows($resql);
341 $row =
$db->fetch_row($resql);
342 $tblyear[$annee][$row[0]] = $row[1];
352 $data_year_0 = array();
353 $data_year_1 = array();
354 $data_year_2 = array();
357 for ($i = 0; $i < 12; $i++) {
358 $data_year_0[$i] = isset($tblyear[0][substr(
"0".($i + 1), -2)]) ? $tblyear[0][substr(
"0".($i + 1), -2)] : 0;
359 $data_year_1[$i] = isset($tblyear[1][substr(
"0".($i + 1), -2)]) ? $tblyear[1][substr(
"0".($i + 1), -2)] : 0;
360 $data_year_2[$i] = isset($tblyear[2][substr(
"0".($i + 1), -2)]) ? $tblyear[2][substr(
"0".($i + 1), -2)] : 0;
361 $labels[$i] = $langs->transnoentitiesnoconv(
"MonthVeryShort".sprintf(
"%02d", $i + 1));
366 $file =
$conf->bank->dir_temp.
"/credmovement".
$id.
"-".$year.
".png";
367 $fileurl = DOL_URL_ROOT.
'/viewimage.php?modulepart=banque_temp&file='.
"/credmovement".$id.
"-".$year.
".png";
368 $title = $langs->transnoentities(
"Credit").
' - '.$langs->transnoentities(
"Year").
': '.($year - 2).
' - '.($year - 1).
" - ".$year;
369 $graph_datas = array();
370 for ($i = 0; $i < 12; $i++) {
371 $graph_datas[$i] = array($labels[$i], $data_year_2[$i], $data_year_1[$i], $data_year_0[$i]);
375 $px1->SetData($graph_datas);
376 $px1->SetLegend(array((
string) ($year - 2), (
string) ($year - 1), (
string) $year));
377 $px1->SetLegendWidthMin(180);
378 $px1->SetMaxValue($px1->GetCeilMaxValue() < 0 ? 0 : $px1->GetCeilMaxValue());
379 $px1->SetMinValue($px1->GetFloorMinValue() > 0 ? 0 : $px1->GetFloorMinValue());
380 $px1->SetTitle($title);
381 $px1->SetWidth($WIDTH);
382 $px1->SetHeight($HEIGHT);
383 $px1->SetType(array(
'line',
'line',
'line'));
385 $px1->setBgColor(
'onglet');
386 $px1->setBgColorGrid(array(255, 255, 255));
387 $px1->SetHorizTickIncrement(1);
388 $px1->draw($file, $fileurl);
390 $show1 = $px1->show();
400 $tblyear[0] = array();
401 $tblyear[1] = array();
402 $tblyear[2] = array();
404 for ($annee = 0; $annee < 3; $annee++) {
405 $sql =
"SELECT date_format(b.datev, '%m')";
406 $sql .=
", SUM(b.amount)";
407 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank as b";
408 $sql .=
", ".MAIN_DB_PREFIX.
"bank_account as ba";
409 $sql .=
" WHERE b.fk_account = ba.rowid";
410 $sql .=
" AND ba.entity IN (".getEntity(
'bank_account').
")";
411 $sql .=
" AND b.datev >= '".($year - $annee).
"-01-01 00:00:00'";
412 $sql .=
" AND b.datev <= '".($year - $annee).
"-12-31 23:59:59'";
413 $sql .=
" AND b.amount < 0";
414 if ($id &&
GETPOST(
"option") !=
'all') {
415 $sql .=
" AND b.fk_account IN (".$db->sanitize($id).
")";
417 $sql .=
" GROUP BY date_format(b.datev, '%m');";
419 $resql =
$db->query($sql);
421 $num =
$db->num_rows($resql);
424 $row =
$db->fetch_row($resql);
425 $tblyear[$annee][$row[0]] = abs($row[1]);
436 $data_year_0 = array();
437 $data_year_1 = array();
438 $data_year_2 = array();
440 for ($i = 0; $i < 12; $i++) {
441 $data_year_0[$i] = isset($tblyear[0][substr(
"0".($i + 1), -2)]) ? $tblyear[0][substr(
"0".($i + 1), -2)] : 0;
442 $data_year_1[$i] = isset($tblyear[1][substr(
"0".($i + 1), -2)]) ? $tblyear[1][substr(
"0".($i + 1), -2)] : 0;
443 $data_year_2[$i] = isset($tblyear[2][substr(
"0".($i + 1), -2)]) ? $tblyear[2][substr(
"0".($i + 1), -2)] : 0;
444 $labels[$i] = $langs->transnoentitiesnoconv(
"MonthVeryShort".sprintf(
"%02d", $i + 1));
448 $file =
$conf->bank->dir_temp.
"/debmovement".
$id.
"-".$year.
".png";
449 $fileurl = DOL_URL_ROOT.
'/viewimage.php?modulepart=banque_temp&file='.
"/debmovement".$id.
"-".$year.
".png";
450 $title = $langs->transnoentities(
"Debit").
' - '.$langs->transnoentities(
"Year").
': '.($year - 2).
' - '.($year - 1).
" - ".$year;
451 $graph_datas = array();
452 for ($i = 0; $i < 12; $i++) {
453 $graph_datas[$i] = array($labels[$i], $data_year_2[$i], $data_year_1[$i], $data_year_0[$i]);
457 $px2->SetData($graph_datas);
458 $px2->SetLegend(array((
string) ($year - 2), (
string) ($year - 1), (
string) $year));
459 $px2->SetLegendWidthMin(180);
460 $px2->SetMaxValue($px2->GetCeilMaxValue() < 0 ? 0 : $px2->GetCeilMaxValue());
461 $px2->SetMinValue($px2->GetFloorMinValue() > 0 ? 0 : $px2->GetFloorMinValue());
462 $px2->SetTitle($title);
463 $px2->SetWidth($WIDTH);
464 $px2->SetHeight($HEIGHT);
465 $px2->SetType(array(
'line',
'line',
'line'));
467 $px2->setBgColor(
'onglet');
468 $px2->setBgColorGrid(array(255, 255, 255));
469 $px2->SetHorizTickIncrement(1);
470 $px2->draw($file, $fileurl);
472 $show2 = $px2->show();
480 print
'<div class="fichecenter"><div class="fichehalfleft"><div align="center">';
482 print
'</div></div><div class="fichehalfright"><div align="center">';
484 print
'</div></div></div>';
485 print
'<div class="clearboth"></div>';
489print
"\n</div><br>\n";
$id
Support class for third parties, contacts, members, users or resources.
if(! $sortfield) if(! $sortorder) $object
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
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_report_prepare_head(Account $object)
Prepare array with list of tabs for bank report.
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...
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, $morecssdiv='')
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.
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_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
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.
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
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.