<style>
    .orderLists.newDesg .imgBoxs {
        height: 170px;
        object-fit: cover;
        width: 120px;
    }
    p.msg-sts {
        padding: 6px 10px !important;
    }
    button.submit-popup.create,
    button.submit-popup.createinpack.mt-3 {
        margin-top: 50px !important;
    }
    .main-popup-contents .rs-flex {
        width: 100%;
    }
    .main-popup-contents p {
        margin-bottom: 30px;
        font-weight: 600;
        font-size: 20px;
    }
    input#datepickerinproduction,
    #datepickerinpackage,
    #datepicker {
        border-radius: 30px;
    }
</style>

<?php $__env->startSection('content'); ?>
    <?php $printId = 1; ?>
    <div class="common-content">
        <div class="page-content">
            <div class="page-heading">
                <div class="headings">
                    <h6>Account Summary</h6>
                    <input name="_token" type="hidden" id="token_po" value="<?php echo e(csrf_token()); ?>">
                </div>
            </div>
            <div class="dashboard-cnts">
                <div class="row">
                    <div class="col-12">
                      
                        <div class="boxings po-sum" style="border-radius: 15px;">
                         
                            <div class="tab-content meddbot-tabcontent">
                                <div id="home" class="tab-pane fade in active show">
                                    <?php if(count($order_summary) != 0): ?>
                                        <?php $__currentLoopData = $order_summary; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $key => $summary): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                            <div class="purchase-order js-category-filterable"
                                                data-category="<?php echo $summary->individual_buyerid; ?>">
                                                <div class="order-id d-flex justify-content-end">
                                                    <h4>Order ID <span class="green-order"><?php echo e($summary->id); ?></span>
                                                    </h4>
                                                </div>
                                                <div class="product_details-grd">
                                                    <div class="product-details">

                                                <?php
                                                   $accountssummary = App\Helpers\CustomHelper::accountsum($summary->id);
                                                ?>
                                                        <ul class="aaCLabel" >
                                                            <li><label class="p-o-label">Tender Number</label>:
                                                                <span><?php echo e($summary->tender_number); ?></span>
                                                            </li>
                                                            <li><label class="p-o-label">Vendor Name</label>:
                                                                <span><?php echo e(ucfirst($summary->name)); ?></span>
                                                            </li>
                                                            <li><label class="p-o-label">Total Amount Approved by GM:</label>:
                                                                <span>₹<?php echo e(number_format($accountssummary['order_sum'],2)); ?></span> 
                                                            </li>
                                                            <li><label class="p-o-label">Paid Amount:</label>:
                                                                <span>₹<?php echo e(number_format($accountssummary['paid_amount'],2)); ?></span> 
                                                            </li>
                                                          
                                                            <?php if($accountssummary['remaining_amount'] >= 0): ?>
                                                            <li><label class="p-o-label">Remaining Amount:</label>:
                                                                <span>₹<?php echo e(number_format($accountssummary['remaining_amount'],2)); ?></span> 
                                                            </li>
                                                            <?php else: ?>

                                                            <li><label class="p-o-label">Remaining Amount</label>:
                                                                <span>₹<?php echo e(number_format(0,2)); ?></span> 
                                                                <li><label class="p-o-label">Excess Payment</label>:
                                                                <span>₹<?php echo e(number_format($accountssummary['remaining_amount']*(-1),2)); ?></span> 
                                                                <?php endif; ?>
                                                          
                                                        </ul>
                                                    </div>
                                                </div>
                                                <div class="p-o-buttons aaC">

                                                   
                                                   
                                                        <?php if((Auth::user()->subbuyer_role==3)||(Auth::user()->user_type==1)): ?>

                                                        <button class="btn medd-buttons medd-blue mt-3"
                                                            onclick="printPdf('<?php echo 'print'.$printId; ?>')">Print</button>
                                                        <iframe id="<?php echo 'print'.$printId; ?>"
                                                            style="display: none;"
                                                            src="<?php echo e(url('assets/pdf/po/file/' . $summary->pdf_file)); ?>"></iframe>
                                                        <?php $printId++; ?>
                                                        <a href='<?php echo e(url('assets/pdf/po/file/' . $summary->pdf_file)); ?>'
                                                            target="_blank"><button class="btn medd-buttons medd-blue"> View
                                                                &amp; Download PO</button></a>
                                                        <a href='<?php echo e(url('buyers/installation_completed/'.$summary->id)); ?>'
                                                            target="_blank"> <button
                                                                class="btn medd-buttons btn-primary">Equipments</button></a>

                                                        <?php if($accountssummary['order_sum']!=0): ?>

                                                            <button style="color: #fff;"
                                                                class="btn medd-buttons medd-blue mt-3"
                                                                id=""
                                                                onclick="updatePayment(<?php echo e($summary->id); ?>)">
                                                                Update Payment
                                                            </button>
                                                        <?php endif; ?>

                                                        <?php endif; ?>
                                                        <?php
                                                            $paymentsHistory = App\Helpers\CustomHelper::paymentsHistoryWithOrderId($summary->id);
                                                        ?>

                                                       
                                                        <?php if($paymentsHistory != false): ?>
                                                      
                                                        

                                                            <button style="color: #fff;"
                                                            class="btn medd-buttons medd-green mt-3 ml-3"
                                                            onclick="payhistory(<?php echo e($summary->id); ?>)">
                                                            Payment History
                                                        </button>
                                                      
                                                        <?php endif; ?>
                                                   
                                                </div>
                                            </div>



                                        <?php
                                            $paymentsHistory = App\Helpers\CustomHelper::paymentsHistoryWithOrderId($summary->id);
                                        ?>
                                        <?php if($paymentsHistory != false): ?>
                                        <div class="modal new-modal fade" id="paymentHistoryModal_<?php echo e($summary->id); ?>" tabindex="-1" role="dialog"
                                        aria-labelledby="paymentHistoryModal_<?php echo e($summary->id); ?>" aria-hidden="true">
                                            <div class="modal-dialog modal-Accxl  cutom-modal new-modal" role="document">
                                                <div class="modal-content" style="border-radius: 8px !important;">
                                                    <div class="modal-body" id="demo">
                                                        <div class="purchase-order purchase-order-no-border">
                                                            <div class="product_details-grd custom flex-column">
                                                                <div class="product-details custom">
                                                                    <h5 class="mb-3">Payment History</h5>
                                                                    <div class="table-responsive tableBox wraper">
                                                                        <table style="margin: 5px 0;" id="table_id" class="display table wraper">
                                                                            <thead>
                                                                                <tr>
                                                                                    <th>SI.No:</th>                                                       
                                                                                    <th>Mode of Payment </th>
                                                                                    <th>Payment Ref: No: or Cheque Number</th>
                                                                                    <th>NEFT/RTGS Counterfoil or Cheque Image</th>
                                                                                    <th>Amount Paid</th>
                                                                                    <th>Date</th>
                                                                                    
                                                                                </tr>
                                                                            </thead>
                                                                        <tbody>
                                                                        <?php $i=1;?>
                                                                        <?php $__currentLoopData = $paymentsHistory; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $item): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                            
                                                                            <tr>
                                                                                
                                                                                   <td><?php echo e($i); ?></td>
                                                                                    <td><?php if($item->mode_of_payment == '1'): ?>
                                                                                        NEFT/RTGS
                                                                                    <?php elseif($item->mode_of_payment == '2'): ?>
                                                                                        Cheque
                                                                                    <?php endif; ?></td>
                                                                                    <td><?php echo e($item->payment_details); ?></td>
                                                                                    <td><a target="_blank" href="<?php echo e(url('assets/payment_images/'.$item->payment_image)); ?>">View</a></td>
                                                                                    <td>₹ <?php echo e(number_format($item->payment_amount,2)); ?></td>
                                                                                    <td><?php echo e(date('d-m-Y', strtotime($item->created_at))); ?></td>
                                                                                    
                                                                            </tr>
                                                                            <?php $i++;?>
                                                                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                                                        </tbody>
                                                                    </table>
                                                                        
                                                                    </div>
                                                                </div>
                                                            </div>
                                                        </div>
                                                    </div>
                                                    <div class="modal-footer d-flex justify-content-end">
                                                        <button type="button" class="btn medd-buttons medd-blue"
                                                            data-dismiss="modal" id="closebar">Close</button>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                        <?php endif; ?>




                                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                        <?php echo e($order_summary->links()); ?>

                                    <?php else: ?>
                                        <div class="col-lg-12 col-md-6 col-sm-12 col-xs-12">
                                            <div class="product-display">
                                                <ul>
                                                    <li>
                                                        <div class="details">
                                                            <div>
                                                                <h6>
                                                                    No Orders available
                                                                </h6>
                                                            </div>
                                                        </div>
                                                    </li>
                                                </ul>
                                            </div>
                                        </div>
                                    <?php endif; ?>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <!-- Modal -->
            <div class="modal fade  new-modal" id="approve" tabindex="-1" aria-labelledby="exampleModalLabel"
                aria-hidden="true">
                <div class="modal-dialog">
                    <div class="modal-content">
                        <div class="modal-body">
                            <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                                <span aria-hidden="true">&times;</span>
                            </button>
                            <div class="otp">
                                <h4>OTP Verification</h4>
                                <p>Please Enter the OTP send to your Phone Number</p>
                                <input type="hidden" name="phone" id="phone_no" value="<?php echo Auth::user()->phone_no; ?>">
                                <input type="hidden" name="email" id="email" value="<?php echo Auth::user()->email; ?>">
                               <div class="otp-dflex">
                <input  min="0" max="9" pattern="\d*" type="number" onkeyup="onKeyUpEvent(1, event)" placeholder="0" maxlength="1" id="otp1">
                <input min="0" max="9" type="number" onkeyup="onKeyUpEvent(2, event)" placeholder="0" maxlength="1" id="otp2">
                <input min="0" max="9" type="number" onkeyup="onKeyUpEvent(3, event)" placeholder="0" maxlength="1" id="otp3">
                <input min="0" max="9" type="number" onkeyup="onKeyUpEvent(4, event)" placeholder="0" maxlength="1" id="otp4">
                <input min="0" max="9" type="number" onkeyup="onKeyUpEvent(5, event)" placeholder="0" maxlength="1" id="otp5">
                <input min="0" max="9" type="number" onkeyup="onKeyUpEvent(6, event)" placeholder="0" maxlength="1" id="otp6">
            </div> 
                            </div>
                            <div class="medd-pop-buttons">
                                <input type="hidden" name="order_id" id="order_id" value="">
                                <button class="btn medd-blue medd-buttons mr-3" id="otpverify">Verify</button>
                                <button class="btn medd-blue medd-buttons" id="resend">Resend OTP</button>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <!-- Update Payment Modal -->
            <div class="modal new-modal fade" id="paymentModal" tabindex="-1" role="dialog"
                aria-labelledby="paymentModal" aria-hidden="true">
                <div class="modal-dialog  cutom-modal new-modal" role="document">
                    <div class="modal-content" style="    border-radius: 8px !important;">
                        <form action="<?php echo e(url('buyers/accounts_update_payment')); ?>" method="post" enctype="multipart/form-data">
                        <?php echo csrf_field(); ?>
                        <div class="modal-body" id="demo">
                            <div class="purchase-order purchase-order-no-border">
                                <div class="product_details-grd custom flex-column">
                                    <div class="product-details custom">
                                        <h5 class="mb-3">Payment Details</h5>
                                        <ul class="custom-details">
                                            <li class="w-100">
                                                <input type="hidden" name='accounts_id' value="">
                                                <div class="form-group">
                                                    <label>Mode of Payment <sup>*</sup></label>
                                                    <select class="form-control" id="mode_of_payment" name="mode_of_payment" required>
                                                      <option value="">Select</option>
                                                      <option value="1">RTGS/NEFT</option>
                                                      <option value="2">Cheque</option>
                                                    </select>
                                                </div>
                                                <div class="form-group">
                                                    <label>Amount Paid<sup>*</sup></label>
                                                    <input type="text" class="form-control" oninput="this.value = this.value.replace(/[^0-9.]/g, '').replace(/(\..*?)\..*/g, '$1').replace(/^0[^.]/, '0');" name="payment_amount" required>
                                                    
                                                    <!-- <input type="number" pattern="[0-9]*"  class="form-control" name="payment_amount"   required> -->
                                                </div>   
                                                <div class="form-group">
                                                    <label>Payment Ref: No: or Cheque Number<sup>*</sup></label>
                                                    <input type="text" class="form-control" name="payment_details" required>
                                                </div>
                                                <div class="form-group">
                                                    <label>Upload NEFT/RTGS Counterfoil or Cheque Image<sup>*</sup></label>
                                                    <input type="file" class="form-control" name="payment_image" required>
                                                </div>
                                            </li>
                                        </ul>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="modal-footer d-flex justify-content-end">
                            <button type="submit" class="btn medd-buttons medd-blue">Submit</button>
                            <button type="cancel" class="btn medd-buttons medd-green "
                                data-dismiss="modal" id="closebar">Close</button>
                        </div>
                        </form>
                    </div>
                </div>
            </div>






            <!-- Modal -->
            <div class="modal fade  new-modal" id="reject" tabindex="-1" aria-labelledby="exampleModalLabel"
                aria-hidden="true">
                <div class="modal-dialog">
                    <div class="modal-content">
                        <form id="reject_po" method="POST" action="<?php echo e(url('buyers/reject_purchaseorder')); ?>"> <?php echo csrf_field(); ?>
                            <div class="modal-body">
                                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                                    <span aria-hidden="true">&times;</span>
                                </button>
                                <div class="otp">
                                    <h4>Reject Reason</h4>
                                    <input type="hidden" name="po_id" value="" id="po_id">
                                    <textarea class="w-100 mb-3 form-control" cols="5" rows="5" placeholder="Reason" name="reject_reason"
                                        id="reject_reason"></textarea>
                                </div>
                                <div class="medd-pop-buttons">
                                    <button class="btn medd-blue medd-buttons">Submit</button>
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
      
        <?php $__env->stopSection(); ?>
        <?php $__env->startSection('scripts'); ?>
            <script type="text/javascript" charset="utf8"
                src="https://cdnjs.cloudflare.com/ajax/libs/jsbarcode/3.5.9/JsBarcode.all.min.js"></script>
            <script src="<?php echo e(URL::to('assets/js/buyernew.js')); ?>"></script>
                          
