PageRenderTime 55ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/compta/tva/quadri_detail.php

https://bitbucket.org/speedealing/speedealing
PHP | 630 lines | 478 code | 65 blank | 87 comment | 111 complexity | 8d0595dbcf01b5f6f7459eafa61151ea MD5 | raw file
Possible License(s): LGPL-3.0, LGPL-2.1, GPL-3.0, MIT
  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 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/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','int');
  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("RulesVATDueServices");
  120. $description.='<br>';
  121. $description.=$langs->trans("RulesVATDueProducts");
  122. //if ($conf->global->MAIN_MODULE_COMPTABILITE || $conf->global->MAIN_MODULE_ACCOUNTING) $description.='<br>'.img_warning().' '.$langs->trans('OptionVatInfoModuleComptabilite');
  123. //if (! empty($conf->global->MAIN_MODULE_COMPTABILITE)) $description.='<br>'.$langs->trans("WarningDepositsNotIncluded");
  124. if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) $description.='<br>'.$langs->trans("DepositsAreNotIncluded");
  125. else $description.='<br>'.$langs->trans("DepositsAreIncluded");
  126. $description.='<br>('.$langs->trans("TaxModuleSetupToModifyRules",DOL_URL_ROOT.'/admin/taxes.php').')';
  127. $description.=$fsearch;
  128. $builddate=time();
  129. //$exportlink=$langs->trans("NotYetAvailable");
  130. $elementcust=$langs->trans("CustomersInvoices");
  131. $productcust=$langs->trans("ProductOrService");
  132. $amountcust=$langs->trans("AmountHT");
  133. $vatcust=$langs->trans("VATReceived");
  134. if ($mysoc->tva_assuj) $vatcust.=' ('.$langs->trans("ToPay").')';
  135. $elementsup=$langs->trans("SuppliersInvoices");
  136. $productsup=$langs->trans("ProductOrService");
  137. $amountsup=$langs->trans("AmountHT");
  138. $vatsup=$langs->trans("VATPaid");
  139. if ($mysoc->tva_assuj) $vatsup.=' ('.$langs->trans("ToGetBack").')';
  140. }
  141. if ($modetax==0) // Invoice for goods, payment for services
  142. {
  143. $nom=$langs->trans("VATReportByQuartersInInputOutputMode");
  144. $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);
  145. $prevyear=$year_start; $prevquarter=$q;
  146. if ($prevquarter > 1) $prevquarter--;
  147. else { $prevquarter=4; $prevyear--; }
  148. $nextyear=$year_start; $nextquarter=$q;
  149. if ($nextquarter < 4) $nextquarter++;
  150. else { $nextquarter=1; $nextyear++; }
  151. //$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>":"");
  152. $description=$langs->trans("RulesVATInServices");
  153. $description.=' '.$langs->trans("DepositsAreIncluded");
  154. $description.='<br>';
  155. $description.=$langs->trans("RulesVATInProducts");
  156. if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) $description.=' '.$langs->trans("DepositsAreNotIncluded");
  157. else $description.=' '.$langs->trans("DepositsAreIncluded");
  158. //if ($conf->global->MAIN_MODULE_COMPTABILITE || $conf->global->MAIN_MODULE_ACCOUNTING) $description.='<br>'.img_warning().' '.$langs->trans('OptionVatInfoModuleComptabilite');
  159. //if (! empty($conf->global->MAIN_MODULE_COMPTABILITE)) $description.='<br>'.$langs->trans("WarningDepositsNotIncluded");
  160. $description.=$fsearch;
  161. $description.='<br>('.$langs->trans("TaxModuleSetupToModifyRules",DOL_URL_ROOT.'/admin/taxes.php').')';
  162. $builddate=time();
  163. //$exportlink=$langs->trans("NotYetAvailable");
  164. $elementcust=$langs->trans("CustomersInvoices");
  165. $productcust=$langs->trans("ProductOrService");
  166. $amountcust=$langs->trans("AmountHT");
  167. $vatcust=$langs->trans("VATReceived");
  168. if ($mysoc->tva_assuj) $vatcust.=' ('.$langs->trans("ToPay").')';
  169. $elementsup=$langs->trans("SuppliersInvoices");
  170. $productsup=$langs->trans("ProductOrService");
  171. $amountsup=$langs->trans("AmountHT");
  172. $vatsup=$langs->trans("VATPaid");
  173. if ($mysoc->tva_assuj) $vatsup.=' ('.$langs->trans("ToGetBack").')';
  174. }
  175. report_header($nom,$nomlink,$period,$periodlink,$description,$builddate,$exportlink);
  176. $vatcust=$langs->trans("VATReceived");
  177. $vatsup=$langs->trans("VATPaid");
  178. // VAT Received and paid
  179. echo '<table class="noborder" width="100%">';
  180. $y = $year_current;
  181. $total = 0;
  182. $i=0;
  183. // Load arrays of datas
  184. $x_coll = vat_by_date($db, 0, 0, $date_start, $date_end, $modetax, 'sell');
  185. $x_paye = vat_by_date($db, 0, 0, $date_start, $date_end, $modetax, 'buy');
  186. if (! is_array($x_coll) || ! is_array($x_paye))
  187. {
  188. $langs->load("errors");
  189. if ($x_coll == -1)
  190. print '<tr><td colspan="5">'.$langs->trans("ErrorNoAccountancyModuleLoaded").'</td></tr>';
  191. else if ($x_coll == -2)
  192. print '<tr><td colspan="5">'.$langs->trans("FeatureNotYetAvailable").'</td></tr>';
  193. else
  194. print '<tr><td colspan="5">'.$langs->trans("Error").'</td></tr>';
  195. }
  196. else
  197. {
  198. $x_both = array();
  199. //now, from these two arrays, get another array with one rate per line
  200. foreach(array_keys($x_coll) as $my_coll_rate)
  201. {
  202. $x_both[$my_coll_rate]['coll']['totalht'] = $x_coll[$my_coll_rate]['totalht'];
  203. $x_both[$my_coll_rate]['coll']['vat'] = $x_coll[$my_coll_rate]['vat'];
  204. $x_both[$my_coll_rate]['paye']['totalht'] = 0;
  205. $x_both[$my_coll_rate]['paye']['vat'] = 0;
  206. $x_both[$my_coll_rate]['coll']['links'] = '';
  207. $x_both[$my_coll_rate]['coll']['detail'] = array();
  208. foreach($x_coll[$my_coll_rate]['facid'] as $id=>$dummy)
  209. {
  210. $invoice_customer->id=$x_coll[$my_coll_rate]['facid'][$id];
  211. $invoice_customer->ref=$x_coll[$my_coll_rate]['facnum'][$id];
  212. $invoice_customer->type=$x_coll[$my_coll_rate]['type'][$id];
  213. $x_both[$my_coll_rate]['coll']['detail'][] = array(
  214. 'id' =>$x_coll[$my_coll_rate]['facid'][$id],
  215. 'descr' =>$x_coll[$my_coll_rate]['descr'][$id],
  216. 'pid' =>$x_coll[$my_coll_rate]['pid'][$id],
  217. 'pref' =>$x_coll[$my_coll_rate]['pref'][$id],
  218. 'ptype' =>$x_coll[$my_coll_rate]['ptype'][$id],
  219. 'payment_id'=>$x_coll[$my_coll_rate]['payment_id'][$id],
  220. 'payment_amount'=>$x_coll[$my_coll_rate]['payment_amount'][$id],
  221. 'ftotal_ttc'=>$x_coll[$my_coll_rate]['ftotal_ttc'][$id],
  222. 'dtotal_ttc'=>$x_coll[$my_coll_rate]['dtotal_ttc'][$id],
  223. 'dtype' =>$x_coll[$my_coll_rate]['dtype'][$id],
  224. 'ddate_start'=>$x_coll[$my_coll_rate]['ddate_start'][$id],
  225. 'ddate_end' =>$x_coll[$my_coll_rate]['ddate_end'][$id],
  226. 'totalht' =>$x_coll[$my_coll_rate]['totalht_list'][$id],
  227. 'vat' =>$x_coll[$my_coll_rate]['vat_list'][$id],
  228. 'link' =>$invoice_customer->getNomUrl(1,'',12));
  229. }
  230. }
  231. // tva paid
  232. foreach(array_keys($x_paye) as $my_paye_rate){
  233. $x_both[$my_paye_rate]['paye']['totalht'] = $x_paye[$my_paye_rate]['totalht'];
  234. $x_both[$my_paye_rate]['paye']['vat'] = $x_paye[$my_paye_rate]['vat'];
  235. if(!isset($x_both[$my_paye_rate]['coll']['totalht'])){
  236. $x_both[$my_paye_rate]['coll']['totalht'] = 0;
  237. $x_both[$my_paye_rate]['coll']['vat'] = 0;
  238. }
  239. $x_both[$my_paye_rate]['paye']['links'] = '';
  240. $x_both[$my_paye_rate]['paye']['detail'] = array();
  241. foreach($x_paye[$my_paye_rate]['facid'] as $id=>$dummy)
  242. {
  243. $invoice_supplier->id=$x_paye[$my_paye_rate]['facid'][$id];
  244. $invoice_supplier->ref=$x_paye[$my_paye_rate]['facnum'][$id];
  245. $invoice_supplier->type=$x_paye[$my_paye_rate]['type'][$id];
  246. $x_both[$my_paye_rate]['paye']['detail'][] = array(
  247. 'id' =>$x_paye[$my_paye_rate]['facid'][$id],
  248. 'descr' =>$x_paye[$my_paye_rate]['descr'][$id],
  249. 'pid' =>$x_paye[$my_paye_rate]['pid'][$id],
  250. 'pref' =>$x_paye[$my_paye_rate]['pref'][$id],
  251. 'ptype' =>$x_paye[$my_paye_rate]['ptype'][$id],
  252. 'payment_id'=>$x_paye[$my_paye_rate]['payment_id'][$id],
  253. 'payment_amount'=>$x_paye[$my_paye_rate]['payment_amount'][$id],
  254. 'ftotal_ttc'=>price2num($x_paye[$my_paye_rate]['ftotal_ttc'][$id]),
  255. 'dtotal_ttc'=>price2num($x_paye[$my_paye_rate]['dtotal_ttc'][$id]),
  256. 'dtype' =>$x_paye[$my_paye_rate]['dtype'][$id],
  257. 'ddate_start'=>$x_paye[$my_paye_rate]['ddate_start'][$id],
  258. 'ddate_end' =>$x_paye[$my_paye_rate]['ddate_end'][$id],
  259. 'totalht' =>price2num($x_paye[$my_paye_rate]['totalht_list'][$id]),
  260. 'vat' =>$x_paye[$my_paye_rate]['vat_list'][$id],
  261. 'link' =>$invoice_supplier->getNomUrl(1,'',12));
  262. }
  263. }
  264. //now we have an array (x_both) indexed by rates for coll and paye
  265. //print table headers for this quadri - incomes first
  266. $x_coll_sum = 0;
  267. $x_coll_ht = 0;
  268. $x_paye_sum = 0;
  269. $x_paye_ht = 0;
  270. $span=3;
  271. if ($modetax == 0) $span+=2;
  272. //print '<tr><td colspan="'.($span+1).'">'..')</td></tr>';
  273. // Customers invoices
  274. print '<tr class="liste_titre">';
  275. print '<td align="left">'.$elementcust.'</td>';
  276. print '<td align="left">'.$productcust.'</td>';
  277. if ($modetax == 0)
  278. {
  279. print '<td align="right">'.$amountcust.'</td>';
  280. print '<td align="right">'.$langs->trans("Payment").' ('.$langs->trans("PercentOfInvoice").')</td>';
  281. }
  282. print '<td align="right">'.$langs->trans("AmountHTVATRealReceived").'</td>';
  283. print '<td align="right">'.$vatcust.'</td>';
  284. print '</tr>';
  285. foreach(array_keys($x_coll) as $rate)
  286. {
  287. $subtot_coll_total_ht = 0;
  288. $subtot_coll_vat = 0;
  289. if (is_array($x_both[$rate]['coll']['detail']))
  290. {
  291. // VAT Rate
  292. $var=true;
  293. print "<tr>";
  294. print '<td class="tax_rate">'.$langs->trans("Rate").': '.vatrate($rate).'%</td><td colspan="'.$span.'"></td>';
  295. print '</tr>'."\n";
  296. foreach($x_both[$rate]['coll']['detail'] as $index => $fields)
  297. {
  298. // Define type
  299. $type=($fields['dtype']?$fields['dtype']:$fields['ptype']);
  300. // Try to enhance type detection using date_start and date_end for free lines where type
  301. // was not saved.
  302. if (! empty($fields['ddate_start'])) $type=1;
  303. if (! empty($fields['ddate_end'])) $type=1;
  304. $var=!$var;
  305. print '<tr '.$bc[$var].'>';
  306. // Ref
  307. print '<td nowrap align="left">'.$fields['link'].'</td>';
  308. // Description
  309. print '<td align="left">';
  310. if ($fields['pid'])
  311. {
  312. $product_static->id=$fields['pid'];
  313. $product_static->ref=$fields['pref'];
  314. $product_static->type=$fields['ptype'];
  315. print $product_static->getNomUrl(1);
  316. if (dol_string_nohtmltag($fields['descr'])) print ' - '.dol_trunc(dol_string_nohtmltag($fields['descr']),16);
  317. }
  318. else
  319. {
  320. if ($type) $text = img_object($langs->trans('Service'),'service');
  321. else $text = img_object($langs->trans('Product'),'product');
  322. if (preg_match('/^\((.*)\)$/',$fields['descr'],$reg))
  323. {
  324. if ($reg[1]=='DEPOSIT') $fields['descr']=$langs->transnoentitiesnoconv('Deposit');
  325. elseif ($reg[1]=='CREDIT_NOTE') $fields['descr']=$langs->transnoentitiesnoconv('CreditNote');
  326. else $fields['descr']=$langs->transnoentitiesnoconv($reg[1]);
  327. }
  328. print $text.' '.dol_trunc(dol_string_nohtmltag($fields['descr']),16);
  329. // Show range
  330. print_date_range($fields['ddate_start'],$fields['ddate_end']);
  331. }
  332. print '</td>';
  333. // Total HT
  334. if ($modetax == 0)
  335. {
  336. print '<td nowrap align="right">';
  337. print price($fields['totalht']);
  338. if (price2num($fields['ftotal_ttc']))
  339. {
  340. //print $fields['dtotal_ttc']."/".$fields['ftotal_ttc']." - ";
  341. $ratiolineinvoice=($fields['dtotal_ttc']/$fields['ftotal_ttc']);
  342. //print ' ('.round($ratiolineinvoice*100,2).'%)';
  343. }
  344. print '</td>';
  345. }
  346. // Payment
  347. $ratiopaymentinvoice=1;
  348. if ($modetax == 0)
  349. {
  350. if (isset($fields['payment_amount']) && $fields['ftotal_ttc']) $ratiopaymentinvoice=($fields['payment_amount']/$fields['ftotal_ttc']);
  351. print '<td nowrap align="right">';
  352. //print $fields['totalht']."-".$fields['payment_amount']."-".$fields['ftotal_ttc'];
  353. if ($fields['payment_amount'] && $fields['ftotal_ttc'])
  354. {
  355. $payment_static->id=$fields['payment_id'];
  356. print $payment_static->getNomUrl(2);
  357. }
  358. if ($type == 0)
  359. {
  360. print $langs->trans("NotUsedForGoods");
  361. }
  362. else {
  363. print $fields['payment_amount'];
  364. if (isset($fields['payment_amount'])) print ' ('.round($ratiopaymentinvoice*100,2).'%)';
  365. }
  366. print '</td>';
  367. }
  368. // Total collected
  369. print '<td nowrap align="right">';
  370. $temp_ht=$fields['totalht'];
  371. if ($type == 1) $temp_ht=$fields['totalht']*$ratiopaymentinvoice;
  372. print price(price2num($temp_ht,'MT'));
  373. print '</td>';
  374. // VAT
  375. print '<td nowrap align="right">';
  376. $temp_vat=$fields['vat'];
  377. if ($type == 1) $temp_vat=$fields['vat']*$ratiopaymentinvoice;
  378. print price(price2num($temp_vat,'MT'));
  379. //print price($fields['vat']);
  380. print '</td>';
  381. print '</tr>';
  382. $subtot_coll_total_ht += $temp_ht;
  383. $subtot_coll_vat += $temp_vat;
  384. $x_coll_sum += $temp_vat;
  385. }
  386. }
  387. // Total customers for this vat rate
  388. print '<tr class="liste_total">';
  389. print '<td></td>';
  390. print '<td align="right">'.$langs->trans("Total").':</td>';
  391. if ($modetax == 0)
  392. {
  393. print '<td nowrap align="right">&nbsp;</td>';
  394. print '<td align="right">&nbsp;</td>';
  395. }
  396. print '<td align="right">'.price(price2num($subtot_coll_total_ht,'MT')).'</td>';
  397. print '<td nowrap align="right">'.price(price2num($subtot_coll_vat,'MT')).'</td>';
  398. print '</tr>';
  399. }
  400. if (count($x_coll) == 0) // Show a total ine if nothing shown
  401. {
  402. print '<tr class="liste_total">';
  403. print '<td>&nbsp;</td>';
  404. print '<td align="right">'.$langs->trans("Total").':</td>';
  405. if ($modetax == 0)
  406. {
  407. print '<td nowrap align="right">&nbsp;</td>';
  408. print '<td align="right">&nbsp;</td>';
  409. }
  410. print '<td align="right">'.price(price2num(0,'MT')).'</td>';
  411. print '<td nowrap align="right">'.price(price2num(0,'MT')).'</td>';
  412. print '</tr>';
  413. }
  414. // Blank line
  415. print '<tr><td colspan="'.($span+1).'">&nbsp;</td></tr>';
  416. //print table headers for this quadri - expenses now
  417. //imprime les en-tete de tables pour ce quadri - maintenant les d�penses
  418. print '<tr class="liste_titre">';
  419. print '<td align="left">'.$elementsup.'</td>';
  420. print '<td align="left">'.$productsup.'</td>';
  421. if ($modetax == 0)
  422. {
  423. print '<td align="right">'.$amountsup.'</td>';
  424. print '<td align="right">'.$langs->trans("Payment").' ('.$langs->trans("PercentOfInvoice").')</td>';
  425. }
  426. print '<td align="right">'.$langs->trans("AmountHTVATRealPaid").'</td>';
  427. print '<td align="right">'.$vatsup.'</td>';
  428. print '</tr>'."\n";
  429. foreach(array_keys($x_paye) as $rate)
  430. {
  431. $subtot_paye_total_ht = 0;
  432. $subtot_paye_vat = 0;
  433. if(is_array($x_both[$rate]['paye']['detail']))
  434. {
  435. $var=true;
  436. print "<tr>";
  437. print '<td class="tax_rate">'.$langs->trans("Rate").': '.vatrate($rate).'%</td><td colspan="'.$span.'"></td>';
  438. print '</tr>'."\n";
  439. foreach($x_both[$rate]['paye']['detail'] as $index=>$fields)
  440. {
  441. // Define type
  442. $type=($fields['dtype']?$fields['dtype']:$fields['ptype']);
  443. // Try to enhance type detection using date_start and date_end for free lines where type
  444. // was not saved.
  445. if (! empty($fields['ddate_start'])) $type=1;
  446. if (! empty($fields['ddate_end'])) $type=1;
  447. $var=!$var;
  448. print '<tr '.$bc[$var].'>';
  449. // Ref
  450. print '<td nowrap align="left">'.$fields['link'].'</td>';
  451. // Description
  452. print '<td align="left">';
  453. if ($fields['pid'])
  454. {
  455. $product_static->id=$fields['pid'];
  456. $product_static->ref=$fields['pref'];
  457. $product_static->type=$fields['ptype'];
  458. print $product_static->getNomUrl(1);
  459. if (dol_string_nohtmltag($fields['descr'])) print ' - '.dol_trunc(dol_string_nohtmltag($fields['descr']),16);
  460. }
  461. else
  462. {
  463. if ($type) $text = img_object($langs->trans('Service'),'service');
  464. else $text = img_object($langs->trans('Product'),'product');
  465. print $text.' '.dol_trunc(dol_string_nohtmltag($fields['descr']),16);
  466. // Show range
  467. print_date_range($fields['ddate_start'],$fields['ddate_end']);
  468. }
  469. print '</td>';
  470. // Total HT
  471. if ($modetax == 0)
  472. {
  473. print '<td nowrap align="right">';
  474. print price($fields['totalht']);
  475. if (price2num($fields['ftotal_ttc']))
  476. {
  477. //print $fields['dtotal_ttc']."/".$fields['ftotal_ttc']." - ";
  478. $ratiolineinvoice=($fields['dtotal_ttc']/$fields['ftotal_ttc']);
  479. //print ' ('.round($ratiolineinvoice*100,2).'%)';
  480. }
  481. print '</td>';
  482. }
  483. // Payment
  484. $ratiopaymentinvoice=1;
  485. if ($modetax == 0)
  486. {
  487. if (isset($fields['payment_amount']) && $fields['ftotal_ttc']) $ratiopaymentinvoice=($fields['payment_amount']/$fields['ftotal_ttc']);
  488. print '<td nowrap align="right">';
  489. if ($fields['payment_amount'] && $fields['ftotal_ttc'])
  490. {
  491. $paymentfourn_static->id=$fields['payment_id'];
  492. print $paymentfourn_static->getNomUrl(2);
  493. }
  494. if ($type == 0)
  495. {
  496. print $langs->trans("NotUsedForGoods");
  497. }
  498. else
  499. {
  500. print $fields['payment_amount'];
  501. if (isset($fields['payment_amount'])) print ' ('.round($ratiopaymentinvoice*100,2).'%)';
  502. }
  503. print '</td>';
  504. }
  505. // VAT paid
  506. print '<td nowrap align="right">';
  507. $temp_ht=$fields['totalht'];
  508. if ($type == 1) $temp_ht=$fields['totalht']*$ratiopaymentinvoice;
  509. print price(price2num($temp_ht,'MT'));
  510. print '</td>';
  511. // VAT
  512. print '<td nowrap align="right">';
  513. $temp_vat=$fields['vat'];
  514. if ($type == 1) $temp_vat=$fields['vat']*$ratiopaymentinvoice;
  515. print price(price2num($temp_vat,'MT'));
  516. //print price($fields['vat']);
  517. print '</td>';
  518. print '</tr>';
  519. $subtot_paye_total_ht += $temp_ht;
  520. $subtot_paye_vat += $temp_vat;
  521. $x_paye_sum += $temp_vat;
  522. }
  523. }
  524. // Total suppliers for this vat rate
  525. print '<tr class="liste_total">';
  526. print '<td>&nbsp;</td>';
  527. print '<td align="right">'.$langs->trans("Total").':</td>';
  528. if ($modetax == 0)
  529. {
  530. print '<td nowrap align="right">&nbsp;</td>';
  531. print '<td align="right">&nbsp;</td>';
  532. }
  533. print '<td align="right">'.price(price2num($subtot_paye_total_ht,'MT')).'</td>';
  534. print '<td nowrap align="right">'.price(price2num($subtot_paye_vat,'MT')).'</td>';
  535. print '</tr>';
  536. }
  537. if (count($x_paye) == 0) // Show a total ine if nothing shown
  538. {
  539. print '<tr class="liste_total">';
  540. print '<td>&nbsp;</td>';
  541. print '<td align="right">'.$langs->trans("Total").':</td>';
  542. if ($modetax == 0)
  543. {
  544. print '<td nowrap align="right">&nbsp;</td>';
  545. print '<td align="right">&nbsp;</td>';
  546. }
  547. print '<td align="right">'.price(price2num(0,'MT')).'</td>';
  548. print '<td nowrap align="right">'.price(price2num(0,'MT')).'</td>';
  549. print '</tr>';
  550. }
  551. print '</table>';
  552. // Total to pay
  553. print '<br><br>';
  554. print '<table class="noborder" width="100%">';
  555. $diff = $x_coll_sum - $x_paye_sum;
  556. print '<tr class="liste_total">';
  557. print '<td class="liste_total" colspan="'.$span.'">'.$langs->trans("TotalToPay").($q?', '.$langs->trans("Quadri").' '.$q:'').'</td>';
  558. print '<td class="liste_total" nowrap="nowrap" align="right"><b>'.price(price2num($diff,'MT'))."</b></td>\n";
  559. print "</tr>\n";
  560. $i++;
  561. }
  562. echo '</table>';
  563. $db->close();
  564. llxFooter();
  565. ?>