<div id="print_div">
    <div class="pathology-bill">
        <div class="row">
            <div class="col-md-12 col-xs-12 p-1">
                <div class="card border-0">
                    <div class="card-body">
                        <div class="row" style="margin-top: 5px;">
                            <x-MiniLetterHead :fromDate="$from_date" :toDate="$to_date" :companyName="$company->name" :voucherTitle="@$voucher_type->voucher_title" />
                            <div class="col-12">
                                <table class="table table-borderless report-container">
                                    <tbody class="report-content">
                                        <tr>
                                            <td class="report-content-cell">
                                                <div class="row">
                                                    <div class="col-12">
                                                        <table class="table table-bordered-print w-100 table-only-header-full-width mb-1" id="quotation_products">

                                                            <thead>
                                                                <tr class="text-uppercase">
                                                                    <th style="text-align: left;">Sl.No</th>
                                                                    <th style="text-align: left;">Date </th>
                                                                    <th style="text-align: left;">Account Name</th>
                                                                    <th style="text-align: left;">Voucher Type</th>
                                                                    <th style="text-align: left;">Transaction Reff. </th>
                                                                    <th style="text-align: left;">Transaction Mode </th>
                                                                    <th style="text-align: left;">Payment Mode </th>
                                                                    <th style="text-align: right;">Amount</th>
                                                                </tr>
                                                            </thead>
                                                            <tbody>
                                                                @if(isset($paymentVoucher) && count($paymentVoucher) > 0)
                                                                @php $i = 1; $totalByTransactionMode = []; @endphp
                                                                 
                                                                @php $grand_total = 0; $totalCash = $totalNeft = $totalCheque = $totalUPI = $totalPaymentGateway = $totalOther = 0; @endphp
                                                                @foreach($paymentVoucher as $payment)
                                                                @if(isset($payment->paymentVoucherDetails)&&count($payment->paymentVoucherDetails)>0)
                                                                @foreach($payment->paymentVoucherDetails as $key => $transactions)
                                                                @php
                                                                if($transactions->transaction_type == 'DEBIT') {
                                                                continue;
                                                                }
                                                             $totalByTransactionMode[$transactions->account->name??''][$transactions->payment_mode->mode??''] = ($totalByTransactionMode[$transactions->account->name??''][$transactions->payment_mode->mode??''] ?? 0) + $transactions->amount; 
                                                                if($transactions->amount < 1) { continue; } @endphp <tr>
                                                                    @if($key == 1)
                                                                    @php
                                                                    $count = @count($payment->paymentVoucherDetails) ?? 0;
                                                                    @endphp
                                                                    <td style="text-align: left;" rowspan="{{$count-1}}">{{ $i }}</td>
                                                                    <td style="text-align: left;" rowspan="{{$count-1}}">{{ formatedDate($transactions->transaction_date) ?? '' }}</td>
                                                                    <td style="text-align: left;" rowspan="{{$count-1}}">
                                                                        {!! $payment->paymentVoucherDetail->account->account_title->name??null !!}
                                                                        {!! $payment->paymentVoucherDetail->account->name ?? '' !!}
                                                                    </td>
                                                                    <td style="text-align: left;" rowspan="{{$count-1}}">{{ $payment->paymentVoucherDetail->voucher_type ?? '' }}</td>
                                                                    <td style="text-align: left;" rowspan="{{$count-1}}">{{ $transactions->transaction_referrence ?? '' }}</td>
                                                                    @endif

                                                                    <td style="text-align: left;">{{ $transactions->account->name ?? '' }}</td>
                                                                    <td style="text-align: left;">{{ $transactions->payment_mode->mode ?? '' }}</td>
                                                                    <td style="text-align: right;">
                                                                        {{ isset($transactions->amount) && $transactions->amount > 0 ? convertDecimelPoint($transactions->amount) : "0" }}
                                                                    </td>
                                        </tr>
                                        @php
                                        $i += 1;
                                        $grand_total = $grand_total + $transactions->amount;
                                        @endphp
                                        @endforeach
                                        @endif

                                        @endforeach
                                       
                                        @foreach ($totalByTransactionMode as $transactionMode => $paymentModes)
                                            <tr>
                                                <td colspan="7" style="text-align: right; text-transform: uppercase;border-right:none !important"><b>{{ $transactionMode }} SUMMARY</b></td>
                                                <td style="border-left:none !important"></td>
                                            </tr>
                                            @foreach ($paymentModes as $paymentMode => $total)
                                                <tr>
                                                    <td colspan="7"  style="text-align: right; text-transform: uppercase;">TOTAL {{ $paymentMode }}</td>
                                                    <td style="text-align: right;"><b>{{$total}}</b></td>
                                                </tr>
                                            @endforeach
                                        @endforeach

                                        <tr>
                                            <td colspan="7" style="text-align: right;"><b>Grand Total</b></td>
                                            <td style="text-align: right;"><b>{!! convertDecimelPoint($grand_total) !!}</b></td>
                                        </tr> 
                                        @else
                                        <tr>
                                            <td colspan="10">No Data Found</td>
                                        </tr>
                                        @endif
                                    </tbody>
                                </table>
                            </div>
                        </div>
                        </td>
                        </tr>
                        </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
</div>
</div>
@if(isset($paymentVoucher) && count($paymentVoucher) > 0)
<div class="row">
    <div class="col-md-6" style="text-align: right;">
        <button id="btn_print" type="button" class="btn btn-primary btn-lg"><i class="bi bi-printer text-white"></i> Print Statement </button>
    </div>

    <div class="col-md-6" style="text-align: left;">
        <a href="javascript:;" class="btn btn-outline-primary export-statement"><i class="bi bi-download"></i> Export</a>
    </div>
</div>
@endif