supplier_turnover.php 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490
  1. <?php
  2. /* Copyright (C) 2020 Maxime Kohlhaas <maxime@atm-consulting.fr>
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  16. */
  17. /**
  18. * \file htdocs/compta/stats/supplier_turnover.php
  19. * \brief Page reporting purchase turnover
  20. */
  21. // Load Dolibarr environment
  22. require '../../main.inc.php';
  23. require_once DOL_DOCUMENT_ROOT.'/core/lib/report.lib.php';
  24. require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
  25. // Load translation files required by the page
  26. $langs->loadLangs(array('compta', 'bills'));
  27. $date_startday = GETPOST('date_startday', 'int');
  28. $date_startmonth = GETPOST('date_startmonth', 'int');
  29. $date_startyear = GETPOST('date_startyear', 'int');
  30. $date_endday = GETPOST('date_endday', 'int');
  31. $date_endmonth = GETPOST('date_endmonth', 'int');
  32. $date_endyear = GETPOST('date_endyear', 'int');
  33. $nbofyear = 4;
  34. // Date range
  35. $year = GETPOST('year', 'int');
  36. if (empty($year)) {
  37. $year_current = dol_print_date(dol_now(), "%Y");
  38. $month_current = dol_print_date(dol_now(), "%m");
  39. $year_start = $year_current - ($nbofyear - 1);
  40. } else {
  41. $year_current = $year;
  42. $month_current = dol_print_date(dol_now(), "%m");
  43. $year_start = $year - ($nbofyear - 1);
  44. }
  45. $date_start = dol_mktime(0, 0, 0, $date_startmonth, $date_startday, $date_startyear, 'tzserver'); // We use timezone of server so report is same from everywhere
  46. $date_end = dol_mktime(23, 59, 59, $date_endmonth, $date_endday, $date_endyear, 'tzserver'); // We use timezone of server so report is same from everywhere
  47. // We define date_start and date_end
  48. if (empty($date_start) || empty($date_end)) { // We define date_start and date_end
  49. $q = GETPOST("q") ?GETPOST("q") : 0;
  50. if ($q == 0) {
  51. // We define date_start and date_end
  52. $year_end = $year_start + ($nbofyear - 1);
  53. $month_start = GETPOSTISSET("month") ? GETPOST("month", 'int') : ($conf->global->SOCIETE_FISCAL_MONTH_START ? $conf->global->SOCIETE_FISCAL_MONTH_START : 1);
  54. if (!GETPOST('month')) {
  55. if (!GETPOST("year") && $month_start > $month_current) {
  56. $year_start--;
  57. $year_end--;
  58. }
  59. $month_end = $month_start - 1;
  60. if ($month_end < 1) {
  61. $month_end = 12;
  62. } else {
  63. $year_end++;
  64. }
  65. } else {
  66. $month_end = $month_start;
  67. }
  68. $date_start = dol_get_first_day($year_start, $month_start, false);
  69. $date_end = dol_get_last_day($year_end, $month_end, false);
  70. }
  71. if ($q == 1) {
  72. $date_start = dol_get_first_day($year_start, 1, false);
  73. $date_end = dol_get_last_day($year_start, 3, false);
  74. }
  75. if ($q == 2) {
  76. $date_start = dol_get_first_day($year_start, 4, false);
  77. $date_end = dol_get_last_day($year_start, 6, false);
  78. }
  79. if ($q == 3) {
  80. $date_start = dol_get_first_day($year_start, 7, false);
  81. $date_end = dol_get_last_day($year_start, 9, false);
  82. }
  83. if ($q == 4) {
  84. $date_start = dol_get_first_day($year_start, 10, false);
  85. $date_end = dol_get_last_day($year_start, 12, false);
  86. }
  87. }
  88. $userid = GETPOST('userid', 'int');
  89. $socid = GETPOST('socid', 'int');
  90. $tmps = dol_getdate($date_start);
  91. $year_start = $tmps['year'];
  92. $tmpe = dol_getdate($date_end);
  93. $year_end = $tmpe['year'];
  94. $nbofyear = ($year_end - $year_start) + 1;
  95. // Define modecompta ('CREANCES-DETTES' or 'RECETTES-DEPENSES' or 'BOOKKEEPING')
  96. $modecompta = $conf->global->ACCOUNTING_MODE;
  97. if (isModEnabled('accounting')) {
  98. $modecompta = 'BOOKKEEPING';
  99. }
  100. if (GETPOST("modecompta")) {
  101. $modecompta = GETPOST("modecompta", 'alpha');
  102. }
  103. // Security check
  104. if ($user->socid > 0) {
  105. $socid = $user->socid;
  106. }
  107. if (isModEnabled('comptabilite')) {
  108. $result = restrictedArea($user, 'compta', '', '', 'resultat');
  109. }
  110. if (isModEnabled('accounting')) {
  111. $result = restrictedArea($user, 'accounting', '', '', 'comptarapport');
  112. }
  113. /*
  114. * View
  115. */
  116. llxHeader();
  117. $form = new Form($db);
  118. // TODO Report from bookkeeping not yet available, so we switch on report on business events
  119. if ($modecompta == "BOOKKEEPING") {
  120. $modecompta = "CREANCES-DETTES";
  121. }
  122. if ($modecompta == "BOOKKEEPINGCOLLECTED") {
  123. $modecompta = "RECETTES-DEPENSES";
  124. }
  125. // Affiche en-tete du rapport
  126. if ($modecompta == "CREANCES-DETTES") {
  127. $name = $langs->trans("PurchaseTurnover");
  128. $calcmode = $langs->trans("CalcModeDebt");
  129. if (isModEnabled('accounting')) {
  130. $calcmode .= '<br>('.$langs->trans("SeeReportInBookkeepingMode", '{link1}', '{link2}').')';
  131. $calcmode = str_replace('{link1}', '<a href="'.$_SERVER["PHP_SELF"].'?year_start='.$year_start.'&modecompta=BOOKKEEPING">', $calcmode);
  132. $calcmode = str_replace('{link2}', '</a>', $calcmode);
  133. }
  134. $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>" : "");
  135. $description = $langs->trans("RulesPurchaseTurnoverDue");
  136. //$exportlink=$langs->trans("NotYetAvailable");
  137. } elseif ($modecompta == "RECETTES-DEPENSES") {
  138. $name = $langs->trans("PurchaseTurnoverCollected");
  139. $calcmode = $langs->trans("CalcModeEngagement");
  140. $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>" : "");
  141. $description = $langs->trans("RulesPurchaseTurnoverIn");
  142. //$exportlink=$langs->trans("NotYetAvailable");
  143. } elseif ($modecompta == "BOOKKEEPING") {
  144. $name = $langs->trans("PurchaseTurnover");
  145. $calcmode = $langs->trans("CalcModeBookkeeping");
  146. $calcmode .= '<br>('.$langs->trans("SeeReportInDueDebtMode", '{link1}', '{link2}').')';
  147. $calcmode = str_replace('{link1}', '<a href="'.$_SERVER["PHP_SELF"].'?year_start='.$year_start.'&modecompta=CREANCES-DETTES">', $calcmode);
  148. $calcmode = str_replace('{link2}', '</a>', $calcmode);
  149. $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>" : "");
  150. $description = $langs->trans("RulesPurchaseTurnoverOfExpenseAccounts");
  151. //$exportlink=$langs->trans("NotYetAvailable");
  152. } elseif ($modecompta == "BOOKKEEPINGCOLLECTED") {
  153. $name = $langs->trans("PurchaseTurnoverCollected");
  154. $calcmode = $langs->trans("CalcModeBookkeeping");
  155. $calcmode .= '<br>('.$langs->trans("SeeReportInDueDebtMode", '{link1}', '{link2}').')';
  156. $calcmode = str_replace('{link1}', '<a href="'.$_SERVER["PHP_SELF"].'?year_start='.$year_start.'&modecompta=RECETTES-DEPENSES">', $calcmode);
  157. $calcmode = str_replace('{link2}', '</a>', $calcmode);
  158. $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>" : "");
  159. $description = $langs->trans("RulesPurchaseTurnoverCollectedOfExpenseAccounts");
  160. //$exportlink=$langs->trans("NotYetAvailable");
  161. }
  162. $builddate = dol_now();
  163. $period = $form->selectDate($date_start, 'date_start', 0, 0, 0, '', 1, 0, 0, '', '', '', '', 1, '', '', 'tzserver');
  164. $period .= ' - ';
  165. $period .= $form->selectDate($date_end, 'date_end', 0, 0, 0, '', 1, 0, 0, '', '', '', '', 1, '', '', 'tzserver');
  166. $moreparam = array();
  167. if (!empty($modecompta)) {
  168. $moreparam['modecompta'] = $modecompta;
  169. }
  170. $exportlink = '';
  171. report_header($name, '', $period, $periodlink, $description, $builddate, $exportlink, $moreparam, $calcmode);
  172. if (isModEnabled('accounting') && $modecompta != 'BOOKKEEPING') {
  173. print info_admin($langs->trans("WarningReportNotReliable"), 0, 0, 1);
  174. }
  175. if ($modecompta == 'CREANCES-DETTES') {
  176. $sql = "SELECT date_format(f.datef,'%Y-%m') as dm, sum(f.total_ht) as amount, sum(f.total_ttc) as amount_ttc";
  177. $sql .= " FROM ".MAIN_DB_PREFIX."facture_fourn as f";
  178. $sql .= " WHERE f.fk_statut in (1,2)";
  179. $sql .= " AND f.type IN (0,2)";
  180. $sql .= " AND f.entity IN (".getEntity('supplier_invoice').")";
  181. if ($socid) {
  182. $sql .= " AND f.fk_soc = ".((int) $socid);
  183. }
  184. } elseif ($modecompta == "RECETTES-DEPENSES") {
  185. $sql = "SELECT date_format(p.datep,'%Y-%m') as dm, sum(pf.amount) as amount_ttc";
  186. $sql .= " FROM ".MAIN_DB_PREFIX."facture_fourn as f";
  187. $sql .= ", ".MAIN_DB_PREFIX."paiementfourn_facturefourn as pf";
  188. $sql .= ", ".MAIN_DB_PREFIX."paiementfourn as p";
  189. $sql .= " WHERE p.rowid = pf.fk_paiementfourn";
  190. $sql .= " AND pf.fk_facturefourn = f.rowid";
  191. $sql .= " AND f.entity IN (".getEntity('supplier_invoice').")";
  192. if ($socid) {
  193. $sql .= " AND f.fk_soc = ".((int) $socid);
  194. }
  195. } elseif ($modecompta == "BOOKKEEPING") {
  196. $pcgverid = $conf->global->CHARTOFACCOUNTS;
  197. $pcgvercode = dol_getIdFromCode($db, $pcgverid, 'accounting_system', 'rowid', 'pcg_version');
  198. if (empty($pcgvercode)) {
  199. $pcgvercode = $pcgverid;
  200. }
  201. $sql = "SELECT date_format(b.doc_date, '%Y-%m') as dm, sum(b.debit - b.credit) as amount_ttc";
  202. $sql .= " FROM ".MAIN_DB_PREFIX."accounting_bookkeeping as b,";
  203. $sql .= " ".MAIN_DB_PREFIX."accounting_account as aa";
  204. $sql .= " WHERE b.entity = ".$conf->entity; // In module double party accounting, we never share entities
  205. $sql .= " AND b.doc_type = 'supplier_invoice'";
  206. $sql .= " AND b.numero_compte = aa.account_number";
  207. $sql .= " AND aa.entity = ".$conf->entity;
  208. $sql .= " AND aa.fk_pcg_version = '".$db->escape($pcgvercode)."'";
  209. $sql .= " AND aa.pcg_type = 'EXPENSE'"; // TODO Be able to use a custom group
  210. }
  211. //print $sql;
  212. $sql .= " GROUP BY dm";
  213. $sql .= " ORDER BY dm";
  214. // TODO Add a filter on $date_start and $date_end to reduce quantity on data
  215. //print $sql;
  216. $minyearmonth = $maxyearmonth = 0;
  217. $result = $db->query($sql);
  218. if ($result) {
  219. $num = $db->num_rows($result);
  220. $i = 0;
  221. while ($i < $num) {
  222. $obj = $db->fetch_object($result);
  223. $cum_ht[$obj->dm] = !empty($obj->amount) ? $obj->amount : 0;
  224. $cum[$obj->dm] = $obj->amount_ttc;
  225. if ($obj->amount_ttc) {
  226. $minyearmonth = ($minyearmonth ? min($minyearmonth, $obj->dm) : $obj->dm);
  227. $maxyearmonth = max($maxyearmonth, $obj->dm);
  228. }
  229. $i++;
  230. }
  231. $db->free($result);
  232. } else {
  233. dol_print_error($db);
  234. }
  235. $moreforfilter = '';
  236. print '<div class="div-table-responsive">';
  237. print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
  238. print '<tr class="liste_titre"><td>&nbsp;</td>';
  239. for ($annee = $year_start; $annee <= $year_end; $annee++) {
  240. if ($modecompta == 'CREANCES-DETTES') {
  241. print '<td align="center" width="10%" colspan="3">';
  242. } else {
  243. print '<td align="center" width="10%" colspan="2" class="borderrightlight">';
  244. }
  245. if ($modecompta != 'BOOKKEEPING') {
  246. print '<a href="supplier_turnover_by_thirdparty.php?year='.$annee.($modecompta ? '&modecompta='.$modecompta : '').'">';
  247. }
  248. print $annee;
  249. if ($conf->global->SOCIETE_FISCAL_MONTH_START > 1) {
  250. print '-'.($annee + 1);
  251. }
  252. if ($modecompta != 'BOOKKEEPING') {
  253. print '</a>';
  254. }
  255. print '</td>';
  256. if ($annee != $year_end) {
  257. print '<td width="15">&nbsp;</td>';
  258. }
  259. }
  260. print '</tr>';
  261. print '<tr class="liste_titre"><td class="liste_titre">'.$langs->trans("Month").'</td>';
  262. for ($annee = $year_start; $annee <= $year_end; $annee++) {
  263. if ($modecompta == 'CREANCES-DETTES') {
  264. print '<td class="liste_titre right">'.$langs->trans("AmountHT").'</td>';
  265. }
  266. print '<td class="liste_titre right">';
  267. if ($modecompta == "BOOKKEEPING") {
  268. print $langs->trans("Amount");
  269. } else {
  270. print $langs->trans("AmountTTC");
  271. }
  272. print '</td>';
  273. print '<td class="liste_titre right borderrightlight">'.$langs->trans("Delta").'</td>';
  274. if ($annee != $year_end) {
  275. print '<td class="liste_titre" width="15">&nbsp;</td>';
  276. }
  277. }
  278. print '</tr>';
  279. $now_show_delta = 0;
  280. $minyear = substr($minyearmonth, 0, 4);
  281. $maxyear = substr($maxyearmonth, 0, 4);
  282. $nowyear = dol_print_date(dol_now('gmt'), "%Y", 'gmt');
  283. $nowyearmonth = strftime("%Y-%m", dol_now());
  284. $maxyearmonth = max($maxyearmonth, $nowyearmonth);
  285. $now = dol_now();
  286. $casenow = dol_print_date($now, "%Y-%m");
  287. // Loop on each month
  288. $nb_mois_decalage = $conf->global->SOCIETE_FISCAL_MONTH_START ? ($conf->global->SOCIETE_FISCAL_MONTH_START - 1) : 0;
  289. for ($mois = 1 + $nb_mois_decalage; $mois <= 12 + $nb_mois_decalage; $mois++) {
  290. $mois_modulo = $mois; // ajout
  291. if ($mois > 12) {
  292. $mois_modulo = $mois - 12;
  293. } // ajout
  294. if ($year_start == $year_end) {
  295. if ($mois > $date_endmonth && $year_end >= $date_endyear) {
  296. break;
  297. }
  298. }
  299. print '<tr class="oddeven">';
  300. // Month
  301. print "<td>".dol_print_date(dol_mktime(12, 0, 0, $mois_modulo, 1, 2000), "%B")."</td>";
  302. for ($annee = $year_start - 1; $annee <= $year_end; $annee++) { // We start one year before to have data to be able to make delta
  303. $annee_decalage = $annee;
  304. if ($mois > 12) {
  305. $annee_decalage = $annee + 1;
  306. }
  307. $case = dol_print_date(dol_mktime(1, 1, 1, $mois_modulo, 1, $annee_decalage), "%Y-%m");
  308. $caseprev = dol_print_date(dol_mktime(1, 1, 1, $mois_modulo, 1, $annee_decalage - 1), "%Y-%m");
  309. if ($annee >= $year_start) { // We ignore $annee < $year_start, we loop on it to be able to make delta, nothing is output.
  310. if ($modecompta == 'CREANCES-DETTES') {
  311. // Valeur CA du mois w/o VAT
  312. print '<td class="right">';
  313. if (!empty($cum_ht[$case])) {
  314. $now_show_delta = 1; // On a trouve le premier mois de la premiere annee generant du chiffre.
  315. print '<a href="supplier_turnover_by_thirdparty.php?year='.$annee_decalage.'&month='.$mois_modulo.($modecompta ? '&modecompta='.$modecompta : '').'">'.price($cum_ht[$case], 1).'</a>';
  316. } else {
  317. if ($minyearmonth < $case && $case <= max($maxyearmonth, $nowyearmonth)) {
  318. print '0';
  319. } else {
  320. print '&nbsp;';
  321. }
  322. }
  323. print "</td>";
  324. }
  325. // Valeur CA du mois
  326. print '<td class="right">';
  327. if (!empty($cum[$case])) {
  328. $now_show_delta = 1; // On a trouve le premier mois de la premiere annee generant du chiffre.
  329. if ($modecompta != 'BOOKKEEPING') {
  330. print '<a href="supplier_turnover_by_thirdparty.php?year='.$annee_decalage.'&month='.$mois_modulo.($modecompta ? '&modecompta='.$modecompta : '').'">';
  331. }
  332. print price($cum[$case], 1);
  333. if ($modecompta != 'BOOKKEEPING') {
  334. print '</a>';
  335. }
  336. } else {
  337. if ($minyearmonth < $case && $case <= max($maxyearmonth, $nowyearmonth)) {
  338. print '0';
  339. } else {
  340. print '&nbsp;';
  341. }
  342. }
  343. print "</td>";
  344. // Pourcentage du mois
  345. if ($annee_decalage > $minyear && $case <= $casenow) {
  346. if (!empty($cum[$caseprev]) && !empty($cum[$case])) {
  347. $percent = (round(($cum[$case] - $cum[$caseprev]) / $cum[$caseprev], 4) * 100);
  348. //print "X $cum[$case] - $cum[$caseprev] - $cum[$caseprev] - $percent X";
  349. print '<td class="borderrightlight right">'.($percent >= 0 ? "+$percent" : "$percent").'%</td>';
  350. }
  351. if (!empty($cum[$caseprev]) && empty($cum[$case])) {
  352. print '<td class="borderrightlight right">-100%</td>';
  353. }
  354. if (empty($cum[$caseprev]) && !empty($cum[$case])) {
  355. //print '<td class="right">+Inf%</td>';
  356. print '<td class="borderrightlight right">-</td>';
  357. }
  358. if (isset($cum[$caseprev]) && empty($cum[$caseprev]) && empty($cum[$case])) {
  359. print '<td class="borderrightlight right">+0%</td>';
  360. }
  361. if (!isset($cum[$caseprev]) && empty($cum[$case])) {
  362. print '<td class="borderrightlight right">-</td>';
  363. }
  364. } else {
  365. print '<td class="borderrightlight right">';
  366. if ($minyearmonth <= $case && $case <= $maxyearmonth) {
  367. print '-';
  368. } else {
  369. print '&nbsp;';
  370. }
  371. print '</td>';
  372. }
  373. if ($annee_decalage < $year_end || ($annee_decalage == $year_end && $mois > 12 && $annee < $year_end)) {
  374. print '<td width="15">&nbsp;</td>';
  375. }
  376. }
  377. if (empty($total_ht[$annee])) {
  378. $total_ht[$annee] = ((!empty($cum_ht[$case])) ? $cum_ht[$case] : 0);
  379. } else {
  380. $total_ht[$annee] += ((!empty($cum_ht[$case])) ? $cum_ht[$case] : 0);
  381. }
  382. if (empty($total[$annee])) {
  383. $total[$annee] = (empty($cum[$case]) ? 0 : $cum[$case]);
  384. } else {
  385. $total[$annee] += (empty($cum[$case]) ? 0 : $cum[$case]);
  386. }
  387. }
  388. print '</tr>';
  389. }
  390. // Affiche total
  391. print '<tr class="liste_total"><td>'.$langs->trans("Total").'</td>';
  392. for ($annee = $year_start; $annee <= $year_end; $annee++) {
  393. if ($modecompta == 'CREANCES-DETTES') {
  394. // Montant total HT
  395. if ($total_ht[$annee] || ($annee >= $minyear && $annee <= max($nowyear, $maxyear))) {
  396. print '<td class="nowrap right">'.($total_ht[$annee] ?price($total_ht[$annee]) : "0")."</td>";
  397. } else {
  398. print '<td>&nbsp;</td>';
  399. }
  400. }
  401. // Montant total
  402. if ($total[$annee] || ($annee >= $minyear && $annee <= max($nowyear, $maxyear))) {
  403. print '<td class="nowrap right">'.($total[$annee] ?price($total[$annee]) : "0")."</td>";
  404. } else {
  405. print '<td>&nbsp;</td>';
  406. }
  407. // Pourcentage total
  408. if ($annee > $minyear && $annee <= max($nowyear, $maxyear)) {
  409. if ($total[$annee - 1] && $total[$annee]) {
  410. $percent = (round(($total[$annee] - $total[$annee - 1]) / $total[$annee - 1], 4) * 100);
  411. print '<td class="nowrap borderrightlight right">'.($percent >= 0 ? "+$percent" : "$percent").'%</td>';
  412. }
  413. if ($total[$annee - 1] && !$total[$annee]) {
  414. print '<td class="borderrightlight right">-100%</td>';
  415. }
  416. if (!$total[$annee - 1] && $total[$annee]) {
  417. print '<td class="borderrightlight right">+'.$langs->trans('Inf').'%</td>';
  418. }
  419. if (!$total[$annee - 1] && !$total[$annee]) {
  420. print '<td class="borderrightlight right">+0%</td>';
  421. }
  422. } else {
  423. print '<td class="borderrightlight right">';
  424. if ($total[$annee] || ($minyear <= $annee && $annee <= max($nowyear, $maxyear))) {
  425. print '-';
  426. } else {
  427. print '&nbsp;';
  428. }
  429. print '</td>';
  430. }
  431. if ($annee != $year_end) {
  432. print '<td width="15">&nbsp;</td>';
  433. }
  434. }
  435. print "</tr>\n";
  436. print "</table>";
  437. print '</div>';
  438. // End of page
  439. llxFooter();
  440. $db->close();