@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 expenses ?></h3>
            <br>



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

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

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

                  echo number_format($total_amount);

                ?>
              </h3>

              <p><a href="{{url('admin/expenses/')}}/{{$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>
		
		
		<?php 
$last_shift = \App\shifts::orderby('id','desc')->first();
?>
@if($last_shift)
    @if($last_shift->shift_end == null) <!-- This means the shift is open -->
        <!-- If shift is open, show Close Shift button -->

                    <a href="{{url('admin/expenses/create')}}" class="btn btn-primary">اضافة منصرف </a>

    @else
		
	        <form action="{{ url('/admin/shift/begin') }}" method="POST">
            @method('POST')
            @csrf
            <button onclick="return confirm(' بداية الوردية ؟ ');" style="border: 0px; color:black; background:none; cursor:pointer;">
                <i class="fas fa-plus"></i>  بداية وردية   
            </button>
        </form>          
		
        <!-- If shift is closed, show Begin Shift button -->
    @endif
@endif




        </td>
        <td>
                    <a href="{{url('admin/report_between')}}" class="btn btn-danger"> 
                        تقرير عن المنصرفات
                    </a>

        </td>
    </tr>
</table>


            <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>
                </tr>
                </thead>
                <tbody>

<?php
$expenses = $expenses->where('shift_id','0');
?>
@forelse($expenses as $expense)

                <tr>
                    <td> {{ $expense->id }}</td>
                    <td> {{ $expense->expense_date }} </td>
                    <td>{{ $expense->expense_name}} </td>
                    <td> {{ number_format($expense->expense_price) }} </td>
                    <td> {{ $expense->expense_note }} </td>


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

                    <td>
                        
                            <span class="btn btn-danger btn-sm" >
                                <form action="{{url('/admin/expenses')}}/{{ $expense->id }}" method="post">
                                    @method('DELETE')
                                    <button onclick="return confirm('هل انت متأكد ؟');" style="border: 0px; background:none; color: white">
                                        <i class="fas fa-trash"></i>
                                        حذف</button>
                                    @csrf
                                </form>


                            </span>
                        
                    </td>
                </tr>

    @empty

    <tr>
       <div style="color: red; font-size: 18px; font-weight: bolder;">لايوجد بيانات</div>
    </tr>

                @endforelse










                </tbody>

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




@endsection
