feat: add payment tracking to user profiles

- Added a check to update the 'paid' status of a user's paymentEvents if the current year's payment has been made
- Updated the user profile view to display past payments
- Added 'paymentEvents' to the query in EinundzwanzigPlebTable.php to fetch the current year's payments
- Added a 'payment' column to the table in EinundzwanzigPlebTable.php to display the amount of the user's current year's payment
This commit is contained in:
fsociety
2024-09-30 15:22:33 +02:00
parent 0bdd890dd3
commit 65fb920150
4 changed files with 99 additions and 12 deletions

View File

@@ -49,6 +49,7 @@ final class EinundzwanzigPlebTable extends PowerGridComponent
return EinundzwanzigPleb::query() return EinundzwanzigPleb::query()
->with([ ->with([
'profile', 'profile',
'paymentEvents' => fn($query) => $query->where('year', date('Y')),
]) ])
->where('association_status', '>', 1) ->where('association_status', '>', 1)
->orWhereNotNull('application_for'); ->orWhereNotNull('application_for');
@@ -74,6 +75,11 @@ final class EinundzwanzigPlebTable extends PowerGridComponent
$model->application_for, $model->application_for,
)->label() . '</div></div>' : '', )->label() . '</div></div>' : '',
) )
->add(
'payment',
fn(EinundzwanzigPleb $model)
=> $model->paymentEvents->count() > 0 ? $model->paymentEvents->first()->amount : 'keine Zahlung vorhanden',
)
->add( ->add(
'npub', 'npub',
fn(EinundzwanzigPleb $model) fn(EinundzwanzigPleb $model)
@@ -112,6 +118,9 @@ final class EinundzwanzigPlebTable extends PowerGridComponent
->visibleInExport( visible: true) ->visibleInExport( visible: true)
->sortable(), ->sortable(),
Column::make('Beitrag ' . date('Y'), 'payment')
->visibleInExport( visible: true),
Column::make('Bewirbt sich für', 'for', 'application_for') Column::make('Bewirbt sich für', 'for', 'application_for')
->visibleInExport( visible: false) ->visibleInExport( visible: false)
->sortable(), ->sortable(),

View File

@@ -0,0 +1,28 @@
<?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::table('payment_events', function (Blueprint $table) {
$table->boolean('paid')->default(false);
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('payment_events', function (Blueprint $table) {
//
});
}
};

View File

@@ -1,4 +1,6 @@
<div class="px-4 py-2 rounded-lg text-sm bg-violet-100 text-gray-700"> <div class="p-4">
<div class="px-4 py-2 rounded-lg text-sm bg-violet-100 text-gray-700">
@if($row->application_text ) @if($row->application_text )
<div class="flex w-full justify-between items-start"> <div class="flex w-full justify-between items-start">
<div class="flex"> <div class="flex">
@@ -11,4 +13,48 @@
@else @else
keine Bewerbung vorhanden keine Bewerbung vorhanden
@endif @endif
</div>
<section class="mt-4">
<h3 class="text-xl leading-snug text-gray-800 dark:text-gray-100 font-bold mb-1">
bisherige Zahlungen</h3>
<!-- Table -->
<table class="table-auto w-full dark:text-gray-400">
<!-- Table header -->
<thead
class="text-xs uppercase text-gray-400 dark:text-gray-500">
<tr class="flex flex-wrap md:table-row md:flex-no-wrap">
<th class="w-full block md:w-auto md:table-cell py-2">
<div class="font-semibold text-left">Satoshis</div>
</th>
<th class="w-full hidden md:w-auto md:table-cell py-2">
<div class="font-semibold text-left">Jahr</div>
</th>
<th class="w-full hidden md:w-auto md:table-cell py-2">
<div class="font-semibold text-left">Event-ID</div>
</th>
</tr>
</thead>
<!-- Table body -->
<tbody class="text-sm">
@foreach($row->paymentEvents as $payment)
<tr class="flex flex-wrap md:table-row md:flex-no-wrap border-b border-gray-200 dark:border-gray-700/60 py-2 md:py-0">
<td class="w-full block md:w-auto md:table-cell py-0.5 md:py-2">
<div
class="text-left font-medium text-gray-800 dark:text-gray-100">{{ $payment->amount }}</div>
</td>
<td class="w-full block md:w-auto md:table-cell py-0.5 md:py-2">
<div
class="text-left">{{ $payment->year }}</div>
</td>
<td class="w-full block md:w-auto md:table-cell py-0.5 md:py-2">
<div
class="text-left font-medium">{{ $payment->event_id }}</div>
</td>
</tr>
@endforeach
</tbody>
</table>
</section>
</div> </div>

View File

@@ -126,6 +126,10 @@ $searchPaymentEvent = function () {
fn($yearPaid) => $yearPaid['year'] == date('Y') && $yearPaid['amount'] == $this->amountToPay, fn($yearPaid) => $yearPaid['year'] == date('Y') && $yearPaid['amount'] == $this->amountToPay,
); );
if ($this->currentYearIsPaid) {
$this->currentPleb->paymentEvents->first()->update(['paid' => true]);
}
$this->paid = true; $this->paid = true;
} }
}; };