byratecountry.php 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474
  1. <?php
  2. /* Copyright (C) 2018 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) 2018-2021 Frédéric France <frederic.france@netlogic.fr>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  17. */
  18. /**
  19. * \file htdocs/compta/stats/byratecountry.php
  20. * \brief VAT by rate
  21. */
  22. require '../../main.inc.php';
  23. require_once DOL_DOCUMENT_ROOT.'/core/lib/report.lib.php';
  24. require_once DOL_DOCUMENT_ROOT.'/core/lib/tax.lib.php';
  25. require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
  26. require_once DOL_DOCUMENT_ROOT.'/compta/tva/class/tva.class.php';
  27. require_once DOL_DOCUMENT_ROOT.'/compta/localtax/class/localtax.class.php';
  28. require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
  29. require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
  30. require_once DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php';
  31. require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
  32. require_once DOL_DOCUMENT_ROOT.'/fourn/class/paiementfourn.class.php';
  33. require_once DOL_DOCUMENT_ROOT.'/expensereport/class/expensereport.class.php';
  34. require_once DOL_DOCUMENT_ROOT.'/expensereport/class/paymentexpensereport.class.php';
  35. // Load translation files required by the page
  36. $langs->loadLangs(array("other", "compta", "banks", "bills", "companies", "product", "trips", "admin", "accountancy"));
  37. $modecompta = (GETPOST('modecompta', 'alpha') ? GETPOST('modecompta', 'alpha') : $conf->global->ACCOUNTING_MODE);
  38. // Date range
  39. $year = GETPOST("year", 'int');
  40. $month = GETPOST("month", 'int');
  41. if (empty($year)) {
  42. $year_current = dol_print_date(dol_now(), '%Y');
  43. $month_current = dol_print_date(dol_now(), '%m');
  44. $year_start = $year_current;
  45. } else {
  46. $year_current = $year;
  47. $month_current = dol_print_date(dol_now(), '%m');
  48. $year_start = $year;
  49. }
  50. $date_start = dol_mktime(0, 0, 0, GETPOST("date_startmonth"), GETPOST("date_startday"), GETPOST("date_startyear"), 'tzserver'); // We use timezone of server so report is same from everywhere
  51. $date_end = dol_mktime(23, 59, 59, GETPOST("date_endmonth"), GETPOST("date_endday"), GETPOST("date_endyear"), 'tzserver'); // We use timezone of server so report is same from everywhere
  52. // Quarter
  53. if (empty($date_start) || empty($date_end)) { // We define date_start and date_end
  54. $q = GETPOST("q", "int");
  55. if (empty($q)) {
  56. // We define date_start and date_end
  57. $month_start = GETPOST("month") ?GETPOST("month") : ($conf->global->SOCIETE_FISCAL_MONTH_START ? ($conf->global->SOCIETE_FISCAL_MONTH_START) : 1);
  58. $year_end = $year_start;
  59. $month_end = $month_start;
  60. if (!GETPOST("month")) { // If month not forced
  61. if (!GETPOST('year') && $month_start > $month_current) {
  62. $year_start--;
  63. $year_end--;
  64. }
  65. $month_end = $month_start - 1;
  66. if ($month_end < 1) {
  67. $month_end = 12;
  68. } else {
  69. $year_end++;
  70. }
  71. }
  72. $date_start = dol_get_first_day($year_start, $month_start, false);
  73. $date_end = dol_get_last_day($year_end, $month_end, false);
  74. } else {
  75. if ($q == 1) {
  76. $date_start = dol_get_first_day($year_start, 1, false);
  77. $date_end = dol_get_last_day($year_start, 3, false);
  78. }
  79. if ($q == 2) {
  80. $date_start = dol_get_first_day($year_start, 4, false);
  81. $date_end = dol_get_last_day($year_start, 6, false);
  82. }
  83. if ($q == 3) {
  84. $date_start = dol_get_first_day($year_start, 7, false);
  85. $date_end = dol_get_last_day($year_start, 9, false);
  86. }
  87. if ($q == 4) {
  88. $date_start = dol_get_first_day($year_start, 10, false);
  89. $date_end = dol_get_last_day($year_start, 12, false);
  90. }
  91. }
  92. }
  93. // $date_start and $date_end are defined. We force $year_start and $nbofyear
  94. $tmps = dol_getdate($date_start);
  95. $year_start = $tmps['year'];
  96. $tmpe = dol_getdate($date_end);
  97. $year_end = $tmpe['year'];
  98. $tmp_date_end = dol_time_plus_duree($date_start, 1, 'y') - 1;
  99. if ($tmp_date_end < $date_end || $date_end < $date_start) {
  100. $date_end = $tmp_date_end;
  101. }
  102. $min = price2num(GETPOST("min", "alpha"));
  103. if (empty($min)) {
  104. $min = 0;
  105. }
  106. // Define modetax (0 or 1)
  107. // 0=normal, 1=option vat for services is on debit, 2=option on payments for products
  108. $modetax = empty($conf->global->TAX_MODE) ? 0 : $conf->global->TAX_MODE;
  109. if (GETPOSTISSET("modetax")) {
  110. $modetax = GETPOST("modetax", 'int');
  111. }
  112. if (empty($modetax)) {
  113. $modetax = 0;
  114. }
  115. // Security check
  116. $socid = GETPOST('socid', 'int');
  117. if ($user->socid) {
  118. $socid = $user->socid;
  119. }
  120. $result = restrictedArea($user, 'tax', '', '', 'charges');
  121. /*
  122. * View
  123. */
  124. $form = new Form($db);
  125. $company_static = new Societe($db);
  126. $invoice_customer = new Facture($db);
  127. $invoice_supplier = new FactureFournisseur($db);
  128. $expensereport = new ExpenseReport($db);
  129. $product_static = new Product($db);
  130. $payment_static = new Paiement($db);
  131. $paymentfourn_static = new PaiementFourn($db);
  132. $paymentexpensereport_static = new PaymentExpenseReport($db);
  133. $morequerystring = '';
  134. $listofparams = array('date_startmonth', 'date_startyear', 'date_startday', 'date_endmonth', 'date_endyear', 'date_endday');
  135. foreach ($listofparams as $param) {
  136. if (GETPOST($param) != '') {
  137. $morequerystring .= ($morequerystring ? '&' : '').$param.'='.GETPOST($param);
  138. }
  139. }
  140. llxHeader('', $langs->trans("TurnoverReport"), '', '', 0, 0, '', '', $morequerystring);
  141. //print load_fiche_titre($langs->trans("VAT"),"");
  142. //$fsearch.='<br>';
  143. $fsearch .= ' <input type="hidden" name="year" value="'.$year.'">';
  144. $fsearch .= ' <input type="hidden" name="modetax" value="'.$modetax.'">';
  145. //$fsearch.=' '.$langs->trans("SalesTurnoverMinimum").': ';
  146. //$fsearch.=' <input type="text" name="min" value="'.$min.'">';
  147. // Show report header
  148. $name = $langs->trans("xxx");
  149. $calcmode = '';
  150. if ($modetax == 0) {
  151. $calcmode = $langs->trans('OptionVATDefault');
  152. }
  153. if ($modetax == 1) {
  154. $calcmode = $langs->trans('OptionVATDebitOption');
  155. }
  156. if ($modetax == 2) {
  157. $calcmode = $langs->trans('OptionPaymentForProductAndServices');
  158. }
  159. $calcmode .= '<br>('.$langs->trans("TaxModuleSetupToModifyRules", DOL_URL_ROOT.'/admin/taxes.php').')';
  160. // Set period
  161. $period = $form->selectDate($date_start, 'date_start', 0, 0, 0, '', 1, 0, 0, '', '', '', '', 1, '', '', 'tzserver');
  162. $period .= ' - ';
  163. $period .= $form->selectDate($date_end, 'date_end', 0, 0, 0, '', 1, 0, 0, '', '', '', '', 1, '', '', 'tzserver');
  164. $prevyear = $year_start;
  165. $prevquarter = $q;
  166. if ($prevquarter > 1) {
  167. $prevquarter--;
  168. } else {
  169. $prevquarter = 4;
  170. $prevyear--;
  171. }
  172. $nextyear = $year_start;
  173. $nextquarter = $q;
  174. if ($nextquarter < 4) {
  175. $nextquarter++;
  176. } else {
  177. $nextquarter = 1;
  178. $nextyear++;
  179. }
  180. $description .= $fsearch;
  181. $builddate = dol_now();
  182. if ($conf->global->TAX_MODE_SELL_PRODUCT == 'invoice') {
  183. $description .= $langs->trans("RulesVATDueProducts");
  184. }
  185. if ($conf->global->TAX_MODE_SELL_PRODUCT == 'payment') {
  186. $description .= $langs->trans("RulesVATInProducts");
  187. }
  188. if ($conf->global->TAX_MODE_SELL_SERVICE == 'invoice') {
  189. $description .= '<br>'.$langs->trans("RulesVATDueServices");
  190. }
  191. if ($conf->global->TAX_MODE_SELL_SERVICE == 'payment') {
  192. $description .= '<br>'.$langs->trans("RulesVATInServices");
  193. }
  194. if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
  195. $description .= '<br>'.$langs->trans("DepositsAreNotIncluded");
  196. }
  197. if (!empty($conf->global->MAIN_MODULE_ACCOUNTING)) {
  198. $description .= '<br>'.$langs->trans("ThisIsAnEstimatedValue");
  199. }
  200. // Customers invoices
  201. $elementcust = $langs->trans("CustomersInvoices");
  202. $productcust = $langs->trans("ProductOrService");
  203. $amountcust = $langs->trans("AmountHT");
  204. // Suppliers invoices
  205. $elementsup = $langs->trans("SuppliersInvoices");
  206. $productsup = $productcust;
  207. $amountsup = $amountcust;
  208. $namesup = $namecust;
  209. // TODO Report from bookkeeping not yet available, so we switch on report on business events
  210. if ($modecompta == "BOOKKEEPING") {
  211. $modecompta = "CREANCES-DETTES";
  212. }
  213. if ($modecompta == "BOOKKEEPINGCOLLECTED") {
  214. $modecompta = "RECETTES-DEPENSES";
  215. }
  216. // Show report header
  217. if ($modecompta == "CREANCES-DETTES") {
  218. $name = $langs->trans("Turnover").', '.$langs->trans("ByVatRate");
  219. $calcmode = $langs->trans("CalcModeDebt");
  220. //$calcmode.='<br>('.$langs->trans("SeeReportInInputOutputMode",'<a href="'.$_SERVER["PHP_SELF"].'?year='.$year_start.'&modecompta=RECETTES-DEPENSES">','</a>').')';
  221. $description = $langs->trans("RulesCADue");
  222. if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
  223. $description .= $langs->trans("DepositsAreNotIncluded");
  224. } else {
  225. $description .= $langs->trans("DepositsAreIncluded");
  226. }
  227. $builddate = dol_now();
  228. } elseif ($modecompta == "RECETTES-DEPENSES") {
  229. $name = $langs->trans("TurnoverCollected").', '.$langs->trans("ByVatRate");
  230. $calcmode = $langs->trans("CalcModeEngagement");
  231. //$calcmode.='<br>('.$langs->trans("SeeReportInDueDebtMode",'<a href="'.$_SERVER["PHP_SELF"].'?year='.$year_start.'&modecompta=CREANCES-DETTES">','</a>').')';
  232. $description = $langs->trans("RulesCAIn");
  233. $description .= $langs->trans("DepositsAreIncluded");
  234. $builddate = dol_now();
  235. } elseif ($modecompta == "BOOKKEEPING") {
  236. } elseif ($modecompta == "BOOKKEEPINGCOLLECTED") {
  237. }
  238. $period = $form->selectDate($date_start, 'date_start', 0, 0, 0, '', 1, 0);
  239. $period .= ' - ';
  240. $period .= $form->selectDate($date_end, 'date_end', 0, 0, 0, '', 1, 0);
  241. if ($date_end == dol_time_plus_duree($date_start, 1, 'y') - 1) {
  242. $periodlink = '<a href="'.$_SERVER["PHP_SELF"].'?year='.($year_start - 1).'&modecompta='.$modecompta.'">'.img_previous().'</a> <a href="'.$_SERVER["PHP_SELF"].'?year='.($year_start + 1).'&modecompta='.$modecompta.'">'.img_next().'</a>';
  243. } else {
  244. $periodlink = '';
  245. }
  246. $description .= ' <input type="hidden" name="modecompta" value="'.$modecompta.'">';
  247. report_header($name, '', $period, $periodlink, $description, $builddate, $exportlink, array(), $calcmode);
  248. if (!empty($conf->accounting->enabled) && $modecompta != 'BOOKKEEPING') {
  249. print info_admin($langs->trans("WarningReportNotReliable"), 0, 0, 1);
  250. }
  251. if ($modecompta == 'CREANCES-DETTES') {
  252. print '<table class="noborder centpercent">';
  253. print '<tr class="liste_titre"><td width="6%" class="right">'.$langs->trans("TurnoverbyVatrate").'</td>';
  254. print '<td class="left">'.$langs->trans("ProductOrService").'</td>';
  255. print '<td class="left">'.$langs->trans("Country").'</td>';
  256. $i = 0;
  257. while ($i < 12) {
  258. $j = $i + (empty($conf->global->SOCIETE_FISCAL_MONTH_START) ? 1 : $conf->global->SOCIETE_FISCAL_MONTH_START);
  259. if ($j > 12) {
  260. $j -= 12;
  261. }
  262. print '<td width="60" class="right">'.$langs->trans('MonthShort'.str_pad($j, 2, '0', STR_PAD_LEFT)).'</td>';
  263. $i++;
  264. }
  265. print '<td width="60" class="right"><b>'.$langs->trans("TotalHT").'</b></td></tr>';
  266. // Sales invoices
  267. $sql = "SELECT fd.tva_tx AS vatrate,";
  268. $sql .= " fd.product_type AS product_type,";
  269. $sql .= " cc.code, cc.label AS country,";
  270. for ($i = 1; $i <= 12; $i++) {
  271. $sql .= " SUM(".$db->ifsql('MONTH(f.datef)='.$i, 'fd.total_ht', '0').") AS month".str_pad($i, 2, '0', STR_PAD_LEFT).",";
  272. }
  273. $sql .= " SUM(fd.total_ht) as total";
  274. $sql .= " FROM ".MAIN_DB_PREFIX."facturedet as fd";
  275. $sql .= " INNER JOIN ".MAIN_DB_PREFIX."facture as f ON f.rowid = fd.fk_facture";
  276. $sql .= " INNER JOIN ".MAIN_DB_PREFIX."societe as soc ON soc.rowid = f.fk_soc";
  277. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as cc ON cc.rowid = soc.fk_pays";
  278. $sql .= " WHERE f.datef >= '".$db->idate($date_start)."'";
  279. $sql .= " AND f.datef <= '".$db->idate($date_end)."'";
  280. $sql .= " AND f.fk_statut in (1,2)";
  281. if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
  282. $sql .= " AND f.type IN (0,1,2,5)";
  283. } else {
  284. $sql .= " AND f.type IN (0,1,2,3,5)";
  285. }
  286. $sql .= " AND f.entity IN (".getEntity('invoice', 0).")";
  287. $sql .= " GROUP BY fd.tva_tx,fd.product_type, cc.label, cc.code ";
  288. $sql .= " ORDER BY country, product_type, vatrate";
  289. dol_syslog("htdocs/compta/tva/index.php sql=".$sql, LOG_DEBUG);
  290. $resql = $db->query($sql);
  291. if ($resql) {
  292. $num = $db->num_rows($resql);
  293. $totalpermonth = array();
  294. while ($obj = $db->fetch_object($resql)) {
  295. print '<tr class="oddeven"><td class="right">'.vatrate($obj->vatrate).'</td>';
  296. if ($obj->product_type == 0) {
  297. print '<td class="left">'.$langs->trans("Product").'</td>';
  298. } else {
  299. print '<td class="left">'.$langs->trans("Service").'</td>';
  300. }
  301. // Country
  302. print '<td>';
  303. print $langs->trans("Country".$obj->code) != "Country".$obj->code ? $langs->trans("Country".$obj->code) : $obj->country;
  304. print '</td>';
  305. for ($i = 0; $i < 12; $i++) {
  306. $j = $i + (empty($conf->global->SOCIETE_FISCAL_MONTH_START) ? 1 : $conf->global->SOCIETE_FISCAL_MONTH_START);
  307. if ($j > 12) {
  308. $j -= 12;
  309. }
  310. $monthj = 'month'.str_pad($j, 2, '0', STR_PAD_LEFT);
  311. print '<td class="right" width="6%">'.price($obj->$monthj).'</td>';
  312. $totalpermonth[$j] = (empty($totalpermonth[$j]) ? 0 : $totalpermonth[$j]) + $obj->$monthj;
  313. }
  314. print '<td class="right" width="6%"><b>'.price($obj->total).'</b></td>';
  315. $totalpermonth['total'] = (empty($totalpermonth['total']) ? 0 : $totalpermonth['total']) + $obj->total;
  316. print '</tr>';
  317. }
  318. $db->free($resql);
  319. // Total
  320. print '<tr class="liste_total"><td class="right"></td>';
  321. print '<td class="left"></td>';
  322. print '<td></td>';
  323. for ($i = 0; $i < 12; $i++) {
  324. $j = $i + (empty($conf->global->SOCIETE_FISCAL_MONTH_START) ? 1 : $conf->global->SOCIETE_FISCAL_MONTH_START);
  325. if ($j > 12) {
  326. $j -= 12;
  327. }
  328. $monthj = 'month'.str_pad($j, 2, '0', STR_PAD_LEFT);
  329. print '<td class="right" width="6%">'.price($totalpermonth[$j]).'</td>';
  330. }
  331. print '<td class="right" width="6%"><b>'.price($totalpermonth['total']).'</b></td>';
  332. print '</tr>';
  333. } else {
  334. print $db->lasterror(); // Show last sql error
  335. }
  336. print '<tr class="liste_titre"><td width="6%" class="right">'.$langs->trans("PurchasebyVatrate").'</td>';
  337. print '<td class="left">'.$langs->trans("ProductOrService").'</td>';
  338. print '<td class="left">'.$langs->trans("Country").'</td>';
  339. $i = 0;
  340. while ($i < 12) {
  341. $j = $i + (empty($conf->global->SOCIETE_FISCAL_MONTH_START) ? 1 : $conf->global->SOCIETE_FISCAL_MONTH_START);
  342. if ($j > 12) {
  343. $j -= 12;
  344. }
  345. print '<td width="60" class="right">'.$langs->trans('MonthShort'.str_pad($j, 2, '0', STR_PAD_LEFT)).'</td>';
  346. $i++;
  347. }
  348. print '<td width="60" class="right"><b>'.$langs->trans("TotalHT").'</b></td></tr>';
  349. // Purchase invoices
  350. $sql2 = "SELECT ffd.tva_tx AS vatrate,";
  351. $sql2 .= " ffd.product_type AS product_type,";
  352. $sql2 .= " cc.code, cc.label AS country,";
  353. for ($i = 1; $i <= 12; $i++) {
  354. $sql2 .= " SUM(".$db->ifsql('MONTH(ff.datef)='.$i, 'ffd.total_ht', '0').") AS month".str_pad($i, 2, '0', STR_PAD_LEFT).",";
  355. }
  356. $sql2 .= " SUM(ffd.total_ht) as total";
  357. $sql2 .= " FROM ".MAIN_DB_PREFIX."facture_fourn_det as ffd";
  358. $sql2 .= " INNER JOIN ".MAIN_DB_PREFIX."facture_fourn as ff ON ff.rowid = ffd.fk_facture_fourn";
  359. $sql2 .= " INNER JOIN ".MAIN_DB_PREFIX."societe as soc ON soc.rowid = ff.fk_soc";
  360. $sql2 .= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as cc ON cc.rowid = soc.fk_pays";
  361. $sql2 .= " WHERE ff.datef >= '".$db->idate($date_start)."'";
  362. $sql2 .= " AND ff.datef <= '".$db->idate($date_end)."'";
  363. $sql .= " AND ff.fk_statut in (1,2)";
  364. if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
  365. $sql .= " AND ff.type IN (0,1,2,5)";
  366. } else {
  367. $sql .= " AND ff.type IN (0,1,2,3,5)";
  368. }
  369. $sql2 .= " AND ff.entity IN (".getEntity("facture_fourn", 0).")";
  370. $sql2 .= " GROUP BY ffd.tva_tx, ffd.product_type, cc.label, cc.code ";
  371. $sql2 .= " ORDER BY country, product_type, vatrate";
  372. //print $sql2;
  373. dol_syslog("htdocs/compta/tva/index.php sql=".$sql, LOG_DEBUG);
  374. $resql2 = $db->query($sql2);
  375. if ($resql2) {
  376. $num = $db->num_rows($resql2);
  377. $totalpermonth = array();
  378. while ($obj = $db->fetch_object($resql2)) {
  379. print '<tr class="oddeven"><td class="right">'.vatrate($obj->vatrate).'</td>';
  380. if ($obj->product_type == 0) {
  381. print '<td class="left">'.$langs->trans("Product").'</td>';
  382. } else {
  383. print '<td class="left">'.$langs->trans("Service").'</td>';
  384. }
  385. print '<td>';
  386. print $langs->trans("Country".$obj->code) != "Country".$obj->code ? $langs->trans("Country".$obj->code) : $obj->country;
  387. print '</td>';
  388. for ($i = 0; $i < 12; $i++) {
  389. $j = $i + (empty($conf->global->SOCIETE_FISCAL_MONTH_START) ? 1 : $conf->global->SOCIETE_FISCAL_MONTH_START);
  390. if ($j > 12) {
  391. $j -= 12;
  392. }
  393. $monthj = 'month'.str_pad($j, 2, '0', STR_PAD_LEFT);
  394. print '<td class="right" width="6%">'.price($obj->$monthj).'</td>';
  395. $totalpermonth[$j] = (empty($totalpermonth[$j]) ? 0 : $totalpermonth[$j]) + $obj->$monthj;
  396. }
  397. print '<td class="right" width="6%"><b>'.price($obj->total).'</b></td>';
  398. $totalpermonth['total'] = (empty($totalpermonth['total']) ? 0 : $totalpermonth['total']) + $obj->total;
  399. print '</tr>';
  400. }
  401. $db->free($resql2);
  402. // Total
  403. print '<tr class="liste_total"><td class="right"></td>';
  404. print '<td class="left"></td>';
  405. print '<td></td>';
  406. for ($i = 0; $i < 12; $i++) {
  407. $j = $i + (empty($conf->global->SOCIETE_FISCAL_MONTH_START) ? 1 : $conf->global->SOCIETE_FISCAL_MONTH_START);
  408. if ($j > 12) {
  409. $j -= 12;
  410. }
  411. $monthj = 'month'.str_pad($j, 2, '0', STR_PAD_LEFT);
  412. print '<td class="right" width="6%">'.price($totalpermonth[$j]).'</td>';
  413. }
  414. print '<td class="right" width="6%"><b>'.price($totalpermonth['total']).'</b></td>';
  415. print '</tr>';
  416. } else {
  417. print $db->lasterror(); // Show last sql error
  418. }
  419. print "</table>\n";
  420. } else {
  421. // $modecompta != 'CREANCES-DETTES'
  422. // "Calculation of part of each product for accountancy in this mode is not possible. When a partial payment (for example 5 euros) is done on an
  423. // invoice with 2 product (product A for 10 euros and product B for 20 euros), what is part of paiment for product A and part of paiment for product B ?
  424. // Because there is no way to know this, this report is not relevant.
  425. print '<br>'.$langs->trans("TurnoverPerSaleTaxRateInCommitmentAccountingNotRelevant").'<br>';
  426. }
  427. // End of page
  428. llxFooter();
  429. $db->close();