--wip-- [skip ci]

This commit is contained in:
philipp lang 2025-03-30 04:06:32 +02:00
parent 9a5d9ae30e
commit 2e77823c3a
6 changed files with 121 additions and 2 deletions

View File

@ -22,7 +22,6 @@ class InsertMemberAction
{
$region = Region::firstWhere('nami_id', $member->regionId ?: -1);
$payload = [
'firstname' => $member->firstname,
'lastname' => $member->lastname,
@ -61,7 +60,17 @@ class InsertMemberAction
}
}
return Member::updateOrCreate(['nami_id' => $member->id], $payload);
return tap(Member::updateOrCreate(['nami_id' => $member->id], $payload), function ($insertedMember) use ($member) {
$insertedMember->bankAccount()->updateOrCreate([
'iban' => $member->bankAccount->iban,
'bic' => $member->bankAccount->bic,
'blz' => $member->bankAccount->blz,
'account_number' => $member->bankAccount->accountNumber,
'person' => $member->bankAccount->person,
'bank_name' => $member->bankAccount->bankName,
'nami_id' => $member->bankAccount->id,
]);
});
}
public function getSubscription(NamiMember $member): ?Subscription

View File

@ -0,0 +1,14 @@
<?php
namespace App\Member;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class BankAccount extends Model
{
/** @use HasFactory<\Database\Factories\\App\Member\BankAccountFactory> */
use HasFactory;
public $guarded = [];
}

View File

@ -34,6 +34,7 @@ use Zoomyboy\Osm\HasGeolocation;
use Zoomyboy\Phone\HasPhoneNumbers;
use App\Prevention\Enums\Prevention;
use Database\Factories\Member\MemberFactory;
use Illuminate\Database\Eloquent\Relations\HasOne;
/**
* @property string $subscription_name
@ -293,6 +294,14 @@ class Member extends Model implements Geolocatable
return $this->memberships()->isAgeGroup()->active();
}
/**
* @return HasOne<BankAccount>
*/
public function bankAccount(): HasOne
{
return $this->hasOne(BankAccount::class);
}
public static function booted()
{
static::deleting(function (self $model): void {

View File

@ -0,0 +1,33 @@
<?php
namespace Database\Factories;
use App\Member\BankAccount;
use Illuminate\Database\Eloquent\Factories\Factory;
/**
* @template TModel of \App\Member\BankAccount
*
* @extends \Illuminate\Database\Eloquent\Factories\Factory<TModel>
*/
class BankAccountFactory extends Factory
{
/**
* The name of the factory's corresponding model.
*
* @var class-string<TModel>
*/
protected $model = BankAccount::class;
/**
* Define the model's default state.
*
* @return array<string, mixed>
*/
public function definition(): array
{
return [
//
];
}
}

View File

@ -0,0 +1,34 @@
<?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::create('bank_accounts', function (Blueprint $table) {
$table->unsignedBigInteger('member_id')->primary();
$table->unsignedBigInteger('nami_id')->nullable();
$table->string('iban')->nullable();
$table->string('bic')->nullable();
$table->string('blz')->nullable();
$table->string('bank_name')->nullable();
$table->string('person')->nullable();
$table->string('account_number')->nullable();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('bank_accounts');
}
};

View File

@ -88,6 +88,26 @@ it('testFetchWiederverwendenFlag', function (array $memberAttributes, array $sto
[['regionId' => 999], ['region_id' => null]]
]);
it('testFetchesKontoverbindung', function (array $memberAttributes, array $storedAttributes) {
$this->loginNami();
Region::factory()->inNami(999)->name('nicht-de')->create(['is_null' => true]);
app(MemberFake::class)->shows(1000, 1001, $memberAttributes);
app(PullMemberAction::class)->handle(1000, 1001);
$this->assertDatabaseHas('bank_accounts', [
'member_id' => Member::first()->id,
...$storedAttributes
]);
})->with([
[['kontoverbindung' => ['iban' => '3300', 'bic' => 'SOLSDE']], ['iban' => '3300', 'bic' => 'SOLSDE']],
[['kontoverbindung' => ['id' => 33003]], ['nami_id' => 33003]],
[['kontoverbindung' => ['blz' => 111]], ['blz' => 111]],
[['kontoverbindung' => ['institut' => 'Sparkasse']], ['bank_name' => 'Sparkasse']],
[['kontoverbindung' => ['kontoinhaber' => 'Max']], ['person' => 'Max']],
[['kontoverbindung' => ['kontonummer' => '333']], ['account_number' => '333']],
]);
it('testItSetsFirstSubscriptionFromFee', function () {
$this->loginNami();
Region::factory()->inNami(999)->name('nicht-de')->create(['is_null' => true]);