Commit 12e14745 authored by Falko Timme's avatar Falko Timme
Browse files

- Added VAT ID check (for EU VAT IDs) to client/reseller form.

parent 7c57f784
......@@ -136,7 +136,85 @@ class validate_client {
}
}
function check_vat_id ($field_name, $field_value, $validator){
global $app, $page;
$vatid = trim($field_value);
if(isset($app->remoting_lib->primary_id)) {
$country = $app->remoting_lib->dataRecord['country'];
} else {
$country = $page->dataRecord['country'];
}
// check if country is member of EU
$country_details = $app->db->queryOneRecord("SELECT * FROM country WHERE iso = '".$country."'");
if($country_details['eu'] == 'y' && $vatid != ''){
$vatid = preg_replace('/\s+/', '', $vatid);
$vatid = str_replace(array('.', '-', ','), '', $vatid);
$cc = substr($vatid, 0, 2);
$vn = substr($vatid, 2);
// Test if the country of the VAT-ID matches the country of the customer
if($country != ''){
if(strtoupper($cc) != $country){
$errmsg = $validator['errmsg'];
if(isset($app->tform->wordbook[$errmsg])) {
return $app->tform->wordbook[$errmsg]."<br>\r\n";
} else {
return $errmsg."<br>\r\n";
}
}
}
$client = new SoapClient("http://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl");
if($client){
$params = array('countryCode' => $cc, 'vatNumber' => $vn);
try{
$r = $client->checkVat($params);
if($r->valid == true){
} else {
$errmsg = $validator['errmsg'];
if(isset($app->tform->wordbook[$errmsg])) {
return $app->tform->wordbook[$errmsg]."<br>\r\n";
} else {
return $errmsg."<br>\r\n";
}
}
// This foreach shows every single line of the returned information
/*
foreach($r as $k=>$prop){
echo $k . ': ' . $prop;
}
*/
} catch(SoapFault $e) {
//echo 'Error, see message: '.$e->faultstring;
switch ($e->faultstring) {
case 'INVALID_INPUT':
$errmsg = $validator['errmsg'];
if(isset($app->tform->wordbook[$errmsg])) {
return $app->tform->wordbook[$errmsg]."<br>\r\n";
} else {
return $errmsg."<br>\r\n";
}
break;
// the following cases shouldn't be the user's fault, so we return no error
case 'SERVICE_UNAVAILABLE':
case 'MS_UNAVAILABLE':
case 'TIMEOUT':
case 'SERVER_BUSY':
break;
}
}
} else {
// Connection to host not possible, europe.eu down?
// this shouldn't be the user's fault, so we return no error
}
}
}
}
......@@ -367,7 +367,12 @@ $form["tabs"]['address'] = array (
'width' => '30',
'maxlength' => '255',
'rows' => '',
'cols' => ''
'cols' => '',
'validators' => array ( 0 => array ( 'type' => 'CUSTOM',
'class' => 'validate_client',
'function' => 'check_vat_id',
'errmsg'=> 'invalid_vat_id'),
),
),
'company_id' => array (
'datatype' => 'VARCHAR',
......
......@@ -364,7 +364,12 @@ $form["tabs"]['address'] = array (
'width' => '30',
'maxlength' => '255',
'rows' => '',
'cols' => ''
'cols' => '',
'validators' => array ( 0 => array ( 'type' => 'CUSTOM',
'class' => 'validate_client',
'function' => 'check_vat_id',
'errmsg'=> 'invalid_vat_id'),
),
),
'company_id' => array (
'datatype' => 'VARCHAR',
......
......@@ -110,7 +110,7 @@ $wb['limit_webdav_user_error_notint'] = 'Das WebDAV Benutzer Limit muss eine Zah
$wb['limit_backup_txt'] = 'Backupfunktion verfügbar';
$wb['limit_dns_slave_zone_error_notint'] = 'Das Secondary DNS Zonen Limit muss eine Zahl sein.';
$wb['customer_no_txt'] = 'Kundennummer';
$wb['vat_id_txt'] = 'USt-ID';
$wb['vat_id_txt'] = 'USt.-ID';
$wb['required_fields_txt'] = '* Benötigte Felder';
$wb['limit_mailmailinglist_txt'] = 'Max. Anzahl an Mailinglisten';
$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
$wb['reseller_txt'] = 'Reseller';
$wb['btn_save_txt'] = 'Speichern';
$wb['btn_cancel_txt'] = 'Abbrechen';
$wb['invalid_vat_id'] = 'Die USt.-ID ist ungültig.';
?>
......@@ -106,7 +106,7 @@ $wb['limit_dns_slave_zone_txt'] = 'Max. Anzahl an Secondary DNS Zonen';
$wb['limit_dns_slave_zone_error_notint'] = 'Das Secondary DNS Zonen Limit muss eine Zahl sein.';
$wb['limit_dns_record_error_notint'] = 'Das DNS Eintrag Limit muss eine Zahl sein.';
$wb['customer_no_txt'] = 'Kundennummer';
$wb['vat_id_txt'] = 'USt-ID';
$wb['vat_id_txt'] = 'USt.-ID';
$wb['required_fields_txt'] = '* Benötigte Felder';
$wb['limit_webdav_user_txt'] = 'Max. Anzahl an WebDAV Benutzern';
$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.';
$wb['limit_domainmodule_txt'] = 'Domainmodule Limit';
$wb['client_limits_txt'] = 'Client Limits';
$wb['err_msg_master_tpl_set'] = 'All custom limit settings are ignored if any master template other than \\"custom\\" is selected.';
$wb['invalid_vat_id'] = 'Die USt.-ID ist ungültig.';
?>
......@@ -179,4 +179,5 @@ $wb['limit_database_quota_error_notint'] = 'The database quota limit must be a n
$wb['reseller_txt'] = 'Reseller';
$wb['btn_save_txt'] = "Save";
$wb['btn_cancel_txt'] = "Cancel";
$wb['invalid_vat_id'] = 'The VAT ID is invalid.';
?>
......@@ -178,4 +178,5 @@ $wb['limit_domainmodule_error_notint'] = 'Domainmodule limit must be a number.';
$wb['limit_domainmodule_txt'] = 'Domainmodule Limit';
$wb['client_limits_txt'] = 'Client Limits';
$wb['err_msg_master_tpl_set'] = 'All custom limit settings are ignored if any master template other than "custom" is selected.';
$wb['invalid_vat_id'] = 'The VAT ID is invalid.';
?>
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment