Add pending payment to member index

This commit is contained in:
philipp lang 2021-07-04 21:47:20 +02:00
parent 782983686b
commit 7954efe1b0
8 changed files with 43 additions and 8 deletions

View File

@ -12,7 +12,7 @@ use App\Payment\PaymentResource;
class MemberView {
public function index(Request $request) {
return [
'data' => MemberResource::collection(Member::select('*')->search($request->query('search', null))->with('billKind')->withSubscriptionName()->withIsConfirmed()->orderByRaw('lastname, firstname')->paginate(15)),
'data' => MemberResource::collection(Member::select('*')->search($request->query('search', null))->with('billKind')->withSubscriptionName()->withIsConfirmed()->withPendingPayment()->orderByRaw('lastname, firstname')->paginate(15)),
'toolbar' => [ ['href' => route('member.index'), 'label' => 'Zurück', 'color' => 'primary', 'icon' => 'plus'] ]
];
}

View File

@ -25,6 +25,7 @@ class Member extends Model
public $dates = ['joined_at', 'birthday'];
public $casts = [
'pending_payment' => 'integer',
'send_newspaper' => 'boolean',
'gender_id' => 'integer',
'way_id' => 'integer',
@ -150,4 +151,13 @@ class Member extends Model
]);
}
public function scopeWithPendingPayment($q) {
return $q->addSelect([
'pending_payment' => Payment::selectRaw('SUM(subscriptions.amount)')
->whereColumn('payments.member_id', 'members.id')
->whereNeedsPayment()
->join('subscriptions', 'subscriptions.id', 'payments.subscription_id')
]);
}
}

View File

@ -49,6 +49,7 @@ class MemberResource extends JsonResource
'is_confirmed' => $this->is_confirmed,
'children_phone' => $this->children_phone,
'payments' => PaymentResource::collection($this->whenLoaded('payments')),
'pending_payment' => $this->pending_payment ? number_format($this->pending_payment / 100, 2, ',', '.').' €' : null,
];
}
}

View File

@ -25,4 +25,10 @@ class Payment extends Model
public function status() {
return $this->belongsTo(Status::class);
}
public function scopeWhereNeedsPayment($q) {
return $q->whereHas('status', function($q) {
return $q->needsPayment();
});
}
}

View File

@ -24,4 +24,11 @@ class Status extends Model
public function isAccepted() {
return $this->is_bill === false && $this->is_remember === false;
}
// ---------------------------------- Scopes -----------------------------------
public function scopeNeedsPayment($q) {
return $q->where(function($q) {
$q->where('is_bill', true)->orWhere('is_remember', true);
});
}
}

View File

@ -1,5 +1,8 @@
.bool {
@apply rounded-full text-xs w-5 h-5 flex items-center justify-center leading-none;
@apply rounded-full w-5 h-5 text-xs flex items-center justify-center leading-none;
&.bool-inline {
@apply w-auto;
}
&.enabled {
@apply bg-green-800 text-red-100;
}

View File

@ -5,7 +5,7 @@
}
&.btn-sm {
@apply text-xs w-6 h-6 px-1 py-1;
@apply text-xs px-2 py-1;
svg {
@apply w-3 h-3 text-primary-100 flex-none;
}

View File

@ -10,8 +10,9 @@
<div>Ort</div>
<div>Tags</div>
<div>Beitrag</div>
<div>Rechnung</div>
<div>Geburtstag</div>
<div>Rechnung</div>
<div>Ausstand</div>
<div>Eintritt</div>
<div></div>
</header>
@ -30,11 +31,18 @@
</div>
</div>
<div v-text="member.subscription_name"></div>
<div>
<div class="py-1 rounded-full flex text-xs items-center justify-center leading-none bg-primary-900" v-text="member.bill_kind_name" v-if="member.bill_kind_name"></div>
<div class="py-1 rounded-full flex text-xs items-center justify-center leading-none" v-else>Kein</div>
</div>
<div v-text="`${member.birthday_human}`"></div>
<div>
<div class="flex justify-center">
<div class="btn btn-sm label primary" v-text="member.bill_kind_name" v-if="member.bill_kind_name"></div>
<div class="text-xs" v-else>Kein</div>
</div>
</div>
<div>
<div class="flex justify-center">
<div class="btn btn-sm label primary" v-show="member.pending_payment" v-text="member.pending_payment"></div>
</div>
</div>
<div v-text="`${member.joined_at_human}`"></div>
<div class="flex">
<inertia-link :href="`/member/${member.id}/edit`" class="inline-flex btn btn-warning btn-sm"><sprite src="pencil"></sprite></inertia-link>