byratecountry.php 19 KB

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