27 require
'../../main.inc.php';
28 require_once DOL_DOCUMENT_ROOT.
'/core/lib/bank.lib.php';
29 require_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/account.class.php';
30 require_once DOL_DOCUMENT_ROOT.
'/core/class/dolgraph.class.php';
33 $langs->loadLangs(array(
'banks',
'categories'));
42 $fieldvalue = (!empty($id) ? $id : (!empty($ref) ? $ref :
''));
43 $fieldtype = (!empty($ref) ?
'ref' :
'rowid');
45 $socid = $user->socid;
47 $result =
restrictedArea($user,
'banque', $fieldvalue,
'bank_account&bank_account',
'',
'', $fieldtype);
49 $year_start =
GETPOST(
'year_start');
50 $year_current = strftime(
"%Y", time());
52 $year_start = $year_current - 2;
53 $year_end = $year_current;
55 $year_end = $year_start + 2;
64 $title = $langs->trans(
"FinancialAccount").
' - '.$langs->trans(
"IOMonthlyReporting");
72 if ($id > 0 && !preg_match(
'/,/', $id)) {
73 $result = $object->fetch($id);
77 $result = $object->fetch(0, $ref);
82 $totentrees = array();
83 $totsorties = array();
88 $sql =
"SELECT SUM(b.amount)";
89 $sql .=
", date_format(b.dateo,'%Y-%m') as dm";
90 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank as b";
91 $sql .=
", ".MAIN_DB_PREFIX.
"bank_account as ba";
92 $sql .=
" WHERE b.fk_account = ba.rowid";
93 $sql .=
" AND ba.entity IN (".getEntity(
'bank_account').
")";
94 $sql .=
" AND b.amount >= 0";
96 $sql .=
" AND b.fk_account IN (".$db->sanitize($db->escape($id)).
")";
98 $sql .=
" GROUP BY dm";
100 $resql = $db->query($sql);
102 $num = $db->num_rows(
$resql);
105 $row = $db->fetch_row(
$resql);
106 $encaiss[$row[1]] = $row[0];
113 $sql =
"SELECT SUM(b.amount)";
114 $sql .=
", date_format(b.dateo,'%Y-%m') as dm";
115 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank as b";
116 $sql .=
", ".MAIN_DB_PREFIX.
"bank_account as ba";
117 $sql .=
" WHERE b.fk_account = ba.rowid";
118 $sql .=
" AND ba.entity IN (".getEntity(
'bank_account').
")";
119 $sql .=
" AND b.amount <= 0";
121 $sql .=
" AND b.fk_account IN (".$db->sanitize($db->escape($id)).
")";
123 $sql .=
" GROUP BY dm";
125 $resql = $db->query($sql);
127 $num = $db->num_rows(
$resql);
130 $row = $db->fetch_row(
$resql);
131 $decaiss[$row[1]] = -$row[0];
141 print
dol_get_fiche_head($head,
'annual', $langs->trans(
"FinancialAccount"), 0,
'account');
143 $title = $langs->trans(
"FinancialAccount").
" : ".$object->label;
144 $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>' :
'');
146 $linkback =
'<a href="'.DOL_URL_ROOT.
'/compta/bank/list.php?restore_lastsearch_values=1">'.$langs->trans(
"BackToList").
'</a>';
151 if (!preg_match(
'/,/', $id)) {
152 dol_banner_tab($object,
'ref', $linkback, 1,
'ref',
'ref', $morehtmlref,
'', 0,
'',
'', 1);
154 $bankaccount =
new Account($db);
155 $listid = explode(
',', $id);
156 foreach ($listid as $key => $aId) {
157 $bankaccount->fetch($aId);
158 $bankaccount->label = $bankaccount->ref;
159 print $bankaccount->getNomUrl(1);
160 if ($key < (count($listid) - 1)) {
166 print $langs->trans(
"AllAccounts");
175 print
'<div class="div-table-responsive">';
176 print
'<table class="noborder centpercent">';
178 print
'<tr class="liste_titre"><td class="liste_titre">'.$langs->trans(
"Month").
'</td>';
179 for ($annee = $year_start; $annee <= $year_end; $annee++) {
180 print
'<td align="center" width="20%" colspan="2" class="liste_titre borderrightlight">'.$annee.
'</td>';
184 print
'<tr class="liste_titre">';
185 print
'<td class="liste_titre"> </td>';
186 for ($annee = $year_start; $annee <= $year_end; $annee++) {
187 print
'<td class="liste_titre" align="center">'.$langs->trans(
"Debit").
'</td><td class="liste_titre" align="center">'.$langs->trans(
"Credit").
'</td>';
191 for ($mois = 1; $mois < 13; $mois++) {
192 print
'<tr class="oddeven">';
193 print
"<td>".dol_print_date(
dol_mktime(1, 1, 1, $mois, 1, 2000),
"%B").
"</td>";
194 for ($annee = $year_start; $annee <= $year_end; $annee++) {
195 $case = sprintf(
"%04s-%02s", $annee, $mois);
197 print
'<td class="right" width="10%"> ';
198 if (isset($decaiss[$case]) && $decaiss[$case] > 0) {
199 print
price($decaiss[$case]);
200 $totsorties[$annee] += $decaiss[$case];
204 print
'<td class="right borderrightlight" width="10%"> ';
205 if (isset($encaiss[$case]) && $encaiss[$case] > 0) {
206 print
price($encaiss[$case]);
207 $totentrees[$annee] += $encaiss[$case];
215 print
'<tr class="liste_total"><td><b>'.$langs->trans(
"Total").
"</b></td>";
216 for ($annee = $year_start; $annee <= $year_end; $annee++) {
217 print
'<td class="right nowraponall"><b>'. (isset($totsorties[$annee]) ?
price($totsorties[$annee]) :
'') .
'</b></td>';
218 print
'<td class="right nowraponall"><b>'. (isset($totentrees[$annee]) ?
price($totentrees[$annee]) :
'') .
'</b></td>';
231 $sql =
"SELECT SUM(b.amount) as total";
232 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank as b";
233 $sql .=
", ".MAIN_DB_PREFIX.
"bank_account as ba";
234 $sql .=
" WHERE b.fk_account = ba.rowid";
235 $sql .=
" AND ba.entity IN (".getEntity(
'bank_account').
")";
237 $sql .=
" AND b.fk_account IN (".$db->sanitize($db->escape($id)).
")";
240 $resql = $db->query($sql);
242 $obj = $db->fetch_object(
$resql);
244 $balance = $obj->total;
250 print
'<table class="noborder centpercent">';
253 print
'<tr class="liste_total"><td><b>'.$langs->trans(
"CurrentBalance").
"</b></td>";
254 print
'<td colspan="'.($nbcol).
'" class="right">'.
price($balance).
'</td>';
263 $result =
dol_mkdir($conf->bank->dir_temp);
265 $langs->load(
"errors");
270 $sql =
"SELECT MIN(b.datev) as min, MAX(b.datev) as max";
271 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank as b";
272 $sql .=
", ".MAIN_DB_PREFIX.
"bank_account as ba";
273 $sql .=
" WHERE b.fk_account = ba.rowid";
274 $sql .=
" AND ba.entity IN (".getEntity(
'bank_account').
")";
275 if ($id &&
GETPOST(
"option") !=
'all') {
276 $sql .=
" AND b.fk_account IN (".$db->sanitize($id).
")";
279 $resql = $db->query($sql);
281 $num = $db->num_rows(
$resql);
282 $obj = $db->fetch_object(
$resql);
283 $min = $db->jdate($obj->min);
284 $max = $db->jdate($obj->max);
288 $log =
"graph.php: min=".$min.
" max=".$max;
293 $tblyear[0] = array();
294 $tblyear[1] = array();
295 $tblyear[2] = array();
297 for ($annee = 0; $annee < 3; $annee++) {
298 $sql =
"SELECT date_format(b.datev,'%m')";
299 $sql .=
", SUM(b.amount)";
300 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank as b";
301 $sql .=
", ".MAIN_DB_PREFIX.
"bank_account as ba";
302 $sql .=
" WHERE b.fk_account = ba.rowid";
303 $sql .=
" AND ba.entity IN (".getEntity(
'bank_account').
")";
304 $sql .=
" AND b.datev >= '".($year - $annee).
"-01-01 00:00:00'";
305 $sql .=
" AND b.datev <= '".($year - $annee).
"-12-31 23:59:59'";
306 $sql .=
" AND b.amount > 0";
307 if ($id &&
GETPOST(
"option") !=
'all') {
308 $sql .=
" AND b.fk_account IN (".$db->sanitize($id).
")";
310 $sql .=
" GROUP BY date_format(b.datev,'%m');";
312 $resql = $db->query($sql);
314 $num = $db->num_rows(
$resql);
317 $row = $db->fetch_row(
$resql);
318 $tblyear[$annee][$row[0]] = $row[1];
328 $data_year_0 = array();
329 $data_year_1 = array();
330 $data_year_2 = array();
332 for ($i = 0; $i < 12; $i++) {
333 $data_year_0[$i] = isset($tblyear[0][substr(
"0".($i + 1), -2)]) ? $tblyear[0][substr(
"0".($i + 1), -2)] : 0;
334 $data_year_1[$i] = isset($tblyear[1][substr(
"0".($i + 1), -2)]) ? $tblyear[1][substr(
"0".($i + 1), -2)] : 0;
335 $data_year_2[$i] = isset($tblyear[2][substr(
"0".($i + 1), -2)]) ? $tblyear[2][substr(
"0".($i + 1), -2)] : 0;
336 $labels[$i] = $langs->transnoentitiesnoconv(
"MonthVeryShort".sprintf(
"%02d", $i + 1));
341 $file = $conf->bank->dir_temp.
"/credmovement".$id.
"-".$year.
".png";
342 $fileurl = DOL_URL_ROOT.
'/viewimage.php?modulepart=banque_temp&file='.
"/credmovement".$id.
"-".$year.
".png";
343 $title = $langs->transnoentities(
"Credit").
' - '.$langs->transnoentities(
"Year").
': '.($year - 2).
' - '.($year - 1).
" - ".$year;
344 $graph_datas = array();
345 for ($i = 0; $i < 12; $i++) {
346 $graph_datas[$i] = array($labels[$i], $data_year_0[$i], $data_year_1[$i], $data_year_2[$i]);
350 $px1->SetData($graph_datas);
351 $px1->SetLegend(array(($year), ($year - 1), ($year - 2)));
352 $px1->SetLegendWidthMin(180);
353 $px1->SetMaxValue($px1->GetCeilMaxValue() < 0 ? 0 : $px1->GetCeilMaxValue());
354 $px1->SetMinValue($px1->GetFloorMinValue() > 0 ? 0 : $px1->GetFloorMinValue());
355 $px1->SetTitle($title);
356 $px1->SetWidth($WIDTH);
357 $px1->SetHeight($HEIGHT);
358 $px1->SetType(array(
'line',
'line',
'line'));
360 $px1->setBgColor(
'onglet');
361 $px1->setBgColorGrid(array(255, 255, 255));
362 $px1->SetHorizTickIncrement(1);
363 $px1->draw($file, $fileurl);
365 $show1 = $px1->show();
375 $tblyear[0] = array();
376 $tblyear[1] = array();
377 $tblyear[2] = array();
379 for ($annee = 0; $annee < 3; $annee++) {
380 $sql =
"SELECT date_format(b.datev,'%m')";
381 $sql .=
", SUM(b.amount)";
382 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank as b";
383 $sql .=
", ".MAIN_DB_PREFIX.
"bank_account as ba";
384 $sql .=
" WHERE b.fk_account = ba.rowid";
385 $sql .=
" AND ba.entity IN (".getEntity(
'bank_account').
")";
386 $sql .=
" AND b.datev >= '".($year - $annee).
"-01-01 00:00:00'";
387 $sql .=
" AND b.datev <= '".($year - $annee).
"-12-31 23:59:59'";
388 $sql .=
" AND b.amount < 0";
389 if ($id &&
GETPOST(
"option") !=
'all') {
390 $sql .=
" AND b.fk_account IN (".$db->sanitize($id).
")";
392 $sql .=
" GROUP BY date_format(b.datev,'%m');";
394 $resql = $db->query($sql);
396 $num = $db->num_rows(
$resql);
399 $row = $db->fetch_row(
$resql);
400 $tblyear[$annee][$row[0]] = abs($row[1]);
410 $data_year_0 = array();
411 $data_year_1 = array();
412 $data_year_2 = array();
414 for ($i = 0; $i < 12; $i++) {
415 $data_year_0[$i] = isset($tblyear[0][substr(
"0".($i + 1), -2)]) ? $tblyear[0][substr(
"0".($i + 1), -2)] : 0;
416 $data_year_1[$i] = isset($tblyear[1][substr(
"0".($i + 1), -2)]) ? $tblyear[1][substr(
"0".($i + 1), -2)] : 0;
417 $data_year_2[$i] = isset($tblyear[2][substr(
"0".($i + 1), -2)]) ? $tblyear[2][substr(
"0".($i + 1), -2)] : 0;
418 $labels[$i] = $langs->transnoentitiesnoconv(
"MonthVeryShort".sprintf(
"%02d", $i + 1));
422 $file = $conf->bank->dir_temp.
"/debmovement".$id.
"-".$year.
".png";
423 $fileurl = DOL_URL_ROOT.
'/viewimage.php?modulepart=banque_temp&file='.
"/debmovement".$id.
"-".$year.
".png";
424 $title = $langs->transnoentities(
"Debit").
' - '.$langs->transnoentities(
"Year").
': '.($year - 2).
' - '.($year - 1).
" - ".$year;
425 $graph_datas = array();
426 for ($i = 0; $i < 12; $i++) {
427 $graph_datas[$i] = array($labels[$i], $data_year_0[$i], $data_year_1[$i], $data_year_2[$i]);
431 $px2->SetData($graph_datas);
432 $px2->SetLegend(array(($year), ($year - 1), ($year - 2)));
433 $px2->SetLegendWidthMin(180);
434 $px2->SetMaxValue($px2->GetCeilMaxValue() < 0 ? 0 : $px2->GetCeilMaxValue());
435 $px2->SetMinValue($px2->GetFloorMinValue() > 0 ? 0 : $px2->GetFloorMinValue());
436 $px2->SetTitle($title);
437 $px2->SetWidth($WIDTH);
438 $px2->SetHeight($HEIGHT);
439 $px2->SetType(array(
'line',
'line',
'line'));
441 $px2->setBgColor(
'onglet');
442 $px2->setBgColorGrid(array(255, 255, 255));
443 $px2->SetHorizTickIncrement(1);
444 $px2->draw($file, $fileurl);
446 $show2 = $px2->show();
454 print
'<div class="fichecenter"><div class="fichehalfleft"><div align="center">';
456 print
'</div></div><div class="fichehalfright"><div align="center">';
458 print
'</div></div></div>';
459 print
'<div style="clear:both"></div>';
463 print
"\n</div><br>\n";
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
if($cancel &&!$id) if($action== 'add'&&!$cancel) if($action== 'delete') if($id) $form
Actions.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm= 'auto', $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
dol_mkdir($dir, $dataroot= '', $newmask= '')
Creation of a directory (this can create recursive subdir)
bank_prepare_head(Account $object)
Prepare array with list of tabs.
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOCSRFCHECK')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Class to manage bank accounts.
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...
setEventMessages($mesg, $mesgs, $style= 'mesgs', $messagekey= '')
Set event messages in dol_events session object.
load_fiche_titre($titre, $morehtmlright= '', $picto= 'generic', $pictoisfullpath=0, $id= '', $morecssontable= '', $morehtmlcenter= '')
Load a title with picto.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
restrictedArea($user, $features, $objectid=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.
if(isModEnabled('facture')&&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur')&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)&&$user->rights->fournisseur->facture->lire)||(isModEnabled('supplier_invoice')&&$user->rights->supplier_invoice->lire)) if(isModEnabled('don')&&!empty($user->rights->don->lire)) if(isModEnabled('tax')&&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture')&&isModEnabled('commande')&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
img_next($titlealt= 'default', $moreatt= '')
Show next logo.
dol_get_fiche_head($links=array(), $active= '', $title= '', $notab=0, $picto= '', $pictoisfullpath=0, $morehtmlright= '', $morecss= '', $limittoshow=0, $moretabssuffix= '')
Show tabs of a record.
img_previous($titlealt= 'default', $moreatt= '')
Show previous logo.
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.
static getDefaultGraphSizeForStats($direction, $defaultsize= '')
getDefaultGraphSizeForStats
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.