diff --git a/src/Faker/Provider/de_DE/Payment.php b/src/Faker/Provider/de_DE/Payment.php index f60e62ffbb..7f6a9874ed 100644 --- a/src/Faker/Provider/de_DE/Payment.php +++ b/src/Faker/Provider/de_DE/Payment.php @@ -53,4 +53,24 @@ public static function bank() { return static::randomElement(static::$banks); } + + /** + * Value Added Tax (VAT) + * + * @example 'DE123456789', ('spaced') 'DE 123456789' + * + * @see http://ec.europa.eu/taxation_customs/vies/faq.html?locale=en#item_11 + * @see http://www.iecomputersystems.com/ordering/eu_vat_numbers.htm + * @see http://en.wikipedia.org/wiki/VAT_identification_number + * + * @param bool $spacedNationalPrefix + * + * @return string VAT Number + */ + public static function vat($spacedNationalPrefix = false) + { + $prefix = $spacedNationalPrefix ? "DE " : "DE"; + + return sprintf("%s%d", $prefix, self::randomNumber(9, true)); + } } diff --git a/src/Faker/Provider/de_DE/Person.php b/src/Faker/Provider/de_DE/Person.php index 5189a2a2fe..33ad17770f 100644 --- a/src/Faker/Provider/de_DE/Person.php +++ b/src/Faker/Provider/de_DE/Person.php @@ -126,4 +126,36 @@ public static function suffix() { return static::randomElement(static::$suffix); } + + /** + * Tax Identification Number (TIN) + * + * @example '76334701345' + * + * @see https://ec.europa.eu/taxation_customs/tin/pdf/de/TIN_-_country_sheet_DE_de.pdf + * + * @return string TIN Number + */ + public function tin() + { + $tin = $this->randomDigitNot(0).$this->randomNumber(9); + + $product = 0; + for($i = 0; $i < strlen($tin); $i++) { + $sum = ($tin[$i] + $product) % 10; + + if ($sum == 0) { + $sum = 10; + } + + $product = ($sum * 2) % 11; + } + + $checkDigit = 11 - $product; + if ($checkDigit == 10) { + $checkDigit = 0; + } + + return $tin . $checkDigit; + } } diff --git a/test/Faker/Provider/de_DE/PaymentTest.php b/test/Faker/Provider/de_DE/PaymentTest.php new file mode 100644 index 0000000000..6c8cae3cf3 --- /dev/null +++ b/test/Faker/Provider/de_DE/PaymentTest.php @@ -0,0 +1,31 @@ +addProvider(new Payment($faker)); + $this->faker = $faker; + } + + public function testVatIsValid() + { + $unspacedVat = $this->faker->vat(); + $vat = $this->faker->vat(true); + $this->assertRegExp('/^(DE \d{9})$/', $vat); + $this->assertRegExp('/^(DE\d{9})$/', $unspacedVat); + } +} diff --git a/test/Faker/Provider/de_DE/PersonTest.php b/test/Faker/Provider/de_DE/PersonTest.php new file mode 100644 index 0000000000..61be920c32 --- /dev/null +++ b/test/Faker/Provider/de_DE/PersonTest.php @@ -0,0 +1,29 @@ +addProvider(new Person($faker)); + $this->faker = $faker; + } + + public function testTinIsValid() + { + $tin = $this->faker->tin(); + $this->assertRegExp('/^(\d{11})$/', $tin); + } +}