
<?php $__env->startSection('statusmenue'); ?>
<div class="lg:flex lg:flex-row px-4 mt-4 w-full">

    <div class="w-full lg:w-1/3 md:w-full mx-2 p-6 bg-white border border-gray-200 rounded-lg shadow-sm dark:bg-gray-800 dark:border-gray-700">

        <img class="w-14 h-14 text-gray-500 dark:text-gray-400 mb-3 border-2 border-solid rounded-xl border-gray-300" src="/icons/breafecase.png" />
        <p class="mb-3 font-normal text-gray-500 dark:text-gray-400">Total Units</p>

        <!-- <h5 class=" mt-6 text-2xl font-semibold tracking-tight text-gray-900 dark:text-white"><?php echo e($countInvoice); ?></h5> -->

    </div>



    <div class="w-full lg:w-1/3 mx-2 p-6 bg-white border border-gray-200 rounded-lg shadow-sm dark:bg-gray-800 dark:border-gray-700">

        <img class="w-14 h-14 text-gray-500 dark:text-gray-400 mb-3 border-2 border-solid rounded-xl border-gray-300" src="/icons/chear.png" />
        <p class="mb-3 font-normal text-gray-500 dark:text-gray-400">Active Units</p>

        <!-- <h5 class=" mt-6 text-2xl font-semibold tracking-tight text-gray-900 dark:text-white"><?php echo e($approvedInvoice); ?></h5> -->

    </div>

    <div class="w-full lg:w-1/3 mx-2 p-6 bg-white border border-gray-200 rounded-lg shadow-sm dark:bg-gray-800 dark:border-gray-700">

        <img class="w-14 h-14 text-gray-500 dark:text-gray-400 mb-3 border-2 border-solid rounded-xl border-gray-300" src="/icons/chear.png" />
        <p class="mb-3 font-normal text-gray-500 dark:text-gray-400">Pending Units</p>

        <!-- <h5 class=" mt-6 text-2xl font-semibold tracking-tight text-gray-900 dark:text-white"><?php echo e($approvedInvoice); ?></h5> -->

    </div>

</div>
<?php $__env->stopSection(); ?>
<?php $__env->startSection('content'); ?>

