index.php 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420
  1. <?php
  2. /* Copyright (C) 2013 Olivier Geffroy <jeff@jeffinfo.com>
  3. * Copyright (C) 2013-2014 Florian Henry <florian.henry@open-concept.pro>
  4. * Copyright (C) 2013-2017 Alexandre Spangaro <aspangaro@open-dsi.fr>
  5. * Copyright (C) 2014 Juanjo Menent <jmenent@2byte.es>
  6. * Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  20. *
  21. */
  22. /**
  23. * \file htdocs/accountancy/customer/index.php
  24. * \ingroup Accountancy (Double entries)
  25. * \brief Home customer journalization page
  26. */
  27. require '../../main.inc.php';
  28. require_once DOL_DOCUMENT_ROOT . '/core/lib/date.lib.php';
  29. require_once DOL_DOCUMENT_ROOT . '/core/lib/accounting.lib.php';
  30. require_once DOL_DOCUMENT_ROOT . '/compta/facture/class/facture.class.php';
  31. // Load translation files required by the page
  32. $langs->loadLangs(array("compta","bills","other","main","accountancy"));
  33. // Security check
  34. if (empty($conf->accounting->enabled)) {
  35. accessforbidden();
  36. }
  37. if ($user->societe_id > 0)
  38. accessforbidden();
  39. if (! $user->rights->accounting->bind->write)
  40. accessforbidden();
  41. $month_start= ($conf->global->SOCIETE_FISCAL_MONTH_START?($conf->global->SOCIETE_FISCAL_MONTH_START):1);
  42. if (GETPOST("year", 'int')) $year_start = GETPOST("year", 'int');
  43. else
  44. {
  45. $year_start = dol_print_date(dol_now(), '%Y');
  46. if (dol_print_date(dol_now(), '%m') < $month_start) $year_start--; // If current month is lower that starting fiscal month, we start last year
  47. }
  48. $year_end = $year_start + 1;
  49. $month_end = $month_start - 1;
  50. if ($month_end < 1)
  51. {
  52. $month_end = 12;
  53. $year_end--;
  54. }
  55. $search_date_start = dol_mktime(0, 0, 0, $month_start, 1, $year_start);
  56. $search_date_end = dol_get_last_day($year_end, $month_end);
  57. $year_current = $year_start;
  58. // Validate History
  59. $action = GETPOST('action', 'aZ09');
  60. /*
  61. * Actions
  62. */
  63. if ($action == 'clean' || $action == 'validatehistory')
  64. {
  65. // Clean database
  66. $db->begin();
  67. $sql1 = "UPDATE " . MAIN_DB_PREFIX . "facturedet as fd";
  68. $sql1 .= " SET fk_code_ventilation = 0";
  69. $sql1 .= ' WHERE fd.fk_code_ventilation NOT IN';
  70. $sql1 .= ' (SELECT accnt.rowid ';
  71. $sql1 .= ' FROM ' . MAIN_DB_PREFIX . 'accounting_account as accnt';
  72. $sql1 .= ' INNER JOIN ' . MAIN_DB_PREFIX . 'accounting_system as syst';
  73. $sql1 .= ' ON accnt.fk_pcg_version = syst.pcg_version AND syst.rowid=' . $conf->global->CHARTOFACCOUNTS . ' AND accnt.entity = '.$conf->entity.')';
  74. $sql1 .= ' AND fd.fk_facture IN (SELECT rowid FROM ' . MAIN_DB_PREFIX . 'facture WHERE entity = '.$conf->entity.')';
  75. $sql1 .= ' AND fk_code_ventilation <> 0';
  76. dol_syslog("htdocs/accountancy/customer/index.php fixaccountancycode", LOG_DEBUG);
  77. $resql1 = $db->query($sql1);
  78. if (! $resql1) {
  79. $error ++;
  80. $db->rollback();
  81. setEventMessages($db->lasterror(), null, 'errors');
  82. } else {
  83. $db->commit();
  84. }
  85. // End clean database
  86. }
  87. if ($action == 'validatehistory') {
  88. $error = 0;
  89. $db->begin();
  90. // Now make the binding. Bind automatically only for product with a dedicated account that exists into chart of account, others need a manual bind
  91. if ($db->type == 'pgsql') {
  92. $sql1 = "UPDATE " . MAIN_DB_PREFIX . "facturedet";
  93. $sql1 .= " SET fk_code_ventilation = accnt.rowid";
  94. $sql1 .= " FROM " . MAIN_DB_PREFIX . "product as p, " . MAIN_DB_PREFIX . "accounting_account as accnt , " . MAIN_DB_PREFIX . "accounting_system as syst";
  95. $sql1 .= " WHERE " . MAIN_DB_PREFIX . "facturedet.fk_product = p.rowid AND accnt.fk_pcg_version = syst.pcg_version AND syst.rowid=" . $conf->global->CHARTOFACCOUNTS.' AND accnt.entity = '.$conf->entity;
  96. $sql1 .= " AND accnt.active = 1 AND p.accountancy_code_sell=accnt.account_number";
  97. $sql1 .= " AND " . MAIN_DB_PREFIX . "facturedet.fk_code_ventilation = 0";
  98. } else {
  99. $sql1 = "UPDATE " . MAIN_DB_PREFIX . "facturedet as fd, " . MAIN_DB_PREFIX . "product as p, " . MAIN_DB_PREFIX . "accounting_account as accnt , " . MAIN_DB_PREFIX . "accounting_system as syst";
  100. $sql1 .= " SET fk_code_ventilation = accnt.rowid";
  101. $sql1 .= " WHERE fd.fk_product = p.rowid AND accnt.fk_pcg_version = syst.pcg_version AND syst.rowid=" . $conf->global->CHARTOFACCOUNTS.' AND accnt.entity = '.$conf->entity;
  102. $sql1 .= " AND accnt.active = 1 AND p.accountancy_code_sell=accnt.account_number";
  103. $sql1 .= " AND fd.fk_code_ventilation = 0";
  104. }
  105. dol_syslog('htdocs/accountancy/customer/index.php');
  106. $resql1 = $db->query($sql1);
  107. if (! $resql1) {
  108. $error ++;
  109. $db->rollback();
  110. setEventMessages($db->lasterror(), null, 'errors');
  111. } else {
  112. $db->commit();
  113. setEventMessages($langs->trans('AutomaticBindingDone'), null, 'mesgs');
  114. }
  115. }
  116. /*
  117. * View
  118. */
  119. llxHeader('', $langs->trans("CustomersVentilation"));
  120. $textprevyear = '<a href="' . $_SERVER["PHP_SELF"] . '?year=' . ($year_current - 1) . '">' . img_previous() . '</a>';
  121. $textnextyear = '&nbsp;<a href="' . $_SERVER["PHP_SELF"] . '?year=' . ($year_current + 1) . '">' . img_next() . '</a>';
  122. print load_fiche_titre($langs->trans("CustomersVentilation") . " " . $textprevyear . " " . $langs->trans("Year") . " " . $year_start . " " . $textnextyear, '', 'title_accountancy');
  123. print '<span class="opacitymedium">'.$langs->trans("DescVentilCustomer") . '<br>';
  124. print $langs->trans("DescVentilMore", $langs->transnoentitiesnoconv("ValidateHistory"), $langs->transnoentitiesnoconv("ToBind")) . '<br>';
  125. print '</span><br>';
  126. $y = $year_current;
  127. $buttonbind = '<a class="butAction" href="' . $_SERVER['PHP_SELF'] . '?year=' . $year_current . '&action=validatehistory">' . $langs->trans("ValidateHistory") . '</a>';
  128. print_barre_liste($langs->trans("OverviewOfAmountOfLinesNotBound"), '', '', '', '', '', '', -1, '', '', 0, $buttonbind, '', 0, 1, 1);
  129. //print load_fiche_titre($langs->trans("OverviewOfAmountOfLinesNotBound"), $buttonbind, '');
  130. print '<div class="div-table-responsive-no-min">';
  131. print '<table class="noborder" width="100%">';
  132. print '<tr class="liste_titre"><td width="200">' . $langs->trans("Account") . '</td>';
  133. print '<td width="200" class="left">' . $langs->trans("Label") . '</td>';
  134. for($i = 1; $i <= 12; $i ++) {
  135. $j = $i + ($conf->global->SOCIETE_FISCAL_MONTH_START?$conf->global->SOCIETE_FISCAL_MONTH_START:1) - 1;
  136. if ($j > 12) $j-=12;
  137. print '<td width="60" class="right">' . $langs->trans('MonthShort' . str_pad($j, 2, '0', STR_PAD_LEFT)) . '</td>';
  138. }
  139. print '<td width="60" class="right"><b>' . $langs->trans("Total") . '</b></td></tr>';
  140. $sql = "SELECT " . $db->ifsql('aa.account_number IS NULL', "'tobind'", 'aa.account_number') . " AS codecomptable,";
  141. $sql .= " " . $db->ifsql('aa.label IS NULL', "'tobind'", 'aa.label') . " AS intitule,";
  142. for($i = 1; $i <= 12; $i ++) {
  143. $j = $i + ($conf->global->SOCIETE_FISCAL_MONTH_START?$conf->global->SOCIETE_FISCAL_MONTH_START:1) - 1;
  144. if ($j > 12) $j-=12;
  145. $sql .= " SUM(" . $db->ifsql('MONTH(f.datef)=' . $j, 'fd.total_ht', '0') . ") AS month" . str_pad($j, 2, '0', STR_PAD_LEFT) . ",";
  146. }
  147. $sql .= " SUM(fd.total_ht) as total";
  148. $sql .= " FROM " . MAIN_DB_PREFIX . "facturedet as fd";
  149. $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "facture as f ON f.rowid = fd.fk_facture";
  150. $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "accounting_account as aa ON aa.rowid = fd.fk_code_ventilation";
  151. $sql .= " WHERE f.datef >= '" . $db->idate($search_date_start) . "'";
  152. $sql .= " AND f.datef <= '" . $db->idate($search_date_end) . "'";
  153. $sql .= " AND f.fk_statut > 0";
  154. $sql .= " AND f.entity IN (" . getEntity('invoice', 0) . ")"; // We don't share object for accountancy
  155. $sql .= " AND aa.account_number IS NULL";
  156. if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
  157. $sql .= " AND f.type IN (" . Facture::TYPE_STANDARD . "," . Facture::TYPE_REPLACEMENT . "," . Facture::TYPE_CREDIT_NOTE . "," . Facture::TYPE_SITUATION . ")";
  158. } else {
  159. $sql .= " AND f.type IN (" . Facture::TYPE_STANDARD . "," . Facture::TYPE_REPLACEMENT . "," . Facture::TYPE_CREDIT_NOTE . "," . Facture::TYPE_DEPOSIT . "," . Facture::TYPE_SITUATION . ")";
  160. }
  161. $sql .= " GROUP BY fd.fk_code_ventilation,aa.account_number,aa.label";
  162. dol_syslog('htdocs/accountancy/customer/index.php sql=' . $sql, LOG_DEBUG);
  163. $resql = $db->query($sql);
  164. if ($resql) {
  165. $num = $db->num_rows($resql);
  166. while ( $row = $db->fetch_row($resql)) {
  167. print '<tr class="oddeven"><td>';
  168. if ($row[0] == 'tobind')
  169. {
  170. print $langs->trans("Unknown");
  171. }
  172. else print length_accountg($row[0]);
  173. print '</td>';
  174. print '<td class="left">';
  175. if ($row[0] == 'tobind')
  176. {
  177. print $langs->trans("UseMenuToSetBindindManualy", DOL_URL_ROOT.'/accountancy/customer/list.php?search_year='.$y, $langs->transnoentitiesnoconv("ToBind"));
  178. }
  179. else print $row[1];
  180. print '</td>';
  181. for($i = 2; $i <= 12; $i ++) {
  182. print '<td class="nowrap right">' . price($row[$i]) . '</td>';
  183. }
  184. print '<td class="nowrap right">' . price($row[13]) . '</td>';
  185. print '<td class="nowrap right"><b>' . price($row[14]) . '</b></td>';
  186. print '</tr>';
  187. }
  188. $db->free($resql);
  189. } else {
  190. print $db->lasterror(); // Show last sql error
  191. }
  192. print "</table>\n";
  193. print '</div>';
  194. print '<br>';
  195. print_barre_liste($langs->trans("OverviewOfAmountOfLinesBound"), '', '', '', '', '', '', -1, '', '', 0, '', '', 0, 1, 1);
  196. //print load_fiche_titre($langs->trans("OverviewOfAmountOfLinesBound"), '', '');
  197. print '<div class="div-table-responsive-no-min">';
  198. print '<table class="noborder" width="100%">';
  199. print '<tr class="liste_titre"><td width="200">' . $langs->trans("Account") . '</td>';
  200. print '<td width="200" class="left">' . $langs->trans("Label") . '</td>';
  201. for($i = 1; $i <= 12; $i ++) {
  202. $j = $i + ($conf->global->SOCIETE_FISCAL_MONTH_START?$conf->global->SOCIETE_FISCAL_MONTH_START:1) - 1;
  203. if ($j > 12) $j-=12;
  204. print '<td width="60" class="right">' . $langs->trans('MonthShort' . str_pad($j, 2, '0', STR_PAD_LEFT)) . '</td>';
  205. }
  206. print '<td width="60" class="right"><b>' . $langs->trans("Total") . '</b></td></tr>';
  207. $sql = "SELECT " . $db->ifsql('aa.account_number IS NULL', "'tobind'", 'aa.account_number') . " AS codecomptable,";
  208. $sql .= " " . $db->ifsql('aa.label IS NULL', "'tobind'", 'aa.label') . " AS intitule,";
  209. for($i = 1; $i <= 12; $i ++) {
  210. $j = $i + ($conf->global->SOCIETE_FISCAL_MONTH_START?$conf->global->SOCIETE_FISCAL_MONTH_START:1) - 1;
  211. if ($j > 12) $j-=12;
  212. $sql .= " SUM(" . $db->ifsql('MONTH(f.datef)=' . $j, 'fd.total_ht', '0') . ") AS month" . str_pad($j, 2, '0', STR_PAD_LEFT) . ",";
  213. }
  214. $sql .= " SUM(fd.total_ht) as total";
  215. $sql .= " FROM " . MAIN_DB_PREFIX . "facturedet as fd";
  216. $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "facture as f ON f.rowid = fd.fk_facture";
  217. $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "accounting_account as aa ON aa.rowid = fd.fk_code_ventilation";
  218. $sql .= " WHERE f.datef >= '" . $db->idate($search_date_start) . "'";
  219. $sql .= " AND f.datef <= '" . $db->idate($search_date_end) . "'";
  220. $sql .= " AND f.entity IN (" . getEntity('invoice', 0) . ")"; // We don't share object for accountancy
  221. $sql .= " AND f.fk_statut > 0";
  222. if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
  223. $sql .= " AND f.type IN (" . Facture::TYPE_STANDARD . "," . Facture::TYPE_REPLACEMENT . "," . Facture::TYPE_CREDIT_NOTE . "," . Facture::TYPE_SITUATION . ")";
  224. } else {
  225. $sql .= " AND f.type IN (" . Facture::TYPE_STANDARD . "," . Facture::TYPE_REPLACEMENT . "," . Facture::TYPE_CREDIT_NOTE . "," . Facture::TYPE_DEPOSIT . "," . Facture::TYPE_SITUATION . ")";
  226. }
  227. $sql .= " AND aa.account_number IS NOT NULL";
  228. $sql .= " GROUP BY fd.fk_code_ventilation,aa.account_number,aa.label";
  229. dol_syslog('htdocs/accountancy/customer/index.php');
  230. $resql = $db->query($sql);
  231. if ($resql) {
  232. $num = $db->num_rows($resql);
  233. while ( $row = $db->fetch_row($resql)) {
  234. print '<tr class="oddeven"><td>';
  235. if ($row[0] == 'tobind')
  236. {
  237. print $langs->trans("Unknown");
  238. }
  239. else print length_accountg($row[0]);
  240. print '</td>';
  241. print '<td class="left">';
  242. if ($row[0] == 'tobind')
  243. {
  244. print $langs->trans("UseMenuToSetBindindManualy", DOL_URL_ROOT.'/accountancy/customer/list.php?search_year='.$y, $langs->transnoentitiesnoconv("ToBind"));
  245. }
  246. else print $row[1];
  247. print '</td>';
  248. for($i = 2; $i <= 12; $i++) {
  249. print '<td class="nowrap right">' . price($row[$i]) . '</td>';
  250. }
  251. print '<td class="nowrap right">' . price($row[13]) . '</td>';
  252. print '<td class="nowrap right"><b>' . price($row[14]) . '</b></td>';
  253. print '</tr>';
  254. }
  255. $db->free($resql);
  256. } else {
  257. print $db->lasterror(); // Show last sql error
  258. }
  259. print "</table>\n";
  260. print '</div>';
  261. if ($conf->global->MAIN_FEATURES_LEVEL > 0) // This part of code looks strange. Why showing a report that should rely on result of this step ?
  262. {
  263. print '<br>';
  264. print '<br>';
  265. print_barre_liste($langs->trans("OtherInfo"), '', '', '', '', '', '', -1, '', '', 0, '', '', 0, 1, 1);
  266. //print load_fiche_titre($langs->trans("OtherInfo"), '', '');
  267. print '<div class="div-table-responsive-no-min">';
  268. print '<table class="noborder" width="100%">';
  269. print '<tr class="liste_titre"><td width="400" class="left">' . $langs->trans("TotalVente") . '</td>';
  270. for($i = 1; $i <= 12; $i ++) {
  271. $j = $i + ($conf->global->SOCIETE_FISCAL_MONTH_START?$conf->global->SOCIETE_FISCAL_MONTH_START:1) - 1;
  272. if ($j > 12) $j-=12;
  273. print '<td width="60" class="right">' . $langs->trans('MonthShort' . str_pad($j, 2, '0', STR_PAD_LEFT)) . '</td>';
  274. }
  275. print '<td width="60" class="right"><b>' . $langs->trans("Total") . '</b></td></tr>';
  276. $sql = "SELECT '" . $langs->trans("TotalVente") . "' AS total,";
  277. for($i = 1; $i <= 12; $i ++) {
  278. $j = $i + ($conf->global->SOCIETE_FISCAL_MONTH_START?$conf->global->SOCIETE_FISCAL_MONTH_START:1) - 1;
  279. if ($j > 12) $j-=12;
  280. $sql .= " SUM(" . $db->ifsql('MONTH(f.datef)=' . $j, 'fd.total_ht', '0') . ") AS month" . str_pad($j, 2, '0', STR_PAD_LEFT) . ",";
  281. }
  282. $sql .= " SUM(fd.total_ht) as total";
  283. $sql .= " FROM " . MAIN_DB_PREFIX . "facturedet as fd";
  284. $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "facture as f ON f.rowid = fd.fk_facture";
  285. $sql .= " WHERE f.datef >= '" . $db->idate($search_date_start) . "'";
  286. $sql .= " AND f.datef <= '" . $db->idate($search_date_end) . "'";
  287. $sql .= " AND f.entity IN (" . getEntity('invoice', 0) . ")"; // We don't share object for accountancy
  288. $sql .= " AND f.fk_statut > 0";
  289. if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
  290. $sql .= " AND f.type IN (" . Facture::TYPE_STANDARD . "," . Facture::TYPE_REPLACEMENT . "," . Facture::TYPE_CREDIT_NOTE . "," . Facture::TYPE_SITUATION . ")";
  291. } else {
  292. $sql .= " AND f.type IN (" . Facture::TYPE_STANDARD . "," . Facture::TYPE_REPLACEMENT . "," . Facture::TYPE_CREDIT_NOTE . "," . Facture::TYPE_DEPOSIT . "," . Facture::TYPE_SITUATION . ")";
  293. }
  294. dol_syslog('htdocs/accountancy/customer/index.php');
  295. $resql = $db->query($sql);
  296. if ($resql) {
  297. $num = $db->num_rows($resql);
  298. while ($row = $db->fetch_row($resql)) {
  299. print '<tr><td>' . $row[0] . '</td>';
  300. for($i = 1; $i <= 12; $i ++) {
  301. print '<td class="nowrap right">' . price($row[$i]) . '</td>';
  302. }
  303. print '<td class="nowrap right"><b>' . price($row[13]) . '</b></td>';
  304. print '</tr>';
  305. }
  306. $db->free($resql);
  307. } else {
  308. print $db->lasterror(); // Show last sql error
  309. }
  310. print "</table>\n";
  311. print '</div>';
  312. if (! empty($conf->margin->enabled)) {
  313. print "<br>\n";
  314. print '<div class="div-table-responsive-no-min">';
  315. print '<table class="noborder" width="100%">';
  316. print '<tr class="liste_titre"><td width="400">' . $langs->trans("TotalMarge") . '</td>';
  317. for($i = 1; $i <= 12; $i ++) {
  318. $j = $i + ($conf->global->SOCIETE_FISCAL_MONTH_START?$conf->global->SOCIETE_FISCAL_MONTH_START:1) - 1;
  319. if ($j > 12) $j-=12;
  320. print '<td width="60" class="right">' . $langs->trans('MonthShort' . str_pad($j, 2, '0', STR_PAD_LEFT)) . '</td>';
  321. }
  322. print '<td width="60" class="right"><b>' . $langs->trans("Total") . '</b></td></tr>';
  323. $sql = "SELECT '" . $langs->trans("Vide") . "' AS marge,";
  324. for($i = 1; $i <= 12; $i ++) {
  325. $j = $i + ($conf->global->SOCIETE_FISCAL_MONTH_START?$conf->global->SOCIETE_FISCAL_MONTH_START:1) - 1;
  326. if ($j > 12) $j-=12;
  327. $sql .= " SUM(" . $db->ifsql('MONTH(f.datef)=' . $j, '(fd.total_ht-(fd.qty * fd.buy_price_ht))', '0') . ") AS month" . str_pad($j, 2, '0', STR_PAD_LEFT) . ",";
  328. }
  329. $sql .= " SUM((fd.total_ht-(fd.qty * fd.buy_price_ht))) as total";
  330. $sql .= " FROM " . MAIN_DB_PREFIX . "facturedet as fd";
  331. $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "facture as f ON f.rowid = fd.fk_facture";
  332. $sql .= " WHERE f.datef >= '" . $db->idate($search_date_start) . "'";
  333. $sql .= " AND f.datef <= '" . $db->idate($search_date_end) . "'";
  334. $sql .= " AND f.entity IN (" . getEntity('invoice', 0) . ")"; // We don't share object for accountancy
  335. $sql .= " AND f.fk_statut > 0";
  336. if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
  337. $sql .= " AND f.type IN (" . Facture::TYPE_STANDARD . "," . Facture::TYPE_REPLACEMENT . "," . Facture::TYPE_CREDIT_NOTE . "," . Facture::TYPE_SITUATION . ")";
  338. } else {
  339. $sql .= " AND f.type IN (" . Facture::TYPE_STANDARD . "," . Facture::TYPE_REPLACEMENT . "," . Facture::TYPE_CREDIT_NOTE . "," . Facture::TYPE_DEPOSIT . "," . Facture::TYPE_SITUATION . ")";
  340. }
  341. dol_syslog('htdocs/accountancy/customer/index.php');
  342. $resql = $db->query($sql);
  343. if ($resql) {
  344. $num = $db->num_rows($resql);
  345. while ($row = $db->fetch_row($resql)) {
  346. print '<tr><td>' . $row[0] . '</td>';
  347. for($i = 1; $i <= 12; $i ++) {
  348. print '<td class="nowrap right">' . price(price2num($row[$i])) . '</td>';
  349. }
  350. print '<td class="nowrap right"><b>' . price(price2num($row[13])) . '</b></td>';
  351. print '</tr>';
  352. }
  353. $db->free($resql);
  354. } else {
  355. print $db->lasterror(); // Show last sql error
  356. }
  357. print "</table>\n";
  358. print '</div>';
  359. }
  360. }
  361. // End of page
  362. llxFooter();
  363. $db->close();