mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-06-04 01:34:35 -04:00
migrations for tax models
This commit is contained in:
parent
25c91d608f
commit
e07e327790
@ -17,7 +17,7 @@ class TaxModel
|
|||||||
public string $seller_subregion = 'CA';
|
public string $seller_subregion = 'CA';
|
||||||
|
|
||||||
/** @var string $version */
|
/** @var string $version */
|
||||||
public string $version = 'alpha';
|
public string $version = 'beta';
|
||||||
|
|
||||||
/** @var object $regions */
|
/** @var object $regions */
|
||||||
public object $regions;
|
public object $regions;
|
||||||
@ -28,15 +28,38 @@ class TaxModel
|
|||||||
* @param TaxModel $model
|
* @param TaxModel $model
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function __construct(public ?TaxModel $model = null)
|
public function __construct(public mixed $model = null)
|
||||||
{
|
{
|
||||||
|
|
||||||
if(!$this->model) {
|
if(!$model) {
|
||||||
$this->regions = $this->init();
|
$this->regions = $this->init();
|
||||||
} else {
|
} else {
|
||||||
$this->regions = $model;
|
|
||||||
|
//@phpstan-ignore-next-line
|
||||||
|
foreach($model as $key => $value) {
|
||||||
|
$this->{$key} = $value;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->migrate();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function migrate(): self
|
||||||
|
{
|
||||||
|
|
||||||
|
if($this->version == 'alpha')
|
||||||
|
{
|
||||||
|
$this->regions->EU->subregions->PL = new \stdClass();
|
||||||
|
$this->regions->EU->subregions->PL->tax_rate = 23;
|
||||||
|
$this->regions->EU->subregions->PL->tax_name = 'VAT';
|
||||||
|
$this->regions->EU->subregions->PL->reduced_tax_rate = 8;
|
||||||
|
$this->regions->EU->subregions->PL->apply_tax = false;
|
||||||
|
|
||||||
|
$this->version = 'beta';
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -0,0 +1,36 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use App\Models\Company;
|
||||||
|
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
|
||||||
|
{
|
||||||
|
Company::whereNotNull('tax_data')
|
||||||
|
->cursor()
|
||||||
|
->each(function($company){
|
||||||
|
|
||||||
|
if($company->tax_data?->version == 'alpha')
|
||||||
|
{
|
||||||
|
|
||||||
|
$company->update(['tax_data' => new \App\DataMapper\Tax\TaxModel($company->tax_data)]);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*/
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
|
};
|
Loading…
x
Reference in New Issue
Block a user