<?php $__env->startSection('title', 'Requisition Details'); ?>


<?php $__env->startSection('internal-js'); ?>
    <script>
        $(document).ready(function () {
            $('#insurers2').DataTable( {
                dom: 'lBfrtip',
                buttons: [
                    { extend: 'excel', className: 'download-buttons'},
                    { extend: 'pdf', className: 'download-buttons'},
                ],
                //"paging":   false,
            } );

            $('#search-vehicle').select2();

            $('#submit-search').on('click', function (){
                var account = $('#search-vehicle').val();
                if(account == ""){
                    alert('Please Select a Requisition to Search');
                }else{
                    window.location = '/requisition-details/'+account+'?type=summary';
                }
            });

            /**MAXIMIZE AND MINIMIZE THE HEADER SECTION**/
            $('#minimize').on('click', function (){
                $('#main-div-section').slideUp();
                $('#maximize').show();
                $('#minimize').hide();
            });
            $('#maximize').on('click', function (){
                $('#main-div-section').slideDown();
                $('#maximize').hide();
                $('#minimize').show();
            });

            $('#summary-url').on('click', function (){
                window.history.pushState({}, null, '?type=summary');
            });
            $('#log-url').on('click', function (){
                window.history.pushState({}, null, '?type=log');
            });
            $('#trash-url').on('click', function (){
                window.history.pushState({}, null, '?type=trash');
            });
        });

        /**Pay for an Approved Requisition**/
        function payRequisition(id,name){
            var route_link = '/pay-requisition/'+id;

            $('#edit_dialog_content').html('<div style="text-align: center; margin: 20px 0 20px 0;"><img src="<?php echo e(asset('images/loads/loader.gif')); ?>" border=0></div>');
            $('#edit_dialog_content').load(encodeURI(route_link));
            $('#edit_dialog_content').dialog({
                modal: true,
                width: 550,
                title: "Make a Payment to a Requisition for: " + name,
                buttons: [
                    {
                        text: "Continue & Pay",
                        icon: "ui-icon-check",
                        id: "my-button-1",
                        click: function(e) {
                            if(confirm('Are you sure to Pay the Amount on the Selected Requisition?')){
                                e.preventDefault();
                                $("#my-button-1").attr('disabled', true).text('Please Wait....');
                                var datas = $('#pay-requisition').serializeArray();
                                $.ajax({
                                    method: "POST",
                                    url: route_link,
                                    data: datas,
                                    success: function (res){
                                        if(res == 'error'){
                                            alert('There was an internal error. Please contact System Admin');
                                            location.reload();
                                        }else if(res == 'success'){
                                            alert('Payment Posted Successfully');
                                            location.reload();
                                        }else if(res == 'empty account'){
                                            alert('Please select an Account to make payment from');
                                            $("#my-button-1").attr('disabled', false).text('Create Requisition');
                                        }else if(res == 'empty mode'){
                                            alert('Please Select Payment Mode before you can proceed');
                                            $("#my-button-1").attr('disabled', false).text('Create Requisition');
                                        }else if(res == 'empty sub mode'){
                                            alert('Please select the Sub-Mode of Payment');
                                            $("#my-button-1").attr('disabled', false).text('Create Requisition');
                                        }else if(res == 'empty ref'){
                                            alert('Please Enter the payment Reference before you can continue');
                                            $("#my-button-1").attr('disabled', false).text('Create Requisition');
                                        }else{
                                            alert('System encountered an error. please contact System Admin');
                                            location.reload();
                                        }
                                    }
                                });
                            }
                            return false;
                        }
                    }
                ],
                open: function() {
                    $(this).parent().css({'top': 50});
                },
            });
        }

        /**Run a First Approval**/
        function firstApproval(id){
            if(confirm('Are you sure to First Approve this Requisition?')){
                $.ajax({
                    method: "GET",
                    url: '/requisition-first-approval/'+id,
                    data: id,
                    success: function (res){
                        if(res == 'error'){
                            alert('There was an internal error. Please contact System Admin');
                            location.reload();
                        }else if(res == 'success'){
                            alert('Requisition First Approved successfully');
                            location.reload();
                        }else{
                            alert('System encountered an error. please contact System Admin');
                            location.reload();
                        }
                    }
                });
            }
            return false;
        }

        /**Run a First Approval**/
        function secondApproval(id){
            if(confirm('Are you sure to Second Approve this Requisition?')){
                $.ajax({
                    method: "GET",
                    url: '/requisition-second-approval/'+id,
                    data: id,
                    success: function (res){
                        if(res == 'error'){
                            alert('There was an internal error. Please contact System Admin');
                            location.reload();
                        }else if(res == 'success'){
                            alert('Requisition Second Approved successfully');
                            location.reload();
                        }else{
                            alert('System encountered an error. please contact System Admin');
                            location.reload();
                        }
                    }
                });
            }
            return false;
        }

        /**Create a Function Delete a Requisition and Revert back the Cart**/
        function deleteRequisition(id){
            if(confirm('Are you sure to Delete this Requisition and Revert it back to a Cart?')){
                $.ajax({
                    method: "GET",
                    url: '/requisition-delete/'+id,
                    data: id,
                    success: function (res){
                        if(res == 'error'){
                            alert('There was an internal error. Please contact System Admin');
                            location.reload();
                        }else if(res == 'success'){
                            alert('Requisition Deleted successfully');
                            location.reload();
                        }else{
                            alert('System encountered an error. please contact System Admin');
                            location.reload();
                        }
                    }
                });
            }
            return false;

        }

        /**Create a Popup Window to allow Editing REQ Narration**/
        function editReqNarration(id){
            var route_link = '/edit-requisition-details/'+id;

            $('#edit_dialog_content').html('<div style="text-align: center; margin: 20px 0 20px 0;"><img src="<?php echo e(asset('images/loads/loader.gif')); ?>" border=0></div>');
            $('#edit_dialog_content').load(encodeURI(route_link));
            $('#edit_dialog_content').dialog({
                modal: true,
                width: 500,
                title: "Edit Requisition Narration: ",
                buttons: [
                    {
                        text: "Continue & Update",
                        icon: "ui-icon-check",
                        id: "my-button-1",
                        click: function(e) {
                            if(confirm('Are you sure to Update Requisition Narration?')){
                                e.preventDefault();
                                $("#my-button-1").attr('disabled', true).text('Please Wait....');
                                var datas = $('#edit-requisition-details').serializeArray();
                                $.ajax({
                                    method: "POST",
                                    url: route_link,
                                    data: datas,
                                    success: function (res){
                                        if(res == 'error'){
                                            alert('There was an internal error. Please contact System Admin');
                                            location.reload();
                                        }else if(res == 'success'){
                                            alert('Requisition Details Updated Successfully');
                                            location.reload();
                                        }else{
                                            alert('System encountered an error. please contact System Admin');
                                            location.reload();
                                        }
                                    }
                                });
                            }
                            return false;
                        }
                    }
                ],
                open: function() {
                    $(this).parent().css({'top': 50});
                },
            });
        }
    </script>
