<?php 
if(!isset($_SESSION)) { 
  session_start(); 
  include('../includes/dbcon.php');
}
if(empty($_SESSION['rm_id'])):
header('Location:../index.php');
endif;

if(isset($_REQUEST['cat_id']))

  {
 
    $rid=$_GET['cat_id'];
    $stringParts = explode("*", $rid);
    $cat_id  = $stringParts[0];
    $loc_status= $stringParts[1];
   
    if ($loc_status=="1"){
      $cval=0;
    }
    else {
      $cval=1;
    }


    mysqli_query($con,"update company_master set cost_active= $cval where cost=$cat_id ")or die(mysqli_error());


  }  //// end of if(isset($_REQUEST['cat_id']))






?>
<!DOCTYPE html>
<html lang="en">


<head>
  <!-- Required meta tags -->
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  <title>saleshub | User Management </title>
  <!-- plugins:css -->
  <?php include('../includes/commonheader.php');?>



</head>
<body>
 <?php include('../includes/header.php');?>
 <?php include('../includes/leftsidebar.php');?>
           <!-- partial -->
 <div class="main-panel">        
        <div class="content-wrapper">

          <div class="page-header">
            <h3 class="page-title">
                Company Registration
            </h3>
           
          </div>
          <div class="col-12 grid-margin">
              <div class="card">
                <div class="card-body">

              
         
                 
    <form class="needs-validation" novalidate method="post" action="admin_company_add.php" enctype="multipart/form-data" onsubmit="return validateForm()"> 
                  
                    <div class="row">
                      <div class="col-md-6">
                        <div class="form-group row">
                          <label class="col-sm-3 col-form-label">Company Name <span style="color:red;font-size: 15px;font-weight:bold;">*</span></label>



                          <div class="col-sm-9">
                            <input type="text" class="form-control" id="cname" name="cname" placeholder="Name of your Company">
                          </div>
                        </div>
                      </div>
                      <div class="col-md-6">
                        <div class="form-group row">
                          <label class="col-sm-3 col-form-label">Address <span style="color:red;font-size: 15px;font-weight:bold;">*</span></label>
                          <div class="col-sm-9">
                            <input type="text" class="form-control" id="address" name="address" placeholder="Address ">
                          </div>
                        </div>
                      </div>
                    </div>
                    <div class="row">
                      <div class="col-md-6">
                        <div class="form-group row">
                          <label class="col-sm-3 col-form-label">Telephone </label>
                          <div class="col-sm-9">
                            <input type="text" class="form-control" id="tel" name="tel" placeholder="Contact Detail">
                          </div>
                        </div>
                      </div>
                      <div class="col-md-6">
                        <div class="form-group row">
                          <label class="col-sm-3 col-form-label">Email</label>
                          <div class="col-sm-9">
                            <input type="text" class="form-control" id="email" name="email" placeholder="Email">
                          </div>
                        </div>
                      </div>
                    </div>
                    <div class="row">
                      <div class="col-md-6">
                        <div class="form-group row">
                          <label class="col-sm-3 col-form-label">Web Site</label>
                          <div class="col-sm-9">
                            <input type="text" class="form-control" id="web" name="web" placeholder="Web Site">
                          </div>
                        </div>

                     

                     
                        </div>
                      <div class="col-md-6">
                        <div class="form-group row">
                          <label class="col-sm-3 col-form-label">Short Company Code</label>
                          <div class="col-sm-9">
                            <input type="text" class="form-control" id="scode" name="scode" placeholder="Short Company Code">
                          </div>
                        </div>
                      </div>
 </div>
                    <div class="row">
                      <div class="col-md-6">
                        <div class="form-group row">
                          <label class="col-sm-3 col-form-label">VAT Reg. No</label>
                          <div class="col-sm-9">
                            <input type="text" class="form-control" id="br" name="br" placeholder="Business Registration Number">
                          </div>
                        </div>

                         </div>
                      <div class="col-md-6">
                        <div class="form-group row">
                          <label class="col-sm-3 col-form-label">Logo</label>
                          <div class="col-sm-9">
                            <input type="file" class="form-control" id="scode" name="scode" placeholder="Short Company Code">
                          </div>
                        </div>
                      </div>
                    </div>                                     
                 
                     <button type="submit" class="btn btn-primary">Save</button>
                    <button class="btn btn-light">Cancel</button>
                  </form>
                </div>
              </div>
            </div>


  <div class="content-wrapper">
          <div class="col-lg-22 grid-margin stretch-card">
              <div class="card">
                <div class="card-body">
                  <h4 >Company </h4>
                  <p class="card-description">
                    <button type="button" onclick="document.location='home.php'" class="btn btn-warning "><i class="fas fa-arrow-left"></i> Go Back
                    
                  </button>
                  </p>
                  <div class="table-responsive">
                    <table class="table table-hover">
                      <thead>
                        <tr>
                          <th>#</th>
                          <th>Name</th>                         
                          <th>Address</th>
                          <th>telephone</th>
                          <th>Email</th>
                          <th>Web</th>
                          <th>VAT Reg.</th>
                          <th>Active</th> 
                           <th>Edit</th> 
                        </tr>
                      </thead>
                      <tbody>
