Add tax entity to licenses table

This commit is contained in:
David Bomba 2024-11-19 15:56:15 +11:00
parent 26b956768f
commit 2bf1afa2c4
11 changed files with 155 additions and 28 deletions

View File

@ -0,0 +1,43 @@
<?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\Casts;
use Illuminate\Contracts\Database\Eloquent\CastsAttributes;
use App\DataMapper\EInvoice\TaxEntity;
class AsTaxEntityCollection implements CastsAttributes
{
public function get($model, string $key, $value, array $attributes)
{
if (!$value || (is_string($value) && $value =="null")) {
return [];
}
$items = json_decode($value, true);
return array_map(fn ($item) => new TaxEntity($item), $items);
}
public function set($model, string $key, $value, array $attributes)
{
if (!$value) {
return '[]';
}
if ($value instanceof TaxEntity) {
$value = [$value];
}
return json_encode(array_map(fn ($entity) => get_object_vars($entity), $value));
}
}

View File

@ -0,0 +1,58 @@
<?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\DataMapper\EInvoice;
class TaxEntity
{
/** @var string $version */
public string $version = 'alpha';
public ?int $legal_entity_id = null;
public string $company_key = '';
/** @var array<mixed> */
public array $received_documents = [];
/**
* __construct
*
* @param mixed $entity
*/
public function __construct(mixed $entity = null)
{
if (!$entity) {
$this->init();
return $this;
}
$entityArray = is_object($entity) ? get_object_vars($entity) : $entity;
// $entityArray = get_object_vars($entity);
foreach ($entityArray as $key => $value) {
$this->{$key} = $value;
}
$this->migrate();
}
public function init(): self
{
return $this;
}
private function migrate(): self
{
return $this;
}
}

View File

@ -22,11 +22,11 @@ class TaxModel
/** @var object $regions */
public object $regions;
/** @var bool $act_as_sender */
public bool $act_as_sender = false;
/** @var bool $acts_as_sender */
public bool $acts_as_sender = false;
/** @var bool $act_as_receiver */
public bool $act_as_receiver = false;
/** @var bool $acts_as_receiver */
public bool $acts_as_receiver = false;
/**
* __construct
@ -42,8 +42,8 @@ class TaxModel
} else {
$this->seller_subregion = $model->seller_subregion ?? '';
$this->act_as_sender = $model->act_as_sender ?? false;
$this->act_as_receiver = $model->act_as_receiver ?? false;
$this->acts_as_sender = $model->acts_as_sender ?? false;
$this->acts_as_receiver = $model->acts_as_receiver ?? false;
$modelArray = get_object_vars($model);
foreach ($modelArray as $key => $value) {

View File

@ -17,7 +17,7 @@ use App\Http\Requests\EInvoice\UpdateTokenRequest;
use Illuminate\Http\Response;
use Illuminate\Support\Facades\Http;
class EInvoiceTokenController extends BaseController
class EInvoiceTokenController extends BaseController //@ben - can we remove this?
{
public function __invoke(UpdateTokenRequest $request): Response
{

View File

@ -65,8 +65,8 @@ class CompanyTaxRate implements ShouldQueue
nlog("could not calculate state from postal code => {$this->company->settings->postal_code} or from state {$this->company->settings->state}");
}
if(!$calculated_state && $this->company->tax_data?->seller_subregion) {
$calculated_state = $this->company->tax_data?->seller_subregion;
if(!$calculated_state && $this->company->tax_data?->seller_subregion) { //@phpstan-ignore-line
$calculated_state = $this->company->tax_data->seller_subregion;
}
if(!$calculated_state) {

View File

@ -61,10 +61,10 @@ class SendToAdmin implements ShouldQueue
$files = [];
$files[] = ['file' => $csv, 'file_name' => "{$this->file_name}", 'mime' => 'text/csv'];
if(in_array(get_class($export), [ARDetailReport::class, ARSummaryReport::class])) {
$pdf = base64_encode($export->getPdf());
$files[] = ['file' => $pdf, 'file_name' => str_replace(".csv", ".pdf", $this->file_name), 'mime' => 'application/pdf'];
}
// if(in_array(get_class($export), [ARDetailReport::class, ARSummaryReport::class])) {
// $pdf = base64_encode($export->getPdf());
// $files[] = ['file' => $pdf, 'file_name' => str_replace(".csv", ".pdf", $this->file_name), 'mime' => 'application/pdf'];
// }
$user = $this->company->owner();

View File

@ -228,7 +228,7 @@ use Laracasts\Presenter\PresentableTrait;
* @method static \Illuminate\Database\Eloquent\Builder|Company find($query)
* @property-read int|null $webhooks_count
* @property int $calculate_taxes
* @property mixed $tax_data
* @property \App\DataMapper\Tax\TaxModel $tax_data
* @method \App\Models\User|null owner()
* @mixin \Eloquent
*/

View File

@ -11,7 +11,9 @@
namespace App\Models;
use App\Casts\AsTaxEntityCollection;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Database\Eloquent\Casts\AsArrayObject;
/**
* App\Models\License
@ -30,6 +32,7 @@ use Illuminate\Database\Eloquent\SoftDeletes;
* @property int|null $recurring_invoice_id
* @property int|null $e_invoice_quota
* @property bool $is_flagged
* @property object|null $entities
* @property-read \App\Models\RecurringInvoice $recurring_invoice
* @method static \Illuminate\Database\Eloquent\Builder|StaticModel company()
* @method static \Illuminate\Database\Eloquent\Builder|StaticModel exclude($columns)
@ -59,6 +62,7 @@ class License extends StaticModel
protected $casts = [
'created_at' => 'date',
'entities' => AsTaxEntityCollection::class,
];
public function expiry(): string
@ -80,4 +84,5 @@ class License extends StaticModel
{
return $this->hasMany(EInvoicingToken::class, 'license_key', 'license_key');
}
}

View File

@ -232,21 +232,9 @@ class Storecove
/**
* Get Sending Evidence
*
*
* "guid" => "661c079d-0c2b-4b45-8263-678ed81224af",
"sender" => "9930:DE923356489",
"receiver" => "9930:DE321281763",
"documents" => [
[
"mime_type" => "application/xml",
"document" => "html URL to fileg",
"expires_at" => "2024-11-17 21:46:47+00:00",
],
],
"evidence" => [
"receiving_accesspoint" => "CN=PNL000151, OU=PEPPOL TEST AP, O=Storecove (Datajust B.V.), C=NL",
*
* @param string $guid
* @return mixed
*/

View File

@ -162,7 +162,15 @@ class SendEDocument implements ShouldQueue
// Successful send - update quota!
if(is_string($r)){
$model->company->account->decrement('e_invoice_quota', 1);
$account = $model->company->account;
$account->decrement('e_invoice_quota', 1);
$account->refresh();
if($account->e_invoice_quota == 0 && class_exists(\Modules\Admin\Jobs\Account\SuspendESendReceive::class)){
\Modules\Admin\Jobs\Account\SuspendESendReceive::dispatch($account->key);
}
return $this->writeActivity($model, $r);
}

View File

@ -0,0 +1,25 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('licenses', function (Blueprint $table) {
$table->text('entities')->nullable();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
}
};