PageRenderTime 36ms CodeModel.GetById 8ms RepoModel.GetById 1ms app.codeStats 0ms

/htdocs/compta/localtax/clients.php

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