Skip to content
This repository has been archived by the owner on Dec 11, 2020. It is now read-only.

added tax support for de_DE #1904

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/Faker/Provider/de_DE/Payment.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
32 changes: 32 additions & 0 deletions src/Faker/Provider/de_DE/Person.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
31 changes: 31 additions & 0 deletions test/Faker/Provider/de_DE/PaymentTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace Faker\Test\Provider\de_DE;

use Faker\Generator;
use Faker\Provider\de_DE\Payment;
use PHPUnit\Framework\TestCase;

final class PaymentTest extends TestCase
{

/**
* @var Generator
*/
private $faker;

protected function setUp()
{
$faker = new Generator();
$faker->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);
}
}
29 changes: 29 additions & 0 deletions test/Faker/Provider/de_DE/PersonTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace Faker\Test\Provider\de_DE;

use Faker\Generator;
use Faker\Provider\de_DE\Person;
use PHPUnit\Framework\TestCase;

final class PersonTest extends TestCase
{

/**
* @var Generator
*/
private $faker;

protected function setUp()
{
$faker = new Generator();
$faker->addProvider(new Person($faker));
$this->faker = $faker;
}

public function testTinIsValid()
{
$tin = $this->faker->tin();
$this->assertRegExp('/^(\d{11})$/', $tin);
}
}