@extends('layouts.admin')

@section('content')


@section('content-actions')

<div style="position: relative; left: 50%;">
<table style="">
    <tr>
        <td>
                    <a href="{{url('admin/purchases/create')}}" class="btn btn-primary">Add purchases</a>
        </td>
      

        <td style="display: none;">
                    <a href="{{url('admin/report_between')}}" class="btn btn-danger">{{__('Report On purchases')}}</a>

        </td>


    </tr>
</table>
</div>


@endsection

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



<?php 
$products = \App\purchases::all();
?>

     
<?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\purchases::where('id',$r->id)->get();
                  $total_amount = 0;    

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

                  echo number_format($total_amount);

                ?>
              </h3>

              <p><a href="{{url('admin/purchases/')}}/{{$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 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>
                    <th>  المتبقي  </th>
                    <th>تعديل</th>
                    <th>حذف</th>
                </tr>
                </thead>
                <tbody>

@forelse($purchases as $purchases)

                <tr>
                    <td> {{ $purchases->id }}</td>
                    <td> {{ $purchases->created_at }}</td>
                    <td> {{ $purchases->customers->first_name." ".$purchases->customers->last_name }} </td>
                    <td> {{ $purchases->title }} </td>
                    <td>{{ $purchases->price}} </td>
                    <td>{{ $purchases->quantity}} </td>
                    <td> {{ number_format($purchases->price * $purchases->quantity) }} </td>
                    <td> {{ $purchases->customers->paid }} </td>
                    <td> {{  ($purchases->price * $purchases->quantity) - $purchases->customers->paid }} </td>


                    <td>

                      <a onclick="return confirm('<?php echo __('new payment ?') ?>');" href="{{url('customers/paid')}}/{{$purchases->customer_id}}">
                          <span class="badge badge-info"><i class="fas fa-plus"></i> new pay </span>
                        </a>



                    </td>

                    <td>
                        
                            <span class="btn btn-danger btn-sm" >
                                <form action="{{url('/admin/purchases')}}/{{ $purchases->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>
                        
                    </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
