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()
->with([
'profile',
'paymentEvents' => fn($query) => $query->where('year', date('Y')),
])
->where('association_status', '>', 1)
->orWhereNotNull('application_for');
@@ -74,6 +75,11 @@ final class EinundzwanzigPlebTable extends PowerGridComponent
$model->application_for,
)->label() . '</div></div>' : '',
)
->add(
'payment',
fn(EinundzwanzigPleb $model)
=> $model->paymentEvents->count() > 0 ? $model->paymentEvents->first()->amount : 'keine Zahlung vorhanden',
)
->add(
'npub',
fn(EinundzwanzigPleb $model)
@@ -112,6 +118,9 @@ final class EinundzwanzigPlebTable extends PowerGridComponent
->visibleInExport( visible: true)
->sortable(),
Column::make('Beitrag ' . date('Y'), 'payment')
->visibleInExport( visible: true),
Column::make('Bewirbt sich für', 'for', 'application_for')
->visibleInExport( visible: false)
->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,14 +1,60 @@
<div class="px-4 py-2 rounded-lg text-sm bg-violet-100 text-gray-700">
@if($row->application_text )
<div class="flex w-full justify-between items-start">
<div class="flex">
<svg class="shrink-0 fill-current text-violet-500 mt-[3px] mr-3" width="16" height="16" viewBox="0 0 16 16">
<path d="M8 0C3.6 0 0 3.6 0 8s3.6 8 8 8 8-3.6 8-8-3.6-8-8-8zm1 12H7V7h2v5zM8 6c-.6 0-1-.4-1-1s.4-1 1-1 1 .4 1 1-.4 1-1 1z"></path>
</svg>
<div>{{ $row->application_text }}</div>
<div class="p-4">
<div class="px-4 py-2 rounded-lg text-sm bg-violet-100 text-gray-700">
@if($row->application_text )
<div class="flex w-full justify-between items-start">
<div class="flex">
<svg class="shrink-0 fill-current text-violet-500 mt-[3px] mr-3" width="16" height="16" viewBox="0 0 16 16">
<path d="M8 0C3.6 0 0 3.6 0 8s3.6 8 8 8 8-3.6 8-8-3.6-8-8-8zm1 12H7V7h2v5zM8 6c-.6 0-1-.4-1-1s.4-1 1-1 1 .4 1 1-.4 1-1 1z"></path>
</svg>
<div>{{ $row->application_text }}</div>
</div>
</div>
</div>
@else
keine Bewerbung vorhanden
@endif
@else
keine Bewerbung vorhanden
@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>

View File

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