<?php require_once('../auth/auth.php');require_once('../auth/function.php'); ?>
<?php
$post_wh_id = $_POST['wh_id'];
$bwhere= mysqli_query($conn,"SELECT bwid,war_location,warehouse_code FROM business_w_house WHERE coid='$coid' AND bwid ='$post_wh_id' AND active=1 ORDER BY bwid ASC") or die(mysqli_error($conn));
$whereh= mysqli_fetch_assoc($bwhere);
?>
<section class="content">
   <div class="container-fluid">
      <div class="row">
         <div class="col-md-1"></div>
         <div class="col-md-10">
            <div class="card card-danger 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(180);?> </h3>
                  <div class="card-tools m-0">
                     <span class="mark1" onclick="copy(this);" title="Copy Invoice"><?php echo $invoice = invoice("ITRA");?></span>
                     <div class="btn-group">
                        <button type="button" class="btn btn-tool" data-dismiss="modal" data-card-widget="remove" onclick="$.post('../itemadjust/order_list_delete.php',{cinvoice:'<?php echo $invoice;?>'});">
                        <i class="fas fa-times"></i>
                        </button>
                        
                     </div>
                  </div>
               </div>
               <div class="card-body mt-2">
                  <div class="col-md-12">
                     <?php if(per('item_scan_status')==1){ ?>   
                     <form id="auto_scan_form" action="#" method="post" autocomplete="off">
                      <?php } ?>

                        <div class="row">
                           <div class="col-md-3"></div>
                           <div class="col-md-6">
                              <div class="form-group">
                                 <label> <?php echo language(138);?> <span style="margin-left:160px;"> <?php echo $whereh["war_location"] ."   ". $whereh["warehouse_code"];?>    </span>  </label>
                                 <input type="text" id="itemid_details" class="form-control form-control-sm inputselect" required="true" autofocus="true">
                              </div>
                           </div>
                           <div class="col-md-3"></div>
                           <div class="col-md-12">
                              <hr style="margin-top:-5px;margin-bottom: 7px;">
                           </div>
                        </div>
                  <?php if(per('item_scan_status')==1){ ?>
                     </form>
                  <?php } ?>

                  </div>
                  <form id="itransfer_form" action="#" method="post" autocomplete="off">
                     <input type="hidden" name="itar_invoice" value="<?php echo $invoice;?>">
                     <input type="hidden" name="minimumqty" >
                     <div class="col-md-12">
                        <div class="row">
                           <div class="col-md-12">
                              <div class="card-body table-responsive cscroll" style="max-height: 450px;">
                                 <table class="ttable" cellpadding="0" cellspacing="0">
                                    <thead>
                                       <tr class="sticky-top">
                                          <th class="text-center" style="width:2%;"><?php echo language(15);?></th>
                                          <th style="width:35%;"><?php echo language(77);?></th>
                                          <th class="text-center" style="width:10%;"><?php echo language(208);?></th>
                                          <th class="text-center" style="width:8%;"> <?php echo language(180);?> <?php echo language(139);?></th>
                                          <th class="text-center" style="width:10%;"><?php echo language(98);?></th>
                                          <th class="text-center" style="width:8%;"><?php echo language(268);?></th>
                                          <th class="text-center" style="width:2%;">#</th>
                                       </tr>
                                    </thead>
                                 <tbody id="itra_row_show<?php echo $invoice;?>"></tbody>
                              </table>
                           </div>
                        </div>
                        <div class="col-md-12"><hr style="margin-top: 7px;margin-bottom: 7px;"></div>
                        <div class="col-md-12">
                           <div class="form-row">
                              <div class="col-md-12">
                                 <div class="form-group">
                                    <label><?php echo language(150);?></label>
                                    <textarea name="itransdetails" class="form-control form-control-sm inputselect" rows="2" placeholder="Enter ..."></textarea>
                                 </div>
                              </div>
                              <div class="col-md-12"><hr style="margin-top: 7px;margin-bottom: 7px;"></div>
                              <input type="hidden" name="out_wh_id" value="<?php echo  $post_wh_id ;?>">
                              <div class="col-md-2">  </div>
                              <div class="col-md-4">
                                 <div class="form-group">
                                    <label><?php echo language(104);?></label>
                                    <select name="load_wh_id" class="form-control select2" style="width: 100%;" required="true">
                                       <option value=""></option>
                                       <?php
                                       $bw= mysqli_query($conn,"SELECT bwid,war_location,warehouse_code FROM business_w_house WHERE coid='$coid' AND bid='$bid' AND brid='$brid' AND active=1 AND bwid != '$post_wh_id' ORDER BY bwid ASC") or die(mysqli_error($conn));
                                       while($wh= mysqli_fetch_assoc($bw)){
                                       echo '<option value='.$wh["bwid"].'>'.$wh["war_location"].'    '.$wh["warehouse_code"].'</option>';
                                       }?>
                                    </select>
                                 </div>
                              </div>
                              
                              <div class="col-md-4">
                                 <div class="form-group">
                                    <label><?php echo language(131);?></label>
                                    <input type="text" name="itardate" class="form-control form-control-sm" onmouseover="lcdate(this)" style="text-align:center;" readonly="true" required="true" value="<?php echo $date;?>">
                                 </div>
                              </div>
                              <div class="col-md-2">  </div>
                           </div>
                        </div>
                     </div>
                  </div>
                  <div class="card-footer mt-1" align="center" style="padding: 8px 5px;">
                     <button type="submit" id="itrasave" class="btn btn-success"><i class="fas fa-save"></i> <?php echo language(23);?></button>
                  </div>
               </form>
            </div>
         </div>
      </div>
      <div class="col-md-1"></div>
   </div>
