 <div class="table-responsive">
  <table id="example" class="table table-bordered align-middle" style="width:100%">
    <thead class="table-light">
      <tr>
        <th>Sl No</th>
        <th>Doctor Name (Dr. Code)</th>
        <th style="text-align: right;">Basic Amount</th>
        <th style="text-align: right;">Total Commission Amount</th>
    </tr>
</thead>
<tbody>
    @php $auth_format = \Session::get('company_data')['date_format'] ?? ''; @endphp
    @php $i=1; @endphp
    @if(count($data)>0)
        @foreach($data as $key=> $row)
            <tr>
                <td>{{ $i }}</td>
                <td>
                    {{ $row['doctor'] }}
                </td>
                @php
                    $total_basic_amount = $total_commission = 0 ;
                @endphp
                @foreach($row['vouchers'] as $value)
                    @php
                        $incentive_setting = !empty($incentive_settings[$value->product_id]) ? $incentive_settings[$value->product_id] : [];

                        $amount = $value->basic_amount ?? 0 ;
                        $discount   = !empty($value->discount_amount) ? $value->discount_amount : (!empty($value->sale_discount_amount) ? $value->sale_discount_amount : '0');
                        $amount     = $amount - $discount;
                        $commission = 0 ;

                        if (!empty($value->calculation_type) && (!empty($value->percentage) || !empty($value->price))) {
                            $type       = $value->calculation_type ?? '' ;
                            $percentage = $value->percentage ?? 0 ;
                            $price      = $value->price ?? 0 ;
                            $commission = 0 ;

                            if ($type == 'quantity') {
                                $commission = $price;
                            } else if ($type == 'percentage') {
                                $commission = ($percentage / 100) * $amount;
                            }
                        } else if (!empty($incentive_setting)) {
                            $type = $incentive_setting->calculation_type != '' ? $incentive_setting->calculation_type : ($incentive_setting->default_calculation_type ?? '') ;
                            $percentage = $incentive_setting->percentage != '' ? $incentive_setting->percentage : ($incentive_setting->default_percentage ?? '0') ;
                            $price = $incentive_setting->price != '' ? $incentive_setting->price : ($incentive_setting->default_price ?? '0') ;
                            $commission = 0 ;

                            if ($type == 'quantity') {
                                $commission = $price;
                            } else if ($type == 'percentage') {
                                $commission = ($percentage / 100) * $amount;
                            }
                        } else if (!empty($incentive_slab)) {
                            $type = $incentive_slab->calculation_type != '' ? $incentive_slab->calculation_type : '' ;
                            $percentage = $incentive_slab->percentage != '' ? $incentive_slab->percentage : '0' ;
                            $price = $incentive_slab->price != '' ? $incentive_slab->price : '0' ;
                            $commission = 0 ;

                            if ($type == 'quantity') {
                                $commission = $price;
                            } else if ($type == 'percentage') {
                                $commission = ($percentage / 100) * $amount;
                            }
                        }

                        $total_basic_amount += $amount;
                        $total_commission += $commission;
                    @endphp
                @endforeach
                <td style="text-align: right;">{{ $total_basic_amount }}</td>
                <td style="text-align: right;">{{ $total_commission }}</td>
            </tr>
            @php $i++; @endphp
        @endforeach
    @else
        <tr>
            <td colspan="10">No Data Found</td>
        </tr>
    @endif
</tbody>
</table>
</div>
<nav class="float-start mt-2">
    <ul class="pagination">
        {{-- {!! $data->onEachSide(0)->render('financialyear.pagination') !!} --}}
    </ul>
</nav>
</div>

