mirror of
https://github.com/fzaninotto/Faker.git
synced 2025-03-23 16:59:53 +01:00
regon in Company
This commit is contained in:
parent
8119a9388e
commit
e182c98c03
55
src/Faker/Provider/pl_PL/Company.php
Normal file
55
src/Faker/Provider/pl_PL/Company.php
Normal file
@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
namespace Faker\Provider\pl_PL;
|
||||
|
||||
class Company extends \Faker\Provider\Company
|
||||
{
|
||||
/**
|
||||
* Register of the National Economy
|
||||
* @link http://pl.wikipedia.org/wiki/REGON
|
||||
* @return 9 digit number
|
||||
*/
|
||||
public static function regon()
|
||||
{
|
||||
$weights = Array(8, 9, 2, 3, 4, 5, 6, 7);
|
||||
$regionNumber = static::numberBetween(0, 49) * 2 + 1;
|
||||
$result = array((int)($regionNumber / 10), $regionNumber % 10);
|
||||
for ($i = 2; $i < count($weights); $i++) {
|
||||
$result[$i] = static::randomDigit();
|
||||
}
|
||||
$checksum = 0;
|
||||
for ($i = 0; $i < count($result); $i++) {
|
||||
$checksum += $weights[$i] * $result[$i];
|
||||
}
|
||||
$checksum %= 11;
|
||||
if ($checksum == 10) {
|
||||
$checksum = 0;
|
||||
}
|
||||
$result[] = $checksum;
|
||||
return implode('', $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register of the National Economy, local entity number
|
||||
* @link http://pl.wikipedia.org/wiki/REGON
|
||||
* @return 14 digit number
|
||||
*/
|
||||
public static function regonLocal()
|
||||
{
|
||||
$weights = array(2, 4, 8, 5, 0, 9, 7, 3, 6, 1, 2, 4, 8);
|
||||
$result = str_split(static::regon());
|
||||
for ($i = count($result); $i < count($weights); $i++) {
|
||||
$result[$i] = static::randomDigit();
|
||||
}
|
||||
$checksum = 0;
|
||||
for ($i = 0; $i < count($result); $i++) {
|
||||
$checksum += $weights[$i] * $result[$i];
|
||||
}
|
||||
$checksum %= 11;
|
||||
if ($checksum == 10) {
|
||||
$checksum = 0;
|
||||
}
|
||||
$result[] = $checksum;
|
||||
return implode('', $result);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user