<!--     OTP auto tabing script          -->
    <script>

    function payhistory(orderid){

        window.location.href=baseurl+'buyers/payment_history/'+orderid;

    }
      function getCodeBoxElement(index) {
        return document.getElementById('otp' + index);
      }
      function onKeyUpEvent(index, event) {
        const eventCode = event.which || event.keyCode;
        if (getCodeBoxElement(index).value.length === 1) {
          if (index !== 6) {
            getCodeBoxElement(index+ 1).focus();
          } else {
            getCodeBoxElement(index).blur();
            // Submit code
            console.log('submit code ');
          }
        }
        if (eventCode === 8 && index !== 1) {
          getCodeBoxElement(index - 1).focus();
        }
      }
      function onFocusEvent(index) {
        for (item = 1; item < index; item++) {
          const currentElement = getCodeBoxElement(item);
          if (!currentElement.value) {
              currentElement.focus();
              break;
          }
        }
      }
        
    
     document.querySelectorAll('input[type="number"]').forEach(input =>{
         input.oninput = () =>{
             if(input.value.length > input.maxLength) input.value = input.value.slice(0, input.maxLength);
         };
     }) ;  
        
        
     function updatePayment(id) {
                    $('input[name="accounts_id"]').val(id);
                    $('#paymentModal').modal('show');
                }  
        
        
        
        
        
        
        
 $(".modal").on('shown.bs.modal', function () {
    $(this).find("#otp1").focus();
});   
        
        
    </script>
            <script>
                var poid='';
                $(function() {
                    $('#buyer_filter').change(function() {
                        var $select = $(this);
                        if ($select.val() == 'all') {
                            // No filter selected.  Show all categories
                            $('.js-category-filterable').show();
                            //$('.js-current-category').text('All');
                        } else {
                            var x = 0;
                            $('.js-category-filterable').each(function() {
                                if ($(this).data('category') == $select.val()) {
                                    x = 1;
                                    $(this).show();
                                } else {
                                    $(this).hide();
                                    x = 0;
                                }
                                if (x == 0) {
                                    $(".not").css("display", "block");
                                } else {
                                    $(".not").css("display", "none");
                                }
                            });
                        }
                    });
                });
                function downloadpdf(oid) {
                    window.location = baseurl + 'generate-pdf?id=' + oid;
                }
                var newotp = '';
                $(document).ready(function() {
                    //Resend OTP
                    $('#resend').on('click', function(event) {
                        $(".pageloader").show();
                        var data = {
                            _token: $('#token_po').val()
                        }
                        $.ajax({
                            url: baseurl + 'sendOTP',
                            type: "POST",
                            data: data,
                            success: function(res) {
                                if (res == true) {
                                    $(".pageloader").hide();
                                    swal({
                                        title: "",
                                        text: "OTP send to your registered Phone Number",
                                        type: "success",
                                        showCancelButton: false,
                                        dangerMode: false,
                                        confirmButtonText: 'OK'
                                    }, function() {
                                        $('#approve').modal({
                                            backdrop: 'static',
                                            keyboard: false
                                        });
                                    })
                                } else {
                                    $(".pageloader").hide();
                                    swal("", "Please try again", "warning");
                                }
                            }
                        });
                    });
                    //OTP VERIFICATION
                    $('#otpverify').on('click', function(event) {
                        event.preventDefault();
                        var otp = $('#otp1').val() + $('#otp2').val() + $('#otp3').val() + $('#otp4').val() + $(
                            '#otp5').val() + $('#otp6').val();
                        if (($('#otp1').val() == '') && ($('#otp2').val() == '') && ($('#otp3').val() == '') && ($(
                                '#otp4').val() == '') && ($('#otp5').val() == '') && ($('#otp6').val() == '')) {
                            swal("", "Please Enter a valid OTP", "warning");
                        } else {
                            var data = {
                                _token: $('#token_po').val(),
                                oid:poid,
                                otp: otp
                            }
                            $.ajax({
                                url: baseurl + 'verifyotpuser',
                                type: "POST",
                                data: data,
                                success: function(res) {
                                    if (res == true) {
                                        swal({
                                            title: "",
                                            text: "OTP is verified successfully",
                                            type: "success",
                                        }, function() {
                                            window.location = baseurl +
                                                'buyers/order_summary_approved/';
                                        });
                                    } else {
                                        swal("", "Please Enter a valid OTP", "warning");
                                        $('#otp1').val('');
                                        $('#otp2').val('');
                                        $('#otp3').val('');
                                        $('#otp4').val('');
                                        $('#otp5').val('');
                                        $('#otp6').val('');
                                    }
                                }
                            });
                        }
                    });
                    $('.approvepo').on('click', function() {
                        poid=$(this).attr('data-orderid');
                        $(".pageloader").show();
                        var data = {
                            _token: $('#token_po').val()
                        }
                        $.ajax({
                            url: baseurl + 'sendOTP',
                            type: "POST",
                            data: data,
                            success: function(res) {
                                if (res == true) {
                                    $(".pageloader").hide();
                                    swal({
                                        title: "",
                                        text: "OTP send to your registered Phone Number",
                                        type: "success",
                                        showCancelButton: false,
                                        dangerMode: false,
                                        confirmButtonText: 'OK'
                                    }, function() {
                                        $('#approve').modal({
                                            backdrop: 'static',
                                            keyboard: false
                                        });
                                    })
                                } else {
                                    $(".pageloader").hide();
                                    swal("", "Please try again", "warning");
                                }
                            }
                        });
                    });
                });
                <?php if(Session::has('message')): ?>
                    swal({
                        title: "",
                        text: "<?php echo e(Session::get('message')); ?>",
                        type: "success",
                        showCancelButton: false,
                        dangerMode: false,
                        confirmButtonText: 'OK',
                    });
                <?php endif; ?>
                <?php if(Session::has('errormessage')): ?>
                    swal({
                        title: "",
                        text: "<?php echo e(Session::get('errormessage')); ?>",
                        type: "error",
                        showCancelButton: false,
                        dangerMode: true,
                        confirmButtonText: 'OK',
                    });
                <?php endif; ?>
                $(document).ready(function() {
                    $("#printBtn").click(function() {
                        var divToPrint = document.getElementById('barcodeModal');
                        var newWin = window.open('', 'Print-Window');
                        newWin.document.open();
                        newWin.document.write('<html><body onload="window.print()">' + divToPrint.innerHTML +
                            '</body></html>');
                        newWin.document.close();
                        setTimeout(function() {
                            newWin.close();
                        }, 10);
                    });
                });
                function printPdf(id) {
                    var getMyFrame = document.getElementById(id);
                    getMyFrame.focus();
                    getMyFrame.contentWindow.print();
                }
            </script>
        <?php $__env->stopSection(); ?>

<?php echo $__env->make('layouts.main', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH /home/meddbot/public_html/resources/views/buyers/ordersummary_accounts.blade.php ENDPATH**/ ?>