@php // 将历史记录转换为 JS 容易读取的对象,Key 是 ID $historyJson = $leaseHistory->keyBy('id')->map(function($item) { return [ 'status' => $item->status, 'checked_out_at' => $item->checked_out_at ? $item->checked_out_at_formatted : null, 'agreement_ended_at' => $item->agreement_ended_at ? $item->agreement_ended_at_formatted : null, 'start_date' => $item->start_date_formatted ?? null, 'end_date' => $item->end_date_formatted ?? null, 'term_type' => strtoupper($item->term_type) ?? 'N/A', 'rent_price' => number_format($item->rent_price, 2), 'deposit_mode' => strtoupper($item->deposit_mode) ?? 'SECURITY', 'security_deposit' => ($item->security_deposit > 0) ? number_format($item->security_deposit, 2) : null, 'utilities_deposit' => ($item->utilities_deposit > 0) ? number_format($item->utilities_deposit, 2) : null, 'edit_url' => route('admin.leases.edit', $item->id), 'stamping_status' => (bool)$item->stamping_status, 'stamping_cert_path' => $item->stamping_cert_path, 'stamping_reference_no' => $item->stamping_reference_no, 'stamped_at' => $item->stamped_at ? $item->stamped_at_formatted : null, 'can_stamp' => in_array($item->status, ['New', 'Renew']), 'upload_url' => route('admin.leases.upload-stamping', $item->id), 'view_url' => route('admin.leases.view-cert', $item->id), 'agreement' => [ 'title' => $item->agreement?->title ?? 'Agreement', 'content' => $item->agreement?->content ?? '', ], 'agreement_id' => $item->agreement_id, 'tenant_name' => $item->tenant?->user->name ?? 'N/A', 'tenant_ic' => $item->tenant?->ic_number ?? 'N/A', 'owner_name' => $item->leasable?->owner?->name ?? $item->leasable?->owner?->unit->name ?? 'N/A', 'owner_ic' => $item->leasable?->owner?->ic_number ?? 'N/A', 'property_address' => $item->leasable?->full_address ?? 'N/A', 'property_type' => $item->leasableTypeLabel ?? 'N/A', 'property_name' => $item->leasableName ?? 'N/A', 'rent_mode' => strtoupper($item->term_type ?? 'N/A'), 'check_out_date' => $item->checked_out_at?->format('d/m/Y') ?? 'N/A', 'end_agreement_date' => $item->agreement_ended_at?->format('d/m/Y') ?? 'N/A', ]; }); $historyData = $historyJson->toArray(); @endphp {{-- 1. 初始化数据,注意 activeId 加了单引号 --}}
Back to Lease List
{{-- Grid Lease Flow --}}

Lease Progression

@foreach($leaseHistory as $history) @php $hStatus = strtolower((string)$history->status); $statusColor = match($hStatus) { 'new' => 'indigo', 'renew' => 'emerald', 'check out' => 'amber', 'end' => 'gray', default => 'slate' }; @endphp {{-- 修改点:@click 内部 ID 加引号,:class 内部比较也加引号 --}}
{{ $history->status }} {{ $history->is_current ? '(Current)' : '' }}

{{ $history->start_date_formatted ?? '-' }} - {{ $history->end_date_formatted ?? '-' }} @if ($history->agreement_ended_at)

({{ $history->agreement_ended_at_formatted ?? '-' }})

@elseif ($history->checked_out_at)

({{ $history->checked_out_at_formatted ?? '-' }})

@endif

@endforeach
{{-- 3. 详情区域 --}}
{{-- 使用 x-cloak 防止闪烁 (如果你的 CSS 里有定义的话) --}}
{{-- 左侧:标题 --}}

Lease Details:

{{-- 右侧:动态操作按钮 --}}
{{-- 3. 关键:将 $lease 替换为页面上定义的变量 --}} {{-- 这里假设你的后端已经通过路由或初始化传了一个总的 $lease 对象 --}}

Owner Name

Start Date

End Date

Term Type

Rent Price

RM

Deposit Mode

Security Deposit

Utilities Deposit

Check Out Date

Agreement Ended Date

Payment Overview

{{-- Add Manual Invoice 按钮 --}}
@csrf
{{-- Rent Outstanding 部分 --}}

Rent Outstanding

@include('adminSide.tenants.payments.paymentTable', [ 'payments' => $rentPayments, 'emptyMessage' => 'No outstanding rent found.' ])
Invoice Type / Period Amount Details Status Method Actions
@if($rentPayments->hasPages())
{{ $rentPayments->appends(['other_page' => request('other_page')])->links() }}
@endif

{{-- Other Bills & Miscellaneous 部分 --}}

Other Bills & Miscellaneous

@include('adminSide.tenants.payments.paymentTable', [ 'payments' => $otherPayments, 'emptyMessage' => 'No miscellaneous records found.' ])
Invoice Type / Period Amount Details Status Method Actions
@if($otherPayments->hasPages())
{{ $otherPayments->appends(['rent_page' => request('rent_page')])->links() }}
@endif