<?php require_once('../auth/auth.php'); ?>
<?php
if(isset($_GET['puid'])){
   $puid= $_GET['puid'];
   $puqu_query= mysqli_query($conn,"SELECT * FROM pro_unit WHERE puid='$puid' AND coid='$coid' LIMIT 1 ") or die (mysqli_error($conn));
  $rowut= mysqli_fetch_assoc($puqu_query);
}
 ?>
<section class="content">
    <div class="container-fluid">
        <div class="row">
         <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"><?php echo language(260); ?></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="unit_form" action="#" method="post" autocomplete="off">
                <?php if(isset($_GET['puid'])){  ?>
                <input type="hidden" name="newunit" id="newunit" value="<?php echo @$puid ;?>"/>
                <?php }else{?>
                <input type="hidden" name="newunit" id="newunit" value="0"/>
                <?php } ?>

                 <div class="card-body">
                     <div class="col-md-12">
                         <div class="row">
                            <div class="col-md-6">
                                <div class="form-group">
                                  <center><label><?php echo language(261); ?><b class="text-danger"> *</b></label></center>
                                  <input type="text" name="unit_name" value="<?php echo @$rowut['unit_name'];?>" class="form-control form-control-sm inputselect"  style="text-align:center;" required="true">
                              </div>
                          </div>

                          <div class="col-md-6">
                              <div class="form-group">
                               <label><?php echo language(262); ?></label>
                               <select name="symble" id="symble"  class="form-control" required="true">
                                <option value="<?php echo @$rowut['unit_symble'];?>" disabled selected> Select <?php echo @$rowut['unit_symble'];?> </option>
                                <option value="Packet">Packet</option>
                                <option value="Kilogram">Kilogram</option>
                                <option value="Pice">Pice</option>
                                <option value="Bag">Bag</option>
                                <option value="Carton">Carton</option>
                                <option value="Meter">Meter</option>
                                <option value="Litre">Litre</option>
                                <option value="foot">foot</option>
                                <option value="inch">inch</option>
                                <option value="gallon">gallon</option>
                                
                                
                                
                                
                                
                                

                            </select>
                        </div>
                    </div>

                          <div class="col-md-12">
                                <div class="form-group">
                                  <center><label> <?php echo language(263); ?><b class="text-danger"> *</b></label></center>
                                  <input type="number" min="1" step="1" name="unit_convart" value="<?php echo @$rowut['unit_convart'];?>"  class="form-control form-control-sm inputselect"  style="text-align:center;" required="true">
                              </div>
                          </div>



                </div>


            </div>
        </div>

        <center>
           <div class="card-footer" style="padding: 8px 5px;">
                    <button type="submit" id="saveu" style="margin-top:19px;" class="btn btn-success btn-xs"><?php if (@$_GET['puid']) {echo language(25);}else{echo language(23);}?></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="trbl_table" class="ttable searchtable" cellpadding="0" cellspacing="0">
  <thead>

    <tr class="sticky-top">
        <th class="text-center" style="width:5%;"><?php echo language(15); ?></th>
        <th style="width:50%;"><?php echo language(261); ?></th>
        <th class="text-center" style="width:40%;"> <?php echo language(264); ?></th>
        <th class="text-center" style="width:5%;">#</th>

    </tr>
