@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 
    $trans_type = Request::segment('2');
    $bank_id = Request::segment('3');
?>

     
<?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">

<h1 style="text-align: center;"> 
<?php
    if($trans_type == "banks") {
        echo \App\banks::where('id',$bank_id)->first()->bank;    
    }
?>
 </h1>


<?php 
   //  $transactions = \App\transactions::where('trans_type',$trans_type)->where('trans_type_id',$bank_id)->get();


    $customer_orders = \App\Models\Order::where('customer_id',Request::segment(3))->get();

    foreach ($customer_orders as $order) {

    $transactions = \App\transactions::where('type','sale')
                    ->where('trans_type_id',$order->id)
                    ->orWhere('type','customers')
                    ->where('');

   // dd($transactions);
?>
            <table id="example1" class="table table-bordered table-striped" style="">
                <thead>
                <tr>

                    <th>#</th>

                    <th>التاريخ</th>

                    <th>  سحب    </th>
                    <th>    ايداع    </th>

                    <th style="width: 27%;">  ملاحظـــات  </th>

                    <th>الرصيد </th>


                </tr>
                </thead>
                <tbody>

<?php 
    $balance = 0;
?>

@forelse($transactions as $transactions)

                <tr>
                    <td> {{ $transactions->id }}</td>

                    <td> {{ $transactions->created_at }}</td>

                    <td style="color: red; font-weight: bolder;"> 

                        <?php
                        if($transactions->type == "depit"){
                            echo number_format($transactions->amount,0);
                        }
                        ?>

                    </td>

                    <td style="font-weight: bolder; color: green;"> 

                        <?php
                        if($transactions->type == "credit"){
                            echo number_format($transactions->amount,0);
                        }
                        ?>

                    </td>

                    <td>
                        {{ $transactions->notes}} 

                        <?php
                        if($transactions->trans_type == "sale" or $transactions->trans_type == "purchase" ){ ?>

-
<a href="#" onclick="window.open('<?php echo url('admin/ticket/'); ?>/<?php echo $transactions->trans_type_id; ?>','','width=400,height=500');">
 اضغط هنا لعرض تفاصيل الفاتورة  رقم  - 
    {{$transactions->trans_type_id}}


</a>

                        <?php } ?>
                    </td>

                    <td style="font-weight: bolder;"> 

                        <span style="color: red;">

                        <?php
                        if($transactions->type == "depit"){
                            $balance = $balance - $transactions->amount;
                        echo number_format($balance,0);

                        ?>
                        </span>

                        <?php 
                        }

                        ?>

                        <span style="color: green;">

                        <?php 
                        if($transactions->type == "credit"){
                            $balance = $balance + $transactions->amount;
                        echo number_format($balance,0);
                        }

                        ?>
                     </span>

                    </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
