<?php require_once('../auth/auth.php'); ?>
<?php 
  $debitor_id = $_GET['debitor_id'];
?>
<div class="row">
   <div class="col-md-3"></div>
   <div class="col-md-6">
      <div class="card card-primary card-outline direct-chat direct-chat-primary shadow-none" style="border-left:1px solid #969c9d;border-right:1px solid #969c9d;border-bottom:1px solid #969c9d;">
         <div class="card-header" style="padding: 3px 8px;">
            <h3 class="card-title">Customer View</h3>
            <div class="card-tools m-0">
               <button type="button" class="btn btn-tool" data-card-widget="remove">
               <i class="fas fa-times"></i>
               </button>
            </div>
         </div>
         <form id="br_form" action="#" autocomplete="off">
            <input type="hidden" name="debitor_id" value="<?php echo $debitor_id;?>">
            <div class="card-body">
               <div class="col-md-12">
                  <div class="row">
                     <div class="col-md-6">
                        <div class="form-group">
                           <label>Select Business<b class="text-danger"> * </b></label>
                           <select name="bid" id="bbid" class="form-control" required="true">
                              <?php 
                                    $prr= mysqli_query($conn,"SELECT bid,bid_name FROM business WHERE coid='$coid'") or die(mysqli_error($conn));
                                      while($prw= mysqli_fetch_assoc($prr)){
                                      echo '<option value='.$prw["bid"].'>'.$prw["bid_name"].'</option>';
                                    }?>
                            </select>
                        </div>
                     </div>
                     <div class="col-md-6">
                        <div class="form-group">
                           <label>Select Branch<b class="text-danger"> * </b></label>
                           <select name="brid" id="viewid" class="form-control" required="true">
                           </select>
                        </div>
                     </div>
                  </div>
               </div>
            </div>
            <center>
               <div class="card-footer" style="padding: 8px 5px;">
                  <button type="submit" id="save" class="btn btn-success btn-xs"> Search <i class="fa fa-arrow-right" aria-hidden="true"></i></button>
               </div>
            </center>
         </form>
      </div>
   </div>
   <div class="col-md-3"></div>
</div>

<script>
   $('select').select2();
   $(document).ready(function() {
     $('#bbid').change(function(e) { 
      var bbid = $(this).val();
       $.post("../customer/branch_show.php",{bbid:bbid},function(data){
         $('#viewid').html(data);
       });
   });
   });  
</script>

<script>
   $(document).ready(function(){
     $('#br_form').on('submit', function(e){
      e.preventDefault();
     $('#save').prop('disabled', true);
     $('#save').html('<span class="spinner-border spinner-border-sm" role="status" aria-hidden="true"></span> '+'Loading...');
     e.preventDefault();  
     $.get("../customer/view_all_customer.php",$(this).serialize(),function(data){
      $('#br_form')[0].reset();
      $('#cusview').html(data);
       toastr.success(Showing, Successfully); 
    });
   });
  });  
</script>