dolibarr 21.0.0-alpha
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
24if (! defined('NOTOKENRENEWAL')) {
25 define('NOTOKENRENEWAL', '1');
26} // Do not roll the Anti CSRF token (used if MAIN_SECURITY_CSRF_WITH_TOKEN is on)
27
28require "../../main.inc.php";
29require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
30require_once NUSOAP_PATH.'/nusoap.php';
31
32$langs->load("companies");
33
34//http://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl
35$WS_DOL_URL = 'https://ec.europa.eu/taxation_customs/vies/services/checkVatService';
36//$WS_DOL_URL_WSDL=$WS_DOL_URL.'?wsdl';
37$WS_DOL_URL_WSDL = 'https://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl';
38$WS_METHOD = 'checkVat';
39
40
41$conf->dol_hide_topmenu = 1;
42$conf->dol_hide_leftmenu = 1;
43
44llxHeader('', $langs->trans("VATIntraCheckableOnEUSite"), '', '', 0, 0, '', '', '', 'marginpopup');
45
46print '<div class="vatcheckarea margintoponly marginbottomonly">';
47
48print load_fiche_titre($langs->trans("VATIntraCheckableOnEUSite"), '', 'title_setup');
49
50$vatNumber = GETPOST("vatNumber", 'alpha');
51
52if (!$vatNumber) {
53 print '<br>';
54 print '<span class="error">'.$langs->transnoentities("ErrorFieldRequired", $langs->trans("VATIntraShort")).'</span><br>';
55} else {
56 $vatNumber = preg_replace('/\^\w/', '', $vatNumber);
57 $vatNumber = str_replace(array(' ', '.'), '', $vatNumber);
58 $countryCode = substr($vatNumber, 0, 2);
59 $vatNumber = substr($vatNumber, 2);
60
61 print '<b>'.$langs->trans("Country").'</b>: '.$countryCode.'<br>';
62 print '<b>'.$langs->trans("VATIntraShort").'</b>: '.$vatNumber.'<br>';
63 print '<br>';
64
65 // Set the parameters to send to the WebService
66 $parameters = array(
67 "countryCode" => $countryCode,
68 "vatNumber" => $vatNumber,
69 );
70
71 // Set the WebService URL
72 dol_syslog("Create nusoap_client for URL=".$WS_DOL_URL." WSDL=".$WS_DOL_URL_WSDL);
73 require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
74 $params = getSoapParams();
75 //ini_set('default_socket_timeout', $params['response_timeout']);
76 //$soapclient = new SoapClient($WS_DOL_URL_WSDL,$params);
77 $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']);
78 $soapclient->soap_defencoding = 'utf-8';
79 $soapclient->xml_encoding = 'utf-8';
80 $soapclient->decode_utf8 = false;
81
82 // Check for an error
83 $err = $soapclient->getError();
84 if ($err) {
85 dol_syslog("Constructor error ".$WS_DOL_URL, LOG_ERR);
86 }
87
88 // Call the WebService and store its result in $result.
89 dol_syslog("Call method ".$WS_METHOD);
90 $result = $soapclient->call($WS_METHOD, $parameters);
91
92 $messagetoshow = '';
93 print '<b>'.$langs->trans("Response").'</b>:<br>';
94 $faultstring = $result['faultstring'] ?? '';
95 // Service indisponible
96 if (!is_array($result) || preg_match('/SERVICE_UNAVAILABLE/i', $faultstring)) {
97 print '<span class="error">'.$langs->trans("ErrorServiceUnavailableTryLater").'</span><br>';
98 $messagetoshow = $soapclient->response;
99 } elseif (preg_match('/TIMEOUT/i', $faultstring)) {
100 print '<span class="error">'.$langs->trans("ErrorServiceUnavailableTryLater").'</span><br>';
101 $messagetoshow = $soapclient->response;
102 } elseif (preg_match('/SERVER_BUSY/i', $faultstring)) {
103 print '<span class="error">'.$langs->trans("ErrorServiceUnavailableTryLater").'</span><br>';
104 $messagetoshow = $soapclient->response;
105 } elseif ($faultstring) {
106 print '<span class="error">'.$langs->trans("Error").'</span><br>';
107 $messagetoshow = $faultstring;
108 } elseif (preg_match('/INVALID_INPUT/i', $faultstring)
109 || ($result['requestDate'] && !$result['valid'])) {
110 // Syntax ko
111 if ($result['requestDate']) {
112 print $langs->trans("Date").': '.$result['requestDate'].'<br>';
113 }
114 print $langs->trans("VATIntraSyntaxIsValid").': <span class="error">'.$langs->trans("No").'</span> (Might be a non europeen VAT)<br>';
115 print $langs->trans("ValueIsValid").': <span class="error">'.$langs->trans("No").'</span> (Might be a non europeen VAT)<br>';
116 //$messagetoshow=$soapclient->response;
117 } else {
118 // Syntax ok
119 if ($result['requestDate']) {
120 print $langs->trans("Date").': '.$result['requestDate'].'<br>';
121 }
122 print $langs->trans("VATIntraSyntaxIsValid").': <span class="ok">'.$langs->trans("Yes").'</span><br>';
123 print $langs->trans("ValueIsValid").': ';
124 if (preg_match('/MS_UNAVAILABLE/i', $faultstring)) {
125 print '<span class="error">'.$langs->trans("ErrorVATCheckMS_UNAVAILABLE", $countryCode).'</span><br>';
126 } else {
127 if (!empty($result['valid']) && ($result['valid'] == 1 || $result['valid'] == 'true')) {
128 print '<span class="ok">'.$langs->trans("Yes").'</span>';
129 print '<br>';
130 print $langs->trans("Name").': '.$result['name'].'<br>';
131 print $langs->trans("Address").': '.$result['address'].'<br>';
132 } else {
133 print '<span class="error">'.$langs->trans("No").'</span>';
134 print '<br>'."\n";
135 }
136 }
137 }
138
139 // Show log data into page
140 // print "\n";
141 // print '<!-- ';
142 // var_dump($result);
143 // print '-->';
144}
145
146print '<br>';
147print '<span class="opacitymedium small">'.$langs->trans("VATIntraManualCheck", $langs->trans("VATIntraCheckURL"), $langs->transnoentitiesnoconv("VATIntraCheckURL")).'</span><br>';
148print '<br>';
149print '<div class="center"><input type="button" class="button small" value="'.$langs->trans("CloseWindow").'" onclick="window.close()"></div>';
150
151if ($messagetoshow) {
152 print '<br><br>';
153 print '<span class="opacitymedium small">Error returned:</small>'."\n";
154 print '<textarea class="small centpercent">';
155 print dol_htmlentitiesbr($messagetoshow, 1);
156 print '</textarea>';
157}
158
159print '</div>';
160
161// End of page
162llxFooter();
163$db->close();
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:70
llxFooter()
Footer empty.
Definition document.php:107
getSoapParams()
Return array to use for SoapClient constructor.
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_htmlentitiesbr($stringtoencode, $nl2brmode=0, $pagecodefrom='UTF-8', $removelasteolbr=1)
This function is called to encode a string into a HTML string but differs from htmlentities because a...
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.