@php $cashBankCount=count($cashBanks); $cashCounter=count($cashBanks->where('type',1)); $bankCounter=count($cashBanks->where('type',2)); @endphp @if($cashCounter) @endif @if($bankCounter) @endif @forelse ($cashBanks->sortBy('type') as $cashBank) @php $opening[$cashBank->id]=0; $closing[$cashBank->id]=0; $total_receipt_arr[$cashBank->id]=0; $total_payment_arr[$cashBank->id]=0; $ledgerWiseBalanceSplited[$cashBank->id] = $ledgerWiseBalanceSplited[$cashBank->id]->merge(collect($ledgerWisePayments)->where('cb_id', $cashBank->id)); @endphp @empty @endforelse @forelse ($cashBanks->sortBy('type') as $cashBank) @empty @endforelse @php $total_receipt=0; $total_payment=0; @endphp @forelse ($ledgerWiseBalance as $m=>$receipt) @if($receipt['amount']<0) @php $l=count($ledgers->where('id',$receipt['ledger_id']))?$ledgers->where('id',$receipt['ledger_id'])->first():null; @endphp @forelse ($cashBanks->sortBy('type') as $cashBank) @php $amtArray=0; if(array_key_exists($cashBank->id,$ledgerWiseBalanceSplited)){ $ledgerAmount=$ledgerWiseBalanceSplited[$cashBank->id]->where('id',$receipt['ledger_id']); if(count($ledgerAmount)){ $amtArray=$ledgerAmount[$receipt['ledger_id']]['amount']; } } $total_receipt_arr[$cashBank->id]+=$amtArray; @endphp @empty @endforelse @php $total_receipt+=abs($receipt['amount']); @endphp @endif @empty @endforelse @forelse ($cashBanks->sortBy('type') as $cashBank) @empty @endforelse @php $newLedgerWiseBalance = []; $payments = collect(array_merge($ledgerWiseBalance->toArray(), $ledgerWisePayments))->groupBy('ledger_id'); foreach ($payments as $i => $items) { $temp = (array) $items->first(); $temp['amount'] = $items->sum('amount'); $newLedgerWiseBalance[] = $temp; } $ledgerWiseBalance = collect($newLedgerWiseBalance); @endphp @forelse ($ledgerWiseBalance as $m=> $receipt) @if($receipt['amount']>0) @php $l=count($ledgers->where('id', $receipt['ledger_id'])) ? $ledgers->where('id', $receipt['ledger_id'])->first() : null; @endphp @forelse ($cashBanks->sortBy('id') as $cashBank) @php $amtArray=0; if(array_key_exists($cashBank->id, $ledgerWiseBalanceSplited)) { $ledgerAmount = $ledgerWiseBalanceSplited[$cashBank->id]->where('amount', '>', 0)->where('ledger_id', $receipt['ledger_id']); if(count($ledgerAmount)) $amtArray = $ledgerAmount->sum('amount'); } $total_payment_arr[$cashBank->id] += $amtArray; @endphp @empty @endforelse @php $total_payment += abs($receipt['amount']); @endphp @endif @empty @endforelse @forelse ($cashBanks->sortBy('type') as $cashBank) @empty @endforelse @forelse ($cashBanks->sortBy('type') as $cashBank) @empty @endforelse
@php function getBalance($amount,$r=0){ if($r){ return ($amount<0)?number_format(abs($amount),2).' '.__('obs.cr'):number_format($amount,2); }else{ return ($amount<0)?'('.number_format(abs($amount),2).')':number_format($amount,2); } } $r_type=env("JOURNAL_BALANCE_TYPE", 1); $printData['start_date']=Request()->start_date?date('d-M-Y',strtotime(Request()->start_date)):date('d-M-Y'); $printData['end_date']=Request()->end_date?date('d-M-Y',strtotime(Request()->end_date)):date('d-M-Y'); // $printData['ledger_name']=count($ledgers->where('id',Request()->ledger_id))>0?$ledgers->where('id',Request()->ledger_id)->first()->name:'ledger not found'; $routeName=str_replace('_api','',Route::currentRouteName()); $printData=getPrintData($routeName,$printData); @endphp {!!$printData['head']!!}
{{__('obs.code')}} {{__('obs.particulars')}} {{__('obs.cash')}} {{__('obs.bank')}} {{__('obs.total')}}
{{$cashBank->name_eng}}
{{__('obs.opening_balance')}} @ {{-- {{Request()->start_date?date('d-M-Y',strtotime(Request()->start_date)):''}} --}} @if(array_key_exists($cashBank->account_id,$ledgerWiseBeginningBalanced)) {{getBalance($ledgerWiseBeginningBalanced[$cashBank->account_id]['amount'],$r_type)}} {{-- @if($r_type) {{($ledgerWiseBeginningBalanced[$cashBank->account_id]['amount']<0)?number_format(abs($ledgerWiseBeginningBalanced[$cashBank->account_id]['amount']),2).' '.__('obs.cr'):number_format($ledgerWiseBeginningBalanced[$cashBank->account_id]['amount'],2)}} @else {{($ledgerWiseBeginningBalanced[$cashBank->account_id]['amount']<0)?'('.number_format(abs($ledgerWiseBeginningBalanced[$cashBank->account_id]['amount']),2).')':number_format($ledgerWiseBeginningBalanced[$cashBank->account_id]['amount'],2)}} @endif --}} @php $opening[$cashBank->id]+=$ledgerWiseBeginningBalanced[$cashBank->account_id]['amount']; @endphp @else {{number_format(0,2)}} @endif {{getBalance(array_sum($opening),$r_type)}} {{-- {{number_format(array_sum($opening),2)}} --}}
    {{__('obs.receipt')}}
 {{$l?$l->auto_code:'-'}}  {{$l?$l->name:'-'}} {{abs($amtArray)}} {{number_format(abs($receipt['amount']),2)}}
{{__('obs.total_receipt')}}: {{number_format(abs($total_receipt_arr[$cashBank->id]),2)}} {{number_format(($total_receipt),2)}}
    {{__('obs.payment')}}:
 {{$l ? $l->auto_code : '-'}}  {{$l ? $l->name : '-'}} {{$amtArray}} {{number_format(abs($receipt['amount']),2)}}
{{__('obs.total_payment')}}: ({{number_format($total_payment_arr[$cashBank->id],2)}})( {{number_format($total_payment,2)}} )
{{__('obs.closing_balance')}}: @ {{-- {{Request()->end_date?date('d-M-Y',strtotime(Request()->end_date)):''}} --}} @if(array_key_exists($cashBank->account_id, $ledgerWiseEndingBalance)) {{getBalance($ledgerWiseEndingBalance[$cashBank->account_id]['amount'], $r_type)}} {{-- @if($r_type) {{($ledgerWiseEndingBalance[$cashBank->account_id]['amount']<0)?number_format(abs($ledgerWiseEndingBalance[$cashBank->account_id]['amount']),2).' '.__('obs.cr'):number_format($ledgerWiseEndingBalance[$cashBank->account_id]['amount'],2)}} @else {{($ledgerWiseEndingBalance[$cashBank->account_id]['amount']<0)?'('.number_format(abs($ledgerWiseEndingBalance[$cashBank->account_id]['amount']),2).')':number_format($ledgerWiseEndingBalance[$cashBank->account_id]['amount'],2)}} @endif --}} @php $closing[$cashBank->id]+=$ledgerWiseEndingBalance[$cashBank->account_id]['amount']; @endphp @else {{ number_format(0,2) }} @endif {{getBalance(array_sum($closing),$r_type)}} {{-- {{number_format(array_sum($closing),2)}} --}}
{!!$printData['foot']!!}