1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* PWWEB\Localisation\Database\Seeders\Tax\Location Seeder. |
5
|
|
|
* |
6
|
|
|
* Standard seeder for the Location Model. |
7
|
|
|
* |
8
|
|
|
* @author Frank Pillukeit <[email protected]> |
9
|
|
|
* @copyright 2020 pw-websolutions.com |
10
|
|
|
* @license http://www.opensource.org/licenses/mit-license.html MIT License |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
namespace PWWEB\Localisation\Database\Seeders\Tax; |
14
|
|
|
|
15
|
|
|
use Illuminate\Database\Seeder; |
16
|
|
|
use Illuminate\Support\Facades\DB; |
17
|
|
|
|
18
|
|
|
class LocationSeeder extends Seeder |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* Run the database seeds. |
22
|
|
|
* |
23
|
|
|
* @return void |
24
|
|
|
*/ |
25
|
|
|
public function run() |
26
|
|
|
{ |
27
|
|
|
// Initializing variables. |
28
|
|
|
$createdAt = date('Y-m-d H:i:s'); |
29
|
|
|
$locations = []; |
30
|
|
|
|
31
|
|
|
$tableNames = config('pwweb.localisation.table_names'); |
32
|
|
|
|
33
|
|
|
// Definition of default locations. |
34
|
|
|
$locations[] = ['tax_rate_id' => 1, 'country_id' => ['United Kingdom', 'Croatia', 'Poland', 'Lithuania', 'Romania', 'Cyprus', 'Malta']]; |
35
|
|
|
$locations[] = ['tax_rate_id' => 2, 'country_id' => ['United Kingdom', 'Hungary', 'Sweden', 'Denmark', 'Poland', 'Ireland', 'Netherlands', 'Latvia', 'Belgium', 'Bulgaria', 'Germany', 'Malta']]; |
36
|
|
|
$locations[] = ['tax_rate_id' => 3, 'country_id' => ['Luxembourg']]; |
37
|
|
|
$locations[] = ['tax_rate_id' => 4, 'country_id' => ['Malta']]; |
38
|
|
|
$locations[] = ['tax_rate_id' => 5, 'country_id' => ['Cyprus', 'Romania', 'Germany']]; |
39
|
|
|
$locations[] = ['tax_rate_id' => 6, 'country_id' => ['Austria', 'Bulgaria', 'France', 'Slovakia', 'Estonia', 'United Kingdom']]; |
40
|
|
|
$locations[] = ['tax_rate_id' => 7, 'country_id' => ['Belgium', 'Czech Republic', 'Latvia', 'Lithuania', 'Netherlands', 'Spain']]; |
41
|
|
|
$locations[] = ['tax_rate_id' => 8, 'country_id' => ['Slovenia', 'Italy']]; |
42
|
|
|
$locations[] = ['tax_rate_id' => 9, 'country_id' => ['Ireland', 'Poland', 'Portugal']]; |
43
|
|
|
$locations[] = ['tax_rate_id' => 10, 'country_id' => ['Finland', 'Greece']]; |
44
|
|
|
$locations[] = ['tax_rate_id' => 11, 'country_id' => ['Croatia', 'Denmark', 'Sweden']]; |
45
|
|
|
$locations[] = ['tax_rate_id' => 12, 'country_id' => ['Hungary']]; |
46
|
|
|
|
47
|
|
|
foreach ($locations as &$location) { |
48
|
|
|
$flag = true; |
49
|
|
|
$countries = $location['country_id']; |
50
|
|
|
if (true === is_array($countries)) { |
51
|
|
|
foreach ($countries as $country) { |
52
|
|
|
$country = DB::table($tableNames['countries'])->where('name', $country)->first(); |
53
|
|
|
if (true === $flag) { |
54
|
|
|
$location['country_id'] = $country->id; |
55
|
|
|
$flag = false; |
56
|
|
|
} else { |
57
|
|
|
$locations[] = ['tax_rate_id' => $location['tax_rate_id'], 'country_id' => $country->id]; |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
$location = array_merge($location, ['active' => false, 'created_at' => $createdAt, 'updated_at' => $createdAt]); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
DB::table($tableNames['tax']['locations'])->insert($locations); |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|