PageRenderTime 46ms CodeModel.GetById 15ms RepoModel.GetById 1ms app.codeStats 0ms

/htdocs/compta/tva/quadri_detail.php

https://github.com/asterix14/dolibarr
PHP | 615 lines | 465 code | 65 blank | 85 comment | 106 complexity | cc1978b91eca91eb8d92555b47a1a1da MD5 | raw file
Possible License(s): LGPL-2.0
  1. <?php
  2. /* Copyright (C) 2001-2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004 Eric Seigne <eric.seigne@ryxeo.com>
  4. * Copyright (C) 2004-2010 Laurent Destailleur <eldy@users.sourceforge.net>
  5. * Copyright (C) 2006-2007 Yannick Warnier <ywarnier@beeznest.org>
  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 2 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/tva/quadri_detail.php
  22. * \ingroup tax
  23. * \brief Trimestrial page - detailed version
  24. * TODO Deal with recurrent invoices as well
  25. */
  26. require('../../main.inc.php');
  27. require_once(DOL_DOCUMENT_ROOT."/core/lib/report.lib.php");
  28. require_once(DOL_DOCUMENT_ROOT."/core/lib/tax.lib.php");
  29. require_once(DOL_DOCUMENT_ROOT."/core/lib/date.lib.php");
  30. require_once(DOL_DOCUMENT_ROOT."/compta/tva/class/tva.class.php");
  31. require_once(DOL_DOCUMENT_ROOT."/compta/facture/class/facture.class.php");
  32. require_once(DOL_DOCUMENT_ROOT."/product/class/product.class.php");
  33. require_once(DOL_DOCUMENT_ROOT."/compta/paiement/class/paiement.class.php");
  34. require_once(DOL_DOCUMENT_ROOT."/fourn/class/fournisseur.facture.class.php");
  35. require_once(DOL_DOCUMENT_ROOT."/fourn/class/paiementfourn.class.php");
  36. $langs->load("bills");
  37. $langs->load("compta");
  38. $langs->load("companies");
  39. $langs->load("products");
  40. // Date range
  41. $year=GETPOST("year");
  42. if (empty($year))
  43. {
  44. $year_current = strftime("%Y",dol_now());
  45. $year_start = $year_current;
  46. } else {
  47. $year_current = $year;
  48. $year_start = $year;
  49. }
  50. $date_start=dol_mktime(0,0,0,$_REQUEST["date_startmonth"],$_REQUEST["date_startday"],$_REQUEST["date_startyear"]);
  51. $date_end=dol_mktime(23,59,59,$_REQUEST["date_endmonth"],$_REQUEST["date_endday"],$_REQUEST["date_endyear"]);
  52. // Quarter
  53. if (empty($date_start) || empty($date_end)) // We define date_start and date_end
  54. {
  55. $q=GETPOST("q");
  56. if (empty($q))
  57. {
  58. if (isset($_REQUEST["month"])) { $date_start=dol_get_first_day($year_start,$_REQUEST["month"],false); $date_end=dol_get_last_day($year_start,$_REQUEST["month"],false); }
  59. else
  60. {
  61. $month_current = strftime("%m",dol_now());
  62. if ($month_current >= 10) $q=4;
  63. elseif ($month_current >= 7) $q=3;
  64. elseif ($month_current >= 4) $q=2;
  65. else $q=1;
  66. }
  67. }
  68. if ($q==1) { $date_start=dol_get_first_day($year_start,1,false); $date_end=dol_get_last_day($year_start,3,false); }
  69. if ($q==2) { $date_start=dol_get_first_day($year_start,4,false); $date_end=dol_get_last_day($year_start,6,false); }
  70. if ($q==3) { $date_start=dol_get_first_day($year_start,7,false); $date_end=dol_get_last_day($year_start,9,false); }
  71. if ($q==4) { $date_start=dol_get_first_day($year_start,10,false); $date_end=dol_get_last_day($year_start,12,false); }
  72. }
  73. $min = GETPOST("min");
  74. if (empty($min)) $min = 0;
  75. // Define modetax (0 or 1)
  76. // 0=normal, 1=option vat for services is on debit
  77. $modetax = $conf->global->TAX_MODE;
  78. if (isset($_REQUEST["modetax"])) $modetax=$_REQUEST["modetax"];
  79. if (empty($modetax)) $modetax=0;
  80. // Security check
  81. $socid = GETPOST("socid");
  82. if ($user->societe_id) $socid=$user->societe_id;
  83. $result = restrictedArea($user, 'tax', '', '', 'charges');
  84. /*
  85. * View
  86. */
  87. $morequerystring='';
  88. $listofparams=array('date_startmonth','date_startyear','date_startday','date_endmonth','date_endyear','date_endday');
  89. foreach($listofparams as $param)
  90. {
  91. if (GETPOST($param)!='') $morequerystring.=($morequerystring?'&':'').$param.'='.GETPOST($param);
  92. }
  93. llxHeader('','','','',0,0,'','',$morequerystring);
  94. $form=new Form($db);
  95. $company_static=new Societe($db);
  96. $invoice_customer=new Facture($db);
  97. $invoice_supplier=new FactureFournisseur($db);
  98. $product_static=new Product($db);
  99. $payment_static=new Paiement($db);
  100. $paymentfourn_static=new PaiementFourn($db);
  101. //print_fiche_titre($langs->trans("VAT"),"");
  102. //$fsearch.='<br>';
  103. $fsearch.=' <input type="hidden" name="year" value="'.$year.'">';
  104. $fsearch.=' <input type="hidden" name="modetax" value="'.$modetax.'">';
  105. //$fsearch.=' '.$langs->trans("SalesTurnover").' '.$langs->trans("Minimum").': ';
  106. //$fsearch.=' <input type="text" name="min" value="'.$min.'">';
  107. // Affiche en-tete du rapport
  108. if ($modetax==1) // Calculate on invoice for goods and services
  109. {
  110. $nom=$langs->trans("VATReportByQuartersInDueDebtMode");
  111. $period=$form->select_date($date_start,'date_start',0,0,0,'',1,0,1).' - '.$form->select_date($date_end,'date_end',0,0,0,'',1,0,1);
  112. $prevyear=$year_start; $prevquarter=$q;
  113. if ($prevquarter > 1) $prevquarter--;
  114. else { $prevquarter=4; $prevyear--; }
  115. $nextyear=$year_start; $nextquarter=$q;
  116. if ($nextquarter < 4) $nextquarter++;
  117. else { $nextquarter=1; $nextyear++; }
  118. //$periodlink=($prevyear?"<a href='".$_SERVER["PHP_SELF"]."?year=".$prevyear."&q=".$prevquarter."&modetax=".$modetax."'>".img_previous()."</a> <a href='".$_SERVER["PHP_SELF"]."?year=".$nextyear."&q=".$nextquarter."&modetax=".$modetax."'>".img_next()."</a>":"");
  119. $description=$langs->trans("RulesVATDue");
  120. //if ($conf->global->MAIN_MODULE_COMPTABILITE || $conf->global->MAIN_MODULE_ACCOUNTING) $description.='<br>'.img_warning().' '.$langs->trans('OptionVatInfoModuleComptabilite');
  121. if ($conf->global->MAIN_MODULE_COMPTABILITE) $description.='<br>'.$langs->trans("WarningDepositsNotIncluded");
  122. $description.='<br>('.$langs->trans("TaxModuleSetupToModifyRules",DOL_URL_ROOT.'/admin/taxes.php').')';
  123. $description.=$fsearch;
  124. $builddate=time();
  125. //$exportlink=$langs->trans("NotYetAvailable");
  126. $elementcust=$langs->trans("CustomersInvoices");
  127. $productcust=$langs->trans("ProductOrService");
  128. $amountcust=$langs->trans("AmountHT");
  129. $vatcust=$langs->trans("VATReceived");
  130. if ($mysoc->tva_assuj) $vatcust.=' ('.$langs->trans("ToPay").')';
  131. $elementsup=$langs->trans("SuppliersInvoices");
  132. $productsup=$langs->trans("ProductOrService");
  133. $amountsup=$langs->trans("AmountHT");
  134. $vatsup=$langs->trans("VATPaid");
  135. if ($mysoc->tva_assuj) $vatsup.=' ('.$langs->trans("ToGetBack").')';
  136. }
  137. if ($modetax==0) // Invoice for goods, payment for services
  138. {
  139. $nom=$langs->trans("VATReportByQuartersInInputOutputMode");
  140. $period=$form->select_date($date_start,'date_start',0,0,0,'',1,0,1).' - '.$form->select_date($date_end,'date_end',0,0,0,'',1,0,1);
  141. $prevyear=$year_start; $prevquarter=$q;
  142. if ($prevquarter > 1) $prevquarter--;
  143. else { $prevquarter=4; $prevyear--; }
  144. $nextyear=$year_start; $nextquarter=$q;
  145. if ($nextquarter < 4) $nextquarter++;
  146. else { $nextquarter=1; $nextyear++; }
  147. //$periodlink=($prevyear?"<a href='".$_SERVER["PHP_SELF"]."?year=".$prevyear."&q=".$prevquarter."&modetax=".$modetax."'>".img_previous()."</a> <a href='".$_SERVER["PHP_SELF"]."?year=".$nextyear."&q=".$nextquarter."&modetax=".$modetax."'>".img_next()."</a>":"");
  148. $description=$langs->trans("RulesVATIn");
  149. //if ($conf->global->MAIN_MODULE_COMPTABILITE || $conf->global->MAIN_MODULE_ACCOUNTING) $description.='<br>'.img_warning().' '.$langs->trans('OptionVatInfoModuleComptabilite');
  150. if ($conf->global->MAIN_MODULE_COMPTABILITE) $description.='<br>'.$langs->trans("WarningDepositsNotIncluded");
  151. $description.=$fsearch;
  152. $description.='<br>('.$langs->trans("TaxModuleSetupToModifyRules",DOL_URL_ROOT.'/admin/taxes.php').')';
  153. $builddate=time();
  154. //$exportlink=$langs->trans("NotYetAvailable");
  155. $elementcust=$langs->trans("CustomersInvoices");
  156. $productcust=$langs->trans("ProductOrService");
  157. $amountcust=$langs->trans("AmountHT");
  158. $vatcust=$langs->trans("VATReceived");
  159. if ($mysoc->tva_assuj) $vatcust.=' ('.$langs->trans("ToPay").')';
  160. $elementsup=$langs->trans("SuppliersInvoices");
  161. $productsup=$langs->trans("ProductOrService");
  162. $amountsup=$langs->trans("AmountHT");
  163. $vatsup=$langs->trans("VATPaid");
  164. if ($mysoc->tva_assuj) $vatsup.=' ('.$langs->trans("ToGetBack").')';
  165. }
  166. report_header($nom,$nomlink,$period,$periodlink,$description,$builddate,$exportlink);
  167. $vatcust=$langs->trans("VATReceived");
  168. $vatsup=$langs->trans("VATPaid");
  169. // VAT Received and paid
  170. echo '<table class="noborder" width="100%">';
  171. $y = $year_current;
  172. $total = 0;
  173. $i=0;
  174. // Load arrays of datas
  175. $x_coll = vat_by_date($db, 0, 0, $date_start, $date_end, $modetax, 'sell');
  176. $x_paye = vat_by_date($db, 0, 0, $date_start, $date_end, $modetax, 'buy');
  177. if (! is_array($x_coll) || ! is_array($x_paye))
  178. {
  179. $langs->load("errors");
  180. if ($x_coll == -1)
  181. print '<tr><td colspan="5">'.$langs->trans("ErrorNoAccountancyModuleLoaded").'</td></tr>';
  182. else if ($x_coll == -2)
  183. print '<tr><td colspan="5">'.$langs->trans("FeatureNotYetAvailable").'</td></tr>';
  184. else
  185. print '<tr><td colspan="5">'.$langs->trans("Error").'</td></tr>';
  186. }
  187. else
  188. {
  189. $x_both = array();
  190. //now, from these two arrays, get another array with one rate per line
  191. foreach(array_keys($x_coll) as $my_coll_rate)
  192. {
  193. $x_both[$my_coll_rate]['coll']['totalht'] = $x_coll[$my_coll_rate]['totalht'];
  194. $x_both[$my_coll_rate]['coll']['vat'] = $x_coll[$my_coll_rate]['vat'];
  195. $x_both[$my_coll_rate]['paye']['totalht'] = 0;
  196. $x_both[$my_coll_rate]['paye']['vat'] = 0;
  197. $x_both[$my_coll_rate]['coll']['links'] = '';
  198. $x_both[$my_coll_rate]['coll']['detail'] = array();
  199. foreach($x_coll[$my_coll_rate]['facid'] as $id=>$dummy)
  200. {
  201. $invoice_customer->id=$x_coll[$my_coll_rate]['facid'][$id];
  202. $invoice_customer->ref=$x_coll[$my_coll_rate]['facnum'][$id];
  203. $invoice_customer->type=$x_coll[$my_coll_rate]['type'][$id];
  204. $x_both[$my_coll_rate]['coll']['detail'][] = array(
  205. 'id' =>$x_coll[$my_coll_rate]['facid'][$id],
  206. 'descr' =>$x_coll[$my_coll_rate]['descr'][$id],
  207. 'pid' =>$x_coll[$my_coll_rate]['pid'][$id],
  208. 'pref' =>$x_coll[$my_coll_rate]['pref'][$id],
  209. 'ptype' =>$x_coll[$my_coll_rate]['ptype'][$id],
  210. 'payment_id'=>$x_coll[$my_coll_rate]['payment_id'][$id],
  211. 'payment_amount'=>$x_coll[$my_coll_rate]['payment_amount'][$id],
  212. 'ftotal_ttc'=>$x_coll[$my_coll_rate]['ftotal_ttc'][$id],
  213. 'dtotal_ttc'=>$x_coll[$my_coll_rate]['dtotal_ttc'][$id],
  214. 'dtype' =>$x_coll[$my_coll_rate]['dtype'][$id],
  215. 'ddate_start'=>$x_coll[$my_coll_rate]['ddate_start'][$id],
  216. 'ddate_end' =>$x_coll[$my_coll_rate]['ddate_end'][$id],
  217. 'totalht' =>$x_coll[$my_coll_rate]['totalht_list'][$id],
  218. 'vat' =>$x_coll[$my_coll_rate]['vat_list'][$id],
  219. 'link' =>$invoice_customer->getNomUrl(1,'',12));
  220. }
  221. }
  222. // tva paid
  223. foreach(array_keys($x_paye) as $my_paye_rate){
  224. $x_both[$my_paye_rate]['paye']['totalht'] = $x_paye[$my_paye_rate]['totalht'];
  225. $x_both[$my_paye_rate]['paye']['vat'] = $x_paye[$my_paye_rate]['vat'];
  226. if(!isset($x_both[$my_paye_rate]['coll']['totalht'])){
  227. $x_both[$my_paye_rate]['coll']['totalht'] = 0;
  228. $x_both[$my_paye_rate]['coll']['vat'] = 0;
  229. }
  230. $x_both[$my_paye_rate]['paye']['links'] = '';
  231. $x_both[$my_paye_rate]['paye']['detail'] = array();
  232. foreach($x_paye[$my_paye_rate]['facid'] as $id=>$dummy)
  233. {
  234. $invoice_supplier->id=$x_paye[$my_paye_rate]['facid'][$id];
  235. $invoice_supplier->ref=$x_paye[$my_paye_rate]['facnum'][$id];
  236. $invoice_supplier->type=$x_paye[$my_paye_rate]['type'][$id];
  237. $x_both[$my_paye_rate]['paye']['detail'][] = array(
  238. 'id' =>$x_paye[$my_paye_rate]['facid'][$id],
  239. 'descr' =>$x_paye[$my_paye_rate]['descr'][$id],
  240. 'pid' =>$x_paye[$my_paye_rate]['pid'][$id],
  241. 'pref' =>$x_paye[$my_paye_rate]['pref'][$id],
  242. 'ptype' =>$x_paye[$my_paye_rate]['ptype'][$id],
  243. 'payment_id'=>$x_paye[$my_paye_rate]['payment_id'][$id],
  244. 'payment_amount'=>$x_paye[$my_paye_rate]['payment_amount'][$id],
  245. 'ftotal_ttc'=>price2num($x_paye[$my_paye_rate]['ftotal_ttc'][$id]),
  246. 'dtotal_ttc'=>price2num($x_paye[$my_paye_rate]['dtotal_ttc'][$id]),
  247. 'dtype' =>$x_paye[$my_paye_rate]['dtype'][$id],
  248. 'ddate_start'=>$x_paye[$my_paye_rate]['ddate_start'][$id],
  249. 'ddate_end' =>$x_paye[$my_paye_rate]['ddate_end'][$id],
  250. 'totalht' =>price2num($x_paye[$my_paye_rate]['totalht_list'][$id]),
  251. 'vat' =>$x_paye[$my_paye_rate]['vat_list'][$id],
  252. 'link' =>$invoice_supplier->getNomUrl(1,'',12));
  253. }
  254. }
  255. //now we have an array (x_both) indexed by rates for coll and paye
  256. //print table headers for this quadri - incomes first
  257. $x_coll_sum = 0;
  258. $x_coll_ht = 0;
  259. $x_paye_sum = 0;
  260. $x_paye_ht = 0;
  261. $span=3;
  262. if ($modetax == 0) $span+=2;
  263. //print '<tr><td colspan="'.($span+1).'">'..')</td></tr>';
  264. // Customers invoices
  265. print '<tr class="liste_titre">';
  266. print '<td align="left">'.$elementcust.'</td>';
  267. print '<td align="left">'.$productcust.'</td>';
  268. if ($modetax == 0)
  269. {
  270. print '<td align="right">'.$amountcust.'</td>';
  271. print '<td align="right">'.$langs->trans("Payment").' ('.$langs->trans("PercentOfInvoice").')</td>';
  272. }
  273. print '<td align="right">'.$langs->trans("AmountHTVATRealReceived").'</td>';
  274. print '<td align="right">'.$vatcust.'</td>';
  275. print '</tr>';
  276. foreach(array_keys($x_coll) as $rate)
  277. {
  278. $subtot_coll_total_ht = 0;
  279. $subtot_coll_vat = 0;
  280. if (is_array($x_both[$rate]['coll']['detail']))
  281. {
  282. // VAT Rate
  283. $var=true;
  284. print "<tr>";
  285. print '<td class="tax_rate">'.$langs->trans("Rate").': '.vatrate($rate).'%</td><td colspan="'.$span.'"></td>';
  286. print '</tr>'."\n";
  287. foreach($x_both[$rate]['coll']['detail'] as $index => $fields)
  288. {
  289. // Define type
  290. $type=($fields['dtype']?$fields['dtype']:$fields['ptype']);
  291. // Try to enhance type detection using date_start and date_end for free lines where type
  292. // was not saved.
  293. if (! empty($fields['ddate_start'])) $type=1;
  294. if (! empty($fields['ddate_end'])) $type=1;
  295. $var=!$var;
  296. print '<tr '.$bc[$var].'>';
  297. // Ref
  298. print '<td nowrap align="left">'.$fields['link'].'</td>';
  299. // Description
  300. print '<td align="left">';
  301. if ($fields['pid'])
  302. {
  303. $product_static->id=$fields['pid'];
  304. $product_static->ref=$fields['pref'];
  305. $product_static->type=$fields['ptype'];
  306. print $product_static->getNomUrl(1);
  307. if (dol_string_nohtmltag($fields['descr'])) print ' - '.dol_trunc(dol_string_nohtmltag($fields['descr']),16);
  308. }
  309. else
  310. {
  311. if ($type) $text = img_object($langs->trans('Service'),'service');
  312. else $text = img_object($langs->trans('Product'),'product');
  313. print $text.' '.dol_trunc(dol_string_nohtmltag($fields['descr']),16);
  314. // Show range
  315. print_date_range($fields['ddate_start'],$fields['ddate_end']);
  316. }
  317. print '</td>';
  318. // Total HT
  319. if ($modetax == 0)
  320. {
  321. print '<td nowrap align="right">';
  322. print price($fields['totalht']);
  323. if (price2num($fields['ftotal_ttc']))
  324. {
  325. //print $fields['dtotal_ttc']."/".$fields['ftotal_ttc']." - ";
  326. $ratiolineinvoice=($fields['dtotal_ttc']/$fields['ftotal_ttc']);
  327. //print ' ('.round($ratiolineinvoice*100,2).'%)';
  328. }
  329. print '</td>';
  330. }
  331. // Payment
  332. $ratiopaymentinvoice=1;
  333. if ($modetax == 0)
  334. {
  335. if (isset($fields['payment_amount']) && $fields['ftotal_ttc']) $ratiopaymentinvoice=($fields['payment_amount']/$fields['ftotal_ttc']);
  336. print '<td nowrap align="right">';
  337. //print $fields['totalht']."-".$fields['payment_amount']."-".$fields['ftotal_ttc'];
  338. if ($fields['payment_amount'] && $fields['ftotal_ttc'])
  339. {
  340. $payment_static->id=$fields['payment_id'];
  341. print $payment_static->getNomUrl(2);
  342. }
  343. if ($type == 0)
  344. {
  345. print $langs->trans("NotUsedForGoods");
  346. }
  347. else {
  348. print $fields['payment_amount'];
  349. if (isset($fields['payment_amount'])) print ' ('.round($ratiopaymentinvoice*100,2).'%)';
  350. }
  351. print '</td>';
  352. }
  353. // Total collected
  354. print '<td nowrap align="right">';
  355. $temp_ht=$fields['totalht'];
  356. if ($type == 1) $temp_ht=$fields['totalht']*$ratiopaymentinvoice;
  357. print price(price2num($temp_ht,'MT'));
  358. print '</td>';
  359. // VAT
  360. print '<td nowrap align="right">';
  361. $temp_vat=$fields['vat'];
  362. if ($type == 1) $temp_vat=$fields['vat']*$ratiopaymentinvoice;
  363. print price(price2num($temp_vat,'MT'));
  364. //print price($fields['vat']);
  365. print '</td>';
  366. print '</tr>';
  367. $subtot_coll_total_ht += $temp_ht;
  368. $subtot_coll_vat += $temp_vat;
  369. $x_coll_sum += $temp_vat;
  370. }
  371. }
  372. // Total customers for this vat rate
  373. print '<tr class="liste_total">';
  374. print '<td></td>';
  375. print '<td align="right">'.$langs->trans("Total").':</td>';
  376. if ($modetax == 0)
  377. {
  378. print '<td nowrap align="right">&nbsp;</td>';
  379. print '<td align="right">&nbsp;</td>';
  380. }
  381. print '<td align="right">'.price(price2num($subtot_coll_total_ht,'MT')).'</td>';
  382. print '<td nowrap align="right">'.price(price2num($subtot_coll_vat,'MT')).'</td>';
  383. print '</tr>';
  384. }
  385. if (count($x_coll) == 0) // Show a total ine if nothing shown
  386. {
  387. print '<tr class="liste_total">';
  388. print '<td>&nbsp;</td>';
  389. print '<td align="right">'.$langs->trans("Total").':</td>';
  390. if ($modetax == 0)
  391. {
  392. print '<td nowrap align="right">&nbsp;</td>';
  393. print '<td align="right">&nbsp;</td>';
  394. }
  395. print '<td align="right">'.price(price2num(0,'MT')).'</td>';
  396. print '<td nowrap align="right">'.price(price2num(0,'MT')).'</td>';
  397. print '</tr>';
  398. }
  399. // Blank line
  400. print '<tr><td colspan="'.($span+1).'">&nbsp;</td></tr>';
  401. //print table headers for this quadri - expenses now
  402. //imprime les en-tete de tables pour ce quadri - maintenant les d�penses
  403. print '<tr class="liste_titre">';
  404. print '<td align="left">'.$elementsup.'</td>';
  405. print '<td align="left">'.$productsup.'</td>';
  406. if ($modetax == 0)
  407. {
  408. print '<td align="right">'.$amountsup.'</td>';
  409. print '<td align="right">'.$langs->trans("Payment").' ('.$langs->trans("PercentOfInvoice").')</td>';
  410. }
  411. print '<td align="right">'.$langs->trans("AmountHTVATRealPaid").'</td>';
  412. print '<td align="right">'.$vatsup.'</td>';
  413. print '</tr>'."\n";
  414. foreach(array_keys($x_paye) as $rate)
  415. {
  416. $subtot_paye_total_ht = 0;
  417. $subtot_paye_vat = 0;
  418. if(is_array($x_both[$rate]['paye']['detail']))
  419. {
  420. $var=true;
  421. print "<tr>";
  422. print '<td class="tax_rate">'.$langs->trans("Rate").': '.vatrate($rate).'%</td><td colspan="'.$span.'"></td>';
  423. print '</tr>'."\n";
  424. foreach($x_both[$rate]['paye']['detail'] as $index=>$fields)
  425. {
  426. // Define type
  427. $type=($fields['dtype']?$fields['dtype']:$fields['ptype']);
  428. // Try to enhance type detection using date_start and date_end for free lines where type
  429. // was not saved.
  430. if (! empty($fields['ddate_start'])) $type=1;
  431. if (! empty($fields['ddate_end'])) $type=1;
  432. $var=!$var;
  433. print '<tr '.$bc[$var].'>';
  434. // Ref
  435. print '<td nowrap align="left">'.$fields['link'].'</td>';
  436. // Description
  437. print '<td align="left">';
  438. if ($fields['pid'])
  439. {
  440. $product_static->id=$fields['pid'];
  441. $product_static->ref=$fields['pref'];
  442. $product_static->type=$fields['ptype'];
  443. print $product_static->getNomUrl(1);
  444. if (dol_string_nohtmltag($fields['descr'])) print ' - '.dol_trunc(dol_string_nohtmltag($fields['descr']),16);
  445. }
  446. else
  447. {
  448. if ($type) $text = img_object($langs->trans('Service'),'service');
  449. else $text = img_object($langs->trans('Product'),'product');
  450. print $text.' '.dol_trunc(dol_string_nohtmltag($fields['descr']),16);
  451. // Show range
  452. print_date_range($fields['ddate_start'],$fields['ddate_end']);
  453. }
  454. print '</td>';
  455. // Total HT
  456. if ($modetax == 0)
  457. {
  458. print '<td nowrap align="right">';
  459. print price($fields['totalht']);
  460. if (price2num($fields['ftotal_ttc']))
  461. {
  462. //print $fields['dtotal_ttc']."/".$fields['ftotal_ttc']." - ";
  463. $ratiolineinvoice=($fields['dtotal_ttc']/$fields['ftotal_ttc']);
  464. //print ' ('.round($ratiolineinvoice*100,2).'%)';
  465. }
  466. print '</td>';
  467. }
  468. // Payment
  469. $ratiopaymentinvoice=1;
  470. if ($modetax == 0)
  471. {
  472. if (isset($fields['payment_amount']) && $fields['ftotal_ttc']) $ratiopaymentinvoice=($fields['payment_amount']/$fields['ftotal_ttc']);
  473. print '<td nowrap align="right">';
  474. if ($fields['payment_amount'] && $fields['ftotal_ttc'])
  475. {
  476. $paymentfourn_static->id=$fields['payment_id'];
  477. print $paymentfourn_static->getNomUrl(2);
  478. }
  479. if ($type == 0)
  480. {
  481. print $langs->trans("NotUsedForGoods");
  482. }
  483. else
  484. {
  485. print $fields['payment_amount'];
  486. if (isset($fields['payment_amount'])) print ' ('.round($ratiopaymentinvoice*100,2).'%)';
  487. }
  488. print '</td>';
  489. }
  490. // VAT paid
  491. print '<td nowrap align="right">';
  492. $temp_ht=$fields['totalht'];
  493. if ($type == 1) $temp_ht=$fields['totalht']*$ratiopaymentinvoice;
  494. print price(price2num($temp_ht,'MT'));
  495. print '</td>';
  496. // VAT
  497. print '<td nowrap align="right">';
  498. $temp_vat=$fields['vat'];
  499. if ($type == 1) $temp_vat=$fields['vat']*$ratiopaymentinvoice;
  500. print price(price2num($temp_vat,'MT'));
  501. //print price($fields['vat']);
  502. print '</td>';
  503. print '</tr>';
  504. $subtot_paye_total_ht += $temp_ht;
  505. $subtot_paye_vat += $temp_vat;
  506. $x_paye_sum += $temp_vat;
  507. }
  508. }
  509. // Total suppliers for this vat rate
  510. print '<tr class="liste_total">';
  511. print '<td>&nbsp;</td>';
  512. print '<td align="right">'.$langs->trans("Total").':</td>';
  513. if ($modetax == 0)
  514. {
  515. print '<td nowrap align="right">&nbsp;</td>';
  516. print '<td align="right">&nbsp;</td>';
  517. }
  518. print '<td align="right">'.price(price2num($subtot_paye_total_ht,'MT')).'</td>';
  519. print '<td nowrap align="right">'.price(price2num($subtot_paye_vat,'MT')).'</td>';
  520. print '</tr>';
  521. }
  522. if (count($x_paye) == 0) // Show a total ine if nothing shown
  523. {
  524. print '<tr class="liste_total">';
  525. print '<td>&nbsp;</td>';
  526. print '<td align="right">'.$langs->trans("Total").':</td>';
  527. if ($modetax == 0)
  528. {
  529. print '<td nowrap align="right">&nbsp;</td>';
  530. print '<td align="right">&nbsp;</td>';
  531. }
  532. print '<td align="right">'.price(price2num(0,'MT')).'</td>';
  533. print '<td nowrap align="right">'.price(price2num(0,'MT')).'</td>';
  534. print '</tr>';
  535. }
  536. print '</table>';
  537. // Total to pay
  538. print '<br><br>';
  539. print '<table class="noborder" width="100%">';
  540. $diff = $x_coll_sum - $x_paye_sum;
  541. print '<tr class="liste_total">';
  542. print '<td class="liste_total" colspan="'.$span.'">'.$langs->trans("TotalToPay").($q?', '.$langs->trans("Quadri").' '.$q:'').'</td>';
  543. print '<td class="liste_total" nowrap="nowrap" align="right"><b>'.price(price2num($diff,'MT'))."</b></td>\n";
  544. print "</tr>\n";
  545. $i++;
  546. }
  547. echo '</table>';
  548. $db->close();
  549. llxFooter();
  550. ?>