diff --git a/app/DataMapper/Tax/BaseRule.php b/app/DataMapper/Tax/BaseRule.php index 37299abc5115..fc71eaa498ae 100644 --- a/app/DataMapper/Tax/BaseRule.php +++ b/app/DataMapper/Tax/BaseRule.php @@ -152,6 +152,7 @@ class BaseRule implements RuleInterface $this->client->saveQuietly(); nlog('Automatic tax calculations not supported for this country - defaulting to company country'); + } /** Harvest the client_region */ diff --git a/app/Http/Controllers/EmailController.php b/app/Http/Controllers/EmailController.php index 8cd59930b6d2..b7e692d3726d 100644 --- a/app/Http/Controllers/EmailController.php +++ b/app/Http/Controllers/EmailController.php @@ -46,74 +46,6 @@ class EmailController extends BaseController parent::__construct(); } - /** - * Returns a template filled with entity variables. - * - * @param SendEmailRequest $request - * @return Response - * - * @OA\Post( - * path="/api/v1/emails", - * operationId="sendEmailTemplate", - * tags={"emails"}, - * summary="Sends an email for an entity", - * description="Sends an email for an entity", - * @OA\Parameter(ref="#/components/parameters/X-Requested-With"), - * @OA\RequestBody( - * description="The template subject and body", - * required=true, - * @OA\MediaType( - * mediaType="application/json", - * @OA\Schema( - * type="object", - * @OA\Property( - * property="subject", - * description="The email subject", - * type="string", - * ), - * @OA\Property( - * property="body", - * description="The email body", - * type="string", - * ), - * @OA\Property( - * property="entity", - * description="The entity name", - * type="string", - * ), - * @OA\Property( - * property="entity_id", - * description="The entity_id", - * type="string", - * ), - * @OA\Property( - * property="template", - * description="The template required", - * type="string", - * ), - * ) - * ) - * ), - * @OA\Response( - * response=200, - * description="success", - * @OA\Header(header="X-MINIMUM-CLIENT-VERSION", ref="#/components/headers/X-MINIMUM-CLIENT-VERSION"), - * @OA\Header(header="X-RateLimit-Remaining", ref="#/components/headers/X-RateLimit-Remaining"), - * @OA\Header(header="X-RateLimit-Limit", ref="#/components/headers/X-RateLimit-Limit"), - * @OA\JsonContent(ref="#/components/schemas/Template"), - * ), - * @OA\Response( - * response=422, - * description="Validation error", - * @OA\JsonContent(ref="#/components/schemas/ValidationError"), - * ), - * @OA\Response( - * response="default", - * description="Unexpected Error", - * @OA\JsonContent(ref="#/components/schemas/Error"), - * ), - * ) - */ public function send(SendEmailRequest $request) { $entity = $request->input('entity'); diff --git a/app/Jobs/Client/UpdateTaxData.php b/app/Jobs/Client/UpdateTaxData.php new file mode 100644 index 000000000000..105360fda062 --- /dev/null +++ b/app/Jobs/Client/UpdateTaxData.php @@ -0,0 +1,78 @@ +company->db); + + if(!config('services.tax.zip_tax.key')) + return; + + $tax_provider = new \App\Services\Tax\Providers\TaxProvider($this->company, $this->client); + + try { + + $tax_provider->updateClientTaxData(); + + + if (!$this->client->state && $this->client->postal_code) { + + $this->client->state = USStates::getState($this->client->postal_code); + + $this->client->save(); + + } + + + }catch(\Exception $e){ + nlog("problem getting tax data => ".$e->getMessage()); + } + + + } +} \ No newline at end of file diff --git a/app/Observers/ClientObserver.php b/app/Observers/ClientObserver.php index ed0a1e7c3310..066afd3c71c1 100644 --- a/app/Observers/ClientObserver.php +++ b/app/Observers/ClientObserver.php @@ -11,9 +11,10 @@ namespace App\Observers; -use App\Jobs\Util\WebhookHandler; use App\Models\Client; use App\Models\Webhook; +use App\Jobs\Util\WebhookHandler; +use App\Jobs\Company\UpdateTaxData; class ClientObserver { @@ -27,6 +28,11 @@ class ClientObserver */ public function created(Client $client) { + + if ($client->country_id == 840 && $client->company->calculate_taxes) { + UpdateTaxData::dispatch($client, $client->company); + } + $subscriptions = Webhook::where('company_id', $client->company_id) ->where('event_id', Webhook::EVENT_CREATE_CLIENT) ->exists(); @@ -44,6 +50,11 @@ class ClientObserver */ public function updated(Client $client) { + if($client->getOriginal('postal_code') != $client->postal_code && $client->country_id == 840 && $client->company->calculate_taxes) + { + UpdateTaxData::dispatch($client, $client->company); + } + $event = Webhook::EVENT_UPDATE_CLIENT; if ($client->getOriginal('deleted_at') && !$client->deleted_at) { @@ -53,8 +64,7 @@ class ClientObserver if ($client->is_deleted) { $event = Webhook::EVENT_DELETE_CLIENT; } - - + $subscriptions = Webhook::where('company_id', $client->company_id) ->where('event_id', $event) ->exists(); diff --git a/tests/Unit/Tax/TaxConfigTest.php b/tests/Unit/Tax/TaxConfigTest.php index c08c84a25ec1..459c36240391 100644 --- a/tests/Unit/Tax/TaxConfigTest.php +++ b/tests/Unit/Tax/TaxConfigTest.php @@ -59,16 +59,16 @@ class TaxConfigTest extends TestCase 'address1' => '400 Evelyn Pl', 'city' => 'Beverley Hills', 'state' => '', - 'postal_code' => 90210, + 'postal_code' => '', 'country_id' => 840, ]); - $this->assertEquals('CA', USStates::getState('90210')); + // $this->assertEquals('CA', USStates::getState('90210')); - // $this->bootApi($client); + $this->bootApi($client); - // $this->tp->updateClientTaxData(); + $this->tp->updateClientTaxData(); }