@extends('layouts.admin')

@section('content')


@section('content-actions')

<div style="position: relative; left: 50%;">

</div>


@endsection

    <div class="card">
        <div class="card-header">
            <h3 class="card-title"><?php //List of banks ?></h3>
            <br>




     
<?php /*
        <div class="row">
@foreach($products as $r)
        <!-- ./col -->
        <div class="col-lg-3 col-xs-6">
          <!-- small box -->
          <div class="small-box bg-red">
            <div class="inner" style="text-align: center;">
              <h3>
                <?php
                  $s_accounts = \App\banks::where('id',$r->id)->get();
                  $total_amount = 0;    

                  foreach($s_accounts as $r2)  {
                    $total_amount = $total_amount + $r2->banks_price;
                  }

                  echo number_format($total_amount);

                ?>
              </h3>

              <p><a href="{{url('admin/banks/')}}/{{$r->id}}" style="text-decoration: none; color: white; cursor: pointer;">اجمالي {{$r->title}}</a></p>
            </div>
            <div class="icon">
              <i class="ion ion-stats-bars"></i>
            </div>
          </div>
        </div>

@endforeach
        </div> <!-- End of Row -->
*/ ?>

        </div>

       




        <!-- /.card-header -->
        <div class="card-body">


            <table style="">
    <tr>
        <td>
                    <a href="{{url('admin/banks/create')}}" class="btn btn-primary">اضافة حساب </a>
                    <a href="{{url('transfer')}}" class="btn btn-primary"> تحويل بين الحسابات  </a>
        </td>
      



    </tr>
</table>
<br>

            <table id="example1" class="table table-bordered table-striped" style="">
                <thead>
                <tr>

                    <th>#</th>
                    <th>التاريخ</th>
                    <th> اسم الحساب  </th>

                    <th> الرصيد   </th>
                    <th>  سحب    </th>
                    <th>    ايداع    </th>
                    <th>تعديل</th>
                    <th>حذف</th>
                </tr>
                </thead>
                <tbody>

@forelse($banks as $banks)

                <tr>
                    <td> {{ $banks->id }}</td>
                    <td> {{ $banks->created_at }}</td>
                    <td> 

                        <a href="{{url('details')}}/banks/{{$banks->id}}"> 
                        {{ $banks->bank}}
                        </a>

                     </td>


                        <?php

                        $the_method = "";
                        $balance = 0;

                        if($banks->id == 3) {
                        $transactions = \App\transactions::where('payment_method','cash')->get();
                        }
                       
                       else if($banks->id == 4) {
                        $transactions = \App\transactions::where('payment_method','bankak')->get();

                        }                        

                       else if($banks->id == 1) {
                            $transactions = \App\transactions::all();
                        }


                       else if($banks->id > 4) {
                            $transactions = \App\transactions::where('trans_type','banks')
                            ->where('trans_type_id',$banks->id)->get();
                        }


                        foreach($transactions as $trans) {

                        if($trans->type == "depit"){
                            $balance = $balance - $trans->amount;
                        }

                        if($trans->type == "credit"){
                            $balance = $balance + $trans->amount;
                        }

                        }

                        ?>



                    <?php 
                    // <td>{{ number_format($banks->balance,0)}} </td>
                    ?>
                    <td>{{ number_format($balance,0)}} 

                        <?php 
                            $balance = 0;
                        ?>
                    </td>


                    <td>
                    @if($banks->id <> 1)
                        <a href="{{url('operation/depit')}}/{{$banks->id}}" style="font-weight: bolder; color: red;"> 
                        سحب 
                        </a>
                    @endif
                    </td>



                    <td>
                    @if($banks->id <> 1)
                        <a href="{{url('operation/credit')}}/{{$banks->id}}" style="font-weight: bolder; color: green;"> 
                        ايداع  
                        </a>
                    @endif
                    </td>

                    <td>
                    @if($banks->id > 4)
                        <a class="btn btn-info btn-sm" href="{{url('/admin/banks')}}/{{$banks->id}}/edit">
                            <i class="fas fa-pencil-alt">
                            </i>
                            تعديل
                        </a>
                    @endif
                    </td>

                    <td>
                        
                    @if($banks->id > 4)

                            <span class="btn btn-danger btn-sm" >
                                <form action="{{url('/admin/banks')}}/{{ $banks->id }}" method="post">
                                    @method('DELETE')
                                    <button onclick="return confirm('Are you sure you want to delete this ?');" style="border: 0px; background:none; color: white">
                                        <i class="fas fa-trash"></i>
                                        Delete</button>
                                    @csrf
                                </form>


                            </span>
                    @endif
                    </td>
                </tr>

    @empty

    <tr>
       <div style="color: red; font-size: 18px; font-weight: bolder;">No Data Available</div>
    </tr>

                @endforelse










                </tbody>

            </table>
        </div>
        <!-- /.card-body -->
    </div>




@endsection
