Skip to content

Commit

Permalink
Merge branch 'development'
Browse files Browse the repository at this point in the history
  • Loading branch information
orkit committed Apr 12, 2024
2 parents ccf9aa2 + baab192 commit 8342052
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 2 deletions.
33 changes: 33 additions & 0 deletions app/Console/Commands/UpdateAllowance.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

namespace App\Console\Commands;

use App\Services\Skatteverket;
use Illuminate\Console\Command;

class UpdateAllowance extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'update-allowance';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Command description';

/**
* Execute the console command.
*/
public function handle()
{
$skatteverket = new Skatteverket();
$skatteverket->getCountry();
$skatteverket->checkAllowance();
}
}
42 changes: 40 additions & 2 deletions app/Services/Skatteverket.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ public function getResource($endpoint)
//Retrieving countries
public function getCountry()
{
//Retrive allowances for 2023
$this->array_resource = json_decode($this->getResource('/dataset/70ccea31-b64c-4bf5-84c7-673f04f32505?%C3%A5r=2023&_limit=500&_offset=0')->getBody()->getContents(), TRUE);
//Retrive allowances
$year = 2024;
$this->array_resource = json_decode($this->getResource('/dataset/70ccea31-b64c-4bf5-84c7-673f04f32505?%C3%A5r=' . $year . '&_limit=500&_offset=0')->getBody()->getContents(), TRUE);

foreach ($this->array_resource['results'] as $result_country) {
$country = Country::updateOrCreate(
Expand All @@ -44,4 +45,41 @@ public function getCountry()
}
return true;
}

public function checkAllowance()
{
$countries = Country::all();
foreach($countries as $country) {
switch($country->allowance) {
case('Se Myanmar'):
$assign = Country::where('country', 'Myanmar')->first();
$country->allowance = $assign->allowance;
case('Se Danmark'):
$assign = Country::where('country', 'Danmark')->first();
$country->allowance = $assign->allowance;
case('Se Kina'):
$assign = Country::where('country', 'Kina')->first();
$country->allowance = $assign->allowance;
case('Se Övriga länder och områden'):
$assign = Country::where('country', 'Irak')->first();
$country->allowance = $assign->allowance;
case('Se Nordmakedonien'):
$assign = Country::where('country', 'Nordmakedonien, f.d. Makedonien')->first();
$country->allowance = $assign->allowance;
case('Se USA'):
$assign = Country::where('country', 'USA')->first();
$country->allowance = $assign->allowance;
case('Se Italien'):
$assign = Country::where('country', 'Italien')->first();
$country->allowance = $assign->allowance;
case('Se Eswatini'):
$assign = Country::where('country', 'Eswatini')->first();
$country->allowance = $assign->allowance;
case('Se Belarus'):
$assign = Country::where('country', 'Belarus')->first();
$country->allowance = $assign->allowance;
}
$country->save();
}
}
}

0 comments on commit 8342052

Please sign in to comment.