<!doctype html>
<html lang="en" data-layout="vertical" data-topbar="light" data-sidebar="dark" data-sidebar-size="lg" data-sidebar-image="none" data-preloader="disable">

<head>
    <meta charset="utf-8" />
    <title>APDC Homes</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta content="Premium Multipurpose Admin & Dashboard Template" name="description" />
    <meta content="Themesbrand" name="author" />
    <!-- App favicon -->
    <link rel="shortcut icon" href="assets/images/favicon.ico">

    <!-- jsvectormap css -->
    <link href="assets/libs/jsvectormap/css/jsvectormap.min.css" rel="stylesheet" type="text/css" />

    <!--Swiper slider css-->
    <link href="assets/libs/swiper/swiper-bundle.min.css" rel="stylesheet" type="text/css" />

    <!-- Layout config Js -->
    <script src="assets/js/layout.js"></script>
    <!-- Bootstrap Css -->
    <link href="assets/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
    <!-- Icons Css -->
    <link href="assets/css/icons.min.css" rel="stylesheet" type="text/css" />
    <!-- App Css-->
    <link href="assets/css/app.min.css" rel="stylesheet" type="text/css" />
    <!-- custom Css-->
    <link href="assets/css/custom.min.css" rel="stylesheet" type="text/css" />

</head>

<body>

<!-- Begin page -->
<div id="layout-wrapper">

    @include('includes.header-topbar')


    <div class="app-menu navbar-menu">
        <!-- LOGO -->
        <div class="navbar-brand-box">
            <!-- Dark Logo-->
            <a href="index.html" class="logo logo-dark">
                <img src="assets/images/logo-dark.png" alt="">
            </a>
            <!-- Light Logo-->
            <a href="index.html" class="logo logo-light">
                    <span class="logo-sm">
                        <img src="assets/images/logo-sm.png" alt="" height="22">
                    </span>
                {{--<span class="logo-lg">
                            <img src="assets/images/logo-light.png" alt="" height="17">
                        </span>--}}
            </a>
            <button type="button" class="btn btn-sm p-0 fs-20 header-item float-end btn-vertical-sm-hover" id="vertical-hover">
                <i class="ri-record-circle-line"></i>
            </button>
        </div>

        @include('includes.admin-sidebar')

        <div class="sidebar-background"></div>
    </div>



    <!-- Left Sidebar End -->
    <!-- Vertical Overlay-->
    <div class="vertical-overlay"></div>

    <!-- ============================================================== -->
    <!-- Start right Content here -->
    <!-- ============================================================== -->


    <div class="main-content">

        <div class="page-content">
            <div class="container-fluid">

                <!-- start page title -->
                <div class="row">
                    <div class="col-12">
                        <div class="page-title-box d-sm-flex align-items-center justify-content-between">
                            <h4 class="mb-sm-0">Approvals</h4>

                            <div class="page-title-right">
                                <ol class="breadcrumb m-0">
                                    <li class="breadcrumb-item"><a href="javascript: void(0);">Dashboard</a></li>
                                    <li class="breadcrumb-item active">Approvals</li>
                                </ol>
                            </div>

                        </div>
                    </div>
                </div>
                <!-- end page title -->

                <!--end row-->



                <div class="card" id="contactList">
                    <div class="card-header">
                        <div class="row align-items-center g-3">
                            <div class="col-md-3">
                                <h5 class="card-title mb-0">Approvals</h5>
                            </div>
                            <!--end col-->
                            <div class="col-md-auto ms-auto">
                                <div class="d-flex gap-2">
                                    <div class="search-box">
                                        <input type="text" class="form-control search" placeholder="Search for transactions...">
                                        <i class="ri-search-line search-icon"></i>
                                    </div>
                                    <button class="btn btn-success"><i class="ri-equalizer-line align-bottom me-1"></i> Filters</button>
                                </div>
                            </div>
                            <!--end col-->
                        </div>
                        <!--end row-->
                    </div>
                    <!--end card-header-->
                    <div class="card-body">
                        <div class="table-responsive table-card">

                            @if(session('success'))
                                <div class="alert alert-success mb-xl-0" role="alert">
                                    {{ session('success') }}
                                </div>
                            @endif

                            <table class="table align-middle table-nowrap" id="customerTable">
                                <thead class="table-light text-muted">
                                <tr>
                                    <th class="sort" data-sort="date" scope="col">Number</th>
                                    <th class="sort" data-sort="date" scope="col">Creation Date</th>
                                    <th class="sort" data-sort="currency_name" scope="col">Customer</th>
                                    <th class="sort" data-sort="to_name" scope="col">House Type</th>
                                    <th class="sort" data-sort="amount" scope="col">Project</th>
                                    <th class="sort" data-sort="status" scope="col">Amount</th>
                                    <th class="sort" data-sort="status" scope="col">Percentage Paid</th>
                                    <th class="sort" data-sort="status" scope="col">Payment Status</th>
                                    <th class="sort" data-sort="status" scope="col">Handover Status</th>
                                    <th class="sort" data-sort="status" scope="col">Action</th>
                                </tr>
                                <!--end tr-->
                                </thead>
                                <tbody class="list form-check-all">

                                @foreach($sales as $sale)
                                    @if($sale->percentage_paid > 99)
                                    <tr>
                                        <td class="id" style="display:none;"><a href="javascript:void(0);" class="fw-medium link-primary">#VZ001</a></td>

                                        <td class="date">{{$sale->order_id ?? ''}}</small></td>
                                        <td class="currency_name">
                                            {{ \Carbon\Carbon::parse($sale->date_order)->format('d-m-Y') ?? '' }}
                                        </td>
                                        <td class="form_name">{{$sale->customer_name ?? ''}}</td>
                                        <td class="type">{{$sale->house_type ?? ''}}</td>
                                        <td class="type">{{$sale->project ?? ''}}</td>
                                        <td>
                                            <p class="text-muted mb-0">₦ {{number_format($sale->amount ?? 0)}}</p>
                                        </td>
                                        <td>
                                            <p class="text-muted mb-0"> {{number_format($sale->percentage_paid, 0) ?? ''}} %</p>
                                        </td>

                                        <td class="status">
                                            @if($sale->percentage_paid > 99 )
                                                <span class="badge bg-warning-subtle text-success fs-11"><i class="ri-time-line align-bottom"></i> Fully Paid</span>
                                            @endif
                                        </td>
                                        <td class="status">
                                            @if($sale->percentage_paid > 99 )
                                                <span class="badge bg-warning-subtle text-success fs-11"><i class="ri-time-line align-bottom"></i> {{$sale->handover_status ?? 'Pending'}}</span>
                                            @endif
                                        </td>
                                        <td>
                                            <div class="dropdown">
                                                <a href="javascript:void(0);" class="btn btn-light btn-icon" id="dropdownMenuLink15" data-bs-toggle="dropdown" aria-expanded="false">
                                                    <i class="ri-equalizer-fill"></i>
                                                </a>
                                                <ul class="dropdown-menu dropdown-menu-end" aria-labelledby="dropdownMenuLink15" style="">
                                                    <form id="initiateOfferForm" method="post" action="{{ route('view-sale-order') }}">
                                                        @csrf
                                                        <input type="hidden" name="id" value="{{$sale->id}}">
                                                        <li>
                                                            <button type="submit" class="dropdown-item">
                                                                <i class="me-2 align-middle text-muted"></i>
                                                                View
                                                            </button>
                                                        </li>
                                                    </form>
                                                    <form id="initiateOfferForm" method="post" action="{{ route('view-payments') }}">
                                                        @csrf
                                                        <input type="hidden" name="id" value="{{$sale->id}}">
                                                        <input type="hidden" name="amount" value="{{$sale->amount}}">
                                                        <li>
                                                            <button type="submit" class="dropdown-item">
                                                                <i class="me-2 align-middle text-muted"></i>
                                                                Payments
                                                            </button>
                                                        </li>
                                                    </form>


                                                    @if($sale->percentage_paid > 99)
                                                        <form id="initiateOfferForm" method="post" action="{{ route('approve-handover') }}">
                                                            @csrf
                                                            <input type="hidden" name="id" value="{{$sale->id}}">
                                                            <li>
                                                                <button type="submit" class="dropdown-item">
                                                                    <i class="me-2 align-middle text-muted"></i>
                                                                    Approve Handover
                                                                </button>
                                                            </li>
                                                        </form>
                                                    @endif

                                                    <li class="dropdown-divider"></li>
                                                    <li><a class="dropdown-item" href="javascript:void(0);"><i class="ri-delete-bin-5-line me-2 align-middle text-muted"></i>Decline</a></li>
                                                </ul>
                                            </div>
                                        </td>
                                    </tr>
                                    @endif
                                @endforeach
                                <!--end tr-->
                                </tbody>
                            </table>
                            <!--end table-->
                            <div class="noresult" style="display: none">
                                <div class="text-center">
                                    <lord-icon src="https://cdn.lordicon.com/msoeawqm.json" trigger="loop" colors="primary:#405189,secondary:#0ab39c" style="width:75px;height:75px"></lord-icon>
                                    <h5 class="mt-2">Sorry! No Result Found</h5>
                                    <p class="text-muted mb-0">We've searched more than 150+ transactions We did not find any transactions for you search.</p>
                                </div>
                            </div>
                        </div>
                        <div class="d-flex justify-content-end mt-3">
                            <div class="pagination-wrap hstack gap-2">
                                <a class="page-item pagination-prev disabled" href="#">
                                    Previous
                                </a>
                                <ul class="pagination listjs-pagination mb-0"></ul>
                                <a class="page-item pagination-next" href="#">
                                    Next
                                </a>
                            </div>
                        </div>
                    </div>
                    <!--end card-body-->
                </div>
                <!--end card-->

            </div>
            <!-- container-fluid -->
        </div>
        <!-- End Page-content -->

        @include('includes.footer')
    </div>
    <!-- end main content-->

