<?php require_once('../auth/auth.php'); ?>
<?php
if(isset($_GET['pgid'])){
   $pgid= $_GET['pgid'];
   $groupquery= mysqli_query($conn,"SELECT `pgid`, `coid`, `bid`, `pgroup_name`, `date`, `active` FROM item_group WHERE pgid='$pgid' LIMIT 1 ") or die (mysqli_error($conn));
  $rowarea= mysqli_fetch_assoc($groupquery);
   $pgroup_name=$rowarea['pgroup_name'];
}

$group_check_default = mysqli_query($conn,"SELECT pgid FROM item_group WHERE coid='$coid'");
 $count = mysqli_num_rows($group_check_default);
if($count < 1){
mysqli_query($conn,"INSERT INTO `item_group`(`coid`,`bid`,`pgroup_name`,`date`,`userid`,`active`) VALUES ('$coid','$bid','Common Group','$date','$uid', '1')")or die(mysqli_error($conn));
}

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

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

              <div class="col-md-3">
              <div class="form-group">
        <button type="submit" id="savea" style="margin-top:19px;" class="btn btn-success btn-xs"><?php if (@$_GET['pgid']) {echo language(25);}else{echo language(23);}?></button>
              </div>
            </div>

          </div>
        </div>
      </div>
   
  </form>
  <div class="card-body p-1">
    <tr>
      <th rowspan="3"  class="text-center" >
        <input type="text"  class="form-control form-control-sm searching"  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 class="text-center" style="width:35%;"><?php echo language(26);?></th>

          <th class="text-center" style="width:60%;"><?php echo language(16);?> </th>
 
        </tr>
      </thead>
      <tbody id="colview" class="searchtable11">
        <?php
        $pro_group_query= mysqli_query($conn,"SELECT `pgid`, `coid`, `bid`, `pgroup_name`, `date`, `active` FROM item_group WHERE  coid='$coid' AND $bid='$bid'   ") or die (mysqli_error($conn));
        $i=0;
        while ($rowar= mysqli_fetch_array ($pro_group_query) ){
         ?>
          <tr class="btn-outline-dark tr-hover delete_op<?php echo $rowar['pgid'];?>"  onclick="pagecall('../itemstock/stock_setup.php?pgid='+'<?php echo $rowar['pgid'];?>','#stockhome')">
          <td  style="font-size: 11.5px;text-align: center;"><?php echo ++$i ?></td>
          <td style="font-size: 11.5px"><?php echo $bid_name=mysqli_fetch_assoc(mysqli_query($conn,"SELECT bid_name FROM business WHERE bid='".$rowar['bid']."' LIMIT 1"))['bid_name'];  
;?> </td>
          <td  style="font-size: 11.5px"><?php echo $rowar['pgroup_name'];?> </td>

        </tr>
      <?php } ?>
    </tbody>
  </table>
</div>
</div>
</div>
<!--  group add complete -->
<?php
if(isset($_GET['pcid'])){
   $pcid= $_GET['pcid'];
   $catquery= mysqli_query($conn,"SELECT  `pcid`, `coid`, `bid`, `pcat_name`, `date`, `userid`, `active` FROM `item_catagory` WHERE pcid='$pcid' LIMIT 1 ") or die (mysqli_error($conn));
  $rowpcat= mysqli_fetch_assoc($catquery);
   $pcat_name=$rowpcat['pcat_name'];
}
$group_check_default = mysqli_query($conn,"SELECT pcid FROM item_catagory WHERE coid='$coid' AND bid='$bid' ");
 $count = mysqli_num_rows($group_check_default);
if($count < 1){
mysqli_query($conn,"INSERT INTO `item_catagory`(`coid`,`bid`,`pcat_name`,`date`,`userid`,`active`) VALUES ('$coid','$bid','Common catagory','$date','$uid', '1')")or die(mysqli_error($conn));

}

?>

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

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

              <div class="col-md-3">
              <div class="form-group">
        <button type="submit" id="saveb" style="margin-top:19px;" class="btn btn-success btn-xs"><?php if (@$_GET['pcid']) {echo language(25);}else{ echo language(23);}?></button>
              </div>
            </div>

          </div>
        </div>
      </div>
   
  </form>
  <div class="card-body p-1">
    <tr>
      <th rowspan="3"  class="text-center" >
        <input type="text" class="form-control form-control-sm search1"  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" cellpadding="0" cellspacing="0">
      <thead>
        <tr class="sticky-top">
          <th class="text-center" style="width:5%;"><?php echo language(15);?></th>
          <th class="text-center" style="width:35%;"><?php echo language(26);?> </th>
          <th class="text-center" style="width:60%;"><?php echo language(19);?> </th>

 
        </tr>
      </thead>
      <tbody id="colview" class="searchtable1">
        <?php
        $pro_cat_query= mysqli_query($conn,"SELECT  `pcid`, `coid`, `bid`, `pcat_name`, `date`, `userid`, `active` FROM `item_catagory` WHERE  coid='$coid' AND $bid='$bid' ") or die (mysqli_error($conn));
        $i=0;
        while ($rowvc= mysqli_fetch_array ($pro_cat_query) ){
   
         ?>
          <tr class="btn-outline-dark tr-hover delete_op<?php echo $rowvc['pcid'];?>"  onclick="pagecall('../itemstock/stock_setup.php?pcid='+'<?php echo $rowvc['pcid'];?>','#stockhome')">
          <td  style="font-size: 11.5px;text-align: center;"><?php echo ++$i ?></td>
              <td style="font-size: 11.5px"><?php echo $bid_name=mysqli_fetch_assoc(mysqli_query($conn,"SELECT bid_name FROM business WHERE bid='".$rowvc['bid']."' LIMIT 1"))['bid_name'];  
;?> </td>
          <td  style="font-size: 11.5px"><?php echo $rowvc['pcat_name'];?> </td>
        </tr>
      <?php } ?>
    </tbody>
  </table>
