2004-10-19 22:35:36 +02:00
< ? php
2018-09-09 09:36:12 +02:00
/* Copyright ( C ) 2003 Rodolphe Quiedeville < rodolphe @ quiedeville . org >
* Copyright ( C ) 2004 - 2012 Laurent Destailleur < eldy @ users . sourceforge . net >
2018-10-27 14:43:12 +02:00
* Copyright ( C ) 2005 - 2012 Regis Houssin < regis . houssin @ inodbox . com >
2018-09-09 09:36:12 +02:00
* Copyright ( C ) 2014 - 2016 Ferran Marcet < fmarcet @ 2 byte . es >
* Copyright ( C ) 2014 Juanjo Menent < jmenent @ 2 byte . es >
* Copyright ( C ) 2014 Florian Henry < florian . henry @ open - concept . pro >
* Copyright ( C ) 2018 Frédéric France < frederic . france @ netlogic . fr >
2020-05-06 08:38:36 +02:00
* Copyright ( C ) 2020 Maxime DEMAREST < maxime @ indelog . fr >
2002-06-19 00:23:12 +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
2002-06-19 00:23:12 +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
2019-09-23 21:55:30 +02:00
* along with this program . If not , see < https :// www . gnu . org / licenses />.
2002-06-19 00:23:12 +02:00
*/
2005-01-31 19:47:14 +01:00
/**
2017-08-31 18:29:57 +02:00
* \file htdocs / compta / resultat / index . php
* \ingroup compta , accountancy
* \brief Page reporting result
2010-01-13 19:51:19 +01:00
*/
2005-01-31 19:47:14 +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' ;
2008-01-10 18:12:07 +01:00
2018-05-27 09:27:09 +02:00
// Load translation files required by the page
2019-12-18 15:20:36 +01:00
$langs -> loadLangs ( array ( 'compta' , 'bills' , 'donation' , 'salaries' ));
2003-11-08 20:05:47 +01:00
2019-12-18 15:20:36 +01:00
$date_startmonth = GETPOST ( 'date_startmonth' , 'int' );
$date_startday = GETPOST ( 'date_startday' , 'int' );
$date_startyear = GETPOST ( 'date_startyear' , 'int' );
$date_endmonth = GETPOST ( 'date_endmonth' , 'int' );
$date_endday = GETPOST ( 'date_endday' , 'int' );
$date_endyear = GETPOST ( 'date_endyear' , 'int' );
2003-11-08 20:05:47 +01:00
2019-12-18 15:20:36 +01:00
$nbofyear = 4 ;
2017-08-31 15:44:36 +02:00
// Date range
2019-12-18 15:20:36 +01:00
$year = GETPOST ( 'year' , 'int' );
2021-02-23 21:09:01 +01:00
if ( empty ( $year )) {
2022-08-24 22:17:32 +02:00
$year_current = dol_print_date ( dol_now (), " %Y " );
$month_current = dol_print_date ( dol_now (), " %m " );
2017-08-31 15:44:36 +02:00
$year_start = $year_current - ( $nbofyear - 1 );
} else {
$year_current = $year ;
2022-08-24 22:17:32 +02:00
$month_current = dol_print_date ( dol_now (), " %m " );
2017-08-31 15:44:36 +02:00
$year_start = $year - ( $nbofyear - 1 );
2005-01-31 19:47:14 +01:00
}
2019-12-18 15:20:36 +01: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 );
2017-08-31 15:44:36 +02:00
// We define date_start and date_end
2021-02-23 21:09:01 +01:00
if ( empty ( $date_start ) || empty ( $date_end )) { // We define date_start and date_end
2021-12-18 21:13:22 +01:00
$q = GETPOST ( " q " ) ? GETPOST ( " q " , 'int' ) : 0 ;
2021-02-23 21:09:01 +01:00
if ( $q == 0 ) {
2017-08-31 15:44:36 +02:00
// We define date_start and date_end
2019-12-18 15:20:36 +01:00
$year_end = $year_start + ( $nbofyear - 1 );
2021-12-18 21:13:22 +01:00
$month_start = GETPOST ( " month " ) ? GETPOST ( " month " , 'int' ) : ( $conf -> global -> SOCIETE_FISCAL_MONTH_START ? ( $conf -> global -> SOCIETE_FISCAL_MONTH_START ) : 1 );
2021-02-23 21:09:01 +01:00
if ( ! GETPOST ( 'month' )) {
if ( ! GETPOST ( " year " ) && $month_start > $month_current ) {
2017-08-31 15:44:36 +02:00
$year_start -- ;
$year_end -- ;
}
2019-12-18 15:20:36 +01:00
$month_end = $month_start - 1 ;
2021-02-23 21:09:01 +01:00
if ( $month_end < 1 ) {
$month_end = 12 ;
} else {
$year_end ++ ;
}
} else {
$month_end = $month_start ;
}
2021-03-01 20:37:16 +01:00
$date_start = dol_get_first_day ( $year_start , $month_start , false );
$date_end = dol_get_last_day ( $year_end , $month_end , false );
2017-08-31 15:44:36 +02:00
}
2021-02-23 21:09:01 +01:00
if ( $q == 1 ) {
2021-03-01 20:37:16 +01:00
$date_start = dol_get_first_day ( $year_start , 1 , false );
$date_end = dol_get_last_day ( $year_start , 3 , false );
2021-02-23 21:09:01 +01:00
}
if ( $q == 2 ) {
2021-03-01 20:37:16 +01:00
$date_start = dol_get_first_day ( $year_start , 4 , false );
$date_end = dol_get_last_day ( $year_start , 6 , false );
2021-02-23 21:09:01 +01:00
}
if ( $q == 3 ) {
2021-03-01 20:37:16 +01:00
$date_start = dol_get_first_day ( $year_start , 7 , false );
$date_end = dol_get_last_day ( $year_start , 9 , false );
2021-02-23 21:09:01 +01:00
}
if ( $q == 4 ) {
2021-03-01 20:37:16 +01:00
$date_start = dol_get_first_day ( $year_start , 10 , false );
$date_end = dol_get_last_day ( $year_start , 12 , false );
2021-02-23 21:09:01 +01:00
}
2005-01-31 19:47:14 +01:00
}
2018-03-27 13:37:40 +02:00
// $date_start and $date_end are defined. We force $year_start and $nbofyear
2019-12-18 15:20:36 +01:00
$tmps = dol_getdate ( $date_start );
2018-03-27 13:37:40 +02:00
$year_start = $tmps [ 'year' ];
2019-12-18 15:20:36 +01:00
$tmpe = dol_getdate ( $date_end );
2017-08-31 18:29:57 +02:00
$year_end = $tmpe [ 'year' ];
2018-04-29 23:26:44 +02:00
$nbofyear = ( $year_end - $year_start ) + 1 ;
2018-03-27 13:37:40 +02:00
//var_dump("year_start=".$year_start." year_end=".$year_end." nbofyear=".$nbofyear." date_start=".dol_print_date($date_start, 'dayhour')." date_end=".dol_print_date($date_end, 'dayhour'));
2021-03-18 14:34:44 +01:00
// Define modecompta ('CREANCES-DETTES' or 'RECETTES-DEPENSES' or 'BOOKKEEPING')
$modecompta = $conf -> global -> ACCOUNTING_MODE ;
2022-08-29 11:26:26 +02:00
if ( isModEnabled ( 'accounting' )) {
2021-03-18 14:34:44 +01:00
$modecompta = 'BOOKKEEPING' ;
}
if ( GETPOST ( " modecompta " , 'alpha' )) {
$modecompta = GETPOST ( " modecompta " , 'alpha' );
}
2017-08-31 18:29:57 +02:00
2010-02-03 00:23:20 +01:00
// Security check
2019-01-27 11:55:16 +01:00
$socid = GETPOST ( 'socid' , 'int' );
2021-02-23 21:09:01 +01:00
if ( $user -> socid > 0 ) {
$socid = $user -> socid ;
}
2022-08-29 11:26:26 +02:00
if ( isModEnabled ( 'comptabilite' )) {
2021-02-23 21:09:01 +01:00
$result = restrictedArea ( $user , 'compta' , '' , '' , 'resultat' );
}
2022-08-29 11:26:26 +02:00
if ( isModEnabled ( 'accounting' )) {
2021-02-23 21:09:01 +01:00
$result = restrictedArea ( $user , 'accounting' , '' , '' , 'comptarapport' );
}
2013-01-02 18:43:59 +01:00
2010-02-03 00:23:20 +01:00
/*
* View
*/
2005-05-03 02:41:51 +02:00
llxHeader ();
2019-12-18 15:20:36 +01:00
$form = new Form ( $db );
2003-10-28 17:49:34 +01:00
2019-12-18 15:20:36 +01:00
$exportlink = '' ;
2012-08-03 20:09:37 +02:00
2021-12-18 18:11:28 +01:00
$encaiss = array ();
$encaiss_ttc = array ();
$decaiss = array ();
$decaiss_ttc = array ();
2009-05-08 17:58:01 +02:00
// Affiche en-tete du rapport
2021-02-23 21:09:01 +01:00
if ( $modecompta == 'CREANCES-DETTES' ) {
2017-09-12 13:05:34 +02:00
$name = $langs -> trans ( " ReportInOut " ) . ', ' . $langs -> trans ( " ByYear " );
2019-12-18 15:20:36 +01:00
$calcmode = $langs -> trans ( " CalcModeDebt " );
2020-12-09 17:02:26 +01:00
$calcmode .= '<br>(' . $langs -> trans ( " SeeReportInInputOutputMode " , '{s1}' , '{s2}' ) . ')' ;
$calcmode = str_replace ( array ( '{s1}' , '{s2}' ), array ( '<a href="' . $_SERVER [ " PHP_SELF " ] . '?year_start=' . $year_start . '&modecompta=RECETTES-DEPENSES">' , '</a>' ), $calcmode );
2022-08-29 11:26:26 +02:00
if ( isModEnabled ( 'accounting' )) {
2020-12-09 17:02:26 +01:00
$calcmode .= '<br>(' . $langs -> trans ( " SeeReportInBookkeepingMode " , '{s1}' , '{s2}' ) . ')' ;
$calcmode = str_replace ( array ( '{s1}' , '{s2}' ), array ( '<a href="' . $_SERVER [ " PHP_SELF " ] . '?year_start=' . $year_start . '&modecompta=BOOKKEEPING">' , '</a>' ), $calcmode );
}
2019-12-18 15:20:36 +01:00
$period = $form -> selectDate ( $date_start , 'date_start' , 0 , 0 , 0 , '' , 1 , 0 ) . ' - ' . $form -> selectDate ( $date_end , 'date_end' , 0 , 0 , 0 , '' , 1 , 0 );
$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> " : " " );
2021-12-18 18:11:28 +01:00
$description = $langs -> trans ( " RulesAmountWithTaxExcluded " );
2019-12-18 15:20:36 +01:00
$description .= '<br>' . $langs -> trans ( " RulesResultDue " );
2021-02-23 21:09:01 +01:00
if ( ! empty ( $conf -> global -> FACTURE_DEPOSITS_ARE_JUST_PAYMENTS )) {
$description .= " <br> " . $langs -> trans ( " DepositsAreNotIncluded " );
} else {
$description .= " <br> " . $langs -> trans ( " DepositsAreIncluded " );
}
2022-10-12 12:14:04 +02:00
if ( ! empty ( $conf -> global -> FACTURE_SUPPLIER_DEPOSITS_ARE_JUST_PAYMENTS )) {
$description .= $langs -> trans ( " SupplierDepositsAreNotIncluded " );
}
2019-12-18 15:20:36 +01:00
$builddate = dol_now ();
2011-01-10 23:36:34 +01:00
//$exportlink=$langs->trans("NotYetAvailable");
2020-05-21 15:05:19 +02:00
} elseif ( $modecompta == " RECETTES-DEPENSES " ) {
2017-09-12 13:05:34 +02:00
$name = $langs -> trans ( " ReportInOut " ) . ', ' . $langs -> trans ( " ByYear " );
2019-12-18 15:20:36 +01:00
$calcmode = $langs -> trans ( " CalcModeEngagement " );
2020-12-09 17:02:26 +01:00
$calcmode .= '<br>(' . $langs -> trans ( " SeeReportInDueDebtMode " , '{s1}' , '{s2}' ) . ')' ;
$calcmode = str_replace ( array ( '{s1}' , '{s2}' ), array ( '<a href="' . $_SERVER [ " PHP_SELF " ] . '?year_start=' . $year_start . '&modecompta=CREANCES-DETTES">' , '</a>' ), $calcmode );
2022-08-29 11:26:26 +02:00
if ( isModEnabled ( 'accounting' )) {
2020-12-09 17:02:26 +01:00
$calcmode .= '<br>(' . $langs -> trans ( " SeeReportInBookkeepingMode " , '{s1}' , '{s2}' ) . ')' ;
$calcmode = str_replace ( array ( '{s1}' , '{s2}' ), array ( '<a href="' . $_SERVER [ " PHP_SELF " ] . '?year_start=' . $year_start . '&modecompta=BOOKKEEPING">' , '</a>' ), $calcmode );
}
2019-12-18 15:20:36 +01:00
$period = $form -> selectDate ( $date_start , 'date_start' , 0 , 0 , 0 , '' , 1 , 0 ) . ' - ' . $form -> selectDate ( $date_end , 'date_end' , 0 , 0 , 0 , '' , 1 , 0 );
$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> " : " " );
$description = $langs -> trans ( " RulesAmountWithTaxIncluded " );
$description .= '<br>' . $langs -> trans ( " RulesResultInOut " );
$builddate = dol_now ();
2011-01-10 23:36:34 +01:00
//$exportlink=$langs->trans("NotYetAvailable");
2021-02-23 21:09:01 +01:00
} elseif ( $modecompta == " BOOKKEEPING " ) {
2017-09-12 13:05:34 +02:00
$name = $langs -> trans ( " ReportInOut " ) . ', ' . $langs -> trans ( " ByYear " );
2019-12-18 15:20:36 +01:00
$calcmode = $langs -> trans ( " CalcModeBookkeeping " );
2020-12-09 17:02:26 +01:00
$calcmode .= '<br>(' . $langs -> trans ( " SeeReportInInputOutputMode " , '{s1}' , '{s2}' ) . ')' ;
$calcmode = str_replace ( array ( '{s1}' , '{s2}' ), array ( '<a href="' . $_SERVER [ " PHP_SELF " ] . '?year_start=' . $year_start . '&modecompta=RECETTES-DEPENSES">' , '</a>' ), $calcmode );
$calcmode .= '<br>(' . $langs -> trans ( " SeeReportInDueDebtMode " , '{s1}' , '{s2}' ) . ')' ;
$calcmode = str_replace ( array ( '{s1}' , '{s2}' ), array ( '<a href="' . $_SERVER [ " PHP_SELF " ] . '?year_start=' . $year_start . '&modecompta=CREANCES-DETTES">' , '</a>' ), $calcmode );
2019-12-18 15:20:36 +01:00
$period = $form -> selectDate ( $date_start , 'date_start' , 0 , 0 , 0 , '' , 1 , 0 ) . ' - ' . $form -> selectDate ( $date_end , 'date_end' , 0 , 0 , 0 , '' , 1 , 0 );
$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> " : " " );
$description = $langs -> trans ( " RulesAmountOnInOutBookkeepingRecord " );
$description .= ' (' . $langs -> trans ( " SeePageForSetup " , DOL_URL_ROOT . '/accountancy/admin/account.php?mainmenu=accountancy&leftmenu=accountancy_admin' , $langs -> transnoentitiesnoconv ( " Accountancy " ) . ' / ' . $langs -> transnoentitiesnoconv ( " Setup " ) . ' / ' . $langs -> trans ( " Chartofaccounts " )) . ')' ;
$builddate = dol_now ();
2011-01-10 23:36:34 +01:00
//$exportlink=$langs->trans("NotYetAvailable");
2005-01-17 20:50:34 +01:00
}
2015-05-13 17:53:25 +02:00
2019-12-18 15:20:36 +01:00
$hselected = 'report' ;
2015-05-13 17:53:25 +02:00
2019-01-27 11:55:16 +01:00
report_header ( $name , '' , $period , $periodlink , $description , $builddate , $exportlink , array ( 'modecompta' => $modecompta ), $calcmode );
2005-05-03 02:41:51 +02:00
2022-08-29 11:26:26 +02:00
if ( isModEnabled ( 'accounting' ) && $modecompta != 'BOOKKEEPING' ) {
2020-10-31 14:32:18 +01:00
print info_admin ( $langs -> trans ( " WarningReportNotReliable " ), 0 , 0 , 1 );
2016-10-10 21:22:28 +02:00
}
2002-06-20 15:23:17 +02:00
2005-01-17 20:50:34 +01:00
/*
* Factures clients
*/
2017-08-31 15:44:36 +02:00
2007-11-11 19:05:08 +01:00
$subtotal_ht = 0 ;
$subtotal_ttc = 0 ;
2022-06-11 09:46:28 +02:00
if ( isModEnabled ( 'facture' ) && ( $modecompta == 'CREANCES-DETTES' || $modecompta == " RECETTES-DEPENSES " )) {
2021-02-23 21:09:01 +01:00
if ( $modecompta == 'CREANCES-DETTES' ) {
2021-03-01 04:07:31 +01:00
$sql = " SELECT sum(f.total_ht) as amount_ht, sum(f.total_ttc) as amount_ttc, date_format(f.datef,'%Y-%m') as dm " ;
2019-12-18 15:20:36 +01:00
$sql .= " FROM " . MAIN_DB_PREFIX . " societe as s " ;
$sql .= " , " . MAIN_DB_PREFIX . " facture as f " ;
$sql .= " WHERE f.fk_soc = s.rowid " ;
$sql .= " AND f.fk_statut IN (1,2) " ;
2021-02-23 21:09:01 +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) " ;
}
if ( ! empty ( $date_start ) && ! empty ( $date_end )) {
2020-10-31 14:32:18 +01:00
$sql .= " AND f.datef >= ' " . $db -> idate ( $date_start ) . " ' AND f.datef <= ' " . $db -> idate ( $date_end ) . " ' " ;
2021-02-23 21:09:01 +01:00
}
} elseif ( $modecompta == " RECETTES-DEPENSES " ) {
2017-08-31 18:29:57 +02: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 )
*/
2019-12-18 15:20:36 +01:00
$sql = " SELECT sum(pf.amount) as amount_ttc, date_format(p.datep,'%Y-%m') as dm " ;
$sql .= " FROM " . MAIN_DB_PREFIX . " facture as f " ;
$sql .= " , " . MAIN_DB_PREFIX . " paiement_facture as pf " ;
$sql .= " , " . MAIN_DB_PREFIX . " paiement as p " ;
$sql .= " WHERE p.rowid = pf.fk_paiement " ;
$sql .= " AND pf.fk_facture = f.rowid " ;
2021-02-23 21:09:01 +01:00
if ( ! empty ( $date_start ) && ! empty ( $date_end )) {
2020-10-31 14:32:18 +01:00
$sql .= " AND p.datep >= ' " . $db -> idate ( $date_start ) . " ' AND p.datep <= ' " . $db -> idate ( $date_end ) . " ' " ;
2021-02-23 21:09:01 +01:00
}
2010-01-13 19:51:19 +01:00
}
2019-12-18 15:20:36 +01:00
$sql .= " AND f.entity IN ( " . getEntity ( 'invoice' ) . " ) " ;
2021-02-23 21:09:01 +01:00
if ( $socid ) {
2021-12-18 18:11:28 +01:00
$sql .= " AND f.fk_soc = " . (( int ) $socid );
2021-02-23 21:09:01 +01:00
}
2019-12-18 15:20:36 +01:00
$sql .= " GROUP BY dm " ;
$sql .= " ORDER BY dm " ;
2010-01-13 19:51:19 +01:00
2017-08-31 18:29:57 +02:00
//print $sql;
dol_syslog ( " get customers invoices " , LOG_DEBUG );
2019-12-18 15:20:36 +01:00
$result = $db -> query ( $sql );
2021-02-23 21:09:01 +01:00
if ( $result ) {
2010-01-13 19:51:19 +01:00
$num = $db -> num_rows ( $result );
$i = 0 ;
2021-02-23 21:09:01 +01:00
while ( $i < $num ) {
2010-01-13 19:51:19 +01:00
$row = $db -> fetch_object ( $result );
2019-12-18 15:20:36 +01:00
$encaiss [ $row -> dm ] = ( isset ( $row -> amount_ht ) ? $row -> amount_ht : 0 );
2017-08-31 18:29:57 +02:00
$encaiss_ttc [ $row -> dm ] = $row -> amount_ttc ;
2010-01-13 19:51:19 +01:00
$i ++ ;
}
2017-08-31 18:29:57 +02:00
$db -> free ( $result );
2020-05-21 15:05:19 +02:00
} else {
2010-01-13 19:51:19 +01:00
dol_print_error ( $db );
}
2021-02-23 21:09:01 +01:00
} elseif ( $modecompta == " BOOKKEEPING " ) {
2017-08-31 18:29:57 +02:00
// Nothing from this table
2004-03-04 22:26:03 +01:00
}
2002-06-20 15:23:17 +02:00
2022-06-11 09:46:28 +02:00
if ( isModEnabled ( 'facture' ) && ( $modecompta == 'CREANCES-DETTES' || $modecompta == " RECETTES-DEPENSES " )) {
2017-08-31 18:29:57 +02:00
// On ajoute les paiements clients anciennes version, non lies par paiement_facture
2021-02-23 21:09:01 +01:00
if ( $modecompta != 'CREANCES-DETTES' ) {
2017-08-31 18:29:57 +02:00
$sql = " SELECT sum(p.amount) as amount_ttc, date_format(p.datep,'%Y-%m') as dm " ;
2019-12-18 15:20:36 +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 " ;
$sql .= " AND ba.entity IN ( " . getEntity ( 'bank_account' ) . " ) " ;
2021-02-23 21:09:01 +01:00
if ( ! empty ( $date_start ) && ! empty ( $date_end )) {
2020-10-31 14:32:18 +01:00
$sql .= " AND p.datep >= ' " . $db -> idate ( $date_start ) . " ' AND p.datep <= ' " . $db -> idate ( $date_end ) . " ' " ;
2021-02-23 21:09:01 +01:00
}
2019-12-18 15:20:36 +01:00
$sql .= " GROUP BY dm " ;
$sql .= " ORDER BY dm " ;
2017-08-31 18:29:57 +02:00
dol_syslog ( " get old customers payments not linked to invoices " , LOG_DEBUG );
$result = $db -> query ( $sql );
if ( $result ) {
$num = $db -> num_rows ( $result );
$i = 0 ;
2021-02-23 21:09:01 +01:00
while ( $i < $num ) {
2017-08-31 18:29:57 +02:00
$row = $db -> fetch_object ( $result );
2005-07-02 19:16:15 +02:00
2021-02-23 21:09:01 +01:00
if ( ! isset ( $encaiss [ $row -> dm ])) {
$encaiss [ $row -> dm ] = 0 ;
}
2019-12-18 15:20:36 +01:00
$encaiss [ $row -> dm ] += ( isset ( $row -> amount_ht ) ? $row -> amount_ht : 0 );
2012-08-03 20:09:37 +02:00
2021-02-23 21:09:01 +01:00
if ( ! isset ( $encaiss_ttc [ $row -> dm ])) {
$encaiss_ttc [ $row -> dm ] = 0 ;
}
2017-08-31 18:29:57 +02:00
$encaiss_ttc [ $row -> dm ] += $row -> amount_ttc ;
2007-11-11 19:05:08 +01:00
2017-08-31 18:29:57 +02:00
$i ++ ;
}
2020-05-21 15:05:19 +02:00
} else {
2017-08-31 18:29:57 +02:00
dol_print_error ( $db );
}
2021-02-23 21:09:01 +01:00
} elseif ( $modecompta == " RECETTES-DEPENSES " ) {
2017-08-31 18:29:57 +02:00
// Nothing from this table
2010-01-13 19:51:19 +01:00
}
2021-02-23 21:09:01 +01:00
} elseif ( $modecompta == " BOOKKEEPING " ) {
2017-08-31 18:29:57 +02:00
// Nothing from this table
2002-06-19 11:20:41 +02:00
}
2010-02-03 00:23:20 +01:00
2010-01-13 19:51:19 +01:00
2005-05-11 03:23:52 +02:00
/*
2017-08-31 18:29:57 +02:00
* Frais , factures fournisseurs .
2005-05-11 03:23:52 +02:00
*/
2007-11-11 19:05:08 +01:00
$subtotal_ht = 0 ;
$subtotal_ttc = 0 ;
2017-08-31 18:29:57 +02:00
2022-06-11 09:46:28 +02:00
if ( isModEnabled ( 'facture' ) && ( $modecompta == 'CREANCES-DETTES' || $modecompta == " RECETTES-DEPENSES " )) {
2021-02-23 21:09:01 +01:00
if ( $modecompta == 'CREANCES-DETTES' ) {
2019-12-18 15:20:36 +01:00
$sql = " SELECT sum(f.total_ht) as amount_ht, sum(f.total_ttc) as amount_ttc, date_format(f.datef,'%Y-%m') as dm " ;
$sql .= " FROM " . MAIN_DB_PREFIX . " facture_fourn as f " ;
$sql .= " WHERE f.fk_statut IN (1,2) " ;
2022-10-12 12:14:04 +02:00
if ( ! empty ( $conf -> global -> FACTURE_SUPPLIER_DEPOSITS_ARE_JUST_PAYMENTS )) {
2021-02-23 21:09:01 +01:00
$sql .= " AND f.type IN (0,1,2) " ;
} else {
$sql .= " AND f.type IN (0,1,2,3) " ;
}
if ( ! empty ( $date_start ) && ! empty ( $date_end )) {
2020-10-31 14:32:18 +01:00
$sql .= " AND f.datef >= ' " . $db -> idate ( $date_start ) . " ' AND f.datef <= ' " . $db -> idate ( $date_end ) . " ' " ;
2021-02-23 21:09:01 +01:00
}
} elseif ( $modecompta == " RECETTES-DEPENSES " ) {
2017-08-31 18:29:57 +02:00
$sql = " SELECT sum(pf.amount) as amount_ttc, date_format(p.datep,'%Y-%m') as dm " ;
2019-12-18 15:20:36 +01:00
$sql .= " FROM " . MAIN_DB_PREFIX . " paiementfourn as p " ;
$sql .= " , " . MAIN_DB_PREFIX . " facture_fourn as f " ;
$sql .= " , " . MAIN_DB_PREFIX . " paiementfourn_facturefourn as pf " ;
$sql .= " WHERE f.rowid = pf.fk_facturefourn " ;
$sql .= " AND p.rowid = pf.fk_paiementfourn " ;
2021-02-23 21:09:01 +01:00
if ( ! empty ( $date_start ) && ! empty ( $date_end )) {
2020-10-31 14:32:18 +01:00
$sql .= " AND p.datep >= ' " . $db -> idate ( $date_start ) . " ' AND p.datep <= ' " . $db -> idate ( $date_end ) . " ' " ;
2021-02-23 21:09:01 +01:00
}
2017-08-31 18:29:57 +02:00
}
2021-12-18 18:11:28 +01:00
$sql .= " AND f.entity IN ( " . getEntity ( 'supplier_invoice' ) . " ) " ;
2017-08-31 18:29:57 +02:00
2021-02-23 21:09:01 +01:00
if ( $socid ) {
2021-03-22 13:31:06 +01:00
$sql .= " AND f.fk_soc = " . (( int ) $socid );
2021-02-23 21:09:01 +01:00
}
2019-12-18 15:20:36 +01:00
$sql .= " GROUP BY dm " ;
2010-01-13 19:51:19 +01:00
2017-08-31 18:29:57 +02:00
dol_syslog ( " get suppliers invoices " , LOG_DEBUG );
2019-12-18 15:20:36 +01:00
$result = $db -> query ( $sql );
2021-02-23 21:09:01 +01:00
if ( $result ) {
2010-01-13 19:51:19 +01:00
$num = $db -> num_rows ( $result );
$i = 0 ;
2021-02-23 21:09:01 +01:00
while ( $i < $num ) {
2017-08-31 18:29:57 +02:00
$row = $db -> fetch_object ( $result );
2010-01-13 19:51:19 +01:00
2021-02-23 21:09:01 +01:00
if ( ! isset ( $decaiss [ $row -> dm ])) {
$decaiss [ $row -> dm ] = 0 ;
}
2019-12-18 15:20:36 +01:00
$decaiss [ $row -> dm ] = ( isset ( $row -> amount_ht ) ? $row -> amount_ht : 0 );
2012-08-03 20:09:37 +02:00
2021-02-23 21:09:01 +01:00
if ( ! isset ( $decaiss_ttc [ $row -> dm ])) {
$decaiss_ttc [ $row -> dm ] = 0 ;
}
2017-08-31 18:29:57 +02:00
$decaiss_ttc [ $row -> dm ] = $row -> amount_ttc ;
2010-01-13 19:51:19 +01:00
2017-08-31 18:29:57 +02:00
$i ++ ;
2010-01-13 19:51:19 +01:00
}
2017-08-31 18:29:57 +02:00
$db -> free ( $result );
2020-05-21 15:05:19 +02:00
} else {
2010-01-13 19:51:19 +01:00
dol_print_error ( $db );
}
2021-02-23 21:09:01 +01:00
} elseif ( $modecompta == " BOOKKEEPING " ) {
2017-08-31 18:29:57 +02:00
// Nothing from this table
}
2010-01-13 19:51:19 +01:00
2012-08-03 20:09:37 +02:00
2017-08-31 18:29:57 +02:00
/*
* TVA
*/
2010-01-13 19:51:19 +01:00
2017-08-31 18:29:57 +02:00
$subtotal_ht = 0 ;
$subtotal_ttc = 0 ;
2022-08-29 12:04:39 +02:00
if ( isModEnabled ( 'tax' ) && ( $modecompta == 'CREANCES-DETTES' || $modecompta == " RECETTES-DEPENSES " )) {
2021-02-23 21:09:01 +01:00
if ( $modecompta == 'CREANCES-DETTES' ) {
2020-04-08 11:39:22 +02:00
// TVA collected to pay
2021-03-01 04:07:31 +01:00
$sql = " SELECT sum(f.total_tva) as amount, date_format(f.datef,'%Y-%m') as dm " ;
2019-12-18 15:20:36 +01:00
$sql .= " FROM " . MAIN_DB_PREFIX . " facture as f " ;
$sql .= " WHERE f.fk_statut IN (1,2) " ;
2021-02-23 21:09:01 +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) " ;
}
2019-12-18 15:20:36 +01:00
$sql .= " AND f.entity IN ( " . getEntity ( 'invoice' ) . " ) " ;
2021-02-23 21:09:01 +01:00
if ( ! empty ( $date_start ) && ! empty ( $date_end )) {
2020-10-31 14:32:18 +01:00
$sql .= " AND f.datef >= ' " . $db -> idate ( $date_start ) . " ' AND f.datef <= ' " . $db -> idate ( $date_end ) . " ' " ;
2021-02-23 21:09:01 +01:00
}
2019-12-18 15:20:36 +01:00
$sql .= " GROUP BY dm " ;
2017-08-31 18:29:57 +02:00
dol_syslog ( " get vat to pay " , LOG_DEBUG );
2019-12-18 15:20:36 +01:00
$result = $db -> query ( $sql );
2017-08-31 18:29:57 +02:00
if ( $result ) {
$num = $db -> num_rows ( $result );
$i = 0 ;
if ( $num ) {
while ( $i < $num ) {
$obj = $db -> fetch_object ( $result );
2021-12-18 19:23:03 +01:00
/* if ( ! isset ( $decaiss [ $obj -> dm ])) {
2021-02-23 21:09:01 +01:00
$decaiss [ $obj -> dm ] = 0 ;
}
2021-12-18 19:23:03 +01:00
$decaiss [ $obj -> dm ] += $obj -> amount ; */
2017-08-31 18:29:57 +02:00
2021-02-23 21:09:01 +01:00
if ( ! isset ( $decaiss_ttc [ $obj -> dm ])) {
$decaiss_ttc [ $obj -> dm ] = 0 ;
}
2017-08-31 18:29:57 +02:00
$decaiss_ttc [ $obj -> dm ] += $obj -> amount ;
$i ++ ;
}
2010-01-13 19:51:19 +01:00
}
2017-08-31 18:29:57 +02:00
} else {
dol_print_error ( $db );
}
2020-04-08 11:39:22 +02:00
// TVA paid to get
2017-08-31 18:29:57 +02:00
$sql = " SELECT sum(f.total_tva) as amount, date_format(f.datef,'%Y-%m') as dm " ;
2019-12-18 15:20:36 +01:00
$sql .= " FROM " . MAIN_DB_PREFIX . " facture_fourn as f " ;
$sql .= " WHERE f.fk_statut IN (1,2) " ;
2022-10-12 12:14:04 +02:00
if ( ! empty ( $conf -> global -> FACTURE_SUPPLIER_DEPOSITS_ARE_JUST_PAYMENTS )) {
2021-02-23 21:09:01 +01:00
$sql .= " AND f.type IN (0,1,2) " ;
} else {
$sql .= " AND f.type IN (0,1,2,3) " ;
}
2021-12-18 18:11:28 +01:00
$sql .= " AND f.entity IN ( " . getEntity ( 'supplier_invoice' ) . " ) " ;
2021-02-23 21:09:01 +01:00
if ( ! empty ( $date_start ) && ! empty ( $date_end )) {
2020-10-31 14:32:18 +01:00
$sql .= " AND f.datef >= ' " . $db -> idate ( $date_start ) . " ' AND f.datef <= ' " . $db -> idate ( $date_end ) . " ' " ;
2021-02-23 21:09:01 +01:00
}
2019-12-18 15:20:36 +01:00
$sql .= " GROUP BY dm " ;
2017-08-31 18:29:57 +02:00
dol_syslog ( " get vat to receive back " , LOG_DEBUG );
2019-12-18 15:20:36 +01:00
$result = $db -> query ( $sql );
2017-08-31 18:29:57 +02:00
if ( $result ) {
$num = $db -> num_rows ( $result );
$i = 0 ;
if ( $num ) {
while ( $i < $num ) {
$obj = $db -> fetch_object ( $result );
2021-12-18 19:23:03 +01:00
/* if ( ! isset ( $encaiss [ $obj -> dm ])) {
2021-02-23 21:09:01 +01:00
$encaiss [ $obj -> dm ] = 0 ;
}
2021-12-18 19:23:03 +01:00
$encaiss [ $obj -> dm ] += $obj -> amount ; */
2017-08-31 18:29:57 +02:00
2021-02-23 21:09:01 +01:00
if ( ! isset ( $encaiss_ttc [ $obj -> dm ])) {
$encaiss_ttc [ $obj -> dm ] = 0 ;
}
2017-08-31 18:29:57 +02:00
$encaiss_ttc [ $obj -> dm ] += $obj -> amount ;
$i ++ ;
}
}
} else {
dol_print_error ( $db );
}
2021-02-23 21:09:01 +01:00
} elseif ( $modecompta == " RECETTES-DEPENSES " ) {
2020-04-08 11:39:22 +02:00
// TVA really already paid
2017-08-31 18:29:57 +02:00
$sql = " SELECT sum(t.amount) as amount, date_format(t.datev,'%Y-%m') as dm " ;
2019-12-18 15:20:36 +01:00
$sql .= " FROM " . MAIN_DB_PREFIX . " tva as t " ;
$sql .= " WHERE amount > 0 " ;
2021-12-18 18:11:28 +01:00
$sql .= " AND t.entity IN ( " . getEntity ( 'vat' ) . " ) " ;
2021-02-23 21:09:01 +01:00
if ( ! empty ( $date_start ) && ! empty ( $date_end )) {
2020-10-31 14:32:18 +01:00
$sql .= " AND t.datev >= ' " . $db -> idate ( $date_start ) . " ' AND t.datev <= ' " . $db -> idate ( $date_end ) . " ' " ;
2021-02-23 21:09:01 +01:00
}
2019-12-18 15:20:36 +01:00
$sql .= " GROUP BY dm " ;
2017-08-31 18:29:57 +02:00
dol_syslog ( " get vat really paid " , LOG_DEBUG );
2019-12-18 15:20:36 +01:00
$result = $db -> query ( $sql );
2017-08-31 18:29:57 +02:00
if ( $result ) {
$num = $db -> num_rows ( $result );
$i = 0 ;
if ( $num ) {
while ( $i < $num ) {
$obj = $db -> fetch_object ( $result );
2021-12-18 19:23:03 +01:00
/* if ( ! isset ( $decaiss [ $obj -> dm ])) {
2021-02-23 21:09:01 +01:00
$decaiss [ $obj -> dm ] = 0 ;
}
2021-12-18 19:23:03 +01:00
$decaiss [ $obj -> dm ] += $obj -> amount ; */
2017-08-31 18:29:57 +02:00
2021-02-23 21:09:01 +01:00
if ( ! isset ( $decaiss_ttc [ $obj -> dm ])) {
$decaiss_ttc [ $obj -> dm ] = 0 ;
}
2017-08-31 18:29:57 +02:00
$decaiss_ttc [ $obj -> dm ] += $obj -> amount ;
$i ++ ;
}
}
} else {
dol_print_error ( $db );
}
2020-10-23 20:08:35 +02:00
// TVA retrieved
2017-08-31 18:29:57 +02:00
$sql = " SELECT sum(t.amount) as amount, date_format(t.datev,'%Y-%m') as dm " ;
2019-12-18 15:20:36 +01:00
$sql .= " FROM " . MAIN_DB_PREFIX . " tva as t " ;
$sql .= " WHERE amount < 0 " ;
2021-12-18 18:11:28 +01:00
$sql .= " AND t.entity IN ( " . getEntity ( 'vat' ) . " ) " ;
2021-02-23 21:09:01 +01:00
if ( ! empty ( $date_start ) && ! empty ( $date_end )) {
2020-10-31 14:32:18 +01:00
$sql .= " AND t.datev >= ' " . $db -> idate ( $date_start ) . " ' AND t.datev <= ' " . $db -> idate ( $date_end ) . " ' " ;
2021-02-23 21:09:01 +01:00
}
2019-12-18 15:20:36 +01:00
$sql .= " GROUP BY dm " ;
2017-08-31 18:29:57 +02:00
dol_syslog ( " get vat really received back " , LOG_DEBUG );
2019-12-18 15:20:36 +01:00
$result = $db -> query ( $sql );
2017-08-31 18:29:57 +02:00
if ( $result ) {
$num = $db -> num_rows ( $result );
$i = 0 ;
if ( $num ) {
while ( $i < $num ) {
$obj = $db -> fetch_object ( $result );
2021-12-18 19:23:03 +01:00
/* if ( ! isset ( $encaiss [ $obj -> dm ])) {
2021-02-23 21:09:01 +01:00
$encaiss [ $obj -> dm ] = 0 ;
}
2021-12-18 19:23:03 +01:00
$encaiss [ $obj -> dm ] += - $obj -> amount ; */
2017-08-31 18:29:57 +02:00
2021-02-23 21:09:01 +01:00
if ( ! isset ( $encaiss_ttc [ $obj -> dm ])) {
$encaiss_ttc [ $obj -> dm ] = 0 ;
}
2019-10-30 02:19:32 +01:00
$encaiss_ttc [ $obj -> dm ] += - $obj -> amount ;
2017-08-31 18:29:57 +02:00
$i ++ ;
}
}
} else {
dol_print_error ( $db );
2010-01-13 19:51:19 +01:00
}
}
2021-02-23 21:09:01 +01:00
} elseif ( $modecompta == " BOOKKEEPING " ) {
2017-08-31 18:29:57 +02:00
// Nothing from this table
}
2010-01-13 19:51:19 +01:00
2017-08-31 18:29:57 +02:00
/*
2020-07-06 11:22:30 +02:00
* Social contributions
2017-08-31 18:29:57 +02:00
*/
$subtotal_ht = 0 ;
$subtotal_ttc = 0 ;
2022-08-29 12:04:39 +02:00
if ( isModEnabled ( 'tax' ) && ( $modecompta == 'CREANCES-DETTES' || $modecompta == " RECETTES-DEPENSES " )) {
2021-02-23 21:09:01 +01:00
if ( $modecompta == 'CREANCES-DETTES' ) {
2017-08-31 18:29:57 +02:00
$sql = " SELECT c.libelle as nom, date_format(cs.date_ech,'%Y-%m') as dm, sum(cs.amount) as amount " ;
2019-12-18 15:20:36 +01:00
$sql .= " FROM " . MAIN_DB_PREFIX . " c_chargesociales as c " ;
$sql .= " , " . MAIN_DB_PREFIX . " chargesociales as cs " ;
$sql .= " WHERE cs.fk_type = c.id " ;
2021-02-23 21:09:01 +01:00
if ( ! empty ( $date_start ) && ! empty ( $date_end )) {
2020-10-31 14:32:18 +01:00
$sql .= " AND cs.date_ech >= ' " . $db -> idate ( $date_start ) . " ' AND cs.date_ech <= ' " . $db -> idate ( $date_end ) . " ' " ;
2021-02-23 21:09:01 +01:00
}
} elseif ( $modecompta == " RECETTES-DEPENSES " ) {
2017-08-31 18:29:57 +02:00
$sql = " SELECT c.libelle as nom, date_format(p.datep,'%Y-%m') as dm, sum(p.amount) as amount " ;
2019-12-18 15:20:36 +01:00
$sql .= " FROM " . MAIN_DB_PREFIX . " c_chargesociales as c " ;
$sql .= " , " . MAIN_DB_PREFIX . " chargesociales as cs " ;
$sql .= " , " . MAIN_DB_PREFIX . " paiementcharge as p " ;
$sql .= " WHERE p.fk_charge = cs.rowid " ;
$sql .= " AND cs.fk_type = c.id " ;
2021-02-23 21:09:01 +01:00
if ( ! empty ( $date_start ) && ! empty ( $date_end )) {
2020-10-31 14:32:18 +01:00
$sql .= " AND p.datep >= ' " . $db -> idate ( $date_start ) . " ' AND p.datep <= ' " . $db -> idate ( $date_end ) . " ' " ;
2021-02-23 21:09:01 +01:00
}
2017-08-31 18:29:57 +02:00
}
2010-01-13 19:51:19 +01:00
2021-12-18 18:11:28 +01:00
$sql .= " AND cs.entity IN ( " . getEntity ( 'social_contributions' ) . " ) " ;
2019-12-18 15:20:36 +01:00
$sql .= " GROUP BY c.libelle, dm " ;
2017-08-31 18:29:57 +02:00
2020-07-06 11:32:04 +02:00
dol_syslog ( " get social contributions " , LOG_DEBUG );
2019-12-18 15:20:36 +01:00
$result = $db -> query ( $sql );
2010-01-13 19:51:19 +01:00
if ( $result ) {
$num = $db -> num_rows ( $result );
$i = 0 ;
if ( $num ) {
while ( $i < $num ) {
$obj = $db -> fetch_object ( $result );
2021-02-23 21:09:01 +01:00
if ( ! isset ( $decaiss [ $obj -> dm ])) {
$decaiss [ $obj -> dm ] = 0 ;
}
2017-08-31 18:29:57 +02:00
$decaiss [ $obj -> dm ] += $obj -> amount ;
2012-08-03 20:09:37 +02:00
2021-02-23 21:09:01 +01:00
if ( ! isset ( $decaiss_ttc [ $obj -> dm ])) {
$decaiss_ttc [ $obj -> dm ] = 0 ;
}
2017-08-31 18:29:57 +02:00
$decaiss_ttc [ $obj -> dm ] += $obj -> amount ;
2010-01-13 19:51:19 +01:00
$i ++ ;
2007-11-11 19:05:08 +01:00
}
2010-01-13 19:51:19 +01:00
}
} else {
dol_print_error ( $db );
}
2021-02-23 21:09:01 +01:00
} elseif ( $modecompta == " BOOKKEEPING " ) {
2017-08-31 18:29:57 +02:00
// Nothing from this table
2005-04-16 01:50:38 +02:00
}
2010-01-13 19:51:19 +01:00
2005-04-16 01:50:38 +02:00
/*
2017-08-31 18:29:57 +02:00
* Salaries
2005-04-16 01:50:38 +02:00
*/
2010-02-03 00:23:20 +01:00
2022-08-29 12:04:39 +02:00
if ( isModEnabled ( 'salaries' ) && ( $modecompta == 'CREANCES-DETTES' || $modecompta == " RECETTES-DEPENSES " )) {
2021-02-23 21:09:01 +01:00
if ( $modecompta == 'CREANCES-DETTES' ) {
2022-02-25 18:53:21 +01:00
$column = 's.dateep' ; // we use the date of end of period of salary
$sql = " SELECT s.label as nom, date_format( " . $column . " ,'%Y-%m') as dm, sum(s.amount) as amount " ;
$sql .= " FROM " . MAIN_DB_PREFIX . " salary as s " ;
$sql .= " WHERE s.entity IN ( " . getEntity ( 'salary' ) . " ) " ;
if ( ! empty ( $date_start ) && ! empty ( $date_end )) {
$sql .= " AND " . $column . " >= ' " . $db -> idate ( $date_start ) . " ' AND " . $column . " <= ' " . $db -> idate ( $date_end ) . " ' " ;
}
$sql .= " GROUP BY s.label, dm " ;
2021-02-23 21:09:01 +01:00
}
if ( $modecompta == " RECETTES-DEPENSES " ) {
$column = 'p.datep' ;
2022-02-25 18:53:21 +01:00
$sql = " SELECT p.label as nom, date_format( " . $column . " ,'%Y-%m') as dm, sum(p.amount) as amount " ;
$sql .= " FROM " . MAIN_DB_PREFIX . " payment_salary as p " ;
$sql .= " INNER JOIN " . MAIN_DB_PREFIX . " salary as s ON p.fk_salary = s.rowid " ;
$sql .= " WHERE p.entity IN ( " . getEntity ( 'payment_salary' ) . " ) " ;
if ( ! empty ( $date_start ) && ! empty ( $date_end )) {
$sql .= " AND " . $column . " >= ' " . $db -> idate ( $date_start ) . " ' AND " . $column . " <= ' " . $db -> idate ( $date_end ) . " ' " ;
}
$sql .= " GROUP BY p.label, dm " ;
2021-02-23 21:09:01 +01:00
}
2009-05-08 17:58:01 +02:00
2017-08-31 18:29:57 +02:00
$subtotal_ht = 0 ;
$subtotal_ttc = 0 ;
dol_syslog ( " get social salaries payments " );
$result = $db -> query ( $sql );
if ( $result ) {
$num = $db -> num_rows ( $result );
$i = 0 ;
if ( $num ) {
while ( $i < $num ) {
$obj = $db -> fetch_object ( $result );
2007-11-11 19:05:08 +01:00
2021-02-23 21:09:01 +01:00
if ( ! isset ( $decaiss [ $obj -> dm ])) {
2017-08-31 18:29:57 +02:00
$decaiss [ $obj -> dm ] = 0 ;
2021-02-23 21:09:01 +01:00
}
2017-08-31 18:29:57 +02:00
$decaiss [ $obj -> dm ] += $obj -> amount ;
2012-08-03 20:09:37 +02:00
2021-02-23 21:09:01 +01:00
if ( ! isset ( $decaiss_ttc [ $obj -> dm ])) {
2017-08-31 18:29:57 +02:00
$decaiss_ttc [ $obj -> dm ] = 0 ;
2021-02-23 21:09:01 +01:00
}
2017-08-31 18:29:57 +02:00
$decaiss_ttc [ $obj -> dm ] += $obj -> amount ;
2010-01-13 19:51:19 +01:00
2019-12-18 15:20:36 +01:00
$i ++ ;
2017-08-31 18:29:57 +02:00
}
2007-11-11 19:05:08 +01:00
}
2017-08-31 18:29:57 +02:00
} else {
dol_print_error ( $db );
2010-01-13 19:51:19 +01:00
}
2021-02-23 21:09:01 +01:00
} elseif ( $modecompta == " BOOKKEEPING " ) {
2017-08-31 18:29:57 +02:00
// Nothing from this table
}
2005-01-31 19:47:14 +01:00
2016-10-04 13:45:22 +02:00
2014-09-16 21:05:57 +02:00
/*
2017-08-31 18:29:57 +02:00
* Expense reports
2014-09-16 21:05:57 +02:00
*/
2016-10-04 13:45:22 +02:00
2022-08-29 12:04:39 +02:00
if ( ! isModEnabled ( 'expensereport' ) && ( $modecompta == 'CREANCES-DETTES' || $modecompta == " RECETTES-DEPENSES " )) {
2016-01-29 14:05:37 +01:00
$langs -> load ( 'trips' );
2017-08-31 18:29:57 +02:00
2016-01-29 14:05:37 +01:00
if ( $modecompta == 'CREANCES-DETTES' ) {
$sql = " SELECT date_format(date_valid,'%Y-%m') as dm, sum(p.total_ht) as amount_ht,sum(p.total_ttc) as amount_ttc " ;
2019-12-18 15:20:36 +01:00
$sql .= " FROM " . MAIN_DB_PREFIX . " expensereport as p " ;
$sql .= " INNER JOIN " . MAIN_DB_PREFIX . " user as u ON u.rowid=p.fk_user_author " ;
$sql .= " WHERE p.entity IN ( " . getEntity ( 'expensereport' ) . " ) " ;
$sql .= " AND p.fk_statut>=5 " ;
$column = 'p.date_valid' ;
2021-02-23 21:09:01 +01:00
if ( ! empty ( $date_start ) && ! empty ( $date_end )) {
2019-12-18 15:20:36 +01:00
$sql .= " AND " . $column . " >= ' " . $db -> idate ( $date_start ) . " ' AND " . $column . " <= ' " . $db -> idate ( $date_end ) . " ' " ;
2021-02-23 21:09:01 +01:00
}
2017-08-31 18:29:57 +02:00
} elseif ( $modecompta == 'RECETTES-DEPENSES' ) {
2016-01-29 14:05:37 +01:00
$sql = " SELECT date_format(pe.datep,'%Y-%m') as dm, sum(p.total_ht) as amount_ht,sum(p.total_ttc) as amount_ttc " ;
2019-12-18 15:20:36 +01:00
$sql .= " FROM " . MAIN_DB_PREFIX . " expensereport as p " ;
$sql .= " INNER JOIN " . MAIN_DB_PREFIX . " user as u ON u.rowid=p.fk_user_author " ;
$sql .= " INNER JOIN " . MAIN_DB_PREFIX . " payment_expensereport as pe ON pe.fk_expensereport = p.rowid " ;
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . " c_paiement as c ON pe.fk_typepayment = c.id " ;
$sql .= " WHERE p.entity IN ( " . getEntity ( 'expensereport' ) . " ) " ;
$sql .= " AND p.fk_statut>=5 " ;
$column = 'pe.datep' ;
2021-02-23 21:09:01 +01:00
if ( ! empty ( $date_start ) && ! empty ( $date_end )) {
2019-12-18 15:20:36 +01:00
$sql .= " AND " . $column . " >= ' " . $db -> idate ( $date_start ) . " ' AND " . $column . " <= ' " . $db -> idate ( $date_end ) . " ' " ;
2021-02-23 21:09:01 +01:00
}
2016-01-29 14:05:37 +01:00
}
2019-12-18 15:20:36 +01:00
$sql .= " GROUP BY dm " ;
2016-01-29 14:05:37 +01:00
dol_syslog ( " get expense report outcome " );
2019-12-18 15:20:36 +01:00
$result = $db -> query ( $sql );
2016-01-29 14:05:37 +01:00
$subtotal_ht = 0 ;
$subtotal_ttc = 0 ;
2021-02-23 21:09:01 +01:00
if ( $result ) {
2016-01-29 14:05:37 +01:00
$num = $db -> num_rows ( $result );
2021-02-23 21:09:01 +01:00
if ( $num ) {
while ( $obj = $db -> fetch_object ( $result )) {
if ( ! isset ( $decaiss [ $obj -> dm ])) {
$decaiss [ $obj -> dm ] = 0 ;
}
2016-01-29 14:05:37 +01:00
$decaiss [ $obj -> dm ] += $obj -> amount_ht ;
2017-06-09 09:25:15 +02:00
2021-02-23 21:09:01 +01:00
if ( ! isset ( $decaiss_ttc [ $obj -> dm ])) {
$decaiss_ttc [ $obj -> dm ] = 0 ;
}
2016-01-29 14:05:37 +01:00
$decaiss_ttc [ $obj -> dm ] += $obj -> amount_ttc ;
}
}
2020-05-21 15:05:19 +02:00
} else {
2016-01-29 14:05:37 +01:00
dol_print_error ( $db );
}
2020-05-21 15:05:19 +02:00
} elseif ( $modecompta == 'BOOKKEEPING' ) {
2017-08-31 18:29:57 +02:00
// Nothing from this table
2016-01-29 14:05:37 +01:00
}
2014-09-16 21:05:57 +02:00
/*
2020-07-06 11:22:30 +02:00
* Donation get dunning payments
2015-10-01 14:38:31 +02:00
*/
2017-08-31 18:29:57 +02:00
2022-08-29 12:04:39 +02:00
if ( isModEnabled ( 'don' ) && ( $modecompta == 'CREANCES-DETTES' || $modecompta == " RECETTES-DEPENSES " )) {
2020-10-31 14:32:18 +01:00
$subtotal_ht = 0 ;
$subtotal_ttc = 0 ;
if ( $modecompta == 'CREANCES-DETTES' ) {
$sql = " SELECT p.societe as nom, p.firstname, p.lastname, date_format(p.datedon,'%Y-%m') as dm, sum(p.amount) as amount " ;
$sql .= " FROM " . MAIN_DB_PREFIX . " don as p " ;
$sql .= " WHERE p.entity IN ( " . getEntity ( 'donation' ) . " ) " ;
$sql .= " AND fk_statut in (1,2) " ;
2021-02-23 21:09:01 +01:00
if ( ! empty ( $date_start ) && ! empty ( $date_end )) {
2019-12-18 15:20:36 +01:00
$sql .= " AND p.datedon >= ' " . $db -> idate ( $date_start ) . " ' AND p.datedon <= ' " . $db -> idate ( $date_end ) . " ' " ;
2021-02-23 21:09:01 +01:00
}
2020-10-31 14:32:18 +01:00
} elseif ( $modecompta == 'RECETTES-DEPENSES' ) {
$sql = " SELECT p.societe as nom, p.firstname, p.lastname, date_format(pe.datep,'%Y-%m') as dm, sum(p.amount) as amount " ;
$sql .= " FROM " . MAIN_DB_PREFIX . " don as p " ;
2019-12-18 15:20:36 +01:00
$sql .= " INNER JOIN " . MAIN_DB_PREFIX . " payment_donation as pe ON pe.fk_donation = p.rowid " ;
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . " c_paiement as c ON pe.fk_typepayment = c.id " ;
$sql .= " WHERE p.entity IN ( " . getEntity ( 'donation' ) . " ) " ;
2021-02-23 21:09:01 +01:00
$sql .= " AND fk_statut >= 2 " ;
2020-10-31 14:32:18 +01:00
if ( ! empty ( $date_start ) && ! empty ( $date_end )) {
$sql .= " AND pe.datep >= ' " . $db -> idate ( $date_start ) . " ' AND pe.datep <= ' " . $db -> idate ( $date_end ) . " ' " ;
}
}
$sql .= " GROUP BY p.societe, p.firstname, p.lastname, dm " ;
dol_syslog ( " get donation payments " );
$result = $db -> query ( $sql );
2021-02-23 21:09:01 +01:00
if ( $result ) {
2020-10-31 14:32:18 +01:00
$num = $db -> num_rows ( $result );
$i = 0 ;
2021-02-23 21:09:01 +01:00
if ( $num ) {
while ( $i < $num ) {
2020-10-31 14:32:18 +01:00
$obj = $db -> fetch_object ( $result );
2021-02-23 21:09:01 +01:00
if ( ! isset ( $encaiss [ $obj -> dm ])) {
$encaiss [ $obj -> dm ] = 0 ;
}
2020-10-31 14:32:18 +01:00
$encaiss [ $obj -> dm ] += $obj -> amount ;
2021-02-23 21:09:01 +01:00
if ( ! isset ( $encaiss_ttc [ $obj -> dm ])) {
$encaiss_ttc [ $obj -> dm ] = 0 ;
}
2020-10-31 14:32:18 +01:00
$encaiss_ttc [ $obj -> dm ] += $obj -> amount ;
$i ++ ;
}
}
} else {
dol_print_error ( $db );
}
2020-05-21 15:05:19 +02:00
} elseif ( $modecompta == 'BOOKKEEPING' ) {
2017-08-31 18:29:57 +02:00
// Nothing from this table
}
2020-05-06 08:38:36 +02:00
/*
* Various Payments
*/
2022-08-29 11:26:26 +02:00
if ( ! empty ( $conf -> global -> ACCOUNTING_REPORTS_INCLUDE_VARPAY ) && isModEnabled ( 'banque' ) && ( $modecompta == 'CREANCES-DETTES' || $modecompta == " RECETTES-DEPENSES " )) {
2020-10-31 14:32:18 +01:00
// decaiss
$sql = " SELECT date_format(p.datep, '%Y-%m') AS dm, SUM(p.amount) AS amount FROM " . MAIN_DB_PREFIX . " payment_various as p " ;
2021-12-18 18:11:28 +01:00
$sql .= " WHERE p.entity IN ( " . getEntity ( 'variouspayment' ) . " ) " ;
$sql .= ' AND p.sens = 0' ;
2021-02-23 21:09:01 +01:00
if ( ! empty ( $date_start ) && ! empty ( $date_end )) {
2020-10-31 14:32:18 +01:00
$sql .= " AND p.datep >= ' " . $db -> idate ( $date_start ) . " ' AND p.datep <= ' " . $db -> idate ( $date_end ) . " ' " ;
2021-02-23 21:09:01 +01:00
}
2020-10-31 14:32:18 +01:00
$sql .= ' GROUP BY dm' ;
dol_syslog ( " get various payments " );
$result = $db -> query ( $sql );
2021-02-23 21:09:01 +01:00
if ( $result ) {
2020-10-31 14:32:18 +01:00
$num = $db -> num_rows ( $result );
$i = 0 ;
2021-02-23 21:09:01 +01:00
if ( $num ) {
while ( $i < $num ) {
2020-10-31 14:32:18 +01:00
$obj = $db -> fetch_object ( $result );
2021-02-23 21:09:01 +01:00
if ( ! isset ( $decaiss_ttc [ $obj -> dm ])) {
$decaiss_ttc [ $obj -> dm ] = 0 ;
}
if ( isset ( $obj -> amount )) {
$decaiss_ttc [ $obj -> dm ] += $obj -> amount ;
}
2020-10-31 14:32:18 +01:00
$i ++ ;
}
}
} else {
dol_print_error ( $db );
}
// encaiss
$sql = " SELECT date_format(p.datep, '%Y-%m') AS dm, SUM(p.amount) AS amount FROM " . MAIN_DB_PREFIX . " payment_various AS p " ;
2021-12-18 18:11:28 +01:00
$sql .= " WHERE p.entity IN ( " . getEntity ( 'variouspayment' ) . " ) " ;
$sql .= ' AND p.sens = 1' ;
2021-02-23 21:09:01 +01:00
if ( ! empty ( $date_start ) && ! empty ( $date_end )) {
2020-10-31 14:32:18 +01:00
$sql .= " AND p.datep >= ' " . $db -> idate ( $date_start ) . " ' AND p.datep <= ' " . $db -> idate ( $date_end ) . " ' " ;
2021-02-23 21:09:01 +01:00
}
2020-10-31 14:32:18 +01:00
$sql .= ' GROUP BY dm' ;
dol_syslog ( " get various payments " );
$result = $db -> query ( $sql );
2021-02-23 21:09:01 +01:00
if ( $result ) {
2020-10-31 14:32:18 +01:00
$num = $db -> num_rows ( $result );
$i = 0 ;
2021-02-23 21:09:01 +01:00
if ( $num ) {
while ( $i < $num ) {
2020-10-31 14:32:18 +01:00
$obj = $db -> fetch_object ( $result );
2021-02-23 21:09:01 +01:00
if ( ! isset ( $encaiss_ttc [ $obj -> dm ])) {
$encaiss_ttc [ $obj -> dm ] = 0 ;
}
if ( isset ( $obj -> amount )) {
$encaiss_ttc [ $obj -> dm ] += $obj -> amount ;
}
2020-10-31 14:32:18 +01:00
$i ++ ;
}
}
} else {
dol_print_error ( $db );
}
2020-05-06 08:38:36 +02:00
}
2020-05-06 13:37:24 +02:00
// Useless with BOOKKEEPING
//elseif ($modecompta == 'BOOKKEEPING') {
//}
2020-05-06 08:38:36 +02:00
/*
* Payement Loan
*/
2022-08-29 12:04:39 +02:00
if ( ! empty ( $conf -> global -> ACCOUNTING_REPORTS_INCLUDE_LOAN ) && isModEnabled ( 'loan' ) && ( $modecompta == 'CREANCES-DETTES' || $modecompta == " RECETTES-DEPENSES " )) {
2021-12-18 18:11:28 +01:00
$sql = " SELECT date_format(p.datep, '%Y-%m') AS dm, SUM(p.amount_capital + p.amount_insurance + p.amount_interest) AS amount " ;
$sql .= " FROM " . MAIN_DB_PREFIX . " payment_loan AS p, " . MAIN_DB_PREFIX . " loan as l " ;
$sql .= " WHERE l.entity IN ( " . getEntity ( 'variouspayment' ) . " ) " ;
$sql .= " AND p.fk_loan = l.rowid " ;
2021-02-23 21:09:01 +01:00
if ( ! empty ( $date_start ) && ! empty ( $date_end )) {
2020-10-31 14:32:18 +01:00
$sql .= " AND p.datep >= ' " . $db -> idate ( $date_start ) . " ' AND p.datep <= ' " . $db -> idate ( $date_end ) . " ' " ;
2021-02-23 21:09:01 +01:00
}
2020-10-31 14:32:18 +01:00
$sql .= ' GROUP BY dm' ;
dol_syslog ( " get loan payments " );
$result = $db -> query ( $sql );
2021-02-23 21:09:01 +01:00
if ( $result ) {
2020-10-31 14:32:18 +01:00
$num = $db -> num_rows ( $result );
$i = 0 ;
2021-02-23 21:09:01 +01:00
if ( $num ) {
while ( $i < $num ) {
2020-10-31 14:32:18 +01:00
$obj = $db -> fetch_object ( $result );
2021-02-23 21:09:01 +01:00
if ( ! isset ( $decaiss_ttc [ $obj -> dm ])) {
$decaiss_ttc [ $obj -> dm ] = 0 ;
}
if ( isset ( $obj -> amount )) {
$decaiss_ttc [ $obj -> dm ] += $obj -> amount ;
}
2020-10-31 14:32:18 +01:00
$i ++ ;
}
}
} else {
dol_print_error ( $db );
}
2020-05-06 08:38:36 +02:00
}
2020-05-06 13:37:24 +02:00
// Useless with BOOKKEEPING
//elseif ($modecompta == 'BOOKKEEPING') {
//}
2017-08-31 18:29:57 +02:00
/*
2017-09-05 09:43:22 +02:00
* Request in mode BOOKKEEPING
2017-08-31 18:29:57 +02:00
*/
2022-08-29 11:26:26 +02:00
if ( isModEnabled ( 'accounting' ) && ( $modecompta == 'BOOKKEEPING' )) {
2018-03-27 14:16:59 +02:00
$predefinedgroupwhere = " ( " ;
2020-12-09 17:02:26 +01:00
$predefinedgroupwhere .= " (aa.pcg_type = 'EXPENSE') " ;
2019-12-18 15:20:36 +01:00
$predefinedgroupwhere .= " OR " ;
2020-12-09 17:02:26 +01:00
$predefinedgroupwhere .= " (aa.pcg_type = 'INCOME') " ;
2019-12-18 15:20:36 +01:00
$predefinedgroupwhere .= " ) " ;
2018-03-27 14:16:59 +02:00
$charofaccountstring = $conf -> global -> CHARTOFACCOUNTS ;
2019-12-18 15:20:36 +01:00
$charofaccountstring = dol_getIdFromCode ( $db , $conf -> global -> CHARTOFACCOUNTS , 'accounting_system' , 'rowid' , 'pcg_version' );
2017-08-31 18:29:57 +02:00
2020-12-09 17:02:26 +01:00
$sql = " SELECT b.doc_ref, b.numero_compte, b.subledger_account, b.subledger_label, aa.pcg_type, date_format(b.doc_date,'%Y-%m') as dm, sum(b.debit) as debit, sum(b.credit) as credit, sum(b.montant) as amount " ;
2019-12-18 15:20:36 +01:00
$sql .= " FROM " . MAIN_DB_PREFIX . " accounting_bookkeeping as b, " . MAIN_DB_PREFIX . " accounting_account as aa " ;
$sql .= " WHERE b.entity = " . $conf -> entity ;
$sql .= " AND aa.entity = " . $conf -> entity ;
$sql .= " AND b.numero_compte = aa.account_number " ;
$sql .= " AND " . $predefinedgroupwhere ;
$sql .= " AND fk_pcg_version = ' " . $db -> escape ( $charofaccountstring ) . " ' " ;
2021-02-23 21:09:01 +01:00
if ( ! empty ( $date_start ) && ! empty ( $date_end )) {
2019-12-18 15:20:36 +01:00
$sql .= " AND b.doc_date >= ' " . $db -> idate ( $date_start ) . " ' AND b.doc_date <= ' " . $db -> idate ( $date_end ) . " ' " ;
2021-02-23 21:09:01 +01:00
}
2019-12-18 15:20:36 +01:00
$sql .= " GROUP BY b.doc_ref, b.numero_compte, b.subledger_account, b.subledger_label, pcg_type, dm " ;
2021-02-10 14:04:06 +01:00
//print $sql;
2017-08-31 18:29:57 +02:00
2018-03-27 14:16:59 +02:00
$subtotal_ht = 0 ;
$subtotal_ttc = 0 ;
2017-09-05 09:43:22 +02:00
dol_syslog ( " get bookkeeping record " );
2019-12-18 15:20:36 +01:00
$result = $db -> query ( $sql );
2021-02-23 21:09:01 +01:00
if ( $result ) {
2017-08-31 18:29:57 +02:00
$num = $db -> num_rows ( $result );
$i = 0 ;
2021-02-23 21:09:01 +01:00
if ( $num ) {
while ( $i < $num ) {
2017-08-31 18:29:57 +02:00
$obj = $db -> fetch_object ( $result );
2020-12-09 21:51:01 +01:00
if ( $obj -> pcg_type == 'INCOME' ) {
2021-02-23 21:09:01 +01:00
if ( ! isset ( $encaiss [ $obj -> dm ])) {
$encaiss [ $obj -> dm ] = 0 ; // To avoid warning of var not defined
}
2020-12-09 21:51:01 +01:00
$encaiss [ $obj -> dm ] += $obj -> credit ;
2021-02-09 23:34:42 +01:00
$encaiss [ $obj -> dm ] -= $obj -> debit ;
2020-12-09 21:51:01 +01:00
}
2021-02-09 23:34:42 +01:00
if ( $obj -> pcg_type == 'EXPENSE' ) {
2021-02-23 21:09:01 +01:00
if ( ! isset ( $decaiss [ $obj -> dm ])) {
$decaiss [ $obj -> dm ] = 0 ; // To avoid warning of var not defined
}
2020-12-09 21:51:01 +01:00
$decaiss [ $obj -> dm ] += $obj -> debit ;
$decaiss [ $obj -> dm ] -= $obj -> credit ;
}
// ???
2021-02-23 21:09:01 +01:00
if ( ! isset ( $encaiss_ttc [ $obj -> dm ])) {
$encaiss_ttc [ $obj -> dm ] = 0 ;
}
if ( ! isset ( $decaiss_ttc [ $obj -> dm ])) {
$decaiss_ttc [ $obj -> dm ] = 0 ;
}
2018-03-27 14:16:59 +02:00
$encaiss_ttc [ $obj -> dm ] += 0 ;
2018-05-30 21:38:57 +02:00
$decaiss_ttc [ $obj -> dm ] += 0 ;
2017-08-31 18:29:57 +02:00
$i ++ ;
}
}
2020-05-21 15:05:19 +02:00
} else {
2017-08-31 18:29:57 +02:00
dol_print_error ( $db );
}
}
$action = " balance " ;
$object = array ( & $encaiss , & $encaiss_ttc , & $decaiss , & $decaiss_ttc );
$parameters [ " mode " ] = $modecompta ;
// Initialize technical object to manage hooks of expenses. Note that conf->hooks_modules contains array array
$hookmanager -> initHooks ( array ( 'externalbalance' ));
2019-12-18 15:20:36 +01:00
$reshook = $hookmanager -> executeHooks ( 'addReportInfo' , $parameters , $object , $action ); // Note that $action and $object may have been modified by some hooks
2017-08-31 18:29:57 +02:00
2014-09-16 21:05:57 +02:00
2005-01-17 20:50:34 +01:00
/*
2010-02-03 00:23:20 +01:00
* Show result array
2005-01-17 20:50:34 +01:00
*/
2010-02-03 00:23:20 +01:00
2019-12-18 15:20:36 +01:00
$totentrees = array ();
$totsorties = array ();
2005-01-17 20:50:34 +01:00
2017-01-22 13:19:07 +01:00
print '<div class="div-table-responsive">' ;
print '<table class="tagtable liste">' . " \n " ;
2012-01-14 12:38:03 +01:00
print '<tr class="liste_titre"><td class="liste_titre"> </td>' ;
2002-06-19 11:20:41 +02:00
2021-02-23 21:09:01 +01:00
for ( $annee = $year_start ; $annee <= $year_end ; $annee ++ ) {
2016-12-27 02:01:27 +01:00
print '<td align="center" colspan="2" class="liste_titre borderrightlight">' ;
2011-05-27 19:30:23 +02:00
print '<a href="clientfourn.php?year=' . $annee . '">' ;
print $annee ;
2021-02-23 21:09:01 +01:00
if ( $conf -> global -> SOCIETE_FISCAL_MONTH_START > 1 ) {
print '-' . ( $annee + 1 );
}
2011-05-27 19:30:23 +02:00
print '</a></td>' ;
2004-03-04 22:26:03 +01:00
}
print '</tr>' ;
2012-01-14 12:38:03 +01:00
print '<tr class="liste_titre"><td class="liste_titre">' . $langs -> trans ( " Month " ) . '</td>' ;
2017-10-14 01:03:59 +02:00
// Loop on each year to ouput
2021-02-23 21:09:01 +01:00
for ( $annee = $year_start ; $annee <= $year_end ; $annee ++ ) {
2017-10-14 01:03:59 +02:00
print '<td class="liste_titre" align="center">' ;
2019-12-18 15:20:36 +01:00
$htmlhelp = '' ;
2017-10-14 01:03:59 +02:00
// if ($modecompta == 'RECETTES-DEPENSES') $htmlhelp=$langs->trans("PurchasesPlusVATEarnedAndDue");
print $form -> textwithpicto ( $langs -> trans ( " Outcome " ), $htmlhelp );
print '</td>' ;
print '<td class="liste_titre" align="center" class="borderrightlight">' ;
2019-12-18 15:20:36 +01:00
$htmlhelp = '' ;
2020-10-23 20:08:35 +02:00
// if ($modecompta == 'RECETTES-DEPENSES') $htmlhelp=$langs->trans("SalesPlusVATToRetrieve");
2017-10-14 01:03:59 +02:00
print $form -> textwithpicto ( $langs -> trans ( " Income " ), $htmlhelp );
print '</td>' ;
2004-03-04 22:26:03 +01:00
}
print '</tr>' ;
2011-01-05 16:15:19 +01:00
2010-02-03 00:23:20 +01:00
// Loop on each month
2019-12-18 15:20:36 +01:00
$nb_mois_decalage = $conf -> global -> SOCIETE_FISCAL_MONTH_START ? ( $conf -> global -> SOCIETE_FISCAL_MONTH_START - 1 ) : 0 ;
2021-02-23 21:09:01 +01:00
for ( $mois = 1 + $nb_mois_decalage ; $mois <= 12 + $nb_mois_decalage ; $mois ++ ) {
2011-01-05 16:15:19 +01:00
$mois_modulo = $mois ;
2021-02-23 21:09:01 +01:00
if ( $mois > 12 ) {
$mois_modulo = $mois - 12 ;
}
2017-06-09 09:25:15 +02:00
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 ( 12 , 0 , 0 , $mois_modulo , 1 , $annee ), " %B " ) . " </td> " ;
2021-02-23 21:09:01 +01:00
for ( $annee = $year_start ; $annee <= $year_end ; $annee ++ ) {
2019-12-18 15:20:36 +01:00
$annee_decalage = $annee ;
2021-02-23 21:09:01 +01:00
if ( $mois > 12 ) {
$annee_decalage = $annee + 1 ;
}
2019-01-27 11:55:16 +01:00
$case = strftime ( " %Y-%m " , dol_mktime ( 12 , 0 , 0 , $mois_modulo , 1 , $annee_decalage ));
2007-11-11 19:05:08 +01:00
2022-04-25 14:07:48 +02:00
print '<td class="right">' ;
2021-12-18 18:11:28 +01:00
if ( $modecompta == 'CREANCES-DETTES' || $modecompta == 'BOOKKEEPING' ) {
2021-02-23 21:09:01 +01:00
if ( isset ( $decaiss [ $case ]) && $decaiss [ $case ] != 0 ) {
2019-12-18 15:20:36 +01:00
print '<a href="clientfourn.php?year=' . $annee_decalage . '&month=' . $mois_modulo . ( $modecompta ? '&modecompta=' . $modecompta : '' ) . '">' . price ( price2num ( $decaiss [ $case ], 'MT' )) . '</a>' ;
2021-02-23 21:09:01 +01:00
if ( ! isset ( $totsorties [ $annee ])) {
$totsorties [ $annee ] = 0 ;
}
2019-12-18 15:20:36 +01:00
$totsorties [ $annee ] += $decaiss [ $case ];
2018-03-27 14:16:59 +02:00
}
2020-05-21 15:05:19 +02:00
} else {
2021-02-23 21:09:01 +01:00
if ( isset ( $decaiss_ttc [ $case ]) && $decaiss_ttc [ $case ] != 0 ) {
2019-12-18 15:20:36 +01:00
print '<a href="clientfourn.php?year=' . $annee_decalage . '&month=' . $mois_modulo . ( $modecompta ? '&modecompta=' . $modecompta : '' ) . '">' . price ( price2num ( $decaiss_ttc [ $case ], 'MT' )) . '</a>' ;
2021-02-23 21:09:01 +01:00
if ( ! isset ( $totsorties [ $annee ])) {
$totsorties [ $annee ] = 0 ;
}
2019-12-18 15:20:36 +01:00
$totsorties [ $annee ] += $decaiss_ttc [ $case ];
2018-03-27 14:16:59 +02:00
}
2007-11-11 19:05:08 +01:00
}
print " </td> " ;
2022-04-25 14:07:48 +02:00
print '<td class="borderrightlight nowrap right">' ;
2021-12-18 18:11:28 +01:00
if ( $modecompta == 'CREANCES-DETTES' || $modecompta == 'BOOKKEEPING' ) {
2021-02-23 21:09:01 +01:00
if ( isset ( $encaiss [ $case ])) {
2019-12-18 15:20:36 +01:00
print '<a href="clientfourn.php?year=' . $annee_decalage . '&month=' . $mois_modulo . ( $modecompta ? '&modecompta=' . $modecompta : '' ) . '">' . price ( price2num ( $encaiss [ $case ], 'MT' )) . '</a>' ;
2021-02-23 21:09:01 +01:00
if ( ! isset ( $totentrees [ $annee ])) {
$totentrees [ $annee ] = 0 ;
}
2019-12-18 15:20:36 +01:00
$totentrees [ $annee ] += $encaiss [ $case ];
2018-03-27 14:16:59 +02:00
}
2020-05-21 15:05:19 +02:00
} else {
2021-02-23 21:09:01 +01:00
if ( isset ( $encaiss_ttc [ $case ])) {
2019-12-18 15:20:36 +01:00
print '<a href="clientfourn.php?year=' . $annee_decalage . '&month=' . $mois_modulo . ( $modecompta ? '&modecompta=' . $modecompta : '' ) . '">' . price ( price2num ( $encaiss_ttc [ $case ], 'MT' )) . '</a>' ;
2021-02-23 21:09:01 +01:00
if ( ! isset ( $totentrees [ $annee ])) {
$totentrees [ $annee ] = 0 ;
}
2019-12-18 15:20:36 +01:00
$totentrees [ $annee ] += $encaiss_ttc [ $case ];
2018-03-27 14:16:59 +02:00
}
2007-11-11 19:05:08 +01:00
}
print " </td> " ;
2004-03-04 22:26:03 +01:00
}
2002-06-19 00:23:12 +02:00
2007-11-11 19:05:08 +01:00
print '</tr>' ;
2004-03-04 22:26:03 +01:00
}
2002-06-19 00:23:12 +02:00
2005-05-07 03:27:54 +02:00
// Total
2017-04-14 11:22:48 +02:00
2019-12-18 15:20:36 +01:00
$nbcols = 0 ;
2018-03-27 14:16:59 +02:00
print '<tr class="liste_total impair"><td>' ;
2021-12-18 18:11:28 +01:00
if ( $modecompta == 'CREANCES-DETTES' || $modecompta == 'BOOKKEEPING' ) {
2021-02-23 21:09:01 +01:00
print $langs -> trans ( " Total " );
} else {
print $langs -> trans ( " TotalTTC " );
}
2018-03-27 14:16:59 +02:00
print '</td>' ;
2021-02-23 21:09:01 +01:00
for ( $annee = $year_start ; $annee <= $year_end ; $annee ++ ) {
2019-12-18 15:20:36 +01:00
$nbcols += 2 ;
print '<td class="nowrap right">' . ( isset ( $totsorties [ $annee ]) ? price ( price2num ( $totsorties [ $annee ], 'MT' )) : ' ' ) . '</td>' ;
print '<td class="nowrap right" style="border-right: 1px solid #DDD">' . ( isset ( $totentrees [ $annee ]) ? price ( price2num ( $totentrees [ $annee ], 'MT' )) : ' ' ) . '</td>' ;
2005-05-07 03:27:54 +02:00
}
print " </tr> \n " ;
2011-01-05 16:15:19 +01:00
// Empty line
2016-12-27 02:01:27 +01:00
print '<tr class="impair"><td> </td>' ;
2005-06-11 13:58:06 +02:00
print '<td colspan="' . $nbcols . '"> </td>' ;
print " </tr> \n " ;
2005-05-07 03:27:54 +02:00
// Balance
2017-04-14 11:22:48 +02:00
2015-02-07 14:55:56 +01:00
print '<tr class="liste_total"><td>' . $langs -> trans ( " AccountingResult " ) . '</td>' ;
2021-02-23 21:09:01 +01:00
for ( $annee = $year_start ; $annee <= $year_end ; $annee ++ ) {
2019-02-12 14:44:25 +01:00
print '<td colspan="2" class="borderrightlight right"> ' ;
2021-02-23 21:09:01 +01:00
if ( isset ( $totentrees [ $annee ]) || isset ( $totsorties [ $annee ])) {
2019-12-18 15:20:36 +01:00
$in = ( isset ( $totentrees [ $annee ]) ? price2num ( $totentrees [ $annee ], 'MT' ) : 0 );
$out = ( isset ( $totsorties [ $annee ]) ? price2num ( $totsorties [ $annee ], 'MT' ) : 0 );
print price ( price2num ( $in - $out , 'MT' )) . '</td>' ;
2010-01-13 19:51:19 +01:00
// print '<td> </td>';
}
2004-03-04 22:26:03 +01:00
}
print " </tr> \n " ;
2002-06-19 00:23:12 +02:00
2004-03-04 22:26:03 +01:00
print " </table> " ;
2017-01-22 13:19:07 +01:00
print '</div>' ;
2002-06-19 00:23:12 +02:00
2018-08-08 12:29:36 +02:00
// End of page
2011-08-27 16:24:16 +02:00
llxFooter ();
2012-01-08 23:43:32 +01:00
$db -> close ();