PageRenderTime 61ms CodeModel.GetById 30ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/compta/tva/clients.php

https://bitbucket.org/speedealing/speedealing
PHP | 340 lines | 248 code | 39 blank | 53 comment | 50 complexity | d0aac4b0df0ce3d148a5f920af39a505 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 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/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','int');
  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("RulesVATDueServices");
  102. $description.='<br>';
  103. $description.=$langs->trans("RulesVATDueProducts");
  104. //if ($conf->global->MAIN_MODULE_COMPTABILITE || $conf->global->MAIN_MODULE_ACCOUNTING) $description.='<br>'.img_warning().' '.$langs->trans('OptionVatInfoModuleComptabilite');
  105. //if (! empty($conf->global->MAIN_MODULE_COMPTABILITE)) $description.='<br>'.$langs->trans("WarningDepositsNotIncluded");
  106. if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) $description.='<br>'.$langs->trans("DepositsAreNotIncluded");
  107. else $description.='<br>'.$langs->trans("DepositsAreIncluded");
  108. $description.=$fsearch;
  109. $description.='<br>('.$langs->trans("TaxModuleSetupToModifyRules",DOL_URL_ROOT.'/admin/taxes.php').')';
  110. $builddate=time();
  111. //$exportlink=$langs->trans("NotYetAvailable");
  112. $elementcust=$langs->trans("CustomersInvoices");
  113. $productcust=$langs->trans("Description");
  114. $amountcust=$langs->trans("AmountHT");
  115. if ($mysoc->tva_assuj) $vatcust.=' ('.$langs->trans("ToPay").')';
  116. $elementsup=$langs->trans("SuppliersInvoices");
  117. $productsup=$langs->trans("Description");
  118. $amountsup=$langs->trans("AmountHT");
  119. if ($mysoc->tva_assuj) $vatsup.=' ('.$langs->trans("ToGetBack").')';
  120. }
  121. if ($modetax==0) // Invoice for goods, payment for services
  122. {
  123. $nom=$langs->trans("VATReportByCustomersInInputOutputMode");
  124. //$nom.='<br>('.$langs->trans("SeeVATReportInDueDebtMode",'<a href="'.$_SERVER["PHP_SELF"].'?year='.$year_start.'&modetax=1">','</a>').')';
  125. $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);
  126. //$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>":"");
  127. $description=$langs->trans("RulesVATInServices");
  128. $description.=' '.$langs->trans("DepositsAreIncluded");
  129. $description.='<br>';
  130. $description.=$langs->trans("RulesVATInProducts");
  131. if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) $description.=' '.$langs->trans("DepositsAreNotIncluded");
  132. else $description.=' '.$langs->trans("DepositsAreIncluded");
  133. //if ($conf->global->MAIN_MODULE_COMPTABILITE || $conf->global->MAIN_MODULE_ACCOUNTING) $description.='<br>'.img_warning().' '.$langs->trans('OptionVatInfoModuleComptabilite');
  134. //if (! empty($conf->global->MAIN_MODULE_COMPTABILITE)) $description.='<br>'.$langs->trans("WarningDepositsNotIncluded");
  135. $description.=$fsearch;
  136. $description.='<br>('.$langs->trans("TaxModuleSetupToModifyRules",DOL_URL_ROOT.'/admin/taxes.php').')';
  137. $builddate=time();
  138. //$exportlink=$langs->trans("NotYetAvailable");
  139. $elementcust=$langs->trans("CustomersInvoices");
  140. $productcust=$langs->trans("Description");
  141. $amountcust=$langs->trans("AmountHT");
  142. if ($mysoc->tva_assuj) $vatcust.=' ('.$langs->trans("ToPay").')';
  143. $elementsup=$langs->trans("SuppliersInvoices");
  144. $productsup=$langs->trans("Description");
  145. $amountsup=$langs->trans("AmountHT");
  146. if ($mysoc->tva_assuj) $vatsup.=' ('.$langs->trans("ToGetBack").')';
  147. }
  148. report_header($nom,$nomlink,$period,$periodlink,$description,$builddate,$exportlink);
  149. $vatcust=$langs->trans("VATReceived");
  150. $vatsup=$langs->trans("VATPaid");
  151. // VAT Received
  152. //print "<br>";
  153. //print_titre($vatcust);
  154. print "<table class=\"noborder\" width=\"100%\">";
  155. print "<tr class=\"liste_titre\">";
  156. print '<td align="left">'.$langs->trans("Num")."</td>";
  157. print '<td align="left">'.$langs->trans("Customer")."</td>";
  158. print "<td>".$langs->trans("VATIntra")."</td>";
  159. print "<td align=\"right\">".$langs->trans("AmountHTVATRealReceived")."</td>";
  160. print "<td align=\"right\">".$vatcust."</td>";
  161. print "</tr>\n";
  162. $coll_list = vat_by_thirdparty($db,0,$date_start,$date_end,$modetax,'sell');
  163. if (is_array($coll_list))
  164. {
  165. $var=true;
  166. $total = 0; $totalamount = 0;
  167. $i = 1;
  168. foreach($coll_list as $coll)
  169. {
  170. if($min == 0 or ($min > 0 && $coll->amount > $min))
  171. {
  172. $var=!$var;
  173. $intra = str_replace($find,$replace,$coll->tva_intra);
  174. if(empty($intra))
  175. {
  176. if($coll->assuj == '1')
  177. {
  178. $intra = $langs->trans('Unknown');
  179. }
  180. else
  181. {
  182. //$intra = $langs->trans('NotRegistered');
  183. $intra = '';
  184. }
  185. }
  186. print "<tr ".$bc[$var].">";
  187. print "<td nowrap>".$i."</td>";
  188. $company_static->id=$coll->socid;
  189. $company_static->nom=$coll->nom;
  190. $company_static->client=1;
  191. print '<td nowrap>'.$company_static->getNomUrl(1,'customer').'</td>';
  192. $find = array(' ','.');
  193. $replace = array('','');
  194. print "<td nowrap>".$intra."</td>";
  195. print "<td nowrap align=\"right\">".price($coll->amount)."</td>";
  196. print "<td nowrap align=\"right\">".price($coll->tva)."</td>";
  197. $totalamount = $totalamount + $coll->amount;
  198. $total = $total + $coll->tva;
  199. print "</tr>\n";
  200. $i++;
  201. }
  202. }
  203. $x_coll_sum = $total;
  204. print '<tr class="liste_total"><td align="right" colspan="3">'.$langs->trans("Total").':</td>';
  205. print '<td nowrap align="right">'.price($totalamount).'</td>';
  206. print '<td nowrap align="right">'.price($total).'</td>';
  207. print '</tr>';
  208. }
  209. else
  210. {
  211. $langs->load("errors");
  212. if ($coll_list == -1)
  213. print '<tr><td colspan="5">'.$langs->trans("ErrorNoAccountancyModuleLoaded").'</td></tr>';
  214. else if ($coll_list == -2)
  215. print '<tr><td colspan="5">'.$langs->trans("FeatureNotYetAvailable").'</td></tr>';
  216. else
  217. print '<tr><td colspan="5">'.$langs->trans("Error").'</td></tr>';
  218. }
  219. //print '</table>';
  220. // VAT Paid
  221. //print "<br>";
  222. //print_titre($vatsup);
  223. //print "<table class=\"noborder\" width=\"100%\">";
  224. print "<tr class=\"liste_titre\">";
  225. print '<td align="left">'.$langs->trans("Num")."</td>";
  226. print '<td align="left">'.$langs->trans("Supplier")."</td>";
  227. print "<td>".$langs->trans("VATIntra")."</td>";
  228. print "<td align=\"right\">".$langs->trans("AmountHTVATRealPaid")."</td>";
  229. print "<td align=\"right\">".$vatsup."</td>";
  230. print "</tr>\n";
  231. $company_static=new Societe($db);
  232. $coll_list = vat_by_thirdparty($db,0,$date_start,$date_end,$modetax,'buy');
  233. if (is_array($coll_list))
  234. {
  235. $var=true;
  236. $total = 0; $totalamount = 0;
  237. $i = 1;
  238. foreach($coll_list as $coll)
  239. {
  240. if($min == 0 or ($min > 0 && $coll->amount > $min))
  241. {
  242. $var=!$var;
  243. $intra = str_replace($find,$replace,$coll->tva_intra);
  244. if(empty($intra))
  245. {
  246. if($coll->assuj == '1')
  247. {
  248. $intra = $langs->trans('Unknown');
  249. }
  250. else
  251. {
  252. //$intra = $langs->trans('NotRegistered');
  253. $intra = '';
  254. }
  255. }
  256. print "<tr $bc[$var]>";
  257. print "<td nowrap>".$i."</td>";
  258. $company_static->id=$coll->socid;
  259. $company_static->nom=$coll->nom;
  260. $company_static->fournisseur=1;
  261. print '<td nowrap>'.$company_static->getNomUrl(1,'supplier').'</td>';
  262. $find = array(' ','.');
  263. $replace = array('','');
  264. print "<td nowrap>".$intra."</td>";
  265. print "<td nowrap align=\"right\">".price($coll->amount)."</td>";
  266. print "<td nowrap align=\"right\">".price($coll->tva)."</td>";
  267. $totalamount = $totalamount + $coll->amount;
  268. $total = $total + $coll->tva;
  269. print "</tr>\n";
  270. $i++;
  271. }
  272. }
  273. $x_paye_sum = $total;
  274. print '<tr class="liste_total"><td align="right" colspan="3">'.$langs->trans("Total").':</td>';
  275. print '<td nowrap align="right">'.price($totalamount).'</td>';
  276. print '<td nowrap align="right">'.price($total).'</td>';
  277. print '</tr>';
  278. print '</table>';
  279. // Total to pay
  280. print '<br><br>';
  281. print '<table class="noborder" width="100%">';
  282. $diff = $x_coll_sum - $x_paye_sum;
  283. print '<tr class="liste_total">';
  284. print '<td class="liste_total" colspan="4">'.$langs->trans("TotalToPay").($q?', '.$langs->trans("Quadri").' '.$q:'').'</td>';
  285. print '<td class="liste_total" nowrap="nowrap" align="right"><b>'.price(price2num($diff,'MT'))."</b></td>\n";
  286. print "</tr>\n";
  287. }
  288. else
  289. {
  290. $langs->load("errors");
  291. if ($coll_list == -1)
  292. print '<tr><td colspan="5">'.$langs->trans("ErrorNoAccountancyModuleLoaded").'</td></tr>';
  293. else if ($coll_list == -2)
  294. print '<tr><td colspan="5">'.$langs->trans("FeatureNotYetAvailable").'</td></tr>';
  295. else
  296. print '<tr><td colspan="5">'.$langs->trans("Error").'</td></tr>';
  297. }
  298. print '</table>';
  299. llxFooter();
  300. $db->close();
  301. ?>