Skip to content

Commit 12e1474

Browse files
committed
- Added VAT ID check (for EU VAT IDs) to client/reseller form.
1 parent 7c57f78 commit 12e1474

File tree

7 files changed

+96
-4
lines changed

7 files changed

+96
-4
lines changed

interface/lib/classes/validate_client.inc.php

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,85 @@ function check_used_servers($field_name, $field_value, $validator)
136136
}
137137
}
138138

139+
function check_vat_id ($field_name, $field_value, $validator){
140+
global $app, $page;
141+
142+
$vatid = trim($field_value);
143+
if(isset($app->remoting_lib->primary_id)) {
144+
$country = $app->remoting_lib->dataRecord['country'];
145+
} else {
146+
$country = $page->dataRecord['country'];
147+
}
148+
149+
// check if country is member of EU
150+
$country_details = $app->db->queryOneRecord("SELECT * FROM country WHERE iso = '".$country."'");
151+
if($country_details['eu'] == 'y' && $vatid != ''){
152+
153+
$vatid = preg_replace('/\s+/', '', $vatid);
154+
$vatid = str_replace(array('.', '-', ','), '', $vatid);
155+
$cc = substr($vatid, 0, 2);
156+
$vn = substr($vatid, 2);
157+
158+
// Test if the country of the VAT-ID matches the country of the customer
159+
if($country != ''){
160+
if(strtoupper($cc) != $country){
161+
$errmsg = $validator['errmsg'];
162+
if(isset($app->tform->wordbook[$errmsg])) {
163+
return $app->tform->wordbook[$errmsg]."<br>\r\n";
164+
} else {
165+
return $errmsg."<br>\r\n";
166+
}
167+
}
168+
}
139169

170+
$client = new SoapClient("http://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl");
171+
172+
if($client){
173+
$params = array('countryCode' => $cc, 'vatNumber' => $vn);
174+
try{
175+
$r = $client->checkVat($params);
176+
if($r->valid == true){
177+
} else {
178+
$errmsg = $validator['errmsg'];
179+
if(isset($app->tform->wordbook[$errmsg])) {
180+
return $app->tform->wordbook[$errmsg]."<br>\r\n";
181+
} else {
182+
return $errmsg."<br>\r\n";
183+
}
184+
}
185+
186+
// This foreach shows every single line of the returned information
187+
/*
188+
foreach($r as $k=>$prop){
189+
echo $k . ': ' . $prop;
190+
}
191+
*/
192+
193+
} catch(SoapFault $e) {
194+
//echo 'Error, see message: '.$e->faultstring;
195+
switch ($e->faultstring) {
196+
case 'INVALID_INPUT':
197+
$errmsg = $validator['errmsg'];
198+
if(isset($app->tform->wordbook[$errmsg])) {
199+
return $app->tform->wordbook[$errmsg]."<br>\r\n";
200+
} else {
201+
return $errmsg."<br>\r\n";
202+
}
203+
break;
204+
// the following cases shouldn't be the user's fault, so we return no error
205+
case 'SERVICE_UNAVAILABLE':
206+
case 'MS_UNAVAILABLE':
207+
case 'TIMEOUT':
208+
case 'SERVER_BUSY':
209+
break;
210+
}
211+
}
212+
} else {
213+
// Connection to host not possible, europe.eu down?
214+
// this shouldn't be the user's fault, so we return no error
215+
}
216+
}
217+
}
140218

141219

142220
}