</thead>
<tbody id="colview">
    <?php
    $pro_unit_query= mysqli_query($conn,"SELECT * FROM pro_unit WHERE puid AND coid='$coid'  ") or die (mysql_error());
    $i=0;
    while ($rowunit= mysqli_fetch_array ($pro_unit_query) ){
        ?>

                    <tr class="btn-outline-dark tr-hover <?php echo $rowunit['puid'];?>"  onclick="pagecall('../itemstock/unit_index.php?puid='+'<?php echo $rowunit['puid'];?>','#stockhome')">

            <td  style="font-size: 11.5px;text-align: center;"><?php echo ++$i ?></td>
            <td  style="font-size: 11.5px"><?php echo $rowunit['unit_name'] ?>  </td>
            <td  style="font-size: 11.5px"><?php echo $rowunit['unit_symble']?>  (1x<?php echo $rowunit['unit_convart']?>  )</td>
            <td  style="font-size: 11.5px">  </td>

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


<?php 

if(isset($_GET['batid'])){
   $batid= $_GET['batid'];
   $batchh_query= mysqli_query($conn,"SELECT * FROM batch_no WHERE batid='$batid' AND coid='$coid' LIMIT 1 ") or die (mysqli_error($conn));
  $rowbt= mysqli_fetch_assoc($batchh_query);
}

?>
<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(265); ?> </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="batch_form" action="#" method="post" autocomplete="off">
        <input type="hidden" name="newbatch" required="true">
        <?php if(isset($_GET['batid'])){  ?>
        <input type="hidden" name="newbatch" id="newbatch" value="<?php echo @$batid ;?>"/>
        <?php }else{?>
        <input type="hidden" name="newbatch" id="newbatch" value="0"/>
        <?php } ?>

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


           <div class="col-md-4">
              <div class="form-group">
                <label> <?php echo language(266); ?> <b class="text-danger"> *</b></label>
                 <input type="text" name="mate_code" value="<?php echo @$rowbt['mate_code'];?>" class="form-control form-control-sm" required="true" >
              </div>
            </div>

            <div class="col-md-4">
              <div class="form-group">
                <label> <?php echo language(267); ?> <b class="text-danger"> *</b></label>
               <input type="text" name="batch_no" value="<?php echo @$rowbt['batch_no'];?>" class="form-control form-control-sm" required="true" >
              </div>
            </div>


            <div class="col-md-4">
              <div class="form-group">
                <label><?php echo language(128); ?> <b class="text-danger"> *</b></label>
                 <input type="text" name="note" value="<?php echo @$rowbt['note'];?>" class="form-control form-control-sm" required="true" >
              </div>
            </div>




            <div class="col-md-6">
              <div class="form-group">
                <label><?php echo language(257); ?> <b class="text-danger"> *</b></label>
                      <input type="text" name="start_date" value="<?php echo @$rowbt['start_date'];?>" class="form-control form-control-sm" onmouseover="stdate(this)" style="text-align:center;" readonly="true" required="true" value="<?php echo $date;?>">
              </div>
            </div>

            <div class="col-md-6">
              <div class="form-group">
                <label><?php echo language(258); ?><b class="text-danger"> *</b></label>
                      <input type="text" name="expiry_date" value="<?php echo @$rowbt['expiry_date'];?>" class="form-control form-control-sm" onmouseover="stdate(this)" style="text-align:center;" readonly="true" required="true" value="<?php echo $date;?>">
                </div>           
            </div>

          </div>
        </div>
      </div>
      <center>
       <div class="card-footer" style="padding: 8px 5px;">
        <button type="submit" id="saveb" class="btn btn-success btn-xs"><?php if (@$_GET['batid']) {echo  language(25);}else{echo language(23);}?></button>
      </div>
    </center>
  </form>
  <div class="card-body p-1">
    <tr>
      <th rowspan="3"  class="text-center" >
        <input type="text" class="form-control form-control-sm search2"  placeholder="searching" required="true" style="border-radius: ;border:1px solid primary;width:100%; text-align:center; padding:; ">
      </th>

    </tr>
    <table  class=" ttable" cellpadding="0" cellspacing="0">
      <thead>
        <tr class="sticky-top">
          <th class="text-center" style="width:5%;"><?php echo language(15); ?></th>
          <th style="width:25%;"><?php echo language(193); ?> </th>
          <th class="text-center" style="width:25%;"><?php echo language(266); ?> </th>
          <th class="text-center" style="width:25%;"><?php echo language(267); ?> </th>
          <th class="text-center" style="width:25%;"><?php echo language(128); ?></th>
          <th class="text-center" style="width:25%;"><?php echo language(257); ?></th>
          <th class="text-center" style="width:25%;"><?php echo language(258); ?></th>
          <th class="text-center" style="width:20%;"><?php echo language(131); ?></th>
        </tr>
      </thead>
      <tbody id="colviewe" class="searchtable2">
        <?php


        $pro_tax_query= mysqli_query($conn,"SELECT * FROM batch_no WHERE  coid='$coid' AND $bid='$bid' AND brid='$brid'  ") or die (mysqli_error($conn));
        $i=0;
        while ($rowar= mysqli_fetch_array ($pro_tax_query) ){
         $companyid  =$rowar['coid'];
         $co_name=mysqli_fetch_assoc(mysqli_query($conn,"SELECT co_name FROM company WHERE coid='$companyid'  LIMIT 1 "))['co_name'];  
         ?>
          <tr class="btn-outline-dark tr-hover"  onclick="pagecall('../itemstock/unit_index.php?batid='+'<?php echo $rowar['batid'];?>','#stockhome')">
          <td  style="font-size: 11.5px;text-align: center;"><?php echo ++$i ?></td>
          <td  style="font-size: 11.5px"><?php echo $co_name;?> </td>
          <td  style="font-size: 11.5px"><?php echo $rowar['mate_code'];?> </td>
          <td   style="font-size: 11.5px"><?php echo $rowar['batch_no'] ;?>  </td>
          <td  style="font-size: 11.5px"><?php echo $rowar['note'];?></td>
          <td  style="font-size: 11.5px"> <?php echo $rowar['start_date'];?></td>
          <td  style="font-size: 11.5px"> <?php echo $rowar['expiry_date'];?></td>
          <td  style="font-size: 11.5px"> <?php echo $rowar['active'];?></td>


        </tr>
      <?php } ?>
    </tbody>
  </table>
</div>
</div>
</div>
</div>
</div>
</section>
<script>
 $(document).ready(function(){
    $('.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();
      }
  });
  });


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

});
</script>




<script>
 $(document).ready(function() {
    $("select").select2();



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

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




});  
</script>


