Create New {{ $pageHeader['title'] }}
@include('backend.layouts.partials.message') @php $userId = request('user_id'); $investments = collect(); $selectedInvestId = request('invest_id', old('invest_id')); if ($userId) { $investments = \App\Models\Invest::where('user_id', $userId)->orderBy('invest_date')->get(); } @endphp @if($investments->count())
Select Investment to Pay Profit:
@php
$selectedInvest = $investments->where('id', $selectedInvestId)->first();
$payableProfit = null;
$displayDueMonths = 0;
$suggestedProfit = 0;
if ($selectedInvest) {
$investDate = \Carbon\Carbon::parse($selectedInvest->invest_date);
$now = \Carbon\Carbon::now();
// Calculate months since investment start (up to now, not future)
$monthsSinceStart = $investDate->diffInMonths($now);
if ($now->day >= $investDate->day) {
$monthsSinceStart += 1;
}
$monthsSinceStart = min($monthsSinceStart, $selectedInvest->months);
// Get number of months already paid
$paidProfits = \App\Models\Profit::where('user_id', $userId)
->where('invest_id', $selectedInvest->id)
->where('date', '>=', $investDate->toDateString())
->where('date', '<=', $investDate->copy()->addMonths($selectedInvest->months)->toDateString())
->get();
$monthsPaid = $paidProfits->count();
// Calculate monthly profit dynamically (same logic as summary)
$monthlyProfit = $selectedInvest->amount * ($selectedInvest->percent / 100);
$totalProfit = $monthlyProfit * $selectedInvest->months;
// Calculate due months and profit (same logic as summary)
$dueMonths = $monthsSinceStart - $monthsPaid;
if ($dueMonths < 0) {
$dueMonths = 0;
}
$displayDueMonths = (int) $dueMonths;
// Due profit is only for elapsed, unpaid months
$payableProfit = $displayDueMonths * $monthlyProfit;
$suggestedProfit = $payableProfit;
}
@endphp
@if($selectedInvest)
@endif
Amount: {{ number_format($selectedInvest->amount, 2) }}
Percent per month: {{ $selectedInvest->percent }}%
Invest Date: {{ $selectedInvest->invest_date }}
Duration: {{ $selectedInvest->months }} months
Profit Due: {{ (int) $suggestedProfit }} (for {{ $displayDueMonths }} month{{ $displayDueMonths == 1 ? '' : 's' }}) @if($suggestedProfit <= 0)
@endif
Percent per month: {{ $selectedInvest->percent }}%
Invest Date: {{ $selectedInvest->invest_date }}
Duration: {{ $selectedInvest->months }} months
Profit Due: {{ (int) $suggestedProfit }} (for {{ $displayDueMonths }} month{{ $displayDueMonths == 1 ? '' : 's' }}) @if($suggestedProfit <= 0)
No profit due. All profits paid or not yet due.
@endif