Skip to content

Commit

Permalink
Add home location (#31)
Browse files Browse the repository at this point in the history
* Add home location

* Add work out of state test

* Cleanup

* More cleanup

* Even more cleanup
  • Loading branch information
rmcdaniel authored Jun 14, 2018
1 parent e69b6c2 commit d952b35
Show file tree
Hide file tree
Showing 39 changed files with 299 additions and 3 deletions.
19 changes: 16 additions & 3 deletions src/Classes/Taxes.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ public function setEarnings($earnings)
$this->earnings = $earnings;
}

public function setHomeLocation($location)
{
$this->home_location = $location;
}

public function setPayPeriods($pay_periods)
{
$this->pay_periods = $pay_periods;
Expand All @@ -41,8 +46,7 @@ public function setUser($user)

public function setWorkLocation($location)
{
$this->latitude = $location[0];
$this->longitude = $location[1];
$this->work_location = $location;
}

public function setYtdEarnings($ytd_earnings)
Expand Down Expand Up @@ -122,7 +126,16 @@ private function getDate()

private function getTaxes()
{
$this->taxes = TaxArea::atPoint($this->latitude, $this->longitude)
$this->taxes = TaxArea::where(function ($query) {
$query
->basedOnHomeLocation()
->atPoint($this->home_location[0], $this->home_location[1]);
})
->orWhere(function ($query) {
$query
->basedOnWorkLocation()
->atPoint($this->work_location[0], $this->work_location[1]);
})
->get()
->pluck('tax');
}
Expand Down
13 changes: 13 additions & 0 deletions src/Models/TaxArea.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

class TaxArea extends Model
{
const BASED_ON_HOME_LOCATION = 'home';
const BASED_ON_WORK_LOCATION = 'work';

protected $table = 'tax_areas';

protected $guarded = [];
Expand All @@ -28,4 +31,14 @@ public function scopeAtPoint($query, $latitude, $longitude)
$query->atPoint($latitude, $longitude);
});
}

public function scopeBasedOnHomeLocation($query)
{
return $query->where('based', TaxArea::BASED_ON_HOME_LOCATION);
}

public function scopeBasedOnWorkLocation($query)
{
return $query->where('based', TaxArea::BASED_ON_WORK_LOCATION);
}
}
118 changes: 118 additions & 0 deletions src/migrations/2018_01_01_000007_add_based_to_tax_areas.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
<?php

use Appleton\Taxes\Countries\US\FederalIncome\FederalIncome;
use Appleton\Taxes\Countries\US\FederalUnemployment\FederalUnemployment;
use Appleton\Taxes\Countries\US\Medicare\Medicare;
use Appleton\Taxes\Countries\US\Medicare\MedicareEmployer;
use Appleton\Taxes\Countries\US\SocialSecurity\SocialSecurity;
use Appleton\Taxes\Countries\US\SocialSecurity\SocialSecurityEmployer;
use Appleton\Taxes\Countries\US\Alabama\AlabamaIncome\AlabamaIncome;
use Appleton\Taxes\Countries\US\Alabama\AlabamaUnemployment\AlabamaUnemployment;
use Appleton\Taxes\Countries\US\Alabama\AttallaOccupational\AttallaOccupational;
use Appleton\Taxes\Countries\US\Alabama\AuburnOccupational\AuburnOccupational;
use Appleton\Taxes\Countries\US\Alabama\BearCreekOccupational\BearCreekOccupational;
use Appleton\Taxes\Countries\US\Alabama\BessemerOccupational\BessemerOccupational;
use Appleton\Taxes\Countries\US\Alabama\BirminghamOccupational\BirminghamOccupational;
use Appleton\Taxes\Countries\US\Alabama\BrilliantOccupational\BrilliantOccupational;
use Appleton\Taxes\Countries\US\Alabama\FairfieldOccupational\FairfieldOccupational;
use Appleton\Taxes\Countries\US\Alabama\GadsdenOccupational\GadsdenOccupational;
use Appleton\Taxes\Countries\US\Alabama\GlencoeOccupational\GlencoeOccupational;
use Appleton\Taxes\Countries\US\Alabama\GoodwaterOccupational\GoodwaterOccupational;
use Appleton\Taxes\Countries\US\Alabama\GuinOccupational\GuinOccupational;
use Appleton\Taxes\Countries\US\Alabama\HackleburgOccupational\HackleburgOccupational;
use Appleton\Taxes\Countries\US\Alabama\HaleyvilleOccupational\HaleyvilleOccupational;
use Appleton\Taxes\Countries\US\Alabama\HamiltonOccupational\HamiltonOccupational;
use Appleton\Taxes\Countries\US\Alabama\LeedsOccupational\LeedsOccupational;
use Appleton\Taxes\Countries\US\Alabama\LynnOccupational\LynnOccupational;
use Appleton\Taxes\Countries\US\Alabama\MaconCountyOccupational\MaconCountyOccupational;
use Appleton\Taxes\Countries\US\Alabama\MidfieldOccupational\MidfieldOccupational;
use Appleton\Taxes\Countries\US\Alabama\MossesOccupational\MossesOccupational;
use Appleton\Taxes\Countries\US\Alabama\OpelikaOccupational\OpelikaOccupational;
use Appleton\Taxes\Countries\US\Alabama\RainbowCityOccupational\RainbowCityOccupational;
use Appleton\Taxes\Countries\US\Alabama\RedBayOccupational\RedBayOccupational;
use Appleton\Taxes\Countries\US\Alabama\ShorterOccupational\ShorterOccupational;
use Appleton\Taxes\Countries\US\Alabama\SouthsideOccupational\SouthsideOccupational;
use Appleton\Taxes\Countries\US\Alabama\SulligentOccupational\SulligentOccupational;
use Appleton\Taxes\Countries\US\Alabama\TuskegeeOccupational\TuskegeeOccupational;
use Appleton\Taxes\Countries\US\Georgia\GeorgiaIncome\GeorgiaIncome;
use Appleton\Taxes\Countries\US\Georgia\GeorgiaUnemployment\GeorgiaUnemployment;
use Appleton\Taxes\Models\TaxArea;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;

