Create member
This commit is contained in:
parent
b24920f2e4
commit
28f847cd10
|
@ -15,7 +15,7 @@ class Activity extends Model
|
||||||
'nami_id' => 'integer'
|
'nami_id' => 'integer'
|
||||||
];
|
];
|
||||||
|
|
||||||
public function groups() {
|
public function subactivities() {
|
||||||
return $this->belongsToMany(Group::class);
|
return $this->belongsToMany(Subactivity::class);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,18 +2,13 @@
|
||||||
|
|
||||||
namespace App;
|
namespace App;
|
||||||
|
|
||||||
use Illuminate\Database\Eloquent\Model;
|
|
||||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
class Group extends Model
|
class Group extends Model
|
||||||
{
|
{
|
||||||
use HasFactory;
|
use HasFactory;
|
||||||
|
|
||||||
public $fillable = ['name', 'nami_id'];
|
public $fillable = ['nami_id', 'name'];
|
||||||
|
|
||||||
public $timestamps = false;
|
public $timestamps = false;
|
||||||
|
|
||||||
public function activities() {
|
|
||||||
return $this->belongsToMany(Activity::class);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,7 @@ class InitializeActivities {
|
||||||
|
|
||||||
$groups = [];
|
$groups = [];
|
||||||
$this->api->subactivitiesOf($activity->id)->each(function($group) use ($activity, &$groups) {
|
$this->api->subactivitiesOf($activity->id)->each(function($group) use ($activity, &$groups) {
|
||||||
$group = \App\Group::updateOrCreate(['nami_id' => $group->id], ['nami_id' => $group->id, 'name' => $group->name]);
|
$group = \App\Subactivity::updateOrCreate(['nami_id' => $group->id], ['nami_id' => $group->id, 'name' => $group->name]);
|
||||||
$groups[] = $group->id;
|
$groups[] = $group->id;
|
||||||
});
|
});
|
||||||
$activity->groups()->sync($groups);
|
$activity->groups()->sync($groups);
|
||||||
|
|
|
@ -10,6 +10,7 @@ use App\Region;
|
||||||
use App\Nationality;
|
use App\Nationality;
|
||||||
use App\Fee;
|
use App\Fee;
|
||||||
use App\Group;
|
use App\Group;
|
||||||
|
use App\Activity;
|
||||||
|
|
||||||
class InitializeMembers {
|
class InitializeMembers {
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,73 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Member;
|
||||||
|
|
||||||
|
use Illuminate\Bus\Queueable;
|
||||||
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||||
|
use Illuminate\Foundation\Bus\Dispatchable;
|
||||||
|
use Illuminate\Queue\InteractsWithQueue;
|
||||||
|
use Illuminate\Queue\SerializesModels;
|
||||||
|
use Zoomyboy\LaravelNami\Nami;
|
||||||
|
use App\Confession;
|
||||||
|
|
||||||
|
class CreateJob implements ShouldQueue
|
||||||
|
{
|
||||||
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||||
|
|
||||||
|
public $memberId;
|
||||||
|
public $member;
|
||||||
|
public $user;
|
||||||
|
|
||||||
|
public function __construct(Member $member, $user)
|
||||||
|
{
|
||||||
|
$this->memberId = $member->id;
|
||||||
|
$this->user = $user;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Execute the job.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function handle()
|
||||||
|
{
|
||||||
|
$this->member = Member::find($this->memberId);
|
||||||
|
|
||||||
|
if ($this->member->hasNami) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$response = Nami::login($this->user->mglnr)->putMember([
|
||||||
|
'firstname' => $this->member->firstname,
|
||||||
|
'lastname' => $this->member->lastname,
|
||||||
|
'nickname' => $this->member->nickname,
|
||||||
|
'joined_at' => $this->member->joined_at,
|
||||||
|
'birthday' => $this->member->birthday,
|
||||||
|
'send_newspaper' => $this->member->send_newspaper,
|
||||||
|
'address' => $this->member->address,
|
||||||
|
'zip' => $this->member->zip,
|
||||||
|
'location' => $this->member->location,
|
||||||
|
'nickname' => $this->member->nickname,
|
||||||
|
'other_country' => $this->member->other_country,
|
||||||
|
'further_address' => $this->member->further_address,
|
||||||
|
'main_phone' => $this->member->main_phone,
|
||||||
|
'mobile_phone' => $this->member->mobile_phone,
|
||||||
|
'work_phone' => $this->member->work_phone,
|
||||||
|
'fax' => $this->member->fax,
|
||||||
|
'email' => $this->member->email,
|
||||||
|
'email_parents' => $this->member->email_parents,
|
||||||
|
'gender_id' => optional($this->member->gender)->nami_id,
|
||||||
|
'confession_id' => $this->member->confession ? $this->member->confession->nami_id : Confession::firstWhere('is_null', true)->id,
|
||||||
|
'region_id' => optional($this->member->region)->nami_id,
|
||||||
|
'country_id' => $this->member->country->nami_id,
|
||||||
|
'fee_id' => optional($this->member->fee)->nami_id,
|
||||||
|
'nationality_id' => $this->member->nationality->nami_id,
|
||||||
|
'group_id' => $this->member->group->nami_id,
|
||||||
|
'first_activity_id' => $this->member->firstActivity->nami_id,
|
||||||
|
'first_subactivity_id' => $this->member->firstSubactivity->nami_id,
|
||||||
|
]);
|
||||||
|
Member::withoutEvents(function() use ($response) {
|
||||||
|
$this->member->update(['version' => $response['version']]);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
|
@ -10,13 +10,15 @@ use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
use App\Nationality;
|
use App\Nationality;
|
||||||
use App\Fee;
|
use App\Fee;
|
||||||
use App\Group;
|
use App\Group;
|
||||||
|
use App\Activity;
|
||||||
|
use App\Subactivity;
|
||||||
|
|
||||||
class Member extends Model
|
class Member extends Model
|
||||||
{
|
{
|
||||||
use Notifiable;
|
use Notifiable;
|
||||||
use HasFactory;
|
use HasFactory;
|
||||||
|
|
||||||
public $fillable = ['firstname', 'lastname', 'nickname', 'other_country', 'birthday', 'joined_at', 'send_newspaper', 'address', 'further_address', 'zip', 'location', 'main_phone', 'mobile_phone', 'work_phone', 'fax', 'email', 'email_parents', 'nami_id', 'group_id', 'letter_address', 'country_id', 'way_id', 'nationality_id', 'fee_id', 'region_id', 'gender_id', 'confession_id', 'letter_address', 'bill_kind_id', 'version'];
|
public $fillable = ['firstname', 'lastname', 'nickname', 'other_country', 'birthday', 'joined_at', 'send_newspaper', 'address', 'further_address', 'zip', 'location', 'main_phone', 'mobile_phone', 'work_phone', 'fax', 'email', 'email_parents', 'nami_id', 'group_id', 'letter_address', 'country_id', 'way_id', 'nationality_id', 'fee_id', 'region_id', 'gender_id', 'confession_id', 'letter_address', 'bill_kind_id', 'version', 'first_subactivity_id', 'first_activity_id'];
|
||||||
|
|
||||||
public $dates = ['joined_at', 'birthday'];
|
public $dates = ['joined_at', 'birthday'];
|
||||||
|
|
||||||
|
@ -102,6 +104,14 @@ class Member extends Model
|
||||||
return $this->belongsTo(Group::class);
|
return $this->belongsTo(Group::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function firstActivity() {
|
||||||
|
return $this->belongsTo(Activity::class, 'first_activity_id');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function firstSubActivity() {
|
||||||
|
return $this->belongsTo(Subactivity::class, 'first_subactivity_id');
|
||||||
|
}
|
||||||
|
|
||||||
public static function booted() {
|
public static function booted() {
|
||||||
static::updating(function($model) {
|
static::updating(function($model) {
|
||||||
if ($model->nami_id === null) {
|
if ($model->nami_id === null) {
|
||||||
|
@ -110,7 +120,12 @@ class Member extends Model
|
||||||
});
|
});
|
||||||
|
|
||||||
static::updated(function($model) {
|
static::updated(function($model) {
|
||||||
|
if ($model->nami_id !== null && $model->getOriginal()['nami_id'] !== null) {
|
||||||
UpdateJob::dispatch($model, auth()->user());
|
UpdateJob::dispatch($model, auth()->user());
|
||||||
|
}
|
||||||
|
if ($model->nami_id !== null && $model->getOriginal()['nami_id'] === null) {
|
||||||
|
CreateJob::dispatch($model, auth()->user());
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,8 @@ use App\Country;
|
||||||
use App\Nationality;
|
use App\Nationality;
|
||||||
use App\Confession;
|
use App\Confession;
|
||||||
use App\Bill\BillKind;
|
use App\Bill\BillKind;
|
||||||
|
use App\Activity;
|
||||||
|
use App\Group;
|
||||||
|
|
||||||
class MemberController extends Controller
|
class MemberController extends Controller
|
||||||
{
|
{
|
||||||
|
@ -29,7 +31,13 @@ class MemberController extends Controller
|
||||||
session()->put('menu', 'member');
|
session()->put('menu', 'member');
|
||||||
session()->put('title', 'Mitglied erstellen');
|
session()->put('title', 'Mitglied erstellen');
|
||||||
|
|
||||||
|
$activities = Activity::with('subactivities')->get();
|
||||||
|
|
||||||
return \Inertia::render('member/Form', [
|
return \Inertia::render('member/Form', [
|
||||||
|
'activities' => $activities->pluck('name', 'id'),
|
||||||
|
'subactivities' => $activities->map(function($activity) {
|
||||||
|
return ['subactivities' => $activity->subactivities->pluck('name', 'id'), 'id' => $activity->id];
|
||||||
|
})->pluck('subactivities', 'id'),
|
||||||
'billKinds' => BillKind::get()->pluck('name', 'id'),
|
'billKinds' => BillKind::get()->pluck('name', 'id'),
|
||||||
'genders' => Gender::get()->pluck('name', 'id'),
|
'genders' => Gender::get()->pluck('name', 'id'),
|
||||||
'countries' => Country::get()->pluck('name', 'id'),
|
'countries' => Country::get()->pluck('name', 'id'),
|
||||||
|
|
|
@ -3,6 +3,8 @@
|
||||||
namespace App\Member;
|
namespace App\Member;
|
||||||
|
|
||||||
use Illuminate\Foundation\Http\FormRequest;
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
|
use Illuminate\Validation\Rule;
|
||||||
|
use App\Group;
|
||||||
|
|
||||||
class MemberRequest extends FormRequest
|
class MemberRequest extends FormRequest
|
||||||
{
|
{
|
||||||
|
@ -24,6 +26,8 @@ class MemberRequest extends FormRequest
|
||||||
public function rules()
|
public function rules()
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
|
'first_activity_id' => Rule::requiredIf(fn() => $this->method() == 'POST'),
|
||||||
|
'first_subactivity_id' => Rule::requiredIf(fn() => $this->method() == 'POST'),
|
||||||
'firstname' => 'required',
|
'firstname' => 'required',
|
||||||
'lastname' => 'required',
|
'lastname' => 'required',
|
||||||
'address' => 'required',
|
'address' => 'required',
|
||||||
|
@ -42,7 +46,8 @@ class MemberRequest extends FormRequest
|
||||||
}
|
}
|
||||||
|
|
||||||
public function persistCreate() {
|
public function persistCreate() {
|
||||||
Member::create($this->input());
|
$this->merge(['group_id' => Group::where('nami_id', auth()->user()->getNamiGroupId())->firstOrFail()->id]);
|
||||||
|
$m = Member::create($this->input());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function persistUpdate(Member $member) {
|
public function persistUpdate(Member $member) {
|
||||||
|
|
|
@ -0,0 +1,19 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
|
|
||||||
|
class Subactivity extends Model
|
||||||
|
{
|
||||||
|
use HasFactory;
|
||||||
|
|
||||||
|
public $fillable = ['name', 'nami_id'];
|
||||||
|
|
||||||
|
public $timestamps = false;
|
||||||
|
|
||||||
|
public function activities() {
|
||||||
|
return $this->belongsToMany(Activity::class);
|
||||||
|
}
|
||||||
|
}
|
|
@ -4,7 +4,7 @@ use Illuminate\Database\Migrations\Migration;
|
||||||
use Illuminate\Database\Schema\Blueprint;
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
use Illuminate\Support\Facades\Schema;
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
class CreateActivityGroupTable extends Migration
|
class CreateSubactivitiesTable extends Migration
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Run the migrations.
|
* Run the migrations.
|
||||||
|
@ -13,10 +13,10 @@ class CreateActivityGroupTable extends Migration
|
||||||
*/
|
*/
|
||||||
public function up()
|
public function up()
|
||||||
{
|
{
|
||||||
Schema::create('activity_group', function (Blueprint $table) {
|
Schema::create('subactivities', function (Blueprint $table) {
|
||||||
$table->integer('activity_id');
|
$table->id();
|
||||||
$table->integer('group_id');
|
$table->string('name');
|
||||||
$table->unique(['activity_id', 'group_id']);
|
$table->string('nami_id')->nullable();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,6 +27,6 @@ class CreateActivityGroupTable extends Migration
|
||||||
*/
|
*/
|
||||||
public function down()
|
public function down()
|
||||||
{
|
{
|
||||||
Schema::dropIfExists('activity_group');
|
Schema::dropIfExists('groups');
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -0,0 +1,32 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
class CreateActivitySubactivityTable extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
Schema::create('activity_subactivity', function (Blueprint $table) {
|
||||||
|
$table->foreignId('activity_id')->constrained();
|
||||||
|
$table->foreignId('subactivity_id')->constrained();
|
||||||
|
$table->unique(['activity_id', 'subactivity_id']);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function down()
|
||||||
|
{
|
||||||
|
Schema::dropIfExists('activity_subactivity');
|
||||||
|
}
|
||||||
|
}
|
|
@ -16,7 +16,7 @@ class CreateGroupsTable extends Migration
|
||||||
Schema::create('groups', function (Blueprint $table) {
|
Schema::create('groups', function (Blueprint $table) {
|
||||||
$table->id();
|
$table->id();
|
||||||
$table->string('name');
|
$table->string('name');
|
||||||
$table->string('nami_id')->nullable();
|
$table->unsignedInteger('nami_id');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,9 +48,11 @@ class CreateMembersTable extends Migration
|
||||||
$table->string('email_parents')->nullable();
|
$table->string('email_parents')->nullable();
|
||||||
$table->integer('nami_id')->nullable();
|
$table->integer('nami_id')->nullable();
|
||||||
$table->foreignId('nationality_id')->constrained();
|
$table->foreignId('nationality_id')->constrained();
|
||||||
$table->foreignId('fee_id')->constrained();
|
$table->foreignId('fee_id')->nullable()->constrained();
|
||||||
$table->text('letter_address')->nullable();
|
$table->text('letter_address')->nullable();
|
||||||
$table->foreignId('bill_kind_id')->nullable()->constrained();
|
$table->foreignId('bill_kind_id')->nullable()->constrained();
|
||||||
|
$table->foreignId('first_activity_id')->nullable()->constrained('activities');
|
||||||
|
$table->foreignId('first_subactivity_id')->nullable()->constrained('subactivities');
|
||||||
$table->unsignedInteger('version')->default(1);
|
$table->unsignedInteger('version')->default(1);
|
||||||
|
|
||||||
$table->timestamps();
|
$table->timestamps();
|
||||||
|
|
|
@ -24,6 +24,12 @@
|
||||||
<f-select :options="regions" id="region_id" v-model="inner.region_id" label="Bundesland"></f-select>
|
<f-select :options="regions" id="region_id" v-model="inner.region_id" label="Bundesland"></f-select>
|
||||||
<f-select :options="countries" id="country_id" v-model="inner.country_id" label="Land" required></f-select>
|
<f-select :options="countries" id="country_id" v-model="inner.country_id" label="Land" required></f-select>
|
||||||
<f-select :options="nationalities" id="nationality_id" v-model="inner.nationality_id" label="Staatsangehörigkeit" required></f-select>
|
<f-select :options="nationalities" id="nationality_id" v-model="inner.nationality_id" label="Staatsangehörigkeit" required></f-select>
|
||||||
|
|
||||||
|
<div class="contents" v-show="mode === 'create'">
|
||||||
|
<h2 class="col-span-full font-semibold text-lg text-white">Erste Gruppierung</h2>
|
||||||
|
<f-select :options="activities" id="first_activity_id" v-model="inner.first_activity_id" label="Erste Tätigkeit" required></f-select>
|
||||||
|
<f-select v-if="inner.first_activity_id" :options="subactivities[inner.first_activity_id]" id="first_subactivity_id" v-model="inner.first_subactivity_id" label="Erste Untertätigkeit" required></f-select>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="grid grid-cols-2 gap-3 p-4" v-if="menuTitle == 'Kontakt'">
|
<div class="grid grid-cols-2 gap-3 p-4" v-if="menuTitle == 'Kontakt'">
|
||||||
<f-text id="main_phone" v-model="inner.main_phone" label="Telefon"></f-text>
|
<f-text id="main_phone" v-model="inner.main_phone" label="Telefon"></f-text>
|
||||||
|
@ -64,6 +70,8 @@ export default {
|
||||||
},
|
},
|
||||||
|
|
||||||
props: {
|
props: {
|
||||||
|
subactivities: {},
|
||||||
|
activities: {},
|
||||||
mode: {},
|
mode: {},
|
||||||
genders: {},
|
genders: {},
|
||||||
fees: {},
|
fees: {},
|
||||||
|
|
|
@ -185,5 +185,7 @@ return [
|
||||||
'zip' => 'PLZ',
|
'zip' => 'PLZ',
|
||||||
'location' => 'Ort',
|
'location' => 'Ort',
|
||||||
'nationality_id' => 'Staatsangehörigkeit',
|
'nationality_id' => 'Staatsangehörigkeit',
|
||||||
|
'first_group_id' => 'Erste Untertätigkeit',
|
||||||
|
'first_activity_id' => 'Erste Tätigkeit',
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
|
Loading…
Reference in New Issue