<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>Manage Payments</h6>
                    <input name="_token" type="hidden" id="token_pbg" 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   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="active show detailsbox"  href="<?php echo e(url('/buyers/manage_payments_rejected')); ?>" >Rejected</a></li>
                            </ul>
                            <div class="tab-content meddbot-tabcontent">

                                <div id="menu2" class="tab-pane fade in active show">

                                    <?php if(count($accounts_rejected) != 0): ?>
                                        <?php $__currentLoopData = $accounts_rejected; $__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->po_product_itemsid); ?></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>
                                                        </ul>

                                                        
                                                        
                                                        <?php if($summary->status == 3): ?>
                                                            <span style="color:red">Status: Rejected</span>
                                                            <br>
                                                            <span style="color:red">Reason: <?php echo e(ucfirst($summary->rejected_reason)); ?></span>
                                                        <?php endif; ?>
                                                       <?php if(Auth::user()->subbuyer_role == '3'): ?> 

                                                        <ul>
                                                            <button style="color: #fff;"
                                                                class="btn medd-buttons medd-blue mt-3" id="send product"
                                                                onclick="sendToGMWithPenality(<?php echo e($summary->id); ?>,<?php echo e($summary->price); ?>,<?php echo e($summary->penalty); ?>,1,<?php echo e($summary->tds_value); ?>)">
                                                                Re-Calculate Payment
                                                            </button>
                                                        </ul>

                                                        <?php endif; ?>


                                                    </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 type="text" placeholder="0" maxlength="1" id="otp1">
                                    <input type="text" placeholder="0" maxlength="1" id="otp2">
                                    <input type="text" placeholder="0" maxlength="1" id="otp3">
                                    <input type="text" placeholder="0" maxlength="1" id="otp4">
                                    <input type="text" placeholder="0" maxlength="1" id="otp5">
                                    <input type="text" placeholder="0" maxlength="1" id="otp6">
                                </div>

                            </div>

                            <div class="medd-pop-buttons">
                                <input type="hidden" name="pbg_id" id="pbg_id" value="">
                                <button class="btn medd-blue medd-buttons" id="otpverify">Verify</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_pbg')); ?>"> <?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="pbgid" value="" id="pbgid">
                                    <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>Price Summary</h4>
                                <label>Price for <span id='qty'></span> quantity</label>
                                <input type="text" name="price" value="" class="form-control" disabled>
                                <label>Penality</label>
                                <input type="text" name="penality" value="" class="form-control"onkeyup="changeTotalPrice()" required>
                                <label>TDS Deduction</label>
                                <input type="text" name="tds_value" value="" class="form-control"onkeyup="changeTotalPrice()" required>
                                <label>Total Amount</label>
                                <input type="text" name="total_price" value="" class="form-control" disabled>
                                <label>Remarks</label>
                                <div class="col-md-12 col-sm-12 form-group">
                                    <textarea class="form-control" rows="5" id="remarks" name="remarks" placeholder="Remark" required></textarea>
                                </div>
                                <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>

            <!-- 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="number" 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>

        <?php $__env->stopSection(); ?>
        <?php $__env->startSection('scripts'); ?>
            <script src="<?php echo e(URL::to('assets/js/buyernew.js')); ?>"></script>
            <script>

                function approves(){

                            $("#home").removeClass('active show');
                            $("#menu2").removeClass('active show');
                            $("#menu1").addClass('active show');

                            $("#pending").removeClass('active show');
                            $("#approved").addClass('active show');
                            $("#rejected").removeClass('active show');

                }

                function reject(){

                             $("#home").removeClass('active show');
                            $("#menu1").removeClass('active show');

                            $("#menu2").addClass('active show');


                            $("#pending").removeClass('active show');
                            $("#approved").removeClass('active show');
                            $("#rejected").addClass('active show');
                    
                   
                }
                $(document).ready(function() {

                    $(".detailsbox").click(function(evt){
                        var x=$(this).attr('href');
                        if(x=='#menu1'){

                            $("#home").removeClass('active show');
                            $("#menu2").removeClass('active show');
                            $("#menu1").addClass('active show');

                            $("#pending").removeClass('active show');
                            $("#approved").addClass('active show');
                            $("#rejected").removeClass('active show');

                        }
                        else if(x=='#menu2'){

                            $("#home").removeClass('active show');
                            $("#menu1").removeClass('active show');

                            $("#menu2").addClass('active show');


                            $("#pending").removeClass('active show');
                            $("#approved").removeClass('active show');
                            $("#rejected").addClass('active show');
                            
                        }
                        else{

                            $("#menu1").removeClass('active show');
                            $("#menu2").removeClass('active show');

                            $("#home").addClass('active show');

                            $("#pending").addClass('active show');
                            $("#approved").removeClass('active show');
                            $("#rejected").removeClass('active show');

                        }

                    });


                    //OTP VERIFICATION

                    $('#otpverify').on('click', function(event) {
                        var pbg_id = $("#pbg_id").val();
                        event.preventDefault();
                        if (($('#otp1').val() == '') && ($('#otp2').val() == '') && ($('#otp3').val() == '') && ($(
                                '#otp4').val() == '') && ($('#otp5').val() == '') && ($('#otp6').val() == '')) {
                            swal("", "Please Enter a valid OTP", "warning");
                        } else {

                            var email = $('#email').val();
                            var phoneno = $('#phone_no').val();
                            var otp = $('#otp1').val() + $('#otp2').val() + $('#otp3').val() + $('#otp4').val() + $(
                                '#otp5').val() + $('#otp6').val();
                            var APP_URL = <?php echo json_encode(url('/verifyOtpuser_pbg')); ?>;
                            var saveData = $.ajax({
                                type: 'GET',
                                url: APP_URL + '/' + email + '/' + phoneno + '/' + otp + '/' + pbg_id,
                                data: {
                                    email: email,
                                    phoneno: phoneno,
                                    _token: '<?php echo e(csrf_token()); ?>',
                                    oid: pbg_id
                                },
                                dataType: "text",
                                success: function(resultData) {

                                    if (resultData == '1') {

                                        swal({
                                            title: "",
                                            text: "OTP is verified successfully",
                                            type: "success",
                                        }, function() {

                                            window.location = baseurl + 'buyers/manage_pbg/';

                                        });

                                    } else if (resultData == '0') {

                                        $('#otp1').val('');
                                        $('#otp2').val('');
                                        $('#otp3').val('');
                                        $('#otp4').val('');
                                        $('#otp5').val('');
                                        $('#otp6').val('');
                                        swal("", "Please Enter a valid OTP", "warning");
                                        //alert('Please Enter a valid otp');
                                    } else {


                                        $('#otp1').val('');
                                        $('#otp2').val('');
                                        $('#otp3').val('');
                                        $('#otp4').val('');
                                        $('#otp5').val('');
                                        $('#otp6').val('');

                                        swal("", "Please Enter a valid OTP", "warning");
                                        // alert('Please Enter a valid otp');
                                    }

                                }
                            });

                        }



                    });

                    $('#approvepbg').on('click', function() {
                        $(".pageloader").show();
                        var pbgid = $(this).data("pbgid");
                        $("#pbg_id").val(pbgid);
                        var email = $('#email').val();
                        var phoneno = $('#phone_no').val();
                        var otp = Math.floor(100000 + Math.random() * 900000);


                        var APP_URL = <?php echo json_encode(url('/setotpuser')); ?>;
                        var saveData = $.ajax({
                            type: 'GET',
                            url: APP_URL + '/' + email + '/' + phoneno + '/' + otp,
                            data: {
                                email: email,
                                phoneno: phoneno,
                                otp: otp,
                                _token: '<?php echo e(csrf_token()); ?>'
                            },
                            dataType: "text",
                            success: function(resultData) {
                                console.log(resultData);
                                /*if(resultData == 'success'){
                                    alert('success');
                                }*/
                            }
                        });
                        var SMS_URL = 'https://www.meddbot.com/twiliosms/';
                        var saveData = $.ajax({
                            type: 'POST',
                            url: SMS_URL,
                            data: {
                                phoneno: phoneno,
                                otp: otp,
                                _token: '<?php echo e(csrf_token()); ?>'
                            },
                            dataType: "text",
                            success: function(resultData) {

                                $(".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
                                    });
                                    $(".pageloader").hide();
                                })
                            }
                        });


                    });

                });

                <?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; ?>
            </script>
            <script>
                function sendToGM(id, price, qty) {
                    $('input[name="order_id"]').val(id);
                    $('input[name="price"]').val(price);
                    $('input[name="penality"]').val('0');
                    $('input[name="tds_value"]').val('0');
                    $('input[name="total_price"]').val(price);
                    $('#qty').html(qty);
                    $('#sendToGMModal').modal('show');
                }
                function sendToGMWithPenality(id, price, penality, qty, tds_value) {
                    $('input[name="order_id"]').val(id);
                    $('input[name="price"]').val(price);
                    $('input[name="penality"]').val(penality);
                    $('input[name="tds_value"]').val(tds_value);
                    $('#qty').html(qty);
                    changeTotalPrice()
                    $('#sendToGMModal').modal('show');
                }

                function changeTotalPrice() {
                    let newVal = parseFloat($('input[name="price"]').val()) - parseFloat($('input[name="penality"]').val()) - parseFloat($('input[name="tds_value"]').val());
                    if (isNaN(newVal))
                        $('input[name="total_price"]').val($('input[name="price"]').val());
                    else
                        $('input[name="total_price"]').val(newVal);
                }

                $(document).ready(function() {
                    $('input[name="tds_value"]').blur(function() {
                        if ($(this).val().trim() == "") {
                            $(this).val(0);
                            changeTotalPrice()
                        }
                    });
                    $('input[name="penality"]').blur(function() {
                        if ($(this).val().trim() == "") {
                            $(this).val(0);
                            changeTotalPrice()
                        }
                    });
                    $('#table_id').DataTable();
                });

                function sendToGmAjax() {
                    let orderId = $('input[name="order_id"]').val();
                    let price = $('input[name="price"]').val();
                    let penality = $('input[name="penality"]').val();
                    let tds_value = $('input[name="tds_value"]').val();
                    let remarks = $('#remarks').val();
                    $.ajax({
                        type: "POST",
                        dataType: "json",
                        url: "<?php echo e(url('buyers/send-to-gm-proc')); ?>",
                        data: {
                            orderId: orderId,
                            price: price,
                            penality: penality,
                            tds_value: tds_value,
                            remarks: remarks,
                            _token: '<?php echo e(csrf_token()); ?>'
                        },
                        success: function(response) {
                            if (response.status == true) {
                                swal({
                                    title: "",
                                    text: "Price details send to GM",
                                    type: "success",
                                }, function() {

                                    window.location = baseurl + 'buyers/manage_payments_pending/';
                                    //location.reload();
                                    // $('#sendToGMModal').modal('hide');
                                    // $('input[name="order_id"]').val('');
                                    // $('input[name="price"]').val('');
                                    // $('input[name="penality"]').val('0');
                                    // $('input[name="total_price"]').val('');
                                });
                            }
                        }
                    });
                }
                function updatePayment(id) {
                    $('input[name="accounts_id"]').val(id);
                    $('#paymentModal').modal('show');
                }
            </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_rejected.blade.php ENDPATH**/ ?>