class AddBasedToTaxAreas extends Migration
{
protected $tax_areas = 'tax_areas';

/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table($this->tax_areas, function (Blueprint $table) {
$table->string('based')->default('');
});

DB::table($this->tax_areas)
->whereIn('tax', [
AlabamaUnemployment::class,
GeorgiaUnemployment::class,
])
->update(['based' => TaxArea::BASED_ON_HOME_LOCATION]);

DB::table($this->tax_areas)
->whereIn('tax', [
FederalIncome::class,
FederalUnemployment::class,
Medicare::class,
MedicareEmployer::class,
SocialSecurity::class,
SocialSecurityEmployer::class,
AlabamaIncome::class,
AttallaOccupational::class,
AuburnOccupational::class,
BearCreekOccupational::class,
BessemerOccupational::class,
BirminghamOccupational::class,
BrilliantOccupational::class,
FairfieldOccupational::class,
GadsdenOccupational::class,
GlencoeOccupational::class,
GoodwaterOccupational::class,
GuinOccupational::class,
HackleburgOccupational::class,
HaleyvilleOccupational::class,
HamiltonOccupational::class,
LeedsOccupational::class,
LynnOccupational::class,
MaconCountyOccupational::class,
MidfieldOccupational::class,
MossesOccupational::class,
OpelikaOccupational::class,
RainbowCityOccupational::class,
RedBayOccupational::class,
ShorterOccupational::class,
SouthsideOccupational::class,
SulligentOccupational::class,
TuskegeeOccupational::class,
GeorgiaIncome::class,
])
->update(['based' => TaxArea::BASED_ON_WORK_LOCATION]);
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table($this->tax_areas, function (Blueprint $table) {
$table->dropColumn('based');
});
}
}
9 changes: 9 additions & 0 deletions tests/Unit/Countries/US/Alabama/AlabamaIncomeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class AlabamaIncomeTest extends \TestCase
public function testAlabamaIncome()
{
$results = $this->taxes->calculate(function ($taxes) {
$taxes->setHomeLocation($this->getLocation('us.alabama'));
$taxes->setWorkLocation($this->getLocation('us.alabama'));
$taxes->setUser($this->user);
$taxes->setEarnings(66.68);
Expand All @@ -23,6 +24,7 @@ public function testAlabamaIncome()
);

$results = $this->taxes->calculate(function ($taxes) {
$taxes->setHomeLocation($this->getLocation('us.alabama'));
$taxes->setWorkLocation($this->getLocation('us.alabama'));
$taxes->setUser($this->user);
$taxes->setEarnings(66.68);
Expand All @@ -37,6 +39,7 @@ public function testAlabamaAdditionalWithholding()
AlabamaIncomeTaxInformation::forUser($this->user)->update(['additional_withholding' => 10]);

$results = $this->taxes->calculate(function ($taxes) {
$taxes->setHomeLocation($this->getLocation('us.alabama'));
$taxes->setWorkLocation($this->getLocation('us.alabama'));
$taxes->setUser($this->user);
$taxes->setEarnings(0);
Expand All @@ -46,6 +49,7 @@ public function testAlabamaAdditionalWithholding()
$this->assertSame(0.0, $results->getTax(AlabamaIncome::class));

$results = $this->taxes->calculate(function ($taxes) {
$taxes->setHomeLocation($this->getLocation('us.alabama'));
$taxes->setWorkLocation($this->getLocation('us.alabama'));
$taxes->setUser($this->user);
$taxes->setEarnings(1);
Expand All @@ -55,6 +59,7 @@ public function testAlabamaAdditionalWithholding()
$this->assertSame(0.92, $results->getTax(AlabamaIncome::class));

$results = $this->taxes->calculate(function ($taxes) {
$taxes->setHomeLocation($this->getLocation('us.alabama'));
$taxes->setWorkLocation($this->getLocation('us.alabama'));
$taxes->setUser($this->user);
$taxes->setEarnings(10);
Expand All @@ -64,6 +69,7 @@ public function testAlabamaAdditionalWithholding()
$this->assertSame(9.12, $results->getTax(AlabamaIncome::class));

$results = $this->taxes->calculate(function ($taxes) {
$taxes->setHomeLocation($this->getLocation('us.alabama'));
$taxes->setWorkLocation($this->getLocation('us.alabama'));
$taxes->setUser($this->user);
$taxes->setEarnings(66.68);
Expand All @@ -76,6 +82,7 @@ public function testAlabamaAdditionalWithholding()
public function testAlabamaSupplemental()
{
$results = $this->taxes->calculate(function ($taxes) {
$taxes->setHomeLocation($this->getLocation('us.alabama'));
$taxes->setWorkLocation($this->getLocation('us.alabama'));
$taxes->setUser($this->user);
$taxes->setEarnings(100);
Expand All @@ -88,6 +95,7 @@ public function testAlabamaSupplemental()
public function testAlabamaIncomeNonNegative()
{
$results = $this->taxes->calculate(function ($taxes) {
$taxes->setHomeLocation($this->getLocation('us.alabama'));
$taxes->setWorkLocation($this->getLocation('us.alabama'));
$taxes->setUser($this->user);
$taxes->setEarnings(10);
Expand All @@ -102,6 +110,7 @@ public function testAlabamaIncomeWithNoPersonalExemption()
AlabamaIncomeTaxInformation::forUser($this->user)->update(['filing_status' => AlabamaIncome::FILING_ZERO]);

$results = $this->taxes->calculate(function ($taxes) {
$taxes->setHomeLocation($this->getLocation('us.alabama'));
$taxes->setWorkLocation($this->getLocation('us.alabama'));
$taxes->setUser($this->user);
$taxes->setEarnings(66.68);
Expand Down
22 changes: 22 additions & 0 deletions tests/Unit/Countries/US/Alabama/AlabamaUnemploymentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@

namespace Appleton\Taxes\Countries\US\Alabama\AlabamaUnemployment;

use Appleton\Taxes\Countries\US\Alabama\AlabamaIncome;

class AlabamaUnemploymentTest extends \TestCase
{
public function testAlabamaUnemployment()
{
$results = $this->taxes->calculate(function ($taxes) {
$taxes->setHomeLocation($this->getLocation('us.alabama'));
$taxes->setWorkLocation($this->getLocation('us.alabama'));
$taxes->setUser($this->user);
$taxes->setEarnings(2300);
Expand All @@ -20,6 +23,7 @@ public function testAlabamaUnemploymentWithTaxRate()
config(['taxes.rates.us.alabama.unemployment' => 0.024]);

$results = $this->taxes->calculate(function ($taxes) {
$taxes->setHomeLocation($this->getLocation('us.alabama'));
$taxes->setWorkLocation($this->getLocation('us.alabama'));
$taxes->setUser($this->user);
$taxes->setEarnings(2300);
Expand All @@ -31,6 +35,7 @@ public function testAlabamaUnemploymentWithTaxRate()
public function testAlabamaUnemploymentMetWageBase()
{
$results = $this->taxes->calculate(function ($taxes) {
$taxes->setHomeLocation($this->getLocation('us.alabama'));
$taxes->setWorkLocation($this->getLocation('us.alabama'));
$taxes->setUser($this->user);
$taxes->setEarnings(100);
Expand All @@ -40,6 +45,7 @@ public function testAlabamaUnemploymentMetWageBase()
$this->assertSame(2.70, $results->getTax(AlabamaUnemployment::class));

$results = $this->taxes->calculate(function ($taxes) {
$taxes->setHomeLocation($this->getLocation('us.alabama'));
$taxes->setWorkLocation($this->getLocation('us.alabama'));
$taxes->setUser($this->user);
$taxes->setEarnings(100);
Expand All @@ -49,6 +55,7 @@ public function testAlabamaUnemploymentMetWageBase()
$this->assertSame(1.35, $results->getTax(AlabamaUnemployment::class));

$results = $this->taxes->calculate(function ($taxes) {
$taxes->setHomeLocation($this->getLocation('us.alabama'));
$taxes->setWorkLocation($this->getLocation('us.alabama'));
$taxes->setUser($this->user);
$taxes->setEarnings(100);
Expand All @@ -58,6 +65,7 @@ public function testAlabamaUnemploymentMetWageBase()
$this->assertSame(0.0, $results->getTax(AlabamaUnemployment::class));

$results = $this->taxes->calculate(function ($taxes) {
$taxes->setHomeLocation($this->getLocation('us.alabama'));
$taxes->setWorkLocation($this->getLocation('us.alabama'));
$taxes->setUser($this->user);
$taxes->setEarnings(100);
Expand All @@ -72,11 +80,25 @@ public function testCaseStudy1()
config(['taxes.rates.us.alabama.unemployment' => 0.019]);

$results = $this->taxes->calculate(function ($taxes) {
$taxes->setHomeLocation($this->getLocation('us.alabama'));
$taxes->setWorkLocation($this->getLocation('us.alabama'));
$taxes->setUser($this->user);
$taxes->setEarnings(66.68);
});

$this->assertSame(1.27, $results->getTax(AlabamaUnemployment::class));
}

public function testWorkOutOfState()
{
$results = $this->taxes->calculate(function ($taxes) {
$taxes->setHomeLocation($this->getLocation('us.alabama'));
$taxes->setWorkLocation($this->getLocation('us'));
$taxes->setUser($this->user);
$taxes->setEarnings(2300);
});

$this->assertNull($results->getTax(AlabamaIncome::class));
$this->assertSame(62.10, $results->getTax(AlabamaUnemployment::class));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class AttallaOccupationalTest extends \TestCase
public function testAttallaOccupational()
{
$results = $this->taxes->calculate(function ($taxes) {
$taxes->setHomeLocation($this->getLocation('us.alabama.attalla'));
$taxes->setWorkLocation($this->getLocation('us.alabama.attalla'));
$taxes->setUser($this->user);
$taxes->setEarnings(2300);
Expand Down
1 change: 1 addition & 0 deletions tests/Unit/Countries/US/Alabama/AuburnOccupationalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class AuburnOccupationalTest extends \TestCase
public function testAuburnOccupational()
{
$results = $this->taxes->calculate(function ($taxes) {
$taxes->setHomeLocation($this->getLocation('us.alabama.auburn'));
$taxes->setWorkLocation($this->getLocation('us.alabama.auburn'));
$taxes->setUser($this->user);
$taxes->setEarnings(2300);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class BearCreekOccupationalTest extends \TestCase
public function testBearCreekOccupational()
{
$results = $this->taxes->calculate(function ($taxes) {
$taxes->setHomeLocation($this->getLocation('us.alabama.bearcreek'));
$taxes->setWorkLocation($this->getLocation('us.alabama.bearcreek'));
$taxes->setUser($this->user);
$taxes->setEarnings(2300);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class BessemerOccupationalTest extends \TestCase
public function testBessemerOccupational()
{
$results = $this->taxes->calculate(function ($taxes) {
$taxes->setHomeLocation($this->getLocation('us.alabama.bessemer'));
$taxes->setWorkLocation($this->getLocation('us.alabama.bessemer'));
$taxes->setUser($this->user);
$taxes->setEarnings(2300);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class BirminghamOccupationalTest extends \TestCase
public function testBirminghamOccupational()
{
$results = $this->taxes->calculate(function ($taxes) {
$taxes->setHomeLocation($this->getLocation('us.alabama.birmingham'));
$taxes->setWorkLocation($this->getLocation('us.alabama.birmingham'));
$taxes->setUser($this->user);
$taxes->setEarnings(2300);
Expand All @@ -18,6 +19,7 @@ public function testBirminghamOccupational()
public function testCaseStudy1()
{
$results = $this->taxes->calculate(function ($taxes) {
$taxes->setHomeLocation($this->getLocation('us.alabama.birmingham'));
$taxes->setWorkLocation($this->getLocation('us.alabama.birmingham'));
$taxes->setUser($this->user);
$taxes->setEarnings(66.68);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class BrilliantOccupationalTest extends \TestCase
public function testBrilliantOccupational()
{
$results = $this->taxes->calculate(function ($taxes) {
$taxes->setHomeLocation($this->getLocation('us.alabama.brilliant'));
$taxes->setWorkLocation($this->getLocation('us.alabama.brilliant'));
$taxes->setUser($this->user);
$taxes->setEarnings(2300);
Expand Down
Loading

0 comments on commit d952b35

Please sign in to comment.