forked from invoiceninja/invoiceninja
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Additional routes for legal entities
- Loading branch information
Showing
6 changed files
with
327 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,9 +17,63 @@ | |
use App\Http\Requests\EInvoice\Peppol\DisconnectRequest; | ||
use App\Http\Requests\EInvoice\Peppol\AddTaxIdentifierRequest; | ||
use App\Http\Requests\EInvoice\Peppol\ShowEntityRequest; | ||
use App\Http\Requests\EInvoice\Peppol\UpdateEntityRequest; | ||
|
||
class EInvoicePeppolController extends BaseController | ||
{ | ||
{ | ||
/** | ||
* Returns the legal entity ID | ||
* | ||
* | ||
* [ | ||
* "id" => 290868, | ||
* "party_name" => "Untitled Company", | ||
* "line1" => "Address 1", | ||
* "line2" => "Address 2", | ||
* "zip" => "Postal Code", | ||
* "city" => "City", | ||
* "county" => "State", | ||
* "country" => "DE", | ||
* "tenant_id" => "EbRYYRWO7oUJE3G3jVa4Xddf6gHGI6kD", | ||
* "public" => true, | ||
* "acts_as_sender" => true, | ||
* "acts_as_receiver" => true, | ||
* "tax_registered" => true, | ||
* "peppol_identifiers" => [ | ||
* [ | ||
* "superscheme" => "iso6523-actorid-upis", | ||
* "scheme" => "DE:VAT", | ||
* "identifier" => "DE923356489", | ||
* "networks" => [ | ||
* "peppol", | ||
* ], | ||
* "corppass_enabled" => false, | ||
* ], | ||
* ], | ||
* "administrations" => [], | ||
* "advertisements" => [ | ||
* "invoice", | ||
* ], | ||
* "smart_inbox" => "[email protected]", | ||
* "api_keys" => [], | ||
* "additional_tax_identifiers" => [ | ||
* [ | ||
* "id" => 264566, | ||
* "legal_entity_id" => 290868, | ||
* "country" => null, | ||
* "county" => null, | ||
* "identifier" => "ATU73769157", | ||
* "superscheme" => "iso6523-actorid-upis", | ||
* "scheme" => "AT:VAT", | ||
* ], | ||
* ], | ||
* ] | ||
* | ||
* | ||
* @param ShowEntityRequest $request | ||
* @param Storecove $storecove | ||
* @return mixed | ||
*/ | ||
public function show(ShowEntityRequest $request, Storecove $storecove) | ||
{ | ||
$company = auth()->user()->company(); | ||
|
@@ -30,9 +84,10 @@ public function show(ShowEntityRequest $request, Storecove $storecove) | |
} | ||
|
||
/** | ||
* Create a legal entity id | ||
* Create a legal entity id, response will be | ||
* the same as show() | ||
* | ||
* @param CreateRequest $request | ||
* @param StoreEntityRequest $request | ||
* @param Storecove $storecove | ||
* @return Response | ||
*/ | ||
|
@@ -68,6 +123,8 @@ public function setup(StoreEntityRequest $request, Storecove $storecove): Respon | |
/** | ||
* Add an additional tax identifier to | ||
* an existing legal entity id | ||
* | ||
* Response will be the same as show() | ||
* | ||
* @param AddTaxIdentifierRequest $request | ||
* @param Storecove $storecove | ||
|
@@ -95,12 +152,29 @@ public function addAdditionalTaxIdentifier(AddTaxIdentifierRequest $request, Sto | |
|
||
return response()->json(['message' => 'ok'], 200); | ||
|
||
} | ||
|
||
public function updateLegalEntity(UpdateEntityRequest $request, Storecove $storecove) | ||
{ | ||
|
||
$company = auth()->user()->company(); | ||
|
||
$r = $storecove->updateLegalEntity($company->legal_entity_id, $request->validated()); | ||
|
||
|
||
} | ||
|
||
public function disconnect(DisconnectRequest $request, Storecove $storecove): Response | ||
/** | ||
* Removed the legal identity from the Peppol network | ||
* | ||
* @param DisconnectRequest $request | ||
* @param Storecove $storecove | ||
* @return \Illuminate\Http\Response | ||
*/ | ||
public function disconnect(DisconnectRequest $request, Storecove $storecove): \Illuminate\Http\Response | ||
{ | ||
/** | ||
* @var \App\Models\Company | ||
* @var \App\Models\Company $company | ||
*/ | ||
$company = auth()->user()->company(); | ||
|
||
|
@@ -110,6 +184,7 @@ public function disconnect(DisconnectRequest $request, Storecove $storecove): Re | |
|
||
if ($response) { | ||
$company->legal_entity_id = null; | ||
$company->tax_data = $this->unsetVatNumbers($company->tax_data); | ||
$company->save(); | ||
|
||
return response()->noContent(); | ||
|
@@ -120,4 +195,26 @@ public function disconnect(DisconnectRequest $request, Storecove $storecove): Re | |
|
||
return response()->noContent(status: 422); | ||
} | ||
|
||
private function unsetVatNumbers(mixed $taxData): mixed | ||
{ | ||
if (isset($taxData->regions->EU->subregions)) { | ||
foreach ($taxData->regions->EU->subregions as $country => $data) { | ||
if (isset($data->vat_number)) { | ||
$newData = new \stdClass(); | ||
if (is_object($data)) { | ||
$dataArray = get_object_vars($data); | ||
foreach ($dataArray as $key => $value) { | ||
if ($key !== 'vat_number') { | ||
$newData->$key = $value; | ||
} | ||
} | ||
} | ||
$taxData->regions->EU->subregions->$country = $newData; | ||
} | ||
} | ||
} | ||
|
||
return $taxData; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php | ||
|
||
/** | ||
* Invoice Ninja (https://invoiceninja.com). | ||
* | ||
* @link https://github.com/invoiceninja/invoiceninja source repository | ||
* | ||
* @copyright Copyright (c) 2024. Invoice Ninja LLC (https://invoiceninja.com) | ||
* | ||
* @license https://www.elastic.co/licensing/elastic-license | ||
*/ | ||
|
||
namespace App\Http\Requests\EInvoice\Peppol; | ||
|
||
use App\Models\Country; | ||
use Illuminate\Auth\Access\AuthorizationException; | ||
use Illuminate\Foundation\Http\FormRequest; | ||
use Illuminate\Validation\Rule; | ||
|
||
class UpdateEntityRequest extends FormRequest | ||
{ | ||
|
||
public function authorize(): bool | ||
{ | ||
/** | ||
* @var \App\Models\User | ||
*/ | ||
$user = auth()->user(); | ||
|
||
if (app()->isLocal()) { | ||
return true; | ||
} | ||
|
||
return $user->account->isPaid() && $user->isAdmin() && | ||
$user->company()->legal_entity_id != null; | ||
} | ||
|
||
/** | ||
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string> | ||
*/ | ||
public function rules(): array | ||
{ | ||
return [ | ||
'acts_as_receiver' => ['required', 'bool'], | ||
'acts_as_sender' => ['required', 'bool'], | ||
]; | ||
} | ||
|
||
public function prepareForValidation() | ||
{ | ||
$input = $this->all(); | ||
|
||
$this->replace($input); | ||
} | ||
} |
Oops, something went wrong.