@extends ('layouts/template')

@section('content')

<div  class="p-3 mcp-theme-1">
    <div class="card" id="admin-billing-report">

        <div class="card-header px-2 py-1 d-flex align-items-center">
            <strong class="mr-4">
                <i class="fas fa-user"></i>
                Note Billing Report
            </strong>
        </div>
        <div class="card-body p-0 border-0 table-responsive">
            <div class="mx-2 mt-3 mb-0 d-flex align-items-start">
                <form action="/practice-management/billing-report"  method="GET" class="form-inline" id="admin-billing-report-form">
                    <div class="form-group mr-2">
                        <label class="form-check">
                            <input type="checkbox" name="no_claims" class="form-check-input" {{request()->input('no_claims') ? 'checked' : ''}}>
                            <span for="" class="form-check-label">No Claims</span>
                        </label>
                    </div>

                    <div class="form-group mr-2">
                        <label class="form-check">
                            <input type="checkbox" name="zero_deductible" class="form-check-input" {{request()->input('zero_deductible') ? 'checked' : ''}}>
                            <span for="" class="form-check-label">Zero Deduc.</span>
                        </label>
                    </div>

                    <div class="form-group mr-2">
                        <label class="control-label  mr-1" for="">Claim</label>
                        <select name="claim_status" class="form-control">
                            <option value="">All</option>
                            @foreach($claimStatuses as $claimStatus)
                               <option value="{{$claimStatus->status}}" {{request()->input('claim_status') === $claimStatus->status ? 'selected' : ''}}>{{ucwords($claimStatus->status)}}</option>
                            @endforeach
                        </select>
                    </div>
                    
                    <div class="form-group mr-2">
                        <label class="control-label mr-1" for="">Bill Verif.</label>
                        <select name="verified" class="form-control">
                            <option value="">All</option>
                            <option {{request()->input('verified') === 'VERIFIED' ? 'selected' : ''}} value="VERIFIED">Verified</option>
                            <option {{request()->input('verified') === 'UNVERIFIED' ? 'selected' : ''}} value="UNVERIFIED">Unverified</option>
                        </select>
                    </div>
                    <div class="form-group mr-2">
                        <label class="control-label mr-1" for="">From</label>
                        <input type="date" name="from" class="form-control" value="{{request()->input('from')}}">
                        <label class="control-label ml-2 mr-1" for="">To</label>
                        <input type="date" name="to" class="form-control" value="{{request()->input('to')}}">
                    </div>
                    <div class="form-group mr-2">
                        <button onclick="return fastLoad('{{ route('practice-management.billing-report') }}?' + $('#admin-billing-report-form').serialize())" class="btn btn-primary btn-sm">Filter</button>
                    </div>
                </form>
                <div class="ml-auto">
                    <div class="d-flex align-items-baseline">
                        {!! $paginator->onEachSide(0)->withQueryString()->links() !!}
                        <div class="">
                            <div class="ml-4 mb-3">Showing <b>{{$paginator->firstItem()}}</b> to <b>{{$paginator->lastItem()}}</b> (page {{$paginator->currentPage()}}) of <b>{{$paginator->total()}}</b></div>
                        </div>
                    </div>
                </div>
            </div>
            <table class="table table-sm table-striped border-0 p-0 m-0 text-nowrap">
                <thead class="bg-light">
                    <tr>
                        <th>Patient</th>
                        <th>Note</th>
                        <th>Pro</th>
                        <th>Date</th>
                        <th>New/FU</th>
                        <th>Method</th>
                        <th>Billing Closed?</th>
                        <th>Claiming Closed?</th>
                        <th>Claims</th>
                        <th>Bills</th>
                        <th>ICDs</th>
                        <th>Status</th>
                    </tr>
                </thead>
                <tbody>
                    @foreach ($rows as $row)
                    <tr class="{{false ? 'bg-light' : ''}}">
                        <td class="text-nowrap border-left-0">
                            <a native target="_blank" href="/patients/view/{{$row->client_uid}}/notes/view/{{$row->note_uid}}">
                                {{$row->client_first}} {{$row->client_last}}
                            </a>
                            {{--@if($row->plan_type)
                                <div>Plan Type: {{$row->plan_type}}</div>
                                @if($row->plan_type == 'MEDICARE')
                                    @if($row->auto_medicare_is_partbprimary == 'YES')
                                        <div>
                                            Deductible: {{friendly_money($row->medicare_deductible)}}
                                        </div>
                                    @else 
                                        <div>
                                            Not part B Primary
                                        </div>
                                    @endif
                                @else 
                                    <div>
                                        {{$row->payer_name ?: '-'}}
                                    </div>
                                    <div>
                                        Deductible: {{friendly_money($row->commercial_deductible)}}
                                    </div>
                                @endif
                            @endif--}}
                            <?php
                            $patient = \App\Models\Client::where('uid', $row->client_uid)->first();
                            ?>
                            @include('app.patient.coverage_column_renderer', ['patient'=>$patient])
                        </td>
                        <td class="text-nowrap border-left-0">
                            <a href="/patients/view/{{$row->client_uid}}/notes/view/{{$row->note_uid}}">
                                {{friendly_date_time($row->note_date, false)}}
                            </a>
                        </td>
                        <td class="text-nowrap border-left-0">
                            {{$row->pro_first}} {{$row->pro_last}}
                        </td>
                        <td class="text-nowrap border-left-0">
                            {{$row->note_date}}
                        </td>
                        <td class="text-nowrap border-left-0">
                            {{$row->new_or_fu_or_na}}
                        </td>
                        <td class="text-nowrap border-left-0">
                            {{$row->method}}
                        </td>
                        <td class="text-nowrap border-left-0">
                            {{$row->is_billing_closed}}
                        </td>
                        <td class="text-nowrap border-left-0">
                            {{$row->is_claiming_closed}}
                        </td>
                        <td class="text-nowrap border-left-0">
                            <pre>{{$row->claim_lines}}</pre>
                        </td>
                        <td class="text-nowrap border-left-0">
                            <pre>{{$row->bills}}</pre>
                        </td>
                        <td class="text-nowrap border-left-0">
                            <pre>{{$row->icds}}</pre>
                        </td>
                        <td class="text-nowrap border-left-0">
                            <pre>{{$row->claim_statuses}}</pre>
                        </td>
                    </tr>
                    @endforeach
                </tbody>
            </table>

        </div>
    </div>


</div>
    <?php
$loadedFilters = @$filters;
$allFilterKeys = [
	'no_claims',
	'zero_deductible',
	'claim_status',
	'verified'
];
for ($i=0; $i < count($allFilterKeys); $i++) {
	if (!isset($loadedFilters[$allFilterKeys[$i]]) || !$loadedFilters[$allFilterKeys[$i]]) {
		$loadedFilters[$allFilterKeys[$i]] = '';
	}
}
?>

@endsection