</div>
</section>
<script>
   $("select").select2();
        pagecall('../item_transfer/order_list.php?invoice=<?php echo $invoice?>'+'&wh_id=<?php echo $post_wh_id?>','#itra_row_show<?php echo $invoice;?>',0);
   </script>
   <script>
      $(document).ready(function() {
         $('#itransfer_form').on('submit', function(e){
         e.preventDefault();
            if (Number($('[name=minimumqty]').val()) >0) {
            $('#itrasave').prop('disabled', true);
            $('#itrasave').html('<span class="spinner-border spinner-border-sm" role="status" aria-hidden="true"></span> '+'Loading...');
            $.post("../item_transfer/transfer_index_db.php",$(this).serialize(),function(data){
            toastr.success(Successfully, yourdata);
            $.post("../item_transfer/transfer_index.php",{wh_id : '<?php echo $post_wh_id?>'},function(data){ $('#stockhome').html(data); });
            });
            } else {
            alert('Please Select Item...??');
            }
         });
      });
</script>
<script>
   $(function() {
      $( "#itemid_details" ).autocomplete({
      source: '../item_transfer/select_item.php?wh_id=<?php echo $post_wh_id;?>',
      autoFocus: true,
      select: function( event, ui ) {
      $( "#itemid_details" ).val( ui.item.label );
      $.post("../item_transfer/order_list_db.php",
      {item_id : ui.item.value,oinvoice:'<?php echo $invoice;?>',whid:'<?php echo $post_wh_id;?>'},
      function(data){
      toastr.success(Successfully, yourdata);
      pagecall('../item_transfer/order_list.php?invoice=<?php echo $invoice?>'+'&wh_id=<?php echo $post_wh_id?>','#itra_row_show<?php echo $invoice;?>',0);
      });
      $( "#itemid_details" ).val('');
      return false;
      }
      });
   });
</script>
<!-- for scan  -->
<script>
$(document).ready(function() {
$('#auto_scan_form').on('submit', function(e){
e.preventDefault();
   let item_code = $('#itemid_details').val();
     $.post("../item_transfer/order_list_db.php",{item_code : item_code,sinvoice:'<?php echo $invoice;?>',whid:'<?php echo $post_wh_id;?>'},function(data){
       toastr.success(Successfully, yourdata);
       pagecall('../item_transfer/order_list.php?invoice=<?php echo $invoice?>','#itra_row_show<?php echo $invoice;?>',0);
       $( "#itemid_details" ).val('');
     });
   });
});
</script>
<!-- for scan  -->