index.php 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550
  1. <?php
  2. /* Copyright (C) 2001-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2012 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005-2009 Regis Houssin <regis.houssin@capnetworks.com>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. /**
  20. * \file htdocs/compta/stats/index.php
  21. * \brief Page reporting CA
  22. */
  23. require '../../main.inc.php';
  24. require_once DOL_DOCUMENT_ROOT.'/core/lib/report.lib.php';
  25. $year_start=GETPOST("year_start");
  26. $year_current = strftime("%Y",time());
  27. $nbofyear=4;
  28. if (! $year_start) {
  29. $year_start = $year_current - ($nbofyear-1);
  30. $year_end = $year_current;
  31. }
  32. else {
  33. $year_end=$year_start + ($nbofyear-1);
  34. }
  35. $userid=GETPOST('userid','int');
  36. $socid = GETPOST('socid','int');
  37. // Define modecompta ('CREANCES-DETTES' or 'RECETTES-DEPENSES')
  38. $modecompta = $conf->global->ACCOUNTING_MODE;
  39. if (GETPOST("modecompta")) $modecompta=GETPOST("modecompta",'alpha');
  40. // Security check
  41. if ($user->societe_id > 0) $socid = $user->societe_id;
  42. if (! empty($conf->comptabilite->enabled)) $result=restrictedArea($user,'compta','','','resultat');
  43. if (! empty($conf->accounting->enabled)) $result=restrictedArea($user,'accounting','','','comptarapport');
  44. /*
  45. * View
  46. */
  47. llxHeader();
  48. $form=new Form($db);
  49. // Affiche en-tete du rapport
  50. if ($modecompta=="CREANCES-DETTES")
  51. {
  52. $nom=$langs->trans("SalesTurnover");
  53. $calcmode=$langs->trans("CalcModeDebt");
  54. $calcmode.='<br>('.$langs->trans("SeeReportInInputOutputMode",'<a href="'.$_SERVER["PHP_SELF"].'?year_start='.$year_start.'&modecompta=RECETTES-DEPENSES">','</a>').')';
  55. $period="$year_start - $year_end";
  56. $periodlink=($year_start?"<a href='".$_SERVER["PHP_SELF"]."?year_start=".($year_start-1)."&modecompta=".$modecompta."'>".img_previous()."</a> <a href='".$_SERVER["PHP_SELF"]."?year_start=".($year_start+1)."&modecompta=".$modecompta."'>".img_next()."</a>":"");
  57. $description=$langs->trans("RulesCADue");
  58. if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) $description.= $langs->trans("DepositsAreNotIncluded");
  59. else $description.= $langs->trans("DepositsAreIncluded");
  60. $builddate=time();
  61. //$exportlink=$langs->trans("NotYetAvailable");
  62. }
  63. else {
  64. $nom=$langs->trans("SalesTurnover");
  65. $calcmode=$langs->trans("CalcModeEngagement");
  66. $calcmode.='<br>('.$langs->trans("SeeReportInDueDebtMode",'<a href="'.$_SERVER["PHP_SELF"].'?year_start='.$year_start.'&modecompta=CREANCES-DETTES">','</a>').')';
  67. $period="$year_start - $year_end";
  68. $periodlink=($year_start?"<a href='".$_SERVER["PHP_SELF"]."?year_start=".($year_start-1)."&modecompta=".$modecompta."'>".img_previous()."</a> <a href='".$_SERVER["PHP_SELF"]."?year_start=".($year_start+1)."&modecompta=".$modecompta."'>".img_next()."</a>":"");
  69. $description=$langs->trans("RulesCAIn");
  70. $description.= $langs->trans("DepositsAreIncluded");
  71. $builddate=time();
  72. //$exportlink=$langs->trans("NotYetAvailable");
  73. }
  74. $moreparam=array();
  75. if (! empty($modecompta)) $moreparam['modecompta']=$modecompta;
  76. report_header($nom,$nomlink,$period,$periodlink,$description,$builddate,$exportlink,$moreparam,$calcmode);
  77. if (! empty($conf->accounting->enabled))
  78. {
  79. print info_admin($langs->trans("WarningReportNotReliable"), 0, 0, 1);
  80. }
  81. if ($modecompta == 'CREANCES-DETTES')
  82. {
  83. $sql = "SELECT date_format(f.datef,'%Y-%m') as dm, sum(f.total) as amount, sum(f.total_ttc) as amount_ttc";
  84. $sql.= " FROM ".MAIN_DB_PREFIX."facture as f";
  85. $sql.= " WHERE f.fk_statut in (1,2)";
  86. if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) $sql.= " AND f.type IN (0,1,2,5)";
  87. else $sql.= " AND f.type IN (0,1,2,3,5)";
  88. }
  89. else
  90. {
  91. /*
  92. * Liste des paiements (les anciens paiements ne sont pas vus par cette requete car, sur les
  93. * vieilles versions, ils n'etaient pas lies via paiement_facture. On les ajoute plus loin)
  94. */
  95. $sql = "SELECT date_format(p.datep,'%Y-%m') as dm, sum(pf.amount) as amount_ttc";
  96. $sql.= " FROM ".MAIN_DB_PREFIX."facture as f";
  97. $sql.= ", ".MAIN_DB_PREFIX."paiement_facture as pf";
  98. $sql.= ", ".MAIN_DB_PREFIX."paiement as p";
  99. $sql.= " WHERE p.rowid = pf.fk_paiement";
  100. $sql.= " AND pf.fk_facture = f.rowid";
  101. }
  102. $sql.= " AND f.entity = ".$conf->entity;
  103. if ($socid) $sql.= " AND f.fk_soc = ".$socid;
  104. $sql.= " GROUP BY dm";
  105. $sql.= " ORDER BY dm";
  106. $result = $db->query($sql);
  107. if ($result)
  108. {
  109. $num = $db->num_rows($result);
  110. $i = 0;
  111. while ($i < $num)
  112. {
  113. $obj = $db->fetch_object($result);
  114. $cum_ht[$obj->dm] = !empty($obj->amount) ? $obj->amount : 0;
  115. $cum[$obj->dm] = $obj->amount_ttc;
  116. if ($obj->amount_ttc)
  117. {
  118. $minyearmonth=($minyearmonth?min($minyearmonth,$obj->dm):$obj->dm);
  119. $maxyearmonth=max($maxyearmonth,$obj->dm);
  120. }
  121. $i++;
  122. }
  123. $db->free($result);
  124. }
  125. else {
  126. dol_print_error($db);
  127. }
  128. // On ajoute les paiements anciennes version, non lies par paiement_facture (very old versions)
  129. if ($modecompta != 'CREANCES-DETTES')
  130. {
  131. $sql = "SELECT date_format(p.datep,'%Y-%m') as dm, sum(p.amount) as amount_ttc";
  132. $sql.= " FROM ".MAIN_DB_PREFIX."bank as b";
  133. $sql.= ", ".MAIN_DB_PREFIX."bank_account as ba";
  134. $sql.= ", ".MAIN_DB_PREFIX."paiement as p";
  135. $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf ON p.rowid = pf.fk_paiement";
  136. $sql.= " WHERE pf.rowid IS NULL";
  137. $sql.= " AND p.fk_bank = b.rowid";
  138. $sql.= " AND b.fk_account = ba.rowid";
  139. $sql.= " AND ba.entity IN (".getEntity('bank_account').")";
  140. $sql.= " GROUP BY dm";
  141. $sql.= " ORDER BY dm";
  142. $result = $db->query($sql);
  143. if ($result)
  144. {
  145. $num = $db->num_rows($result);
  146. $i = 0;
  147. while ($i < $num)
  148. {
  149. $obj = $db->fetch_object($result);
  150. $cum[$obj->dm] += $obj->amount_ttc;
  151. if ($obj->amount_ttc)
  152. {
  153. $minyearmonth=($minyearmonth?min($minyearmonth,$obj->dm):$obj->dm);
  154. $maxyearmonth=max($maxyearmonth,$obj->dm);
  155. }
  156. $i++;
  157. }
  158. }
  159. else
  160. {
  161. dol_print_error($db);
  162. }
  163. }
  164. $moreforfilter='';
  165. print '<div class="div-table-responsive">';
  166. print '<table class="tagtable liste'.($moreforfilter?" listwithfilterbefore":"").'">'."\n";
  167. print '<tr class="liste_titre"><td>&nbsp;</td>';
  168. for ($annee = $year_start ; $annee <= $year_end ; $annee++)
  169. {
  170. if ($modecompta == 'CREANCES-DETTES') print '<td align="center" width="10%" colspan="3">';
  171. else print '<td align="center" width="10%" colspan="2" class="borderrightlight">';
  172. print '<a href="casoc.php?year='.$annee.'">';
  173. print $annee;
  174. if ($conf->global->SOCIETE_FISCAL_MONTH_START > 1) print '-'.($annee+1);
  175. print '</a></td>';
  176. if ($annee != $year_end) print '<td width="15">&nbsp;</td>';
  177. }
  178. print '</tr>';
  179. print '<tr class="liste_titre"><td class="liste_titre">'.$langs->trans("Month").'</td>';
  180. for ($annee = $year_start ; $annee <= $year_end ; $annee++)
  181. {
  182. if ($modecompta == 'CREANCES-DETTES') print '<td class="liste_titre" align="right">'.$langs->trans("AmountHT").'</td>';
  183. print '<td class="liste_titre" align="right">'.$langs->trans("AmountTTC").'</td>';
  184. print '<td class="liste_titre" align="right" class="borderrightlight">'.$langs->trans("Delta").'</td>';
  185. if ($annee != $year_end) print '<td class="liste_titre" width="15">&nbsp;</td>';
  186. }
  187. print '</tr>';
  188. $now_show_delta=0;
  189. $minyear=substr($minyearmonth,0,4);
  190. $maxyear=substr($maxyearmonth,0,4);
  191. $nowyear=strftime("%Y",dol_now());
  192. $nowyearmonth=strftime("%Y-%m",dol_now());
  193. $maxyearmonth=max($maxyearmonth,$nowyearmonth);
  194. $now=dol_now();
  195. $casenow = dol_print_date($now,"%Y-%m");
  196. // Loop on each month
  197. $nb_mois_decalage = $conf->global->SOCIETE_FISCAL_MONTH_START?($conf->global->SOCIETE_FISCAL_MONTH_START-1):0;
  198. for ($mois = 1+$nb_mois_decalage ; $mois <= 12+$nb_mois_decalage ; $mois++)
  199. {
  200. $mois_modulo = $mois;// ajout
  201. if($mois>12){$mois_modulo = $mois-12;} // ajout
  202. print '<tr class="oddeven">';
  203. print "<td>".dol_print_date(dol_mktime(12,0,0,$mois_modulo,1,2000),"%B")."</td>";
  204. for ($annee = $year_start -1 ; $annee <= $year_end ; $annee++) // We start one year before to have data to be able to make delta
  205. {
  206. $annee_decalage=$annee;
  207. if ($mois>12) {$annee_decalage=$annee+1;}
  208. $case = dol_print_date(dol_mktime(1,1,1,$mois_modulo,1,$annee_decalage),"%Y-%m");
  209. $caseprev = dol_print_date(dol_mktime(1,1,1,$mois_modulo,1,$annee_decalage-1),"%Y-%m");
  210. if ($annee >= $year_start)
  211. {
  212. if ($modecompta == 'CREANCES-DETTES') {
  213. // Valeur CA du mois w/o VAT
  214. print '<td align="right">';
  215. if ($cum_ht[$case])
  216. {
  217. $now_show_delta=1; // On a trouve le premier mois de la premiere annee generant du chiffre.
  218. print '<a href="casoc.php?year='.$annee_decalage.'&month='.$mois_modulo.($modecompta?'&modecompta='.$modecompta:'').'">'.price($cum_ht[$case],1).'</a>';
  219. }
  220. else
  221. {
  222. if ($minyearmonth < $case && $case <= max($maxyearmonth,$nowyearmonth)) { print '0'; }
  223. else { print '&nbsp;'; }
  224. }
  225. print "</td>";
  226. }
  227. // Valeur CA du mois
  228. print '<td align="right">';
  229. if ($cum[$case])
  230. {
  231. $now_show_delta=1; // On a trouve le premier mois de la premiere annee generant du chiffre.
  232. print '<a href="casoc.php?year='.$annee_decalage.'&month='.$mois_modulo.($modecompta?'&modecompta='.$modecompta:'').'">'.price($cum[$case],1).'</a>';
  233. }
  234. else
  235. {
  236. if ($minyearmonth < $case && $case <= max($maxyearmonth,$nowyearmonth)) { print '0'; }
  237. else { print '&nbsp;'; }
  238. }
  239. print "</td>";
  240. // Pourcentage du mois
  241. if ($annee_decalage > $minyear && $case <= $casenow)
  242. {
  243. if ($cum[$caseprev] && $cum[$case])
  244. {
  245. $percent=(round(($cum[$case]-$cum[$caseprev])/$cum[$caseprev],4)*100);
  246. //print "X $cum[$case] - $cum[$caseprev] - $cum[$caseprev] - $percent X";
  247. print '<td align="right" class="borderrightlight">'.($percent>=0?"+$percent":"$percent").'%</td>';
  248. }
  249. if ($cum[$caseprev] && ! $cum[$case])
  250. {
  251. print '<td align="right" class="borderrightlight">-100%</td>';
  252. }
  253. if (! $cum[$caseprev] && $cum[$case])
  254. {
  255. //print '<td align="right">+Inf%</td>';
  256. print '<td align="right" class="borderrightlight">-</td>';
  257. }
  258. if (isset($cum[$caseprev]) && ! $cum[$caseprev] && ! $cum[$case])
  259. {
  260. print '<td align="right" class="borderrightlight">+0%</td>';
  261. }
  262. if (! isset($cum[$caseprev]) && ! $cum[$case])
  263. {
  264. print '<td align="right" class="borderrightlight">-</td>';
  265. }
  266. }
  267. else
  268. {
  269. print '<td align="right" class="borderrightlight">';
  270. if ($minyearmonth <= $case && $case <= $maxyearmonth) { print '-'; }
  271. else { print '&nbsp;'; }
  272. print '</td>';
  273. }
  274. if ($annee_decalage != $year_end) print '<td width="15">&nbsp;</td>';
  275. }
  276. $total_ht[$annee]+=!empty($cum_ht[$case]) ? $cum_ht[$case] : 0;
  277. $total[$annee]+=$cum[$case];
  278. }
  279. print '</tr>';
  280. }
  281. /*
  282. for ($mois = 1 ; $mois < 13 ; $mois++)
  283. {
  284. print '<tr class="oddeven">';
  285. print "<td>".dol_print_date(dol_mktime(12,0,0,$mois,1,2000),"%B")."</td>";
  286. for ($annee = $year_start ; $annee <= $year_end ; $annee++)
  287. {
  288. $casenow = dol_print_date(mktime(),"%Y-%m");
  289. $case = dol_print_date(dol_mktime(1,1,1,$mois,1,$annee),"%Y-%m");
  290. $caseprev = dol_print_date(dol_mktime(1,1,1,$mois,1,$annee-1),"%Y-%m");
  291. // Valeur CA du mois
  292. print '<td align="right">';
  293. if ($cum[$case])
  294. {
  295. $now_show_delta=1; // On a trouve le premier mois de la premiere annee generant du chiffre.
  296. print '<a href="casoc.php?year='.$annee.'&month='.$mois.'">'.price($cum[$case],1).'</a>';
  297. }
  298. else
  299. {
  300. if ($minyearmonth < $case && $case <= max($maxyearmonth,$nowyearmonth)) { print '0'; }
  301. else { print '&nbsp;'; }
  302. }
  303. print "</td>";
  304. // Pourcentage du mois
  305. if ($annee > $minyear && $case <= $casenow) {
  306. if ($cum[$caseprev] && $cum[$case])
  307. {
  308. $percent=(round(($cum[$case]-$cum[$caseprev])/$cum[$caseprev],4)*100);
  309. //print "X $cum[$case] - $cum[$caseprev] - $cum[$caseprev] - $percent X";
  310. print '<td align="right">'.($percent>=0?"+$percent":"$percent").'%</td>';
  311. }
  312. if ($cum[$caseprev] && ! $cum[$case])
  313. {
  314. print '<td align="right">-100%</td>';
  315. }
  316. if (! $cum[$caseprev] && $cum[$case])
  317. {
  318. print '<td align="right">+Inf%</td>';
  319. }
  320. if (! $cum[$caseprev] && ! $cum[$case])
  321. {
  322. print '<td align="right">+0%</td>';
  323. }
  324. }
  325. else
  326. {
  327. print '<td align="right">';
  328. if ($minyearmonth <= $case && $case <= $maxyearmonth) { print '-'; }
  329. else { print '&nbsp;'; }
  330. print '</td>';
  331. }
  332. $total[$annee]+=$cum[$case];
  333. if ($annee != $year_end) print '<td width="15">&nbsp;</td>';
  334. }
  335. print '</tr>';
  336. }
  337. */
  338. // Affiche total
  339. print '<tr class="liste_total"><td>'.$langs->trans("Total").'</td>';
  340. for ($annee = $year_start ; $annee <= $year_end ; $annee++)
  341. {
  342. if ($modecompta == 'CREANCES-DETTES') {
  343. // Montant total HT
  344. if ($total_ht[$annee] || ($annee >= $minyear && $annee <= max($nowyear,$maxyear)))
  345. {
  346. print '<td align="right" class="nowrap">'.($total_ht[$annee]?price($total_ht[$annee]):"0")."</td>";
  347. }
  348. else
  349. {
  350. print '<td>&nbsp;</td>';
  351. }
  352. }
  353. // Montant total
  354. if ($total[$annee] || ($annee >= $minyear && $annee <= max($nowyear,$maxyear)))
  355. {
  356. print '<td align="right" class="nowrap">'.($total[$annee]?price($total[$annee]):"0")."</td>";
  357. }
  358. else
  359. {
  360. print '<td>&nbsp;</td>';
  361. }
  362. // Pourcentage total
  363. if ($annee > $minyear && $annee <= max($nowyear,$maxyear))
  364. {
  365. if ($total[$annee-1] && $total[$annee]) {
  366. $percent=(round(($total[$annee]-$total[$annee-1])/$total[$annee-1],4)*100);
  367. print '<td align="right" class="nowrap borderrightlight">'.($percent>=0?"+$percent":"$percent").'%</td>';
  368. }
  369. if ($total[$annee-1] && ! $total[$annee])
  370. {
  371. print '<td align="right" class="borderrightlight">-100%</td>';
  372. }
  373. if (! $total[$annee-1] && $total[$annee])
  374. {
  375. print '<td align="right" class="borderrightlight">+zzzz'.$total[$annee-1].$langs->trans('Inf').'%</td>';
  376. }
  377. if (! $total[$annee-1] && ! $total[$annee])
  378. {
  379. print '<td align="right" class="borderrightlight">+0%</td>';
  380. }
  381. }
  382. else
  383. {
  384. print '<td align="right" class="borderrightlight">';
  385. if ($total[$annee] || ($minyear <= $annee && $annee <= max($nowyear,$maxyear))) { print '-'; }
  386. else { print '&nbsp;'; }
  387. print '</td>';
  388. }
  389. if ($annee != $year_end) print '<td width="15">&nbsp;</td>';
  390. }
  391. print "</tr>\n";
  392. print "</table>";
  393. print '</div>';
  394. /*
  395. * En mode recettes/depenses, on complete avec les montants factures non regles
  396. * et les propales signees mais pas facturees. En effet, en recettes-depenses,
  397. * on comptabilise lorsque le montant est sur le compte donc il est interessant
  398. * d'avoir une vision de ce qui va arriver.
  399. */
  400. /*
  401. Je commente toute cette partie car les chiffres affichees sont faux - Eldy.
  402. En attendant correction.
  403. if ($modecompta != 'CREANCES-DETTES')
  404. {
  405. print '<br><table width="100%" class="noborder">';
  406. // Factures non reglees
  407. // Y a bug ici. Il faut prendre le reste a payer et non le total des factures non reglees !
  408. $sql = "SELECT f.facnumber, f.rowid, s.nom, s.rowid as socid, f.total_ttc, sum(pf.amount) as am";
  409. $sql .= " FROM ".MAIN_DB_PREFIX."societe as s,".MAIN_DB_PREFIX."facture as f left join ".MAIN_DB_PREFIX."paiement_facture as pf on f.rowid=pf.fk_facture";
  410. $sql .= " WHERE s.rowid = f.fk_soc AND f.paye = 0 AND f.fk_statut = 1";
  411. if ($socid)
  412. {
  413. $sql .= " AND f.fk_soc = $socid";
  414. }
  415. $sql .= " GROUP BY f.facnumber,f.rowid,s.nom, s.rowid, f.total_ttc";
  416. $resql=$db->query($sql);
  417. if ($resql)
  418. {
  419. $num = $db->num_rows($resql);
  420. $i = 0;
  421. if ($num)
  422. {
  423. $var = True;
  424. $total_ttc_Rac = $totalam_Rac = $total_Rac = 0;
  425. while ($i < $num)
  426. {
  427. $obj = $db->fetch_object($resql);
  428. $total_ttc_Rac += $obj->total_ttc;
  429. $totalam_Rac += $obj->am;
  430. $i++;
  431. }
  432. print "<tr ".$bc[$var]."><td align=\"right\" colspan=\"5\"><i>Facture a encaisser : </i></td><td align=\"right\"><i>".price($total_ttc_Rac)."</i></td><td colspan=\"5\"><-- bug ici car n'exclut pas le deja r�gl� des factures partiellement r�gl�es</td></tr>";
  433. }
  434. $db->free($resql);
  435. }
  436. else
  437. {
  438. dol_print_error($db);
  439. }
  440. */
  441. /*
  442. *
  443. * Propales signees, et non facturees
  444. *
  445. */
  446. /*
  447. Je commente toute cette partie car les chiffres affichees sont faux - Eldy.
  448. En attendant correction.
  449. $sql = "SELECT sum(f.total) as tot_fht,sum(f.total_ttc) as tot_fttc, p.rowid, p.ref, s.nom, s.rowid as socid, p.total_ht, p.total_ttc
  450. FROM ".MAIN_DB_PREFIX."commande AS p, ".MAIN_DB_PREFIX."societe AS s
  451. LEFT JOIN ".MAIN_DB_PREFIX."co_fa AS co_fa ON co_fa.fk_commande = p.rowid
  452. LEFT JOIN ".MAIN_DB_PREFIX."facture AS f ON co_fa.fk_facture = f.rowid
  453. WHERE p.fk_soc = s.rowid
  454. AND p.fk_statut >=1
  455. AND p.facture =0";
  456. if ($socid)
  457. {
  458. $sql .= " AND f.fk_soc = ".$socid;
  459. }
  460. $sql .= " GROUP BY p.rowid";
  461. $resql=$db->query($sql);
  462. if ($resql)
  463. {
  464. $num = $db->num_rows($resql);
  465. $i = 0;
  466. if ($num)
  467. {
  468. $var = True;
  469. $total_pr = 0;
  470. while ($i < $num)
  471. {
  472. $obj = $db->fetch_object($resql);
  473. $total_pr += $obj->total_ttc-$obj->tot_fttc;
  474. $i++;
  475. }
  476. print "<tr ".$bc[$var]."><td align=\"right\" colspan=\"5\"><i>Signe et non facture:</i></td><td align=\"right\"><i>".price($total_pr)."</i></td><td colspan=\"5\"><-- bug ici, ca devrait exclure le deja facture</td></tr>";
  477. }
  478. $db->free($resql);
  479. }
  480. else
  481. {
  482. dol_print_error($db);
  483. }
  484. print "<tr ".$bc[$var]."><td align=\"right\" colspan=\"5\"><i>Total CA previsionnel : </i></td><td align=\"right\"><i>".price($total_CA)."</i></td><td colspan=\"3\"><-- bug ici car bug sur les 2 precedents</td></tr>";
  485. }
  486. print "</table>";
  487. */
  488. llxFooter();
  489. $db->close();