From e5bd186b617edf962eb007356cb0270fc84b6f71 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Thu, 19 Oct 2023 11:23:13 +1100 Subject: [PATCH 1/2] Fixes for tax calculations --- app/Http/Controllers/ClientController.php | 3 +- app/Jobs/Client/UpdateTaxData.php | 65 +--------------------- app/Services/Tax/Providers/TaxProvider.php | 2 + 3 files changed, 5 insertions(+), 65 deletions(-) diff --git a/app/Http/Controllers/ClientController.php b/app/Http/Controllers/ClientController.php index 7b305b09ff65..0bb9508f7646 100644 --- a/app/Http/Controllers/ClientController.php +++ b/app/Http/Controllers/ClientController.php @@ -308,7 +308,8 @@ class ClientController extends BaseController */ public function updateTaxData(PurgeClientRequest $request, Client $client) { - (new UpdateTaxData($client, $client->company))->handle(); + if($client->company->account->isPaid()) + (new UpdateTaxData($client, $client->company))->handle(); return $this->itemResponse($client->fresh()); } diff --git a/app/Jobs/Client/UpdateTaxData.php b/app/Jobs/Client/UpdateTaxData.php index f28781bfe080..89a25bdd865c 100644 --- a/app/Jobs/Client/UpdateTaxData.php +++ b/app/Jobs/Client/UpdateTaxData.php @@ -52,7 +52,7 @@ class UpdateTaxData implements ShouldQueue { MultiDB::setDb($this->company->db); - if($this->company->account->isFreeHostedClient()) + if($this->company->account->isFreeHostedClient() || $this->client->country_id != 840) return; $tax_provider = new \App\Services\Tax\Providers\TaxProvider($this->company, $this->client); @@ -73,69 +73,6 @@ class UpdateTaxData implements ShouldQueue nlog("problem getting tax data => ".$e->getMessage()); } - /* - if(!$tax_provider->updatedTaxStatus() && $this->client->country_id == 840){ - - $calculated_state = false; - - if(array_key_exists($this->client->shipping_state, USStates::get())) { - $calculated_state = $this->client->shipping_state; - $calculated_postal_code = $this->client->shipping_postal_code; - $calculated_city = $this->client->shipping_city; - } - elseif(array_key_exists($this->client->state, USStates::get())){ - $calculated_state = $this->client->state; - $calculated_postal_code = $this->client->postal_code; - $calculated_city = $this->client->city; - } - else { - - try{ - $calculated_state = USStates::getState($this->client->shipping_postal_code); - $calculated_postal_code = $this->client->shipping_postal_code; - $calculated_city = $this->client->shipping_city; - } - catch(\Exception $e){ - nlog("could not calculate state from postal code => {$this->client->shipping_postal_code} or from state {$this->client->shipping_state}"); - } - - if(!$calculated_state) { - try { - $calculated_state = USStates::getState($this->client->postal_code); - $calculated_postal_code = $this->client->postal_code; - $calculated_city = $this->client->city; - } catch(\Exception $e) { - nlog("could not calculate state from postal code => {$this->client->postal_code} or from state {$this->client->state}"); - } - } - - if($this->company->tax_data?->seller_subregion) - $calculated_state = $this->company->tax_data?->seller_subregion; - - nlog("i am trying"); - - if(!$calculated_state) { - nlog("could not determine state"); - return; - } - - } - - $data = [ - 'seller_subregion' => $this->company->tax_data?->seller_subregion ?: '', - 'geoPostalCode' => $this->client->postal_code ?? '', - 'geoCity' => $this->client->city ?? '', - 'geoState' => $calculated_state, - 'taxSales' => $this->company->tax_data->regions->US->subregions?->{$calculated_state}?->taxSales ?? 0, - ]; - - $tax_data = new Response($data); - - $this->client->tax_data = $tax_data; - $this->client->saveQuietly(); - - } - */ } public function middleware() diff --git a/app/Services/Tax/Providers/TaxProvider.php b/app/Services/Tax/Providers/TaxProvider.php index 9598813b80f9..00b540bbc0a4 100644 --- a/app/Services/Tax/Providers/TaxProvider.php +++ b/app/Services/Tax/Providers/TaxProvider.php @@ -225,6 +225,8 @@ class TaxProvider */ private function configureEuTax(): self { + throw new \Exception("No tax region defined for this country"); + $this->provider = EuTax::class; return $this; From 574c800c2ea3eb52876258e3443cd1bb7e67f5fb Mon Sep 17 00:00:00 2001 From: David Bomba Date: Fri, 20 Oct 2023 07:46:45 +1100 Subject: [PATCH 2/2] v5.7.33 --- VERSION.txt | 2 +- app/Helpers/Epc/EpcQrGenerator.php | 14 ++++++++------ app/Http/Controllers/PreviewController.php | 9 +++++---- config/ninja.php | 4 ++-- 4 files changed, 16 insertions(+), 13 deletions(-) diff --git a/VERSION.txt b/VERSION.txt index 5a3ee7ad5530..71c2c6e276ca 100644 --- a/VERSION.txt +++ b/VERSION.txt @@ -1 +1 @@ -5.7.32 \ No newline at end of file +5.7.33 \ No newline at end of file diff --git a/app/Helpers/Epc/EpcQrGenerator.php b/app/Helpers/Epc/EpcQrGenerator.php index 342c5f775f06..965e2dad1f13 100644 --- a/app/Helpers/Epc/EpcQrGenerator.php +++ b/app/Helpers/Epc/EpcQrGenerator.php @@ -15,6 +15,7 @@ use App\Models\Company; use App\Models\Invoice; use App\Models\RecurringInvoice; use App\Utils\Ninja; +use BaconQrCode\Exception\InvalidArgumentException; use BaconQrCode\Renderer\Image\SvgImageBackEnd; use BaconQrCode\Renderer\ImageRenderer; use BaconQrCode\Renderer\RendererStyle\RendererStyle; @@ -50,8 +51,7 @@ class EpcQrGenerator ); $writer = new Writer($renderer); - if($this->validateFields()) - return ''; + $this->validateFields(); $qr = $writer->writeString($this->encodeMessage(), 'utf-8'); @@ -59,10 +59,15 @@ class EpcQrGenerator {$qr}"; } catch(\Throwable $e) { + nlog("EPC QR failure => ".$e->getMessage()); return ''; } catch(\Exception $e) { + nlog("EPC QR failure => ".$e->getMessage()); return ''; - } + } catch( InvalidArgumentException $e) { + nlog("EPC QR failure => ".$e->getMessage()); + return ''; + } } @@ -88,16 +93,13 @@ class EpcQrGenerator private function validateFields() { if (Ninja::isSelfHost() && isset($this->company?->custom_fields?->company2)) { - return true; nlog('The BIC field is not present and _may_ be a required fields for EPC QR codes'); } if (Ninja::isSelfHost() && isset($this->company?->custom_fields?->company1)) { - return true; nlog('The IBAN field is required'); } - return false; } private function formatMoney($value) diff --git a/app/Http/Controllers/PreviewController.php b/app/Http/Controllers/PreviewController.php index ad68dd371c70..8b5d499d8de8 100644 --- a/app/Http/Controllers/PreviewController.php +++ b/app/Http/Controllers/PreviewController.php @@ -111,11 +111,12 @@ class PreviewController extends BaseController $html->settings = $settings; $variables = $html->generateLabelsAndValues(); - $design = \App\Models\Design::withTrashed()->find($entity_obj->design_id ?? 2); + + $design = \App\Models\Design::query()->withTrashed()->find($entity_obj->design_id ?? 2); /* Catch all in case migration doesn't pass back a valid design */ if (! $design) { - $design = \App\Models\Design::find(2); + $design = \App\Models\Design::query()->find(2); } if ($design->is_custom) { @@ -329,8 +330,8 @@ class PreviewController extends BaseController /** * @deprecated due to usage of transactions * - * @param mixed $request - * @return void + * @param PreviewInvoiceRequest $request + * @return mixed */ public function livex(PreviewInvoiceRequest $request) { diff --git a/config/ninja.php b/config/ninja.php index 56b9f06de32f..d5f584da4e29 100644 --- a/config/ninja.php +++ b/config/ninja.php @@ -15,8 +15,8 @@ return [ 'require_https' => env('REQUIRE_HTTPS', true), 'app_url' => rtrim(env('APP_URL', ''), '/'), 'app_domain' => env('APP_DOMAIN', 'invoicing.co'), - 'app_version' => env('APP_VERSION','5.7.32'), - 'app_tag' => env('APP_TAG','5.7.32'), + 'app_version' => env('APP_VERSION','5.7.33'), + 'app_tag' => env('APP_TAG','5.7.33'), 'minimum_client_version' => '5.0.16', 'terms_version' => '1.0.1', 'api_secret' => env('API_SECRET', ''),