clients.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579
  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-2013 Laurent Destailleur <eldy@users.sourceforge.net>
  5. * Copyright (C) 2006 Yannick Warnier <ywarnier@beeznest.org>
  6. * Copyright (C) 2014 Ferran Marcet <fmarcet@2byte.es>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. */
  21. /**
  22. * \file htdocs/compta/tva/clients.php
  23. * \ingroup tax
  24. * \brief Page des societes
  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.'/core/class/ccountry.class.php';
  32. $langs->load("bills");
  33. $langs->load("compta");
  34. $langs->load("companies");
  35. $langs->load("products");
  36. $langs->load("other");
  37. // Date range
  38. $year=GETPOST("year");
  39. if (empty($year)) {
  40. $year_current = strftime("%Y",dol_now());
  41. $year_start = $year_current;
  42. } else {
  43. $year_current = $year;
  44. $year_start = $year;
  45. }
  46. $date_start=dol_mktime(0,0,0,$_REQUEST["date_startmonth"],$_REQUEST["date_startday"],$_REQUEST["date_startyear"]);
  47. $date_end=dol_mktime(23,59,59,$_REQUEST["date_endmonth"],$_REQUEST["date_endday"],$_REQUEST["date_endyear"]);
  48. // Quarter
  49. if (empty($date_start) || empty($date_end)) {// We define date_start and date_end
  50. $q=GETPOST("q");
  51. if (empty($q)) {
  52. if (isset($_REQUEST["month"])) {
  53. $date_start=dol_get_first_day($year_start,$_REQUEST["month"],false);
  54. $date_end=dol_get_last_day($year_start,$_REQUEST["month"],false);
  55. } else {
  56. $month_current = strftime("%m",dol_now());
  57. if ($month_current >= 10) $q=4;
  58. elseif ($month_current >= 7) $q=3;
  59. elseif ($month_current >= 4) $q=2;
  60. else $q=1;
  61. }
  62. }
  63. if ($q==1) {
  64. $date_start=dol_get_first_day($year_start,1,false);
  65. $date_end=dol_get_last_day($year_start,3,false);
  66. }
  67. if ($q==2) {
  68. $date_start=dol_get_first_day($year_start,4,false);
  69. $date_end=dol_get_last_day($year_start,6,false);
  70. }
  71. if ($q==3) {
  72. $date_start=dol_get_first_day($year_start,7,false);
  73. $date_end=dol_get_last_day($year_start,9,false);
  74. }
  75. if ($q==4) {
  76. $date_start=dol_get_first_day($year_start,10,false);
  77. $date_end=dol_get_last_day($year_start,12,false);
  78. }
  79. }
  80. $min = price2num(GETPOST("min"));
  81. if (empty($min)) $min = 0;
  82. // Define modetax (0 or 1)
  83. // 0=normal, 1=option vat for services is on debit
  84. $modetax = $conf->global->TAX_MODE;
  85. if (isset($_REQUEST["modetax"])) $modetax=$_REQUEST["modetax"];
  86. if (empty($modetax)) $modetax=0;
  87. // Security check
  88. $socid = GETPOST('socid','int');
  89. if ($user->societe_id) {
  90. $socid=$user->societe_id;
  91. }
  92. $result = restrictedArea($user, 'tax', '', '', 'charges');
  93. // Define modecompta ('CREANCES-DETTES' or 'RECETTES-DEPENSES')
  94. $modecompta = $conf->global->ACCOUNTING_MODE;
  95. if (GETPOST("modecompta")) $modecompta=GETPOST("modecompta");
  96. /*
  97. * View
  98. */
  99. $form=new Form($db);
  100. $company_static=new Societe($db);
  101. $morequerystring='';
  102. $listofparams=array('date_startmonth','date_startyear','date_startday','date_endmonth','date_endyear','date_endday');
  103. foreach($listofparams as $param) {
  104. if (GETPOST($param)!='') {
  105. $morequerystring.=($morequerystring?'&':'').$param.'='.GETPOST($param);
  106. }
  107. }
  108. $special_report = false;
  109. if (isset($_REQUEST['extra_report']) && $_REQUEST['extra_report'] == 1) {
  110. $special_report = true;
  111. }
  112. llxHeader('',$langs->trans("VATReport"),'','',0,0,'','',$morequerystring);
  113. $fsearch.='<br>';
  114. $fsearch.=' <input type="hidden" name="year" value="'.$year.'">';
  115. $fsearch.=' <input type="hidden" name="modetax" value="'.$modetax.'">';
  116. $fsearch.=' '.$langs->trans("SalesTurnoverMinimum").': ';
  117. $fsearch.=' <input type="text" name="min" id="min" value="'.$min.'" size="6">';
  118. // Affiche en-tete du rapport
  119. if ($modetax==1) { // Calculate on invoice for goods and services
  120. $name=$langs->trans("VATReportByCustomersInDueDebtMode");
  121. $calcmode=$langs->trans("CalcModeVATDebt");
  122. $calcmode.='<br>('.$langs->trans("TaxModuleSetupToModifyRules",DOL_URL_ROOT.'/admin/taxes.php').')';
  123. //$name.='<br>('.$langs->trans("SeeVATReportInInputOutputMode",'<a href="'.$_SERVER["PHP_SELF"].'?year='.$year_start.'&modetax=0">','</a>').')';
  124. $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);
  125. //$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>":"");
  126. $description=$langs->trans("RulesVATDueServices");
  127. $description.='<br>';
  128. $description.=$langs->trans("RulesVATDueProducts");
  129. //if ($conf->global->MAIN_MODULE_COMPTABILITE || $conf->global->MAIN_MODULE_ACCOUNTING) $description.='<br>'.img_warning().' '.$langs->trans('OptionVatInfoModuleComptabilite');
  130. //if (! empty($conf->global->MAIN_MODULE_COMPTABILITE)) $description.='<br>'.$langs->trans("WarningDepositsNotIncluded");
  131. if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
  132. $description.='<br>'.$langs->trans("DepositsAreNotIncluded");
  133. } else {
  134. $description.='<br>'.$langs->trans("DepositsAreIncluded");
  135. }
  136. $description.=$fsearch;
  137. $description.='<br>'
  138. . '<input type="radio" name="extra_report" value="0" '.($special_report?'':'checked="checked"').'> '
  139. . $langs->trans('SimpleReport')
  140. . '</input>'
  141. . '<br>'
  142. . '<input type="radio" name="extra_report" value="1" '.($special_report?'checked="checked"':'').'> '
  143. . $langs->trans('AddExtraReport')
  144. . '</input>'
  145. . '<br>';
  146. $builddate=dol_now();
  147. //$exportlink=$langs->trans("NotYetAvailable");
  148. $elementcust=$langs->trans("CustomersInvoices");
  149. $productcust=$langs->trans("Description");
  150. $amountcust=$langs->trans("AmountHT");
  151. if ($mysoc->tva_assuj) {
  152. $vatcust.=' ('.$langs->trans("ToPay").')';
  153. }
  154. $elementsup=$langs->trans("SuppliersInvoices");
  155. $productsup=$langs->trans("Description");
  156. $amountsup=$langs->trans("AmountHT");
  157. if ($mysoc->tva_assuj) {
  158. $vatsup.=' ('.$langs->trans("ToGetBack").')';
  159. }
  160. }
  161. if ($modetax==0) { // Invoice for goods, payment for services
  162. $name=$langs->trans("VATReportByCustomersInInputOutputMode");
  163. $calcmode=$langs->trans("CalcModeVATEngagement");
  164. $calcmode.='<br>('.$langs->trans("TaxModuleSetupToModifyRules",DOL_URL_ROOT.'/admin/taxes.php').')';
  165. //$name.='<br>('.$langs->trans("SeeVATReportInDueDebtMode",'<a href="'.$_SERVER["PHP_SELF"].'?year='.$year_start.'&modetax=1">','</a>').')';
  166. $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);
  167. //$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>":"");
  168. $description=$langs->trans("RulesVATInServices");
  169. $description.=' '.$langs->trans("DepositsAreIncluded");
  170. $description.='<br>';
  171. $description.=$langs->trans("RulesVATInProducts");
  172. if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
  173. $description .= ' ' . $langs->trans("DepositsAreNotIncluded");
  174. } else {
  175. $description .= ' ' . $langs->trans("DepositsAreIncluded");
  176. }
  177. //if ($conf->global->MAIN_MODULE_COMPTABILITE || $conf->global->MAIN_MODULE_ACCOUNTING) $description.='<br>'.img_warning().' '.$langs->trans('OptionVatInfoModuleComptabilite');
  178. //if (! empty($conf->global->MAIN_MODULE_COMPTABILITE)) $description.='<br>'.$langs->trans("WarningDepositsNotIncluded");
  179. $description.=$fsearch;
  180. $description.='<br>'
  181. . '<input type="radio" name="extra_report" value="0" '.($special_report?'':'checked="checked"').'> '
  182. . $langs->trans('SimpleReport')
  183. . '</input>'
  184. . '<br>'
  185. . '<input type="radio" name="extra_report" value="1" '.($special_report?'checked="checked"':'').'> '
  186. . $langs->trans('AddExtraReport')
  187. . '</input>'
  188. . '<br>';
  189. $builddate=dol_now();
  190. //$exportlink=$langs->trans("NotYetAvailable");
  191. $elementcust=$langs->trans("CustomersInvoices");
  192. $productcust=$langs->trans("Description");
  193. $amountcust=$langs->trans("AmountHT");
  194. if ($mysoc->tva_assuj) {
  195. $vatcust.=' ('.$langs->trans("ToPay").')';
  196. }
  197. $elementsup=$langs->trans("SuppliersInvoices");
  198. $productsup=$langs->trans("Description");
  199. $amountsup=$langs->trans("AmountHT");
  200. if ($mysoc->tva_assuj) {
  201. $vatsup.=' ('.$langs->trans("ToGetBack").')';
  202. }
  203. }
  204. report_header($name,$namelink,$period,$periodlink,$description,$builddate,$exportlink,array(),$calcmode);
  205. $vatcust=$langs->trans("VATReceived");
  206. $vatsup=$langs->trans("VATPaid");
  207. // VAT Received
  208. //print "<br>";
  209. //print load_fiche_titre($vatcust);
  210. print "<table class=\"noborder\" width=\"100%\">";
  211. print "<tr class=\"liste_titre\">";
  212. print '<td align="left">'.$langs->trans("Num")."</td>";
  213. print '<td align="left">'.$langs->trans("Customer")."</td>";
  214. print "<td>".$langs->trans("VATIntra")."</td>";
  215. print "<td align=\"right\">".$langs->trans("AmountHTVATRealReceived")."</td>";
  216. print "<td align=\"right\">".$vatcust."</td>";
  217. print "</tr>\n";
  218. $coll_list = vat_by_thirdparty($db,0,$date_start,$date_end,$modetax,'sell');
  219. $action = "tvaclient";
  220. $object = &$coll_list;
  221. $parameters["mode"] = $modetax;
  222. $parameters["start"] = $date_start;
  223. $parameters["end"] = $date_end;
  224. $parameters["direction"] = 'sell';
  225. $parameters["type"] = 'vat';
  226. // Initialize technical object to manage hooks of expenses. Note that conf->hooks_modules contains array array
  227. $hookmanager->initHooks(array('externalbalance'));
  228. $reshook=$hookmanager->executeHooks('addVatLine',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
  229. if (is_array($coll_list)) {
  230. $var=true;
  231. $total = 0; $totalamount = 0;
  232. $i = 1;
  233. foreach ($coll_list as $coll) {
  234. if ($min == 0 or ($min > 0 && $coll->amount > $min)) {
  235. $intra = str_replace($find,$replace,$coll->tva_intra);
  236. if(empty($intra)) {
  237. if($coll->assuj == '1') {
  238. $intra = $langs->trans('Unknown');
  239. } else {
  240. //$intra = $langs->trans('NotRegistered');
  241. $intra = '';
  242. }
  243. }
  244. print '<tr class="oddeven">';
  245. print '<td class="nowrap">'.$i."</td>";
  246. $company_static->id=$coll->socid;
  247. $company_static->name=$coll->name;
  248. $company_static->client=1;
  249. print '<td class="nowrap">'.$company_static->getNomUrl(1,'customer').'</td>';
  250. $find = array(' ','.');
  251. $replace = array('','');
  252. print '<td class="nowrap">'.$intra."</td>";
  253. print "<td class=\"nowrap\" align=\"right\">".price($coll->amount)."</td>";
  254. print "<td class=\"nowrap\" align=\"right\">".price($coll->tva)."</td>";
  255. $totalamount = $totalamount + $coll->amount;
  256. $total = $total + $coll->tva;
  257. print "</tr>\n";
  258. $i++;
  259. }
  260. }
  261. $x_coll_sum = $total;
  262. print '<tr class="liste_total"><td align="right" colspan="3">'.$langs->trans("Total").':</td>';
  263. print '<td class="nowrap" align="right">'.price($totalamount).'</td>';
  264. print '<td class="nowrap" align="right">'.price($total).'</td>';
  265. print '</tr>';
  266. } else {
  267. $langs->load("errors");
  268. if ($coll_list == -1) {
  269. if ($modecompta == 'CREANCES-DETTES')
  270. {
  271. print '<tr><td colspan="5">' . $langs->trans("ErrorNoAccountancyModuleLoaded") . '</td></tr>';
  272. }
  273. else
  274. {
  275. print '<tr><td colspan="5">' . $langs->trans("FeatureNotYetAvailable") . '</td></tr>';
  276. }
  277. } else if ($coll_list == -2) {
  278. print '<tr><td colspan="5">' . $langs->trans("FeatureNotYetAvailable") . '</td></tr>';
  279. } else {
  280. print '<tr><td colspan="5">' . $langs->trans("Error") . '</td></tr>';
  281. }
  282. }
  283. //print '</table>';
  284. // VAT Paid
  285. //print "<br>";
  286. //print load_fiche_titre($vatsup);
  287. //print "<table class=\"noborder\" width=\"100%\">";
  288. print "<tr class=\"liste_titre liste_titre_topborder\">";
  289. print '<td align="left">'.$langs->trans("Num")."</td>";
  290. print '<td align="left">'.$langs->trans("Supplier")."</td>";
  291. print "<td>".$langs->trans("VATIntra")."</td>";
  292. print "<td align=\"right\">".$langs->trans("AmountHTVATRealPaid")."</td>";
  293. print "<td align=\"right\">".$vatsup."</td>";
  294. print "</tr>\n";
  295. $company_static=new Societe($db);
  296. $coll_list = vat_by_thirdparty($db,0,$date_start,$date_end,$modetax,'buy');
  297. $parameters["direction"] = 'buy';
  298. $reshook=$hookmanager->executeHooks('addVatLine',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
  299. if (is_array($coll_list)) {
  300. $var=true;
  301. $total = 0; $totalamount = 0;
  302. $i = 1;
  303. foreach ($coll_list as $coll) {
  304. if ($min == 0 or ($min > 0 && $coll->amount > $min)) {
  305. $intra = str_replace($find,$replace,$coll->tva_intra);
  306. if (empty($intra)) {
  307. if ($coll->assuj == '1') {
  308. $intra = $langs->trans('Unknown');
  309. } else {
  310. //$intra = $langs->trans('NotRegistered');
  311. $intra = '';
  312. }
  313. }
  314. print '<tr class="oddeven">';
  315. print '<td class="nowrap">'.$i."</td>";
  316. $company_static->id=$coll->socid;
  317. $company_static->name=$coll->name;
  318. $company_static->fournisseur=1;
  319. print '<td class="nowrap">'.$company_static->getNomUrl(1,'supplier').'</td>';
  320. $find = array(' ','.');
  321. $replace = array('','');
  322. print '<td class="nowrap">'.$intra."</td>";
  323. print "<td class=\"nowrap\" align=\"right\">".price($coll->amount)."</td>";
  324. print "<td class=\"nowrap\" align=\"right\">".price($coll->tva)."</td>";
  325. $totalamount = $totalamount + $coll->amount;
  326. $total = $total + $coll->tva;
  327. print "</tr>\n";
  328. $i++;
  329. }
  330. }
  331. $x_paye_sum = $total;
  332. print '<tr class="liste_total"><td align="right" colspan="3">'.$langs->trans("Total").':</td>';
  333. print '<td class="nowrap" align="right">'.price($totalamount).'</td>';
  334. print '<td class="nowrap" align="right">'.price($total).'</td>';
  335. print '</tr>';
  336. print '</table>';
  337. // Total to pay
  338. print '<br><br>';
  339. print '<table class="noborder" width="100%">';
  340. $diff = $x_coll_sum - $x_paye_sum;
  341. print '<tr class="liste_total">';
  342. print '<td class="liste_total" colspan="4">'.$langs->trans("TotalToPay").($q?', '.$langs->trans("Quadri").' '.$q:'').'</td>';
  343. print '<td class="liste_total nowrap" align="right"><b>'.price(price2num($diff,'MT'))."</b></td>\n";
  344. print "</tr>\n";
  345. } else {
  346. $langs->load("errors");
  347. if ($coll_list == -1) {
  348. if ($modecompta == 'CREANCES-DETTES')
  349. {
  350. print '<tr><td colspan="5">' . $langs->trans("ErrorNoAccountancyModuleLoaded") . '</td></tr>';
  351. }
  352. else
  353. {
  354. print '<tr><td colspan="5">' . $langs->trans("FeatureNotYetAvailable") . '</td></tr>';
  355. }
  356. } else if ($coll_list == -2) {
  357. print '<tr><td colspan="5">' . $langs->trans("FeatureNotYetAvailable") . '</td></tr>';
  358. } else {
  359. print '<tr><td colspan="5">' . $langs->trans("Error") . '</td></tr>';
  360. }
  361. }
  362. print '</table>';
  363. if ($special_report) {
  364. // Get country 2-letters code
  365. global $mysoc;
  366. $country_id = $mysoc->country_id;
  367. $country = new Ccountry($db);
  368. $country->fetch($country_id);
  369. // Print listing of other-country customers as additional report
  370. // This matches tax requirements to list all same-country customers (only)
  371. print '<h3>'.$langs->trans('OtherCountriesCustomersReport').'</h3>';
  372. print $langs->trans('BasedOnTwoFirstLettersOfVATNumberBeingDifferentFromYourCompanyCountry');
  373. $coll_list = vat_by_thirdparty($db, 0, $date_start, $date_end, $modetax, 'sell');
  374. print "<table class=\"noborder\" width=\"100%\">";
  375. print "<tr class=\"liste_titre\">";
  376. print '<td align="left">' . $langs->trans("Num") . "</td>";
  377. print '<td align="left">' . $langs->trans("Customer") . "</td>";
  378. print "<td>" . $langs->trans("VATIntra") . "</td>";
  379. print "<td align=\"right\">" . $langs->trans("AmountHTVATRealReceived") . "</td>";
  380. print "<td align=\"right\">" . $vatcust . "</td>";
  381. print "</tr>\n";
  382. if (is_array($coll_list)) {
  383. $var = true;
  384. $total = 0;
  385. $totalamount = 0;
  386. $i = 1;
  387. foreach ($coll_list as $coll) {
  388. if (substr($coll->tva_intra, 0, 2) == $country->code) {
  389. // Only use different-country VAT codes
  390. continue;
  391. }
  392. if ($min == 0 or ($min > 0 && $coll->amount > $min)) {
  393. $var = !$var;
  394. $intra = str_replace($find, $replace, $coll->tva_intra);
  395. if (empty($intra)) {
  396. if ($coll->assuj == '1') {
  397. $intra = $langs->trans('Unknown');
  398. } else {
  399. //$intra = $langs->trans('NotRegistered');
  400. $intra = '';
  401. }
  402. }
  403. print "<tr " . $bc[$var] . ">";
  404. print '<td class="nowrap">' . $i . "</td>";
  405. $company_static->id = $coll->socid;
  406. $company_static->name = $coll->name;
  407. $company_static->client = 1;
  408. print '<td class="nowrap">' . $company_static->getNomUrl(1,
  409. 'customer') . '</td>';
  410. $find = array(' ', '.');
  411. $replace = array('', '');
  412. print '<td class="nowrap">' . $intra . "</td>";
  413. print "<td class=\"nowrap\" align=\"right\">" . price($coll->amount) . "</td>";
  414. print "<td class=\"nowrap\" align=\"right\">" . price($coll->tva) . "</td>";
  415. $totalamount = $totalamount + $coll->amount;
  416. $total = $total + $coll->tva;
  417. print "</tr>\n";
  418. $i++;
  419. }
  420. }
  421. $x_coll_sum = $total;
  422. print '<tr class="liste_total"><td align="right" colspan="3">' . $langs->trans("Total") . ':</td>';
  423. print '<td class="nowrap" align="right">' . price($totalamount) . '</td>';
  424. print '<td class="nowrap" align="right">' . price($total) . '</td>';
  425. print '</tr>';
  426. } else {
  427. $langs->load("errors");
  428. if ($coll_list == -1) {
  429. if ($modecompta == 'CREANCES-DETTES')
  430. {
  431. print '<tr><td colspan="5">' . $langs->trans("ErrorNoAccountancyModuleLoaded") . '</td></tr>';
  432. }
  433. else
  434. {
  435. print '<tr><td colspan="5">' . $langs->trans("FeatureNotYetAvailable") . '</td></tr>';
  436. }
  437. } else {
  438. if ($coll_list == -2) {
  439. print '<tr><td colspan="5">' . $langs->trans("FeatureNotYetAvailable") . '</td></tr>';
  440. } else {
  441. print '<tr><td colspan="5">' . $langs->trans("Error") . '</td></tr>';
  442. }
  443. }
  444. }
  445. print '</table>';
  446. // Print listing of same-country customers as additional report
  447. // This matches tax requirements to list all same-country customers (only)
  448. print '<h3>'.$langs->trans('SameCountryCustomersWithVAT').'</h3>';
  449. print $langs->trans('BasedOnTwoFirstLettersOfVATNumberBeingTheSameAsYourCompanyCountry');
  450. $coll_list = vat_by_thirdparty($db, 0, $date_start, $date_end, $modetax, 'sell');
  451. print "<table class=\"noborder\" width=\"100%\">";
  452. print "<tr class=\"liste_titre\">";
  453. print '<td align="left">' . $langs->trans("Num") . "</td>";
  454. print '<td align="left">' . $langs->trans("Customer") . "</td>";
  455. print "<td>" . $langs->trans("VATIntra") . "</td>";
  456. print "<td align=\"right\">" . $langs->trans("AmountHTVATRealReceived") . "</td>";
  457. print "<td align=\"right\">" . $vatcust . "</td>";
  458. print "</tr>\n";
  459. if (is_array($coll_list)) {
  460. $var = true;
  461. $total = 0;
  462. $totalamount = 0;
  463. $i = 1;
  464. foreach ($coll_list as $coll) {
  465. if (substr($coll->tva_intra, 0, 2) != $country->code) {
  466. // Only use same-country VAT codes
  467. continue;
  468. }
  469. if ($min == 0 or ($min > 0 && $coll->amount > $min)) {
  470. $var = !$var;
  471. $intra = str_replace($find, $replace, $coll->tva_intra);
  472. if (empty($intra)) {
  473. if ($coll->assuj == '1') {
  474. $intra = $langs->trans('Unknown');
  475. } else {
  476. //$intra = $langs->trans('NotRegistered');
  477. $intra = '';
  478. }
  479. }
  480. print "<tr " . $bc[$var] . ">";
  481. print '<td class="nowrap">' . $i . "</td>";
  482. $company_static->id = $coll->socid;
  483. $company_static->name = $coll->name;
  484. $company_static->client = 1;
  485. print '<td class="nowrap">' . $company_static->getNomUrl(1, 'customer') . '</td>';
  486. $find = array(' ', '.');
  487. $replace = array('', '');
  488. print '<td class="nowrap">' . $intra . "</td>";
  489. print "<td class=\"nowrap\" align=\"right\">" . price($coll->amount) . "</td>";
  490. print "<td class=\"nowrap\" align=\"right\">" . price($coll->tva) . "</td>";
  491. $totalamount = $totalamount + $coll->amount;
  492. $total = $total + $coll->tva;
  493. print "</tr>\n";
  494. $i++;
  495. }
  496. }
  497. $x_coll_sum = $total;
  498. print '<tr class="liste_total"><td align="right" colspan="3">' . $langs->trans("Total") . ':</td>';
  499. print '<td class="nowrap" align="right">' . price($totalamount) . '</td>';
  500. print '<td class="nowrap" align="right">' . price($total) . '</td>';
  501. print '</tr>';
  502. } else {
  503. $langs->load("errors");
  504. if ($coll_list == -1) {
  505. if ($modecompta == 'CREANCES-DETTES')
  506. {
  507. print '<tr><td colspan="5">' . $langs->trans("ErrorNoAccountancyModuleLoaded") . '</td></tr>';
  508. }
  509. else
  510. {
  511. print '<tr><td colspan="5">' . $langs->trans("FeatureNotYetAvailable") . '</td></tr>';
  512. }
  513. } else {
  514. if ($coll_list == -2) {
  515. print '<tr><td colspan="5">' . $langs->trans("FeatureNotYetAvailable") . '</td></tr>';
  516. } else {
  517. print '<tr><td colspan="5">' . $langs->trans("Error") . '</td></tr>';
  518. }
  519. }
  520. }
  521. print '</table>';
  522. }
  523. llxFooter();
  524. $db->close();