Skip to content
Richard McDaniel edited this page Feb 7, 2018 · 2 revisions

This page describes the models used in this library.

Model Description
GovernmentalUnitArea Examples of governmental unit areas are the USA, Alabama and Huntsville. Each one has a name and a PostGIS geometry that can be used to determine if a latitude and longitude falls within that jurisdiction. The default table name is governmental_unit_areas.
TaxArea A TaxArea is an association between a governmental unit area and a particular tax. Each one has a name, a tax class name, such as FederalIncome::class and an association with a GovernmentalUnitArea. The default table name is tax_areas.
TaxInformation Some taxes require information about a user, such as additional withholding, dependents, exemptions, filing status or citizenship. A TaxInformation is an association between a user and a particular type of tax information. It includes two scopes forUser and isTypeOf which let you filter by a particular user or a particular type of tax information, for example, FederalIncomeTaxInformation. The default table name is tax_information.
BaseTaxInformationModel The BaseTaxInformationModel isn't used directly. It is extended by other specific types of tax information, again, for example, FederalIncomeTaxInformation. The base class has a tax information association, a static helper function createForUser which creates tax information for a user, and a scope forUser which lets you filter by a specific user. There is no table for this class.
FederalIncomeTaxInformation FederalIncomeTaxInformation extends BaseTaxInformationModel. It stores tax information needed to calculate federal income tax withholding for a user. The default table name is federal_income_tax_information.
AlabamaIncomeTaxInformation AlabamaIncomeTaxInformation extends BaseTaxInformationModel. It stores tax information needed to calculate Alabama income tax withholding for a user. The default table name is alabama_income_tax_information.

Example Usage:

// taken from a migration
// ----
$id = DB::table($this->governmental_unit_areas)->insertGetId([
    'name' => 'US',
    'area' => `...huge binary blob here...`
]);  

DB::table($this->tax_areas)->insert([
    'name' => 'Federal Income Tax',
    'tax' => FederalIncome::class,
    'governmental_unit_area_id' => $id,
]);
// ----

// setup a users tax information
FederalIncomeTaxInformation::createForUser([
    'additional_withholding' => 0,
    'exemptions' => 0,
    'filing_status' => FederalIncome::FILING_SINGLE,
    'non_resident_alien' => false,
], $this->user);

// update it later if it changes
FederalIncomeTaxInformation::forUser($this->user)->update(['filing_status' => FederalIncome::FILING_MARRIED]);

// might as well calculate some taxes too
$results = $this->taxes->calculate(function ($taxes) {
    $taxes->setWorkLocation([38.9072, -77.0369]);
    $taxes->setUser($this->user);
    $taxes->setEarnings(2301);
});

$this->assertSame(10.10, $results->getTax(FederalIncome::class));
Clone this wiki locally