@extends('layouts.organisation')

@section('page-title')
    Organisation | Dashboard
@endsection

@section('page-content')

<!-- start page title -->
<div class="row">
    <div class="col-12">
        <div class="page-title-box">
            <div class="page-title-right">
                <form class="form-inline">
                    <div class="form-group">
                        <!-- <div class="input-group">
                            <input type="text" class="form-control form-control-light" id="dash-daterange">
                            <div class="input-group-append">
                                <span class="input-group-text bg-info border-info text-white">
                                    <i class="mdi mdi-calendar-range font-13"></i>
                                </span>
                            </div>
                        </div> -->
                    </div>
                </form>
            </div>
            <h4 class="page-title">Dashboard</h4>
        </div>
    </div>
</div>
<!-- end page title -->

{{-- Alert --}}
@include('layouts.alert')

<div class="row">
    <div class="col-md-6">
        <div class="card">
            <!-- top up merchants here  -->
        </div>
        <div class="card widget-flat">
            <div class="card-body">
                <div class="float-right">
                    <i class="mdi mdi-cart-plus widget-icon bg-danger-lighten text-danger"></i>
                </div>
                <h5 class="text-muted font-weight-normal mt-0" title="Number of Orders">Current Balance</h5>
                <h3 class="mt-3 mb-3">{{ number_format($organisation->balance, 2) }}</h3>
                <!-- <p class="mb-0 text-muted">
                    <span class="text-danger mr-2"><i class="mdi mdi-arrow-down-bold"></i> 1.08%</span>
                    <span class="text-nowrap">Since last month</span>
                </p> -->
                <form action="{{ url('organisation/topup') }}" method="POST" >
                    {{csrf_field()}}
                    
                    <div class="form-row">
                        <div class="form-group col-md-12">
                            <label for="merchant" class="col-form-label">Select Account to Top Up</label>
                            <select required class="form-control" name="merchant" id="merchant" placeholder="Merchant" >
                                <option>-- Select Account --</option>
                                <?php foreach ($merchants as $row): ?>
                                    <option value="{{ $row->id }}">{{ $row->fullname }} ({{ $row->phone }}) </option>      
                                <?php endforeach ?>
                            </select>
                        </div>
                    </div>
                    <div class="form-row">
                        <div class="form-group col-md-12">
                            <label for="amount" class="col-form-label">Amount</label>
                            <input type="number" required class="form-control" name="amount" value="{{ old('amount') }}" id="amount" placeholder="Amount">
                        </div>
                    </div>
                    <button type="submit" class="btn btn-primary btn-block">Submit </button>
                    <button type="reset" class="btn btn-danger btn-block">Reset</button>

                </form>
            </div> <!-- end card-body-->
        </div> <!-- end card-->
    </div>
    <div class="col-md-6">
        <div class="card">
            <div class="card-body">
                <h3 class="header-title mt-2">Total Transactions : {{ $transaction_count }}</h3>
                <h4 class="header-title mt-2">Recent Transactions</h4>

                <div class="table-responsive">
                    <table class="table table-centered table-nowrap table-hover mb-0">
                        <tbody>

                            @forelse ($merchant_topups as $transaction)
                            <tr>
                                <td>
                                    <h5 class="font-14 my-1 font-weight-normal">@if($transaction->merchantInfo) {{ $transaction->merchantInfo->fullname }} @else N/A @endif</h5>
                                    <span class="text-muted font-13"><strong>Merchant</strong></span>
                                </td>
                                <td>
                                    <h5 class="font-14 my-1 font-weight-normal">K {{ $transaction->amount }}</h5>
                                    <span class="text-muted font-13"><strong>Amount</strong></span>
                                </td>
                                <td>
                                <!-- <h5 class="font-14 my-1 font-weight-normal">{{ Carbon\Carbon::parse($transaction->created_at)->format('F dS Y') }}</h5> -->
                                <h5 class="font-14 my-1 font-weight-normal">{{ $transaction->created_at }}</h5>
                                    <span class="text-muted font-13"><strong>Date</strong></span>
                                </td>
                            </tr>
                            @empty
                            @endforelse
                        </tbody>
                    </table>
                </div> <!-- end table-responsive-->
            </div> <!-- end card-body-->
        </div> <!-- end card-->
    </div> <!-- end col-->

   

</div>
<!-- end row -->
@endsection

@section('page-js')

<!-- third party js -->
<script src="{{ url('public/assets/js/vendor/apexcharts.min.js')}}"></script>
<script src="{{ url('public/assets/js/vendor/jquery-jvectormap-1.2.2.min.js')}}"></script>
<script src="{{ url('public/assets/js/vendor/jquery-jvectormap-world-mill-en.js')}}"></script>
<!-- third party js ends -->

<!-- demo app -->
<script src="{{ url('public/assets/js/pages/demo.dashboard.js')}}"></script>
<!-- end demo js-->
    
@endsection