mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
self host einvoicing
This commit is contained in:
parent
3ad93ac8aa
commit
17602f5fcd
@ -14,6 +14,7 @@ namespace App\Livewire\EInvoice;
|
|||||||
use Livewire\Component;
|
use Livewire\Component;
|
||||||
use Illuminate\Support\Facades\App;
|
use Illuminate\Support\Facades\App;
|
||||||
use Illuminate\Support\Facades\Auth;
|
use Illuminate\Support\Facades\Auth;
|
||||||
|
use Illuminate\Support\Facades\Http;
|
||||||
|
|
||||||
class Portal extends Component
|
class Portal extends Component
|
||||||
{
|
{
|
||||||
@ -25,10 +26,17 @@ class Portal extends Component
|
|||||||
// private string $api_url = 'https://invoicing.co'
|
// private string $api_url = 'https://invoicing.co'
|
||||||
|
|
||||||
private string $api_url = 'http://ninja.test:8000';
|
private string $api_url = 'http://ninja.test:8000';
|
||||||
|
|
||||||
public function mount()
|
public function mount()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
$this->getCompanies();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private function getCompanies(): self
|
||||||
|
{
|
||||||
|
|
||||||
$this->companies = auth()->guard('user')->check() ? auth()->guard('user')->user()->account->companies->map(function ($company) {
|
$this->companies = auth()->guard('user')->check() ? auth()->guard('user')->user()->account->companies->map(function ($company) {
|
||||||
return [
|
return [
|
||||||
'key' => $company->company_key,
|
'key' => $company->company_key,
|
||||||
@ -37,13 +45,18 @@ class Portal extends Component
|
|||||||
'county' => $company->settings->state,
|
'county' => $company->settings->state,
|
||||||
'line1' => $company->settings->address1,
|
'line1' => $company->settings->address1,
|
||||||
'line2' => $company->settings->address2,
|
'line2' => $company->settings->address2,
|
||||||
'name' => $company->settings->name,
|
'party_name' => $company->settings->name,
|
||||||
'vat_number' => $company->settings->vat_number,
|
'vat_number' => $company->settings->vat_number,
|
||||||
'zip' => $company->settings->postal_code,
|
'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() : [];
|
})->toArray() : [];
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function login()
|
public function login()
|
||||||
@ -55,23 +68,7 @@ class Portal extends Component
|
|||||||
|
|
||||||
App::setLocale(auth()->guard('user')->user()->account->companies->first()->getLocale());
|
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) {
|
$this->getCOmpanies();
|
||||||
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() : [];
|
|
||||||
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
@ -102,19 +99,31 @@ class Portal extends Component
|
|||||||
$register_company = array_merge($company, $register_company);
|
$register_company = array_merge($company, $register_company);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
nlog("{$this->api_url}/api/einvoice/createLegalEntity");
|
||||||
|
nlog($register_company);
|
||||||
|
|
||||||
$r = Http::withHeaders($this->getHeaders())
|
$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())
|
if($r->successful())
|
||||||
{
|
{
|
||||||
|
nlog($r->json());
|
||||||
|
nlog($r->body());
|
||||||
$response = $r->json();
|
$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->legal_entity_id = $response['id'];
|
||||||
$_company->save();
|
$_company->save();
|
||||||
|
|
||||||
|
$this->getCompanies();
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if($r->failed())
|
||||||
|
nlog($r->getBody()->getContents());
|
||||||
|
|
||||||
|
|
||||||
$error = json_decode($r->getBody()->getContents(),true);
|
$error = json_decode($r->getBody()->getContents(),true);
|
||||||
|
|
||||||
session()->flash('error', $error['message']);
|
session()->flash('error', $error['message']);
|
||||||
@ -125,6 +134,8 @@ class Portal extends Component
|
|||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'X-API-SELF-HOST-TOKEN' => config('ninja.license_key'),
|
'X-API-SELF-HOST-TOKEN' => config('ninja.license_key'),
|
||||||
|
"X-Requested-With" => "XMLHttpRequest",
|
||||||
|
"Content-Type" => "application/json",
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -302,9 +302,7 @@ class Storecove
|
|||||||
|
|
||||||
if($r->successful()) {
|
if($r->successful()) {
|
||||||
$data = $r->json();
|
$data = $r->json();
|
||||||
|
|
||||||
LightLogs::create(new LegalEntityCreated($data['id'], $legal_entity_id))->batch();
|
|
||||||
|
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user