1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-08 20:22:42 +01:00
invoiceninja/database/seeds/CountriesSeeder.php

195 lines
6.7 KiB
PHP
Raw Normal View History

2015-03-16 22:45:25 +01:00
<?php
2017-01-30 20:40:43 +01:00
2016-02-27 21:12:22 +01:00
use App\Models\Country;
2015-03-16 22:45:25 +01:00
2017-01-30 17:05:31 +01:00
class CountriesSeeder extends Seeder
{
2015-03-16 22:45:25 +01:00
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
2017-05-14 16:42:24 +02:00
Eloquent::unguard();
2015-03-16 22:45:25 +01:00
2017-05-14 16:42:24 +02:00
$countries = Countries::getList();
foreach ($countries as $countryId => $country) {
if ($record = Country::whereCountryCode($country['country-code'])->first()) {
$record->name = $country['name'];
$record->full_name = ((isset($country['full_name'])) ? $country['full_name'] : null);
$record->save();
} else {
2017-01-30 20:40:43 +01:00
DB::table('countries')->insert([
2016-02-27 21:12:22 +01:00
'id' => $countryId,
'capital' => ((isset($country['capital'])) ? $country['capital'] : null),
'citizenship' => ((isset($country['citizenship'])) ? $country['citizenship'] : null),
'country_code' => $country['country-code'],
'currency' => ((isset($country['currency'])) ? $country['currency'] : null),
'currency_code' => ((isset($country['currency_code'])) ? $country['currency_code'] : null),
'currency_sub_unit' => ((isset($country['currency_sub_unit'])) ? $country['currency_sub_unit'] : null),
'full_name' => ((isset($country['full_name'])) ? $country['full_name'] : null),
'iso_3166_2' => $country['iso_3166_2'],
'iso_3166_3' => $country['iso_3166_3'],
'name' => $country['name'],
'region_code' => $country['region-code'],
'sub_region_code' => $country['sub-region-code'],
2017-01-30 20:40:43 +01:00
'eea' => (bool) $country['eea'],
]);
2016-02-27 21:12:22 +01:00
}
}
2017-05-14 16:42:24 +02:00
2016-02-27 21:12:22 +01:00
// Source: http://www.bitboost.com/ref/international-address-formats.html
// Source: https://en.wikipedia.org/wiki/Linguistic_issues_concerning_the_euro
$countries = [
'AR' => [
'swap_postal_code' => true,
],
'AT' => [ // Austria
'swap_postal_code' => true,
'swap_currency_symbol' => true,
],
'BE' => [
'swap_postal_code' => true,
],
'BG' => [ // Belgium
'swap_currency_symbol' => true,
],
2018-03-20 14:51:25 +01:00
'CA' => [
'thousand_separator' => ',',
'decimal_separator' => '.',
],
2016-02-27 21:12:22 +01:00
'CH' => [
'swap_postal_code' => true,
],
2019-10-27 10:41:19 +01:00
'CN' => [ // China
'thousand_separator' => ',',
'decimal_separator' => '.',
],
2016-02-27 21:12:22 +01:00
'CZ' => [ // Czech Republic
'swap_currency_symbol' => true,
],
'DE' => [ // Germany
'swap_postal_code' => true,
'swap_currency_symbol' => true,
],
'DK' => [
'swap_postal_code' => true,
],
'EE' => [ // Estonia
'swap_currency_symbol' => true,
],
'ES' => [ // Spain
'swap_postal_code' => true,
'swap_currency_symbol' => true,
],
'FI' => [ // Finland
'swap_postal_code' => true,
'swap_currency_symbol' => true,
],
'FR' => [ // France
'swap_postal_code' => true,
'swap_currency_symbol' => true,
],
'GR' => [ // Greece
'swap_currency_symbol' => true,
],
'HR' => [ // Croatia
'swap_currency_symbol' => true,
],
'HU' => [ // Hungary
'swap_currency_symbol' => true,
],
'GL' => [
'swap_postal_code' => true,
],
'IE' => [ // Ireland
'thousand_separator' => ',',
'decimal_separator' => '.',
],
'IL' => [
'swap_postal_code' => true,
],
'IS' => [ // Iceland
'swap_postal_code' => true,
'swap_currency_symbol' => true,
],
'IT' => [ // Italy
'swap_postal_code' => true,
'swap_currency_symbol' => true,
],
2016-03-09 16:37:28 +01:00
'JP' => [ // Japan
'swap_postal_code' => true,
'swap_currency_symbol' => true,
],
2016-02-27 21:12:22 +01:00
'LT' => [ // Lithuania
'swap_currency_symbol' => true,
],
'LU' => [
'swap_postal_code' => true,
],
2018-03-20 14:51:25 +01:00
'MT' => [
'thousand_separator' => ',',
'decimal_separator' => '.',
],
2016-02-27 21:12:22 +01:00
'MY' => [
'swap_postal_code' => true,
],
'MX' => [
'swap_postal_code' => true,
],
'NL' => [
'swap_postal_code' => true,
],
'PL' => [ // Poland
'swap_postal_code' => true,
'swap_currency_symbol' => true,
],
'PT' => [ // Portugal
'swap_postal_code' => true,
'swap_currency_symbol' => true,
],
'RO' => [ // Romania
'swap_currency_symbol' => true,
],
'SE' => [ // Sweden
'swap_postal_code' => true,
'swap_currency_symbol' => true,
],
'SI' => [ // Slovenia
'swap_currency_symbol' => true,
],
'SK' => [ // Slovakia
'swap_currency_symbol' => true,
],
2017-06-13 19:16:20 +02:00
'US' => [
'thousand_separator' => ',',
'decimal_separator' => '.',
],
'SR' => [ // Suriname
'swap_currency_symbol' => true,
],
2016-02-27 21:12:22 +01:00
'UY' => [
'swap_postal_code' => true,
],
];
foreach ($countries as $code => $data) {
$country = Country::where('iso_3166_2', '=', $code)->first();
if (isset($data['swap_postal_code'])) {
$country->swap_postal_code = true;
}
if (isset($data['swap_currency_symbol'])) {
$country->swap_currency_symbol = true;
}
if (isset($data['thousand_separator'])) {
$country->thousand_separator = $data['thousand_separator'];
}
if (isset($data['decimal_separator'])) {
$country->decimal_separator = $data['decimal_separator'];
}
$country->save();
2015-03-16 22:45:25 +01:00
}
}
2017-01-30 17:05:31 +01:00
}