2013-05-15 18:14:37 +02:00
< ? php
2022-06-13 04:37:41 +02:00
/* Copyright ( C ) 2005 Rodolphe Quiedeville < rodolphe @ quiedeville . org >
* Copyright ( C ) 2004 - 2017 Laurent Destailleur < eldy @ users . sourceforge . net >
* Copyright ( C ) 2005 - 2012 Regis Houssin < regis . houssin @ inodbox . com >
* Copyright ( C ) 2013 Charles - Fr BENKE < charles . fr @ benke . fr >
2013-05-15 18:14:37 +02:00
*
* This program is free software ; you can redistribute it and / or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation ; either version 3 of the License , or
* ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
2019-09-23 21:55:30 +02:00
* along with this program . If not , see < https :// www . gnu . org / licenses />.
2013-05-15 18:14:37 +02:00
*/
/**
* \file htdocs / compta / bank / annuel . php
* \ingroup banque
* \brief Page to report input - output of a bank account
*/
2018-07-26 11:57:25 +02:00
require '../../main.inc.php' ;
2013-05-15 18:14:37 +02:00
require_once DOL_DOCUMENT_ROOT . '/core/lib/bank.lib.php' ;
require_once DOL_DOCUMENT_ROOT . '/compta/bank/class/account.class.php' ;
require_once DOL_DOCUMENT_ROOT . '/core/class/dolgraph.class.php' ;
2018-05-27 09:40:17 +02:00
// Load translation files required by the page
$langs -> loadLangs ( array ( 'banks' , 'categories' ));
2013-05-15 18:14:37 +02:00
2019-11-12 00:15:34 +01:00
$WIDTH = DolGraph :: getDefaultGraphSizeForStats ( 'width' , 380 ); // Large for one graph in a smarpthone.
$HEIGHT = DolGraph :: getDefaultGraphSizeForStats ( 'height' , 160 );
2016-11-11 23:47:56 +01:00
2019-11-12 00:15:34 +01:00
$id = GETPOST ( 'account' ) ? GETPOST ( 'account' , 'alpha' ) : GETPOST ( 'id' );
$ref = GETPOST ( 'ref' );
2013-05-15 18:14:37 +02:00
// Security check
2019-11-12 00:15:34 +01:00
$fieldvalue = ( ! empty ( $id ) ? $id : ( ! empty ( $ref ) ? $ref : '' ));
$fieldtype = ( ! empty ( $ref ) ? 'ref' : 'rowid' );
2021-02-23 21:09:01 +01:00
if ( $user -> socid ) {
$socid = $user -> socid ;
}
2019-11-12 00:15:34 +01:00
$result = restrictedArea ( $user , 'banque' , $fieldvalue , 'bank_account&bank_account' , '' , '' , $fieldtype );
2013-05-15 18:14:37 +02:00
2019-11-12 00:15:34 +01:00
$year_start = GETPOST ( 'year_start' );
2019-01-27 11:55:16 +01:00
$year_current = strftime ( " %Y " , time ());
2021-02-23 21:09:01 +01:00
if ( ! $year_start ) {
2013-05-15 18:14:37 +02:00
$year_start = $year_current - 2 ;
$year_end = $year_current ;
2020-05-21 15:05:19 +02:00
} else {
2019-11-12 00:15:34 +01:00
$year_end = $year_start + 2 ;
2013-05-15 18:14:37 +02:00
}
2016-11-11 23:47:56 +01:00
/*
* View
*/
2016-08-29 21:49:34 +02:00
$title = $langs -> trans ( " FinancialAccount " ) . ' - ' . $langs -> trans ( " IOMonthlyReporting " );
$helpurl = " " ;
2019-01-27 11:55:16 +01:00
llxHeader ( '' , $title , $helpurl );
2013-05-15 18:14:37 +02:00
$form = new Form ( $db );
// Get account informations
2016-10-21 17:00:31 +02:00
$object = new Account ( $db );
2021-02-23 21:09:01 +01:00
if ( $id > 0 && ! preg_match ( '/,/' , $id )) { // if for a particular account and not a list
2019-11-12 00:15:34 +01:00
$result = $object -> fetch ( $id );
$id = $object -> id ;
2013-05-15 18:14:37 +02:00
}
2021-02-23 21:09:01 +01:00
if ( ! empty ( $ref )) {
2019-11-12 00:15:34 +01:00
$result = $object -> fetch ( 0 , $ref );
$id = $object -> id ;
2013-05-15 18:14:37 +02:00
}
2022-06-13 04:37:41 +02:00
$annee = '' ;
$totentrees = array ();
$totsorties = array ();
2013-05-15 18:14:37 +02:00
// Ce rapport de tresorerie est base sur llx_bank (car doit inclure les transactions sans facture)
// plutot que sur llx_paiement + llx_paiementfourn
$sql = " SELECT SUM(b.amount) " ;
2019-11-12 00:15:34 +01:00
$sql .= " , date_format(b.dateo,'%Y-%m') as dm " ;
$sql .= " FROM " . MAIN_DB_PREFIX . " bank as b " ;
$sql .= " , " . MAIN_DB_PREFIX . " bank_account as ba " ;
$sql .= " WHERE b.fk_account = ba.rowid " ;
$sql .= " AND ba.entity IN ( " . getEntity ( 'bank_account' ) . " ) " ;
$sql .= " AND b.amount >= 0 " ;
2021-02-23 21:09:01 +01:00
if ( ! empty ( $id )) {
2020-09-18 17:24:31 +02:00
$sql .= " AND b.fk_account IN ( " . $db -> sanitize ( $db -> escape ( $id )) . " ) " ;
2021-02-23 21:09:01 +01:00
}
2019-11-12 00:15:34 +01:00
$sql .= " GROUP BY dm " ;
2013-05-15 18:14:37 +02:00
2019-11-12 00:15:34 +01:00
$resql = $db -> query ( $sql );
2021-02-23 21:09:01 +01:00
if ( $resql ) {
2013-05-15 18:14:37 +02:00
$num = $db -> num_rows ( $resql );
$i = 0 ;
2021-02-23 21:09:01 +01:00
while ( $i < $num ) {
2013-05-15 18:14:37 +02:00
$row = $db -> fetch_row ( $resql );
$encaiss [ $row [ 1 ]] = $row [ 0 ];
$i ++ ;
}
2020-05-21 15:05:19 +02:00
} else {
2013-05-15 18:14:37 +02:00
dol_print_error ( $db );
}
$sql = " SELECT SUM(b.amount) " ;
2019-11-12 00:15:34 +01:00
$sql .= " , date_format(b.dateo,'%Y-%m') as dm " ;
$sql .= " FROM " . MAIN_DB_PREFIX . " bank as b " ;
$sql .= " , " . MAIN_DB_PREFIX . " bank_account as ba " ;
$sql .= " WHERE b.fk_account = ba.rowid " ;
$sql .= " AND ba.entity IN ( " . getEntity ( 'bank_account' ) . " ) " ;
$sql .= " AND b.amount <= 0 " ;
2021-02-23 21:09:01 +01:00
if ( ! empty ( $id )) {
2020-09-18 17:24:31 +02:00
$sql .= " AND b.fk_account IN ( " . $db -> sanitize ( $db -> escape ( $id )) . " ) " ;
2021-02-23 21:09:01 +01:00
}
2019-11-12 00:15:34 +01:00
$sql .= " GROUP BY dm " ;
2013-05-15 18:14:37 +02:00
2019-11-12 00:15:34 +01:00
$resql = $db -> query ( $sql );
2021-02-23 21:09:01 +01:00
if ( $resql ) {
2013-05-15 18:14:37 +02:00
$num = $db -> num_rows ( $resql );
$i = 0 ;
2021-02-23 21:09:01 +01:00
while ( $i < $num ) {
2013-05-15 18:14:37 +02:00
$row = $db -> fetch_row ( $resql );
$decaiss [ $row [ 1 ]] = - $row [ 0 ];
$i ++ ;
}
2020-05-21 15:05:19 +02:00
} else {
2013-05-15 18:14:37 +02:00
dol_print_error ( $db );
}
// Onglets
2019-11-12 00:15:34 +01:00
$head = bank_prepare_head ( $object );
2020-10-22 22:50:03 +02:00
print dol_get_fiche_head ( $head , 'annual' , $langs -> trans ( " FinancialAccount " ), 0 , 'account' );
2013-05-15 18:14:37 +02:00
2019-11-12 00:15:34 +01:00
$title = $langs -> trans ( " FinancialAccount " ) . " : " . $object -> label ;
2021-03-29 23:14:42 +02:00
$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>' : '' );
2013-05-15 18:14:37 +02:00
2017-10-03 16:00:52 +02:00
$linkback = '<a href="' . DOL_URL_ROOT . '/compta/bank/list.php?restore_lastsearch_values=1">' . $langs -> trans ( " BackToList " ) . '</a>' ;
2013-05-15 18:14:37 +02:00
2021-03-29 23:14:42 +02:00
$morehtmlref = '' ;
2013-05-15 18:14:37 +02:00
2021-02-23 21:09:01 +01:00
if ( ! empty ( $id )) {
if ( ! preg_match ( '/,/' , $id )) {
2020-10-31 14:32:18 +01:00
dol_banner_tab ( $object , 'ref' , $linkback , 1 , 'ref' , 'ref' , $morehtmlref , '' , 0 , '' , '' , 1 );
} else {
$bankaccount = new Account ( $db );
$listid = explode ( ',' , $id );
2021-02-23 21:09:01 +01:00
foreach ( $listid as $key => $aId ) {
2020-10-31 14:32:18 +01:00
$bankaccount -> fetch ( $aId );
$bankaccount -> label = $bankaccount -> ref ;
print $bankaccount -> getNomUrl ( 1 );
2021-02-23 21:09:01 +01:00
if ( $key < ( count ( $listid ) - 1 )) {
print ', ' ;
}
2020-10-31 14:32:18 +01:00
}
}
2020-05-21 15:05:19 +02:00
} else {
2013-05-15 18:14:37 +02:00
print $langs -> trans ( " AllAccounts " );
}
2020-10-27 18:19:31 +01:00
print dol_get_fiche_end ();
2015-05-15 12:53:14 +02:00
2013-05-15 18:14:37 +02:00
// Affiche tableau
2017-12-08 20:15:28 +01:00
print load_fiche_titre ( '' , $link , '' );
2015-05-15 12:53:14 +02:00
2019-11-12 00:15:34 +01:00
print '<div class="div-table-responsive">' ; // You can use div-table-responsive-no-min if you dont need reserved height for your table
2019-11-05 21:24:41 +01:00
print '<table class="noborder centpercent">' ;
2013-05-15 18:14:37 +02:00
print '<tr class="liste_titre"><td class="liste_titre">' . $langs -> trans ( " Month " ) . '</td>' ;
2021-02-23 21:09:01 +01:00
for ( $annee = $year_start ; $annee <= $year_end ; $annee ++ ) {
2017-01-18 15:49:12 +01:00
print '<td align="center" width="20%" colspan="2" class="liste_titre borderrightlight">' . $annee . '</td>' ;
2013-05-15 18:14:37 +02:00
}
print '</tr>' ;
print '<tr class="liste_titre">' ;
print '<td class="liste_titre"> </td>' ;
2021-02-23 21:09:01 +01:00
for ( $annee = $year_start ; $annee <= $year_end ; $annee ++ ) {
2017-01-18 15:49:12 +01:00
print '<td class="liste_titre" align="center">' . $langs -> trans ( " Debit " ) . '</td><td class="liste_titre" align="center">' . $langs -> trans ( " Credit " ) . '</td>' ;
2013-05-15 18:14:37 +02:00
}
print '</tr>' ;
2021-02-23 21:09:01 +01:00
for ( $mois = 1 ; $mois < 13 ; $mois ++ ) {
2017-04-14 11:22:48 +02:00
print '<tr class="oddeven">' ;
2019-01-27 11:55:16 +01:00
print " <td> " . dol_print_date ( dol_mktime ( 1 , 1 , 1 , $mois , 1 , 2000 ), " %B " ) . " </td> " ;
2021-02-23 21:09:01 +01:00
for ( $annee = $year_start ; $annee <= $year_end ; $annee ++ ) {
2019-01-27 11:55:16 +01:00
$case = sprintf ( " %04s-%02s " , $annee , $mois );
2013-05-15 18:14:37 +02:00
2019-02-04 13:40:00 +01:00
print '<td class="right" width="10%"> ' ;
2022-06-13 04:37:41 +02:00
if ( isset ( $decaiss [ $case ]) && $decaiss [ $case ] > 0 ) {
2013-05-15 18:14:37 +02:00
print price ( $decaiss [ $case ]);
2019-11-12 00:15:34 +01:00
$totsorties [ $annee ] += $decaiss [ $case ];
2013-05-15 18:14:37 +02:00
}
print " </td> " ;
2019-06-12 13:10:17 +02:00
print '<td class="right borderrightlight" width="10%"> ' ;
2022-06-13 04:37:41 +02:00
if ( isset ( $encaiss [ $case ]) && $encaiss [ $case ] > 0 ) {
2013-05-15 18:14:37 +02:00
print price ( $encaiss [ $case ]);
2019-11-12 00:15:34 +01:00
$totentrees [ $annee ] += $encaiss [ $case ];
2013-05-15 18:14:37 +02:00
}
print " </td> " ;
}
print '</tr>' ;
}
// Total debit-credit
print '<tr class="liste_total"><td><b>' . $langs -> trans ( " Total " ) . " </b></td> " ;
2021-02-23 21:09:01 +01:00
for ( $annee = $year_start ; $annee <= $year_end ; $annee ++ ) {
2022-06-13 04:37:41 +02:00
print '<td class="right nowraponall"><b>' . ( isset ( $totsorties [ $annee ]) ? price ( $totsorties [ $annee ]) : '' ) . '</b></td>' ;
print '<td class="right nowraponall"><b>' . ( isset ( $totentrees [ $annee ]) ? price ( $totentrees [ $annee ]) : '' ) . '</b></td>' ;
2013-05-15 18:14:37 +02:00
}
print " </tr> \n " ;
2015-05-15 12:53:14 +02:00
print " </table> " ;
2017-12-08 20:15:28 +01:00
print " </div> " ;
2015-05-15 12:53:14 +02:00
print '<br>' ;
2013-05-15 18:14:37 +02:00
2015-05-15 12:53:14 +02:00
// Current balance
2019-11-12 00:15:34 +01:00
$balance = 0 ;
2013-05-15 18:14:37 +02:00
$sql = " SELECT SUM(b.amount) as total " ;
2019-11-12 00:15:34 +01:00
$sql .= " FROM " . MAIN_DB_PREFIX . " bank as b " ;
$sql .= " , " . MAIN_DB_PREFIX . " bank_account as ba " ;
$sql .= " WHERE b.fk_account = ba.rowid " ;
$sql .= " AND ba.entity IN ( " . getEntity ( 'bank_account' ) . " ) " ;
2021-02-23 21:09:01 +01:00
if ( ! empty ( $id )) {
2020-09-18 17:24:31 +02:00
$sql .= " AND b.fk_account IN ( " . $db -> sanitize ( $db -> escape ( $id )) . " ) " ;
2021-02-23 21:09:01 +01:00
}
2019-11-12 00:15:34 +01:00
$resql = $db -> query ( $sql );
2021-02-23 21:09:01 +01:00
if ( $resql ) {
2013-05-15 18:14:37 +02:00
$obj = $db -> fetch_object ( $resql );
2021-02-23 21:09:01 +01:00
if ( $obj ) {
$balance = $obj -> total ;
}
2020-05-21 15:05:19 +02:00
} else {
2013-05-15 18:14:37 +02:00
dol_print_error ( $db );
}
2015-05-15 12:53:14 +02:00
2019-11-05 21:24:41 +01:00
print '<table class="noborder centpercent">' ;
2015-05-15 12:53:14 +02:00
2022-06-13 04:37:41 +02:00
$nbcol = '' ;
2013-05-15 18:14:37 +02:00
print '<tr class="liste_total"><td><b>' . $langs -> trans ( " CurrentBalance " ) . " </b></td> " ;
2019-02-04 13:40:00 +01:00
print '<td colspan="' . ( $nbcol ) . '" class="right">' . price ( $balance ) . '</td>' ;
2013-05-15 18:14:37 +02:00
print " </tr> \n " ;
print " </table> " ;
// BUILDING GRAPHICS
2013-08-27 12:02:33 +02:00
$year = $year_end ;
2013-05-15 18:14:37 +02:00
2019-11-12 00:15:34 +01:00
$result = dol_mkdir ( $conf -> bank -> dir_temp );
2021-02-23 21:09:01 +01:00
if ( $result < 0 ) {
2013-05-15 18:14:37 +02:00
$langs -> load ( " errors " );
$error ++ ;
2015-11-11 12:27:09 +01:00
setEventMessages ( $langs -> trans ( " ErrorFailedToCreateDir " ), null , 'errors' );
2020-05-21 15:05:19 +02:00
} else {
2013-05-15 18:14:37 +02:00
// Calcul de $min et $max
$sql = " SELECT MIN(b.datev) as min, MAX(b.datev) as max " ;
2019-11-12 00:15:34 +01:00
$sql .= " FROM " . MAIN_DB_PREFIX . " bank as b " ;
$sql .= " , " . MAIN_DB_PREFIX . " bank_account as ba " ;
$sql .= " WHERE b.fk_account = ba.rowid " ;
$sql .= " AND ba.entity IN ( " . getEntity ( 'bank_account' ) . " ) " ;
2022-06-13 04:37:41 +02:00
if ( $id && GETPOST ( " option " ) != 'all' ) {
2021-03-22 11:30:18 +01:00
$sql .= " AND b.fk_account IN ( " . $db -> sanitize ( $id ) . " ) " ;
2021-02-23 21:09:01 +01:00
}
2013-05-15 18:14:37 +02:00
$resql = $db -> query ( $sql );
2021-02-23 21:09:01 +01:00
if ( $resql ) {
2013-05-15 18:14:37 +02:00
$num = $db -> num_rows ( $resql );
$obj = $db -> fetch_object ( $resql );
$min = $db -> jdate ( $obj -> min );
$max = $db -> jdate ( $obj -> max );
2020-05-21 15:05:19 +02:00
} else {
2013-05-15 18:14:37 +02:00
dol_print_error ( $db );
}
2019-11-12 00:15:34 +01:00
$log = " graph.php: min= " . $min . " max= " . $max ;
2013-05-15 18:14:37 +02:00
dol_syslog ( $log );
2019-10-26 14:42:25 +02:00
// CRED PART
2013-05-15 18:14:37 +02:00
// Chargement du tableau des années
$tblyear [ 0 ] = array ();
$tblyear [ 1 ] = array ();
$tblyear [ 2 ] = array ();
2021-02-23 21:09:01 +01:00
for ( $annee = 0 ; $annee < 3 ; $annee ++ ) {
2013-05-15 18:14:37 +02:00
$sql = " SELECT date_format(b.datev,'%m') " ;
2019-11-12 00:15:34 +01:00
$sql .= " , SUM(b.amount) " ;
$sql .= " FROM " . MAIN_DB_PREFIX . " bank as b " ;
$sql .= " , " . MAIN_DB_PREFIX . " bank_account as ba " ;
$sql .= " WHERE b.fk_account = ba.rowid " ;
$sql .= " AND ba.entity IN ( " . getEntity ( 'bank_account' ) . " ) " ;
$sql .= " AND b.datev >= ' " . ( $year - $annee ) . " -01-01 00:00:00' " ;
$sql .= " AND b.datev <= ' " . ( $year - $annee ) . " -12-31 23:59:59' " ;
$sql .= " AND b.amount > 0 " ;
2022-06-13 04:37:41 +02:00
if ( $id && GETPOST ( " option " ) != 'all' ) {
2021-03-22 11:30:18 +01:00
$sql .= " AND b.fk_account IN ( " . $db -> sanitize ( $id ) . " ) " ;
2021-02-23 21:09:01 +01:00
}
2013-05-15 18:14:37 +02:00
$sql .= " GROUP BY date_format(b.datev,'%m'); " ;
$resql = $db -> query ( $sql );
2021-02-23 21:09:01 +01:00
if ( $resql ) {
2013-05-15 18:14:37 +02:00
$num = $db -> num_rows ( $resql );
$i = 0 ;
2021-02-23 21:09:01 +01:00
while ( $i < $num ) {
2013-05-15 18:14:37 +02:00
$row = $db -> fetch_row ( $resql );
$tblyear [ $annee ][ $row [ 0 ]] = $row [ 1 ];
$i ++ ;
}
$db -> free ( $resql );
2020-05-21 15:05:19 +02:00
} else {
2013-05-15 18:14:37 +02:00
dol_print_error ( $db );
}
}
// Chargement de labels et data_xxx pour tableau 4 Mouvements
$labels = array ();
$data_year_0 = array ();
$data_year_1 = array ();
$data_year_2 = array ();
2021-02-23 21:09:01 +01:00
for ( $i = 0 ; $i < 12 ; $i ++ ) {
2019-11-12 00:15:34 +01:00
$data_year_0 [ $i ] = isset ( $tblyear [ 0 ][ substr ( " 0 " . ( $i + 1 ), - 2 )]) ? $tblyear [ 0 ][ substr ( " 0 " . ( $i + 1 ), - 2 )] : 0 ;
$data_year_1 [ $i ] = isset ( $tblyear [ 1 ][ substr ( " 0 " . ( $i + 1 ), - 2 )]) ? $tblyear [ 1 ][ substr ( " 0 " . ( $i + 1 ), - 2 )] : 0 ;
$data_year_2 [ $i ] = isset ( $tblyear [ 2 ][ substr ( " 0 " . ( $i + 1 ), - 2 )]) ? $tblyear [ 2 ][ substr ( " 0 " . ( $i + 1 ), - 2 )] : 0 ;
$labels [ $i ] = $langs -> transnoentitiesnoconv ( " MonthVeryShort " . sprintf ( " %02d " , $i + 1 ));
2013-05-15 18:14:37 +02:00
$datamin [ $i ] = 0 ;
}
// Fabrication tableau 4b
2019-11-12 00:15:34 +01:00
$file = $conf -> bank -> dir_temp . " /credmovement " . $id . " - " . $year . " .png " ;
$fileurl = DOL_URL_ROOT . '/viewimage.php?modulepart=banque_temp&file=' . " /credmovement " . $id . " - " . $year . " .png " ;
$title = $langs -> transnoentities ( " Credit " ) . ' - ' . $langs -> transnoentities ( " Year " ) . ': ' . ( $year - 2 ) . ' - ' . ( $year - 1 ) . " - " . $year ;
$graph_datas = array ();
2021-02-23 21:09:01 +01:00
for ( $i = 0 ; $i < 12 ; $i ++ ) {
2019-11-12 00:15:34 +01:00
$graph_datas [ $i ] = array ( $labels [ $i ], $data_year_0 [ $i ], $data_year_1 [ $i ], $data_year_2 [ $i ]);
2013-05-15 18:14:37 +02:00
}
$px1 = new DolGraph ();
$px1 -> SetData ( $graph_datas );
2019-11-12 00:15:34 +01:00
$px1 -> SetLegend ( array (( $year ), ( $year - 1 ), ( $year - 2 )));
2013-05-15 18:14:37 +02:00
$px1 -> SetLegendWidthMin ( 180 );
2019-11-12 00:15:34 +01:00
$px1 -> SetMaxValue ( $px1 -> GetCeilMaxValue () < 0 ? 0 : $px1 -> GetCeilMaxValue ());
$px1 -> SetMinValue ( $px1 -> GetFloorMinValue () > 0 ? 0 : $px1 -> GetFloorMinValue ());
2013-05-15 18:14:37 +02:00
$px1 -> SetTitle ( $title );
2016-11-11 23:47:56 +01:00
$px1 -> SetWidth ( $WIDTH );
$px1 -> SetHeight ( $HEIGHT );
2019-11-12 00:15:34 +01:00
$px1 -> SetType ( array ( 'line' , 'line' , 'line' ));
2013-05-15 18:14:37 +02:00
$px1 -> SetShading ( 3 );
$px1 -> setBgColor ( 'onglet' );
2019-11-12 00:15:34 +01:00
$px1 -> setBgColorGrid ( array ( 255 , 255 , 255 ));
2013-05-15 18:14:37 +02:00
$px1 -> SetHorizTickIncrement ( 1 );
2019-01-27 11:55:16 +01:00
$px1 -> draw ( $file , $fileurl );
2013-05-15 18:14:37 +02:00
$show1 = $px1 -> show ();
unset ( $graph_datas );
unset ( $px1 );
unset ( $tblyear [ 0 ]);
unset ( $tblyear [ 1 ]);
unset ( $tblyear [ 2 ]);
2019-10-26 14:42:25 +02:00
// DEDBT PART
2013-05-15 18:14:37 +02:00
// Chargement du tableau des années
$tblyear [ 0 ] = array ();
$tblyear [ 1 ] = array ();
$tblyear [ 2 ] = array ();
2021-02-23 21:09:01 +01:00
for ( $annee = 0 ; $annee < 3 ; $annee ++ ) {
2013-05-15 18:14:37 +02:00
$sql = " SELECT date_format(b.datev,'%m') " ;
2019-11-12 00:15:34 +01:00
$sql .= " , SUM(b.amount) " ;
$sql .= " FROM " . MAIN_DB_PREFIX . " bank as b " ;
$sql .= " , " . MAIN_DB_PREFIX . " bank_account as ba " ;
$sql .= " WHERE b.fk_account = ba.rowid " ;
$sql .= " AND ba.entity IN ( " . getEntity ( 'bank_account' ) . " ) " ;
$sql .= " AND b.datev >= ' " . ( $year - $annee ) . " -01-01 00:00:00' " ;
$sql .= " AND b.datev <= ' " . ( $year - $annee ) . " -12-31 23:59:59' " ;
$sql .= " AND b.amount < 0 " ;
2022-06-13 04:37:41 +02:00
if ( $id && GETPOST ( " option " ) != 'all' ) {
2021-03-22 11:30:18 +01:00
$sql .= " AND b.fk_account IN ( " . $db -> sanitize ( $id ) . " ) " ;
2021-02-23 21:09:01 +01:00
}
2013-05-15 18:14:37 +02:00
$sql .= " GROUP BY date_format(b.datev,'%m'); " ;
$resql = $db -> query ( $sql );
2021-02-23 21:09:01 +01:00
if ( $resql ) {
2013-05-15 18:14:37 +02:00
$num = $db -> num_rows ( $resql );
$i = 0 ;
2021-02-23 21:09:01 +01:00
while ( $i < $num ) {
2013-05-15 18:14:37 +02:00
$row = $db -> fetch_row ( $resql );
$tblyear [ $annee ][ $row [ 0 ]] = abs ( $row [ 1 ]);
$i ++ ;
}
$db -> free ( $resql );
2020-05-21 15:05:19 +02:00
} else {
2013-05-15 18:14:37 +02:00
dol_print_error ( $db );
}
}
// Chargement de labels et data_xxx pour tableau 4 Mouvements
$labels = array ();
$data_year_0 = array ();
$data_year_1 = array ();
$data_year_2 = array ();
2021-02-23 21:09:01 +01:00
for ( $i = 0 ; $i < 12 ; $i ++ ) {
2019-11-12 00:15:34 +01:00
$data_year_0 [ $i ] = isset ( $tblyear [ 0 ][ substr ( " 0 " . ( $i + 1 ), - 2 )]) ? $tblyear [ 0 ][ substr ( " 0 " . ( $i + 1 ), - 2 )] : 0 ;
$data_year_1 [ $i ] = isset ( $tblyear [ 1 ][ substr ( " 0 " . ( $i + 1 ), - 2 )]) ? $tblyear [ 1 ][ substr ( " 0 " . ( $i + 1 ), - 2 )] : 0 ;
$data_year_2 [ $i ] = isset ( $tblyear [ 2 ][ substr ( " 0 " . ( $i + 1 ), - 2 )]) ? $tblyear [ 2 ][ substr ( " 0 " . ( $i + 1 ), - 2 )] : 0 ;
$labels [ $i ] = $langs -> transnoentitiesnoconv ( " MonthVeryShort " . sprintf ( " %02d " , $i + 1 ));
2013-05-15 18:14:37 +02:00
$datamin [ $i ] = 0 ;
}
2019-11-12 00:15:34 +01:00
$file = $conf -> bank -> dir_temp . " /debmovement " . $id . " - " . $year . " .png " ;
$fileurl = DOL_URL_ROOT . '/viewimage.php?modulepart=banque_temp&file=' . " /debmovement " . $id . " - " . $year . " .png " ;
$title = $langs -> transnoentities ( " Debit " ) . ' - ' . $langs -> transnoentities ( " Year " ) . ': ' . ( $year - 2 ) . ' - ' . ( $year - 1 ) . " - " . $year ;
$graph_datas = array ();
2021-02-23 21:09:01 +01:00
for ( $i = 0 ; $i < 12 ; $i ++ ) {
2019-11-12 00:15:34 +01:00
$graph_datas [ $i ] = array ( $labels [ $i ], $data_year_0 [ $i ], $data_year_1 [ $i ], $data_year_2 [ $i ]);
2013-05-15 18:14:37 +02:00
}
$px2 = new DolGraph ();
$px2 -> SetData ( $graph_datas );
2019-11-12 00:15:34 +01:00
$px2 -> SetLegend ( array (( $year ), ( $year - 1 ), ( $year - 2 )));
2013-05-15 18:14:37 +02:00
$px2 -> SetLegendWidthMin ( 180 );
2019-11-12 00:15:34 +01:00
$px2 -> SetMaxValue ( $px2 -> GetCeilMaxValue () < 0 ? 0 : $px2 -> GetCeilMaxValue ());
$px2 -> SetMinValue ( $px2 -> GetFloorMinValue () > 0 ? 0 : $px2 -> GetFloorMinValue ());
2013-05-15 18:14:37 +02:00
$px2 -> SetTitle ( $title );
2016-11-11 23:47:56 +01:00
$px2 -> SetWidth ( $WIDTH );
$px2 -> SetHeight ( $HEIGHT );
2019-11-12 00:15:34 +01:00
$px2 -> SetType ( array ( 'line' , 'line' , 'line' ));
2013-05-15 18:14:37 +02:00
$px2 -> SetShading ( 3 );
$px2 -> setBgColor ( 'onglet' );
2019-11-12 00:15:34 +01:00
$px2 -> setBgColorGrid ( array ( 255 , 255 , 255 ));
2013-05-15 18:14:37 +02:00
$px2 -> SetHorizTickIncrement ( 1 );
2019-01-27 11:55:16 +01:00
$px2 -> draw ( $file , $fileurl );
2013-05-15 18:14:37 +02:00
$show2 = $px2 -> show ();
unset ( $graph_datas );
unset ( $px2 );
unset ( $tblyear [ 0 ]);
unset ( $tblyear [ 1 ]);
unset ( $tblyear [ 2 ]);
2019-11-12 00:15:34 +01:00
print '<div class="fichecenter"><div class="fichehalfleft"><div align="center">' ; // do not use class="center" here, it will have no effect for the js graph inside.
2013-05-15 18:14:37 +02:00
print $show1 ;
2021-10-23 17:18:35 +02:00
print '</div></div><div class="fichehalfright"><div align="center">' ; // do not use class="center" here, it will have no effect for the js graph inside.
2013-05-15 18:14:37 +02:00
print $show2 ;
2021-10-23 17:18:35 +02:00
print '</div></div></div>' ;
2013-07-26 12:45:31 +02:00
print '<div style="clear:both"></div>' ;
2013-05-15 18:14:37 +02:00
}
2017-03-03 14:27:01 +01:00
print " \n </div><br> \n " ;
2013-05-15 18:14:37 +02:00
2018-07-29 19:16:28 +02:00
// End of page
2013-05-15 18:14:37 +02:00
llxFooter ();
$db -> close ();