</div>
<!-- END layout-wrapper -->



<!--start back-to-top-->
<button onclick="topFunction()" class="btn btn-danger btn-icon" id="back-to-top">
    <i class="ri-arrow-up-line"></i>
</button>
<!--end back-to-top-->

<!--preloader-->


<!-- JAVASCRIPT -->
<script src="assets/libs/bootstrap/js/bootstrap.bundle.min.js"></script>
<script src="assets/libs/simplebar/simplebar.min.js"></script>
<script src="assets/libs/node-waves/waves.min.js"></script>
<script src="assets/libs/feather-icons/feather.min.js"></script>
<script src="assets/js/pages/plugins/lord-icon-2.1.0.js"></script>
<script src="assets/js/plugins.js"></script>

<!-- apexcharts -->
<script src="assets/libs/apexcharts/apexcharts.min.js"></script>

<!-- Vector map-->
<script src="assets/libs/jsvectormap/js/jsvectormap.min.js"></script>
<script src="assets/libs/jsvectormap/maps/world-merc.js"></script>

<!--Swiper slider js-->
<script src="assets/libs/swiper/swiper-bundle.min.js"></script>

<!-- Dashboard init -->
<script src="assets/js/pages/dashboard-ecommerce.init.js"></script>

<!-- App js -->
<script src="assets/js/app.js"></script>
</body>


</html>
