<?php require_once('../auth/auth.php'); ?>
<?php
if(isset($_GET['bwid'])){
   $bwid= $_GET['bwid'];
   $areaquery= mysqli_query($conn,"SELECT bid,warehouse_code,war_location FROM business_w_house WHERE bwid='$bwid' LIMIT 1 ") or die (mysqli_error($conn));
  $rowarea= mysqli_fetch_assoc($areaquery);
   $warehouse_code=$rowarea['warehouse_code'];
   $war_location=$rowarea['war_location'];
}
?>
<section class="content">
  <div class="container-fluid">
    <div class="row">
     <div class="col-md-8">
       <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: 5px 8px;"><h3 class="card-title"><?php echo language(332); ?></h3> <div class="card-tools"> <button type="button" class="btn btn-tool" data-card-widget="remove"> <i class="fas fa-times"></i>  </button> </div>
       </div>
       <form id="newwarehouse_form" action="#" method="post" autocomplete="off">
        <?php if(isset($_GET['bwid'])){  ?>
        <input type="hidden" name="newwarehouse" id="newwarehouse" value="<?php echo @$bwid ;?>"/>
        <?php }else{?>
        <input type="hidden" name="newwarehouse" id="newwarehouse" value="0"/>
        <?php } ?>

        <div class="card-body">
         <div class="col-md-12">
           <div class="row">

                <div class="col-md-6">
              <div class="form-group">
                <label><?php echo language(231); ?><b class="text-danger"> *</b></label>
                <select name="bid" id="bid" class="form-control select2" style="width: 100%;" required="true">
                    <?php 
         $bid_query= mysqli_query($conn,"SELECT * FROM business  WHERE coid='$coid' ") or die (mysqli_error($conn));
         while($bidrow= mysqli_fetch_assoc($bid_query)){
           echo '<option value='.$bidrow["bid"].'>'.$bidrow["bid_name"].'('.$bidrow["bid_gsm"].') </option>'; 
         }?> 
                </select> 
              </div>
            </div>
            
            
                    <div class="col-md-6">
              <div class="form-group">
                <label><?php echo language(232); ?><b class="text-danger"> *</b></label>
                <select name="brid" id="brid" class="form-control select2" style="width: 100%;" required="true">
                    <?php 
         $brid_query= mysqli_query($conn,"SELECT * FROM branch  WHERE coid='$coid' ") or die (mysqli_error($conn));
         while($bridrow= mysqli_fetch_assoc($brid_query)){
           echo '<option value='.$bridrow["brid"].'>'.$bridrow["branch_name"].'('.$bridrow["branch_number"].') </option>'; 
         }?> 
                </select> 
              </div>
            </div>
            
            
            
            <div class="col-md-6">
              <div class="form-group">
                <label><?php echo language(333); ?> <b class="text-danger"> *</b></label>
                <input type="text" name="warehouse_code"  value="<?php echo @$warehouse_code ?>" class="form-control form-control-sm inputselect"  required="true">
              </div>
            </div>

            <div class="col-md-6">
              <div class="form-group">
                <label><?php echo language(334); ?><b class="text-danger"> *</b></label>
                <input type="text" name="war_location"  value="<?php echo @$war_location ?>" class="form-control form-control-sm inputselect"  required="true">
              </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"><?php if (@$_GET['bwid']) {echo language(25);}else{echo language(23);}?></button>
        <button type="reset" class="btn btn-secondary btn-xs"><?php echo language(24);?></button>
      </div>
    </center>
  </form>
  <div class="card-body p-1">
    <tr>
      <th rowspan="3"  class="text-center" >
        <input type="text" id="search" class="form-control form-control-sm search"  placeholder="searching" required="true" style="border-radius: ;border:1px solid primary;width:100%; text-align:center; padding:; ">
      </th>

    </tr>
    <table id="table table-sm" class="table table-sm " cellpadding="0" cellspacing="0">
      <thead>
        <tr class="sticky-top">
          <th class="text-center">  <?php echo language(15);?></th>
          <th class="text-center"> <?php echo language(319);?> / <?php echo language(320);?> </th>
          <th class="text-center"> <?php echo language(333); ?> </th>
          <th class="text-center"> <?php echo language(334); ?>  </th>
          <th class="text-center"> <?php echo language(131);?> </th>
          <th class="text-center">  <?php echo language(90);?>  </th>

        </tr>
      </thead>
      <tbody id="colview" class="searchtable">
        <?php
        $whare_house_query= mysqli_query($conn,"SELECT * FROM business_w_house  
        
          WHERE  business_w_house.coid='$coid'  ") or die (mysqli_error($conn));
        $i=0;
        while ($rowar= mysqli_fetch_array ($whare_house_query) ){
         $businessid  =$rowar['bid'];
         $branchid  =$rowar['brid'];

          $bid_name=mysqli_fetch_assoc(mysqli_query($conn,"SELECT bid_name FROM business WHERE bid='$businessid'  LIMIT 1 "))['bid_name'];
          $brid_name=mysqli_fetch_assoc(mysqli_query($conn,"SELECT branch_name FROM branch WHERE brid='$branchid'  LIMIT 1 "))['branch_name'];  



         ?>
          <tr class="btn-outline-dark tr-hover delete_op<?php echo $rowar['bwid'];?>"  onclick="pagecall('../company_setup/wharehouse_index.php?bwid='+'<?php echo $rowar['bwid'];?>','#settingview')">
          <td  style="text-align: center;"><?php echo ++$i ?></td>
          <td  style="text-align: center;"><?php echo $bid_name ;?>  > <?php echo $brid_name ;?></td>
          <td  style="text-align: center;"><?php echo $rowar['warehouse_code'];?>  </td>
          <td   style="text-align: center;"><?php echo $rowar['war_location'] ;?>  </td>
          <td  style="text-align: center;"> <?php $date=date_create($rowar['date']);echo date_format($date,"Y/m/d ");?></td>



          <?php if($rowar['default_set'] == 'primary' ){ ?>
             <td  class="bg-success" > <span class="fa fa-star checked"></span> Primary </td>
          <?php } else if($rowar['default_set'] == NULL) { ?>
          <td class="bg-danger" > Secondary  </td>
           <?php  } ?>



        </tr>
      <?php } ?>
    </tbody>
  </table>
</div>
</div>
</div>




<div class="col-md-4">
 <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: 5px 8px;"><h3 class="card-title">New Feature  Add</h3> <div class="card-tools"> <button type="button" class="btn btn-tool" data-card-widget="remove"> <i class="fas fa-times"></i>  </button> </div>
 </div>


 <center>Please Wait for new Feature</center>

</div>
</div>


</div>
</div>
</section>

<script>
 $(document).ready(function() {
     $("#bid,#brid").select2();

   $('#newwarehouse_form').on('submit', function(e){
     $('#save').prop('disabled', true);
     $('#save').html('<span class="spinner-border spinner-border-sm" role="status" aria-hidden="true"></span> '+'Loading...');
     e.preventDefault();  
     $.post("../company_setup/wharehouse_index_db.php",$(this).serialize(),function(data){
      $('#newwarehouse_form')[0].reset();
      $('#save').prop('disabled', false);
      $('#save').html('Save');
      $.post('../company_setup/wharehouse_index.php?running='+1,{},function(res){
       $('#settingview').html(res);
       toastr.success(Showing, '<?php echo "Data Load Succefully " ?>');
     }); 
    });
   });

    $('.search').on('keyup',function(){
      var searchTerm = $(this).val().toLowerCase();
      $('.searchtable tr').each(function(){
        var lineStr = $(this).text().toLowerCase();
        if(lineStr.indexOf(searchTerm) === -1){
          $(this).hide();
        }else{
          $(this).show();
        }
      });
    });

    $('th').each(function (col) {
      $(this).hover(
        function () {
          $(this).addClass('focus');
        },
        function () {
          $(this).removeClass('focus');
        }
        );
      $(this).click(function () {
        if ($(this).is('.asc')) {
          $(this).removeClass('asc');
          $(this).addClass('desc selected');
          sortOrder = -1;
        } else {
          $(this).addClass('asc selected');
          $(this).removeClass('desc');
          sortOrder = 1;
        }
        $(this).siblings().removeClass('asc selected');
        $(this).siblings().removeClass('desc selected');
        var arrData = $('table').find('tbody >tr:has(td)').get();
        arrData.sort(function (a, b) {
          var val1 = $(a).children('td').eq(col).text().toUpperCase();
          var val2 = $(b).children('td').eq(col).text().toUpperCase();
          if ($.isNumeric(val1) && $.isNumeric(val2))
            return sortOrder == 1 ? val1 - val2 : val2 - val1;
          else
            return (val1 < val2) ? -sortOrder : (val1 > val2) ? sortOrder : 0;
        });
        $.each(arrData, function (index, row) {
          $('tbody').append(row);
        });
      });
    });
  });
</script>

