<?php  require_once('../auth/auth.php'); ?>
<?php
$comid= $_GET['comid'];
if(isset($_GET['bid'])){
$bid= $_GET['bid'];
$areaquery= mysqli_query($conn,"SELECT * FROM business WHERE coid='$coid' AND  bid='$bid' LIMIT 1 ") or die (mysqli_error($conn));
$rowarea= mysqli_fetch_assoc($areaquery);
$com_id=$rowarea['coid'];
$bid=$rowarea['bid'];
$bid_type=$rowarea['bid_type'];
$bid_name=$rowarea['bid_name'];
$bid_gsm=$rowarea['bid_gsm'];
$bid_address=$rowarea['bid_address'];
$bid_shipping_add=$rowarea['bid_shipping_add'];
$bid_td_no=$rowarea['bid_td_no'];
}
?>
<section class="content">
  <div class="container-fluid">
    <div class="row">
      <div class="col-md-12">
        <div class="card card-secondary card-outline direct-chat direct-chat-secondary 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"><i class="fa fa-language"></i>   New Business  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>
        <form id="business_from" action="#" method="post" class="form mt-2"  autocomplete="off"   >
          <?php if(isset($_GET['bid'])){  ?>
          <input type="hidden" name="bis_submit" id="bis_submit" value="<?php echo @$bid ;?>"/>
          <?php }else{?>
          <input type="hidden" name="bis_submit" id="bis_submit" value="0"/>
          <input type="hidden" name="com_id" value="<?php echo $comid ;?>"/>
          <?php } ?>

          <div class="card-body">
            <div class="col-md-12">
              <div class="row mt-2">
                <div class="col-md-3">
                  <div class="form-group">
                    <label><?php echo language(231);?></label>
                    <select name="bid_type" id="bid_type"  class="form-control select2" style="width: 100%;" required="true">
                      <option value="<?php echo  @$bid_type ?>" selected>
                        <?php echo  @$business_type= mysqli_fetch_array (mysqli_query($conn,"SELECT bt_name FROM business_type WHERE btid='$bid_type' LIMIT 1"))['bt_name']; ?>
                      </option>
                      <?php
                      $accat1= mysqli_query($conn,"SELECT btid,bt_name FROM business_type  WHERE btid ") or die (mysqli_error($conn));
                      while($acat1= mysqli_fetch_assoc($accat1)){
                      echo '<option value='.$acat1["btid"].'>'.$acat1["bt_name"]. ' </option>';
                      }
                      ?>
                    </select>
                  </div>
                </div>
                
                <div class="col-md-6">
                  <div class="form-group">
                    <label><?php echo language(26);?>   <b class="text-danger"> *</b></label>
                    <input type="text" id="bid_name" name="bid_name" value="<?php echo  @$bid_name ?>"  class="form-control form-control-sm " required="true">
                  </div>
                </div>
                <div class="col-md-3">
                  <div class="form-group">
                    <label><?php echo language(111);?> <b class="text-danger"> *</b></label>
                    <input type="text" id="bid_gsm" name="bid_gsm" value="<?php echo  @$bid_gsm ?>" class="form-control form-control-sm " required="true">
                  </div>
                </div>
                <div class="col-md-3">
                  <div class="form-group">
                    <label><?php echo language(248);?> <b class="text-danger"> *</b></label>
                    <input type="text" id="bid_address" name="bid_address" value="<?php echo  @$bid_address ?>" class="form-control form-control-sm " required="true">
                  </div>
                </div>
                <div class="col-md-3">
                  <div class="form-group">
                    <label><?php echo language(116);?> <b class="text-danger"> *</b></label>
                    <input type="text" id="bid_shipping_add" name="bid_shipping_add" value="<?php echo  @$bid_shipping_add ?>" class="form-control form-control-sm " required="true">
                  </div>
                </div>
                <div class="col-md-3">
                  <div class="form-group">
                    <label><?php echo language(395);?><b class="text-danger"> *</b></label>
                    <input type="text" id="bid_td_no" name="bid_td_no" value="<?php echo  @$bid_td_no ?>" class="form-control form-control-sm " required="true">
                  </div>
                </div>
                <div class="col-md-3">
                  <div class="form-group">
                    <center><label><?php echo language(131);?></label></center>
                    <input type="text" name="ac_op_date" class="form-control form-control-sm" onmouseover="lcdate(this)" style="text-align:center;" readonly="true" required="true" value="<?php echo $date;?>">
                  </div>
                </div>
              </div>
              <center>
              <div class="card-footer" style="padding: 8px 5px;">
                <button type="reset" class="btn btn-secondary btn-xs">Reset</button>
                <button type="submit" id="save" class="btn btn-success btn-xs"><?php if (@$_GET['bid']) {echo language(25);}else{echo language(23);}?></button>

              </div>
              </center>
            </div>
          </div>
        </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; ">
            </th>
          </tr>
          <table id="trbl_table" class="searchtable ttable" cellpadding="0" cellspacing="0">
            <thead>
              <tr class="sticky-top">
                <th><?php echo language(15); ?></th>
                <th title="Company"> <?php echo language(193); ?> </th>
                <th class="text-center" title="Type"> <?php echo language(207); ?> </th>
                <th class="text-center" title="Business Name"> <?php echo language(26); ?>   </th>
                <th class="text-center" title="Number">  <?php echo language(111);?></th>
                <th class="text-center" title="Address"> <?php echo language(248);?> </th>
                <th class="text-center" title="Shipping Address"> <?php echo language(116);?> </th>
                <th class="text-center" title="Trade No"> <?php echo language(395);?> </th>
                <th class="text-center"><?php echo language(131); ?> </th>
                <th class="text-center"> <?php echo language(90); ?> </th>
                <th class="text-center"> # </th>

              </tr>
            </thead>
            <tbody id="colview">
              <?php
              $i=0;
              $group= mysqli_query($conn,"SELECT * FROM business WHERE coid='$coid'  ORDER BY bid DESC ") or die (mysqli_error($conn));
              while ($rowg= mysqli_fetch_array ($group) ){
              ?>
              <tr>
                
                <td  class="text-center"><?php echo ++$i;?></td>
                <td > <?php echo $com_iddd= mysqli_fetch_array (mysqli_query($conn,"SELECT co_name FROM company WHERE coid ='".$rowg['coid']."' LIMIT 1"))['co_name']; ?></td>
                <td>  <?php echo $business_type= mysqli_fetch_array (mysqli_query($conn,"SELECT bt_name FROM business_type WHERE btid ='".$rowg['bid_type']."' LIMIT 1"))['bt_name']; ?></td>
                <td onclick="pagecall('../company_setup/business_add.php?bid='+'<?php echo $rowg['bid'];?>'+'&comid=<?php echo $comid ?>','#com_profile_view')"><?php echo $rowg['bid_name'];?>  <i class="fa fa-edit float-right"></i> </td>
                <td><?php echo $rowg['bid_gsm'];?></td>
                <td><?php echo $rowg['bid_address'];?></td>
                <td><?php echo $rowg['bid_shipping_add'];?></td>
                <td><?php echo $rowg['bid_td_no'];?></td>
                <td><?php echo $rowg['bid_opining_d'];?></td>
                <td><?php  $status=$rowg['active'];
                  if ($status==1) {
                  echo "Active";
                  }else if($status==0){
                  echo "Deactive";
                  }
                ?></td>

                <td onclick="pagecall('../company_setup/permissoin.php?getid='+'<?php echo $rowg['bid']?>'+'&type=business','#com_profile_view')"> <i class="fa fa-cog"> </i> </td>

                
              </tr>
              <?php } ?>
            </tbody>
          </table>
        </div>
      </div>
    </div>
  </div>
</div>
</section>
<script>
$(document).ready(function() {
$("select").select2();
$('#business_from').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/business_db.php",$(this).serialize(),function(data){
$('#business_from')[0].reset();
$('#save').prop('disabled', false);
$('#save').html(' Save');
var bis_submit = $("#bis_submit").val();
if (bis_submit ==0) {
$.post('../company_setup/business_add.php?comid='+'<?php echo $comid;?>',{},function(res){
$('#com_profile_view').html(res);
});
toastr.success(Showing, '<?php echo "New Balance Add Successful" ?>');
}else if(bis_submit >0){
$.post('../company_setup/business_add.php?comid='+'<?php echo $comid;?>',{},function(res){
$('#com_profile_view').html(res);
});
toastr.success(Showing, '<?php echo "New Update Successful" ?>');
}
});
});
$('.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();
}
});
});

});
</script>