dolibarr  13.0.2
checkVatPopup.php
Go to the documentation of this file.
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 <https://www.gnu.org/licenses/>.
16  */
17 
24 require "../../main.inc.php";
25 require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
26 require_once NUSOAP_PATH.'/nusoap.php';
27 
28 $langs->load("companies");
29 
30 //http://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl
31 $WS_DOL_URL = 'https://ec.europa.eu/taxation_customs/vies/services/checkVatService';
32 //$WS_DOL_URL_WSDL=$WS_DOL_URL.'?wsdl';
33 $WS_DOL_URL_WSDL = 'https://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl';
34 $WS_METHOD = 'checkVat';
35 
36 
37 $conf->dol_hide_topmenu = 1;
38 $conf->dol_hide_leftmenu = 1;
39 
40 llxHeader('', $langs->trans("VATIntraCheckableOnEUSite"));
41 
42 print '<div class="vatcheckarea" style="margin-bottom: 10px">';
43 
44 print load_fiche_titre($langs->trans("VATIntraCheckableOnEUSite"), '', 'title_setup');
45 
46 $vatNumber = GETPOST("vatNumber", 'alpha');
47 
48 if (!$vatNumber)
49 {
50  print '<br>';
51  print '<font class="error">'.$langs->transnoentities("ErrorFieldRequired", $langs->trans("VATIntraShort")).'</font><br>';
52 } else {
53  $vatNumber = preg_replace('/\^\w/', '', $vatNumber);
54  $vatNumber = str_replace(array(' ', '.'), '', $vatNumber);
55  $countryCode = substr($vatNumber, 0, 2);
56  $vatNumber = substr($vatNumber, 2);
57 
58  print '<b>'.$langs->trans("Country").'</b>: '.$countryCode.'<br>';
59  print '<b>'.$langs->trans("VATIntraShort").'</b>: '.$vatNumber.'<br>';
60  print '<br>';
61 
62  // Set the parameters to send to the WebService
63  $parameters = array("countryCode" => $countryCode,
64  "vatNumber" => $vatNumber);
65 
66  // Set the WebService URL
67  dol_syslog("Create nusoap_client for URL=".$WS_DOL_URL." WSDL=".$WS_DOL_URL_WSDL);
68  require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
69  $params = getSoapParams();
70  //ini_set('default_socket_timeout', $params['response_timeout']);
71  //$soapclient = new SoapClient($WS_DOL_URL_WSDL,$params);
72  $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']);
73  $soapclient->soap_defencoding = 'utf-8';
74  $soapclient->xml_encoding = 'utf-8';
75  $soapclient->decode_utf8 = false;
76 
77  // Check for an error
78  $err = $soapclient->getError();
79  if ($err)
80  {
81  dol_syslog("Constructor error ".$WS_DOL_URL, LOG_ERR);
82  }
83 
84  // Call the WebService and store its result in $result.
85  dol_syslog("Call method ".$WS_METHOD);
86  $result = $soapclient->call($WS_METHOD, $parameters);
87 
88  //var_dump($parameters);
89  //var_dump($soapclient);
90  //print "x".is_array($result)."i";
91  //var_dump($result);
92  //print $soapclient->request.'<br>';
93  //print $soapclient->response.'<br>';
94 
95  $messagetoshow = '';
96  print '<b>'.$langs->trans("Response").'</b>:<br>';
97 
98  // Service indisponible
99  if (!is_array($result) || preg_match('/SERVICE_UNAVAILABLE/i', $result['faultstring']))
100  {
101  print '<font class="error">'.$langs->trans("ErrorServiceUnavailableTryLater").'</font><br>';
102  $messagetoshow = $soapclient->response;
103  } elseif (preg_match('/TIMEOUT/i', $result['faultstring']))
104  {
105  print '<font class="error">'.$langs->trans("ErrorServiceUnavailableTryLater").'</font><br>';
106  $messagetoshow = $soapclient->response;
107  } elseif (preg_match('/SERVER_BUSY/i', $result['faultstring']))
108  {
109  print '<font class="error">'.$langs->trans("ErrorServiceUnavailableTryLater").'</font><br>';
110  $messagetoshow = $soapclient->response;
111  } elseif ($result['faultstring'])
112  {
113  print '<font class="error">'.$langs->trans("Error").'</font><br>';
114  $messagetoshow = $result['faultstring'];
115  }
116  // Syntaxe ko
117  elseif (preg_match('/INVALID_INPUT/i', $result['faultstring'])
118  || ($result['requestDate'] && !$result['valid']))
119  {
120  if ($result['requestDate']) print $langs->trans("Date").': '.$result['requestDate'].'<br>';
121  print $langs->trans("VATIntraSyntaxIsValid").': <font class="error">'.$langs->trans("No").'</font> (Might be a non europeen VAT)<br>';
122  print $langs->trans("ValueIsValid").': <font class="error">'.$langs->trans("No").'</font> (Might be a non europeen VAT)<br>';
123  //$messagetoshow=$soapclient->response;
124  } else {
125  // Syntaxe ok
126  if ($result['requestDate']) print $langs->trans("Date").': '.$result['requestDate'].'<br>';
127  print $langs->trans("VATIntraSyntaxIsValid").': <font class="ok">'.$langs->trans("Yes").'</font><br>';
128  print $langs->trans("ValueIsValid").': ';
129  if (preg_match('/MS_UNAVAILABLE/i', $result['faultstring']))
130  {
131  print '<font class="error">'.$langs->trans("ErrorVATCheckMS_UNAVAILABLE", $countryCode).'</font><br>';
132  } else {
133  if (!empty($result['valid']) && ($result['valid'] == 1 || $result['valid'] == 'true'))
134  {
135  print '<font class="ok">'.$langs->trans("Yes").'</font>';
136  print '<br>';
137  print $langs->trans("Name").': '.$result['name'].'<br>';
138  print $langs->trans("Address").': '.$result['address'].'<br>';
139  } else {
140  print '<font class="error">'.$langs->trans("No").'</font>';
141  print '<br>'."\n";
142  }
143  }
144  }
145 
146  // Show log data into page
147  print "\n";
148  print '<!-- ';
149  var_dump($result);
150  print '-->';
151 }
152 
153 print '<br>';
154 print $langs->trans("VATIntraManualCheck", $langs->trans("VATIntraCheckURL"), $langs->transnoentitiesnoconv("VATIntraCheckURL")).'<br>';
155 print '<br>';
156 print '<div class="center"><input type="button" class="button" value="'.$langs->trans("CloseWindow").'" onclick="javascript: window.close()"></div>';
157 
158 if ($messagetoshow)
159 {
160  print '<br><br>';
161  print "\n".'Error returned:<br>';
162  print nl2br($messagetoshow);
163 }
164 
165 print '</div>';
166 
167 // End of page
168 llxFooter();
169 $db->close();
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
llxHeader()
Empty header.
Definition: wrapper.php:45
load_fiche_titre($titre, $morehtmlright= '', $picto= 'generic', $pictoisfullpath=0, $id= '', $morecssontable= '', $morehtmlcenter= '')
Load a title with picto.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
print
Draft customers invoices.
Definition: index.php:89
llxFooter()
Empty footer.
Definition: wrapper.php:59
getSoapParams()
Return array to use for SoapClient constructor.