dolibarr 24.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 * Copyright (C) 2025 MDW <mdeweerd@users.noreply.github.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
26if (! defined('NOTOKENRENEWAL')) {
27 define('NOTOKENRENEWAL', '1');
28} // Do not roll the Anti CSRF token (used if MAIN_SECURITY_CSRF_WITH_TOKEN is on)
29
30require "../../main.inc.php";
31require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
32require_once NUSOAP_PATH.'/nusoap.php';
33
40$langs->load("companies");
41
42//http://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl
43$WS_DOL_URL = 'https://ec.europa.eu/taxation_customs/vies/services/checkVatService';
44//$WS_DOL_URL_WSDL=$WS_DOL_URL.'?wsdl';
45$WS_DOL_URL_WSDL = 'https://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl';
46$WS_METHOD = 'checkVat';
47
48
49$conf->dol_hide_topmenu = 1;
50$conf->dol_hide_leftmenu = 1;
51
52llxHeader('', $langs->trans("VATIntraCheckableOnEUSite"), '', '', 0, 0, '', '', '', 'marginpopup');
53
54print '<div class="vatcheckarea margintoponly marginbottomonly">';
55
56print load_fiche_titre($langs->trans("VATIntraCheckableOnEUSite"), '', 'title_setup');
57
58$messagetoshow = '';
59
60$vatNumber = GETPOST("vatNumber", 'alpha');
61
62if (!$vatNumber) {
63 print '<br>';
64 print '<span class="error">'.$langs->transnoentities("ErrorFieldRequired", $langs->trans("VATIntraShort")).'</span><br>';
65} else {
66 $vatNumber = preg_replace('/\^\w/', '', $vatNumber);
67 $vatNumber = str_replace(array(' ', '.'), '', $vatNumber);
68 $countryCode = substr($vatNumber, 0, 2);
69 $vatNumber = substr($vatNumber, 2);
70
71 print '<b>'.$langs->trans("Country").'</b>: '.$countryCode.'<br>';
72 print '<b>'.$langs->trans("VATIntraShort").'</b>: '.$vatNumber.'<br>';
73 print '<br>';
74
75 // Set the parameters to send to the WebService
76 $parameters = array(
77 "countryCode" => $countryCode,
78 "vatNumber" => $vatNumber,
79 );
80
81 // Set the WebService URL
82 dol_syslog("Create nusoap_client for URL=".$WS_DOL_URL." WSDL=".$WS_DOL_URL_WSDL);
83 require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
84 $params = getSoapParams();
85 //ini_set('default_socket_timeout', $params['response_timeout']);
86 //$soapclient = new SoapClient($WS_DOL_URL_WSDL,$params);
87 $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']);
88 $soapclient->soap_defencoding = 'utf-8';
89 $soapclient->xml_encoding = 'utf-8';
90 $soapclient->decode_utf8 = false;
91
92 // Check for an error
93 $err = $soapclient->getError();
94 if ($err) {
95 dol_syslog("Constructor error ".$WS_DOL_URL, LOG_ERR);
96 }
97
98 // Call the WebService and store its result in $result.
99 dol_syslog("Call method ".$WS_METHOD);
100 $result = $soapclient->call($WS_METHOD, $parameters);
101
102 print '<b>'.$langs->trans("Response").'</b>:<br>';
103 $faultstring = $result['faultstring'] ?? '';
104 // Service indisponible
105 if (!is_array($result) || preg_match('/SERVICE_UNAVAILABLE/i', $faultstring)) {
106 print '<span class="error">'.$langs->trans("ErrorServiceUnavailableTryLater").'</span><br>';
107 $messagetoshow = $soapclient->response;
108 } elseif (preg_match('/TIMEOUT/i', $faultstring)) {
109 print '<span class="error">'.$langs->trans("ErrorServiceUnavailableTryLater").'</span><br>';
110 $messagetoshow = $soapclient->response;
111 } elseif (preg_match('/SERVER_BUSY/i', $faultstring)) {
112 print '<span class="error">'.$langs->trans("ErrorServiceUnavailableTryLater").'</span><br>';
113 $messagetoshow = $soapclient->response;
114 } elseif ($faultstring) {
115 print '<span class="error">'.$langs->trans("Error").'</span><br>';
116 $messagetoshow = $faultstring;
117 } elseif (preg_match('/INVALID_INPUT/i', $faultstring)
118 || ($result['requestDate'] && !$result['valid'])) {
119 // Syntax ko
120 if ($result['requestDate']) {
121 print $langs->trans("Date").': '.$result['requestDate'].'<br>';
122 }
123 print $langs->trans("VATIntraSyntaxIsValid").': <span class="error">'.$langs->trans("No").'</span> (Might be a non europeen VAT)<br>';
124 print $langs->trans("ValueIsValid").': <span class="error">'.$langs->trans("No").'</span> (Might be a non europeen VAT)<br>';
125 //$messagetoshow=$soapclient->response;
126 } else {
127 // Syntax ok
128 if ($result['requestDate']) {
129 print $langs->trans("Date").': '.$result['requestDate'].'<br>';
130 }
131 print $langs->trans("VATIntraSyntaxIsValid").': <span class="ok">'.$langs->trans("Yes").'</span><br>';
132 print $langs->trans("ValueIsValid").': ';
133 if (preg_match('/MS_UNAVAILABLE/i', $faultstring)) {
134 print '<span class="error">'.$langs->trans("ErrorVATCheckMS_UNAVAILABLE", $countryCode).'</span><br>';
135 } else {
136 if (!empty($result['valid']) && ($result['valid'] == 1 || $result['valid'] == 'true')) {
137 print '<span class="ok">'.$langs->trans("Yes").'</span>';
138 print '<br>';
139 print $langs->trans("Name").': '.$result['name'].'<br>';
140 print $langs->trans("Address").': '.$result['address'].'<br>';
141 } else {
142 print '<span class="error">'.$langs->trans("No").'</span>';
143 print '<br>'."\n";
144 }
145 }
146 }
147
148 // Show log data into page
149 // print "\n";
150 // print '<!-- ';
151 // var_dump($result);
152 // print '-->';
153}
154
155print '<br>';
156print '<span class="opacitymedium small">'.$langs->trans("VATIntraManualCheck", $langs->trans("VATIntraCheckURL"), $langs->transnoentitiesnoconv("VATIntraCheckURL")).'</span><br>';
157print '<br>';
158print '<div class="center"><input type="button" class="button small" value="'.$langs->trans("CloseWindow").'" onclick="window.close()"></div>';
159
160if ($messagetoshow) {
161 print '<br><br>';
162 print '<span class="opacitymedium small">Error returned:</small>'."\n";
163 print '<textarea class="small centpercent">';
164 print dol_htmlentitiesbr($messagetoshow, 1);
165 print '</textarea>';
166}
167
168print '</div>';
169
170// End of page
171llxFooter();
172$db->close();
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:91
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:73
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $db
API class for accounts.
getSoapParams()
Return array to use for SoapClient constructor.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
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.