clients.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  1. <?php
  2. /* Copyright (C) 2011 Juanjo Menent <jmenent@2byte.es>
  3. * Copyright (C) 2014 Ferran Marcet <fmarcet@2byte.es>
  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 <http://www.gnu.org/licenses/>.
  17. */
  18. /**
  19. * \file htdocs/compta/localtax/clients.php
  20. * \ingroup tax
  21. * \brief Third parties localtax report
  22. */
  23. require '../../main.inc.php';
  24. require_once DOL_DOCUMENT_ROOT.'/core/lib/report.lib.php';
  25. require_once DOL_DOCUMENT_ROOT.'/core/lib/tax.lib.php';
  26. require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
  27. require_once DOL_DOCUMENT_ROOT.'/compta/localtax/class/localtax.class.php';
  28. $langs->load("bills");
  29. $langs->load("compta");
  30. $langs->load("companies");
  31. $langs->load("products");
  32. // Date range
  33. $year=GETPOST("year");
  34. if (empty($year))
  35. {
  36. $year_current = strftime("%Y",dol_now());
  37. $year_start = $year_current;
  38. } else {
  39. $year_current = $year;
  40. $year_start = $year;
  41. }
  42. $date_start=dol_mktime(0,0,0,$_REQUEST["date_startmonth"],$_REQUEST["date_startday"],$_REQUEST["date_startyear"]);
  43. $date_end=dol_mktime(23,59,59,$_REQUEST["date_endmonth"],$_REQUEST["date_endday"],$_REQUEST["date_endyear"]);
  44. // Quarter
  45. if (empty($date_start) || empty($date_end)) // We define date_start and date_end
  46. {
  47. $q=GETPOST("q");
  48. if (empty($q))
  49. {
  50. 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); }
  51. else
  52. {
  53. $month_current = strftime("%m",dol_now());
  54. if ($month_current >= 10) $q=4;
  55. elseif ($month_current >= 7) $q=3;
  56. elseif ($month_current >= 4) $q=2;
  57. else $q=1;
  58. }
  59. }
  60. if ($q==1) { $date_start=dol_get_first_day($year_start,1,false); $date_end=dol_get_last_day($year_start,3,false); }
  61. if ($q==2) { $date_start=dol_get_first_day($year_start,4,false); $date_end=dol_get_last_day($year_start,6,false); }
  62. if ($q==3) { $date_start=dol_get_first_day($year_start,7,false); $date_end=dol_get_last_day($year_start,9,false); }
  63. if ($q==4) { $date_start=dol_get_first_day($year_start,10,false); $date_end=dol_get_last_day($year_start,12,false); }
  64. }
  65. $min = GETPOST("min");
  66. if (empty($min)) $min = 0;
  67. // Define modetax (0 or 1)
  68. // 0=normal, 1=option vat for services is on debit
  69. $modetax = $conf->global->TAX_MODE;
  70. if (isset($_REQUEST["modetax"])) $modetax=$_REQUEST["modetax"];
  71. // Security check
  72. $socid = GETPOST('socid','int');
  73. if ($user->societe_id) $socid=$user->societe_id;
  74. $result = restrictedArea($user, 'tax', '', '', 'charges');
  75. /*
  76. * View
  77. */
  78. $form=new Form($db);
  79. $company_static=new Societe($db);
  80. $morequerystring='';
  81. $listofparams=array('date_startmonth','date_startyear','date_startday','date_endmonth','date_endyear','date_endday');
  82. foreach($listofparams as $param)
  83. {
  84. if (GETPOST($param)!='') $morequerystring.=($morequerystring?'&':'').$param.'='.GETPOST($param);
  85. }
  86. llxHeader('','','','',0,0,'','',$morequerystring);
  87. $fsearch.='<br>';
  88. $fsearch.=' <input type="hidden" name="year" value="'.$year.'">';
  89. $fsearch.=' <input type="hidden" name="modetax" value="'.$modetax.'">';
  90. $fsearch.=' '.$langs->trans("SalesTurnoverMinimum").': ';
  91. $fsearch.=' <input type="text" name="min" id="min" value="'.$min.'" size="6">';
  92. // Affiche en-tete du rapport
  93. if ($modetax==1) // Calculate on invoice for goods and services
  94. {
  95. $nom=$langs->transcountry("LT2ReportByCustomersInInputOutputMode",$mysoc->country_code);
  96. $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);
  97. $description=$langs->trans("RulesVATDue");
  98. if (! empty($conf->global->MAIN_MODULE_COMPTABILITE)) $description.='<br>'.$langs->trans("WarningDepositsNotIncluded");
  99. $description.=$fsearch;
  100. $description.='<br>('.$langs->trans("TaxModuleSetupToModifyRules",DOL_URL_ROOT.'/admin/taxes.php').')';
  101. $builddate=time();
  102. $elementcust=$langs->trans("CustomersInvoices");
  103. $productcust=$langs->trans("Description");
  104. $amountcust=$langs->trans("AmountHT");
  105. $elementsup=$langs->trans("SuppliersInvoices");
  106. $productsup=$langs->trans("Description");
  107. $amountsup=$langs->trans("AmountHT");
  108. }
  109. if ($modetax==0) // Invoice for goods, payment for services
  110. {
  111. $nom=$langs->transcountry("LT2ReportByCustomersInInputOutputMode",$mysoc->country_code);
  112. $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);
  113. $description=$langs->trans("RulesVATIn");
  114. if (! empty($conf->global->MAIN_MODULE_COMPTABILITE)) $description.='<br>'.$langs->trans("WarningDepositsNotIncluded");
  115. $description.=$fsearch;
  116. $description.='<br>('.$langs->trans("TaxModuleSetupToModifyRules",DOL_URL_ROOT.'/admin/taxes.php').')';
  117. $builddate=time();
  118. $elementcust=$langs->trans("CustomersInvoices");
  119. $productcust=$langs->trans("Description");
  120. $amountcust=$langs->trans("AmountHT");
  121. $elementsup=$langs->trans("SuppliersInvoices");
  122. $productsup=$langs->trans("Description");
  123. $amountsup=$langs->trans("AmountHT");
  124. }
  125. report_header($nom,$nomlink,$period,$periodlink,$description,$builddate,$exportlink);
  126. $vatcust=$langs->transcountry("LT2",$mysoc->country_code);
  127. $vatsup=$langs->transcountry("LT2",$mysoc->country_code);
  128. // IRPF that the customer has retained me
  129. print "<table class=\"noborder\" width=\"100%\">";
  130. print "<tr class=\"liste_titre\">";
  131. print '<td align="left">'.$langs->trans("Num")."</td>";
  132. print '<td align="left">'.$langs->trans("Customer")."</td>";
  133. print "<td>".$langs->transcountry("ProfId1",$mysoc->country_code)."</td>";
  134. print "<td align=\"right\">".$langs->trans("TotalHT")."</td>";
  135. print "<td align=\"right\">".$vatcust."</td>";
  136. print "</tr>\n";
  137. $coll_list = vat_by_thirdparty($db,0,$date_start,$date_end,$modetax,'sell');
  138. $action = "tvaclient";
  139. $object = &$coll_list;
  140. $parameters["mode"] = $modetax;
  141. $parameters["start"] = $date_start;
  142. $parameters["end"] = $date_end;
  143. $parameters["direction"] = 'sell';
  144. // Initialize technical object to manage hooks of expenses. Note that conf->hooks_modules contains array array
  145. $hookmanager->initHooks(array('externalbalance'));
  146. $reshook=$hookmanager->executeHooks('addStatisticLine',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
  147. if (is_array($coll_list))
  148. {
  149. $var=true;
  150. $total = 0; $totalamount = 0;
  151. $i = 1;
  152. foreach($coll_list as $coll)
  153. {
  154. if(($min == 0 or ($min > 0 && $coll->amount > $min)) && $coll->localtax2!=0)
  155. {
  156. $var=!$var;
  157. $intra = str_replace($find,$replace,$coll->tva_intra);
  158. if(empty($intra))
  159. {
  160. if($coll->assuj == '1')
  161. {
  162. $intra = $langs->trans('Unknown');
  163. }
  164. else
  165. {
  166. $intra = '';
  167. }
  168. }
  169. print "<tr ".$bc[$var].">";
  170. print '<td class="nowrap">'.$i."</td>";
  171. $company_static->id=$coll->socid;
  172. $company_static->nom=$coll->nom;
  173. print '<td class="nowrap">'.$company_static->getNomUrl(1).'</td>';
  174. $find = array(' ','.');
  175. $replace = array('','');
  176. print '<td class="nowrap">'.$intra."</td>";
  177. print "<td class=\"nowrap\" align=\"right\">".price($coll->amount)."</td>";
  178. print "<td class=\"nowrap\" align=\"right\">".price($coll->localtax2)."</td>";
  179. $totalamount = $totalamount + $coll->amount;
  180. $total = $total + $coll->localtax2;
  181. print "</tr>\n";
  182. $i++;
  183. }
  184. }
  185. $x_coll_sum = $total;
  186. print '<tr class="liste_total"><td align="right" colspan="3">'.$langs->trans("Total").':</td>';
  187. print '<td class="nowrap" align="right">'.price($totalamount).'</td>';
  188. print '<td class="nowrap" align="right">'.price($total).'</td>';
  189. print '</tr>';
  190. }
  191. else
  192. {
  193. $langs->load("errors");
  194. if ($coll_list == -1)
  195. print '<tr><td colspan="5">'.$langs->trans("ErrorNoAccountancyModuleLoaded").'</td></tr>';
  196. else if ($coll_list == -2)
  197. print '<tr><td colspan="5">'.$langs->trans("FeatureNotYetAvailable").'</td></tr>';
  198. else
  199. print '<tr><td colspan="5">'.$langs->trans("Error").'</td></tr>';
  200. }
  201. // IRPF I retained my supplier
  202. print "<tr class=\"liste_titre\">";
  203. print '<td align="left">'.$langs->trans("Num")."</td>";
  204. print '<td align="left">'.$langs->trans("Supplier")."</td>";
  205. print "<td>".$langs->transcountry("ProfId1",$mysoc->country_code)."</td>";
  206. print "<td align=\"right\">".$langs->trans("TotalHT")."</td>";
  207. print "<td align=\"right\">".$vatsup."</td>";
  208. print "</tr>\n";
  209. $company_static=new Societe($db);
  210. $coll_list = vat_by_thirdparty($db,0,$date_start,$date_end,$modetax,'buy');
  211. $parameters["direction"] = 'buy';
  212. $reshook=$hookmanager->executeHooks('addStatisticLine',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
  213. if (is_array($coll_list))
  214. {
  215. $var=true;
  216. $total = 0; $totalamount = 0;
  217. $i = 1;
  218. foreach($coll_list as $coll)
  219. {
  220. if(($min == 0 or ($min > 0 && $coll->amount > $min)) && $coll->localtax2!=0)
  221. {
  222. $var=!$var;
  223. $intra = str_replace($find,$replace,$coll->tva_intra);
  224. if(empty($intra))
  225. {
  226. if($coll->assuj == '1')
  227. {
  228. $intra = $langs->trans('Unknown');
  229. }
  230. else
  231. {
  232. $intra = '';
  233. }
  234. }
  235. print "<tr ".$bc[$var].">";
  236. print '<td class="nowrap">'.$i."</td>";
  237. $company_static->id=$coll->socid;
  238. $company_static->nom=$coll->nom;
  239. print '<td class="nowrap">'.$company_static->getNomUrl(1).'</td>';
  240. $find = array(' ','.');
  241. $replace = array('','');
  242. print '<td class="nowrap">'.$intra."</td>";
  243. print "<td class=\"nowrap\" align=\"right\">".price($coll->amount)."</td>";
  244. print "<td class=\"nowrap\" align=\"right\">".price($coll->localtax2)."</td>";
  245. $totalamount = $totalamount + $coll->amount;
  246. $total = $total + $coll->localtax2;
  247. print "</tr>\n";
  248. $i++;
  249. }
  250. }
  251. $x_paye_sum = $total;
  252. print '<tr class="liste_total"><td align="right" colspan="3">'.$langs->trans("Total").':</td>';
  253. print '<td class="nowrap" align="right">'.price($totalamount).'</td>';
  254. print '<td class="nowrap" align="right">'.price($total).'</td>';
  255. print '</tr>';
  256. print '</table>';
  257. // Total to pay
  258. print '<br><br>';
  259. print '<table class="noborder" width="100%">';
  260. $diff = $x_paye_sum;
  261. print '<tr class="liste_total">';
  262. print '<td class="liste_total" colspan="4">'.$langs->trans("TotalToPay").($q?', '.$langs->trans("Quadri").' '.$q:'').'</td>';
  263. print '<td class="liste_total nowrap" align="right"><b>'.price(price2num($diff,'MT'))."</b></td>\n";
  264. print "</tr>\n";
  265. }
  266. else
  267. {
  268. $langs->load("errors");
  269. if ($coll_list == -1)
  270. print '<tr><td colspan="5">'.$langs->trans("ErrorNoAccountancyModuleLoaded").'</td></tr>';
  271. else if ($coll_list == -2)
  272. print '<tr><td colspan="5">'.$langs->trans("FeatureNotYetAvailable").'</td></tr>';
  273. else
  274. print '<tr><td colspan="5">'.$langs->trans("Error").'</td></tr>';
  275. }
  276. print '</table>';
  277. $db->close();
  278. llxFooter();