@extends('layouts.job_order_pdf') @section('title') {{'job_order_'.$invoice['barcode'].'_'.date('d-m-Y_H-i',strtotime($invoice['created_at'])).'.pdf'}} @endsection @section('content') @php $categoryIds = \App\Models\InvoiceSampleTest::query() ->where('invoice_id', $invoice['id']) ->distinct() ->pluck('category_id'); $categories = \App\Models\Category::query() ->whereIn('id', $categoryIds) ->with(['invoice_sample_tests' => function ($q) use ($invoice) { $q->with('testable','sample.sample_type')->where('invoice_id', $invoice['id']); }]) ->get(); @endphp
@php $count_category=0; @endphp @foreach($categories as $category) @php // group by sample id (change key name to your actual FK) $bySample = $category->invoice_sample_tests->groupBy('invoice_sample_id'); @endphp @foreach($bySample as $invoiceSampleId => $rows) @php $sample = optional($rows->first())->sample; // sample model @endphp @foreach($rows as $row) @endforeach @endforeach @if(isset($invoice['note'])) @endif
{{$category['name']}} barcode
{{__('Sample ID')}} {{__('Test')}} {{__('Result Date')}} {{__('Sample')}}
{{$sample['sample_id']}} {{$row['testable']['name']}} {{$row['invoiceable']['deadline_date']}} {{$sample['sample_type']['name']}}
@for ($i = 0; $i < count($invoice['questions_arr']); $i += 2) {{-- First question --}} {{-- Second question (if exists) --}} @if (isset($invoice['questions_arr'][$i + 1])) @else {{-- Fill empty cells if no second question --}} @endif @endfor
{{__('This is the visit No.')}} : {{\App\Models\Invoice::where('patient_id',$invoice['patient_id'])->where('id','<=',$invoice['id'])->count()}}
{{ $invoice['questions_arr'][$i]['question'] }} : @if ($invoice['questions_arr'][$i]['type'] == 'checkbox') {{ __('Yes') }} @else {{ $invoice['questions_arr'][$i]['value'] }} @endif {{ $invoice['questions_arr'][$i + 1]['question'] }} : @if ($invoice['questions_arr'][$i + 1]['type'] == 'checkbox') {{ __('Yes') }} @else {{ $invoice['questions_arr'][$i + 1]['value'] }} @endif
@php $count_category++; @endphp @if(count($categories)>$count_category) @endif @endforeach
@endsection