Remove SubscriptionName

This commit is contained in:
philipp lang 2022-11-18 22:41:40 +01:00
parent cbd6fe9b0f
commit 30592a1dc9
5 changed files with 26 additions and 10 deletions

View File

@ -21,8 +21,8 @@ class MemberView
return [ return [
'data' => MemberResource::collection(Member::select('*') 'data' => MemberResource::collection(Member::select('*')
->filter($filter)->search($request->query('search', null)) ->filter($filter)->search($request->query('search', null))
->with('billKind')->with('payments')->with('memberships')->with('courses')->with('leaderMemberships')->with('ageGroupMemberships') ->with('billKind')->with('payments.subscription')->with('memberships')->with('courses')->with('leaderMemberships')->with('ageGroupMemberships')
->withSubscriptionName()->withIsConfirmed()->withPendingPayment() ->withIsConfirmed()->withPendingPayment()
->orderByRaw('lastname, firstname') ->orderByRaw('lastname, firstname')
->paginate(15) ->paginate(15)
), ),

View File

@ -285,13 +285,6 @@ class Member extends Model
return $q->selectSub('DATEDIFF(NOW(), IFNULL(confirmed_at, DATE_SUB(NOW(), INTERVAL 3 YEAR))) < 712', 'is_confirmed'); return $q->selectSub('DATEDIFF(NOW(), IFNULL(confirmed_at, DATE_SUB(NOW(), INTERVAL 3 YEAR))) < 712', 'is_confirmed');
} }
public function scopeWithSubscriptionName(Builder $q): Builder
{
return $q->addSelect([
'subscription_name' => Subscription::select('name')->whereColumn('subscriptions.id', 'members.subscription_id')->limit(1),
]);
}
public function scopeWithPendingPayment(Builder $q): Builder public function scopeWithPendingPayment(Builder $q): Builder
{ {
return $q->addSelect([ return $q->addSelect([

View File

@ -19,6 +19,7 @@ class PaymentResource extends JsonResource
public function toArray($request) public function toArray($request)
{ {
return [ return [
'subscription_id' => $this->subscription_id,
'subscription' => new SubscriptionResource($this->whenLoaded('subscription')), 'subscription' => new SubscriptionResource($this->whenLoaded('subscription')),
'status_name' => $this->status->name, 'status_name' => $this->status->name,
'status_id' => $this->status->id, 'status_id' => $this->status->id,

View File

@ -43,7 +43,7 @@
<tr v-for="(payment, index) in value.payments" :key="index"> <tr v-for="(payment, index) in value.payments" :key="index">
<td v-text="payment.nr"></td> <td v-text="payment.nr"></td>
<td v-text="payment.status_name"></td> <td v-text="payment.status_name"></td>
<td v-text="payment.subscription_name"></td> <td v-text="payment.subscription.name"></td>
<td class="flex"> <td class="flex">
<a <a
href="#" href="#"

View File

@ -7,6 +7,7 @@ use App\Course\Models\Course;
use App\Course\Models\CourseMember; use App\Course\Models\CourseMember;
use App\Member\Member; use App\Member\Member;
use App\Member\Membership; use App\Member\Membership;
use App\Payment\Payment;
use App\Subactivity; use App\Subactivity;
use Carbon\Carbon; use Carbon\Carbon;
use Illuminate\Foundation\Testing\DatabaseTransactions; use Illuminate\Foundation\Testing\DatabaseTransactions;
@ -118,4 +119,25 @@ class IndexTest extends TestCase
'id' => $member->memberships->first()->id, 'id' => $member->memberships->first()->id,
], $response, 'data.data.0.memberships.0'); ], $response, 'data.data.0.memberships.0');
} }
public function testItReturnsPayments(): void
{
$this->withoutExceptionHandling()->login()->loginNami();
$member = Member::factory()
->has(Payment::factory()->notPaid()->nr('2019')->subscription('Free', 1050))
->defaults()->create();
$response = $this->get('/member');
$this->assertInertiaHas([
'subscription' => [
'name' => 'Free',
'id' => $member->payments->first()->subscription->id,
'amount' => 1050,
],
'subscription_id' => $member->payments->first()->subscription->id,
'status_name' => 'Nicht bezahlt',
'nr' => '2019',
], $response, 'data.data.0.payments.0');
}
} }