From 4f9db0124e0637fded88fef7aa362a2e1aae7448 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Wed, 22 Mar 2023 07:30:37 +1100 Subject: [PATCH] Remove requirement for names for schedules --- .../TaskScheduler/StoreSchedulerRequest.php | 2 +- .../TaskScheduler/UpdateSchedulerRequest.php | 2 +- app/Models/Company.php | 5 ++ app/Services/Tax/Providers/ZipTax.php | 59 +++++++++++++++++++ ...1_053933_tax_calculations_for_invoices.php | 12 ++++ 5 files changed, 78 insertions(+), 2 deletions(-) create mode 100644 app/Services/Tax/Providers/ZipTax.php diff --git a/app/Http/Requests/TaskScheduler/StoreSchedulerRequest.php b/app/Http/Requests/TaskScheduler/StoreSchedulerRequest.php index 632cd8cb80..48d5073f4f 100644 --- a/app/Http/Requests/TaskScheduler/StoreSchedulerRequest.php +++ b/app/Http/Requests/TaskScheduler/StoreSchedulerRequest.php @@ -32,7 +32,7 @@ class StoreSchedulerRequest extends Request public function rules() { $rules = [ - 'name' => ['bail', 'required', Rule::unique('schedulers')->where('company_id', auth()->user()->company()->id)], + 'name' => 'bail|sometimes|nullable|string', 'is_paused' => 'bail|sometimes|boolean', 'frequency_id' => 'bail|sometimes|integer|digits_between:1,12', 'next_run' => 'bail|required|date:Y-m-d|after_or_equal:today', diff --git a/app/Http/Requests/TaskScheduler/UpdateSchedulerRequest.php b/app/Http/Requests/TaskScheduler/UpdateSchedulerRequest.php index 4c50388136..a7f70f48b2 100644 --- a/app/Http/Requests/TaskScheduler/UpdateSchedulerRequest.php +++ b/app/Http/Requests/TaskScheduler/UpdateSchedulerRequest.php @@ -29,7 +29,7 @@ class UpdateSchedulerRequest extends Request public function rules(): array { $rules = [ - 'name' => ['bail', 'sometimes', Rule::unique('schedulers')->where('company_id', auth()->user()->company()->id)->ignore($this->task_scheduler->id)], + 'name' => 'bail|sometimes|nullable|string', 'is_paused' => 'bail|sometimes|boolean', 'frequency_id' => 'bail|sometimes|integer|digits_between:1,12', 'next_run' => 'bail|required|date:Y-m-d|after_or_equal:today', diff --git a/app/Models/Company.php b/app/Models/Company.php index 9cd858a84e..174b6b1e72 100644 --- a/app/Models/Company.php +++ b/app/Models/Company.php @@ -557,6 +557,11 @@ class Company extends BaseModel return $this->calculate_taxes && in_array($this->getSetting('country_id'), $this->tax_coverage_countries); } + public function refreshTaxData() + { + + } + public function documents() { return $this->morphMany(Document::class, 'documentable'); diff --git a/app/Services/Tax/Providers/ZipTax.php b/app/Services/Tax/Providers/ZipTax.php new file mode 100644 index 0000000000..74d43fec16 --- /dev/null +++ b/app/Services/Tax/Providers/ZipTax.php @@ -0,0 +1,59 @@ +callApi(['key' => $this->api_key, 'address' => $this->address]); + + if($response->successful()) + return $response->json(); + + if($this->postal_code) { + $response = $this->callApi(['key' => $this->api_key, 'address' => $this->postal_code]); + + if($response->successful()) + return $response->json(); + + } + + $response->throw(); + + } + + /** + * callApi + * + * @param array $parameters + * @return Response + */ + private function callApi(array $parameters): Response + { + $response = Http::retry(3, 1000)->withHeaders([])->get($this->endpoint, $parameters); + + return $response; + + } +} diff --git a/database/migrations/2023_03_21_053933_tax_calculations_for_invoices.php b/database/migrations/2023_03_21_053933_tax_calculations_for_invoices.php index 1c6d885e9f..710f59e8c6 100644 --- a/database/migrations/2023_03_21_053933_tax_calculations_for_invoices.php +++ b/database/migrations/2023_03_21_053933_tax_calculations_for_invoices.php @@ -31,6 +31,18 @@ return new class extends Migration $table->boolean('tax_data'); }); + Schema::table('schedulers', function (Blueprint $table){ + $table->dropUnique('schedulers_company_id_name_unique'); + }); + + Schema::table('schedulers', function (Blueprint $table) { + $table->string('name', 191)->nullable()->change(); + }); + + + + + } /**