Fix subcontract jobs not appearing in PDF
Load subcontractJobs via explicit query (bypassing TenantScope but scoped manually by work_order_id + company_id) to avoid relation caching issues. Pass as separate blade variable \$subcontractJobs. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -9,7 +9,12 @@ class WorkOrderPdfService
|
|||||||
{
|
{
|
||||||
public function generate(WorkOrder $wo): \Barryvdh\DomPDF\PDF
|
public function generate(WorkOrder $wo): \Barryvdh\DomPDF\PDF
|
||||||
{
|
{
|
||||||
$wo->load(['client', 'vehicle', 'master', 'works.master', 'parts', 'payments', 'subcontractJobs.subcontractor']);
|
$wo->load(['client', 'vehicle', 'master', 'works.master', 'parts', 'payments']);
|
||||||
|
$subcontractJobs = \App\Models\Tenant\SubcontractJob::withoutGlobalScope(\App\Models\Scopes\TenantScope::class)
|
||||||
|
->where('work_order_id', $wo->id)
|
||||||
|
->where('company_id', $wo->company_id)
|
||||||
|
->with('subcontractor')
|
||||||
|
->get();
|
||||||
$company = $wo->company ?: \App\Models\Central\Company::find($wo->company_id);
|
$company = $wo->company ?: \App\Models\Central\Company::find($wo->company_id);
|
||||||
|
|
||||||
$themeColor = $company?->settings['theme_color'] ?? '#3B82F6';
|
$themeColor = $company?->settings['theme_color'] ?? '#3B82F6';
|
||||||
@@ -34,15 +39,16 @@ class WorkOrderPdfService
|
|||||||
}
|
}
|
||||||
|
|
||||||
$html = view('pdf.work-order', [
|
$html = view('pdf.work-order', [
|
||||||
'wo' => $wo,
|
'wo' => $wo,
|
||||||
'company' => $company,
|
'company' => $company,
|
||||||
'themeColor' => $themeColor,
|
'themeColor' => $themeColor,
|
||||||
'currency' => $currency,
|
'currency' => $currency,
|
||||||
'worksTotal' => $worksTotal,
|
'worksTotal' => $worksTotal,
|
||||||
'partsTotal' => $partsTotal,
|
'partsTotal' => $partsTotal,
|
||||||
'paid' => $paid,
|
'paid' => $paid,
|
||||||
'balance' => $balance,
|
'balance' => $balance,
|
||||||
'logoData' => $logoData,
|
'logoData' => $logoData,
|
||||||
|
'subcontractJobs' => $subcontractJobs,
|
||||||
])->render();
|
])->render();
|
||||||
|
|
||||||
// DejaVu Sans lacks U+0219 (ș) and U+021B (ț) — normalize to cedilla
|
// DejaVu Sans lacks U+0219 (ș) and U+021B (ț) — normalize to cedilla
|
||||||
|
|||||||
@@ -252,7 +252,7 @@
|
|||||||
</table>
|
</table>
|
||||||
@endif
|
@endif
|
||||||
|
|
||||||
@if ($wo->subcontractJobs->isNotEmpty())
|
@if ($subcontractJobs->isNotEmpty())
|
||||||
<h3 style="font-size: 12px; margin: 12px 0 4px; text-transform: uppercase; color: {{ $themeColor }};">{{ __('Lucrări terțe') }}</h3>
|
<h3 style="font-size: 12px; margin: 12px 0 4px; text-transform: uppercase; color: {{ $themeColor }};">{{ __('Lucrări terțe') }}</h3>
|
||||||
<table class="items">
|
<table class="items">
|
||||||
<thead>
|
<thead>
|
||||||
@@ -264,7 +264,7 @@
|
|||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
@foreach ($wo->subcontractJobs as $sj)
|
@foreach ($subcontractJobs as $sj)
|
||||||
<tr>
|
<tr>
|
||||||
<td>{{ $sj->description ?? '—' }}</td>
|
<td>{{ $sj->description ?? '—' }}</td>
|
||||||
<td>{{ $sj->subcontractor?->name ?? '—' }}</td>
|
<td>{{ $sj->subcontractor?->name ?? '—' }}</td>
|
||||||
@@ -276,7 +276,7 @@
|
|||||||
<tfoot>
|
<tfoot>
|
||||||
<tr>
|
<tr>
|
||||||
<td colspan="3" class="r">{{ __('Subtotal terțe:') }}</td>
|
<td colspan="3" class="r">{{ __('Subtotal terțe:') }}</td>
|
||||||
<td class="r">{{ number_format((float) $wo->subcontractJobs->sum('client_price'), 2, '.', ' ') }} {{ $currency }}</td>
|
<td class="r">{{ number_format((float) $subcontractJobs->sum('client_price'), 2, '.', ' ') }} {{ $currency }}</td>
|
||||||
</tr>
|
</tr>
|
||||||
</tfoot>
|
</tfoot>
|
||||||
</table>
|
</table>
|
||||||
|
|||||||
Reference in New Issue
Block a user