interface/web/client/form/client.tform.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,12 @@
367367
'width' => '30',
368368
'maxlength' => '255',
369369
'rows' => '',
370-
'cols' => ''
370+
'cols' => '',
371+
'validators' => array ( 0 => array ( 'type' => 'CUSTOM',
372+
'class' => 'validate_client',
373+
'function' => 'check_vat_id',
374+
'errmsg'=> 'invalid_vat_id'),
375+
),
371376
),
372377
'company_id' => array (
373378
'datatype' => 'VARCHAR',

interface/web/client/form/reseller.tform.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,12 @@
364364
'width' => '30',
365365
'maxlength' => '255',
366366
'rows' => '',
367-
'cols' => ''
367+
'cols' => '',
368+
'validators' => array ( 0 => array ( 'type' => 'CUSTOM',
369+
'class' => 'validate_client',
370+
'function' => 'check_vat_id',
371+
'errmsg'=> 'invalid_vat_id'),
372+
),
368373
),
369374
'company_id' => array (
370375
'datatype' => 'VARCHAR',

interface/web/client/lib/lang/de_client.lng

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ $wb['limit_webdav_user_error_notint'] = 'Das WebDAV Benutzer Limit muss eine Zah
110110
$wb['limit_backup_txt'] = 'Backupfunktion verfügbar';
111111
$wb['limit_dns_slave_zone_error_notint'] = 'Das Secondary DNS Zonen Limit muss eine Zahl sein.';
112112
$wb['customer_no_txt'] = 'Kundennummer';
113-
$wb['vat_id_txt'] = 'USt-ID';
113+
$wb['vat_id_txt'] = 'USt.-ID';
114114
$wb['required_fields_txt'] = '* Benötigte Felder';
115115
$wb['limit_mailmailinglist_txt'] = 'Max. Anzahl an Mailinglisten';
116116
$wb['limit_mailmailinglist_error_notint'] = 'Das Mailinglisten Limit muss eine Zahl sein.';
@@ -176,4 +176,5 @@ $wb['limit_database_quota_error_notint'] = 'Das Datenbank-quota muß eine Nummer
176176
$wb['reseller_txt'] = 'Reseller';
177177
$wb['btn_save_txt'] = 'Speichern';
178178
$wb['btn_cancel_txt'] = 'Abbrechen';
179+
$wb['invalid_vat_id'] = 'Die USt.-ID ist ungültig.';
179180
?>

interface/web/client/lib/lang/de_reseller.lng

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ $wb['limit_dns_slave_zone_txt'] = 'Max. Anzahl an Secondary DNS Zonen';
106106
$wb['limit_dns_slave_zone_error_notint'] = 'Das Secondary DNS Zonen Limit muss eine Zahl sein.';
107107
$wb['limit_dns_record_error_notint'] = 'Das DNS Eintrag Limit muss eine Zahl sein.';
108108
$wb['customer_no_txt'] = 'Kundennummer';
109-
$wb['vat_id_txt'] = 'USt-ID';
109+
$wb['vat_id_txt'] = 'USt.-ID';
110110
$wb['required_fields_txt'] = '* Benötigte Felder';
111111
$wb['limit_webdav_user_txt'] = 'Max. Anzahl an WebDAV Benutzern';
112112
$wb['limit_webdav_user_error_notint'] = 'Das WebDAV Benutzer Limit muss eine Zahl sein.';
@@ -160,4 +160,5 @@ $wb['limit_domainmodule_error_notint'] = 'Domainmodule limit must be a number.';
160160
$wb['limit_domainmodule_txt'] = 'Domainmodule Limit';
161161
$wb['client_limits_txt'] = 'Client Limits';
162162
$wb['err_msg_master_tpl_set'] = 'All custom limit settings are ignored if any master template other than \\"custom\\" is selected.';
163+
$wb['invalid_vat_id'] = 'Die USt.-ID ist ungültig.';
163164
?>

interface/web/client/lib/lang/en_client.lng

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,4 +179,5 @@ $wb['limit_database_quota_error_notint'] = 'The database quota limit must be a n
179179
$wb['reseller_txt'] = 'Reseller';
180180
$wb['btn_save_txt'] = "Save";
181181
$wb['btn_cancel_txt'] = "Cancel";
182+
$wb['invalid_vat_id'] = 'The VAT ID is invalid.';
182183
?>

interface/web/client/lib/lang/en_reseller.lng

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,4 +178,5 @@ $wb['limit_domainmodule_error_notint'] = 'Domainmodule limit must be a number.';
178178
$wb['limit_domainmodule_txt'] = 'Domainmodule Limit';
179179
$wb['client_limits_txt'] = 'Client Limits';
180180
$wb['err_msg_master_tpl_set'] = 'All custom limit settings are ignored if any master template other than "custom" is selected.';
181+
$wb['invalid_vat_id'] = 'The VAT ID is invalid.';
181182
?>

0 commit comments

Comments
 (0)