@php
        $sr = 1;
        $totalBillAmount = 0;
        $totalCreditBillAmount = 0;
        $totalReceiptAmount = 0;
        $totalCshAmount = 0;
        $totalCrdAmount = 0;
        $totalDbtAmount = 0;
        $totalChqAmount = 0;
        $totalNeftAmount = 0;
        $totalWalletAmount = 0;
        @endphp
        @foreach($billData as $bill)
        @php
        $cshAmount = 0;
        $crdAmount = 0;
        $dbtAmount = 0;
        $chqAmount = 0;
        $neftAmount = 0;
        $walletAmount = 0;
        $patOrCustName = ($bill->patient_name != '') ? $bill->patient_id." / ".$bill->patient_name : '*'.$bill->ph_cust_id." / ".$bill->ph_cust_name; 
        $headerBillAmount = ($bill->trn_type == 'I') ? $bill->total : $bill->total  * (-1);
        $paymentMode = $bill->payment_mode;
        if($bill->is_credit_bill == 'Y'){
        $creditBillAmount = $headerBillAmount;
        $billAmount = '';
        }else{
        $creditBillAmount = '';
        $billAmount = $headerBillAmount;
        if($paymentMode == 'CSH'){
        $cshAmount += $headerBillAmount;
        $totalCshAmount += $cshAmount;
        }else if($paymentMode == 'CRD'){
        $crdAmount += $headerBillAmount;
        $totalCrdAmount += $crdAmount;
        }else if($paymentMode == '2'){
        $dbtAmount += $headerBillAmount;
        $totalDbtAmount += $dbtAmount;
        }else if($paymentMode == '3'){
        $walletAmount += $headerBillAmount;
        $totalWalletAmount += $walletAmount;
        }else if ($paymentMode == 'CHQ'){
        $chqAmount += $headerBillAmount;
        $totalChqAmount += $chqAmount;
        }else if($paymentMode == '1'){
        $neftAmount += $headerBillAmount;
        $totalNeftAmount += $neftAmount;
        }
        }
        $totalCreditBillAmount = $totalCreditBillAmount + $creditBillAmount;
        $totalBillAmount = $totalBillAmount + $billAmount;
        if(strtoupper($bill->payment_agency != '')){
        $message = $bill->gm_description.",".strtoupper($bill->payment_agency).",".strtoupper($bill->payment_number);
        }else{
        $message = $bill->gm_description;
        }
        @endphp
        
            | {{$sr++}} | 
            {{$bill->trn_type."".$bill->trn_id}}   | 
            {{\Helper::getDisplayDate($bill->bill_date)}}   | 
            {{$patOrCustName}} | 
            {{$message}} | 
            {{ \Helper::customAmountFormat($neftAmount) }} | 
            {{ \Helper::customAmountFormat($walletAmount) }} | 
            {{ \Helper::customAmountFormat($chqAmount) }} | 
            {{ \Helper::customAmountFormat($crdAmount) }} | 
            {{ \Helper::customAmountFormat($dbtAmount) }} | 
            {{ \Helper::customAmountFormat($cshAmount) }} | 
              {{ $bill->created_by }} | 
        
  
        @endforeach
        @foreach($receiptData as $receipt)
        @php
        $receiptCash = 0;
        $receiptCheque = 0;
        $receiptCredit = 0;
        $receiptDebit = 0;
        $receiptNeft = 0;
        $receiptWallet = 0;
        $receiptAmount = $receipt->receipt_amount;
        if(strtoupper($receipt->payment_agency != '')){
        $message = $receipt->gm_description.", ".strtoupper($receipt->payment_agency).", ".strtoupper($receipt->payment_number)." towards Bills ".$receipt->bill_no ;
        }else{
        $message = $receipt->gm_description." towards Bills ".$receipt->bill_no;
        }
        $totalBillAmount += $receiptAmount;
        $totalReceiptAmount += $receiptAmount;
        $patOrCustName = ($receipt->patient_name != '') ? $receipt->patient_id." / ".$receipt->patient_name : '*'.$receipt->ph_cust_id." / ".$receipt->ph_cust_name; 
        if($receipt->payment_mode == 'CSH'){
        $receiptCash = $receiptAmount;
        $totalCshAmount += $receiptAmount;
        }else if($receipt->payment_mode == 'CHQ'){
        $receiptCheque = $receiptAmount;
        $totalChqAmount += $receiptAmount;
        }else if($receipt->payment_mode == 'CRD'){
        $receiptCredit = $receiptAmount;
        $totalCrdAmount += $receiptAmount;
        }else if($receipt->payment_mode == '2'){
        $receiptDebit = $receiptAmount;
        $totalDbtAmount += $receiptAmount;
        }else if($receipt->payment_mode == '3'){
        $receiptWallet = $receiptAmount;
        $totalWalletAmount += $receiptAmount;
        }else if($receipt->payment_mode == '1'){
        $receiptNeft = $receiptAmount;
        $totalNeftAmount += $receiptAmount;
        }
        @endphp
        
            | {{$sr++}} | 
            {{$receipt->trn_receipt_no}}   | 
            {{$patOrCustName}} | 
            {{$message}} | 
            {{ \Helper::customAmountFormat($receiptNeft) }} | 
            {{ \Helper::customAmountFormat($receiptWallet) }} | 
            {{ \Helper::customAmountFormat($receiptCheque) }} | 
            {{ \Helper::customAmountFormat($receiptCredit) }} | 
            {{ \Helper::customAmountFormat($receiptDebit) }} | 
            {{ \Helper::customAmountFormat($receiptCash) }} | 
              {{ $receipt->created_by }} | 
        
        @endforeach
        
            | Total : | 
            {{ \Helper::customAmountFormat($totalNeftAmount) }} | 
            {{ \Helper::customAmountFormat($totalWalletAmount) }} | 
            {{ \Helper::customAmountFormat($totalChqAmount) }} | 
            {{ \Helper::customAmountFormat($totalCrdAmount) }} | 
            {{ \Helper::customAmountFormat($totalDbtAmount) }} | 
            {{ \Helper::customAmountFormat($totalCshAmount) }} | 
             | 
             |