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


<?php $__env->startSection('internal-js'); ?>
    <script>
        $(document).ready(function () {
            $('#docsTable').DataTable();
            $('#example1').dataTable();
            $('#example2').dataTable();
            $('#example3').dataTable();
            $('#example7').dataTable();
            $('#example').DataTable( {
                dom: 'lBfrtip',
                buttons: [
                    { extend: 'excel', className: 'download-buttons' },
                    { extend: 'print', className: 'download-buttons' },
                ]
            } );

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

            $('#submit-search').on('click', function (){
                var payment = $('#search-vehicle').val();
                if(payment == ""){
                    alert('Please Select a Payment to Search');
                }else{
                    <?php if($module == 'finance'): ?>
                        window.location = '/payment/'+payment+'/finance?type=summary';
                    <?php else: ?>
                        window.location = '/payment/'+payment+'?type=summary';
                    <?php endif; ?>
                }
            });

            /**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');
            });
        });

        
        function printOptions(id){
            var route_link = '/payment-print-options/'+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>')
            .load(encodeURI(route_link))
            .dialog({
                modal: true,
                width: 500,
                title: "Payment Preview & Printing Options",
                buttons: [
                    {
                        text: "Continue to Preview & Print",
                        icon: "ui-icon-check",
                        click: function(e) {
                            e.preventDefault();
                            var datas = $('#payment-print-options').serializeArray();

                            $.ajax({
                                method: "POST",
                                url: route_link,
                                data: datas,
                                success: function (res){
                                    if(res == 'empty type'){
                                        alert('Please select at least one option of the Documents to Preview');
                                    }else{
                                        window.open(res, '_blank');
                                    }
                                }
                            });
                            return false;
                        }
                    }
                ],
                open: function() {
                    $(this).parent().css({'top': 50});
                }
            });
        }

        
        function reversePayment(id){
            var route_link = '/reverse-payment/'+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>')
                .load(encodeURI(route_link))
                .dialog({
                modal: true,
                width: 520,
                title: "Reverse Payment",
                buttons: [
                    {
                        text: "Continue to Reverse Payment",
                        icon: "ui-icon-check",
                        click: function(e) {
                            if(confirm('Are you sure to Reverse this Payment?')){
                                e.preventDefault();
                                var datas = $('#reverse-payment').serializeArray();

                                $.ajax({
                                    method: "POST",
                                    url: route_link,
                                    data: datas,
                                    success: function (res){
                                        if(res == 'empty reason'){
                                            alert('Please provide a reason for Reversing this Direct PV');
                                        }else if(res == 'error'){
                                            alert('System is unable to perform the Requested action. Please Try Again!');
                                            window.location = '/receipt/'+id+'/finance?type=summary&reverseRCT=false';
                                        }else if(res == 'success'){
                                            window.location = '/receipt/'+id+'/finance?type=summary&reverseRCT=true';
                                        }else{
                                            alert('System Encountered an Error. Please Contact System Admin for Help');
                                            location.reload();
                                        }
                                    }
                                });
                                return false;
                            }
                            return  false;
                        }
                    }
                ],
                open: function() {
                    $(this).parent().css({'top': 20});
                }
            });
        }

        
        function editPaymentRefNumber(id){
            var route_link = '/edit-payment-ref-number/'+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>')
            .load(encodeURI(route_link))
            .dialog({
                modal: true,
                width: 500,
                title: "Edit Payment Reference Number",
                buttons: [
                    {
                        text: "Update Reference Number",
                        icon: "ui-icon-check",
                        click: function(e) {
                            if(confirm('Are you sure to Save Entered Changes?')){
                                e.preventDefault();
                                var datas = $('#edit-reference-number').serializeArray();

                                $.ajax({
                                    method: "POST",
                                    url: route_link,
                                    data: datas,
                                    success: function (res){
                                        if(res == 'empty ref'){
                                            alert('Please provide the Payment Reference Number');
                                        }else if(res == 'error'){
                                            alert('System is unable to perform the Requested action. Please Try Again!');
                                           location.reload();
                                        }else if(res == 'success'){
                                            location.reload();
                                        }else{
                                            alert('System Encountered an Error. Please Contact System Admin for Help');
                                            location.reload();
                                        }
                                    }
                                });
                                return false;
                            }
                            return false;
                        }
                    }
                ],
                open: function() {
                    $(this).parent().css({'top': 50});
                }
            });
        }


        
        function nextPlcy(id){
            <?php if($module == 'finance'): ?>
                window.location = '/payment/'+id+'/finance?type=summary';
            <?php else: ?>
                window.location = '/payment/'+id+'?type=summary';
            <?php endif; ?>
        }

        
        function prevPlcy(id){
            <?php if($module == 'finance'): ?>
                window.location = '/payment/'+id+'/finance?type=summary';
            <?php else: ?>
                window.location = '/payment/'+id+'?type=summary';
            <?php endif; ?>
        }
    </script>
<?php $__env->stopSection(); ?>


<?php $__env->startSection('internal-css'); ?>
    <style>
        #example th, td {
            text-align: left;
            padding: 5px;
        }


        #example1 tr:hover {background-color: #a3aef6;}

        #example2 th, td {
            text-align: left;
            padding: 5px;
        }

        #example2 tr:hover {background-color: #a3aef6;}
        #example3 th, td {
            text-align: left;
            padding: 5px;
        }

        #example3 tr:hover {background-color: #a3aef6;}
        #example7 th, td {
            text-align: left;
            padding: 5px;
        }
        #example7 tr:hover {background-color: #a3aef6;}

        #docsTable th, td {
            text-align: left;
            padding: 5px;
        }
        #docsTable tr:hover {background-color: #a3aef6;}
    </style>
<?php $__env->stopSection(); ?>


<?php $__env->startSection('headers'); ?>
    <?php if($module == 'finance'): ?>
        <?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'); ?>

     Payment No.:
    <?php if(isset($pv)): ?>
        <span class="error">PV<?php echo e($pv->pv_id); ?></span>
    <?php endif; ?>
    <?php if($data['prev'] != null): ?>
        <span style="margin-left: 3%; cursor: pointer" onclick="prevPlcy('<?php echo e($data['prev']); ?>')" class="quick-buttons"> <i class="fa fa-chevron-left" aria-hidden="true" style="font-size: 9pt" title="Previous Payment"> Prev</i> </span>&nbsp;&nbsp; |
    <?php else: ?>
        <span style="margin-left: 3%; cursor: pointer; color: grey" disabled="true" class="quick-buttons"> <i class="fa fa-chevron-left" aria-hidden="true" style="font-size: 9pt" title="No Previous Payment"> No Prev</i> </span>&nbsp;&nbsp; |
    <?php endif; ?>

    <?php if($data['next'] != null): ?>
        <span style="margin-left: 1%; cursor: pointer" onclick="nextPlcy('<?php echo e($data['next']); ?>')" class="quick-buttons" title="Next Payment"> <i class="fa fa">Next</i> <i class="fa fa-chevron-right" aria-hidden="true" style="font-size: 9pt"></i></span>
    <?php else: ?>
        <span style="margin-left: 1%; cursor: pointer; color: grey" disabled="true" class="quick-buttons"> <i class="fa fa" title="No Next Payment">No Next</i> <i class="fa fa-chevron-right" aria-hidden="true" style="font-size: 9pt"></i></span>
    <?php endif; ?>
<?php $__env->stopSection(); ?>

<?php $__env->startSection('searches', ''); ?>

<?php $__env->startSection('content'); ?>
    <div style="float: left">
        <button onclick="printOptions('<?php echo e($pv->stamp); ?>')" type="button" class="navButtons" style="margin-left: 0px;background-color: #f1d414; color: black"><i class="fa fa-print"></i> &nbsp;PRINT OPTIONS</button>
    </div>
    <div style="text-align: right">
        

        <button type="button" onclick="uploadFiles('<?php echo e($pv->pv_id); ?>')" class="navButtons" style="background-color: #bdbbb2;color: black"><i class="fa fa-upload"></i> &nbsp;UPLOAD FILES</button>

        <?php if($pv->pv_status != 'reversed'): ?>
            <button onclick="reverseRCT('<?php echo e($pv->stamp); ?>')" type="button" class="navButtons" style="background-color: #f10e21"><i class="fa fa-undo"></i> &nbsp;REVERSE PAYMENT</button>
        <?php else: ?>
            <button onclick="restorePV('<?php echo e($pv->stamp); ?>')" type="button" class="navButtons" style="background-color: #57e505"><i class="fa fa-undo"></i> &nbsp;RESTORE PAYMENT</button>
        <?php endif; ?>
        <div class="guestDetails_inputDivider"></div>
        
        <?php if($pv->pv_status == 'reversed'): ?>
            <div class="notice">Reversed!</div><br>
        <?php endif; ?>
    </div>
    <div style="background-color: rgba(234,236,238,0.72); border-radius: 5px; padding: 5px 6px">
        <div style="font-size: 12px">
            Paid To: <span class="error">
                    <?php if($pv->type == 'remit-premium'): ?>
                    <?php if($pv->insurer != null): ?>
                        <?php echo e(strtoupper($pv->insurer->lgnm)); ?>

                    <?php endif; ?>
                <?php elseif($pv->type == 'commission'): ?>
                    <?php if($pv->insurer != null): ?>
                        <?php echo e(strtoupper($pv->insurer->lgnm)); ?>

                    <?php endif; ?>
                <?php endif; ?>
                </span>
        </div>
        <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>Description:</th>
                            <td><b class="error">PAYMENT VOUCHER</b></td>
                        </tr>
                        <tr>
                            <th>Paid By:</th>
                            <td>
                                <?php if($pv->user != null): ?>
                                   <b><?php echo strtoupper($pv->user->firstName." ".$pv->user->lastName); ?></b>
                                <?php endif; ?>
                            </td>
                        </tr>
                        <tr>
                            <th>Date of Payment:</th>
                            <td><b><?php echo e(date('d-m-Y', strtotime($pv->pv_date))); ?></b></td>
                        </tr>
                        <tr>
                            <th>Date Registered:</th>
                            <td><b><?php echo e(date('d-m-Y', strtotime($pv->created_at))); ?></b></td>
                        </tr>
                    </table>
                </div>
                <div class="column">
                    <table class="table" style="width: 100%; border-collapse:collapse; margin: 5px">
                        <tr>
                            <th>Paid From:</th>
                            <td>
                                <?php if($pv->account != null): ?>
                                    <b class="error"><?php echo e(strtoupper($pv->account->acc_name)); ?></b>
                                <?php endif; ?>
                            </td>
                        </tr>
                        <tr>
                            <th>Ledger Account:</th>
                            <td>
                                <?php if($pv->glAccount != null): ?>
                                    <b class="error"><?php echo e(strtoupper($pv->glAccount->acc_name)); ?></b>
                                <?php endif; ?>
                            </td>
                        </tr>
                        <tr>
                            <th>Mode of Payment:</th>
                            <td>

                                <?php if($pv->modeOfPayment != null): ?>
                                    <b class="error" > <?php echo e($pv->modeOfPayment->name); ?></b>
                                    <?php if($pv->subModeOfPayment != null): ?>
                                        <b> - <?php echo e($pv->subModeOfPayment->name); ?></b>
                                    <?php endif; ?>
                                <?php endif; ?>

                            </td>
                        </tr>
                        <tr>
                            <th>Reference No.:</th>
                            <td><b class="error"><?php echo e($pv->ref); ?></b></td>
                            <td style=" text-align: right">
                                <?php if(auth()->user()->admin == 1): ?>
                                    <a href="javascript: void(0);" onclick="editPaymentRefNumber('<?php echo e($pv->id); ?>')" class="inner"><b class="error">EDIT <i class="fa fa-pencil fa-md"></i></b></a>
                                <?php endif; ?>
                            </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($pv->currencyDetails != null): ?>
                                    <b class="error"><?php echo e($pv->currencyDetails->name); ?>(<?php echo e($pv->currencyDetails->abbr); ?>)</b>
                                <?php endif; ?>
                            </td>
                        </tr>
                        <tr>
                            <th>Exchange Rate:</th>
                            <td><b class="error"><?php echo e(number_format($pv->conversion_rate,2)); ?></b></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">PV Amount
                                    <?php if($pv->currencyDetails != null): ?>
                                        (<?php echo $pv->currencyDetails->abbr; ?>)
                                    <?php endif; ?>
                                    :
                                    <b class="error" style="margin-left: 10px">
                                        <?php if($pv->currencyDetails != null): ?>
                                            <?php echo $pv->currencyDetails->symbol; ?>

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

                                    </b>
                                </button>
                            </td>
                        </tr>
                    </table>
                </div>
            </div>
            <div class="guestDetails_inputDivider"></div>
            <table style="width: 100%; border-collapse: collapse">
                <tr style="padding: 6px">
                    <th style="width: 10%">Payment Narration:</th>
                    <td><?php echo e($pv->nar); ?></td>
                </tr>
                <tr style="padding: 6px">
                    <th style="width: 10%">Amount in Words:</th>
                    <td><?php echo e(strtoupper($amountInWords.' '.$pv->currencyDetails->name.' only')); ?></td>
                </tr>
            </table>
        </div>

        <?php if($pv->reversal_reason != null): ?>
            <div class="guestDetails_inputDivider"></div>
            <div class="policy-notes">
                <table style="border-collapse: collapse; width: 100%" >
                    <tr>
                        <td><b>REVERSAL COMMENTS: </b> <?php echo $pv->reversal_reason; ?></td>
                        <td style="text-align: right">Reversed By:
                            <?php if($pv->reversedBy != null): ?>
                                <b><?php echo e($pv->reversedBy->firstName." ".$pv->reversedBy->lastName); ?></b>
                            <?php endif; ?>
                        </td>
                    </tr>
                </table>
            </div>
        <?php endif; ?>

    </div><br>


    <div class="tab">
        <button class="tablinks" onclick="openCity(event, 'policies')" <?php if(isset($_GET['type']) && $_GET['type'] == 'summary'): ?>id="defaultOpen" <?php else: ?> id="summary-url"<?php endif; ?>>Allocations</button>
        <button class="tablinks" onclick="openCity(event, 'documents')" <?php if(isset($_GET['type']) && $_GET['type'] == 'documents'): ?> id="defaultOpen" <?php else: ?> id="documents-url"<?php endif; ?>>Documents <span class="
            <?php if(!1): ?>
                <?php echo e('countItems'); ?>

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

            <?php endif; ?>
            ">&nbsp;<?php echo e(0); ?>&nbsp;</span> </button>
        <button class="tablinks" onclick="openCity(event, 'log')" <?php if(isset($_GET['type']) && $_GET['type'] == 'log'): ?>id="defaultOpen" <?php else: ?> id="log-url"<?php endif; ?>>LOG <span class="zeroItems">&nbsp;<?php echo e(0); ?>&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">Payment Allocation Listing</span></h3>

    </div>

    
    <div class="tabcontent" id="documents">
        <span onclick="this.parentElement.style.display='none'" class="topright">&times</span>
        <h3 class="error">View Client's Documents Listing</h3>

        <table id="docsTable" class="display" style="width:100%; border-collapse: collapse">
            <thead>
            <tr style="background-color: #a1b5d3">
                <th>No</th>
                <th>Document Name</th>
                <th>Uploaded By</th>
                <th>Date Uploaded</th>
                <th>Print Document</th>
                <th></th>
            </tr>
            </thead>
            <tbody>
            
            </tbody>
            <tfoot>
            <tr style="background-color: #a1b5d3">
                <th>No</th>
                <th>Document Name</th>
                <th>Uploaded By</th>
                <th>Date Uploaded</th>
                <th>Print Document</th>
                <th></th>
            </tr>
            </tfoot>
        </table>
    </div>
    <div class="tabcontent" id="log">
        <span onclick="this.parentElement.style.display='none'" class="topright">&times</span>
        <h3 class="error">Audit Trails (LOGs)</h3>
        <table id="example7" class="display" style="width:100%; border-collapse: collapse">
            <thead>
            <tr style="background-color: #a1b5d3">
                <th style="text-align: left;">No</th>
                <th style="text-align: left">Log Narration.</th>
                <th style="text-align: left">User</th>
                <th style="text-align: left">Date & Time</th>
            </tr>
            </thead>
            <tbody>
            
            </tbody>
            <tfoot>
            <tr style="background-color: #a1b5d3">
                <th style="text-align: left">No</th>
                <th style="text-align: left">Log Narration.</th>
                <th style="text-align: left">User</th>
                <th style="text-align: left">Date & Time</th>
            </tr>
            </tfoot>
        </table>
    </div>
<?php $__env->stopSection(); ?>
<?php $__env->startSection('created-by'); ?>
    * Payment Registered
    <?php if($pv->user != null): ?>
        By <b><?php echo e($pv->user->firstName." ".$pv->user->lastName); ?></b>
    <?php endif; ?>
    on <b><?php echo e($pv->created_at->format('j F Y H:i:s')); ?></b>
<?php $__env->stopSection(); ?>

<?php $__env->startSection('modal_heading'); ?>
    <h1>Payment File</h1>
<?php $__env->stopSection(); ?>
<?php $__env->startSection('modal_title'); ?>
    <h3><u>Dashboard Functionalities</u></h3>
    <b>
        <ol>
            <li>View Payment Details</li>
            <li>View Utilization of the Payment</li>
            <li>Print payment Document</li>
            <li>View Logs on the Payment</li>
        </ol>
    </b>
<?php $__env->stopSection(); ?>

<?php echo $__env->make('layouts.app', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH C:\xampp\htdocs\finewood\resources\views/payments/payment.blade.php ENDPATH**/ ?>