2004-10-19 22:35:36 +02:00
< ? php
2018-09-09 09:36:12 +02:00
/* Copyright ( C ) 2002 - 2006 Rodolphe Quiedeville < rodolphe @ quiedeville . org >
* Copyright ( C ) 2004 - 2017 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 ) 2012 Cédric Salvador < csalvador @ gpcsolutions . fr >
* Copyright ( C ) 2012 - 2014 Raphaël Dourseanud < rdoursenaud @ gpcsolutions . fr >
* Copyright ( C ) 2014 - 2106 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 >
2004-03-04 22:26:03 +01: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
2004-03-04 22:26:03 +01: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-03 02:45:22 +02:00
* along with this program . If not , see < http :// www . gnu . org / licenses />.
2004-03-04 22:26:03 +01:00
*/
2005-05-03 02:41:51 +02:00
/**
2017-08-31 18:29:57 +02:00
* \file htdocs / compta / resultat / clientfourn . php
* \ingroup compta , accountancy
* \brief Page reporting
2010-02-02 22:23:23 +01:00
*/
2005-05-03 02:41:51 +02: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 . '/compta/tva/class/tva.class.php' ;
require_once DOL_DOCUMENT_ROOT . '/compta/sociales/class/chargesociales.class.php' ;
require_once DOL_DOCUMENT_ROOT . '/core/lib/report.lib.php' ;
require_once DOL_DOCUMENT_ROOT . '/core/lib/tax.lib.php' ;
require_once DOL_DOCUMENT_ROOT . '/core/lib/date.lib.php' ;
2017-09-05 02:26:23 +02:00
require_once DOL_DOCUMENT_ROOT . '/accountancy/class/accountancycategory.class.php' ;
2008-01-10 18:12:07 +01:00
2018-05-27 09:27:09 +02:00
// Load translation files required by the page
2017-09-05 12:53:25 +02:00
$langs -> loadLangs ( array ( 'compta' , 'bills' , 'donation' , 'salaries' , 'accountancy' ));
2004-03-04 22:26:03 +01:00
2017-09-05 02:13:02 +02: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' );
2017-09-12 13:52:19 +02:00
$showaccountdetail = GETPOST ( 'showaccountdetail' , 'aZ09' ) ? GETPOST ( 'showaccountdetail' , 'aZ09' ) : 'no' ;
2012-08-03 20:09:37 +02:00
2010-02-03 00:23:20 +01:00
// Security check
2012-02-27 22:26:22 +01:00
$socid = GETPOST ( 'socid' , 'int' );
2010-02-03 00:23:20 +01:00
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' );
2004-03-04 22:26:03 +01:00
2017-06-08 14:55:12 +02:00
$limit = GETPOST ( 'limit' , 'int' ) ? GETPOST ( 'limit' , 'int' ) : $conf -> liste_limit ;
2016-11-28 18:38:48 +01:00
$sortfield = GETPOST ( " sortfield " , 'alpha' );
$sortorder = GETPOST ( " sortorder " , 'alpha' );
$page = GETPOST ( " page " , 'int' );
2017-06-06 10:53:53 +02:00
if ( empty ( $page ) || $page == - 1 ) { $page = 0 ; } // If $page is not defined, or '' or -1
2016-11-28 18:38:48 +01:00
$offset = $limit * $page ;
$pageprev = $page - 1 ;
$pagenext = $page + 1 ;
2017-08-31 18:29:57 +02:00
//if (! $sortfield) $sortfield='s.nom, s.rowid';
2016-11-28 18:38:48 +01:00
if ( ! $sortorder ) $sortorder = 'ASC' ;
2010-02-02 22:23:23 +01:00
// Date range
2017-08-31 15:44:36 +02:00
$year = GETPOST ( 'year' , 'int' );
2010-02-02 22:23:23 +01:00
if ( empty ( $year ))
{
2011-05-28 14:19:49 +02:00
$year_current = strftime ( " %Y " , dol_now ());
$month_current = strftime ( " %m " , dol_now ());
$year_start = $year_current ;
2010-02-02 22:23:23 +01:00
} else {
2011-05-28 14:19:49 +02:00
$year_current = $year ;
$month_current = strftime ( " %m " , dol_now ());
$year_start = $year ;
2010-02-02 22:23:23 +01:00
}
2012-08-03 20:09:37 +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 );
2017-08-31 15:44:36 +02:00
// We define date_start and date_end
2010-02-02 22:23:23 +01:00
if ( empty ( $date_start ) || empty ( $date_end )) // We define date_start and date_end
{
2011-05-28 14:19:49 +02:00
$q = GETPOST ( " q " ) ? GETPOST ( " q " ) : 0 ;
if ( $q == 0 )
{
// We define date_start and date_end
$year_end = $year_start ;
$month_start = GETPOST ( " month " ) ? GETPOST ( " month " ) : ( $conf -> global -> SOCIETE_FISCAL_MONTH_START ? ( $conf -> global -> SOCIETE_FISCAL_MONTH_START ) : 1 );
if ( ! GETPOST ( 'month' ))
{
2011-06-13 13:10:43 +02:00
if ( ! GETPOST ( " year " ) && $month_start > $month_current )
2011-05-28 14:19:49 +02:00
{
$year_start -- ;
$year_end -- ;
}
$month_end = $month_start - 1 ;
if ( $month_end < 1 ) $month_end = 12 ;
else $year_end ++ ;
}
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 ); }
2010-02-02 22:23:23 +01:00
}
2018-03-27 13:37:40 +02:00
// $date_start and $date_end are defined. We force $year_start and $nbofyear
2017-08-31 18:29:57 +02:00
$tmps = dol_getdate ( $date_start );
2018-03-27 13:37:40 +02:00
$year_start = $tmps [ 'year' ];
2017-08-31 18:29:57 +02:00
$tmpe = dol_getdate ( $date_end );
$year_end = $tmpe [ 'year' ];
$nbofyear = ( $year_end - $start_year ) + 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'));
2017-08-31 18:29:57 +02:00
// Define modecompta ('CREANCES-DETTES' or 'RECETTES-DEPENSES' or 'BOOKKEEPING')
$modecompta = $conf -> global -> ACCOUNTING_MODE ;
if ( ! empty ( $conf -> accounting -> enabled )) $modecompta = 'BOOKKEEPING' ;
if ( GETPOST ( " modecompta " , 'alpha' )) $modecompta = GETPOST ( " modecompta " , 'alpha' );
2004-03-04 22:26:03 +01:00
2017-09-05 02:26:23 +02:00
$AccCat = new AccountancyCategory ( $db );
2010-02-02 22:23:23 +01:00
2004-03-04 22:26:03 +01:00
2010-02-03 00:23:20 +01:00
/*
* View
*/
2017-09-05 02:26:23 +02:00
$months = array (
$langs -> trans ( " JanuaryMin " ),
$langs -> trans ( " FebruaryMin " ),
$langs -> trans ( " MarchMin " ),
$langs -> trans ( " AprilMin " ),
$langs -> trans ( " MayMin " ),
$langs -> trans ( " JuneMin " ),
$langs -> trans ( " JulyMin " ),
$langs -> trans ( " AugustMin " ),
$langs -> trans ( " SeptemberMin " ),
$langs -> trans ( " OctoberMin " ),
$langs -> trans ( " NovemberMin " ),
$langs -> trans ( " DecemberMin " ),
);
2005-05-03 02:41:51 +02:00
llxHeader ();
2011-11-08 10:18:45 +01:00
$form = new Form ( $db );
2005-05-03 02:41:51 +02:00
2012-08-03 20:09:37 +02:00
$periodlink = '' ;
$exportlink = '' ;
$total_ht = 0 ;
$total_ttc = 0 ;
2009-05-08 17:58:01 +02:00
// Affiche en-tete de rapport
2005-01-17 20:50:34 +01:00
if ( $modecompta == " CREANCES-DETTES " )
{
2017-09-12 13:05:34 +02:00
$name = $langs -> trans ( " ReportInOut " ) . ', ' . $langs -> trans ( " ByPredefinedAccountGroups " );
2013-10-10 19:26:07 +02:00
$calcmode = $langs -> trans ( " CalcModeDebt " );
2017-09-05 12:53:25 +02:00
$calcmode .= '<br>(' . $langs -> trans ( " SeeReportInInputOutputMode " , '<a href="' . $_SERVER [ " PHP_SELF " ] . '?date_startyear=' . $tmps [ 'year' ] . '&date_startmonth=' . $tmps [ 'mon' ] . '&date_startday=' . $tmps [ 'mday' ] . '&date_endyear=' . $tmpe [ 'year' ] . '&date_endmonth=' . $tmpe [ 'mon' ] . '&date_endday=' . $tmpe [ 'mday' ] . '&modecompta=RECETTES-DEPENSES">' , '</a>' ) . ')' ;
2018-01-20 12:12:36 +01:00
if ( ! empty ( $conf -> accounting -> enabled )) $calcmode .= '<br>(' . $langs -> trans ( " SeeReportInBookkeepingMode " , '<a href="' . $_SERVER [ " PHP_SELF " ] . '?date_startyear=' . $tmps [ 'year' ] . '&date_startmonth=' . $tmps [ 'mon' ] . '&date_startday=' . $tmps [ 'mday' ] . '&date_endyear=' . $tmpe [ 'year' ] . '&date_endmonth=' . $tmpe [ 'mon' ] . '&date_endday=' . $tmpe [ 'mday' ] . '&modecompta=BOOKKEEPING">' , '</a>' ) . ')' ;
2018-09-09 09:36:12 +02:00
$period = $form -> selectDate ( $date_start , 'date_start' , 0 , 0 , 0 , '' , 1 , 0 ) . ' - ' . $form -> selectDate ( $date_end , 'date_end' , 0 , 0 , 0 , '' , 1 , 0 );
2017-09-05 12:53:25 +02:00
$periodlink = ( $year_start ? " <a href=' " . $_SERVER [ " PHP_SELF " ] . " ?year= " . ( $tmps [ 'year' ] - 1 ) . " &modecompta= " . $modecompta . " '> " . img_previous () . " </a> <a href=' " . $_SERVER [ " PHP_SELF " ] . " ?year= " . ( $tmps [ 'year' ] + 1 ) . " &modecompta= " . $modecompta . " '> " . img_next () . " </a> " : " " );
2011-05-28 14:19:49 +02:00
$description = $langs -> trans ( " RulesResultDue " );
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-05-28 14:19:49 +02:00
//$exportlink=$langs->trans("NotYetAvailable");
2005-01-17 20:50:34 +01:00
}
2017-08-31 18:29:57 +02:00
elseif ( $modecompta == " RECETTES-DEPENSES " )
{
2017-09-12 13:05:34 +02:00
$name = $langs -> trans ( " ReportInOut " ) . ', ' . $langs -> trans ( " ByPredefinedAccountGroups " );
2013-10-10 19:26:07 +02:00
$calcmode = $langs -> trans ( " CalcModeEngagement " );
2017-09-05 12:53:25 +02:00
$calcmode .= '<br>(' . $langs -> trans ( " SeeReportInDueDebtMode " , '<a href="' . $_SERVER [ " PHP_SELF " ] . '?date_startyear=' . $tmps [ 'year' ] . '&date_startmonth=' . $tmps [ 'mon' ] . '&date_startday=' . $tmps [ 'mday' ] . '&date_endyear=' . $tmpe [ 'year' ] . '&date_endmonth=' . $tmpe [ 'mon' ] . '&date_endday=' . $tmpe [ 'mday' ] . '&modecompta=CREANCES-DETTES">' , '</a>' ) . ')' ;
2018-01-20 12:12:36 +01:00
if ( ! empty ( $conf -> accounting -> enabled )) $calcmode .= '<br>(' . $langs -> trans ( " SeeReportInBookkeepingMode " , '<a href="' . $_SERVER [ " PHP_SELF " ] . '?date_startyear=' . $tmps [ 'year' ] . '&date_startmonth=' . $tmps [ 'mon' ] . '&date_startday=' . $tmps [ 'mday' ] . '&date_endyear=' . $tmpe [ 'year' ] . '&date_endmonth=' . $tmpe [ 'mon' ] . '&date_endday=' . $tmpe [ 'mday' ] . '&modecompta=BOOKKEEPING">' , '</a>' ) . ')' ;
2018-09-09 09:36:12 +02: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= " . ( $tmps [ 'year' ] - 1 ) . " &modecompta= " . $modecompta . " '> " . img_previous () . " </a> <a href=' " . $_SERVER [ " PHP_SELF " ] . " ?year= " . ( $tmps [ 'year' ] + 1 ) . " &modecompta= " . $modecompta . " '> " . img_next () . " </a> " : " " );
2011-05-28 14:19:49 +02:00
$description = $langs -> trans ( " RulesResultInOut " );
2017-09-05 09:43:22 +02:00
$builddate = dol_now ();
2011-05-28 14:19:49 +02:00
//$exportlink=$langs->trans("NotYetAvailable");
2005-01-17 20:50:34 +01:00
}
2017-08-31 18:29:57 +02:00
elseif ( $modecompta == " BOOKKEEPING " )
{
2017-09-12 13:05:34 +02:00
$name = $langs -> trans ( " ReportInOut " ) . ', ' . $langs -> trans ( " ByPredefinedAccountGroups " );
2017-08-31 18:29:57 +02:00
$calcmode = $langs -> trans ( " CalcModeBookkeeping " );
2017-09-05 12:53:25 +02:00
$calcmode .= '<br>(' . $langs -> trans ( " SeeReportInInputOutputMode " , '<a href="' . $_SERVER [ " PHP_SELF " ] . '?date_startyear=' . $tmps [ 'year' ] . '&date_startmonth=' . $tmps [ 'mon' ] . '&date_startday=' . $tmps [ 'mday' ] . '&date_endyear=' . $tmpe [ 'year' ] . '&date_endmonth=' . $tmpe [ 'mon' ] . '&date_endday=' . $tmpe [ 'mday' ] . '&modecompta=RECETTES-DEPENSES">' , '</a>' ) . ')' ;
$calcmode .= '<br>(' . $langs -> trans ( " SeeReportInDueDebtMode " , '<a href="' . $_SERVER [ " PHP_SELF " ] . '?date_startyear=' . $tmps [ 'year' ] . '&date_startmonth=' . $tmps [ 'mon' ] . '&date_startday=' . $tmps [ 'mday' ] . '&date_endyear=' . $tmpe [ 'year' ] . '&date_endmonth=' . $tmpe [ 'mon' ] . '&date_endday=' . $tmpe [ 'mday' ] . '&modecompta=CREANCES-DETTES">' , '</a>' ) . ')' ;
2018-09-09 09:36:12 +02:00
$period = $form -> selectDate ( $date_start , 'date_start' , 0 , 0 , 0 , '' , 1 , 0 ) . ' - ' . $form -> selectDate ( $date_end , 'date_end' , 0 , 0 , 0 , '' , 1 , 0 );
2017-09-12 12:52:48 +02:00
$arraylist = array ( 'no' => $langs -> trans ( " No " ), 'yes' => $langs -> trans ( " AccountWithNonZeroValues " ), 'all' => $langs -> trans ( " All " ));
$period .= ' ' . $langs -> trans ( " DetailByAccount " ) . ' ' . $form -> selectarray ( 'showaccountdetail' , $arraylist , $showaccountdetail , 0 );
2017-09-05 12:53:25 +02:00
$periodlink = ( $year_start ? " <a href=' " . $_SERVER [ " PHP_SELF " ] . " ?year= " . ( $tmps [ 'year' ] - 1 ) . " &modecompta= " . $modecompta . " '> " . img_previous () . " </a> <a href=' " . $_SERVER [ " PHP_SELF " ] . " ?year= " . ( $tmps [ 'year' ] + 1 ) . " &modecompta= " . $modecompta . " '> " . img_next () . " </a> " : " " );
2017-09-05 02:13:02 +02:00
$description = $langs -> trans ( " RulesResultBookkeepingPredefined " );
2017-11-28 11:31:55 +01:00
$description .= ' (' . $langs -> trans ( " SeePageForSetup " , DOL_URL_ROOT . '/accountancy/admin/account.php?mainmenu=accountancy&leftmenu=accountancy_admin' , $langs -> transnoentitiesnoconv ( " Accountancy " ) . ' / ' . $langs -> transnoentitiesnoconv ( " Setup " ) . ' / ' . $langs -> transnoentitiesnoconv ( " Chartofaccounts " )) . ')' ;
2017-09-05 09:43:22 +02:00
$builddate = dol_now ();
2017-08-31 18:29:57 +02:00
//$exportlink=$langs->trans("NotYetAvailable");
}
2015-05-13 17:53:25 +02:00
$hselected = 'report' ;
2017-09-05 10:16:08 +02:00
report_header ( $name , '' , $period , $periodlink , $description , $builddate , $exportlink , array ( 'modecompta' => $modecompta ), $calcmode );
2005-01-17 20:50:34 +01: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 );
}
2010-02-03 00:23:20 +01:00
// Show report array
2016-11-28 18:38:48 +01:00
$param = '&modecompta=' . $modecompta ;
if ( $date_startday ) $param .= '&date_startday=' . $date_startday ;
if ( $date_startmonth ) $param .= '&date_startmonth=' . $date_startmonth ;
if ( $date_startyear ) $param .= '&date_startyear=' . $date_startyear ;
if ( $date_endday ) $param .= '&date_endday=' . $date_endday ;
if ( $date_endmonth ) $param .= '&date_endmonth=' . $date_endmonth ;
if ( $date_endyear ) $param .= '&date_endyear=' . $date_startyear ;
2005-01-17 20:50:34 +01:00
print '<table class="noborder" width="100%">' ;
2004-03-04 22:26:03 +01:00
print '<tr class="liste_titre">' ;
2018-03-15 13:19:29 +01:00
print_liste_field_titre ( " PredefinedGroups " , $_SERVER [ " PHP_SELF " ], 'f.thirdparty_code,f.rowid' , '' , $param , '' , $sortfield , $sortorder , 'width200 ' );
2016-11-28 18:38:48 +01:00
print_liste_field_titre ( '' );
2017-08-31 18:29:57 +02:00
if ( $modecompta == 'BOOKKEEPING' )
2016-11-28 18:38:48 +01:00
{
2017-08-31 18:29:57 +02:00
print_liste_field_titre ( " Amount " , $_SERVER [ " PHP_SELF " ], 'amount' , '' , $param , 'align="right"' , $sortfield , $sortorder );
2012-01-08 23:43:32 +01:00
}
else
{
2017-08-31 18:29:57 +02:00
if ( $modecompta == 'CREANCES-DETTES' )
{
print_liste_field_titre ( " AmountHT " , $_SERVER [ " PHP_SELF " ], 'amount_ht' , '' , $param , 'align="right"' , $sortfield , $sortorder );
}
print_liste_field_titre ( " AmountTTC " , $_SERVER [ " PHP_SELF " ], 'amount_ttc' , '' , $param , 'align="right"' , $sortfield , $sortorder );
2016-11-28 18:38:48 +01:00
}
2004-03-04 22:26:03 +01:00
print " </tr> \n " ;
2004-04-10 21:04:14 +02:00
2005-05-06 02:21:33 +02:00
2011-05-28 14:19:49 +02:00
2017-08-31 18:29:57 +02:00
if ( $modecompta == 'BOOKKEEPING' )
2012-01-08 23:43:32 +01:00
{
2017-09-05 12:53:25 +02:00
$predefinedgroupwhere = " ( " ;
2017-09-06 19:21:46 +02:00
//$predefinedgroupwhere.= " (pcg_type = 'EXPENSE' and pcg_subtype in ('PRODUCT','SERVICE'))";
$predefinedgroupwhere .= " (pcg_type = 'EXPENSE') " ;
2017-09-05 12:53:25 +02:00
$predefinedgroupwhere .= " OR " ;
2017-09-06 19:21:46 +02:00
//$predefinedgroupwhere.= " (pcg_type = 'INCOME' and pcg_subtype in ('PRODUCT','SERVICE'))";
$predefinedgroupwhere .= " (pcg_type = 'INCOME') " ;
2017-09-05 12:53:25 +02:00
$predefinedgroupwhere .= " ) " ;
$charofaccountstring = $conf -> global -> CHARTOFACCOUNTS ;
$charofaccountstring = dol_getIdFromCode ( $db , $conf -> global -> CHARTOFACCOUNTS , 'accounting_system' , 'rowid' , 'pcg_version' );
2017-08-31 18:29:57 +02:00
$sql = " SELECT f.thirdparty_code as name, -1 as socid, aa.pcg_type, aa.pcg_subtype, sum(f.credit - f.debit) as amount " ;
$sql .= " FROM " . MAIN_DB_PREFIX . " accounting_bookkeeping as f " ;
$sql .= " , " . MAIN_DB_PREFIX . " accounting_account as aa " ;
$sql .= " WHERE f.numero_compte = aa.account_number " ;
2017-09-05 12:53:25 +02:00
$sql .= " AND " . $predefinedgroupwhere ;
2018-03-27 13:55:10 +02:00
$sql .= " AND fk_pcg_version = ' " . $db -> escape ( $charofaccountstring ) . " ' " ;
2018-03-06 19:56:08 +01:00
$sql .= " AND f.entity = " . $conf -> entity ;
2017-08-31 18:29:57 +02:00
if ( ! empty ( $date_start ) && ! empty ( $date_end ))
$sql .= " AND f.doc_date >= ' " . $db -> idate ( $date_start ) . " ' AND f.doc_date <= ' " . $db -> idate ( $date_end ) . " ' " ;
2017-09-05 12:53:25 +02:00
$sql .= " GROUP BY pcg_type, pcg_subtype, name, socid " ;
2017-08-31 18:29:57 +02:00
$sql .= $db -> order ( $sortfield , $sortorder );
2017-06-09 09:25:15 +02:00
2017-08-31 18:29:57 +02:00
$oldpcgtype = '' ;
2017-09-05 12:53:25 +02:00
$oldpcgsubtype = '' ;
2011-05-28 14:19:49 +02:00
2017-08-31 18:29:57 +02:00
dol_syslog ( " get bookkeeping entries " , LOG_DEBUG );
$result = $db -> query ( $sql );
if ( $result ) {
$num = $db -> num_rows ( $result );
$i = 0 ;
if ( $num > 0 )
{
while ( $i < $num )
{
$objp = $db -> fetch_object ( $result );
2005-05-07 18:02:22 +02:00
2017-08-31 18:29:57 +02:00
if ( $objp -> pcg_type != $oldpcgtype )
{
print '<tr><td colspan="4">' . $objp -> pcg_type . '</td></tr>' ;
$oldpcgtype = $objp -> pcg_type ;
}
2005-05-07 18:02:22 +02:00
2017-08-31 18:29:57 +02:00
print '<tr class="oddeven">' ;
print '<td> </td>' ;
print '<td>' . $objp -> pcg_type . ( $objp -> pcg_subtype != 'XXXXXX' ? ' - ' . $objp -> pcg_subtype : '' ) . ( $objp -> name ? ' (' . $objp -> name . ')' : '' ) . " </td> \n " ;
print '<td align="right">' . price ( $objp -> amount ) . " </td> \n " ;
print " </tr> \n " ;
2004-04-10 21:04:14 +02:00
2017-08-31 18:29:57 +02:00
$total_ht += ( isset ( $objp -> amount ) ? $objp -> amount : 0 );
$total_ttc += ( isset ( $objp -> amount ) ? $objp -> amount : 0 );
2005-05-11 03:23:52 +02:00
2017-09-05 02:13:02 +02:00
// Loop on detail of all accounts
// This make 14 calls for each detail of account (NP, N and month m)
2017-09-12 12:52:48 +02:00
if ( $showaccountdetail != 'no' )
2017-09-05 02:26:23 +02:00
{
2017-09-05 12:53:25 +02:00
$tmppredefinedgroupwhere = " pcg_type = ' " . $db -> escape ( $objp -> pcg_type ) . " ' AND pcg_subtype = ' " . $db -> escape ( $objp -> pcg_subtype ) . " ' " ;
2018-03-27 13:55:10 +02:00
$tmppredefinedgroupwhere .= " AND fk_pcg_version = ' " . $db -> escape ( $charofaccountstring ) . " ' " ;
2017-09-05 12:53:25 +02:00
//$tmppredefinedgroupwhere.= " AND thirdparty_code = '".$db->escape($objp->name)."'";
// Get cpts of category/group
$cpts = $AccCat -> getCptsCat ( 0 , $tmppredefinedgroupwhere );
2017-09-05 02:26:23 +02:00
2017-09-05 02:13:02 +02:00
foreach ( $cpts as $i => $cpt )
{
2018-11-22 10:40:15 +01:00
$return = $AccCat -> getSumDebitCredit ( $cpt [ 'account_number' ], $date_start , $date_end , $cpt [ 'dc' ]);
2017-09-05 12:53:25 +02:00
if ( $return < 0 ) {
setEventMessages ( null , $AccCat -> errors , 'errors' );
$resultN = 0 ;
} else {
$resultN = $AccCat -> sdc ;
}
2017-09-05 02:13:02 +02:00
2017-09-12 12:52:48 +02:00
2018-03-27 13:55:10 +02:00
if ( $showaccountdetail == 'all' || $resultN <> 0 )
2017-09-05 02:13:02 +02:00
{
2017-09-05 12:53:25 +02:00
print '<tr>' ;
print '<td></td>' ;
print '<td class="tdoverflowmax200"> ' . length_accountg ( $cpt [ 'account_number' ]) . ' - ' . $cpt [ 'account_label' ] . '</td>' ;
print '<td align="right">' . price ( $resultN ) . '</td>' ;
print " </tr> \n " ;
2017-09-05 02:13:02 +02:00
}
}
}
2011-05-28 14:19:49 +02:00
2017-08-31 18:29:57 +02:00
$i ++ ;
}
}
else
{
print '<tr><td colspan="4" class="opacitymedium">' . $langs -> trans ( " NoRecordFound " ) . '</td></tr>' ;
}
}
else dol_print_error ( $db );
2004-03-04 22:26:03 +01:00
}
2012-01-08 23:43:32 +01:00
else
2009-02-11 22:15:47 +01:00
{
2017-08-31 18:29:57 +02:00
/*
* Factures clients
*/
2017-10-14 01:03:59 +02:00
print '<tr class="trforbreak"><td colspan="4">' . $langs -> trans ( " CustomersInvoices " ) . '</td></tr>' ;
2011-05-28 14:19:49 +02:00
2017-08-31 18:29:57 +02:00
if ( $modecompta == 'CREANCES-DETTES' )
{
$sql = " SELECT s.nom as name, s.rowid as socid, sum(f.total) as amount_ht, sum(f.total_ttc) as amount_ttc " ;
$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) " ;
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 ))
$sql .= " AND f.datef >= ' " . $db -> idate ( $date_start ) . " ' AND f.datef <= ' " . $db -> idate ( $date_end ) . " ' " ;
}
elseif ( $modecompta == 'RECETTES-DEPENSES' )
{
/*
* 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 )
*/
$sql = " SELECT s.nom as name, s.rowid as socid, sum(pf.amount) as amount_ttc " ;
$sql .= " FROM " . MAIN_DB_PREFIX . " societe as s " ;
$sql .= " , " . 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 " ;
$sql .= " AND f.fk_soc = s.rowid " ;
if ( ! empty ( $date_start ) && ! empty ( $date_end ))
$sql .= " AND p.datep >= ' " . $db -> idate ( $date_start ) . " ' AND p.datep <= ' " . $db -> idate ( $date_end ) . " ' " ;
}
$sql .= " AND f.entity = " . $conf -> entity ;
if ( $socid ) $sql .= " AND f.fk_soc = " . $socid ;
$sql .= " GROUP BY name, socid " ;
$sql .= $db -> order ( $sortfield , $sortorder );
dol_syslog ( " get customer invoices " , LOG_DEBUG );
$result = $db -> query ( $sql );
if ( $result ) {
$num = $db -> num_rows ( $result );
$i = 0 ;
while ( $i < $num )
{
$objp = $db -> fetch_object ( $result );
2011-05-28 14:19:49 +02:00
2017-08-31 18:29:57 +02:00
print '<tr class="oddeven"><td> </td>' ;
print " <td> " . $langs -> trans ( " Bills " ) . ' <a href="' . DOL_URL_ROOT . '/compta/facture/list.php?socid=' . $objp -> socid . '">' . $objp -> name . " </td> \n " ;
2011-05-28 14:19:49 +02:00
2017-08-31 18:29:57 +02:00
if ( $modecompta == 'CREANCES-DETTES' )
print " <td align= \" right \" > " . price ( $objp -> amount_ht ) . " </td> \n " ;
print " <td align= \" right \" > " . price ( $objp -> amount_ttc ) . " </td> \n " ;
2012-08-03 20:09:37 +02:00
2017-08-31 18:29:57 +02:00
$total_ht += ( isset ( $objp -> amount_ht ) ? $objp -> amount_ht : 0 );
$total_ttc += $objp -> amount_ttc ;
print " </tr> \n " ;
$i ++ ;
}
$db -> free ( $result );
} else {
dol_print_error ( $db );
}
2005-05-07 18:02:22 +02:00
2017-08-31 18:29:57 +02:00
// On ajoute les paiements clients anciennes version, non lie par paiement_facture
if ( $modecompta == 'RECETTES-DEPENSES' )
{
$sql = " SELECT 'Autres' as name, '0' as idp, sum(p.amount) as amount_ttc " ;
$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' ) . " ) " ;
if ( ! empty ( $date_start ) && ! empty ( $date_end ))
$sql .= " AND p.datep >= ' " . $db -> idate ( $date_start ) . " ' AND p.datep <= ' " . $db -> idate ( $date_end ) . " ' " ;
$sql .= " GROUP BY name, idp " ;
$sql .= " ORDER BY name " ;
dol_syslog ( " get old customer payments not linked to invoices " , LOG_DEBUG );
$result = $db -> query ( $sql );
if ( $result ) {
$num = $db -> num_rows ( $result );
$i = 0 ;
if ( $num ) {
while ( $i < $num )
{
$objp = $db -> fetch_object ( $result );
print '<tr class="oddeven"><td> </td>' ;
print " <td> " . $langs -> trans ( " Bills " ) . " " . $langs -> trans ( " Other " ) . " ( " . $langs -> trans ( " PaymentsNotLinkedToInvoice " ) . " ) \n " ;
if ( $modecompta == 'CREANCES-DETTES' )
print " <td align= \" right \" > " . price ( $objp -> amount_ht ) . " </td> \n " ;
print " <td align= \" right \" > " . price ( $objp -> amount_ttc ) . " </td> \n " ;
$total_ht += ( isset ( $objp -> amount_ht ) ? $objp -> amount_ht : 0 );
$total_ttc += $objp -> amount_ttc ;
print " </tr> \n " ;
$i ++ ;
}
}
$db -> free ( $result );
} else {
dol_print_error ( $db );
}
}
2005-05-07 18:02:22 +02:00
2017-08-31 18:29:57 +02:00
if ( $total_ttc == 0 )
{
print '<tr class="oddeven"><td> </td>' ;
print '<td colspan="3" class="opacitymedium">' . $langs -> trans ( " None " ) . '</td>' ;
print '</tr>' ;
}
2004-04-10 21:04:14 +02:00
2017-08-31 18:29:57 +02:00
print '<tr class="liste_total">' ;
if ( $modecompta == 'CREANCES-DETTES' )
print '<td colspan="3" align="right">' . price ( $total_ht ) . '</td>' ;
print '<td colspan="3" align="right">' . price ( $total_ttc ) . '</td>' ;
print '</tr>' ;
2005-05-11 03:23:52 +02:00
2017-06-09 09:25:15 +02:00
2017-08-31 18:29:57 +02:00
/*
* Suppliers invoices
*/
if ( $modecompta == 'CREANCES-DETTES' )
{
$sql = " SELECT s.nom as name, s.rowid as socid, sum(f.total_ht) as amount_ht, sum(f.total_ttc) as amount_ttc " ;
$sql .= " FROM " . MAIN_DB_PREFIX . " societe as s " ;
$sql .= " , " . MAIN_DB_PREFIX . " facture_fourn as f " ;
$sql .= " WHERE f.fk_soc = s.rowid " ;
$sql .= " AND f.fk_statut IN (1,2) " ;
if ( ! empty ( $conf -> global -> FACTURE_DEPOSITS_ARE_JUST_PAYMENTS ))
$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 ))
$sql .= " AND f.datef >= ' " . $db -> idate ( $date_start ) . " ' AND f.datef <= ' " . $db -> idate ( $date_end ) . " ' " ;
}
elseif ( $modecompta == 'RECETTES-DEPENSES' )
{
$sql = " SELECT s.nom as name, s.rowid as socid, sum(pf.amount) as amount_ttc " ;
$sql .= " FROM " . MAIN_DB_PREFIX . " paiementfourn as p " ;
$sql .= " , " . MAIN_DB_PREFIX . " paiementfourn_facturefourn as pf " ;
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . " facture_fourn as f " ;
$sql .= " ON pf.fk_facturefourn = f.rowid " ;
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . " societe as s " ;
$sql .= " ON f.fk_soc = s.rowid " ;
$sql .= " WHERE p.rowid = pf.fk_paiementfourn " ;
if ( ! empty ( $date_start ) && ! empty ( $date_end ))
$sql .= " AND p.datep >= ' " . $db -> idate ( $date_start ) . " ' AND p.datep <= ' " . $db -> idate ( $date_end ) . " ' " ;
}
2011-05-28 14:19:49 +02:00
2017-08-31 18:29:57 +02:00
$sql .= " AND f.entity = " . $conf -> entity ;
if ( $socid ) $sql .= " AND f.fk_soc = " . $socid ;
$sql .= " GROUP BY name, socid " ;
$sql .= $db -> order ( $sortfield , $sortorder );
2011-05-28 14:19:49 +02:00
2017-10-14 01:03:59 +02:00
print '<tr class="trforbreak"><td colspan="4">' . $langs -> trans ( " SuppliersInvoices " ) . '</td></tr>' ;
2012-08-03 20:09:37 +02:00
2017-08-31 18:29:57 +02:00
$subtotal_ht = 0 ;
$subtotal_ttc = 0 ;
dol_syslog ( " get suppliers invoices " , LOG_DEBUG );
$result = $db -> query ( $sql );
if ( $result ) {
$num = $db -> num_rows ( $result );
$i = 0 ;
if ( $num > 0 )
{
while ( $i < $num )
{
$objp = $db -> fetch_object ( $result );
2011-05-28 14:19:49 +02:00
2017-08-31 18:29:57 +02:00
print '<tr class="oddeven"><td> </td>' ;
print " <td> " . $langs -> trans ( " Bills " ) . " <a href= \" " . DOL_URL_ROOT . " /fourn/facture/list.php?socid= " . $objp -> socid . " \" > " . $objp -> name . " </a></td> \n " ;
2005-05-11 03:23:52 +02:00
2017-08-31 18:29:57 +02:00
if ( $modecompta == 'CREANCES-DETTES' )
print " <td align= \" right \" > " . price ( - $objp -> amount_ht ) . " </td> \n " ;
print " <td align= \" right \" > " . price ( - $objp -> amount_ttc ) . " </td> \n " ;
2005-05-11 03:23:52 +02:00
2017-08-31 18:29:57 +02:00
$total_ht -= ( isset ( $objp -> amount_ht ) ? $objp -> amount_ht : 0 );
$total_ttc -= $objp -> amount_ttc ;
$subtotal_ht += ( isset ( $objp -> amount_ht ) ? $objp -> amount_ht : 0 );
$subtotal_ttc += $objp -> amount_ttc ;
2009-02-11 22:15:47 +01:00
2017-08-31 18:29:57 +02:00
print " </tr> \n " ;
$i ++ ;
}
}
else
{
print '<tr class="oddeven"><td> </td>' ;
print '<td colspan="3" class="opacitymedium">' . $langs -> trans ( " None " ) . '</td>' ;
print '</tr>' ;
}
2009-02-11 22:15:47 +01:00
2017-08-31 18:29:57 +02:00
$db -> free ( $result );
2015-07-30 15:07:22 +02:00
} else {
2017-08-31 18:29:57 +02:00
dol_print_error ( $db );
2015-07-30 15:07:22 +02:00
}
2017-08-31 18:29:57 +02:00
print '<tr class="liste_total">' ;
if ( $modecompta == 'CREANCES-DETTES' )
print '<td colspan="3" align="right">' . price ( - $subtotal_ht ) . '</td>' ;
print '<td colspan="3" align="right">' . price ( - $subtotal_ttc ) . '</td>' ;
print '</tr>' ;
2009-02-11 22:15:47 +01:00
2017-08-31 18:29:57 +02:00
/*
* Charges sociales non deductibles
*/
2009-02-11 22:15:47 +01:00
2017-10-14 01:03:59 +02:00
print '<tr class="trforbreak"><td colspan="4">' . $langs -> trans ( " SocialContributionsNondeductibles " ) . '</td></tr>' ;
2009-02-11 22:15:47 +01:00
2017-08-31 18:29:57 +02:00
if ( $modecompta == 'CREANCES-DETTES' )
{
$sql = " SELECT c.id, c.libelle as label, sum(cs.amount) as amount " ;
$sql .= " FROM " . MAIN_DB_PREFIX . " c_chargesociales as c " ;
$sql .= " , " . MAIN_DB_PREFIX . " chargesociales as cs " ;
$sql .= " WHERE cs.fk_type = c.id " ;
$sql .= " AND c.deductible = 0 " ;
if ( ! empty ( $date_start ) && ! empty ( $date_end ))
$sql .= " AND cs.date_ech >= ' " . $db -> idate ( $date_start ) . " ' AND cs.date_ech <= ' " . $db -> idate ( $date_end ) . " ' " ;
}
elseif ( $modecompta == 'RECETTES-DEPENSES' )
{
$sql = " SELECT c.id, c.libelle as label, sum(p.amount) as amount " ;
$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 " ;
$sql .= " AND c.deductible = 0 " ;
if ( ! empty ( $date_start ) && ! empty ( $date_end ))
$sql .= " AND p.datep >= ' " . $db -> idate ( $date_start ) . " ' AND p.datep <= ' " . $db -> idate ( $date_end ) . " ' " ;
}
$sql .= " AND cs.entity = " . $conf -> entity ;
$sql .= " GROUP BY c.libelle, c.id " ;
2016-11-28 18:38:48 +01:00
$newsortfield = $sortfield ;
2017-08-31 18:29:57 +02:00
if ( $newsortfield == 's.nom, s.rowid' ) $newsortfield = 'c.libelle, c.id' ;
if ( $newsortfield == 'amount_ht' ) $newsortfield = 'amount' ;
if ( $newsortfield == 'amount_ttc' ) $newsortfield = 'amount' ;
2009-02-11 22:15:47 +01:00
2016-11-28 18:38:48 +01:00
$sql .= $db -> order ( $newsortfield , $sortorder );
2009-02-11 22:15:47 +01:00
2017-08-31 18:29:57 +02:00
dol_syslog ( " get social contributions deductible=0 " , LOG_DEBUG );
2014-10-03 12:15:21 +02:00
$result = $db -> query ( $sql );
$subtotal_ht = 0 ;
$subtotal_ttc = 0 ;
2017-08-31 18:29:57 +02:00
if ( $result ) {
$num = $db -> num_rows ( $result );
2014-10-03 12:15:21 +02:00
$i = 0 ;
2017-08-31 18:29:57 +02:00
if ( $num ) {
while ( $i < $num ) {
2014-10-03 12:15:21 +02:00
$obj = $db -> fetch_object ( $result );
2014-09-16 21:19:07 +02:00
2014-10-03 12:15:21 +02:00
$total_ht -= $obj -> amount ;
$total_ttc -= $obj -> amount ;
$subtotal_ht += $obj -> amount ;
$subtotal_ttc += $obj -> amount ;
2014-09-16 21:05:57 +02:00
2017-05-16 12:43:16 +02:00
print '<tr class="oddeven"><td> </td>' ;
2017-08-31 18:29:57 +02:00
print '<td>' . $obj -> label . '</td>' ;
2014-10-03 12:15:21 +02:00
if ( $modecompta == 'CREANCES-DETTES' ) print '<td align="right">' . price ( - $obj -> amount ) . '</td>' ;
print '<td align="right">' . price ( - $obj -> amount ) . '</td>' ;
print '</tr>' ;
$i ++ ;
}
}
2017-08-31 18:29:57 +02:00
else {
2017-05-16 12:43:16 +02:00
print '<tr class="oddeven"><td> </td>' ;
2016-06-07 15:58:02 +02:00
print '<td colspan="3" class="opacitymedium">' . $langs -> trans ( " None " ) . '</td>' ;
2014-10-03 12:15:21 +02:00
print '</tr>' ;
}
2015-07-30 15:07:22 +02:00
} else {
2014-10-03 12:15:21 +02:00
dol_print_error ( $db );
2015-07-30 15:07:22 +02:00
}
2014-10-03 12:15:21 +02:00
print '<tr class="liste_total">' ;
if ( $modecompta == 'CREANCES-DETTES' )
print '<td colspan="3" align="right">' . price ( - $subtotal_ht ) . '</td>' ;
print '<td colspan="3" align="right">' . price ( - $subtotal_ttc ) . '</td>' ;
print '</tr>' ;
2015-07-30 15:07:22 +02:00
2016-10-29 06:06:44 +02:00
2017-08-31 18:29:57 +02:00
/*
* Charges sociales deductibles
*/
2016-01-28 14:26:52 +01:00
2017-10-14 01:03:59 +02:00
print '<tr class="trforbreak"><td colspan="4">' . $langs -> trans ( " SocialContributionsDeductibles " ) . '</td></tr>' ;
2016-10-29 06:06:44 +02:00
2017-08-31 18:29:57 +02:00
if ( $modecompta == 'CREANCES-DETTES' )
2016-11-28 18:38:48 +01:00
{
2017-08-31 18:29:57 +02:00
$sql = " SELECT c.id, c.libelle as label, sum(cs.amount) as amount " ;
$sql .= " FROM " . MAIN_DB_PREFIX . " c_chargesociales as c " ;
$sql .= " , " . MAIN_DB_PREFIX . " chargesociales as cs " ;
$sql .= " WHERE cs.fk_type = c.id " ;
$sql .= " AND c.deductible = 1 " ;
if ( ! empty ( $date_start ) && ! empty ( $date_end ))
$sql .= " AND cs.date_ech >= ' " . $db -> idate ( $date_start ) . " ' AND cs.date_ech <= ' " . $db -> idate ( $date_end ) . " ' " ;
$sql .= " AND cs.entity = " . $conf -> entity ;
2016-11-28 18:38:48 +01:00
}
2017-08-31 18:29:57 +02:00
elseif ( $modecompta == 'RECETTES-DEPENSES' )
{
$sql = " SELECT c.id, c.libelle as label, sum(p.amount) as amount " ;
$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 " ;
$sql .= " AND c.deductible = 1 " ;
if ( ! empty ( $date_start ) && ! empty ( $date_end ))
$sql .= " AND p.datep >= ' " . $db -> idate ( $date_start ) . " ' AND p.datep <= ' " . $db -> idate ( $date_end ) . " ' " ;
$sql .= " AND cs.entity = " . $conf -> entity ;
}
$sql .= " GROUP BY c.libelle, c.id " ;
2016-11-28 18:38:48 +01:00
$newsortfield = $sortfield ;
2017-08-31 18:29:57 +02:00
if ( $newsortfield == 's.nom, s.rowid' ) $newsortfield = 'c.libelle, c.id' ;
if ( $newsortfield == 'amount_ht' ) $newsortfield = 'amount' ;
if ( $newsortfield == 'amount_ttc' ) $newsortfield = 'amount' ;
2016-11-28 18:38:48 +01:00
$sql .= $db -> order ( $newsortfield , $sortorder );
2017-06-09 09:25:15 +02:00
2017-08-31 18:29:57 +02:00
dol_syslog ( " get social contributions deductible=1 " , LOG_DEBUG );
2014-10-03 12:15:21 +02:00
$result = $db -> query ( $sql );
$subtotal_ht = 0 ;
$subtotal_ttc = 0 ;
2017-08-31 18:29:57 +02:00
if ( $result ) {
2014-10-03 12:15:21 +02:00
$num = $db -> num_rows ( $result );
$i = 0 ;
2017-08-31 18:29:57 +02:00
if ( $num ) {
while ( $i < $num ) {
2014-10-03 12:15:21 +02:00
$obj = $db -> fetch_object ( $result );
$total_ht -= $obj -> amount ;
$total_ttc -= $obj -> amount ;
$subtotal_ht += $obj -> amount ;
$subtotal_ttc += $obj -> amount ;
2017-05-16 12:43:16 +02:00
print '<tr class="oddeven"><td> </td>' ;
2017-08-31 18:29:57 +02:00
print '<td>' . $obj -> label . '</td>' ;
if ( $modecompta == 'CREANCES-DETTES' )
print '<td align="right">' . price ( - $obj -> amount ) . '</td>' ;
2014-10-03 12:15:21 +02:00
print '<td align="right">' . price ( - $obj -> amount ) . '</td>' ;
print '</tr>' ;
$i ++ ;
}
}
2017-08-31 18:29:57 +02:00
else {
2017-05-16 12:43:16 +02:00
print '<tr class="oddeven"><td> </td>' ;
2016-06-07 15:58:02 +02:00
print '<td colspan="3" class="opacitymedium">' . $langs -> trans ( " None " ) . '</td>' ;
2014-10-03 12:15:21 +02:00
print '</tr>' ;
}
2017-08-31 18:29:57 +02:00
} else {
2014-10-03 12:15:21 +02:00
dol_print_error ( $db );
}
print '<tr class="liste_total">' ;
if ( $modecompta == 'CREANCES-DETTES' )
print '<td colspan="3" align="right">' . price ( - $subtotal_ht ) . '</td>' ;
print '<td colspan="3" align="right">' . price ( - $subtotal_ttc ) . '</td>' ;
print '</tr>' ;
2017-08-31 18:29:57 +02:00
if ( $mysoc -> tva_assuj == 'franchise' ) // Non assujetti
2016-11-28 18:38:48 +01:00
{
2017-08-31 18:29:57 +02:00
// Total
print '<tr>' ;
print '<td colspan="4"> </td>' ;
print '</tr>' ;
print '<tr class="liste_total"><td align="left" colspan="2">' . $langs -> trans ( " Profit " ) . '</td>' ;
if ( $modecompta == 'CREANCES-DETTES' )
print '<td class="border" align="right">' . price ( $total_ht ) . '</td>' ;
print '<td align="right">' . price ( $total_ttc ) . '</td>' ;
print '</tr>' ;
print '<tr>' ;
print '<td colspan="4"> </td>' ;
print '</tr>' ;
2016-01-28 14:26:52 +01:00
}
2016-10-29 06:06:44 +02:00
2017-08-31 18:29:57 +02:00
/*
* Salaries
*/
2016-11-28 18:38:48 +01:00
2017-08-31 18:29:57 +02:00
if ( ! empty ( $conf -> salaries -> enabled ))
2016-11-28 18:38:48 +01:00
{
2017-10-14 01:03:59 +02:00
print '<tr class="trforbreak"><td colspan="4">' . $langs -> trans ( " Salaries " ) . '</td></tr>' ;
2017-08-31 18:29:57 +02:00
if ( $modecompta == 'CREANCES-DETTES' || $modecompta == 'RECETTES-DEPENSES' )
{
if ( $modecompta == 'CREANCES-DETTES' ) {
$column = 'p.datev' ;
} else {
$column = 'p.datep' ;
2016-01-28 14:26:52 +01:00
}
2017-08-31 18:29:57 +02:00
$sql = " SELECT u.rowid, u.firstname, u.lastname, p.fk_user, p.label as label, 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 . " user as u ON u.rowid=p.fk_user " ;
2018-02-06 10:57:53 +01:00
$sql .= " WHERE p.entity IN ( " . getEntity ( 'payment_salary' ) . " ) " ;
2017-08-31 18:29:57 +02:00
if ( ! empty ( $date_start ) && ! empty ( $date_end ))
$sql .= " AND $column >= ' " . $db -> idate ( $date_start ) . " ' AND $column <= ' " . $db -> idate ( $date_end ) . " ' " ;
$sql .= " GROUP BY u.rowid, u.firstname, u.lastname, p.fk_user, p.label, dm " ;
$newsortfield = $sortfield ;
if ( $newsortfield == 's.nom, s.rowid' ) $newsortfield = 'u.firstname, u.lastname' ;
if ( $newsortfield == 'amount_ht' ) $newsortfield = 'amount' ;
if ( $newsortfield == 'amount_ttc' ) $newsortfield = 'amount' ;
$sql .= $db -> order ( $newsortfield , $sortorder );
}
dol_syslog ( " get payment salaries " );
$result = $db -> query ( $sql );
$subtotal_ht = 0 ;
$subtotal_ttc = 0 ;
if ( $result )
{
$num = $db -> num_rows ( $result );
$i = 0 ;
if ( $num )
{
while ( $i < $num )
{
$obj = $db -> fetch_object ( $result );
$total_ht -= $obj -> amount ;
$total_ttc -= $obj -> amount ;
$subtotal_ht += $obj -> amount ;
$subtotal_ttc += $obj -> amount ;
print '<tr class="oddeven"><td> </td>' ;
2018-11-08 10:04:25 +01:00
print " <td> " . $langs -> trans ( " Salary " ) . " <a href= \" " . DOL_URL_ROOT . " /compta/salaries/list.php?filtre=s.fk_user= " . $obj -> fk_user . " \" > " . $obj -> firstname . " " . $obj -> lastname . " </a></td> \n " ;
2017-08-31 18:29:57 +02:00
if ( $modecompta == 'CREANCES-DETTES' ) print '<td align="right">' . price ( - $obj -> amount ) . '</td>' ;
print '<td align="right">' . price ( - $obj -> amount ) . '</td>' ;
print '</tr>' ;
$i ++ ;
}
}
else
{
print '<tr class="oddeven"><td> </td>' ;
print '<td colspan="3" class="opacitymedium">' . $langs -> trans ( " None " ) . '</td>' ;
print '</tr>' ;
}
2016-01-28 14:26:52 +01:00
}
else
{
2017-08-31 18:29:57 +02:00
dol_print_error ( $db );
2016-11-28 18:38:48 +01:00
}
2017-08-31 18:29:57 +02:00
print '<tr class="liste_total">' ;
if ( $modecompta == 'CREANCES-DETTES' )
print '<td colspan="3" align="right">' . price ( - $subtotal_ht ) . '</td>' ;
2016-11-28 18:38:48 +01:00
print '<td colspan="3" align="right">' . price ( - $subtotal_ttc ) . '</td>' ;
print '</tr>' ;
}
2017-06-09 09:25:15 +02:00
2016-01-28 14:26:52 +01:00
2017-08-31 18:29:57 +02:00
/*
* Expense
*/
if ( ! empty ( $conf -> expensereport -> enabled ))
2016-11-28 18:38:48 +01:00
{
2017-08-31 18:29:57 +02:00
if ( $modecompta == 'CREANCES-DETTES' || $modecompta == 'RECETTES-DEPENSES' )
2016-01-28 14:26:52 +01:00
{
2017-08-31 18:29:57 +02:00
$langs -> load ( 'trips' );
if ( $modecompta == 'CREANCES-DETTES' ) {
$sql = " SELECT p.rowid, p.ref, u.rowid as userid, u.firstname, u.lastname, date_format(date_valid,'%Y-%m') as dm, sum(p.total_ht) as amount_ht,sum(p.total_ttc) as amount_ttc " ;
$sql .= " FROM " . MAIN_DB_PREFIX . " expensereport as p " ;
$sql .= " INNER JOIN " . MAIN_DB_PREFIX . " user as u ON u.rowid=p.fk_user_author " ;
2018-02-06 10:57:53 +01:00
$sql .= " WHERE p.entity IN ( " . getEntity ( 'expensereport' ) . " ) " ;
2017-08-31 18:29:57 +02:00
$sql .= " AND p.fk_statut>=5 " ;
$column = 'p.date_valid' ;
} else {
$sql = " SELECT p.rowid, p.ref, u.rowid as userid, u.firstname, u.lastname, date_format(pe.datep,'%Y-%m') as dm, sum(p.total_ht) as amount_ht, sum(p.total_ttc) as amount_ttc " ;
$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 " ;
2018-03-07 17:32:57 +01:00
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . " c_paiement as c ON pe.fk_typepayment = c.id " ;
2018-02-06 10:57:53 +01:00
$sql .= " WHERE p.entity IN ( " . getEntity ( 'expensereport' ) . " ) " ;
2017-08-31 18:29:57 +02:00
$sql .= " AND p.fk_statut>=5 " ;
$column = 'pe.datep' ;
}
if ( ! empty ( $date_start ) && ! empty ( $date_end ))
2016-01-28 14:26:52 +01:00
{
2017-08-31 18:29:57 +02:00
$sql .= " AND $column >= ' " . $db -> idate ( $date_start ) . " ' AND $column <= ' " . $db -> idate ( $date_end ) . " ' " ;
}
2016-11-28 18:38:48 +01:00
2017-08-31 18:29:57 +02:00
$sql .= " GROUP BY u.rowid, p.rowid, p.ref, u.firstname, u.lastname, dm " ;
$newsortfield = $sortfield ;
if ( $newsortfield == 's.nom, s.rowid' ) $newsortfield = 'p.ref' ;
$sql .= $db -> order ( $newsortfield , $sortorder );
}
2016-11-28 18:38:48 +01:00
2017-10-14 01:03:59 +02:00
print '<tr class="trforbreak"><td colspan="4">' . $langs -> trans ( " ExpenseReport " ) . '</td></tr>' ;
2016-11-28 18:38:48 +01:00
2017-08-31 18:29:57 +02:00
dol_syslog ( " get expense report outcome " );
$result = $db -> query ( $sql );
$subtotal_ht = 0 ;
$subtotal_ttc = 0 ;
if ( $result )
{
$num = $db -> num_rows ( $result );
if ( $num )
{
while ( $obj = $db -> fetch_object ( $result ))
{
$total_ht -= $obj -> amount_ht ;
$total_ttc -= $obj -> amount_ttc ;
$subtotal_ht += $obj -> amount_ht ;
$subtotal_ttc += $obj -> amount_ttc ;
2014-09-16 21:05:57 +02:00
2017-08-31 18:29:57 +02:00
print '<tr class="oddeven"><td> </td>' ;
2014-09-16 21:05:57 +02:00
2017-08-31 18:29:57 +02:00
print " <td> " . $langs -> trans ( " ExpenseReport " ) . " <a href= \" " . DOL_URL_ROOT . " /expensereport/list.php?search_user= " . $obj -> userid . " \" > " . $obj -> firstname . " " . $obj -> lastname . " </a></td> \n " ;
if ( $modecompta == 'CREANCES-DETTES' ) print '<td align="right">' . price ( - $obj -> amount_ht ) . '</td>' ;
print '<td align="right">' . price ( - $obj -> amount_ttc ) . '</td>' ;
print '</tr>' ;
}
}
else
{
print '<tr class="oddeven"><td> </td>' ;
print '<td colspan="3" class="opacitymedium">' . $langs -> trans ( " None " ) . '</td>' ;
2016-01-28 14:26:52 +01:00
print '</tr>' ;
}
}
else
{
2017-08-31 18:29:57 +02:00
dol_print_error ( $db );
2016-11-28 18:38:48 +01:00
}
2017-08-31 18:29:57 +02:00
print '<tr class="liste_total">' ;
if ( $modecompta == 'CREANCES-DETTES' ) print '<td colspan="3" align="right">' . price ( - $subtotal_ht ) . '</td>' ;
2016-11-28 18:38:48 +01:00
print '<td colspan="3" align="right">' . price ( - $subtotal_ttc ) . '</td>' ;
print '</tr>' ;
2014-09-16 21:05:57 +02:00
}
2014-09-16 21:09:53 +02:00
2017-08-31 18:29:57 +02:00
/*
* Donations
*/
2014-10-03 12:15:21 +02:00
2017-08-31 18:29:57 +02:00
if ( ! empty ( $conf -> don -> enabled ))
2016-10-04 13:45:22 +02:00
{
2017-10-14 01:03:59 +02:00
print '<tr class="trforbreak"><td colspan="4">' . $langs -> trans ( " Donations " ) . '</td></tr>' ;
2009-02-11 22:15:47 +01:00
2017-08-31 18:29:57 +02:00
if ( $modecompta == 'CREANCES-DETTES' || $modecompta == 'RECETTES-DEPENSES' )
2014-09-16 21:05:57 +02:00
{
2017-08-31 18:29:57 +02:00
if ( $modecompta == 'CREANCES-DETTES' )
{
$sql = " SELECT p.societe as name, 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 " ;
2018-02-06 10:57:53 +01:00
$sql .= " WHERE p.entity IN ( " . getEntity ( 'donation' ) . " ) " ;
2017-08-31 18:29:57 +02:00
$sql .= " AND fk_statut in (1,2) " ;
}
else
{
$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 .= " INNER JOIN " . MAIN_DB_PREFIX . " payment_donation as pe ON pe.fk_donation = p.rowid " ;
2018-03-07 17:32:57 +01:00
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . " c_paiement as c ON pe.fk_typepayment = c.id " ;
2017-11-12 12:39:23 +01:00
$sql .= " WHERE p.entity IN ( " . getEntity ( 'donation' ) . " ) " ;
2017-08-31 18:29:57 +02:00
$sql .= " AND fk_statut >= 2 " ;
}
if ( ! empty ( $date_start ) && ! empty ( $date_end ))
$sql .= " AND p.datedon >= ' " . $db -> idate ( $date_start ) . " ' AND p.datedon <= ' " . $db -> idate ( $date_end ) . " ' " ;
}
$sql .= " GROUP BY p.societe, p.firstname, p.lastname, dm " ;
$newsortfield = $sortfield ;
if ( $newsortfield == 's.nom, s.rowid' ) $newsortfield = 'p.societe, p.firstname, p.lastname, dm' ;
if ( $newsortfield == 'amount_ht' ) $newsortfield = 'amount' ;
if ( $newsortfield == 'amount_ttc' ) $newsortfield = 'amount' ;
$sql .= $db -> order ( $newsortfield , $sortorder );
dol_syslog ( " get dunning " );
$result = $db -> query ( $sql );
$subtotal_ht = 0 ;
$subtotal_ttc = 0 ;
if ( $result )
{
$num = $db -> num_rows ( $result );
$i = 0 ;
if ( $num )
2014-10-03 12:15:21 +02:00
{
2017-08-31 18:29:57 +02:00
while ( $i < $num )
{
$obj = $db -> fetch_object ( $result );
2014-09-16 21:05:57 +02:00
2017-08-31 18:29:57 +02:00
$total_ht += $obj -> amount ;
$total_ttc += $obj -> amount ;
$subtotal_ht += $obj -> amount ;
$subtotal_ttc += $obj -> amount ;
2014-09-16 21:05:57 +02:00
2017-08-31 18:29:57 +02:00
print '<tr class="oddeven"><td> </td>' ;
2014-09-16 21:05:57 +02:00
2017-08-31 18:29:57 +02:00
print " <td> " . $langs -> trans ( " Donation " ) . " <a href= \" " . DOL_URL_ROOT . " /don/list.php?search_company= " . $obj -> name . " &search_name= " . $obj -> firstname . " " . $obj -> lastname . " \" > " . $obj -> name . " " . $obj -> firstname . " " . $obj -> lastname . " </a></td> \n " ;
2014-09-16 21:05:57 +02:00
2017-08-31 18:29:57 +02:00
if ( $modecompta == 'CREANCES-DETTES' ) print '<td align="right">' . price ( $obj -> amount ) . '</td>' ;
print '<td align="right">' . price ( $obj -> amount ) . '</td>' ;
print '</tr>' ;
$i ++ ;
}
}
else
{
print '<tr class="oddeven"><td> </td>' ;
print '<td colspan="3" class="opacitymedium">' . $langs -> trans ( " None " ) . '</td>' ;
2014-10-03 12:15:21 +02:00
print '</tr>' ;
}
}
else
{
2017-08-31 18:29:57 +02:00
dol_print_error ( $db );
2014-09-16 21:05:57 +02:00
}
2017-08-31 18:29:57 +02:00
print '<tr class="liste_total">' ;
if ( $modecompta == 'CREANCES-DETTES' )
print '<td colspan="3" align="right">' . price ( $subtotal_ht ) . '</td>' ;
print '<td colspan="3" align="right">' . price ( $subtotal_ttc ) . '</td>' ;
print '</tr>' ;
2014-09-16 21:05:57 +02:00
}
2009-02-11 22:15:47 +01:00
2011-05-28 14:19:49 +02:00
2017-08-31 18:29:57 +02:00
/*
* VAT
*/
2011-05-28 14:19:49 +02:00
2017-10-14 01:03:59 +02:00
print '<tr class="trforbreak"><td colspan="4">' . $langs -> trans ( " VAT " ) . '</td></tr>' ;
2017-08-31 18:29:57 +02:00
$subtotal_ht = 0 ;
$subtotal_ttc = 0 ;
2004-04-10 21:04:14 +02:00
2017-08-31 18:29:57 +02:00
if ( $conf -> tax -> enabled && ( $modecompta == 'CREANCES-DETTES' || $modecompta == 'RECETTES-DEPENSES' ))
{
if ( $modecompta == 'CREANCES-DETTES' )
{
// TVA a payer
$amount = 0 ;
$sql = " SELECT date_format(f.datef,'%Y-%m') as dm, sum(f.tva) as amount " ;
$sql .= " FROM " . MAIN_DB_PREFIX . " facture as f " ;
$sql .= " WHERE f.fk_statut IN (1,2) " ;
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 ))
$sql .= " AND f.datef >= ' " . $db -> idate ( $date_start ) . " ' AND f.datef <= ' " . $db -> idate ( $date_end ) . " ' " ;
$sql .= " AND f.entity = " . $conf -> entity ;
$sql .= " GROUP BY dm " ;
$newsortfield = $sortfield ;
if ( $newsortfield == 's.nom, s.rowid' ) $newsortfield = 'dm' ;
if ( $newsortfield == 'amount_ht' ) $newsortfield = 'amount' ;
if ( $newsortfield == 'amount_ttc' ) $newsortfield = 'amount' ;
$sql .= $db -> order ( $newsortfield , $sortorder );
dol_syslog ( " get vat to pay " , LOG_DEBUG );
$result = $db -> query ( $sql );
if ( $result )
{
$num = $db -> num_rows ( $result );
$i = 0 ;
if ( $num )
{
while ( $i < $num )
{
$obj = $db -> fetch_object ( $result );
$amount -= $obj -> amount ;
//$total_ht -= $obj->amount;
$total_ttc -= $obj -> amount ;
//$subtotal_ht -= $obj->amount;
$subtotal_ttc -= $obj -> amount ;
$i ++ ;
}
}
} else {
dol_print_error ( $db );
}
print '<tr class="oddeven"><td> </td>' ;
print " <td> " . $langs -> trans ( " VATToPay " ) . " </td> \n " ;
print " <td align= \" right \" > </td> \n " ;
print " <td align= \" right \" > " . price ( $amount ) . " </td> \n " ;
print " </tr> \n " ;
// TVA a recuperer
$amount = 0 ;
$sql = " SELECT date_format(f.datef,'%Y-%m') as dm, sum(f.total_tva) as amount " ;
$sql .= " FROM " . MAIN_DB_PREFIX . " facture_fourn as f " ;
$sql .= " WHERE f.fk_statut IN (1,2) " ;
if ( ! empty ( $conf -> global -> FACTURE_DEPOSITS_ARE_JUST_PAYMENTS ))
$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 ))
$sql .= " AND f.datef >= ' " . $db -> idate ( $date_start ) . " ' AND f.datef <= ' " . $db -> idate ( $date_end ) . " ' " ;
$sql .= " AND f.entity = " . $conf -> entity ;
$sql .= " GROUP BY dm " ;
$newsortfield = $sortfield ;
if ( $newsortfield == 's.nom, s.rowid' ) $newsortfield = 'dm' ;
if ( $newsortfield == 'amount_ht' ) $newsortfield = 'amount' ;
if ( $newsortfield == 'amount_ttc' ) $newsortfield = 'amount' ;
$sql .= $db -> order ( $newsortfield , $sortorder );
dol_syslog ( " get vat received back " , LOG_DEBUG );
$result = $db -> query ( $sql );
if ( $result )
{
$num = $db -> num_rows ( $result );
$i = 0 ;
if ( $num )
{
while ( $i < $num )
{
$obj = $db -> fetch_object ( $result );
$amount += $obj -> amount ;
//$total_ht += $obj->amount;
$total_ttc += $obj -> amount ;
//$subtotal_ht += $obj->amount;
$subtotal_ttc += $obj -> amount ;
$i ++ ;
}
}
} else {
dol_print_error ( $db );
}
print '<tr class="oddeven"><td> </td>' ;
print " <td> " . $langs -> trans ( " VATToCollect " ) . " </td> \n " ;
print " <td align= \" right \" > </td> \n " ;
print " <td align= \" right \" > " . price ( $amount ) . " </td> \n " ;
print " </tr> \n " ;
}
else
{
// VAT really already paid
$amount = 0 ;
$sql = " SELECT date_format(t.datev,'%Y-%m') as dm, sum(t.amount) as amount " ;
$sql .= " FROM " . MAIN_DB_PREFIX . " tva as t " ;
$sql .= " WHERE amount > 0 " ;
if ( ! empty ( $date_start ) && ! empty ( $date_end ))
$sql .= " AND t.datev >= ' " . $db -> idate ( $date_start ) . " ' AND t.datev <= ' " . $db -> idate ( $date_end ) . " ' " ;
$sql .= " AND t.entity = " . $conf -> entity ;
$sql .= " GROUP BY dm " ;
$newsortfield = $sortfield ;
if ( $newsortfield == 's.nom, s.rowid' ) $newsortfield = 'dm' ;
if ( $newsortfield == 'amount_ht' ) $newsortfield = 'amount' ;
if ( $newsortfield == 'amount_ttc' ) $newsortfield = 'amount' ;
$sql .= $db -> order ( $newsortfield , $sortorder );
dol_syslog ( " get vat really paid " , LOG_DEBUG );
$result = $db -> query ( $sql );
if ( $result ) {
$num = $db -> num_rows ( $result );
$i = 0 ;
if ( $num ) {
while ( $i < $num ) {
$obj = $db -> fetch_object ( $result );
$amount -= $obj -> amount ;
$total_ht -= $obj -> amount ;
$total_ttc -= $obj -> amount ;
$subtotal_ht -= $obj -> amount ;
$subtotal_ttc -= $obj -> amount ;
$i ++ ;
}
}
$db -> free ( $result );
} else {
dol_print_error ( $db );
}
print '<tr class="oddeven"><td> </td>' ;
print " <td> " . $langs -> trans ( " VATPaid " ) . " </td> \n " ;
if ( $modecompta == 'CREANCES-DETTES' )
print " <td align= \" right \" > " . price ( $amount ) . " </td> \n " ;
print " <td align= \" right \" > " . price ( $amount ) . " </td> \n " ;
print " </tr> \n " ;
// VAT really received
$amount = 0 ;
$sql = " SELECT date_format(t.datev,'%Y-%m') as dm, sum(t.amount) as amount " ;
$sql .= " FROM " . MAIN_DB_PREFIX . " tva as t " ;
$sql .= " WHERE amount < 0 " ;
if ( ! empty ( $date_start ) && ! empty ( $date_end ))
$sql .= " AND t.datev >= ' " . $db -> idate ( $date_start ) . " ' AND t.datev <= ' " . $db -> idate ( $date_end ) . " ' " ;
$sql .= " AND t.entity = " . $conf -> entity ;
$sql .= " GROUP BY dm " ;
$newsortfield = $sortfield ;
if ( $newsortfield == 's.nom, s.rowid' ) $newsortfield = 'dm' ;
if ( $newsortfield == 'amount_ht' ) $newsortfield = 'amount' ;
if ( $newsortfield == 'amount_ttc' ) $newsortfield = 'amount' ;
$sql .= $db -> order ( $newsortfield , $sortorder );
dol_syslog ( " get vat really received back " , LOG_DEBUG );
$result = $db -> query ( $sql );
if ( $result ) {
$num = $db -> num_rows ( $result );
$i = 0 ;
if ( $num ) {
while ( $i < $num ) {
$obj = $db -> fetch_object ( $result );
$amount += $obj -> amount ;
$total_ht += $obj -> amount ;
$total_ttc += $obj -> amount ;
$subtotal_ht += $obj -> amount ;
$subtotal_ttc += $obj -> amount ;
$i ++ ;
}
}
$db -> free ( $result );
}
else
{
dol_print_error ( $db );
}
print '<tr class="oddeven"><td> </td>' ;
print " <td> " . $langs -> trans ( " VATCollected " ) . " </td> \n " ;
if ( $modecompta == 'CREANCES-DETTES' )
print " <td align= \" right \" > " . price ( $amount ) . " </td> \n " ;
print " <td align= \" right \" > " . price ( $amount ) . " </td> \n " ;
print " </tr> \n " ;
}
}
2004-03-04 22:26:03 +01:00
2017-08-31 18:29:57 +02:00
if ( $mysoc -> tva_assuj != 'franchise' ) // Assujetti
{
print '<tr class="liste_total">' ;
if ( $modecompta == 'CREANCES-DETTES' )
print '<td colspan="3" align="right"> </td>' ;
print '<td colspan="3" align="right">' . price ( price2num ( $subtotal_ttc , 'MT' )) . '</td>' ;
print '</tr>' ;
}
2004-03-04 22:26:03 +01:00
}
2005-01-17 21:26:12 +01:00
2014-03-28 18:31:43 +01:00
$action = " balanceclient " ;
$object = array ( & $total_ht , & $total_ttc );
$parameters [ " mode " ] = $modecompta ;
$parameters [ " date_start " ] = $date_start ;
$parameters [ " date_end " ] = $date_end ;
$parameters [ " bc " ] = $bc ;
// Initialize technical object to manage hooks of expenses. Note that conf->hooks_modules contains array array
$hookmanager -> initHooks ( array ( 'externalbalance' ));
2016-03-25 16:23:09 +01:00
$reshook = $hookmanager -> executeHooks ( 'addBalanceLine' , $parameters , $object , $action ); // Note that $action and $object may have been modified by some hooks
2014-03-28 18:31:43 +01:00
print $hookmanager -> resPrint ;
2004-03-04 22:26:03 +01:00
2016-10-29 06:06:44 +02:00
if ( $mysoc -> tva_assuj != 'franchise' ) // Assujetti
2009-02-11 22:15:47 +01:00
{
2011-05-28 14:19:49 +02:00
// Total
print '<tr>' ;
print '<td colspan="4"> </td>' ;
print '</tr>' ;
2016-11-11 14:19:21 +01:00
print '<tr class="liste_total"><td align="left" colspan="2">' . $langs -> trans ( " Profit " ) . '</td>' ;
2012-08-03 20:09:37 +02:00
if ( $modecompta == 'CREANCES-DETTES' )
print '<td class="liste_total" align="right">' . price ( price2num ( $total_ht , 'MT' )) . '</td>' ;
2011-10-19 13:04:03 +02:00
print '<td class="liste_total" align="right">' . price ( price2num ( $total_ttc , 'MT' )) . '</td>' ;
2011-05-28 14:19:49 +02:00
print '</tr>' ;
2009-02-11 22:15:47 +01:00
}
2004-03-04 22:26:03 +01:00
print " </table> " ;
2005-04-08 01:39:47 +02:00
print '<br>' ;
2004-03-04 22:26:03 +01:00
2018-08-08 12:29:36 +02:00
// End of page
2011-10-19 13:04:03 +02:00
llxFooter ();
2004-03-04 22:26:03 +01:00
$db -> close ();