checkVatPopup.php 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. <?php
  2. /* Copyright (C) 2006-2016 Laurent Destailleur <eldy@users.sourceforge.net>
  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/societe/checkvat/checkVatPopup.php
  19. * \ingroup societe
  20. * \brief Popup screen to validate VAT
  21. */
  22. require "../../main.inc.php";
  23. require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
  24. require_once NUSOAP_PATH.'/nusoap.php';
  25. $langs->load("companies");
  26. //http://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl
  27. $WS_DOL_URL='http://ec.europa.eu/taxation_customs/vies/services/checkVatService';
  28. //$WS_DOL_URL_WSDL=$WS_DOL_URL.'?wsdl';
  29. $WS_DOL_URL_WSDL='http://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl';
  30. $WS_METHOD ='checkVat';
  31. $conf->dol_hide_topmenu=1;
  32. $conf->dol_hide_leftmenu=1;
  33. llxHeader('', $langs->trans("VATIntraCheckableOnEUSite"));
  34. print '<div class="vatcheckarea" style="margin-bottom: 10px">';
  35. print load_fiche_titre($langs->trans("VATIntraCheckableOnEUSite"),'','title_setup');
  36. $vatNumber = GETPOST("vatNumber",'alpha');
  37. if (! $vatNumber)
  38. {
  39. print '<br>';
  40. print '<font class="error">'.$langs->transnoentities("ErrorFieldRequired",$langs->trans("VATIntraShort")).'</font><br>';
  41. }
  42. else
  43. {
  44. $vatNumber = preg_replace('/\^\w/', '', $vatNumber);
  45. $countryCode=substr($vatNumber,0,2);
  46. $vatNumber=substr($vatNumber,2);
  47. print '<b>'.$langs->trans("Country").'</b>: '.$countryCode.'<br>';
  48. print '<b>'.$langs->trans("VATIntraShort").'</b>: '.$vatNumber.'<br>';
  49. print '<br>';
  50. // Set the parameters to send to the WebService
  51. $parameters = array("countryCode" => $countryCode,
  52. "vatNumber" => $vatNumber);
  53. // Set the WebService URL
  54. dol_syslog("Create nusoap_client for URL=".$WS_DOL_URL." WSDL=".$WS_DOL_URL_WSDL);
  55. require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
  56. $params=getSoapParams();
  57. //ini_set('default_socket_timeout', $params['response_timeout']);
  58. //$soapclient = new SoapClient($WS_DOL_URL_WSDL,$params);
  59. $soapclient = new nusoap_client($WS_DOL_URL_WSDL,true,$params['proxy_host'],$params['proxy_port'],$params['proxy_login'],$params['proxy_password'],$params['connection_timeout'],$params['response_timeout']);
  60. $soapclient->soap_defencoding = 'utf-8';
  61. $soapclient->xml_encoding = 'utf-8';
  62. $soapclient->decode_utf8 = false;
  63. // Check for an error
  64. $err = $soapclient->getError();
  65. if ($err)
  66. {
  67. dol_syslog("Constructor error ".$WS_DOL_URL, LOG_ERR);
  68. }
  69. // Call the WebService and store its result in $result.
  70. dol_syslog("Call method ".$WS_METHOD);
  71. $result = $soapclient->call($WS_METHOD,$parameters);
  72. //var_dump($parameters);
  73. //var_dump($soapclient);
  74. //print "x".is_array($result)."i";
  75. //var_dump($result);
  76. //print $soapclient->request.'<br>';
  77. //print $soapclient->response.'<br>';
  78. $messagetoshow='';
  79. print '<b>'.$langs->trans("Response").'</b>:<br>';
  80. // Service indisponible
  81. if (! is_array($result) || preg_match('/SERVICE_UNAVAILABLE/i',$result['faultstring']))
  82. {
  83. print '<font class="error">'.$langs->trans("ErrorServiceUnavailableTryLater").'</font><br>';
  84. $messagetoshow=$soapclient->response;
  85. }
  86. elseif (preg_match('/TIMEOUT/i',$result['faultstring']))
  87. {
  88. print '<font class="error">'.$langs->trans("ErrorServiceUnavailableTryLater").'</font><br>';
  89. $messagetoshow=$soapclient->response;
  90. }
  91. elseif (preg_match('/SERVER_BUSY/i',$result['faultstring']))
  92. {
  93. print '<font class="error">'.$langs->trans("ErrorServiceUnavailableTryLater").'</font><br>';
  94. $messagetoshow=$soapclient->response;
  95. }
  96. elseif ($result['faultstring'])
  97. {
  98. print '<font class="error">'.$langs->trans("Error").'</font><br>';
  99. $messagetoshow=$result['faultstring'];
  100. }
  101. // Syntaxe ko
  102. elseif (preg_match('/INVALID_INPUT/i',$result['faultstring'])
  103. || ($result['requestDate'] && ! $result['valid']))
  104. {
  105. if ($result['requestDate']) print $langs->trans("Date").': '.$result['requestDate'].'<br>';
  106. print $langs->trans("VATIntraSyntaxIsValid").': <font class="error">'.$langs->trans("No").'</font> (Might be a non europeen VAT)<br>';
  107. print $langs->trans("ValueIsValid").': <font class="error">'.$langs->trans("No").'</font> (Might be a non europeen VAT)<br>';
  108. //$messagetoshow=$soapclient->response;
  109. }
  110. else
  111. {
  112. // Syntaxe ok
  113. if ($result['requestDate']) print $langs->trans("Date").': '.$result['requestDate'].'<br>';
  114. print $langs->trans("VATIntraSyntaxIsValid").': <font class="ok">'.$langs->trans("Yes").'</font><br>';
  115. print $langs->trans("ValueIsValid").': ';
  116. if (preg_match('/MS_UNAVAILABLE/i',$result['faultstring']))
  117. {
  118. print '<font class="error">'.$langs->trans("ErrorVATCheckMS_UNAVAILABLE",$countryCode).'</font><br>';
  119. }
  120. else
  121. {
  122. if (! empty($result['valid']) && ($result['valid']==1 || $result['valid']=='true'))
  123. {
  124. print '<font class="ok">'.$langs->trans("Yes").'</font>';
  125. print '<br>';
  126. print $langs->trans("Name").': '.$result['name'].'<br>';
  127. print $langs->trans("Address").': '.$result['address'].'<br>';
  128. }
  129. else
  130. {
  131. print '<font class="error">'.$langs->trans("No").'</font>';
  132. print '<br>'."\n";
  133. }
  134. }
  135. }
  136. // Show log data into page
  137. print "\n";
  138. print '<!-- ';
  139. var_dump($result);
  140. print '-->';
  141. }
  142. print '<br>';
  143. print $langs->trans("VATIntraManualCheck",$langs->trans("VATIntraCheckURL"),$langs->trans("VATIntraCheckURL")).'<br>';
  144. print '<br>';
  145. print '<div class="center"><input type="button" class="button" value="'.$langs->trans("CloseWindow").'" onclick="javascript: window.close()"></div>';
  146. if ($messagetoshow)
  147. {
  148. print '<br><br>';
  149. print "\n".'Error returned:<br>';
  150. print nl2br($messagetoshow);
  151. }
  152. print '</div>';
  153. // End of page
  154. llxFooter();
  155. $db->close();