Skip to content

Commit a2f2507

Browse files
committed
Improve expense report detail screen with new request types
Closes #903
1 parent 8cd5707 commit a2f2507

1 file changed

Lines changed: 106 additions & 24 deletions

File tree

app/Nova/ExpenseReport.php

Lines changed: 106 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -123,36 +123,118 @@ public function fields(NovaRequest $request): array
123123
->onlyOnDetail(),
124124

125125
Currency::make('Amount')
126-
->sortable(),
127-
128-
Currency::make(
129-
'Envelopes Total Amount',
130-
fn (): string|int => $this->envelopes()->sum('docusign_envelopes.amount')
131-
)
132-
->onlyOnDetail(),
126+
->sortable()
127+
->onlyOnIndex(),
133128

134129
URL::make('View in Workday', 'workday_url')
135130
->canSee(static fn (Request $request): bool => $request->user()->can('access-workday')),
136131

132+
Panel::make('Totals', [
133+
Currency::make('Expense Report Amount', 'amount')
134+
->onlyOnDetail(),
135+
136+
Currency::make(
137+
'Expense Report Lines Total Amount',
138+
fn (): string|int => $this->lines()->sum('expense_report_lines.amount')
139+
)
140+
->onlyOnDetail()
141+
->showOnDetail(
142+
static fn (
143+
NovaRequest $request,
144+
\App\Models\ExpenseReport $expenseReport
145+
): bool => $expenseReport->lines()->count() > 0
146+
),
147+
148+
Currency::make(
149+
'Envelopes Total Amount',
150+
fn (): string|int => $this->envelopes()->sum('docusign_envelopes.amount')
151+
)
152+
->onlyOnDetail()
153+
->showOnDetail(
154+
static fn (
155+
NovaRequest $request,
156+
\App\Models\ExpenseReport $expenseReport
157+
): bool => $expenseReport->envelopes()->count() > 0
158+
),
159+
160+
Currency::make(
161+
'Engage Requests Total Submitted Amount',
162+
fn (): string|int => $this->engagePurchaseRequests()->sum(
163+
'engage_purchase_requests.submitted_amount'
164+
)
165+
)
166+
->onlyOnDetail()
167+
->showOnDetail(
168+
static fn (
169+
NovaRequest $request,
170+
\App\Models\ExpenseReport $expenseReport
171+
): bool => $expenseReport->engagePurchaseRequests()->count() > 0
172+
),
173+
174+
Currency::make(
175+
'Engage Requests Total Approved Amount',
176+
fn (): string|int => $this->engagePurchaseRequests()->sum(
177+
'engage_purchase_requests.approved_amount'
178+
)
179+
)
180+
->onlyOnDetail()
181+
->showOnDetail(
182+
static fn (
183+
NovaRequest $request,
184+
\App\Models\ExpenseReport $expenseReport
185+
): bool => $expenseReport->engagePurchaseRequests()->count() > 0
186+
),
187+
188+
Currency::make(
189+
'Email Requests Total Amount',
190+
fn (): string|int => $this->emailRequests()->sum('email_requests.vendor_document_amount')
191+
)
192+
->onlyOnDetail()
193+
->showOnDetail(
194+
static fn (
195+
NovaRequest $request,
196+
\App\Models\ExpenseReport $expenseReport
197+
): bool => $expenseReport->emailRequests()->count() > 0
198+
),
199+
]),
200+
137201
HasMany::make('Lines', 'lines', ExpenseReportLine::class),
138202

139-
...($this->engagePurchaseRequests()->count() === 0 ||
140-
$this->emailRequests()->count() === 0 ||
141-
$this->envelopes()->count() > 0 ? [
142-
HasMany::make('DocuSign Envelopes', 'envelopes', DocuSignEnvelope::class),
143-
] : []),
144-
145-
...($this->envelopes()->count() === 0 ||
146-
$this->emailRequests()->count() === 0 ||
147-
$this->engagePurchaseRequests()->count() > 0 ? [
148-
HasMany::make('Engage Requests', 'engagePurchaseRequests', EngagePurchaseRequest::class),
149-
] : []),
150-
151-
...($this->engagePurchaseRequests()->count() === 0 ||
152-
$this->envelopes()->count() === 0 ||
153-
$this->emailRequests()->count() > 0 ? [
154-
HasMany::make('Email Requests'),
155-
] : []),
203+
HasMany::make('DocuSign Envelopes', 'envelopes', DocuSignEnvelope::class)
204+
->showOnDetail(
205+
static fn (
206+
NovaRequest $request,
207+
\App\Models\ExpenseReport $expenseReport
208+
): bool => ($expenseReport->envelopes()->count() > 0) ||
209+
(
210+
$expenseReport->engagePurchaseRequests()->count() === 0 &&
211+
$expenseReport->emailRequests()->count() === 0
212+
)
213+
),
214+
215+
HasMany::make('Engage Requests', 'engagePurchaseRequests', EngagePurchaseRequest::class)
216+
->showOnDetail(
217+
static fn (
218+
NovaRequest $request,
219+
\App\Models\ExpenseReport $expenseReport
220+
): bool => ($expenseReport->engagePurchaseRequests()->count() > 0) ||
221+
(
222+
$expenseReport->envelopes()->count() === 0 &&
223+
$expenseReport->emailRequests()->count() === 0
224+
)
225+
),
226+
227+
HasMany::make('Email Requests')
228+
->showOnDetail(
229+
static fn (
230+
NovaRequest $request,
231+
\App\Models\ExpenseReport $expenseReport
232+
): bool => ($expenseReport->emailRequests()->count() > 0) ||
233+
(
234+
$expenseReport->envelopes()->count() === 0 &&
235+
$expenseReport->engagePurchaseRequests()->count() === 0
236+
)
237+
),
156238

157239
Panel::make('Timestamps', [
158240
DateTime::make('Created', 'created_at')

0 commit comments

Comments
 (0)