PageRenderTime 39ms CodeModel.GetById 12ms RepoModel.GetById 1ms app.codeStats 0ms

/htdocs/compta/tva/clients.php

https://github.com/asterix14/dolibarr
PHP | 329 lines | 239 code | 39 blank | 51 comment | 48 complexity | 6fef3cb3a380c73579ca35bdac1563cc 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 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/clients.php
  22. * \ingroup tax
  23. * \brief Page des societes
  24. */
  25. require('../../main.inc.php');
  26. require_once(DOL_DOCUMENT_ROOT."/core/lib/report.lib.php");
  27. require_once(DOL_DOCUMENT_ROOT."/core/lib/tax.lib.php");
  28. require_once(DOL_DOCUMENT_ROOT."/core/lib/date.lib.php");
  29. require_once(DOL_DOCUMENT_ROOT."/compta/tva/class/tva.class.php");
  30. $langs->load("bills");
  31. $langs->load("compta");
  32. $langs->load("companies");
  33. $langs->load("products");
  34. // Date range
  35. $year=GETPOST("year");
  36. if (empty($year))
  37. {
  38. $year_current = strftime("%Y",dol_now());
  39. $year_start = $year_current;
  40. } else {
  41. $year_current = $year;
  42. $year_start = $year;
  43. }
  44. $date_start=dol_mktime(0,0,0,$_REQUEST["date_startmonth"],$_REQUEST["date_startday"],$_REQUEST["date_startyear"]);
  45. $date_end=dol_mktime(23,59,59,$_REQUEST["date_endmonth"],$_REQUEST["date_endday"],$_REQUEST["date_endyear"]);
  46. // Quarter
  47. if (empty($date_start) || empty($date_end)) // We define date_start and date_end
  48. {
  49. $q=GETPOST("q");
  50. if (empty($q))
  51. {
  52. 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); }
  53. else
  54. {
  55. $month_current = strftime("%m",dol_now());
  56. if ($month_current >= 10) $q=4;
  57. elseif ($month_current >= 7) $q=3;
  58. elseif ($month_current >= 4) $q=2;
  59. else $q=1;
  60. }
  61. }
  62. if ($q==1) { $date_start=dol_get_first_day($year_start,1,false); $date_end=dol_get_last_day($year_start,3,false); }
  63. if ($q==2) { $date_start=dol_get_first_day($year_start,4,false); $date_end=dol_get_last_day($year_start,6,false); }
  64. if ($q==3) { $date_start=dol_get_first_day($year_start,7,false); $date_end=dol_get_last_day($year_start,9,false); }
  65. if ($q==4) { $date_start=dol_get_first_day($year_start,10,false); $date_end=dol_get_last_day($year_start,12,false); }
  66. }
  67. $min = GETPOST("min");
  68. if (empty($min)) $min = 0;
  69. // Define modetax (0 or 1)
  70. // 0=normal, 1=option vat for services is on debit
  71. $modetax = $conf->global->TAX_MODE;
  72. if (isset($_REQUEST["modetax"])) $modetax=$_REQUEST["modetax"];
  73. // Security check
  74. $socid = GETPOST("socid");
  75. if ($user->societe_id) $socid=$user->societe_id;
  76. $result = restrictedArea($user, 'tax', '', '', 'charges');
  77. /*
  78. * View
  79. */
  80. $form=new Form($db);
  81. $company_static=new Societe($db);
  82. $morequerystring='';
  83. $listofparams=array('date_startmonth','date_startyear','date_startday','date_endmonth','date_endyear','date_endday');
  84. foreach($listofparams as $param)
  85. {
  86. if (GETPOST($param)!='') $morequerystring.=($morequerystring?'&':'').$param.'='.GETPOST($param);
  87. }
  88. llxHeader('','','','',0,0,'','',$morequerystring);
  89. $fsearch.='<br>';
  90. $fsearch.=' <input type="hidden" name="year" value="'.$year.'">';
  91. $fsearch.=' <input type="hidden" name="modetax" value="'.$modetax.'">';
  92. $fsearch.=' '.$langs->trans("SalesTurnover").' '.$langs->trans("Minimum").': ';
  93. $fsearch.=' <input type="text" name="min" id="min" value="'.$min.'" size="6">';
  94. // Affiche en-tete du rapport
  95. if ($modetax==1) // Calculate on invoice for goods and services
  96. {
  97. $nom=$langs->trans("VATReportByCustomersInDueDebtMode");
  98. //$nom.='<br>('.$langs->trans("SeeVATReportInInputOutputMode",'<a href="'.$_SERVER["PHP_SELF"].'?year='.$year_start.'&modetax=0">','</a>').')';
  99. $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);
  100. //$periodlink=($year_start?"<a href='".$_SERVER["PHP_SELF"]."?year=".($year_start-1)."&modetax=".$modetax."'>".img_previous()."</a> <a href='".$_SERVER["PHP_SELF"]."?year=".($year_start+1)."&modetax=".$modetax."'>".img_next()."</a>":"");
  101. $description=$langs->trans("RulesVATDue");
  102. //if ($conf->global->MAIN_MODULE_COMPTABILITE || $conf->global->MAIN_MODULE_ACCOUNTING) $description.='<br>'.img_warning().' '.$langs->trans('OptionVatInfoModuleComptabilite');
  103. if ($conf->global->MAIN_MODULE_COMPTABILITE) $description.='<br>'.$langs->trans("WarningDepositsNotIncluded");
  104. $description.=$fsearch;
  105. $description.='<br>('.$langs->trans("TaxModuleSetupToModifyRules",DOL_URL_ROOT.'/admin/taxes.php').')';
  106. $builddate=time();
  107. //$exportlink=$langs->trans("NotYetAvailable");
  108. $elementcust=$langs->trans("CustomersInvoices");
  109. $productcust=$langs->trans("Description");
  110. $amountcust=$langs->trans("AmountHT");
  111. if ($mysoc->tva_assuj) $vatcust.=' ('.$langs->trans("ToPay").')';
  112. $elementsup=$langs->trans("SuppliersInvoices");
  113. $productsup=$langs->trans("Description");
  114. $amountsup=$langs->trans("AmountHT");
  115. if ($mysoc->tva_assuj) $vatsup.=' ('.$langs->trans("ToGetBack").')';
  116. }
  117. if ($modetax==0) // Invoice for goods, payment for services
  118. {
  119. $nom=$langs->trans("VATReportByCustomersInInputOutputMode");
  120. //$nom.='<br>('.$langs->trans("SeeVATReportInDueDebtMode",'<a href="'.$_SERVER["PHP_SELF"].'?year='.$year_start.'&modetax=1">','</a>').')';
  121. $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);
  122. //$periodlink=($year_start?"<a href='".$_SERVER["PHP_SELF"]."?year=".($year_start-1)."&modetax=".$modetax."'>".img_previous()."</a> <a href='".$_SERVER["PHP_SELF"]."?year=".($year_start+1)."&modetax=".$modetax."'>".img_next()."</a>":"");
  123. $description=$langs->trans("RulesVATIn");
  124. //if ($conf->global->MAIN_MODULE_COMPTABILITE || $conf->global->MAIN_MODULE_ACCOUNTING) $description.='<br>'.img_warning().' '.$langs->trans('OptionVatInfoModuleComptabilite');
  125. if ($conf->global->MAIN_MODULE_COMPTABILITE) $description.='<br>'.$langs->trans("WarningDepositsNotIncluded");
  126. $description.=$fsearch;
  127. $description.='<br>('.$langs->trans("TaxModuleSetupToModifyRules",DOL_URL_ROOT.'/admin/taxes.php').')';
  128. $builddate=time();
  129. //$exportlink=$langs->trans("NotYetAvailable");
  130. $elementcust=$langs->trans("CustomersInvoices");
  131. $productcust=$langs->trans("Description");
  132. $amountcust=$langs->trans("AmountHT");
  133. if ($mysoc->tva_assuj) $vatcust.=' ('.$langs->trans("ToPay").')';
  134. $elementsup=$langs->trans("SuppliersInvoices");
  135. $productsup=$langs->trans("Description");
  136. $amountsup=$langs->trans("AmountHT");
  137. if ($mysoc->tva_assuj) $vatsup.=' ('.$langs->trans("ToGetBack").')';
  138. }
  139. report_header($nom,$nomlink,$period,$periodlink,$description,$builddate,$exportlink);
  140. $vatcust=$langs->trans("VATReceived");
  141. $vatsup=$langs->trans("VATPaid");
  142. // VAT Received
  143. //print "<br>";
  144. //print_titre($vatcust);
  145. print "<table class=\"noborder\" width=\"100%\">";
  146. print "<tr class=\"liste_titre\">";
  147. print '<td align="left">'.$langs->trans("Num")."</td>";
  148. print '<td align="left">'.$langs->trans("Customer")."</td>";
  149. print "<td>".$langs->trans("VATIntra")."</td>";
  150. print "<td align=\"right\">".$langs->trans("AmountHTVATRealReceived")."</td>";
  151. print "<td align=\"right\">".$vatcust."</td>";
  152. print "</tr>\n";
  153. $coll_list = vat_by_thirdparty($db,0,$date_start,$date_end,$modetax,'sell');
  154. if (is_array($coll_list))
  155. {
  156. $var=true;
  157. $total = 0; $totalamount = 0;
  158. $i = 1;
  159. foreach($coll_list as $coll)
  160. {
  161. if($min == 0 or ($min > 0 && $coll->amount > $min))
  162. {
  163. $var=!$var;
  164. $intra = str_replace($find,$replace,$coll->tva_intra);
  165. if(empty($intra))
  166. {
  167. if($coll->assuj == '1')
  168. {
  169. $intra = $langs->trans('Unknown');
  170. }
  171. else
  172. {
  173. //$intra = $langs->trans('NotRegistered');
  174. $intra = '';
  175. }
  176. }
  177. print "<tr ".$bc[$var].">";
  178. print "<td nowrap>".$i."</td>";
  179. $company_static->id=$coll->socid;
  180. $company_static->nom=$coll->nom;
  181. print '<td nowrap>'.$company_static->getNomUrl(1).'</td>';
  182. $find = array(' ','.');
  183. $replace = array('','');
  184. print "<td nowrap>".$intra."</td>";
  185. print "<td nowrap align=\"right\">".price($coll->amount)."</td>";
  186. print "<td nowrap align=\"right\">".price($coll->tva)."</td>";
  187. $totalamount = $totalamount + $coll->amount;
  188. $total = $total + $coll->tva;
  189. print "</tr>\n";
  190. $i++;
  191. }
  192. }
  193. $x_coll_sum = $total;
  194. print '<tr class="liste_total"><td align="right" colspan="3">'.$langs->trans("Total").':</td>';
  195. print '<td nowrap align="right">'.price($totalamount).'</td>';
  196. print '<td nowrap align="right">'.price($total).'</td>';
  197. print '</tr>';
  198. }
  199. else
  200. {
  201. $langs->load("errors");
  202. if ($coll_list == -1)
  203. print '<tr><td colspan="5">'.$langs->trans("ErrorNoAccountancyModuleLoaded").'</td></tr>';
  204. else if ($coll_list == -2)
  205. print '<tr><td colspan="5">'.$langs->trans("FeatureNotYetAvailable").'</td></tr>';
  206. else
  207. print '<tr><td colspan="5">'.$langs->trans("Error").'</td></tr>';
  208. }
  209. //print '</table>';
  210. // VAT Paid
  211. //print "<br>";
  212. //print_titre($vatsup);
  213. //print "<table class=\"noborder\" width=\"100%\">";
  214. print "<tr class=\"liste_titre\">";
  215. print '<td align="left">'.$langs->trans("Num")."</td>";
  216. print '<td align="left">'.$langs->trans("Supplier")."</td>";
  217. print "<td>".$langs->trans("VATIntra")."</td>";
  218. print "<td align=\"right\">".$langs->trans("AmountHTVATRealPaid")."</td>";
  219. print "<td align=\"right\">".$vatsup."</td>";
  220. print "</tr>\n";
  221. $company_static=new Societe($db);
  222. $coll_list = vat_by_thirdparty($db,0,$date_start,$date_end,$modetax,'buy');
  223. if (is_array($coll_list))
  224. {
  225. $var=true;
  226. $total = 0; $totalamount = 0;
  227. $i = 1;
  228. foreach($coll_list as $coll)
  229. {
  230. if($min == 0 or ($min > 0 && $coll->amount > $min))
  231. {
  232. $var=!$var;
  233. $intra = str_replace($find,$replace,$coll->tva_intra);
  234. if(empty($intra))
  235. {
  236. if($coll->assuj == '1')
  237. {
  238. $intra = $langs->trans('Unknown');
  239. }
  240. else
  241. {
  242. //$intra = $langs->trans('NotRegistered');
  243. $intra = '';
  244. }
  245. }
  246. print "<tr $bc[$var]>";
  247. print "<td nowrap>".$i."</td>";
  248. $company_static->id=$coll->socid;
  249. $company_static->nom=$coll->nom;
  250. print '<td nowrap>'.$company_static->getNomUrl(1).'</td>';
  251. $find = array(' ','.');
  252. $replace = array('','');
  253. print "<td nowrap>".$intra."</td>";
  254. print "<td nowrap align=\"right\">".price($coll->amount)."</td>";
  255. print "<td nowrap align=\"right\">".price($coll->tva)."</td>";
  256. $totalamount = $totalamount + $coll->amount;
  257. $total = $total + $coll->tva;
  258. print "</tr>\n";
  259. $i++;
  260. }
  261. }
  262. $x_paye_sum = $total;
  263. print '<tr class="liste_total"><td align="right" colspan="3">'.$langs->trans("Total").':</td>';
  264. print '<td nowrap align="right">'.price($totalamount).'</td>';
  265. print '<td nowrap align="right">'.price($total).'</td>';
  266. print '</tr>';
  267. print '</table>';
  268. // Total to pay
  269. print '<br><br>';
  270. print '<table class="noborder" width="100%">';
  271. $diff = $x_coll_sum - $x_paye_sum;
  272. print '<tr class="liste_total">';
  273. print '<td class="liste_total" colspan="4">'.$langs->trans("TotalToPay").($q?', '.$langs->trans("Quadri").' '.$q:'').'</td>';
  274. print '<td class="liste_total" nowrap="nowrap" align="right"><b>'.price(price2num($diff,'MT'))."</b></td>\n";
  275. print "</tr>\n";
  276. }
  277. else
  278. {
  279. $langs->load("errors");
  280. if ($coll_list == -1)
  281. print '<tr><td colspan="5">'.$langs->trans("ErrorNoAccountancyModuleLoaded").'</td></tr>';
  282. else if ($coll_list == -2)
  283. print '<tr><td colspan="5">'.$langs->trans("FeatureNotYetAvailable").'</td></tr>';
  284. else
  285. print '<tr><td colspan="5">'.$langs->trans("Error").'</td></tr>';
  286. }
  287. print '</table>';
  288. $db->close();
  289. llxFooter();
  290. ?>