dolibarr 21.0.0-beta
checkVatPopup.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2006-2016 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <https://www.gnu.org/licenses/>.
17 */
18
25if (! defined('NOTOKENRENEWAL')) {
26 define('NOTOKENRENEWAL', '1');
27} // Do not roll the Anti CSRF token (used if MAIN_SECURITY_CSRF_WITH_TOKEN is on)
28
29require "../../main.inc.php";
30require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
31require_once NUSOAP_PATH.'/nusoap.php';
32
39$langs->load("companies");
40
41//http://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl
42$WS_DOL_URL = 'https://ec.europa.eu/taxation_customs/vies/services/checkVatService';
43//$WS_DOL_URL_WSDL=$WS_DOL_URL.'?wsdl';
44$WS_DOL_URL_WSDL = 'https://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl';
45$WS_METHOD = 'checkVat';
46
47
48$conf->dol_hide_topmenu = 1;
49$conf->dol_hide_leftmenu = 1;
50
51llxHeader('', $langs->trans("VATIntraCheckableOnEUSite"), '', '', 0, 0, '', '', '', 'marginpopup');
52
53print '<div class="vatcheckarea margintoponly marginbottomonly">';
54
55print load_fiche_titre($langs->trans("VATIntraCheckableOnEUSite"), '', 'title_setup');
56
57$vatNumber = GETPOST("vatNumber", 'alpha');
58
59if (!$vatNumber) {
60 print '<br>';
61 print '<span class="error">'.$langs->transnoentities("ErrorFieldRequired", $langs->trans("VATIntraShort")).'</span><br>';
62} else {
63 $vatNumber = preg_replace('/\^\w/', '', $vatNumber);
64 $vatNumber = str_replace(array(' ', '.'), '', $vatNumber);
65 $countryCode = substr($vatNumber, 0, 2);
66 $vatNumber = substr($vatNumber, 2);
67
68 print '<b>'.$langs->trans("Country").'</b>: '.$countryCode.'<br>';
69 print '<b>'.$langs->trans("VATIntraShort").'</b>: '.$vatNumber.'<br>';
70 print '<br>';
71
72 // Set the parameters to send to the WebService
73 $parameters = array(
74 "countryCode" => $countryCode,
75 "vatNumber" => $vatNumber,
76 );
77
78 // Set the WebService URL
79 dol_syslog("Create nusoap_client for URL=".$WS_DOL_URL." WSDL=".$WS_DOL_URL_WSDL);
80 require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
81 $params = getSoapParams();
82 //ini_set('default_socket_timeout', $params['response_timeout']);
83 //$soapclient = new SoapClient($WS_DOL_URL_WSDL,$params);
84 $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']);
85 $soapclient->soap_defencoding = 'utf-8';
86 $soapclient->xml_encoding = 'utf-8';
87 $soapclient->decode_utf8 = false;
88
89 // Check for an error
90 $err = $soapclient->getError();
91 if ($err) {
92 dol_syslog("Constructor error ".$WS_DOL_URL, LOG_ERR);
93 }
94
95 // Call the WebService and store its result in $result.
96 dol_syslog("Call method ".$WS_METHOD);
97 $result = $soapclient->call($WS_METHOD, $parameters);
98
99 $messagetoshow = '';
100 print '<b>'.$langs->trans("Response").'</b>:<br>';
101 $faultstring = $result['faultstring'] ?? '';
102 // Service indisponible
103 if (!is_array($result) || preg_match('/SERVICE_UNAVAILABLE/i', $faultstring)) {
104 print '<span class="error">'.$langs->trans("ErrorServiceUnavailableTryLater").'</span><br>';
105 $messagetoshow = $soapclient->response;
106 } elseif (preg_match('/TIMEOUT/i', $faultstring)) {
107 print '<span class="error">'.$langs->trans("ErrorServiceUnavailableTryLater").'</span><br>';
108 $messagetoshow = $soapclient->response;
109 } elseif (preg_match('/SERVER_BUSY/i', $faultstring)) {
110 print '<span class="error">'.$langs->trans("ErrorServiceUnavailableTryLater").'</span><br>';
111 $messagetoshow = $soapclient->response;
112 } elseif ($faultstring) {
113 print '<span class="error">'.$langs->trans("Error").'</span><br>';
114 $messagetoshow = $faultstring;
115 } elseif (preg_match('/INVALID_INPUT/i', $faultstring)
116 || ($result['requestDate'] && !$result['valid'])) {
117 // Syntax ko
118 if ($result['requestDate']) {
119 print $langs->trans("Date").': '.$result['requestDate'].'<br>';
120 }
121 print $langs->trans("VATIntraSyntaxIsValid").': <span class="error">'.$langs->trans("No").'</span> (Might be a non europeen VAT)<br>';
122 print $langs->trans("ValueIsValid").': <span class="error">'.$langs->trans("No").'</span> (Might be a non europeen VAT)<br>';
123 //$messagetoshow=$soapclient->response;
124 } else {
125 // Syntax ok
126 if ($result['requestDate']) {
127 print $langs->trans("Date").': '.$result['requestDate'].'<br>';
128 }
129 print $langs->trans("VATIntraSyntaxIsValid").': <span class="ok">'.$langs->trans("Yes").'</span><br>';
130 print $langs->trans("ValueIsValid").': ';
131 if (preg_match('/MS_UNAVAILABLE/i', $faultstring)) {
132 print '<span class="error">'.$langs->trans("ErrorVATCheckMS_UNAVAILABLE", $countryCode).'</span><br>';
133 } else {
134 if (!empty($result['valid']) && ($result['valid'] == 1 || $result['valid'] == 'true')) {
135 print '<span class="ok">'.$langs->trans("Yes").'</span>';
136 print '<br>';
137 print $langs->trans("Name").': '.$result['name'].'<br>';
138 print $langs->trans("Address").': '.$result['address'].'<br>';
139 } else {
140 print '<span class="error">'.$langs->trans("No").'</span>';
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
153print '<br>';
154print '<span class="opacitymedium small">'.$langs->trans("VATIntraManualCheck", $langs->trans("VATIntraCheckURL"), $langs->transnoentitiesnoconv("VATIntraCheckURL")).'</span><br>';
155print '<br>';
156print '<div class="center"><input type="button" class="button small" value="'.$langs->trans("CloseWindow").'" onclick="window.close()"></div>';
157
158if ($messagetoshow) {
159 print '<br><br>';
160 print '<span class="opacitymedium small">Error returned:</small>'."\n";
161 print '<textarea class="small centpercent">';
162 print dol_htmlentitiesbr($messagetoshow, 1);
163 print '</textarea>';
164}
165
166print '</div>';
167
168// End of page
169llxFooter();
170$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:71
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.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79