Working on taxes

This commit is contained in:
David Bomba 2023-03-24 13:56:26 +11:00
parent e87e5397fb
commit b5a4fc9865
3 changed files with 104 additions and 67 deletions

View File

@ -18,8 +18,7 @@ class Response
public int $rCode = 100; public int $rCode = 100;
/** /**
* ["results" => [ * [
* [
* "geoPostalCode" => "92582", * "geoPostalCode" => "92582",
* "geoCity" => "SAN JACINTO", * "geoCity" => "SAN JACINTO",
* "geoCounty" => "RIVERSIDE", * "geoCounty" => "RIVERSIDE",
@ -54,13 +53,45 @@ class Response
* "district5SalesTax" => 0, * "district5SalesTax" => 0,
* "district5UseTax" => 0, * "district5UseTax" => 0,
* "originDestination" => "D", * "originDestination" => "D",
* ], *
* ]
* ]; * ];
* *
* @var mixed[]
*/ */
public array $results = [];
public string $geoPostalCode = "92582";
public string $geoCity = "SAN JACINTO";
public string $geoCounty = "RIVERSIDE";
public string $geoState = "CA";
public float $taxSales = 0.0875;
public float $taxUse = 0.0875;
public string $txbService = "N";
public string $txbFreight = "N";
public float $stateSalesTax = 0.06;
public float $stateUseTax = 0.06;
public float $citySalesTax = 0.01;
public float $cityUseTax = 0.01;
public string $cityTaxCode = "874";
public float $countySalesTax = 0.0025;
public float $countyUseTax = 0.0025;
public string $countyTaxCode = "";
public float $districtSalesTax = 0.015;
public float $districtUseTax = 0.015;
public string $district1Code = "26";
public float $district1SalesTax = 0;
public float $district1UseTax = 0;
public string $district2Code = "26";
public float $district2SalesTax = 0.005;
public float $district2UseTax = 0.005;
public string $district3Code = "";
public float $district3SalesTax = 0;
public float $district3UseTax = 0;
public string $district4Code = "33";
public float $district4SalesTax = 0.01;
public float $district4UseTax = 0.01;
public string $district5Code = "";
public float $district5SalesTax = 0;
public float $district5UseTax = 0;
public string $originDestination = "D";
} }

View File

@ -148,6 +148,7 @@ class InvoiceItemSum
private function calcTaxesAutomatically() private function calcTaxesAutomatically()
{ {
return $this;
} }
private function calcTaxes() private function calcTaxes()

View File

