From 5e709092e3586d59c49df9c32afc86933feb4975 Mon Sep 17 00:00:00 2001 From: AnabolicsAnonymous Date: Mon, 20 Jan 2025 20:22:18 -0600 Subject: [PATCH] fix: append donation expiry instead of replacing it --- app/Http/Controllers/Staff/DonationController.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/Staff/DonationController.php b/app/Http/Controllers/Staff/DonationController.php index ee4c27630b..96abb79cc0 100644 --- a/app/Http/Controllers/Staff/DonationController.php +++ b/app/Http/Controllers/Staff/DonationController.php @@ -72,9 +72,19 @@ public function update(Request $request, int $id): \Illuminate\Http\RedirectResp $donation = Donation::with(['user', 'package'])->findOrFail($id); $donation->status = Donation::APPROVED; $donation->starts_at = $now; + $active_donation = Donation::where('status', '=', Donation::APPROVED)->where('user_id', '=', $donation->user->id)->latest()->first(); if ($donation->package->donor_value > 0) { - $donation->ends_at = $now->addDays($donation->package->donor_value); + if ($donation->user->is_lifetime) { + $donation->ends_at = null; + } else { + if (!is_null($active_donation->ends_at) && $donation->user->is_donor) { + $active_donation_expiry = Carbon::parse($active_donation->ends_at); + $donation->ends_at = $active_donation_expiry->addDays($donation->package->donor_value); + } else { + $donation->ends_at = $now->addDays($donation->package->donor_value); + } + } } else { $donation->ends_at = null; }