<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'); ?>
    <div class="common-content">
        <div class="page-content">
            <div class="page-heading">
                <div class="headings">
                    <h6>Payments Summary</h6>
                    <input name="_token" type="hidden" id="token_buyer" value="<?php echo e(csrf_token()); ?>">
                </div>
            </div>

            <div class="dashboard-cnts">
                <div class="row">
                    <div class="col-12">
                        <!--<div class="search-bar order-search">
                                     <div class="form-group has-search">
                                        <span class="fa fa-search form-control-feedback"></span>
                                        <input type="text" class="form-control search" placeholder="Search">
                                      </div>
                                  </div>-->


                        <div class="boxings po-sum" style="border-radius: 15px;">


                            <ul class="nav nav-tabs meddbot-tab">
                                <li class="active"><a class="active show detailsbox"  href="<?php echo e(url('/buyers/manage_payments_pending')); ?>">Pending</a></li>
                                <li><a class="detailsbox" href="<?php echo e(url('/buyers/manage_payments_approved')); ?>" >Approved</a></li>
                                <li><a class="detailsbox"  href="<?php echo e(url('/buyers/manage_payments_rejected')); ?>" >Rejected</a></li>
                            </ul>
                            <div class="tab-content meddbot-tabcontent">
                                <div id="home" class="tab-pane fade in active show">
                                    <?php if(count($accounts_pending) != 0): ?>
                                        <?php $__currentLoopData = $accounts_pending; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $key => $summary): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                            <div class="purchase-order">
                                                <div class="order-id d-flex justify-content-end">
                                                    <h4>Order ID <span class="green-order"><?php echo e($summary->order_id); ?></span>
                                                    </h4>
                                                </div>
                                                <div class="product_details-grd custom">
                                                    <div class="product-image custom">
                                                        <?php if(!empty($summary->photo)): ?>
                                                            <img src="<?php echo e(url('product_files')); ?>/<?php echo e($summary->photo); ?>">
                                                        <?php else: ?>
                                                            <img
                                                                src="<?php echo e(url('assets/images/1200px-No-Image-Placeholder.svg.png')); ?>">
                                                        <?php endif; ?>
                                                    </div>
                                                    <div class="product-details custom">
                                                        <ul>
                                                            <li>
                                                                <h4 class="product-name">
                                                                    <?php echo e(ucfirst($summary->product_name)); ?></h4>
                                                            </li>

                                                        </ul>

                                                        <ul class="custom-details">
                                                            <li><label class="p-o-label">Equipment Id</label>:
                                                                <span><?php echo e($summary->equipmentid); ?></span>
                                                            </li>
                                                            <li><label class="p-o-label">Quantity</label>:
                                                                <span>1</span>
                                                            </li>
                                                            <li><label class="p-o-label">Price per quantity</label>:
                                                                <span>₹<?php echo e(number_format($summary->price,2)); ?></span>
                                                            </li>
                                                            <li><label class="p-o-label">Penalty</label>:
                                                                <span>₹<?php echo e(number_format($summary->penalty,2)); ?></span>
                                                            </li>
                                                            <li><label class="p-o-label">TDS</label>:
                                                                <span>₹<?php echo e(number_format($summary->tds_value,2)); ?></span>
                                                            </li>
                                                            <li><label class="p-o-label">Total Amount</label>:
                                                                <span>₹<?php echo e(number_format($summary->total_price, 2)); ?></span>
                                                            </li>
                                                            <li><label class="p-o-label">Purchase Order  Date</label>:
                                                                <span><?php echo e(date('d-m-Y', strtotime($summary->created_date))); ?></span>
                                                            </li>
                                                            <li><label class="p-o-label">Delivery Days</label>:
                                                                <span><?php echo e($summary->delivery_days); ?> days</span>
                                                            </li>
                                                            <li><label class="p-o-label">Received Date</label>:
                                                                <span><?php echo e(date('d-m-Y', strtotime($summary->product_received_date))); ?></span>
                                                            </li>

                                                            <li><label class="p-o-label">Delayed Days</label>:
                                                                <?php
                                                                    $delay = round((strtotime(date('d-m-Y', strtotime($summary->product_received_date))) - strtotime(date('d-m-Y', strtotime($summary->created_date . ' + '.$summary->delivery_days.' days')))) / (60 * 60 * 24)); 
                                                                    if ($delay <= 0) $delay = 0;
                                                                ?>
                                                                <span><?php echo e($delay); ?> days</span>
                                                            </li>
                                                            <?php if($summary->remarks != null): ?>
                                                            <li><label class="p-o-label">Remarks</label>:
                                                                <span><?php echo e(ucfirst($summary->remarks)); ?></span>
                                                            </li>
                                                            <?php endif; ?>
                                                        </ul>


                                                        <?php if($summary->status==1): ?>

                                                        <span  style="color:red">Status:Pending</span>

                                                        <?php endif; ?>

                                                    </br>

                                                        <button class="btn medd-buttons medd-green" 
                                                        onclick="approvepay(<?php echo e($summary->id); ?>,<?php echo e($summary->order_id); ?>);">Approve</button>
                                                        <button class="btn medd-buttons medd-red"
                                                            onclick="rejectpay(<?php echo e($summary->id); ?>,<?php echo e($summary->equipmentid); ?>);">Reject</button>


                                                    </div>
                                                </div>

                                            </div>
                                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                    <?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 Datas 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="pay_id" id="pay_id_approve" value="">
                                <input type="hidden" name="pay_id" id="order_id_approve" value="">
                                <button class="btn medd-blue medd-buttons" id="otpverify">Verify</button>
                                <button class="btn medd-blue medd-buttons" id="resend">Resend OTP</button>

                            </div>
                        </div>
                    </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_payment')); ?>"> <?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="payid" value="" id="payid">
                                    <input type="hidden" name="order_id" value="" id="order_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>
                                    <!--              <button class="btn medd-black medd-buttons" >Resend OTP</button>-->
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
            </div>

            <!-- Send To GM Modal -->
            <div class="modal fade  new-modal" id="sendToGMModal" 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>Send To GM</h4>
                                    <label>Price</label>
                                    <input type="text" name="price" value="" class="form-control" onkeyup="changeTotalPrice()" required>
                                    <label>Penality</label>
                                    <input type="text" name="penality" value="" class="form-control" onkeyup="changeTotalPrice()" required>
                                    <label>Total Amount</label>
                                    <input type="text" name="total_price" value="" class="form-control" disabled>
                                    <input type="hidden" name="order_id" value="">
                                    <br>
                                </div>
                                <div class="medd-pop-buttons">
                                    <button class="btn medd-blue medd-buttons" onclick="sendToGmAjax()">Submit</button>
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
            </div>

        <?php $__env->stopSection(); ?>
        <?php $__env->startSection('scripts'); ?>
            <script src="<?php echo e(URL::to('assets/js/buyernew.js')); ?>"></script>
            <script>
                
                
                       //                <!--     OTP auto tabing script          -->
    
      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;
          }
        }
      }
      
      $(".modal").on('shown.bs.modal', function () {
    $(this).find("#otp1").focus();
});  

                var newotp='';
                $(document).ready(function() {

                     //Resend Otp

            $('#resend').on('click', function(event) {
                        $(".pageloader").show();
                        var data = {
                            _token: $('#token_buyer').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) {
                        var pay_id     = $("#pay_id_approve").val();
                        var order_id   = $("#order_id_approve").val();




                        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_buyer').val(),
                                pay_id:pay_id,
                                 order_id:order_id,
                                 otp:otp
                            }
                            $.ajax({
                                url: baseurl + 'buyers/approve_payment_gm',
                                type: "POST",
                                data: data,
                                success: function(res) {
                                    if (res == true) {
                                        swal({
                                            title: "",
                                            text: "OTP is verified successfully",
                                            type: "success",
                                        }, function() {
                                            window.location = baseurl + 'buyers/manage_payments_approved';
                                        });
                                    } else {
                                        swal("", "Please Enter a valid OTP", "warning");
                                        $('#otp1').val('');
                                        $('#otp2').val('');
                                        $('#otp3').val('');
                                        $('#otp4').val('');
                                        $('#otp5').val('');
                                        $('#otp6').val('');
                                    }
                                }
                            });
                        }



                    });

               
             });

               

                <?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; ?>
          
                function approvepay(payid,order_id){
                        $(".pageloader").show();                       
                        $("#pay_id_approve").val(payid);
                        $("#order_id_approve").val(order_id);


                        var data = {
                            _token: $('#token_buyer').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");
                                }
                            }
                        });
                         

                }




            function sendToGM(id, price) {
                $('input[name="order_id"]').val(id);
                $('input[name="price"]').val(price);
                $('input[name="penality"]').val('0');
                $('input[name="total_price"]').val(price);
                $('#sendToGMModal').modal('show');
            }
            function changeTotalPrice() {
                let newVal = parseFloat($('input[name="price"]').val()) + parseFloat($('input[name="penality"]').val());
                if (isNaN(newVal))
                $('input[name="total_price"]').val($('input[name="price"]').val());
                else
                $('input[name="total_price"]').val(newVal);
            }
            function sendToGmAjax() {
                let orderId = $('input[name="order_id"]').val();
                let price = $('input[name="price"]').val();
                let penality = $('input[name="penality"]').val();
                $.ajax({
                    type: "POST", 
                    dataType: "json", 
                    url: "<?php echo e(url('buyers/send-to-gm-proc')); ?>",
                    data: {
                        orderId : orderId,
                        price : price,
                        penality : penality,
                        _token: '<?php echo e(csrf_token()); ?>'
                    },
                    success: function(response) {
                    if (response.status == true) {
                        swal({
                            title: "",
                            text: "Price details send to GM",
                            type: "success",
                        }, function() {
                            location.reload();
                            // $('#sendToGMModal').modal('hide');
                            // $('input[name="order_id"]').val('');
                            // $('input[name="price"]').val('');
                            // $('input[name="penality"]').val('0');
                            // $('input[name="total_price"]').val('');
                        });
                        }
                    }
                });
            }
            </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/accounts_gm_pending.blade.php ENDPATH**/ ?>