result.php 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559
  1. <?php
  2. /* Copyright (C) 2016-2017 Jamal Elbaz <jamelbaz@gmail.com>
  3. * Copyright (C) 2016 Alexandre Spangaro <aspangaro@open-dsi.fr>
  4. * Copyright (C) 2018 Laurent Destailleur <eldy@destailleur.fr>
  5. * Copyright (C) 2018 Frédéric France <frederic.france@netlogic.fr>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 3 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20. /**
  21. * \file htdocs/compta/resultat/result.php
  22. * \ingroup compta, accountancy
  23. * \brief Page for accounting result
  24. */
  25. require '../../main.inc.php';
  26. require_once DOL_DOCUMENT_ROOT.'/core/lib/accounting.lib.php';
  27. require_once DOL_DOCUMENT_ROOT.'/core/lib/report.lib.php';
  28. require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
  29. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formaccounting.class.php';
  30. require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountancycategory.class.php';
  31. // Load translation files required by the page
  32. $langs->loadLangs(array('compta','bills','donation','salaries','accountancy'));
  33. $error = 0;
  34. $mesg = '';
  35. $action = GETPOST('action','aZ09');
  36. $cat_id = GETPOST('account_category');
  37. $selectcpt = GETPOST('cpt_bk');
  38. $id = GETPOST('id', 'int');
  39. $rowid = GETPOST('rowid', 'int');
  40. $cancel = GETPOST('cancel','alpha');
  41. $showaccountdetail = GETPOST('showaccountdetail','aZ09')?GETPOST('showaccountdetail','aZ09'):'no';
  42. $date_startmonth=GETPOST('date_startmonth','int');
  43. $date_startday=GETPOST('date_startday','int');
  44. $date_startyear=GETPOST('date_startyear','int');
  45. $date_endmonth=GETPOST('date_endmonth','int');
  46. $date_endday=GETPOST('date_endday','int');
  47. $date_endyear=GETPOST('date_endyear','int');
  48. $nbofyear=1;
  49. // Date range
  50. $year=GETPOST('year','int');
  51. if (empty($year))
  52. {
  53. $year_current = strftime("%Y", dol_now());
  54. $month_current = strftime("%m", dol_now());
  55. $year_start = $year_current - ($nbofyear - 1);
  56. } else {
  57. $year_current = $year;
  58. $month_current = strftime("%m", dol_now());
  59. $year_start = $year - ($nbofyear - 1);
  60. }
  61. $date_start=dol_mktime(0, 0, 0, $date_startmonth, $date_startday, $date_startyear);
  62. $date_end=dol_mktime(23, 59, 59, $date_endmonth, $date_endday, $date_endyear);
  63. // We define date_start and date_end
  64. if (empty($date_start) || empty($date_end)) // We define date_start and date_end
  65. {
  66. $q=GETPOST("q")?GETPOST("q"):0;
  67. if ($q==0)
  68. {
  69. // We define date_start and date_end
  70. $year_end=$year_start + ($nbofyear - 1);
  71. $month_start=GETPOST("month",'int')?GETPOST("month",'int'):($conf->global->SOCIETE_FISCAL_MONTH_START?($conf->global->SOCIETE_FISCAL_MONTH_START):1);
  72. $date_startmonth = $month_start;
  73. if (! GETPOST('month'))
  74. {
  75. if (! GETPOST("year") && $month_start > $month_current)
  76. {
  77. $year_start--;
  78. $year_end--;
  79. }
  80. $month_end=$month_start-1;
  81. if ($month_end < 1) $month_end=12;
  82. else $year_end++;
  83. }
  84. else $month_end=$month_start;
  85. $date_start=dol_get_first_day($year_start,$month_start,false); $date_end=dol_get_last_day($year_end,$month_end,false);
  86. }
  87. if ($q==1) { $date_start=dol_get_first_day($year_start,1,false); $date_end=dol_get_last_day($year_start,3,false); }
  88. if ($q==2) { $date_start=dol_get_first_day($year_start,4,false); $date_end=dol_get_last_day($year_start,6,false); }
  89. if ($q==3) { $date_start=dol_get_first_day($year_start,7,false); $date_end=dol_get_last_day($year_start,9,false); }
  90. if ($q==4) { $date_start=dol_get_first_day($year_start,10,false); $date_end=dol_get_last_day($year_start,12,false); }
  91. }
  92. if (($date_start < dol_time_plus_duree($date_end, -1, 'y')) || ($date_start > $date_end))
  93. {
  94. $date_end = dol_time_plus_duree($date_start - 1, 1, 'y');
  95. }
  96. // $date_start and $date_end are defined. We force $start_year and $nbofyear
  97. $tmps=dol_getdate($date_start);
  98. $start_year = $tmps['year'];
  99. $start_month = $tmps['mon'];
  100. $tmpe=dol_getdate($date_end);
  101. $year_end = $tmpe['year'];
  102. $month_end = $tmpe['mon'];
  103. $nbofyear = ($year_end - $start_year) + 1;
  104. $date_start_previous = dol_time_plus_duree($date_start, -1, 'y');
  105. $date_end_previous = dol_time_plus_duree($date_end, -1, 'y');
  106. //var_dump($date_start." ".$date_end." ".$date_start_previous." ".$date_end_previous." ".$nbofyear);
  107. if($cat_id == 0){
  108. $cat_id = null;
  109. }
  110. // Define modecompta ('CREANCES-DETTES' or 'RECETTES-DEPENSES' or 'BOOKKEEPING')
  111. $modecompta = $conf->global->ACCOUNTING_MODE;
  112. if (! empty($conf->accounting->enabled)) $modecompta='BOOKKEEPING';
  113. if (GETPOST("modecompta")) $modecompta=GETPOST("modecompta",'alpha');
  114. // Security check
  115. if ($user->societe_id > 0)
  116. accessforbidden();
  117. if (! $user->rights->accounting->comptarapport->lire)
  118. accessforbidden();
  119. $AccCat = new AccountancyCategory($db);
  120. /*
  121. * View
  122. */
  123. $months = array(
  124. $langs->trans("JanuaryMin"),
  125. $langs->trans("FebruaryMin"),
  126. $langs->trans("MarchMin"),
  127. $langs->trans("AprilMin"),
  128. $langs->trans("MayMin"),
  129. $langs->trans("JuneMin"),
  130. $langs->trans("JulyMin"),
  131. $langs->trans("AugustMin"),
  132. $langs->trans("SeptemberMin"),
  133. $langs->trans("OctoberMin"),
  134. $langs->trans("NovemberMin"),
  135. $langs->trans("DecemberMin"),
  136. );
  137. llxheader('', $langs->trans('ReportInOut'));
  138. $formaccounting = new FormAccounting($db);
  139. $form = new Form($db);
  140. $textprevyear = '<a href="' . $_SERVER["PHP_SELF"] . '?year=' . ($start_year - 1) . '">' . img_previous() . '</a>';
  141. $textnextyear = '&nbsp;<a href="' . $_SERVER["PHP_SELF"] . '?year=' . ($start_year + 1) . '">' . img_next() . '</a>';
  142. // Affiche en-tete de rapport
  143. if ($modecompta=="CREANCES-DETTES")
  144. {
  145. $name=$langs->trans("AnnualByAccountDueDebtMode");
  146. $calcmode=$langs->trans("CalcModeDebt");
  147. $calcmode.='<br>('.$langs->trans("SeeReportInInputOutputMode",'<a href="'.$_SERVER["PHP_SELF"].'?year='.$start_year.(GETPOST("month")>0?'&month='.GETPOST("month"):'').'&modecompta=RECETTES-DEPENSES">','</a>').')';
  148. if (! empty($conf->accounting->enabled)) $calcmode.='<br>('.$langs->trans("SeeReportInBookkeepingMode",'<a href="'.$_SERVER["PHP_SELF"].'?year='.$start_year.'&modecompta=BOOKKEEPING">','</a>').')';
  149. $period=$form->selectDate($date_start, 'date_start', 0, 0, 0, '', 1, 0).' - '.$form->selectDate($date_end, 'date_end', 0, 0, 0, '', 1, 0);
  150. //$periodlink='<a href="'.$_SERVER["PHP_SELF"].'?year='.($year-1).'&modecompta='.$modecompta.'">'.img_previous().'</a> <a href="'.$_SERVER["PHP_SELF"].'?year='.($year+1).'&modecompta='.$modecompta.'">'.img_next().'</a>';
  151. $description=$langs->trans("RulesResultDue");
  152. if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) $description.= $langs->trans("DepositsAreNotIncluded");
  153. else $description.= $langs->trans("DepositsAreIncluded");
  154. $builddate=dol_now();
  155. //$exportlink=$langs->trans("NotYetAvailable");
  156. }
  157. elseif ($modecompta=="RECETTES-DEPENSES") {
  158. $name=$langs->trans("AnnualByAccountInputOutputMode");
  159. $calcmode=$langs->trans("CalcModeEngagement");
  160. $calcmode.='<br>('.$langs->trans("SeeReportInDueDebtMode",'<a href="'.$_SERVER["PHP_SELF"].'?year='.$year.(GETPOST("month")>0?'&month='.GETPOST("month"):'').'&modecompta=CREANCES-DETTES">','</a>').')';
  161. if (! empty($conf->accounting->enabled)) $calcmode.='<br>('.$langs->trans("SeeReportInBookkeepingMode",'<a href="'.$_SERVER["PHP_SELF"].'?year='.$year.'&modecompta=BOOKKEEPING">','</a>').')';
  162. $period=$form->selectDate($date_start, 'date_start', 0, 0, 0, '', 1, 0).' - '.$form->selectDate($date_end, 'date_end', 0, 0, 0, '', 1, 0);
  163. //$periodlink='<a href="'.$_SERVER["PHP_SELF"].'?year='.($year-1).'&modecompta='.$modecompta.'">'.img_previous().'</a> <a href="'.$_SERVER["PHP_SELF"].'?year='.($year+1).'&modecompta='.$modecompta.'">'.img_next().'</a>';
  164. $description=$langs->trans("RulesResultInOut");
  165. $builddate=dol_now();
  166. //$exportlink=$langs->trans("NotYetAvailable");
  167. }
  168. elseif ($modecompta=="BOOKKEEPING")
  169. {
  170. $name = $langs->trans("ReportInOut").', '.$langs->trans("ByPersonalizedAccountGroups");
  171. $calcmode=$langs->trans("CalcModeBookkeeping");
  172. //$calcmode.='<br>('.$langs->trans("SeeReportInDueDebtMode",'<a href="'.$_SERVER["PHP_SELF"].'?year_start='.$year_start.'&modecompta=CREANCES-DETTES">','</a>').')';
  173. //$calcmode.='<br>('.$langs->trans("SeeReportInInputOutputMode",'<a href="'.$_SERVER["PHP_SELF"].'?year_start='.$year_start.'&modecompta=RECETTES-DEPENSES">','</a>').')';
  174. $period=$form->selectDate($date_start, 'date_start', 0, 0, 0, '', 1, 0).' - '.$form->selectDate($date_end, 'date_end', 0, 0, 0, '', 1, 0);
  175. $arraylist=array('no'=>$langs->trans("No"), 'yes'=>$langs->trans("AccountWithNonZeroValues"), 'all'=>$langs->trans("All"));
  176. $period.=' &nbsp; &nbsp; '.$langs->trans("DetailByAccount").' '. $form->selectarray('showaccountdetail', $arraylist, $showaccountdetail, 0);
  177. $periodlink = $textprevyear . $textnextyear ;
  178. $exportlink = '';
  179. $description=$langs->trans("RulesResultBookkeepingPersonalized").
  180. $description.=' ('.$langs->trans("SeePageForSetup", DOL_URL_ROOT.'/accountancy/admin/categories_list.php?search_country_id='.$mysoc->country_id.'&mainmenu=accountancy&leftmenu=accountancy_admin', $langs->transnoentitiesnoconv("Accountancy").' / '.$langs->transnoentitiesnoconv("Setup").' / '.$langs->transnoentitiesnoconv("AccountingCategory")).')';
  181. //if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) $description.= $langs->trans("DepositsAreNotIncluded");
  182. //else $description.= $langs->trans("DepositsAreIncluded");
  183. $builddate=dol_now();
  184. }
  185. report_header($name, '', $period, $periodlink, $description, $builddate, $exportlink, array('modecompta'=>$modecompta, 'action' => ''), $calcmode);
  186. if (! empty($conf->accounting->enabled) && $modecompta != 'BOOKKEEPING')
  187. {
  188. print info_admin($langs->trans("WarningReportNotReliable"), 0, 0, 1);
  189. }
  190. $moreforfilter='';
  191. print '<div class="div-table-responsive">';
  192. print '<table class="tagtable liste'.($moreforfilter?" listwithfilterbefore":"").'">'."\n";
  193. print '<tr class="liste_titre">';
  194. print '<th class="liste_titre">'.$langs->trans("AccountingCategory").'</th>';
  195. print '<th class="liste_titre"></th>';
  196. print '<th class="liste_titre" align="right">'.$langs->trans("PreviousPeriod").'</th>';
  197. print '<th class="liste_titre" align="right">'.$langs->trans("SelectedPeriod").'</th>';
  198. foreach($months as $k => $v){
  199. if (($k+1) >= $date_startmonth)
  200. {
  201. print '<th class="liste_titre width50" align="right" >'.$langs->trans('MonthShort'.sprintf("%02s",($k+1))).'</th>';
  202. }
  203. }
  204. foreach($months as $k => $v){
  205. if (($k+1) < $date_startmonth)
  206. {
  207. print '<th class="liste_titre width50" align="right" >'.$langs->trans('MonthShort'.sprintf("%02s",($k+1))).'</th>';
  208. }
  209. }
  210. print '</tr>';
  211. if ($modecompta == 'CREANCES-DETTES')
  212. {
  213. //if (! empty($date_start) && ! empty($date_end))
  214. // $sql.= " AND f.datef >= '".$db->idate($date_start)."' AND f.datef <= '".$db->idate($date_end)."'";
  215. }
  216. elseif ($modecompta=="RECETTES-DEPENSES")
  217. {
  218. //if (! empty($date_start) && ! empty($date_end))
  219. // $sql.= " AND p.datep >= '".$db->idate($date_start)."' AND p.datep <= '".$db->idate($date_end)."'";
  220. }
  221. elseif ($modecompta=="BOOKKEEPING")
  222. {
  223. // Get array of all report groups that are active
  224. $cats = $AccCat->getCats(); // WARNING: Computed groups must be after group they include
  225. /*
  226. $sql = 'SELECT DISTINCT t.numero_compte as nb FROM '.MAIN_DB_PREFIX.'accounting_bookkeeping as t, '.MAIN_DB_PREFIX.'accounting_account as aa';
  227. $sql.= " WHERE t.numero_compte = aa.account_number AND aa.fk_accounting_category = 0";
  228. if (! empty($date_start) && ! empty($date_end))
  229. $sql.= " AND t.doc_date >= '".$db->idate($date_start)."' AND t.doc_date <= '".$db->idate($date_end)."'";
  230. if (! empty($month)) {
  231. $sql .= " AND MONTH(t.doc_date) = " . $month;
  232. }
  233. $resql = $db->query($sql);
  234. if ($resql)
  235. {
  236. $num_rows = $db->num_rows($resql);
  237. if ($num_rows) {
  238. print '<div class="warning">Warning: There is '.$num_rows.' accounts in your ledger table that are not set into a reporting group</div>';
  239. $i = 0;
  240. //while ($i < $num) {
  241. // $obj = $db->fetch_object($resql);
  242. // $i++;
  243. //}
  244. }
  245. }
  246. else dol_print_error($db);
  247. */
  248. $j=1;
  249. $sommes = array();
  250. $totPerAccount = array();
  251. foreach ($cats as $cat) // Loop on each group
  252. {
  253. if (!empty($cat['category_type'])) // category calculed
  254. {
  255. // When we enter here, $sommes was filled by group of accounts
  256. $formula = $cat['formula'];
  257. print '<tr class="liste_total">';
  258. // Year NP
  259. print '<td class="liste_total width200">';
  260. print $cat['code'];
  261. print '</td><td>';
  262. print $cat['label'];
  263. print '</td>';
  264. $vars = array();
  265. // Previous Fiscal year (N-1)
  266. foreach($sommes as $code => $det){
  267. $vars[$code] = $det['NP'];
  268. }
  269. $result = strtr($formula, $vars);
  270. //var_dump($result);
  271. //$r = $AccCat->calculate($result);
  272. $r = dol_eval($result, 1);
  273. //var_dump($r);
  274. print '<td class="liste_total right">' . price($r) . '</td>';
  275. // Year N
  276. $code = $cat['code']; // code of categorie ('VTE', 'MAR', ...)
  277. $sommes[$code]['NP'] += $r;
  278. // Current fiscal year (N)
  279. if (is_array($sommes) && ! empty($sommes)){
  280. foreach($sommes as $code => $det){
  281. $vars[$code] = $det['N'];
  282. }
  283. }
  284. $result = strtr($formula, $vars);
  285. //$r = $AccCat->calculate($result);
  286. $r = dol_eval($result, 1);
  287. print '<td class="liste_total right">' . price($r) . '</td>';
  288. $sommes[$code]['N'] += $r;
  289. // Detail by month
  290. foreach($months as $k => $v)
  291. {
  292. if (($k+1) >= $date_startmonth)
  293. {
  294. foreach($sommes as $code => $det){
  295. $vars[$code] = $det['M'][$k];
  296. }
  297. $result = strtr($formula, $vars);
  298. //$r = $AccCat->calculate($result);
  299. $r = dol_eval($result, 1);
  300. print '<td class="liste_total right">' . price($r) . '</td>';
  301. $sommes[$code]['M'][$k] += $r;
  302. }
  303. }
  304. foreach($months as $k => $v)
  305. {
  306. if (($k+1) < $date_startmonth)
  307. {
  308. foreach($sommes as $code => $det){
  309. $vars[$code] = $det['M'][$k];
  310. }
  311. $result = strtr($formula, $vars);
  312. //$r = $AccCat->calculate($result);
  313. $r = dol_eval($result, 1);
  314. print '<td class="liste_total right">' . price($r) . '</td>';
  315. $sommes[$code]['M'][$k] += $r;
  316. }
  317. }
  318. print "</tr>\n";
  319. //var_dump($sommes);
  320. }
  321. else // normal category
  322. {
  323. $code = $cat['code']; // Category code we process
  324. $totCat = array();
  325. $totCat['NP'] = 0;
  326. $totCat['N'] = 0;
  327. $totCat['M'] = array();
  328. foreach($months as $k => $v)
  329. {
  330. $totCat['M'][$k] = 0;
  331. }
  332. // Set $cpts with array of accounts in the category/group
  333. $cpts = $AccCat->getCptsCat($cat['rowid']);
  334. $arrayofaccountforfilter=array();
  335. foreach($cpts as $i => $cpt) // Loop on each account.
  336. {
  337. $arrayofaccountforfilter[]=$cpt['account_number'];
  338. }
  339. // N-1
  340. if (! empty($arrayofaccountforfilter))
  341. {
  342. $return = $AccCat->getSumDebitCredit($arrayofaccountforfilter, $date_start_previous, $date_end_previous, $cpt['dc']?$cpt['dc']:0);
  343. if ($return < 0) {
  344. setEventMessages(null, $AccCat->errors, 'errors');
  345. $resultNP=0;
  346. } else {
  347. foreach($cpts as $i => $cpt) // Loop on each account.
  348. {
  349. $resultNP = empty($AccCat->sdcperaccount[$cpt['account_number']])?0:$AccCat->sdcperaccount[$cpt['account_number']];
  350. $totCat['NP'] += $resultNP;
  351. $sommes[$code]['NP'] += $resultNP;
  352. $totPerAccount[$cpt['account_number']]['NP'] = $resultNP;
  353. }
  354. }
  355. }
  356. // Set value into column N and month M ($totCat)
  357. // This make 12 calls for each accountancy account (12 monthes M)
  358. foreach($cpts as $i => $cpt) // Loop on each account.
  359. {
  360. // We make 1 loop for each account because we may want detail per account.
  361. // @TODO Optimize to ask a 'group by' account and a filter with account in (..., ...) in request
  362. // Each month
  363. $resultN = 0;
  364. foreach($months as $k => $v)
  365. {
  366. $monthtoprocess = $k+1; // ($k+1) is month 1, 2, ..., 12
  367. $yeartoprocess = $start_year;
  368. if (($k+1) < $start_month) $yeartoprocess++;
  369. //var_dump($monthtoprocess.'_'.$yeartoprocess);
  370. $return = $AccCat->getSumDebitCredit($cpt['account_number'], $date_start, $date_end, $cpt['dc']?$cpt['dc']:0, 'nofilter', $monthtoprocess, $yeartoprocess);
  371. if ($return < 0) {
  372. setEventMessages(null, $AccCat->errors, 'errors');
  373. $resultM=0;
  374. } else {
  375. $resultM=$AccCat->sdc;
  376. }
  377. $totCat['M'][$k] += $resultM;
  378. $sommes[$code]['M'][$k] += $resultM;
  379. $totPerAccount[$cpt['account_number']]['M'][$k] = $resultM;
  380. $resultN += $resultM;
  381. }
  382. $totCat['N'] += $resultN;
  383. $sommes[$code]['N'] += $resultN;
  384. $totPerAccount[$cpt['account_number']]['N'] = $resultN;
  385. }
  386. // Now output columns for row $code ('VTE', 'MAR', ...)
  387. print "<tr>";
  388. // Column group
  389. print '<td class="width200">';
  390. print $cat['code'];
  391. print '</td>';
  392. // Label of group
  393. print '<td>';
  394. print $cat['label'];
  395. if (count($cpts) > 0) // Show example of 5 first accounting accounts
  396. {
  397. $i=0;
  398. foreach($cpts as $cpt)
  399. {
  400. if ($i > 5)
  401. {
  402. print '...)';
  403. break;
  404. }
  405. if ($i > 0) print ', ';
  406. else print ' (';
  407. print $cpt['account_number'];
  408. $i++;
  409. }
  410. if ($i <= 5) print ')';
  411. }
  412. else
  413. {
  414. print ' - <span class="warning">'.$langs->trans("GroupIsEmptyCheckSetup").'</span>';
  415. }
  416. print '</td>';
  417. print '<td align="right">' . price($totCat['NP']) . '</td>';
  418. print '<td align="right">' . price($totCat['N']) . '</td>';
  419. // Each month
  420. foreach($totCat['M'] as $k => $v){
  421. if (($k+1) >= $date_startmonth) print '<td align="right">' . price($v) . '</td>';
  422. }
  423. foreach($totCat['M'] as $k => $v){
  424. if (($k+1) < $date_startmonth) print '<td align="right">' . price($v) . '</td>';
  425. }
  426. print "</tr>\n";
  427. // Loop on detail of all accounts to output the detail
  428. if ($showaccountdetail != 'no')
  429. {
  430. foreach($cpts as $i => $cpt)
  431. {
  432. $resultNP=$totPerAccount[$cpt['account_number']]['NP'];
  433. $resultN=$totPerAccount[$cpt['account_number']]['N'];
  434. if ($showaccountdetail == 'all' || $resultN > 0)
  435. {
  436. print '<tr>';
  437. print '<td></td>';
  438. print '<td class="tdoverflowmax200">';
  439. print ' &nbsp; &nbsp; ' . length_accountg($cpt['account_number']);
  440. print ' - ';
  441. print $cpt['account_label'];
  442. print '</td>';
  443. print '<td align="right">' . price($resultNP) . '</td>';
  444. print '<td align="right">' . price($resultN) . '</td>';
  445. // Make one call for each month
  446. foreach($months as $k => $v)
  447. {
  448. if (($k+1) >= $date_startmonth)
  449. {
  450. $resultM=$totPerAccount[$cpt['account_number']]['M'][$k];
  451. print '<td align="right">' . price($resultM) . '</td>';
  452. }
  453. }
  454. foreach($months as $k => $v)
  455. {
  456. if (($k+1) < $date_startmonth)
  457. {
  458. $resultM=$totPerAccount[$cpt['account_number']]['M'][$k];
  459. print '<td align="right">' . price($resultM) . '</td>';
  460. }
  461. }
  462. print "</tr>\n";
  463. }
  464. }
  465. }
  466. }
  467. }
  468. }
  469. print "</table>";
  470. print '</div>';
  471. // End of page
  472. llxFooter();
  473. $db->close();