2017-08-27 00:33:50 +02:00
< ? php
2004-04-07 14:56:05 +02:00
/* Copyright ( C ) 2001 - 2004 Rodolphe Quiedeville < rodolphe @ quiedeville . org >
2012-01-08 23:43:32 +01:00
* Copyright ( C ) 2004 - 2012 Laurent Destailleur < eldy @ users . sourceforge . net >
2012-12-30 15:13:49 +01:00
* Copyright ( C ) 2005 - 2009 Regis Houssin < regis . houssin @ capnetworks . com >
2017-07-20 18:22:53 +02:00
* Copyright ( C ) 2017 Olivier Geffroy < jeff @ jeffinfo . com >
2003-06-29 11:01:29 +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
2013-01-16 15:36:08 +01:00
* the Free Software Foundation ; either version 3 of the License , or
2003-06-29 11:01:29 +02:00
* ( 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
2011-08-01 00:21:57 +02:00
* along with this program . If not , see < http :// www . gnu . org / licenses />.
2003-06-29 11:01:29 +02:00
*/
2005-01-31 21:03:10 +01:00
/**
2010-02-03 00:23:20 +01:00
* \file htdocs / compta / stats / index . php
* \brief Page reporting CA
*/
2005-01-31 21:03:10 +01:00
2012-08-22 23:24:21 +02:00
require '../../main.inc.php' ;
2012-08-22 23:11:24 +02:00
require_once DOL_DOCUMENT_ROOT . '/core/lib/report.lib.php' ;
2017-08-31 15:44:36 +02:00
require_once DOL_DOCUMENT_ROOT . '/core/lib/date.lib.php' ;
2018-05-27 09:27:09 +02:00
// Load translation files required by the page
2017-08-31 18:29:57 +02:00
$langs -> loadLangs ( array ( 'compta' , 'bills' , 'donation' , 'salaries' ));
2017-08-31 15:44:36 +02:00
$date_startmonth = GETPOST ( 'date_startmonth' );
$date_startday = GETPOST ( 'date_startday' );
$date_startyear = GETPOST ( 'date_startyear' );
$date_endmonth = GETPOST ( 'date_endmonth' );
$date_endday = GETPOST ( 'date_endday' );
$date_endyear = GETPOST ( 'date_endyear' );
2008-01-10 18:12:07 +01:00
2011-06-13 13:10:43 +02:00
$nbofyear = 4 ;
2017-08-31 15:44:36 +02:00
// Date range
$year = GETPOST ( 'year' , 'int' );
if ( empty ( $year ))
{
$year_current = strftime ( " %Y " , dol_now ());
$month_current = strftime ( " %m " , dol_now ());
$year_start = $year_current - ( $nbofyear - 1 );
} else {
$year_current = $year ;
$month_current = strftime ( " %m " , dol_now ());
$year_start = $year - ( $nbofyear - 1 );
2005-01-31 21:03:10 +01:00
}
2017-08-31 15:44:36 +02:00
$date_start = dol_mktime ( 0 , 0 , 0 , $date_startmonth , $date_startday , $date_startyear );
$date_end = dol_mktime ( 23 , 59 , 59 , $date_endmonth , $date_endday , $date_endyear );
// We define date_start and date_end
if ( empty ( $date_start ) || empty ( $date_end )) // We define date_start and date_end
{
$q = GETPOST ( " q " ) ? GETPOST ( " q " ) : 0 ;
if ( $q == 0 )
{
// We define date_start and date_end
$year_end = $year_start + ( $nbofyear - 1 );
$month_start = GETPOST ( " month " ) ? GETPOST ( " month " ) : ( $conf -> global -> SOCIETE_FISCAL_MONTH_START ? ( $conf -> global -> SOCIETE_FISCAL_MONTH_START ) : 1 );
if ( ! GETPOST ( 'month' ))
{
if ( ! GETPOST ( " year " ) && $month_start > $month_current )
{
$year_start -- ;
$year_end -- ;
}
$month_end = $month_start - 1 ;
if ( $month_end < 1 ) $month_end = 12 ;
}
else $month_end = $month_start ;
$date_start = dol_get_first_day ( $year_start , $month_start , false ); $date_end = dol_get_last_day ( $year_end , $month_end , false );
}
if ( $q == 1 ) { $date_start = dol_get_first_day ( $year_start , 1 , false ); $date_end = dol_get_last_day ( $year_start , 3 , false ); }
if ( $q == 2 ) { $date_start = dol_get_first_day ( $year_start , 4 , false ); $date_end = dol_get_last_day ( $year_start , 6 , false ); }
if ( $q == 3 ) { $date_start = dol_get_first_day ( $year_start , 7 , false ); $date_end = dol_get_last_day ( $year_start , 9 , false ); }
if ( $q == 4 ) { $date_start = dol_get_first_day ( $year_start , 10 , false ); $date_end = dol_get_last_day ( $year_start , 12 , false ); }
2005-01-31 21:03:10 +01:00
}
2017-08-31 15:44:36 +02:00
2012-02-27 22:26:22 +01:00
$userid = GETPOST ( 'userid' , 'int' );
2013-01-10 08:27:12 +01:00
$socid = GETPOST ( 'socid' , 'int' );
2017-08-31 15:44:36 +02:00
2018-04-29 23:22:46 +02:00
$tmps = dol_getdate ( $date_start );
$year_start = $tmps [ 'year' ];
$tmpe = dol_getdate ( $date_end );
$year_end = $tmpe [ 'year' ];
$nbofyear = ( $year_end - $year_start ) + 1 ;
2017-08-31 15:44:36 +02:00
// Define modecompta ('CREANCES-DETTES' or 'RECETTES-DEPENSES' or 'BOOKKEEPING')
2014-09-21 20:30:55 +02:00
$modecompta = $conf -> global -> ACCOUNTING_MODE ;
2017-08-31 15:44:36 +02:00
if ( ! empty ( $conf -> accounting -> enabled )) $modecompta = 'BOOKKEEPING' ;
2016-12-18 13:27:14 +01:00
if ( GETPOST ( " modecompta " )) $modecompta = GETPOST ( " modecompta " , 'alpha' );
2013-01-02 18:43:59 +01:00
2010-02-03 00:23:20 +01:00
// Security check
if ( $user -> societe_id > 0 ) $socid = $user -> societe_id ;
2013-01-02 18:43:59 +01:00
if ( ! empty ( $conf -> comptabilite -> enabled )) $result = restrictedArea ( $user , 'compta' , '' , '' , 'resultat' );
if ( ! empty ( $conf -> accounting -> enabled )) $result = restrictedArea ( $user , 'accounting' , '' , '' , 'comptarapport' );
2003-06-29 11:01:29 +02:00
2004-02-16 22:20:42 +01:00
2008-02-16 18:50:25 +01:00
2010-02-03 00:23:20 +01:00
/*
* View
*/
2005-05-03 02:41:51 +02:00
llxHeader ();
2017-08-31 15:44:36 +02:00
2011-11-08 10:18:45 +01:00
$form = new Form ( $db );
2005-05-03 02:41:51 +02:00
2010-02-03 00:23:20 +01:00
// Affiche en-tete du rapport
2005-04-07 23:21:44 +02:00
if ( $modecompta == " CREANCES-DETTES " )
{
2018-06-26 11:18:31 +02:00
$name = $langs -> trans ( " Turnover " );
2013-10-10 19:26:07 +02:00
$calcmode = $langs -> trans ( " CalcModeDebt " );
2018-06-26 11:18:31 +02:00
//$calcmode.='<br>('.$langs->trans("SeeReportInInputOutputMode",'<a href="'.$_SERVER["PHP_SELF"].'?year_start='.$year_start.'&modecompta=RECETTES-DEPENSES">','</a>').')';
2017-07-20 18:22:53 +02:00
$calcmode .= '<br>(' . $langs -> trans ( " SeeReportInBookkeepingMode " , '<a href="' . $_SERVER [ " PHP_SELF " ] . '?year_start=' . $year_start . '&modecompta=BOOKKEEPING">' , '</a>' ) . ')' ;
2017-08-31 15:44:36 +02:00
$period = $form -> select_date ( $date_start , 'date_start' , 0 , 0 , 0 , '' , 1 , 0 , 1 ) . ' - ' . $form -> select_date ( $date_end , 'date_end' , 0 , 0 , 0 , '' , 1 , 0 , 1 );
2018-04-23 11:39:34 +02:00
$periodlink = ( $year_start ? " <a href=' " . $_SERVER [ " PHP_SELF " ] . " ?year= " . ( $year_start + $nbofyear - 2 ) . " &modecompta= " . $modecompta . " '> " . img_previous () . " </a> <a href=' " . $_SERVER [ " PHP_SELF " ] . " ?year= " . ( $year_start + $nbofyear ) . " &modecompta= " . $modecompta . " '> " . img_next () . " </a> " : " " );
2010-02-03 00:23:20 +01:00
$description = $langs -> trans ( " RulesCADue " );
2012-01-08 23:43:32 +01:00
if ( ! empty ( $conf -> global -> FACTURE_DEPOSITS_ARE_JUST_PAYMENTS )) $description .= $langs -> trans ( " DepositsAreNotIncluded " );
else $description .= $langs -> trans ( " DepositsAreIncluded " );
2017-09-05 09:43:22 +02:00
$builddate = dol_now ();
2011-01-10 23:36:34 +01:00
//$exportlink=$langs->trans("NotYetAvailable");
2005-04-07 23:21:44 +02:00
}
2017-07-20 18:22:53 +02:00
else if ( $modecompta == " RECETTES-DEPENSES " )
{
2018-06-26 11:18:31 +02:00
$name = $langs -> trans ( " TurnoverCollected " );
2013-10-10 19:26:07 +02:00
$calcmode = $langs -> trans ( " CalcModeEngagement " );
2018-06-26 11:18:31 +02:00
//$calcmode.='<br>('.$langs->trans("SeeReportInDueDebtMode",'<a href="'.$_SERVER["PHP_SELF"].'?year_start='.$year_start.'&modecompta=CREANCES-DETTES">','</a>').')';
//$calcmode.='<br>('.$langs->trans("SeeReportInBookkeepingMode",'<a href="'.$_SERVER["PHP_SELF"].'?year_start='.$year_start.'&modecompta=BOOKKEEPINGCOLLECTED">','</a>').')';
2017-08-31 15:44:36 +02:00
$period = $form -> select_date ( $date_start , 'date_start' , 0 , 0 , 0 , '' , 1 , 0 , 1 ) . ' - ' . $form -> select_date ( $date_end , 'date_end' , 0 , 0 , 0 , '' , 1 , 0 , 1 );
2018-04-23 11:39:34 +02:00
$periodlink = ( $year_start ? " <a href=' " . $_SERVER [ " PHP_SELF " ] . " ?year= " . ( $year_start + $nbofyear - 2 ) . " &modecompta= " . $modecompta . " '> " . img_previous () . " </a> <a href=' " . $_SERVER [ " PHP_SELF " ] . " ?year= " . ( $year_start + $nbofyear ) . " &modecompta= " . $modecompta . " '> " . img_next () . " </a> " : " " );
2010-02-03 00:23:20 +01:00
$description = $langs -> trans ( " RulesCAIn " );
2012-01-08 23:43:32 +01:00
$description .= $langs -> trans ( " DepositsAreIncluded " );
2017-09-05 09:43:22 +02:00
$builddate = dol_now ();
2011-01-10 23:36:34 +01:00
//$exportlink=$langs->trans("NotYetAvailable");
2005-04-07 23:21:44 +02:00
}
2017-07-20 18:22:53 +02:00
else if ( $modecompta == " BOOKKEEPING " )
{
2018-06-26 11:18:31 +02:00
$name = $langs -> trans ( " Turnover " );
2017-07-20 18:22:53 +02:00
$calcmode = $langs -> trans ( " CalcModeBookkeeping " );
$calcmode .= '<br>(' . $langs -> trans ( " SeeReportInDueDebtMode " , '<a href="' . $_SERVER [ " PHP_SELF " ] . '?year_start=' . $year_start . '&modecompta=CREANCES-DETTES">' , '</a>' ) . ')' ;
2018-06-26 11:18:31 +02:00
//$calcmode.='<br>('.$langs->trans("SeeReportInInputOutputMode",'<a href="'.$_SERVER["PHP_SELF"].'?year_start='.$year_start.'&modecompta=RECETTES-DEPENSES">','</a>').')';
2017-08-31 15:44:36 +02:00
$period = $form -> select_date ( $date_start , 'date_start' , 0 , 0 , 0 , '' , 1 , 0 , 1 ) . ' - ' . $form -> select_date ( $date_end , 'date_end' , 0 , 0 , 0 , '' , 1 , 0 , 1 );
2018-04-23 11:39:34 +02:00
$periodlink = ( $year_start ? " <a href=' " . $_SERVER [ " PHP_SELF " ] . " ?year= " . ( $year_start + $nbofyear - 2 ) . " &modecompta= " . $modecompta . " '> " . img_previous () . " </a> <a href=' " . $_SERVER [ " PHP_SELF " ] . " ?year= " . ( $year_start + $nbofyear ) . " &modecompta= " . $modecompta . " '> " . img_next () . " </a> " : " " );
2018-03-06 19:56:08 +01:00
$description = $langs -> trans ( " RulesCATotalSaleJournal " );
2017-09-05 09:43:22 +02:00
$builddate = dol_now ();
2017-07-20 18:22:53 +02:00
//$exportlink=$langs->trans("NotYetAvailable");
}
2012-01-14 13:45:42 +01:00
$moreparam = array ();
if ( ! empty ( $modecompta )) $moreparam [ 'modecompta' ] = $modecompta ;
2017-08-31 15:44:36 +02:00
report_header ( $name , $namelink , $period , $periodlink , $description , $builddate , $exportlink , $moreparam , $calcmode );
2003-06-29 11:01:29 +02:00
2017-08-31 15:44:36 +02:00
if ( ! empty ( $conf -> accounting -> enabled ) && $modecompta != 'BOOKKEEPING' )
2016-10-10 21:22:28 +02:00
{
print info_admin ( $langs -> trans ( " WarningReportNotReliable " ), 0 , 0 , 1 );
}
2005-04-07 23:21:44 +02:00
2012-01-08 23:43:32 +01:00
if ( $modecompta == 'CREANCES-DETTES' )
{
2010-11-16 23:04:07 +01:00
$sql = " SELECT date_format(f.datef,'%Y-%m') as dm, sum(f.total) as amount, sum(f.total_ttc) as amount_ttc " ;
2009-05-08 17:58:01 +02:00
$sql .= " FROM " . MAIN_DB_PREFIX . " facture as f " ;
$sql .= " WHERE f.fk_statut in (1,2) " ;
2014-11-14 16:43:49 +01:00
if ( ! empty ( $conf -> global -> FACTURE_DEPOSITS_ARE_JUST_PAYMENTS )) $sql .= " AND f.type IN (0,1,2,5) " ;
else $sql .= " AND f.type IN (0,1,2,3,5) " ;
2017-07-20 18:22:53 +02:00
$sql .= " AND f.entity = " . $conf -> entity ;
if ( $socid ) $sql .= " AND f.fk_soc = " . $socid ;
2012-01-08 23:43:32 +01:00
}
2017-07-20 18:22:53 +02:00
else if ( $modecompta == " RECETTES-DEPENSES " )
2012-01-08 23:43:32 +01:00
{
2010-02-03 00:23:20 +01:00
/*
* Liste des paiements ( les anciens paiements ne sont pas vus par cette requete car , sur les
* vieilles versions , ils n ' etaient pas lies via paiement_facture . On les ajoute plus loin )
*/
2010-11-16 23:04:07 +01:00
$sql = " SELECT date_format(p.datep,'%Y-%m') as dm, sum(pf.amount) as amount_ttc " ;
2009-05-08 17:58:01 +02:00
$sql .= " FROM " . MAIN_DB_PREFIX . " facture as f " ;
$sql .= " , " . MAIN_DB_PREFIX . " paiement_facture as pf " ;
$sql .= " , " . MAIN_DB_PREFIX . " paiement as p " ;
2010-02-03 00:23:20 +01:00
$sql .= " WHERE p.rowid = pf.fk_paiement " ;
$sql .= " AND pf.fk_facture = f.rowid " ;
2017-07-20 18:22:53 +02:00
$sql .= " AND f.entity = " . $conf -> entity ;
2009-05-08 17:58:01 +02:00
if ( $socid ) $sql .= " AND f.fk_soc = " . $socid ;
2017-07-20 18:22:53 +02:00
}
else if ( $modecompta == " BOOKKEEPING " )
{
$sql = " SELECT date_format(b.doc_date,'%Y-%m') as dm, sum(b.credit) as amount_ttc " ;
2018-03-06 19:56:08 +01:00
$sql .= " FROM " . MAIN_DB_PREFIX . " accounting_bookkeeping as b, " . MAIN_DB_PREFIX . " accounting_journal as aj " ;
$sql .= " WHERE b.entity = " . $conf -> entity ;
$sql .= " AND b.code_journal = aj.code AND aj.nature = 2 " ; // @TODO currently count amount in sale journal, but we need to define a category group for turnover
2017-07-20 18:22:53 +02:00
}
2010-11-16 23:04:07 +01:00
$sql .= " GROUP BY dm " ;
$sql .= " ORDER BY dm " ;
2018-03-06 19:56:08 +01:00
//print $sql;
2003-06-29 11:01:29 +02:00
$result = $db -> query ( $sql );
if ( $result )
{
2010-02-03 00:23:20 +01:00
$num = $db -> num_rows ( $result );
$i = 0 ;
while ( $i < $num )
{
$obj = $db -> fetch_object ( $result );
2013-07-16 00:30:44 +02:00
$cum_ht [ $obj -> dm ] = ! empty ( $obj -> amount ) ? $obj -> amount : 0 ;
2010-02-03 00:23:20 +01:00
$cum [ $obj -> dm ] = $obj -> amount_ttc ;
if ( $obj -> amount_ttc )
{
$minyearmonth = ( $minyearmonth ? min ( $minyearmonth , $obj -> dm ) : $obj -> dm );
$maxyearmonth = max ( $maxyearmonth , $obj -> dm );
}
$i ++ ;
}
$db -> free ( $result );
2005-04-07 23:21:44 +02:00
}
else {
2010-02-03 00:23:20 +01:00
dol_print_error ( $db );
2003-06-29 11:01:29 +02:00
}
2016-10-04 13:45:22 +02:00
// On ajoute les paiements anciennes version, non lies par paiement_facture (very old versions)
2018-03-06 19:56:08 +01:00
if ( $modecompta == 'RECETTES-DEPENSES' )
2012-01-08 23:43:32 +01:00
{
2010-11-16 23:04:07 +01:00
$sql = " SELECT date_format(p.datep,'%Y-%m') as dm, sum(p.amount) as amount_ttc " ;
2010-02-03 00:23:20 +01:00
$sql .= " FROM " . MAIN_DB_PREFIX . " bank as b " ;
$sql .= " , " . MAIN_DB_PREFIX . " bank_account as ba " ;
$sql .= " , " . MAIN_DB_PREFIX . " paiement as p " ;
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . " paiement_facture as pf ON p.rowid = pf.fk_paiement " ;
$sql .= " WHERE pf.rowid IS NULL " ;
$sql .= " AND p.fk_bank = b.rowid " ;
$sql .= " AND b.fk_account = ba.rowid " ;
2017-05-30 18:50:54 +02:00
$sql .= " AND ba.entity IN ( " . getEntity ( 'bank_account' ) . " ) " ;
2010-02-03 00:23:20 +01:00
$sql .= " GROUP BY dm " ;
$sql .= " ORDER BY dm " ;
$result = $db -> query ( $sql );
2012-01-08 23:43:32 +01:00
if ( $result )
{
2010-02-03 00:23:20 +01:00
$num = $db -> num_rows ( $result );
$i = 0 ;
while ( $i < $num )
{
$obj = $db -> fetch_object ( $result );
$cum [ $obj -> dm ] += $obj -> amount_ttc ;
if ( $obj -> amount_ttc )
{
$minyearmonth = ( $minyearmonth ? min ( $minyearmonth , $obj -> dm ) : $obj -> dm );
$maxyearmonth = max ( $maxyearmonth , $obj -> dm );
}
$i ++ ;
}
}
2012-01-08 23:43:32 +01:00
else
{
2010-02-03 00:23:20 +01:00
dol_print_error ( $db );
}
2005-05-06 02:21:33 +02:00
}
2016-11-28 19:30:55 +01:00
$moreforfilter = '' ;
2005-05-06 02:21:33 +02:00
2016-11-28 19:30:55 +01:00
print '<div class="div-table-responsive">' ;
print '<table class="tagtable liste' . ( $moreforfilter ? " listwithfilterbefore " : " " ) . '">' . " \n " ;
2011-06-13 13:10:43 +02:00
2011-07-20 21:03:31 +02:00
print '<tr class="liste_titre"><td> </td>' ;
2003-06-29 11:01:29 +02:00
for ( $annee = $year_start ; $annee <= $year_end ; $annee ++ )
{
2013-07-16 00:30:44 +02:00
if ( $modecompta == 'CREANCES-DETTES' ) print '<td align="center" width="10%" colspan="3">' ;
2014-11-07 23:25:39 +01:00
else print '<td align="center" width="10%" colspan="2" class="borderrightlight">' ;
2018-03-06 19:56:08 +01:00
if ( $modecompta != 'BOOKKEEPING' ) print '<a href="casoc.php?year=' . $annee . '">' ;
2011-06-13 13:10:43 +02:00
print $annee ;
if ( $conf -> global -> SOCIETE_FISCAL_MONTH_START > 1 ) print '-' . ( $annee + 1 );
2018-03-06 19:56:08 +01:00
if ( $modecompta != 'BOOKKEEPING' ) print '</a>' ;
print '</td>' ;
2010-02-03 00:23:20 +01:00
if ( $annee != $year_end ) print '<td width="15"> </td>' ;
2003-06-29 11:01:29 +02:00
}
2004-02-08 18:38:37 +01:00
print '</tr>' ;
2004-02-16 22:20:42 +01:00
2016-12-27 02:01:27 +01:00
print '<tr class="liste_titre"><td class="liste_titre">' . $langs -> trans ( " Month " ) . '</td>' ;
2004-02-16 22:20:42 +01:00
for ( $annee = $year_start ; $annee <= $year_end ; $annee ++ )
{
2016-12-27 02:01:27 +01:00
if ( $modecompta == 'CREANCES-DETTES' ) print '<td class="liste_titre" align="right">' . $langs -> trans ( " AmountHT " ) . '</td>' ;
print '<td class="liste_titre" align="right">' . $langs -> trans ( " AmountTTC " ) . '</td>' ;
print '<td class="liste_titre" align="right" class="borderrightlight">' . $langs -> trans ( " Delta " ) . '</td>' ;
if ( $annee != $year_end ) print '<td class="liste_titre" width="15"> </td>' ;
2004-02-16 22:20:42 +01:00
}
print '</tr>' ;
2005-04-16 01:47:41 +02:00
$now_show_delta = 0 ;
$minyear = substr ( $minyearmonth , 0 , 4 );
$maxyear = substr ( $maxyearmonth , 0 , 4 );
2011-01-05 17:22:06 +01:00
$nowyear = strftime ( " %Y " , dol_now ());
$nowyearmonth = strftime ( " %Y-%m " , dol_now ());
$maxyearmonth = max ( $maxyearmonth , $nowyearmonth );
2014-12-21 14:15:36 +01:00
$now = dol_now ();
$casenow = dol_print_date ( $now , " %Y-%m " );
2005-04-16 01:47:41 +02:00
2011-01-05 17:22:06 +01:00
// Loop on each month
$nb_mois_decalage = $conf -> global -> SOCIETE_FISCAL_MONTH_START ? ( $conf -> global -> SOCIETE_FISCAL_MONTH_START - 1 ) : 0 ;
for ( $mois = 1 + $nb_mois_decalage ; $mois <= 12 + $nb_mois_decalage ; $mois ++ )
2003-06-29 11:01:29 +02:00
{
2011-01-05 17:22:06 +01:00
$mois_modulo = $mois ; // ajout
if ( $mois > 12 ){ $mois_modulo = $mois - 12 ;} // ajout
2017-08-31 15:44:36 +02:00
2017-04-14 11:22:48 +02:00
print '<tr class="oddeven">' ;
2010-02-03 00:23:20 +01:00
2011-01-05 17:22:06 +01:00
print " <td> " . dol_print_date ( dol_mktime ( 12 , 0 , 0 , $mois_modulo , 1 , 2000 ), " %B " ) . " </td> " ;
2014-12-21 14:15:36 +01:00
for ( $annee = $year_start - 1 ; $annee <= $year_end ; $annee ++ ) // We start one year before to have data to be able to make delta
2010-02-03 00:23:20 +01:00
{
2011-01-05 17:22:06 +01:00
$annee_decalage = $annee ;
2012-04-30 15:01:25 +02:00
if ( $mois > 12 ) { $annee_decalage = $annee + 1 ;}
2011-01-05 17:22:06 +01:00
$case = dol_print_date ( dol_mktime ( 1 , 1 , 1 , $mois_modulo , 1 , $annee_decalage ), " %Y-%m " );
$caseprev = dol_print_date ( dol_mktime ( 1 , 1 , 1 , $mois_modulo , 1 , $annee_decalage - 1 ), " %Y-%m " );
2010-02-03 00:23:20 +01:00
2014-12-21 14:15:36 +01:00
if ( $annee >= $year_start )
{
if ( $modecompta == 'CREANCES-DETTES' ) {
// Valeur CA du mois w/o VAT
print '<td align="right">' ;
if ( $cum_ht [ $case ])
{
$now_show_delta = 1 ; // On a trouve le premier mois de la premiere annee generant du chiffre.
print '<a href="casoc.php?year=' . $annee_decalage . '&month=' . $mois_modulo . ( $modecompta ? '&modecompta=' . $modecompta : '' ) . '">' . price ( $cum_ht [ $case ], 1 ) . '</a>' ;
}
else
{
if ( $minyearmonth < $case && $case <= max ( $maxyearmonth , $nowyearmonth )) { print '0' ; }
else { print ' ' ; }
}
print " </td> " ;
}
// Valeur CA du mois
2013-07-16 00:30:44 +02:00
print '<td align="right">' ;
2014-12-21 14:15:36 +01:00
if ( $cum [ $case ])
2013-07-16 00:30:44 +02:00
{
$now_show_delta = 1 ; // On a trouve le premier mois de la premiere annee generant du chiffre.
2018-03-06 19:56:08 +01:00
if ( $modecompta != 'BOOKKEEPING' ) print '<a href="casoc.php?year=' . $annee_decalage . '&month=' . $mois_modulo . ( $modecompta ? '&modecompta=' . $modecompta : '' ) . '">' ;
print price ( $cum [ $case ], 1 );
if ( $modecompta != 'BOOKKEEPING' ) print '</a>' ;
2013-07-16 00:30:44 +02:00
}
else
{
if ( $minyearmonth < $case && $case <= max ( $maxyearmonth , $nowyearmonth )) { print '0' ; }
else { print ' ' ; }
}
print " </td> " ;
2014-11-07 23:25:39 +01:00
2014-12-21 14:15:36 +01:00
// Pourcentage du mois
if ( $annee_decalage > $minyear && $case <= $casenow )
2010-02-03 00:23:20 +01:00
{
2014-12-21 14:15:36 +01:00
if ( $cum [ $caseprev ] && $cum [ $case ])
{
$percent = ( round (( $cum [ $case ] - $cum [ $caseprev ]) / $cum [ $caseprev ], 4 ) * 100 );
//print "X $cum[$case] - $cum[$caseprev] - $cum[$caseprev] - $percent X";
print '<td align="right" class="borderrightlight">' . ( $percent >= 0 ? " + $percent " : " $percent " ) . '%</td>' ;
}
if ( $cum [ $caseprev ] && ! $cum [ $case ])
{
print '<td align="right" class="borderrightlight">-100%</td>' ;
}
if ( ! $cum [ $caseprev ] && $cum [ $case ])
{
//print '<td align="right">+Inf%</td>';
print '<td align="right" class="borderrightlight">-</td>' ;
}
if ( isset ( $cum [ $caseprev ]) && ! $cum [ $caseprev ] && ! $cum [ $case ])
{
print '<td align="right" class="borderrightlight">+0%</td>' ;
}
if ( ! isset ( $cum [ $caseprev ]) && ! $cum [ $case ])
{
print '<td align="right" class="borderrightlight">-</td>' ;
}
2010-02-03 00:23:20 +01:00
}
2014-12-21 14:15:36 +01:00
else
2011-01-05 17:22:06 +01:00
{
2014-12-21 14:15:36 +01:00
print '<td align="right" class="borderrightlight">' ;
if ( $minyearmonth <= $case && $case <= $maxyearmonth ) { print '-' ; }
else { print ' ' ; }
print '</td>' ;
2011-01-05 17:22:06 +01:00
}
2014-12-21 14:15:36 +01:00
if ( $annee_decalage != $year_end ) print '<td width="15"> </td>' ;
2010-02-03 00:23:20 +01:00
}
2015-04-18 18:07:41 +02:00
$total_ht [ $annee ] +=! empty ( $cum_ht [ $case ]) ? $cum_ht [ $case ] : 0 ;
2010-02-03 00:23:20 +01:00
$total [ $annee ] += $cum [ $case ];
}
print '</tr>' ;
2003-06-29 11:01:29 +02:00
}
2011-01-05 17:22:06 +01:00
/*
for ( $mois = 1 ; $mois < 13 ; $mois ++ )
{
2017-08-31 15:44:36 +02:00
2017-04-14 11:22:48 +02:00
print '<tr class="oddeven">' ;
2011-01-05 17:22:06 +01:00
print " <td> " . dol_print_date ( dol_mktime ( 12 , 0 , 0 , $mois , 1 , 2000 ), " %B " ) . " </td> " ;
for ( $annee = $year_start ; $annee <= $year_end ; $annee ++ )
{
$casenow = dol_print_date ( mktime (), " %Y-%m " );
$case = dol_print_date ( dol_mktime ( 1 , 1 , 1 , $mois , 1 , $annee ), " %Y-%m " );
$caseprev = dol_print_date ( dol_mktime ( 1 , 1 , 1 , $mois , 1 , $annee - 1 ), " %Y-%m " );
// Valeur CA du mois
print '<td align="right">' ;
if ( $cum [ $case ])
{
$now_show_delta = 1 ; // On a trouve le premier mois de la premiere annee generant du chiffre.
print '<a href="casoc.php?year=' . $annee . '&month=' . $mois . '">' . price ( $cum [ $case ], 1 ) . '</a>' ;
}
else
{
if ( $minyearmonth < $case && $case <= max ( $maxyearmonth , $nowyearmonth )) { print '0' ; }
else { print ' ' ; }
}
print " </td> " ;
// Pourcentage du mois
if ( $annee > $minyear && $case <= $casenow ) {
if ( $cum [ $caseprev ] && $cum [ $case ])
{
$percent = ( round (( $cum [ $case ] - $cum [ $caseprev ]) / $cum [ $caseprev ], 4 ) * 100 );
//print "X $cum[$case] - $cum[$caseprev] - $cum[$caseprev] - $percent X";
print '<td align="right">' . ( $percent >= 0 ? " + $percent " : " $percent " ) . '%</td>' ;
}
if ( $cum [ $caseprev ] && ! $cum [ $case ])
{
print '<td align="right">-100%</td>' ;
}
if ( ! $cum [ $caseprev ] && $cum [ $case ])
{
print '<td align="right">+Inf%</td>' ;
}
if ( ! $cum [ $caseprev ] && ! $cum [ $case ])
{
print '<td align="right">+0%</td>' ;
}
}
else
{
print '<td align="right">' ;
if ( $minyearmonth <= $case && $case <= $maxyearmonth ) { print '-' ; }
else { print ' ' ; }
print '</td>' ;
}
$total [ $annee ] += $cum [ $case ];
if ( $annee != $year_end ) print '<td width="15"> </td>' ;
}
print '</tr>' ;
}
*/
2004-02-08 18:38:37 +01:00
// Affiche total
2005-06-11 13:58:06 +02:00
print '<tr class="liste_total"><td>' . $langs -> trans ( " Total " ) . '</td>' ;
2004-02-08 18:38:37 +01:00
for ( $annee = $year_start ; $annee <= $year_end ; $annee ++ )
{
2013-07-16 00:30:44 +02:00
if ( $modecompta == 'CREANCES-DETTES' ) {
// Montant total HT
if ( $total_ht [ $annee ] || ( $annee >= $minyear && $annee <= max ( $nowyear , $maxyear )))
{
print '<td align="right" class="nowrap">' . ( $total_ht [ $annee ] ? price ( $total_ht [ $annee ]) : " 0 " ) . " </td> " ;
}
else
{
print '<td> </td>' ;
}
}
2014-11-07 23:25:39 +01:00
2010-02-03 00:23:20 +01:00
// Montant total
2011-01-05 17:22:06 +01:00
if ( $total [ $annee ] || ( $annee >= $minyear && $annee <= max ( $nowyear , $maxyear )))
2010-02-03 00:23:20 +01:00
{
2013-04-25 01:13:13 +02:00
print '<td align="right" class="nowrap">' . ( $total [ $annee ] ? price ( $total [ $annee ]) : " 0 " ) . " </td> " ;
2010-02-03 00:23:20 +01:00
}
else
{
print '<td> </td>' ;
}
// Pourcentage total
2011-01-10 23:36:34 +01:00
if ( $annee > $minyear && $annee <= max ( $nowyear , $maxyear ))
2011-01-05 17:22:06 +01:00
{
2010-02-03 00:23:20 +01:00
if ( $total [ $annee - 1 ] && $total [ $annee ]) {
$percent = ( round (( $total [ $annee ] - $total [ $annee - 1 ]) / $total [ $annee - 1 ], 4 ) * 100 );
2014-11-07 23:25:39 +01:00
print '<td align="right" class="nowrap borderrightlight">' . ( $percent >= 0 ? " + $percent " : " $percent " ) . '%</td>' ;
2010-02-03 00:23:20 +01:00
}
if ( $total [ $annee - 1 ] && ! $total [ $annee ])
{
2014-11-07 23:25:39 +01:00
print '<td align="right" class="borderrightlight">-100%</td>' ;
2010-02-03 00:23:20 +01:00
}
if ( ! $total [ $annee - 1 ] && $total [ $annee ])
{
2018-04-27 10:23:09 +02:00
print '<td align="right" class="borderrightlight">+' . $langs -> trans ( 'Inf' ) . '%</td>' ;
2010-02-03 00:23:20 +01:00
}
if ( ! $total [ $annee - 1 ] && ! $total [ $annee ])
{
2014-11-07 23:25:39 +01:00
print '<td align="right" class="borderrightlight">+0%</td>' ;
2010-02-03 00:23:20 +01:00
}
}
else
{
2014-11-07 23:25:39 +01:00
print '<td align="right" class="borderrightlight">' ;
2011-01-05 17:22:06 +01:00
if ( $total [ $annee ] || ( $minyear <= $annee && $annee <= max ( $nowyear , $maxyear ))) { print '-' ; }
2010-02-03 00:23:20 +01:00
else { print ' ' ; }
print '</td>' ;
}
if ( $annee != $year_end ) print '<td width="15"> </td>' ;
2004-02-08 18:38:37 +01:00
}
print " </tr> \n " ;
2005-04-16 01:47:41 +02:00
print " </table> " ;
2016-11-28 19:30:55 +01:00
print '</div>' ;
2005-04-16 01:47:41 +02:00
2005-04-08 01:39:47 +02:00
2005-03-15 10:24:03 +01:00
/*
2010-02-03 00:23:20 +01:00
* En mode recettes / depenses , on complete avec les montants factures non regles
* et les propales signees mais pas facturees . En effet , en recettes - depenses ,
* on comptabilise lorsque le montant est sur le compte donc il est interessant
2005-04-08 01:39:47 +02:00
* d ' avoir une vision de ce qui va arriver .
*/
2005-04-16 01:47:41 +02:00
/*
2010-02-03 00:23:20 +01:00
Je commente toute cette partie car les chiffres affichees sont faux - Eldy .
En attendant correction .
if ( $modecompta != 'CREANCES-DETTES' )
{
print '<br><table width="100%" class="noborder">' ;
// Factures non reglees
2011-09-03 02:14:27 +02:00
// Y a bug ici. Il faut prendre le reste a payer et non le total des factures non reglees !
2010-02-03 00:23:20 +01:00
$sql = " SELECT f.facnumber, f.rowid, s.nom, s.rowid as socid, f.total_ttc, sum(pf.amount) as am " ;
$sql .= " FROM " . MAIN_DB_PREFIX . " societe as s, " . MAIN_DB_PREFIX . " facture as f left join " . MAIN_DB_PREFIX . " paiement_facture as pf on f.rowid=pf.fk_facture " ;
$sql .= " WHERE s.rowid = f.fk_soc AND f.paye = 0 AND f.fk_statut = 1 " ;
if ( $socid )
{
$sql .= " AND f.fk_soc = $socid " ;
}
$sql .= " GROUP BY f.facnumber,f.rowid,s.nom, s.rowid, f.total_ttc " ;
2010-08-09 17:42:57 +02:00
$resql = $db -> query ( $sql );
if ( $resql )
2010-02-03 00:23:20 +01:00
{
2010-08-09 17:42:57 +02:00
$num = $db -> num_rows ( $resql );
2010-02-03 00:23:20 +01:00
$i = 0 ;
if ( $num )
{
$total_ttc_Rac = $totalam_Rac = $total_Rac = 0 ;
while ( $i < $num )
{
2010-08-09 17:42:57 +02:00
$obj = $db -> fetch_object ( $resql );
2010-02-03 00:23:20 +01:00
$total_ttc_Rac += $obj -> total_ttc ;
$totalam_Rac += $obj -> am ;
$i ++ ;
}
2017-08-31 15:44:36 +02:00
2018-05-15 17:51:19 +02:00
print " <tr class= " oddeven " ><td align= \" right \" colspan= \" 5 \" ><i>Facture a encaisser : </i></td><td align= \" right \" ><i> " . price ( $total_ttc_Rac ) . " </i></td><td colspan= \" 5 \" ><-- bug ici car n'exclut pas le deja r?gl? des factures partiellement r?gl?es</td></tr> " ;
2010-02-03 00:23:20 +01:00
}
2010-08-09 17:42:57 +02:00
$db -> free ( $resql );
2010-02-03 00:23:20 +01:00
}
else
{
dol_print_error ( $db );
}
*/
2005-03-15 10:24:03 +01:00
/*
2010-02-03 00:23:20 +01:00
*
* Propales signees , et non facturees
*
*/
2005-04-16 01:47:41 +02:00
/*
2010-02-03 00:23:20 +01:00
Je commente toute cette partie car les chiffres affichees sont faux - Eldy .
En attendant correction .
$sql = " SELECT sum(f.total) as tot_fht,sum(f.total_ttc) as tot_fttc, p.rowid, p.ref, s.nom, s.rowid as socid, p.total_ht, p.total_ttc
2011-11-23 21:25:02 +01:00
FROM " .MAIN_DB_PREFIX. " commande AS p , " .MAIN_DB_PREFIX. " societe AS s
2010-02-03 00:23:20 +01:00
LEFT JOIN " .MAIN_DB_PREFIX. " co_fa AS co_fa ON co_fa . fk_commande = p . rowid
LEFT JOIN " .MAIN_DB_PREFIX. " facture AS f ON co_fa . fk_facture = f . rowid
WHERE p . fk_soc = s . rowid
AND p . fk_statut >= 1
AND p . facture = 0 " ;
if ( $socid )
{
$sql .= " AND f.fk_soc = " . $socid ;
}
$sql .= " GROUP BY p.rowid " ;
2010-08-09 17:42:57 +02:00
$resql = $db -> query ( $sql );
if ( $resql )
2010-02-03 00:23:20 +01:00
{
2010-08-09 17:42:57 +02:00
$num = $db -> num_rows ( $resql );
2010-02-03 00:23:20 +01:00
$i = 0 ;
if ( $num )
{
$total_pr = 0 ;
while ( $i < $num )
{
2010-08-09 17:42:57 +02:00
$obj = $db -> fetch_object ( $resql );
2010-02-03 00:23:20 +01:00
$total_pr += $obj -> total_ttc - $obj -> tot_fttc ;
$i ++ ;
}
2017-08-31 15:44:36 +02:00
2018-05-15 17:51:19 +02:00
print " <tr class= " oddeven " ><td align= \" right \" colspan= \" 5 \" ><i>Signe et non facture:</i></td><td align= \" right \" ><i> " . price ( $total_pr ) . " </i></td><td colspan= \" 5 \" ><-- bug ici, ca devrait exclure le deja facture</td></tr> " ;
2010-02-03 00:23:20 +01:00
}
2010-08-09 17:42:57 +02:00
$db -> free ( $resql );
2010-02-03 00:23:20 +01:00
}
else
{
dol_print_error ( $db );
}
2018-05-15 17:51:19 +02:00
print " <tr class= " oddeven " ><td align= \" right \" colspan= \" 5 \" ><i>Total CA previsionnel : </i></td><td align= \" right \" ><i> " . price ( $total_CA ) . " </i></td><td colspan= \" 3 \" ><-- bug ici car bug sur les 2 precedents</td></tr> " ;
2010-02-03 00:23:20 +01:00
}
print " </table> " ;
2005-04-16 01:47:41 +02:00
2010-02-03 00:23:20 +01:00
*/
2005-04-16 01:47:41 +02:00
2011-08-27 16:24:16 +02:00
llxFooter ();
2003-06-29 11:01:29 +02:00
2012-01-08 23:43:32 +01:00
$db -> close ();