<div class="w-full mt-4 relative  shadow-md sm:rounded-lg overflow-auto ">

    <div class="w-full mt-4 relative  shadow-md sm:rounded-lg overflow-auto ">
        <div class="flex items-center justify-between flex-column flex-wrap md:flex-row space-y-4 md:space-y-0 pb-4 bg-white dark:bg-gray-900">

            <div class="mt-2 mx-4">
                <div class="Imprest">
                    Imprest
                </div>
                <div class="pettyCash">
                    You can search any request by user
                </div>
            </div>
            <div class="mt-2 mx-4">
                <label for="table-search" class="sr-only">Search</label>
                <div class="relative">
                    <div class="absolute inset-y-0 rtl:inset-r-0 start-0 flex items-center ps-3 pointer-events-none">
                        <svg class="w-4 h-4 text-gray-500 dark:text-gray-400" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 20 20">
                            <path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="m19 19-4-4m0-7A7 7 0 1 1 1 8a7 7 0 0 1 14 0Z" />
                        </svg>
                    </div>
                    <input type="text" id="table-search-users" class="block p-2 ps-10 text-sm text-gray-900 border border-gray-300 rounded-lg bg-gray-50 focus:ring-blue-500 focus:border-blue-500 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500" placeholder="Search for users">
                </div>
            </div>
        </div>
        <?php if(\Session::has('message')): ?>
        <ul class="" style="list-style: none;">
            <li>
                <div class="p-4 mb-4 text-sm text-green-800 rounded-lg bg-green-50 dark:bg-gray-800 dark:text-green-400" role="alert">
                    <span class="font-medium"><?php echo e(\Session::get('message')); ?></span>
                </div>
            </li>
        </ul>
        <?php endif; ?>
        <table class="w-full text-sm text-left rtl:text-right text-gray-500 dark:text-gray-400">
            <thead class="text-xs text-gray-700 uppercase bg-gray-50 dark:bg-gray-700 dark:text-gray-400">
                <tr>

                    <th scope="col" class="px-6 py-3">
                        Account Details
                    </th>
                    <th scope="col" class="px-6 py-3">
                        Bank Details
                    </th>
                    <th scope="col" class="px-6 py-3">
                        Amount ₦/ Status
                    </th>
                    <th scope="col" class="px-6 py-3">
                        Action
                    </th>
                </tr>
            </thead>
            <tbody>
                <?php if(count($invoices) > 0 ): ?>
                <?php $__currentLoopData = $invoices->all(); $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $invoice): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                <tr class="bg-white border-b dark:bg-gray-800 dark:border-gray-700 border-gray-200 hover:bg-gray-50 dark:hover:bg-gray-600">

                    <th scope="row" class=" px-6 py-4 text-gray-900 whitespace-nowrap dark:text-white">

                        <a href="/invoice?id=<?php echo e($invoice->id); ?>">
                            <div class="ps-3">
                                <div class="text-base font-semibold"><?php echo e($invoice->accountName); ?></div>
                                <div class="font-normal text-gray-500"><?php echo e($invoice->accountNumber); ?></div>
                            </div>
                        </a>
                    </th>
                    <td class="px-6 py-4">
                        <div class="flex items-center">
                            <?php echo e($invoice->bank); ?>

                        </div>
                        <div class="flex items-center">
                            <?php echo e($invoice->bankCode); ?>

                        </div>

                    </td>
                    <td class="px-6 py-4">
                        <div class="flex items-center">
                            <?php echo e(number_format($invoice->amount/100)); ?>

                        </div>
                        <?php if($invoice->status=="pending"): ?>
                        <div class="flex items-center text-yellow-500">
                            <?php elseif($invoice->status=="approved" || $invoice->status=="paid"): ?>
                            <div class="flex items-center text-green-500">
                                <?php elseif($invoice->status=="canceled"): ?>
                                <div class="flex items-center text-red-500">
                                    <?php else: ?>
                                    <div class="flex items-center">
                                        <?php endif; ?>
                                        <?php echo e($invoice->status); ?>

                                    </div>
                    </td>

                    <td class="flex px-6 py-4">
                        <?php if($invoice->status=="pending"): ?>
                        <form action="/admin/imprest" method="post">
                            <?php echo csrf_field(); ?>
                            <input type="hidden" name="invoiceId" value="<?php echo e($invoice->id); ?>">
                            <button type="submit" title="Approve request" class="mx-1 h-10 w-10 bg-gray-100 rounded-lg hover:bg-green-200">
                                <img class="h-10 w-10 rounded-lg" src="/icons/check-green.png" alt="" srcset="">
                            </button>
                        </form>
                        <a href="/invoice?id=<?php echo e($invoice->id); ?>" title="View / Edit request" class="mx-1 h-10 w-10 bg-gray-100 rounded-lg hover:bg-yellow-200">
                            <img class="h-10 w-10 rounded-lg" src="/icons/ButtonEdit.png" alt="" srcset="">
                        </a>
                        <?php endif; ?>
                        <?php if($invoice->status=="approved"): ?>
                        <button type="button" onclick='showPayModal("<?php echo e($invoice->id); ?>|<?php echo e($invoice->accountNumber); ?>|<?php echo e($invoice->bankCode); ?>")' title="Pay to bank" class="mx-1 h-10 w-10 bg-gray-100 rounded-lg hover:bg-green-200 flex justify-center items-center">
                            <img class="h-5 w-5 rounded-lg" src="/icons/payment-method.png" alt="" srcset="">
                        </button>
                        <div id="modal<?php echo e($invoice->id); ?>" tabindex="-1" class="hidden bg-gray-800 bg-opacity-70 flex overflow-y-auto overflow-x-hidden fixed top-0  z-50 justify-center  w-full md:inset-0 h-[calc(100%-1rem)] max-h-full">
                            <div class="relative p-4 w-full max-w-md max-h-full">
                                <!-- Modal content -->
                                <div class="relative bg-white rounded-lg shadow-sm dark:bg-gray-700">
                                    <!-- Modal header -->
                                    <div class="flex items-center justify-between p-4 md:p-5 border-b rounded-t dark:border-gray-600 border-gray-200">
                                        <h3 class="text-xl font-semibold text-gray-900 dark:text-white">
                                            Confirm payment details
                                        </h3>
                                        <button type="button" class="end-2.5 text-gray-400 bg-transparent hover:bg-gray-200 hover:text-gray-900 rounded-lg text-sm w-8 h-8 ms-auto inline-flex justify-center items-center dark:hover:bg-gray-600 dark:hover:text-white" data-modal-hide="authentication-modal">
                                            <svg class="w-3 h-3" onclick='showPayModal("<?php echo e($invoice->id); ?>|<?php echo e($invoice->accountNumber); ?>|<?php echo e($invoice->bankCode); ?>")' xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 14 14">
                                                <path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="m1 1 6 6m0 0 6 6M7 7l6-6M7 7l-6 6" />
                                            </svg>
                                            <span class="sr-only">Close modal</span>
                                        </button>
                                    </div>
                                    <!-- Modal body -->
                                    <div class="p-4 md:p-5">
                                        <form class="space-y-4" action="/admin/imprest-payout" method="post">
                                            <?php echo csrf_field(); ?>

                                            <input type="hidden" name="invoiceId" value="<?php echo e($invoice->id); ?>">
                                            <div>
                                                <label class="block mb-2 text-sm font-medium text-gray-900 dark:text-white">Account number</label>
                                                <label class="block mb-2 text-sm font-medium text-gray-900 dark:text-white"><?php echo e($invoice->accountNumber); ?></label>
                                            </div>
                                            <div>
                                                <label class="block mb-2 text-sm font-medium text-gray-900 dark:text-white">Account name</label>
                                                <label id="accountName<?php echo e($invoice->id); ?>" class="flex items-center block mb-2 text-sm font-medium text-gray-900 dark:text-white"><?php echo e($invoice->accountName); ?></label>
                                            </div>
                                            <div>
                                                <label class="block mb-2 text-sm font-medium text-gray-900 dark:text-white">Bank</label>
                                                <label class="block mb-2 text-sm font-medium text-gray-900 dark:text-white"><?php echo e($invoice->bank); ?></label>
                                            </div>
                                            <div>
                                                <label class="block mb-2 text-sm font-medium text-gray-900 dark:text-white">Total Amount</label>
                                                <label class="block mb-2 text-sm font-medium text-gray-900 dark:text-white"><?php echo e(number_format($invoice->amount/100)); ?></label>
                                            </div>
                                            <div class="text-sm font-medium text-yellow-500 dark:text-yellow-300">
                                                Please Note! Once Pay Now is clicked the above amount will be transfered to the account details.
                                            </div>
                                            <button type="submit" class="w-full text-white bg-blue-700 hover:bg-blue-800 focus:ring-4 focus:outline-none focus:ring-blue-300 font-medium rounded-lg text-sm px-5 py-2.5 text-center dark:bg-blue-600 dark:hover:bg-blue-700 dark:focus:ring-blue-800">Pay now</button>

                                        </form>
                                    </div>
                                </div>
                            </div>
                        </div>

                        <?php endif; ?>
                        <?php if($invoice->status!="canceled"&& $invoice->status!="paid"): ?>
                        <form action="/admin/imprest-cancel" method="post">
                            <?php echo csrf_field(); ?>
                            <input type="hidden" name="invoiceId" value="<?php echo e($invoice->id); ?>">
                            <button type="submit" title="Cancele request" class="mx-1 h-10 w-10 bg-red-100 rounded-lg hover:bg-red-200 flex justify-center items-center">
                                <img class="h-5 w-5 rounded-lg" src="/icons/cancelled.png" alt="" srcset="">
                            </button>
                        </form>
                        <?php endif; ?>
                    </td>

                </tr>
                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                <?php endif; ?>

            </tbody>
        </table>
    </div>