<?php
$rcount=0;
$query=mysqli_query($con,"SELECT * from company_master")or die(mysqli_error()); 
 while($row=mysqli_fetch_array($query)){   $rcount=$rcount+1;
             
                $cost_name=$row['cost_name'];
                $address=$row['address'];
                $telephone=$row['telephone'];
                $email=$row['email'];
                $web=$row['web'];              
                $cost_active=$row['cost_active'];
                $cost=$row['cost'];
                $br=$row['br'];

                if ($cost_active==1) {
                    $locactive="Yes";
                }
             
                if ($cost_active==0) {
                    $locactive="No";
                }

 ?>
   <tr>
                         <td><?php echo $rcount;  ?></td>
                         <td><?php echo $row['cost_name'];?></td>
                         <td><?php echo $row['address'];?></td>
                         <td><?php echo $row['telephone'];?></td>
                         <td><?php echo $row['email'];?></td>
                         <td><?php echo $row['web'];?></td>
                         <td><?php echo $row['br'];?></td>
                        
                         <td><?php if ($row['cost_active']>0) { ?> &#10004;<?php } else { ?> &#10006; <?php } ?><a href="admin_company.php?cat_id=<?php echo $row['cost'];echo "*";echo $cost_active;?>"> Change</a></td>


                 
</td>  

<td>
         <td><a href="#addvoucher<?php echo $row['cost'];?>" data-target="#addvoucher<?php echo $row['cost'];?>"data-toggle="modal"     </div> <i class="fas fa-edit "></i>  </i> </a> </td>
              </td> 

<!----------------------Model ------------------------------->
     <div id="addvoucher<?php echo $row['cost'];?>" class="modal fade in" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" style="display: none;">
          <div class="modal-dialog" style="width:80%; aria-hidden="true>
          <div class="modal-content" style="height:auto">        
          <div class="modal-body">

             <form class="form-horizontal" method="post" action="admin_company_edit.php" enctype='multipart/form-data'>

               <div class="form-group">
              <label for="exampleInputEmail1">Company Name </label>
              <input type="text" class="form-control" id="costname_edit" name="costname_edit" value="<?php echo $row['cost_name'];?>">
              <input type="hidden" class="form-control" id="cost_edit" name="cost_edit" value="<?php echo $row['cost'];?>">
               </div>


                  <div class="form-group">
                  <label for="exampleInputPassword1">Address</label>
                  <input type="text" class="form-control" id="add_edit" name="add_edit"value="<?php echo $row['address'];?>">
                  </div>  

                     <div class="form-group">
                  <label for="exampleInputPassword1">Telephone</label>
                  <input type="text" class="form-control" id="tele_edit" name="tele_edit"value="<?php echo $row['telephone'];?>">
                  </div>  

                   <div class="form-group">
                  <label for="exampleInputPassword1">Email</label>
                  <input type="text" class="form-control" id="email_edit" name="email_edit"value="<?php echo $row['email'];?>">
                  </div>  

                  <div class="form-group">
                  <label for="exampleInputPassword1">Web Site</label>
                  <input type="text" class="form-control" id="web_edit" name="web_edit"value="<?php echo $row['web'];?>">
                  </div>

                  <div class="form-group">
                  <label for="exampleInputPassword1">VAT Reg. No</label>
                  <input type="text" class="form-control" id="br_edit" name="br_edit"value="<?php echo $row['br'];?>">
                  </div>


                   <div class="modal-footer">
                   <button type="submit" class="btn btn-primary">Save changes</button>
                   <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                   </div>                   
          </form>

             </form> 


          </div>
        </div>
      </div>
    </div>
<!--------------- End of Model ------------------------------------>

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



        </div>  <!----- <div class="content-wrapper">------>
  </div> 
</div>


</div>  <!----- <div class="content-wrapper">------>
  

 </div><!-----End of main panel--~~~~~~~~~~~~~~~~~~~~~~~--------------->
 </div><!-----Dont Delete this DIV--~~~~~~~~~~~~~~~~~~~~~~~--------------->
  <!-- container-scroller -->
<?php include('../includes/footer.php');?>
<?php include('../includes/commonjs.php');?>
 
</body>


</html>

<script>
    $( document ).ready(function() {
         // alert("Please Select Order Type");

    });

function validateForm() { 

    //````````route````````````````````````````````````
    if($('#vroute').val().trim().length == 0) {
           alert("Please enter the route you visited !!!");               
            return false;
    } ////``````````````````````````````````````````

     //````````start mileage````````````````````````````````````
    if ($('#sm').val() == 0){
           alert("Please enter the start mileage !!!");               
            return false;
    } ////``````````````````````````````````````````


 //````````end mileage````````````````````````````````````
    if ($('#em').val() == 0){
           alert("Please enter the end mileage !!!");               
            return false;
    } ////``````````````````


//````````fuel charge````````````````````````````````````
    if ($('#fg').val() == 0){
           alert("Please enter the fuel charge !!!");               
            return false;
    } ////``````````````````


//````````bata````````````````````````````````````
    if ($('#bata').val() == 0){
           alert("Please enter the bata !!!");               
            return false;
    } ////``````````````````

//````````Customer````````````````````````````````````
    if($('#cus').val().trim().length == 0) {
           alert("Please enter visited customer code and name");               
            return false;
      }///``````````````````



 } ///validateForm() { 

</script>

 <!-- End custom js for this page-->
  <script>
  $(function () {
    //Initialize Select2 Elements
    $('.select2').select2()

    //Initialize Select2 Elements
    $('.select2bs4').select2({
      theme: 'bootstrap4'
    })
  })

</script>



