<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 PBG</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">
                                <?php if($buyer_type == 'proc'): ?>
                                <div class="form-inputs">
                                    <div class="form-group">
                                      <label>Consignee</label>
                                      <select class="form-control" id="buyer_filter" name="buyer_filter">
                                        <option value="all">All</option>
                                        <?php $__currentLoopData = $individual_buyers; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $individual_buyers): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                        <option value="<?php echo e($individual_buyers->id); ?>"><?php echo e($individual_buyers->name); ?></option>
                                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                      </select>
                                    </div>
                                </div>
                                <?php endif; ?>
                              </div>
                          	<div class="boxings po-sum" style="border-radius: 15px;">
                              <ul class="nav nav-tabs meddbot-tab">
                                    <li class="active"><a class="active show" href="<?php echo e(url('/buyers/manage_pbg')); ?>">Pending</a></li>
                                    <li><a href="<?php echo e(url('/buyers/manage_pbg_approved')); ?>">Approved</a></li>
                                    <li><a href="<?php echo e(url('/buyers/manage_pbg_rejected')); ?>">Rejected</a></li> 
                              </ul>
                            <div class="tab-content meddbot-tabcontent">
                                <div id="home" class="tab-pane fade in active show">
                        <?php if(count($pbg_summary_pending)!=0): ?>        
                            <?php $__currentLoopData = $pbg_summary_pending; $__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->po_id); ?></span></h4>
                                 </div>
                                 <div class="product_details-grd custom">
                                     <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" >
                                            <?php if($summary->individual_buyerid != '0'): ?>
                                            <li><label class="p-o-label">Consignee</label>: <span><?php echo e(ucfirst(App\Helpers\CustomHelper::manu_name($summary->individual_buyerid))); ?></span></li>
                                            <?php endif; ?>
                                            <?php if($summary->pbgoption==1): ?>
                                             <li><label class="p-o-label">PBG Issue Date</label>: <span><?php echo e($summary->issue_date); ?></span></li>
                                             <li><label class="p-o-label">PBG Expiry Date</label>: <span><?php echo e($summary->expiry_date); ?></span></li>
                                             <li><label class="p-o-label">PBG Number</label>: <span><?php echo e($summary->pbg_number); ?></span></li>
                                             <?php endif; ?>
                                         </ul>
                                         <?php if($summary->pbgoption==1): ?>
                                         <h5 class="bank-details" >Bank Details</h5>
                                         <ul class="custom-details" >
                                             <li><label class="p-o-label">Bank Name</label>: <span><?php echo e(ucfirst($summary->bank_name)); ?></span></li>
                                             <li><label class="p-o-label">Branch</label>: <span><?php echo e(ucfirst($summary->branch_name)); ?></span></li>
                                             <li><label class="p-o-label">Country</label>: <span><?php echo e(ucfirst($summary->countryname)); ?></span></li>
                                            <li><label class="p-o-label">State</label>: <span><?php echo e(ucfirst($summary->statename)); ?></span></li>
                                            <li><label class="p-o-label">Address</label>: <span><?php echo e(ucfirst($summary->address)); ?></span></li>
                                            <li><label class="p-o-label">Contact Name</label>: <span><?php echo e(ucfirst($summary->c_name)); ?></span></li>
                                            <li><label class="p-o-label">Contact Email</label>: <span><?php echo e(ucfirst($summary->c_email)); ?></span></li>
                                            <li><label class="p-o-label">Contact Phone</label>: <span><?php echo e(ucfirst($summary->c_phone)); ?></span></li>
                                         </ul>
                                         <?php endif; ?>
                                     </div>
                                 </div>
                                 <div class="p-o-buttons">
                                        <button class="btn medd-buttons medd-green approvepbg" data-pbgid="<?php echo e($summary->pbgid); ?>">Approve</button>
                                        <button class="btn medd-buttons medd-red" onClick="rejectpbg(<?php echo e($summary->pbgid); ?>)" >Reject</button>
                                        <a href='<?php echo e(url('buyers/po_products/' . $summary->po_id)); ?>'
                                            target="_blank"> <button
                                                class="btn medd-buttons btn-primary">View
                                                Products</button></a>
                                        <a target="_blank" class="" href="<?php echo e(url('uploads/pbgdoc/'.$summary->doc)); ?>"><button class="btn medd-buttons medd-blue">View Document</button></a>
                                 </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="number" onkeyup="onKeyUpEvent(1, event)" placeholder="0" maxlength="1" id="otp1">
                <input type="number" onkeyup="onKeyUpEvent(2, event)" placeholder="0" maxlength="1" id="otp2">
                <input type="number" onkeyup="onKeyUpEvent(3, event)" placeholder="0" maxlength="1" id="otp3">
                <input type="number" onkeyup="onKeyUpEvent(4, event)" placeholder="0" maxlength="1" id="otp4">
                <input type="number" onkeyup="onKeyUpEvent(5, event)" placeholder="0" maxlength="1" id="otp5">
                <input type="number" onkeyup="onKeyUpEvent(6, event)" 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>
              <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_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>
<?php $__env->stopSection(); ?>
<?php $__env->startSection('scripts'); ?>
<script src="<?php echo e(URL::to('assets/js/buyernew.js')); ?>"></script>
              
              
<!--     OTP auto tabing script          -->
    <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;
          }
        }
      }
        
    
     document.querySelectorAll('input[type="number"]').forEach(input =>{
         input.oninput = () =>{
             if(input.value.length > input.maxLength) input.value = input.value.slice(0, input.maxLength);
         };
     }) ;
        
        
        
        
        
        
        
 $(".modal").on('shown.bs.modal', function () {
    $(this).find("#otp1").focus();
});   
        
        
    </script>
              
              
              
              
<script>
$(function() {
$('#buyer_filter').change(function() {   
var $select = $(this);
if ($select.val() == 'all') {
  $('.js-category-filterable').show();
 } 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");  
    }
  });
}
});
});
var newotp='';
$(document).ready(function() {
        //Resend OTP
        $('#resend').on('click', function(event) {
                        $(".pageloader").show();
                        var data = {
                            _token: $('#token_pbg').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 pbg_id= $("#pbg_id").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{

        $(".pageloader").show();
        var data = {
                                _token: $('#token_pbg').val(),
                                pbgid:pbg_id,
                                otp: otp
                            }
                            $.ajax({
                                url: baseurl + 'verifyotpuser_pbg',
                                type: "POST",
                                data: data,
                                success: function(res) {
                                    if (res == true) {
                                        $(".pageloader").hide();
                                        swal({
                                            title: "",
                                            text: "OTP is verified successfully",
                                            type: "success",
                                        }, function() {

                                          
                                            window.location = baseurl +
                                                'buyers/manage_pbg_approved/';
                                        });
                                    } else {
                                        swal("", "Please Enter a valid OTP", "warning");
                                        $(".pageloader").hide();
                                        $('#otp1').val('');
                                        $('#otp2').val('');
                                        $('#otp3').val('');
                                        $('#otp4').val('');
                                        $('#otp5').val('');
                                        $('#otp6').val('');
                                    }
                                }
                            });
                    }
            });
                
    
    $('.approvepbg').on('click', function() {
                $(".pageloader").show();
                var pbgid=$(this).data("pbgid");
                 $("#pbg_id").val(pbgid);
                        var data = {
                            _token: $('#token_pbg').val()
                        }
                        $.ajax({
                            url: baseurl + 'sendOTP',
                            type: "POST",
                            data: data,
                            success: function(res) {
                                console.log(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("", "Invalid  Phone number", "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; ?>
</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/pbg_summary_pending.blade.php ENDPATH**/ ?>