index.php 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979
  1. <?php
  2. /* Copyright (C) 2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2012 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@capnetworks.com>
  5. * Copyright (C) 2014-2016 Ferran Marcet <fmarcet@2byte.es>
  6. * Copyright (C) 2014 Juanjo Menent <jmenent@2byte.es>
  7. * Copyright (C) 2014 Florian Henry <florian.henry@open-concept.pro>
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 3 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  21. */
  22. /**
  23. * \file htdocs/compta/resultat/index.php
  24. * \ingroup compta, accountancy
  25. * \brief Page reporting result
  26. */
  27. require '../../main.inc.php';
  28. require_once DOL_DOCUMENT_ROOT.'/core/lib/report.lib.php';
  29. require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
  30. $langs->loadLangs(array('compta','bills','donation','salaries'));
  31. $date_startmonth=GETPOST('date_startmonth','int');
  32. $date_startday=GETPOST('date_startday','int');
  33. $date_startyear=GETPOST('date_startyear','int');
  34. $date_endmonth=GETPOST('date_endmonth','int');
  35. $date_endday=GETPOST('date_endday','int');
  36. $date_endyear=GETPOST('date_endyear','int');
  37. $nbofyear=4;
  38. // Date range
  39. $year=GETPOST('year','int');
  40. if (empty($year))
  41. {
  42. $year_current = strftime("%Y",dol_now());
  43. $month_current = strftime("%m",dol_now());
  44. $year_start = $year_current - ($nbofyear - 1);
  45. } else {
  46. $year_current = $year;
  47. $month_current = strftime("%m",dol_now());
  48. $year_start = $year - ($nbofyear - 1);
  49. }
  50. $date_start=dol_mktime(0, 0, 0, $date_startmonth, $date_startday, $date_startyear);
  51. $date_end=dol_mktime(23, 59, 59, $date_endmonth, $date_endday, $date_endyear);
  52. // We define date_start and date_end
  53. if (empty($date_start) || empty($date_end)) // We define date_start and date_end
  54. {
  55. $q=GETPOST("q")?GETPOST("q"):0;
  56. if ($q==0)
  57. {
  58. // We define date_start and date_end
  59. $year_end=$year_start + ($nbofyear - 1);
  60. $month_start=GETPOST("month")?GETPOST("month"):($conf->global->SOCIETE_FISCAL_MONTH_START?($conf->global->SOCIETE_FISCAL_MONTH_START):1);
  61. if (! GETPOST('month'))
  62. {
  63. if (! GETPOST("year") && $month_start > $month_current)
  64. {
  65. $year_start--;
  66. $year_end--;
  67. }
  68. $month_end=$month_start-1;
  69. if ($month_end < 1) $month_end=12;
  70. else $year_end++;
  71. }
  72. else $month_end=$month_start;
  73. $date_start=dol_get_first_day($year_start,$month_start,false); $date_end=dol_get_last_day($year_end,$month_end,false);
  74. }
  75. if ($q==1) { $date_start=dol_get_first_day($year_start,1,false); $date_end=dol_get_last_day($year_start,3,false); }
  76. if ($q==2) { $date_start=dol_get_first_day($year_start,4,false); $date_end=dol_get_last_day($year_start,6,false); }
  77. if ($q==3) { $date_start=dol_get_first_day($year_start,7,false); $date_end=dol_get_last_day($year_start,9,false); }
  78. if ($q==4) { $date_start=dol_get_first_day($year_start,10,false); $date_end=dol_get_last_day($year_start,12,false); }
  79. }
  80. // $date_start and $date_end are defined. We force $start_year and $nbofyear
  81. $tmps=dol_getdate($date_start);
  82. $start_year = $tmps['year'];
  83. $tmpe=dol_getdate($date_end);
  84. $year_end = $tmpe['year'];
  85. $nbofyear = ($year_end - $start_year) + 1;
  86. //var_dump($start_year." ".$end_year." ".$nbofyear);
  87. // Security check
  88. $socid = GETPOST('socid','int');
  89. if ($user->societe_id > 0) $socid = $user->societe_id;
  90. if (! empty($conf->comptabilite->enabled)) $result=restrictedArea($user,'compta','','','resultat');
  91. if (! empty($conf->accounting->enabled)) $result=restrictedArea($user,'accounting','','','comptarapport');
  92. // Define modecompta ('CREANCES-DETTES' or 'RECETTES-DEPENSES' or 'BOOKKEEPING')
  93. $modecompta = $conf->global->ACCOUNTING_MODE;
  94. if (! empty($conf->accounting->enabled)) $modecompta='BOOKKEEPING';
  95. if (GETPOST("modecompta",'alpha')) $modecompta=GETPOST("modecompta",'alpha');
  96. /*
  97. * View
  98. */
  99. llxHeader();
  100. $form=new Form($db);
  101. $namelink='';
  102. $exportlink='';
  103. // Affiche en-tete du rapport
  104. if ($modecompta == 'CREANCES-DETTES')
  105. {
  106. $name=$langs->trans("AnnualSummaryDueDebtMode");
  107. $calcmode=$langs->trans("CalcModeDebt");
  108. $calcmode.='<br>('.$langs->trans("SeeReportInInputOutputMode",'<a href="'.$_SERVER["PHP_SELF"].'?year_start='.$year_start.'&modecompta=RECETTES-DEPENSES">','</a>').')';
  109. $calcmode.='<br>('.$langs->trans("SeeReportInBookkeepingMode",'<a href="'.$_SERVER["PHP_SELF"].'?year_start='.$year_start.'&modecompta=BOOKKEEPING">','</a>').')';
  110. $period=$form->select_date($date_start,'date_start',0,0,0,'',1,0,1).' - '.$form->select_date($date_end,'date_end',0,0,0,'',1,0,1);
  111. $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>":"");
  112. $description=$langs->trans("RulesAmountWithTaxIncluded");
  113. $description.='<br>'.$langs->trans("RulesResultDue");
  114. if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) $description.="<br>".$langs->trans("DepositsAreNotIncluded");
  115. else $description.="<br>".$langs->trans("DepositsAreIncluded");
  116. $builddate=dol_now();
  117. //$exportlink=$langs->trans("NotYetAvailable");
  118. }
  119. else if ($modecompta=="RECETTES-DEPENSES") {
  120. $name=$langs->trans("AnnualSummaryInputOutputMode");
  121. $calcmode=$langs->trans("CalcModeEngagement");
  122. $calcmode.='<br>('.$langs->trans("SeeReportInDueDebtMode",'<a href="'.$_SERVER["PHP_SELF"].'?year_start='.$year_start.'&modecompta=CREANCES-DETTES">','</a>').')';
  123. $calcmode.='<br>('.$langs->trans("SeeReportInBookkeepingMode",'<a href="'.$_SERVER["PHP_SELF"].'?year_start='.$year_start.'&modecompta=BOOKKEEPING">','</a>').')';
  124. $period=$form->select_date($date_start,'date_start',0,0,0,'',1,0,1).' - '.$form->select_date($date_end,'date_end',0,0,0,'',1,0,1);
  125. $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>":"");
  126. $description=$langs->trans("RulesAmountWithTaxIncluded");
  127. $description.='<br>'.$langs->trans("RulesResultInOut");
  128. $builddate=dol_now();
  129. //$exportlink=$langs->trans("NotYetAvailable");
  130. }
  131. else if ($modecompta=="BOOKKEEPING")
  132. {
  133. $name=$langs->trans("AnnualSummaryDueDebtMode");
  134. $calcmode=$langs->trans("CalcModeBookkeeping");
  135. $calcmode.='<br>('.$langs->trans("SeeReportInInputOutputMode",'<a href="'.$_SERVER["PHP_SELF"].'?year_start='.$year_start.'&modecompta=RECETTES-DEPENSES">','</a>').')';
  136. $calcmode.='<br>('.$langs->trans("SeeReportInDueDebtMode",'<a href="'.$_SERVER["PHP_SELF"].'?year_start='.$year_start.'&modecompta=CREANCES-DETTES">','</a>').')';
  137. $period=$form->select_date($date_start,'date_start',0,0,0,'',1,0,1).' - '.$form->select_date($date_end,'date_end',0,0,0,'',1,0,1);
  138. $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>":"");
  139. $description=$langs->trans("RulesAmountOnInOutBookkeepingRecord");
  140. $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")).')';
  141. $builddate=dol_now();
  142. //$exportlink=$langs->trans("NotYetAvailable");
  143. }
  144. $hselected='report';
  145. report_header($name,$namelink,$period,$periodlink,$description,$builddate,$exportlink,array('modecompta'=>$modecompta),$calcmode);
  146. if (! empty($conf->accounting->enabled) && $modecompta != 'BOOKKEEPING')
  147. {
  148. print info_admin($langs->trans("WarningReportNotReliable"), 0, 0, 1);
  149. }
  150. /*
  151. * Factures clients
  152. */
  153. $subtotal_ht = 0;
  154. $subtotal_ttc = 0;
  155. if (! empty($conf->facture->enabled) && ($modecompta == 'CREANCES-DETTES' || $modecompta=="RECETTES-DEPENSES"))
  156. {
  157. if ($modecompta == 'CREANCES-DETTES')
  158. {
  159. $sql = "SELECT sum(f.total) as amount_ht, sum(f.total_ttc) as amount_ttc, date_format(f.datef,'%Y-%m') as dm";
  160. $sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
  161. $sql.= ", ".MAIN_DB_PREFIX."facture as f";
  162. $sql.= " WHERE f.fk_soc = s.rowid";
  163. $sql.= " AND f.fk_statut IN (1,2)";
  164. if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) $sql.= " AND f.type IN (0,1,2,5)";
  165. else $sql.= " AND f.type IN (0,1,2,3,5)";
  166. if (! empty($date_start) && ! empty($date_end))
  167. $sql.= " AND f.datef >= '".$db->idate($date_start)."' AND f.datef <= '".$db->idate($date_end)."'";
  168. }
  169. else if ($modecompta=="RECETTES-DEPENSES")
  170. {
  171. /*
  172. * Liste des paiements (les anciens paiements ne sont pas vus par cette requete car, sur les
  173. * vieilles versions, ils n'etaient pas lies via paiement_facture. On les ajoute plus loin)
  174. */
  175. $sql = "SELECT sum(pf.amount) as amount_ttc, date_format(p.datep,'%Y-%m') as dm";
  176. $sql.= " FROM ".MAIN_DB_PREFIX."facture as f";
  177. $sql.= ", ".MAIN_DB_PREFIX."paiement_facture as pf";
  178. $sql.= ", ".MAIN_DB_PREFIX."paiement as p";
  179. $sql.= " WHERE p.rowid = pf.fk_paiement";
  180. $sql.= " AND pf.fk_facture = f.rowid";
  181. if (! empty($date_start) && ! empty($date_end))
  182. $sql.= " AND p.datep >= '".$db->idate($date_start)."' AND p.datep <= '".$db->idate($date_end)."'";
  183. }
  184. $sql.= " AND f.entity = ".$conf->entity;
  185. if ($socid) $sql.= " AND f.fk_soc = $socid";
  186. $sql.= " GROUP BY dm";
  187. $sql.= " ORDER BY dm";
  188. //print $sql;
  189. dol_syslog("get customers invoices", LOG_DEBUG);
  190. $result=$db->query($sql);
  191. if ($result)
  192. {
  193. $num = $db->num_rows($result);
  194. $i = 0;
  195. while ($i < $num)
  196. {
  197. $row = $db->fetch_object($result);
  198. $encaiss[$row->dm] = (isset($row->amount_ht)?$row->amount_ht:0);
  199. $encaiss_ttc[$row->dm] = $row->amount_ttc;
  200. $i++;
  201. }
  202. $db->free($result);
  203. }
  204. else {
  205. dol_print_error($db);
  206. }
  207. }
  208. else if ($modecompta=="BOOKKEEPING")
  209. {
  210. // Nothing from this table
  211. }
  212. if (! empty($conf->facture->enabled) && ($modecompta == 'CREANCES-DETTES' || $modecompta=="RECETTES-DEPENSES"))
  213. {
  214. // On ajoute les paiements clients anciennes version, non lies par paiement_facture
  215. if ($modecompta != 'CREANCES-DETTES')
  216. {
  217. $sql = "SELECT sum(p.amount) as amount_ttc, date_format(p.datep,'%Y-%m') as dm";
  218. $sql.= " FROM ".MAIN_DB_PREFIX."bank as b";
  219. $sql.= ", ".MAIN_DB_PREFIX."bank_account as ba";
  220. $sql.= ", ".MAIN_DB_PREFIX."paiement as p";
  221. $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf ON p.rowid = pf.fk_paiement";
  222. $sql.= " WHERE pf.rowid IS NULL";
  223. $sql.= " AND p.fk_bank = b.rowid";
  224. $sql.= " AND b.fk_account = ba.rowid";
  225. $sql.= " AND ba.entity IN (".getEntity('bank_account').")";
  226. if (! empty($date_start) && ! empty($date_end))
  227. $sql.= " AND p.datep >= '".$db->idate($date_start)."' AND p.datep <= '".$db->idate($date_end)."'";
  228. $sql.= " GROUP BY dm";
  229. $sql.= " ORDER BY dm";
  230. dol_syslog("get old customers payments not linked to invoices", LOG_DEBUG);
  231. $result = $db->query($sql);
  232. if ($result) {
  233. $num = $db->num_rows($result);
  234. $i = 0;
  235. while ($i < $num)
  236. {
  237. $row = $db->fetch_object($result);
  238. if (! isset($encaiss[$row->dm])) $encaiss[$row->dm]=0;
  239. $encaiss[$row->dm] += (isset($row->amount_ht)?$row->amount_ht:0);
  240. if (! isset($encaiss_ttc[$row->dm])) $encaiss_ttc[$row->dm]=0;
  241. $encaiss_ttc[$row->dm] += $row->amount_ttc;
  242. $i++;
  243. }
  244. }
  245. else {
  246. dol_print_error($db);
  247. }
  248. }
  249. else if ($modecompta=="RECETTES-DEPENSES")
  250. {
  251. // Nothing from this table
  252. }
  253. }
  254. else if ($modecompta=="BOOKKEEPING")
  255. {
  256. // Nothing from this table
  257. }
  258. /*
  259. * Frais, factures fournisseurs.
  260. */
  261. $subtotal_ht = 0;
  262. $subtotal_ttc = 0;
  263. if (! empty($conf->facture->enabled) && ($modecompta == 'CREANCES-DETTES' || $modecompta=="RECETTES-DEPENSES"))
  264. {
  265. if ($modecompta == 'CREANCES-DETTES')
  266. {
  267. $sql = "SELECT sum(f.total_ht) as amount_ht, sum(f.total_ttc) as amount_ttc, date_format(f.datef,'%Y-%m') as dm";
  268. $sql.= " FROM ".MAIN_DB_PREFIX."facture_fourn as f";
  269. $sql.= " WHERE f.fk_statut IN (1,2)";
  270. if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) $sql.= " AND f.type IN (0,1,2)";
  271. else $sql.= " AND f.type IN (0,1,2,3)";
  272. if (! empty($date_start) && ! empty($date_end))
  273. $sql.= " AND f.datef >= '".$db->idate($date_start)."' AND f.datef <= '".$db->idate($date_end)."'";
  274. }
  275. else if ($modecompta=="RECETTES-DEPENSES")
  276. {
  277. $sql = "SELECT sum(pf.amount) as amount_ttc, date_format(p.datep,'%Y-%m') as dm";
  278. $sql.= " FROM ".MAIN_DB_PREFIX."paiementfourn as p";
  279. $sql.= ", ".MAIN_DB_PREFIX."facture_fourn as f";
  280. $sql.= ", ".MAIN_DB_PREFIX."paiementfourn_facturefourn as pf";
  281. $sql.= " WHERE f.rowid = pf.fk_facturefourn";
  282. $sql.= " AND p.rowid = pf.fk_paiementfourn";
  283. if (! empty($date_start) && ! empty($date_end))
  284. $sql.= " AND p.datep >= '".$db->idate($date_start)."' AND p.datep <= '".$db->idate($date_end)."'";
  285. }
  286. $sql.= " AND f.entity = ".$conf->entity;
  287. if ($socid) $sql.= " AND f.fk_soc = ".$socid;
  288. $sql.= " GROUP BY dm";
  289. dol_syslog("get suppliers invoices", LOG_DEBUG);
  290. $result=$db->query($sql);
  291. if ($result)
  292. {
  293. $num = $db->num_rows($result);
  294. $i = 0;
  295. while ($i < $num)
  296. {
  297. $row = $db->fetch_object($result);
  298. if (! isset($decaiss[$row->dm])) $decaiss[$row->dm]=0;
  299. $decaiss[$row->dm] = (isset($row->amount_ht)?$row->amount_ht:0);
  300. if (! isset($decaiss_ttc[$row->dm])) $decaiss_ttc[$row->dm]=0;
  301. $decaiss_ttc[$row->dm] = $row->amount_ttc;
  302. $i++;
  303. }
  304. $db->free($result);
  305. }
  306. else {
  307. dol_print_error($db);
  308. }
  309. }
  310. else if ($modecompta=="BOOKKEEPING")
  311. {
  312. // Nothing from this table
  313. }
  314. /*
  315. * TVA
  316. */
  317. $subtotal_ht = 0;
  318. $subtotal_ttc = 0;
  319. if (! empty($conf->tax->enabled) && ($modecompta == 'CREANCES-DETTES' || $modecompta=="RECETTES-DEPENSES"))
  320. {
  321. if ($modecompta == 'CREANCES-DETTES')
  322. {
  323. // TVA a payer
  324. $sql = "SELECT sum(f.tva) as amount, date_format(f.datef,'%Y-%m') as dm";
  325. $sql.= " FROM ".MAIN_DB_PREFIX."facture as f";
  326. $sql.= " WHERE f.fk_statut IN (1,2)";
  327. if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) $sql.= " AND f.type IN (0,1,2,5)";
  328. else $sql.= " AND f.type IN (0,1,2,3,5)";
  329. $sql.= " AND f.entity = ".$conf->entity;
  330. if (! empty($date_start) && ! empty($date_end))
  331. $sql.= " AND f.datef >= '".$db->idate($date_start)."' AND f.datef <= '".$db->idate($date_end)."'";
  332. $sql.= " GROUP BY dm";
  333. dol_syslog("get vat to pay", LOG_DEBUG);
  334. $result=$db->query($sql);
  335. if ($result) {
  336. $num = $db->num_rows($result);
  337. $var=false;
  338. $i = 0;
  339. if ($num) {
  340. while ($i < $num) {
  341. $obj = $db->fetch_object($result);
  342. if (! isset($decaiss[$obj->dm])) $decaiss[$obj->dm]=0;
  343. $decaiss[$obj->dm] += $obj->amount;
  344. if (! isset($decaiss_ttc[$obj->dm])) $decaiss_ttc[$obj->dm]=0;
  345. $decaiss_ttc[$obj->dm] += $obj->amount;
  346. $i++;
  347. }
  348. }
  349. } else {
  350. dol_print_error($db);
  351. }
  352. // TVA a recuperer
  353. $sql = "SELECT sum(f.total_tva) as amount, date_format(f.datef,'%Y-%m') as dm";
  354. $sql.= " FROM ".MAIN_DB_PREFIX."facture_fourn as f";
  355. $sql.= " WHERE f.fk_statut IN (1,2)";
  356. if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) $sql.= " AND f.type IN (0,1,2)";
  357. else $sql.= " AND f.type IN (0,1,2,3)";
  358. $sql.= " AND f.entity = ".$conf->entity;
  359. if (! empty($date_start) && ! empty($date_end))
  360. $sql.= " AND f.datef >= '".$db->idate($date_start)."' AND f.datef <= '".$db->idate($date_end)."'";
  361. $sql.= " GROUP BY dm";
  362. dol_syslog("get vat to receive back", LOG_DEBUG);
  363. $result=$db->query($sql);
  364. if ($result) {
  365. $num = $db->num_rows($result);
  366. $var=false;
  367. $i = 0;
  368. if ($num) {
  369. while ($i < $num) {
  370. $obj = $db->fetch_object($result);
  371. if (! isset($encaiss[$obj->dm])) $encaiss[$obj->dm]=0;
  372. $encaiss[$obj->dm] += $obj->amount;
  373. if (! isset($encaiss_ttc[$obj->dm])) $encaiss_ttc[$obj->dm]=0;
  374. $encaiss_ttc[$obj->dm] += $obj->amount;
  375. $i++;
  376. }
  377. }
  378. } else {
  379. dol_print_error($db);
  380. }
  381. }
  382. else if ($modecompta=="RECETTES-DEPENSES")
  383. {
  384. // TVA reellement deja payee
  385. $sql = "SELECT sum(t.amount) as amount, date_format(t.datev,'%Y-%m') as dm";
  386. $sql.= " FROM ".MAIN_DB_PREFIX."tva as t";
  387. $sql.= " WHERE amount > 0";
  388. $sql.= " AND t.entity = ".$conf->entity;
  389. if (! empty($date_start) && ! empty($date_end))
  390. $sql.= " AND t.datev >= '".$db->idate($date_start)."' AND t.datev <= '".$db->idate($date_end)."'";
  391. $sql.= " GROUP BY dm";
  392. dol_syslog("get vat really paid", LOG_DEBUG);
  393. $result=$db->query($sql);
  394. if ($result) {
  395. $num = $db->num_rows($result);
  396. $var=false;
  397. $i = 0;
  398. if ($num) {
  399. while ($i < $num) {
  400. $obj = $db->fetch_object($result);
  401. if (! isset($decaiss[$obj->dm])) $decaiss[$obj->dm]=0;
  402. $decaiss[$obj->dm] += $obj->amount;
  403. if (! isset($decaiss_ttc[$obj->dm])) $decaiss_ttc[$obj->dm]=0;
  404. $decaiss_ttc[$obj->dm] += $obj->amount;
  405. $i++;
  406. }
  407. }
  408. } else {
  409. dol_print_error($db);
  410. }
  411. // TVA recuperee
  412. $sql = "SELECT sum(t.amount) as amount, date_format(t.datev,'%Y-%m') as dm";
  413. $sql.= " FROM ".MAIN_DB_PREFIX."tva as t";
  414. $sql.= " WHERE amount < 0";
  415. $sql.= " AND t.entity = ".$conf->entity;
  416. if (! empty($date_start) && ! empty($date_end))
  417. $sql.= " AND t.datev >= '".$db->idate($date_start)."' AND t.datev <= '".$db->idate($date_end)."'";
  418. $sql.= " GROUP BY dm";
  419. dol_syslog("get vat really received back", LOG_DEBUG);
  420. $result=$db->query($sql);
  421. if ($result) {
  422. $num = $db->num_rows($result);
  423. $var=false;
  424. $i = 0;
  425. if ($num) {
  426. while ($i < $num) {
  427. $obj = $db->fetch_object($result);
  428. if (! isset($encaiss[$obj->dm])) $encaiss[$obj->dm]=0;
  429. $encaiss[$obj->dm] += $obj->amount;
  430. if (! isset($encaiss_ttc[$obj->dm])) $encaiss_ttc[$obj->dm]=0;
  431. $encaiss_ttc[$obj->dm] += $obj->amount;
  432. $i++;
  433. }
  434. }
  435. } else {
  436. dol_print_error($db);
  437. }
  438. }
  439. }
  440. else if ($modecompta=="BOOKKEEPING")
  441. {
  442. // Nothing from this table
  443. }
  444. /*
  445. * Charges sociales non deductibles
  446. */
  447. $subtotal_ht = 0;
  448. $subtotal_ttc = 0;
  449. if (! empty($conf->tax->enabled) && ($modecompta == 'CREANCES-DETTES' || $modecompta=="RECETTES-DEPENSES"))
  450. {
  451. if ($modecompta == 'CREANCES-DETTES')
  452. {
  453. $sql = "SELECT c.libelle as nom, date_format(cs.date_ech,'%Y-%m') as dm, sum(cs.amount) as amount";
  454. $sql.= " FROM ".MAIN_DB_PREFIX."c_chargesociales as c";
  455. $sql.= ", ".MAIN_DB_PREFIX."chargesociales as cs";
  456. $sql.= " WHERE cs.fk_type = c.id";
  457. $sql.= " AND c.deductible = 0";
  458. if (! empty($date_start) && ! empty($date_end))
  459. $sql.= " AND cs.date_ech >= '".$db->idate($date_start)."' AND cs.date_ech <= '".$db->idate($date_end)."'";
  460. }
  461. else if ($modecompta=="RECETTES-DEPENSES")
  462. {
  463. $sql = "SELECT c.libelle as nom, date_format(p.datep,'%Y-%m') as dm, sum(p.amount) as amount";
  464. $sql.= " FROM ".MAIN_DB_PREFIX."c_chargesociales as c";
  465. $sql.= ", ".MAIN_DB_PREFIX."chargesociales as cs";
  466. $sql.= ", ".MAIN_DB_PREFIX."paiementcharge as p";
  467. $sql.= " WHERE p.fk_charge = cs.rowid";
  468. $sql.= " AND cs.fk_type = c.id";
  469. $sql.= " AND c.deductible = 0";
  470. if (! empty($date_start) && ! empty($date_end))
  471. $sql.= " AND p.datep >= '".$db->idate($date_start)."' AND p.datep <= '".$db->idate($date_end)."'";
  472. }
  473. $sql.= " AND cs.entity = ".$conf->entity;
  474. $sql.= " GROUP BY c.libelle, dm";
  475. dol_syslog("get social contributions deductible=0 ", LOG_DEBUG);
  476. $result=$db->query($sql);
  477. if ($result) {
  478. $num = $db->num_rows($result);
  479. $var=false;
  480. $i = 0;
  481. if ($num) {
  482. while ($i < $num) {
  483. $obj = $db->fetch_object($result);
  484. if (! isset($decaiss[$obj->dm])) $decaiss[$obj->dm]=0;
  485. $decaiss[$obj->dm] += $obj->amount;
  486. if (! isset($decaiss_ttc[$obj->dm])) $decaiss_ttc[$obj->dm]=0;
  487. $decaiss_ttc[$obj->dm] += $obj->amount;
  488. $i++;
  489. }
  490. }
  491. } else {
  492. dol_print_error($db);
  493. }
  494. }
  495. else if ($modecompta=="BOOKKEEPING")
  496. {
  497. // Nothing from this table
  498. }
  499. /*
  500. * Charges sociales deductibles
  501. */
  502. $subtotal_ht = 0;
  503. $subtotal_ttc = 0;
  504. if (! empty($conf->tax->enabled) && ($modecompta == 'CREANCES-DETTES' || $modecompta=="RECETTES-DEPENSES"))
  505. {
  506. if ($modecompta == 'CREANCES-DETTES')
  507. {
  508. $sql = "SELECT c.libelle as nom, date_format(cs.date_ech,'%Y-%m') as dm, sum(cs.amount) as amount";
  509. $sql.= " FROM ".MAIN_DB_PREFIX."c_chargesociales as c";
  510. $sql.= ", ".MAIN_DB_PREFIX."chargesociales as cs";
  511. $sql.= " WHERE cs.fk_type = c.id";
  512. $sql.= " AND c.deductible = 1";
  513. if (! empty($date_start) && ! empty($date_end))
  514. $sql.= " AND cs.date_ech >= '".$db->idate($date_start)."' AND cs.date_ech <= '".$db->idate($date_end)."'";
  515. }
  516. else if ($modecompta=="RECETTES-DEPENSES")
  517. {
  518. $sql = "SELECT c.libelle as nom, date_format(p.datep,'%Y-%m') as dm, sum(p.amount) as amount";
  519. $sql.= " FROM ".MAIN_DB_PREFIX."c_chargesociales as c";
  520. $sql.= ", ".MAIN_DB_PREFIX."chargesociales as cs";
  521. $sql.= ", ".MAIN_DB_PREFIX."paiementcharge as p";
  522. $sql.= " WHERE p.fk_charge = cs.rowid";
  523. $sql.= " AND cs.fk_type = c.id";
  524. $sql.= " AND c.deductible = 1";
  525. if (! empty($date_start) && ! empty($date_end))
  526. $sql.= " AND p.datep >= '".$db->idate($date_start)."' AND p.datep <= '".$db->idate($date_end)."'";
  527. }
  528. $sql.= " AND cs.entity = ".$conf->entity;
  529. $sql.= " GROUP BY c.libelle, dm";
  530. dol_syslog("get social contributions paid deductible=1", LOG_DEBUG);
  531. $result=$db->query($sql);
  532. if ($result) {
  533. $num = $db->num_rows($result);
  534. $var=false;
  535. $i = 0;
  536. if ($num) {
  537. while ($i < $num) {
  538. $obj = $db->fetch_object($result);
  539. if (! isset($decaiss[$obj->dm])) $decaiss[$obj->dm]=0;
  540. $decaiss[$obj->dm] += $obj->amount;
  541. if (! isset($decaiss_ttc[$obj->dm])) $decaiss_ttc[$obj->dm]=0;
  542. $decaiss_ttc[$obj->dm] += $obj->amount;
  543. $i++;
  544. }
  545. }
  546. } else {
  547. dol_print_error($db);
  548. }
  549. }
  550. else if ($modecompta=="BOOKKEEPING")
  551. {
  552. // Nothing from this table
  553. }
  554. /*
  555. * Salaries
  556. */
  557. if (! empty($conf->salaries->enabled) && ($modecompta == 'CREANCES-DETTES' || $modecompta=="RECETTES-DEPENSES"))
  558. {
  559. if ($modecompta == 'CREANCES-DETTES') $column = 'p.datev';
  560. if ($modecompta == "RECETTES-DEPENSES") $column = 'p.datep';
  561. $subtotal_ht = 0;
  562. $subtotal_ttc = 0;
  563. $sql = "SELECT p.label as nom, date_format($column,'%Y-%m') as dm, sum(p.amount) as amount";
  564. $sql .= " FROM " . MAIN_DB_PREFIX . "payment_salary as p";
  565. $sql .= " WHERE p.entity = " . $conf->entity;
  566. $sql .= " GROUP BY p.label, dm";
  567. if (! empty($date_start) && ! empty($date_end))
  568. $sql.= " AND ".$column." >= '".$db->idate($date_start)."' AND ".$column." <= '".$db->idate($date_end)."'";
  569. dol_syslog("get social salaries payments");
  570. $result = $db->query($sql);
  571. if ($result) {
  572. $num = $db->num_rows($result);
  573. $var = false;
  574. $i = 0;
  575. if ($num) {
  576. while ($i < $num) {
  577. $obj = $db->fetch_object($result);
  578. if (! isset($decaiss[$obj->dm]))
  579. $decaiss[$obj->dm] = 0;
  580. $decaiss[$obj->dm] += $obj->amount;
  581. if (! isset($decaiss_ttc[$obj->dm]))
  582. $decaiss_ttc[$obj->dm] = 0;
  583. $decaiss_ttc[$obj->dm] += $obj->amount;
  584. $i ++;
  585. }
  586. }
  587. } else {
  588. dol_print_error($db);
  589. }
  590. }
  591. elseif ($modecompta == "BOOKKEEPING")
  592. {
  593. // Nothing from this table
  594. }
  595. /*
  596. * Expense reports
  597. */
  598. if (! empty($conf->expensereport->enabled) && ($modecompta == 'CREANCES-DETTES' || $modecompta=="RECETTES-DEPENSES"))
  599. {
  600. $langs->load('trips');
  601. if ($modecompta == 'CREANCES-DETTES') {
  602. $sql = "SELECT date_format(date_valid,'%Y-%m') as dm, sum(p.total_ht) as amount_ht,sum(p.total_ttc) as amount_ttc";
  603. $sql.= " FROM ".MAIN_DB_PREFIX."expensereport as p";
  604. $sql.= " INNER JOIN ".MAIN_DB_PREFIX."user as u ON u.rowid=p.fk_user_author";
  605. $sql.= " WHERE p.entity = ".getEntity('expensereport');
  606. $sql.= " AND p.fk_statut>=5";
  607. $column='p.date_valid';
  608. if (! empty($date_start) && ! empty($date_end))
  609. $sql.= " AND ".$column." >= '".$db->idate($date_start)."' AND ".$column." <= '".$db->idate($date_end)."'";
  610. } elseif ($modecompta == 'RECETTES-DEPENSES') {
  611. $sql = "SELECT date_format(pe.datep,'%Y-%m') as dm, sum(p.total_ht) as amount_ht,sum(p.total_ttc) as amount_ttc";
  612. $sql.= " FROM ".MAIN_DB_PREFIX."expensereport as p";
  613. $sql.= " INNER JOIN ".MAIN_DB_PREFIX."user as u ON u.rowid=p.fk_user_author";
  614. $sql.= " INNER JOIN ".MAIN_DB_PREFIX."payment_expensereport as pe ON pe.fk_expensereport = p.rowid";
  615. $sql.= " INNER JOIN ".MAIN_DB_PREFIX."c_paiement as c ON pe.fk_typepayment = c.id";
  616. $sql.= " WHERE p.entity = ".getEntity('expensereport');
  617. $sql.= " AND p.fk_statut>=5";
  618. $column='pe.datep';
  619. if (! empty($date_start) && ! empty($date_end))
  620. $sql.= " AND ".$column." >= '".$db->idate($date_start)."' AND ".$column." <= '".$db->idate($date_end)."'";
  621. }
  622. $sql.= " GROUP BY dm";
  623. dol_syslog("get expense report outcome");
  624. $result=$db->query($sql);
  625. $subtotal_ht = 0;
  626. $subtotal_ttc = 0;
  627. if ($result)
  628. {
  629. $num = $db->num_rows($result);
  630. if ($num)
  631. {
  632. while ($obj = $db->fetch_object($result))
  633. {
  634. if (! isset($decaiss[$obj->dm])) $decaiss[$obj->dm]=0;
  635. $decaiss[$obj->dm] += $obj->amount_ht;
  636. if (! isset($decaiss_ttc[$obj->dm])) $decaiss_ttc[$obj->dm]=0;
  637. $decaiss_ttc[$obj->dm] += $obj->amount_ttc;
  638. }
  639. }
  640. }
  641. else
  642. {
  643. dol_print_error($db);
  644. }
  645. }
  646. elseif ($modecompta == 'BOOKKEEPING') {
  647. // Nothing from this table
  648. }
  649. /*
  650. * Donation get dunning paiement
  651. */
  652. if (! empty($conf->don->enabled) && ($modecompta == 'CREANCES-DETTES' || $modecompta=="RECETTES-DEPENSES"))
  653. {
  654. $subtotal_ht = 0;
  655. $subtotal_ttc = 0;
  656. if ($modecompta == 'CREANCES-DETTES') {
  657. $sql = "SELECT p.societe as nom, p.firstname, p.lastname, date_format(p.datedon,'%Y-%m') as dm, sum(p.amount) as amount";
  658. $sql.= " FROM ".MAIN_DB_PREFIX."don as p";
  659. $sql.= " WHERE p.entity = ".$conf->entity;
  660. $sql.= " AND fk_statut in (1,2)";
  661. if (! empty($date_start) && ! empty($date_end))
  662. $sql.= " AND p.datedon >= '".$db->idate($date_start)."' AND p.datedon <= '".$db->idate($date_end)."'";
  663. }
  664. elseif ($modecompta == 'RECETTES-DEPENSES') {
  665. $sql = "SELECT p.societe as nom, p.firstname, p.lastname, date_format(pe.datep,'%Y-%m') as dm, sum(p.amount) as amount";
  666. $sql.= " FROM ".MAIN_DB_PREFIX."don as p";
  667. $sql.= " INNER JOIN ".MAIN_DB_PREFIX."payment_donation as pe ON pe.fk_donation = p.rowid";
  668. $sql.= " INNER JOIN ".MAIN_DB_PREFIX."c_paiement as c ON pe.fk_typepayment = c.id";
  669. $sql.= " WHERE p.entity = ".getEntity('donation');
  670. $sql.= " AND fk_statut >= 2";
  671. if (! empty($date_start) && ! empty($date_end))
  672. $sql.= " AND pe.datep >= '".$db->idate($date_start)."' AND pe.datep <= '".$db->idate($date_end)."'";
  673. }
  674. $sql.= " GROUP BY p.societe, p.firstname, p.lastname, dm";
  675. dol_syslog("get donation payments");
  676. $result=$db->query($sql);
  677. if ($result)
  678. {
  679. $num = $db->num_rows($result);
  680. $var=false;
  681. $i = 0;
  682. if ($num)
  683. {
  684. while ($i < $num)
  685. {
  686. $obj = $db->fetch_object($result);
  687. if (! isset($encaiss[$obj->dm])) $encaiss[$obj->dm]=0;
  688. $encaiss[$obj->dm] += $obj->amount;
  689. if (! isset($encaiss_ttc[$obj->dm])) $encaiss_ttc[$obj->dm]=0;
  690. $encaiss_ttc[$obj->dm] += $obj->amount;
  691. $i++;
  692. }
  693. }
  694. }
  695. else
  696. {
  697. dol_print_error($db);
  698. }
  699. }
  700. elseif ($modecompta == 'BOOKKEEPING') {
  701. // Nothing from this table
  702. }
  703. /*
  704. * Request in mode BOOKKEEPING
  705. */
  706. if (! empty($conf->accounting->enabled) && ($modecompta == 'BOOKKEEPING'))
  707. {
  708. $subtotal_ht = 0;
  709. $subtotal_ttc = 0;
  710. $sql = "SELECT b.doc_ref, b.numero_compte, b.subledger_account, b.subledger_label, 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";
  711. $sql.= " FROM ".MAIN_DB_PREFIX."accounting_bookkeeping as b, ".MAIN_DB_PREFIX."accounting_account as aa";
  712. $sql.= " WHERE b.numero_compte = aa.account_number AND b.entity = ".$conf->entity;
  713. //$sql.= " AND fk_statut in (1,2)";
  714. $sql.= " AND (";
  715. $sql.= " (pcg_type = 'EXPENSE' and pcg_subtype in ('PRODUCT','SERVICE'))";
  716. $sql.= " OR ";
  717. $sql.= " (pcg_type = 'INCOME' and pcg_subtype in ('PRODUCT','SERVICE'))";
  718. $sql.= ")";
  719. //$sql.= " AND code_journal in ('VT', 'AC')";
  720. if (! empty($date_start) && ! empty($date_end))
  721. $sql.= " AND b.doc_date >= '".$db->idate($date_start)."' AND b.doc_date <= '".$db->idate($date_end)."'";
  722. $sql.= " GROUP BY b.doc_ref, b.numero_compte, b.subledger_account, b.subledger_label, pcg_type, dm";
  723. //print $sql;
  724. dol_syslog("get bookkeeping record");
  725. $result=$db->query($sql);
  726. if ($result)
  727. {
  728. $num = $db->num_rows($result);
  729. $var=false;
  730. $i = 0;
  731. if ($num)
  732. {
  733. while ($i < $num)
  734. {
  735. $obj = $db->fetch_object($result);
  736. if (! isset($encaiss[$obj->dm])) $encaiss[$obj->dm]=0;
  737. $encaiss[$obj->dm] += $obj->debit;
  738. if (! isset($encaiss_ttc[$obj->dm])) $encaiss_ttc[$obj->dm]=0;
  739. $encaiss_ttc[$obj->dm] += $obj->credit;
  740. $i++;
  741. }
  742. }
  743. }
  744. else
  745. {
  746. dol_print_error($db);
  747. }
  748. }
  749. $action = "balance";
  750. $object = array(&$encaiss, &$encaiss_ttc, &$decaiss, &$decaiss_ttc);
  751. $parameters["mode"] = $modecompta;
  752. // Initialize technical object to manage hooks of expenses. Note that conf->hooks_modules contains array array
  753. $hookmanager->initHooks(array('externalbalance'));
  754. $reshook=$hookmanager->executeHooks('addReportInfo',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
  755. /*
  756. * Show result array
  757. */
  758. $totentrees=array();
  759. $totsorties=array();
  760. print '<div class="div-table-responsive">';
  761. print '<table class="tagtable liste">'."\n";
  762. print '<tr class="liste_titre"><td class="liste_titre">&nbsp;</td>';
  763. for ($annee = $year_start ; $annee <= $year_end ; $annee++)
  764. {
  765. print '<td align="center" colspan="2" class="liste_titre borderrightlight">';
  766. print '<a href="clientfourn.php?year='.$annee.'">';
  767. print $annee;
  768. if ($conf->global->SOCIETE_FISCAL_MONTH_START > 1) print '-'.($annee+1);
  769. print '</a></td>';
  770. }
  771. print '</tr>';
  772. print '<tr class="liste_titre"><td class="liste_titre">'.$langs->trans("Month").'</td>';
  773. for ($annee = $year_start ; $annee <= $year_end ; $annee++)
  774. {
  775. print '<td class="liste_titre" align="center">'.$langs->trans("Outcome").'</td>';
  776. print '<td class="liste_titre" align="center" class="borderrightlight">'.$langs->trans("Income").'</td>';
  777. }
  778. print '</tr>';
  779. $var=True;
  780. // Loop on each month
  781. $nb_mois_decalage = $conf->global->SOCIETE_FISCAL_MONTH_START?($conf->global->SOCIETE_FISCAL_MONTH_START-1):0;
  782. for ($mois = 1+$nb_mois_decalage ; $mois <= 12+$nb_mois_decalage ; $mois++)
  783. {
  784. $mois_modulo = $mois;
  785. if($mois>12) {$mois_modulo = $mois-12;}
  786. print '<tr class="oddeven">';
  787. print "<td>".dol_print_date(dol_mktime(12,0,0,$mois_modulo,1,$annee),"%B")."</td>";
  788. for ($annee = $year_start ; $annee <= $year_end ; $annee++)
  789. {
  790. $annee_decalage=$annee;
  791. if($mois>12) {$annee_decalage=$annee+1;}
  792. $case = strftime("%Y-%m",dol_mktime(12,0,0,$mois_modulo,1,$annee_decalage));
  793. print '<td align="right">&nbsp;';
  794. if (isset($decaiss_ttc[$case]) && $decaiss_ttc[$case] != 0)
  795. {
  796. print '<a href="clientfourn.php?year='.$annee_decalage.'&month='.$mois_modulo.($modecompta?'&modecompta='.$modecompta:'').'">'.price(price2num($decaiss_ttc[$case],'MT')).'</a>';
  797. if (! isset($totsorties[$annee])) $totsorties[$annee]=0;
  798. $totsorties[$annee]+=$decaiss_ttc[$case];
  799. }
  800. print "</td>";
  801. print '<td align="right" class="borderrightlight">&nbsp;';
  802. //if (isset($encaiss_ttc[$case]) && $encaiss_ttc[$case] != 0)
  803. if (isset($encaiss_ttc[$case]))
  804. {
  805. print '<a href="clientfourn.php?year='.$annee_decalage.'&month='.$mois_modulo.($modecompta?'&modecompta='.$modecompta:'').'">'.price(price2num($encaiss_ttc[$case],'MT')).'</a>';
  806. if (! isset($totentrees[$annee])) $totentrees[$annee]=0;
  807. $totentrees[$annee]+=$encaiss_ttc[$case];
  808. }
  809. print "</td>";
  810. }
  811. print '</tr>';
  812. }
  813. // Total
  814. $nbcols=0;
  815. print '<tr class="liste_total impair"><td>'.$langs->trans("TotalTTC").'</td>';
  816. for ($annee = $year_start ; $annee <= $year_end ; $annee++)
  817. {
  818. $nbcols+=2;
  819. print '<td align="right">'.(isset($totsorties[$annee])?price(price2num($totsorties[$annee],'MT')):'&nbsp;').'</td>';
  820. print '<td align="right" style="border-right: 1px solid #DDD">'.(isset($totentrees[$annee])?price(price2num($totentrees[$annee],'MT')):'&nbsp;').'</td>';
  821. }
  822. print "</tr>\n";
  823. // Empty line
  824. print '<tr class="impair"><td>&nbsp;</td>';
  825. print '<td colspan="'.$nbcols.'">&nbsp;</td>';
  826. print "</tr>\n";
  827. // Balance
  828. print '<tr class="liste_total"><td>'.$langs->trans("AccountingResult").'</td>';
  829. for ($annee = $year_start ; $annee <= $year_end ; $annee++)
  830. {
  831. print '<td align="right" colspan="2" class="borderrightlight"> ';
  832. if (isset($totentrees[$annee]) || isset($totsorties[$annee]))
  833. {
  834. $in=(isset($totentrees[$annee])?price2num($totentrees[$annee], 'MT'):0);
  835. $out=(isset($totsorties[$annee])?price2num($totsorties[$annee],'MT'):0);
  836. print price($in-$out).'</td>';
  837. // print '<td>&nbsp;</td>';
  838. }
  839. }
  840. print "</tr>\n";
  841. print "</table>";
  842. print '</div>';
  843. llxFooter();
  844. $db->close();