<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>Accounts Summary</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;">
                           
                            <div class="tab-content meddbot-tabcontent">
                       
                                <div id="menu1">
                                    
                                            <div class="purchase-order custom">
                                                
                                                <div class="product_details-grd custom">
                                                    <div class="order-id d-flex justify-content-between w-100 hd-accnt">
                                                    <h3 >Account Details</h3>
                                                    
                                                    <h4>Order ID <span class="green-order"><?php echo e($accounts_approved['order_id']); ?></span>
                                                    </h4>
                                                </div>

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

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

                                                    </div>
                                                </div>

                                            </div>

                               
                                </div>
                           

                            </div>

                        </div>


                        
                        
















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

                $(document).ready(function() {

                    $('#table_id').DataTable();

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

                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();
                    $.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,
                            _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('');
                                });
                            }
                        }
                    });
                }
                function updatePayment(id) {
                    $.ajax({
                        type: "POST",
                        dataType: "json",
                        url: "<?php echo e(url('buyers/accounts_update_payment')); ?>",
                        data: {
                            id: id,
                            _token: '<?php echo e(csrf_token()); ?>'
                        },
                        success: function(response) {
                            if (response.status == true) {
                                swal({
                                    title: "",
                                    text: "Payment status updated successfully",
                                    type: "success",
                                }, function() {
                                    location.reload();
                                });
                            }
                        }
                    });
                }
            </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/vendors/accounts.blade.php ENDPATH**/ ?>