@ -12,6 +12,7 @@
namespace Tests\Unit\Tax; namespace Tests\Unit\Tax;
use Tests\TestCase; use Tests\TestCase;
use App\Models\Client;
use Tests\MockAccountData; use Tests\MockAccountData;
use Illuminate\Routing\Middleware\ThrottleRequests; use Illuminate\Routing\Middleware\ThrottleRequests;
use Illuminate\Foundation\Testing\DatabaseTransactions; use Illuminate\Foundation\Testing\DatabaseTransactions;
@ -24,45 +25,41 @@ class SumTaxTest extends TestCase
use MockAccountData; use MockAccountData;
use DatabaseTransactions; use DatabaseTransactions;
public array $response = public array $response = [
["results" => [ "geoPostalCode" => "92582",
[ "geoCity" => "SAN JACINTO",
"geoPostalCode" => "92582", "geoCounty" => "RIVERSIDE",
"geoCity" => "SAN JACINTO", "geoState" => "CA",
"geoCounty" => "RIVERSIDE", "taxSales" => 0.0875,
"geoState" => "CA", "taxUse" => 0.0875, // tax amount where destination does not charge sales tax, but origin does
"taxSales" => 0.0875, "txbService" => "N", // whether services are taxed in this locale
"taxUse" => 0.0875, // tax amount where destination does not charge sales tax, but origin does "txbFreight" => "N", // whether freight is taxes in this locale
"txbService" => "N", // whether services are taxed in this locale "stateSalesTax" => 0.06,
"txbFreight" => "N", // whether freight is taxes in this locale "stateUseTax" => 0.06,
"stateSalesTax" => 0.06, "citySalesTax" => 0.01,
"stateUseTax" => 0.06, "cityUseTax" => 0.01,
"citySalesTax" => 0.01, "cityTaxCode" => "874",
"cityUseTax" => 0.01, "countySalesTax" => 0.0025,
"cityTaxCode" => "874", "countyUseTax" => 0.0025,
"countySalesTax" => 0.0025, "countyTaxCode" => "",
"countyUseTax" => 0.0025, "districtSalesTax" => 0.015,
"countyTaxCode" => "", "districtUseTax" => 0.015,
"districtSalesTax" => 0.015, "district1Code" => "26",
"districtUseTax" => 0.015, "district1SalesTax" => 0,
"district1Code" => "26", "district1UseTax" => 0,
"district1SalesTax" => 0, "district2Code" => "26",
"district1UseTax" => 0, "district2SalesTax" => 0.005,
"district2Code" => "26", "district2UseTax" => 0.005,
"district2SalesTax" => 0.005, "district3Code" => "",
"district2UseTax" => 0.005, "district3SalesTax" => 0,
"district3Code" => "", "district3UseTax" => 0,
"district3SalesTax" => 0, "district4Code" => "33",
"district3UseTax" => 0, "district4SalesTax" => 0.01,
"district4Code" => "33", "district4UseTax" => 0.01,
"district4SalesTax" => 0.01, "district5Code" => "",
"district4UseTax" => 0.01, "district5SalesTax" => 0,
"district5Code" => "", "district5UseTax" => 0, //district1-5 portion of the district tax
"district5SalesTax" => 0, "originDestination" => "D", //location where this is taxed origin/destination/null
"district5UseTax" => 0, //district1-5 portion of the district tax
"originDestination" => "D", //location where this is taxed origin/destination/null
],
]
]; ];
@ -76,42 +73,50 @@ class SumTaxTest extends TestCase
$this->withoutExceptionHandling(); $this->withoutExceptionHandling();
// $this->makeTestData(); $this->makeTestData();
} }
public function testTaxOnInvoice() public function testTaxOnInvoice()
{ {
$c = Client::factory()->create([
'user_id' => $this->user->id,
'company_id' => $this->company->id,
]);
$c->tax_data = $this->response;
$c->save();
$this->assertEquals("92582", $c->tax_data->geoPostalCode);
} }
public function testSumOfInvoice() public function testSumOfInvoice()
{ {
$this->assertEquals("CA", $this->response['results'][0]['geoState']); $this->assertEquals("CA", $this->response['geoState']);
} }
public function testSumOfTaxes() public function testSumOfTaxes()
{ {
$sum = $sum =
$this->response['results'][0]['stateSalesTax'] + $this->response['stateSalesTax'] +
// $this->response['results'][0]['stateUseTax'] + // $this->response['stateUseTax'] +
$this->response['results'][0]['citySalesTax'] + $this->response['citySalesTax'] +
// $this->response['results'][0]['cityUseTax'] + // $this->response['cityUseTax'] +
$this->response['results'][0]['countySalesTax'] + $this->response['countySalesTax'] +
// $this->response['results'][0]['countyUseTax'] + // $this->response['countyUseTax'] +
$this->response['results'][0]['districtSalesTax']; $this->response['districtSalesTax'];
// // $this->response['results'][0]['districtUseTax'] + // // $this->response['districtUseTax'] +
// $this->response['results'][0]['district1SalesTax'] + // $this->response['district1SalesTax'] +
// // $this->response['results'][0]['district1UseTax'] + // // $this->response['district1UseTax'] +
// $this->response['results'][0]['district2SalesTax'] + // $this->response['district2SalesTax'] +
// // $this->response['results'][0]['district2UseTax'] + // // $this->response['district2UseTax'] +
// $this->response['results'][0]['district3SalesTax'] + // $this->response['district3SalesTax'] +
// // $this->response['results'][0]['district3UseTax'] + // // $this->response['district3UseTax'] +
// $this->response['results'][0]['district4SalesTax'] + // $this->response['district4SalesTax'] +
// // $this->response['results'][0]['district4UseTax'] + // // $this->response['district4UseTax'] +
// $this->response['results'][0]['district5SalesTax']; // $this->response['district5SalesTax'];
// $this->response['results'][0]['district5UseTax']; // $this->response['district5UseTax'];
$this->assertEquals(0.0875, $sum); $this->assertEquals(0.0875, $sum);
} }