</div>
<script>
    async function fetchAsync(url, method, data) {

        const rawResponse = await fetch(url, {
            method,
            headers: {
                'Accept': 'application/json',
                'Content-Type': 'application/json',
            },
            body: JSON.stringify(data),
        });
        const content = await rawResponse.json();

        return content;
    }
    const showPayModal = async (input) => {
        const inputDetails = input.split("|");

        const modalDetails = document.getElementById(`modal${inputDetails[0]}`);

        if (modalDetails.classList.contains("hidden")) {
            modalDetails.classList.remove("hidden");
            const csrf = "zXJHMrMrfJiMY4FfLSIYfy3lXpiy42w7MB4M6bRr";

            const stateData = await fetchAsync("/verify-account", "POST", {
                bankCode: inputDetails[2],
                accountNumber: inputDetails[1],
                _token: csrf
            });

            if (stateData.status === "success") {
                const accountDetails = stateData.data;
                document.getElementById(`accountName${inputDetails[0]}`).innerHTML = `${accountDetails.account_name} <img class="h-10 w-10 rounded-lg" src="/icons/check-green.png" alt="" srcset="">`;
            }

        } else {
            modalDetails.classList.add("hidden");
        }

    }
</script>
<?php $__env->stopSection(); ?>
<?php echo $__env->make('layouts.adminDashboard',['title'=> "Units"], \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH C:\Users\USER\Documents\GitHub\SPS-ERP\resources\views\admin\units.blade.php ENDPATH**/ ?>