<?php $__env->stopSection(); ?>


<?php $__env->startSection('internal-css'); ?>
    <style>
        #insurers2 th, td {
            text-align: left;
            padding: 5px;
        }
        #insurers2 tr:hover {background-color: #bec4ee;}
    </style>
<?php $__env->stopSection(); ?>


<?php $__env->startSection('headers'); ?>
    <?php if(auth()->user()->access == 0 || auth()->user()->access == 1 || auth()->user()->access == 3): ?>
        <?php echo $__env->make('headers.finance-header', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>
    <?php else: ?>
        <?php echo $__env->make('headers.dash-header', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>
    <?php endif; ?>
<?php $__env->stopSection(); ?>



<?php $__env->startSection('heading'); ?>
    Requisition Type.:
    <?php if(isset($req)): ?>
        <span class="error"><?php echo $req->req_type; ?></span>/<?php echo e($req->batch ?? $req->payee); ?>

    <?php endif; ?>
<?php $__env->stopSection(); ?>

<?php $__env->startSection('searches'); ?>
    <div style="float: right">
        <br>
        <?php echo Form::open(['method'=>'POST']); ?>

        <div class="guestDetails_input">
            <div class="guestDetails_input" style="text-align: center">
                <select name="search-vehicle" id="search-vehicle" style="width: 200px">
                    <option value="">--Select Requisition--</option>
                    
                </select>
            </div>
        </div>
        <div class="guestDetails_input">
            <div class="guestDetails_input">
                <button type="button" id="submit-search" style="width: auto; height: 22px; cursor: pointer" title="Search a Product"><i class="fa fa-search" aria-hidden="true"></i></button>
            </div>
        </div>
        <?php echo Form::close(); ?>

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

<?php $__env->startSection('content'); ?>
    <div style="float: left">
        <?php if($req->first_approved == 0): ?>
            <button onclick="firstApproval('<?php echo e($req->id); ?>')" class="navButtons" style="background-color: #2dd314; margin-left: 0"><i class="fa fa-check" aria-hidden="true"></i> FIRST APPROVAL</button>
        <?php else: ?>
            <?php if($req->second_approved == 0): ?>
                <button onclick="secondApproval('<?php echo e($req->id); ?>')" class="navButtons" style="background-color: #2dd314; margin-left: 0"><i class="fa fa-check" aria-hidden="true"></i> SECOND APPROVAL</button>
            <?php endif; ?>
        <?php endif; ?>

        <button onclick="printOptions('<?php echo e($req->id); ?>')" type="button" class="navButtons" style="background-color: #f1d414; color: black"><i class="fa fa-print"></i> &nbsp;PRINT OPTIONS</button>
    </div>
    <div style="text-align: right">
        <?php if($req->req_status == 'pending payment'): ?>
            <button onclick="payRequisition('<?php echo e($req->id); ?>')" class="navButtons" style="background-color: #2dd314; margin-left: 0"><i class="fa fa-money" aria-hidden="true"></i> PAY NOW</button>
        <?php endif; ?>
        <button type="button" onclick="uploadRequisitionFiles('<?php echo e($req->id); ?>')" class="navButtons" style="background-color: #bdbbb2;color: black"><i class="fa fa-upload"></i> &nbsp;UPLOAD FILES</button>

        <?php if($req->first_approved == 0): ?>
            <button type="button" class="navButtons" style="background-color: #2f45d7" onclick="editRequisitionDetails('<?php echo e($req->id); ?>')"><i class="fa fa-pencil-square-o"></i> &nbsp;EDIT REQUISITION</button>
            <button onclick="deleteRequisition('<?php echo e($req->id); ?>')" type="button" class="navButtons" style="background-color: #f10e21"><i class="fa fa-trash"></i> &nbsp;DELETE REQUISITION</button>

        <?php else: ?>
            
            <?php if($req->req_status != 'paid'): ?>
                <button onclick="declineRequisition('<?php echo e($req->id); ?>')" type="button" class="navButtons" style="background-color: #f10e21"><i class="fa fa-trash"></i> &nbsp;DECLINE REQUISITION</button>
            <?php endif; ?>
        <?php endif; ?>

        <div class="guestDetails_inputDivider"></div>
    </div>
    <?php if($req->first_approved == 0): ?>
        <div class="notice">Pending First Approval</div><br>
    <?php else: ?>
        <?php if($req->second_approved == 0): ?>
            <div class="notice">Pending Second Approval</div><br>
        <?php endif; ?>
    <?php endif; ?>
    <?php if($req->req_status == 'pending payment'): ?>
        <div class="notice">Pending Payment</div><br>
    <?php endif; ?>
    <div style="background-color: rgba(234,236,238,0.72); border-radius: 5px; padding: 5px 6px">
        <div style="float: right;">
            <i id="minimize" class="fa fa-chevron-up" aria-hidden="true" title="Minimize" style="cursor: pointer"></i>
            <i id="maximize" class="fa fa-chevron-down" aria-hidden="true" title="Maximize" style="cursor: pointer; display: none"></i>
        </div><br>
        <div id="main-div-section">
            <div class="wrapperer" id="client-table-wrapper">
                <div class="column">
                    <table  class="table" style="width: 100%; border-collapse:collapse; margin: 5px">
                        <tr>
                            <th>Requisition Type:</th>
                            <td><b class="error"><?php echo strtoupper($req->req_type); ?></b></td>
                        </tr>
                        <tr>
                            <th>Payee:</th>
                            <td><b><?php echo strtoupper($req->payee); ?></b></td>
                        </tr>
                        <tr>
                            <th>Date Requisitioned:</th>
                            <td><b><?php echo e(date('d-m-Y', strtotime($req->created_at))); ?></b></td>
                        </tr>
                    </table>
                </div>
                <div class="column">
                    <table class="table" style="width: 100%; border-collapse:collapse; margin: 5px">
                        <tr>
                            <th>Main Account:</th>
                            <td>
                                <?php if($req->account): ?>
                                    <b class="error"><?php echo strtoupper($req->account->acc_name); ?></b>
                                <?php else: ?>
                                    -
                                <?php endif; ?>
                            </td>
                        </tr>

                        <tr>
                            <th>Credit Account (CR):</th>
                            <td>-</td>
                        </tr>
                        <tr>
                            <th>Date Created:</th>
                            <td><b><?php echo e(date('d-m-Y', strtotime($req->created_at))); ?></b></td>
                        </tr>
                    </table>

                </div>
                <div class="column">
                    <table class="table" style="width: 100%; border-collapse:collapse; margin: 5px">
                        <tr>
                            <th>Currency Name:</th>
                            <td>
                                <?php if($req->currencyDetails != null): ?>
                                    <b class="error"><?php echo e($req->currencyDetails->name); ?>(<?php echo e($req->currencyDetails->abbr); ?>)</b>
                                <?php endif; ?>
                            </td>
                        </tr>
                    </table>
                    <div class="guestDetails_inputDivider"></div>
                    <table style="width: 100%; border-collapse: collapse;">
                        <tr>
                            <td>
                                <button type="button" class="navButtons" style="background-color: #d9ffff;color: black; margin-bottom: 0;font-weight: bold; min-width: 200px ;font-size: 14px">REQ AMOUNT
                                    <?php if($req->currencyDetails != null): ?>
                                        (<?php echo $req->currencyDetails->abbr; ?>)
                                    <?php endif; ?>
                                    :
                                    <b class="error" style="margin-left: 10px">
                                        <?php if($req->currencyDetails != null): ?>
                                            <?php echo $req->currencyDetails->symbol; ?>

                                        <?php endif; ?>
                                        <?php echo e(number_format($req->amount,2)); ?>

                                    </b>
                                </button>
                            </td>
                        </tr>
                    </table>
                </div>
            </div>
        </div>
        <?php if($req->nar != null): ?>
            <div class="guestDetails_inputDivider"></div>
            <div class="policy-notes">
                <table style="border-collapse: collapse; width: 100%" >
                    <tr>
                        <td><b>REQ NARRATION: </b> <?php echo $req->nar; ?></td>
                        <td style="width: 10px"><i class="fa fa-pencil error" onclick="editReqNarration('<?php echo e($req->id); ?>')" style="cursor: pointer"></i></td>
                    </tr>
                </table>
            </div>
        <?php endif; ?>
    </div><br>

    <div class="tab">
        <button class="tablinks" onclick="openCity(event, 'policies')" id="defaultOpen" >Requisition Details <span class="
        <?php if(count($list) > 0): ?>
            <?php echo e('countItems'); ?>

        <?php else: ?>
            <?php echo e('zeroItems'); ?>

        <?php endif; ?>
        ">&nbsp;<?php echo e(count($list)); ?>&nbsp;</span> </button>
    </div>

    <div class="tabcontent" id="policies">
        <span onclick="this.parentElement.style.display='none'" class="topright" style="margin-left: 20px">&times</span>
        <h3 ><span class="error" style="margin-right: 20px">Requisitioned Item(s)</span></h3>
        <?php if($req->req_type == 'office-stationary' || $req->req_type == 'kitchen-consumables'): ?>
            <?php if($list != null): ?>
                <table id="insurers2"  style="width: 100%; border-collapse: collapse;">
                    <thead>
                    <tr style="background-color: #a1b5d3">
                        <th>No</th>
                        <th>Item Name</th>
                        <th>Quantity</th>
                        <th>Unit Price</th>
                        <th>Total Price</th>
                        <th>Amount Paid</th>
                        <th>Balance</th>
                        <th>Status</th>
                    </tr>
                    </thead>
                    <tbody>
                    <?php $__currentLoopData = $list; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $row): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                        <tr class="debit-row">
                            <td class="cr"></td>
                            <td>
                                <?php if($row->item != null): ?>
                                    <b><?php echo $row->item->name; ?></b>
                                <?php endif; ?>
                            </td>
                            <td><b class="error"><?php echo $row->quantity; ?></b></td>
                            <td class="error"> <b><?php echo number_format( $row->unit_price,2); ?></b></td>
                            <td> <b class="error"><?php echo number_format( $row->total_price,2); ?></b></td>
                            <td><b class=""><?php echo number_format($row->paid_amount,2); ?></b></td>
                            <td><b class=""><?php echo number_format(($row->total_price - $row->paid_amount), 2); ?></b></td>

                            <td >
                                <?php if($row->cert_status == 'paid'): ?>
                                    <b class="success">Fully Paid</b>
                                <?php else: ?>
                                    <i class="error"><?php echo e($row->status); ?></i>
                                <?php endif; ?>
                            </td>
                        </tr>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                    </tbody>
                    <tfoot>
                    <tr style="background-color: #a1b5d3">
                        <th>No</th>
                        <th>Item Name</th>
                        <th>Quantity</th>
                        <th>Unit Price</th>
                        <th>Total Price</th>
                        <th>Amount Paid</th>
                        <th>Balance</th>
                        <th>Status</th>
                    </tr>
                    </tfoot>
                </table>
            <?php else: ?>
                <p class="error" style="text-align: center">No Data Available. Please filter to view Report!</p>
            <?php endif; ?>
        <?php endif; ?>
    </div>
<?php $__env->stopSection(); ?>
<?php $__env->startSection('created-by'); ?>
    * Requisition Created
    <?php if($req->user != null): ?>
        By <b><?php echo e($req->user->firstName." ".$req->user->lastName); ?></b>
    <?php endif; ?>
    on <b><?php echo e($req->created_at->format('j F Y H:i:s')); ?></b>
<?php $__env->stopSection(); ?>


<?php $__env->startSection('modal_heading'); ?>
    <h1>Requisition Details</h1>
<?php $__env->stopSection(); ?>
<?php $__env->startSection('modal_title'); ?>
    <h3><u>Dashboard Functionalities</u></h3>
    <b>
        <ol>
            <li>View Requisition Details</li>
            <li>Amend Requisition Details</li>
            <li>Generate Requisition Transactional Report</li>
            <li>Delete a Wrongly created Requisition</li>
        </ol>
    </b>
<?php $__env->stopSection(); ?>

<?php echo $__env->make('layouts.app', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH /home/zedarroot/public_html/edwulp/resources/views/payments/requisition-details.blade.php ENDPATH**/ ?>