</div>
</div>
</div>
<!-- brand  -->
<?php
if(isset($_GET['pbid'])){
   $pbid= $_GET['pbid'];
   $brandquery= mysqli_query($conn,"SELECT  `pbid`, `coid`, `bid`, `pbrand_name`, `date`, `userid`, `active` FROM `item_brand` WHERE pbid='$pbid' LIMIT 1 ") or die (mysqli_error($conn));
  $rowpbra= mysqli_fetch_assoc($brandquery);
   $pbrand_name=$rowpbra['pbrand_name'];
}

$group_check_default = mysqli_query($conn,"SELECT pbid FROM item_brand WHERE coid='$coid' AND bid='$bid' ");
 $count = mysqli_num_rows($group_check_default);
if($count < 1){
mysqli_query($conn,"INSERT INTO `item_brand`(`coid`,`bid`,`pbrand_name`,`date`,`userid`,`active`) VALUES ('$coid','$bid','Common Brand','$date','$uid', '1')")or die(mysqli_error($conn));
}
?>
     <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(20);?></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="brand_form" action="#" method="post" autocomplete="off">
        <?php if(isset($_GET['pbid'])){  ?>
        <input type="hidden" name="newbrand" id="newbrand" value="<?php echo @$pbid ;?>"/>
        <?php }else{?>
        <input type="hidden" name="newbrand" id="newbrand" value="0"/>
        <?php } ?>

        <div class="card-body">
         <div class="col-md-12">
           <div class="row">
            <div class="col-md-9">
              <div class="form-group">
                <label><?php echo language(21);?><b class="text-danger"> *</b></label>
                <input type="text" name="pbrand_name" autofocus value="<?php echo @$pbrand_name ?>" class="form-control form-control-sm inputselect" style="text-align:center;" required="true">
              </div>
            </div>

              <div class="col-md-3">
              <div class="form-group">
        <button type="submit" id="savec" style="margin-top:19px;" class="btn btn-success btn-xs"><?php if (@$_GET['pbid']) { echo language(25);}else{ echo language(23);}?></button>
              </div>
            </div>

          </div>
        </div>
      </div>
   
  </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 id="trbl_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 class="text-center" style="width:35%;"><?php echo language(26);?> </th>
          <th class="text-center" style="width:60%;"><?php echo language(21);?></ </th>

 
        </tr>
      </thead>
      <tbody id="colview" class="searchtable2">
        <?php
        $pro_brand_query= mysqli_query($conn,"SELECT  `pbid`, `coid`, `bid`, `pbrand_name`, `date`, `userid`, `active` FROM `item_brand` WHERE  coid='$coid' AND $bid='$bid'  ") or die (mysqli_error($conn));
        $i=0;
        while ($rowvb= mysqli_fetch_array ($pro_brand_query) ){
   
         ?>
          <tr class="btn-outline-dark tr-hover delete_op<?php echo $rowvb['pbid'];?>"  onclick="pagecall('../itemstock/stock_setup.php?pbid='+'<?php echo $rowvb['pbid'];?>','#stockhome')">
          <td  style="font-size: 11.5px;text-align: center;"><?php echo ++$i ?></td>
                <td style="font-size: 11.5px"><?php echo $bid_name=mysqli_fetch_assoc(mysqli_query($conn,"SELECT bid_name FROM business WHERE bid='".$rowvb['bid']."' LIMIT 1"))['bid_name'];  
;?> </td>
          <td  style="font-size: 11.5px"><?php echo $rowvb['pbrand_name'];?> </td>
        </tr>
      <?php } ?>
    </tbody>
  </table>
</div>
</div>
</div>



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

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


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

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







    $('.searching').on('keyup',function(){
      var searchTerm = $(this).val().toLowerCase();
      $('.searchtable11 tr').each(function(){
        var lineStr = $(this).text().toLowerCase();
        if(lineStr.indexOf(searchTerm) === -1){
          $(this).hide();
        }else{
          $(this).show();
        }
      });
    });
    
        $('.search1').on('keyup',function(){
      var searchTerm = $(this).val().toLowerCase();
      $('.searchtable1 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>

