diff --git a/app/Livewire/EInvoice/Portal.php b/app/Livewire/EInvoice/Portal.php index 2853db0418f9..8756168029ab 100644 --- a/app/Livewire/EInvoice/Portal.php +++ b/app/Livewire/EInvoice/Portal.php @@ -14,6 +14,7 @@ namespace App\Livewire\EInvoice; use Livewire\Component; use Illuminate\Support\Facades\App; use Illuminate\Support\Facades\Auth; +use Illuminate\Support\Facades\Http; class Portal extends Component { @@ -25,10 +26,17 @@ class Portal extends Component // private string $api_url = 'https://invoicing.co' private string $api_url = 'http://ninja.test:8000'; - + public function mount() { + $this->getCompanies(); + + } + + private function getCompanies(): self + { + $this->companies = auth()->guard('user')->check() ? auth()->guard('user')->user()->account->companies->map(function ($company) { return [ 'key' => $company->company_key, @@ -37,13 +45,18 @@ class Portal extends Component 'county' => $company->settings->state, 'line1' => $company->settings->address1, 'line2' => $company->settings->address2, - 'name' => $company->settings->name, + 'party_name' => $company->settings->name, 'vat_number' => $company->settings->vat_number, 'zip' => $company->settings->postal_code, - 'legal_entity_id' => $company->legal_entity_id + 'legal_entity_id' => $company->legal_entity_id, + 'tax_registered' => (bool) strlen($company->settings->vat_number ?? '') > 2, + 'tenant_id' => $company->company_key, + 'classification' => strlen($company->settings->classification ?? '') > 2 ? $company->settings->classification : 'business', ]; })->toArray() : []; + return $this; + } public function login() @@ -55,23 +68,7 @@ class Portal extends Component App::setLocale(auth()->guard('user')->user()->account->companies->first()->getLocale()); - $this->companies = auth()->guard('user')->check() ? auth()->guard('user')->user()->account->companies->map(function ($company) { - return [ - 'key' => $company->company_key, - 'city' => $company->settings->city, - 'country' => $company->country()->iso_3166_2, - 'county' => $company->settings->state, - 'line1' => $company->settings->address1, - 'line2' => $company->settings->address2, - 'party_name' => $company->settings->name, - 'vat_number' => $company->settings->vat_number, - 'zip' => $company->settings->postal_code, - 'legal_entity_id' => $company->legal_entity_id, - 'tax_registered' => (bool) strlen($company->settings->vat_number ?? '') > 2, - 'tenant_id' => $company->company_key, - 'classification' => strlen($company->settings->classification ?? '') > 2 ? $company->settings->classification : 'business', - ]; - })->toArray() : []; + $this->getCOmpanies(); } else { @@ -102,19 +99,31 @@ class Portal extends Component $register_company = array_merge($company, $register_company); } + nlog("{$this->api_url}/api/einvoice/createLegalEntity"); + nlog($register_company); + $r = Http::withHeaders($this->getHeaders()) - ->post("{$api_url}/api/einvoice/createLegalEntity", $register_company); + ->post("{$this->api_url}/api/einvoice/createLegalEntity", $register_company); if($r->successful()) { + nlog($r->json()); + nlog($r->body()); $response = $r->json(); - $_company = auth()->guard('user')->user()->account->companies()->where('company_id', $company_key)->first(); + $_company = auth()->guard('user')->user()->account->companies()->where('company_key', $company_key)->first(); $_company->legal_entity_id = $response['id']; $_company->save(); + + $this->getCompanies(); + return; } + if($r->failed()) + nlog($r->getBody()->getContents()); + + $error = json_decode($r->getBody()->getContents(),true); session()->flash('error', $error['message']); @@ -125,6 +134,8 @@ class Portal extends Component { return [ 'X-API-SELF-HOST-TOKEN' => config('ninja.license_key'), + "X-Requested-With" => "XMLHttpRequest", + "Content-Type" => "application/json", ]; } diff --git a/app/Services/EDocument/Gateway/Storecove/Storecove.php b/app/Services/EDocument/Gateway/Storecove/Storecove.php index 0c35dacf55ec..b1734df5f11d 100644 --- a/app/Services/EDocument/Gateway/Storecove/Storecove.php +++ b/app/Services/EDocument/Gateway/Storecove/Storecove.php @@ -302,9 +302,7 @@ class Storecove if($r->successful()) { $data = $r->json(); - - LightLogs::create(new LegalEntityCreated($data['id'], $legal_entity_id))->batch(); - + return $data; }