<?php 
session_start();
ob_start();
include("../../pidbco/pidbjoin.php");
$sujpath="./";
?>
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>Projects</title>
    <!-- Tell the browser to be responsive to screen width -->
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
    <!-- Bootstrap 3.3.5 -->
    <link rel="stylesheet" href="<?php echo $sujpath; ?>bootstrap/css/bootstrap.min.css">
    <!-- Font Awesome -->
    <link rel="stylesheet" href="<?php echo $sujpath; ?>font-awesome/font-awesome.min.css">
    <!-- Ionicons -->
    <link rel="stylesheet" href="<?php echo $sujpath; ?>font-awesome/ionicons.min.css">
    <!-- DataTables -->
    <link rel="stylesheet" href="<?php echo $sujpath; ?>plugins/datatables/dataTables.bootstrap.css">
    <!-- Theme style -->
    <link rel="stylesheet" href="<?php echo $sujpath; ?>dist/css/AdminLTE.min.css">
    <!-- AdminLTE Skins. Choose a skin from the css/skins
         folder instead of downloading all of them to reduce the load. -->
    <link rel="stylesheet" href="<?php echo $sujpath; ?>dist/css/skins/_all-skins.min.css">
   
    
    <script>
    function add_new_vendor(){
             var vcompany = $('#vcompany').val();
             var vcontact = $('#vcontact').val();
             var vmob = $('#vmob').val();
             var vemail = $('#vemail').val();
             var vmob2 = $('#vmob2').val();
             var vemail2 = $('#vemail2').val();
             var vaddress = $('#vaddress').val();
             var vpin = $('#vpin').val();
             var vcountry = $('#vcountry').val();
             var vstate = $('#vstate').val();
             var vdistrict = $('#vdistrict').val();
             var vstatus = $('#vstatus').val();
             var vcurrent = $('#vcurrent').val();
             var cred_deb = $('#cred_deb').val();
             var gstNo = $('#gstNo').val();
             if(vcompany == ''){
                alert("Enter The Company");   	
             } else if(vmob == ''){
             	alert("Enter Mobile");
             } else {                    
                  $.ajax({
                    type: "POST",
                    url: "ajaxmarket.php",
                     data: {
                          add_new_vendor: 1,
                          vcompany     : vcompany,
                          vcontact     : vcontact,
                          vmob         : vmob,
                          vemail       : vemail,
                          vcountry     : vcountry,
                          vstate       : vstate,
                          vdistrict    : vdistrict,
                          vstatus      : vstatus,
                          vcurrent     : vcurrent,
                          vpin         : vpin,
                          vaddress     : vaddress,
                          vmob2        : vmob2,
                          vemail2      : vemail2,
                          gstNo        : gstNo,
                          cred_deb     : cred_deb
                          
                     },
                     cache: true,
                     success: function(res23)
                     {
                     	   	$('#vcompany').val('');
                           	$('#vcontact').val('');
                           	$('#vmob').val('');
                           	$('#vemail').val('');
                            $('#vmob2').val('');
                            $('#vemail2').val('');
                           	$('#vcountry').val('');
                           	$('#vstate').val('');
                           	$('#vdistrict').val('');
                           	$('#vcurrent').val('');
                           	$('#cred_deb').val('');
                            $('#vaddress').val('');
                            $('#vpin').val('');
                            $('#gstNo').val('');
                           	$("#marketingdiv123").load("vender.php #marketingdiv123");   
                            datat2();                    
                      }
                   }); 
    	    }
    }


    	
    	
       function edit_venders()
       {
             var vcompany = $('#vcompany').val();
             var vcontact = $('#vcontact').val();
             var vmob = $('#vmob').val();
             var vemail = $('#vemail').val();
             var vcountry = $('#vcountry').val();
             var vstate = $('#vstate').val();
             var vdistrict = $('#vdistrict').val();
             var vstatus = $('#vstatus').val();
             var hidvall = $('#hidvall').val();
             var vcurrent = $('#vcurrent').val();
             var cred_deb = $('#cred_deb').val();
             var vmob2 = $('#vmob2').val();
             var vemail2 = $('#vemail2').val();
             var vaddress = $('#vaddress').val();
             var vpin = $('#vpin').val();
             var gstNo = $('#gstNo').val();
             
             if(vcompany == ''){
                alert("Enter The Company");   	
             } else if(vmob == ''){
             	alert("Enter Mobile");
             } else {                    
                  $.ajax({
                    type: "POST",
                    url: "ajaxmarket.php",
                     data: {
                          edit_new_vendor: 1,
                          vcompany     : vcompany,
                          vcontact     : vcontact,
                          vmob         : vmob,
                          vemail       : vemail,
                          vcountry     : vcountry,
                          vstate       : vstate,
                          vdistrict    : vdistrict,
                          vstatus      : vstatus,
                          hidvall      : hidvall,
                          vcurrent     : vcurrent,
                          vpin         : vpin,
                          vaddress     : vaddress,
                          vmob2        : vmob2,
                          vemail2      : vemail2,
                          gstNo        : gstNo,
                          cred_deb     : cred_deb
                     },
                     cache: true,
                     success: function(res23)
                     {
                     	   	$('#vcompany').val('');
                           	$('#vcontact').val('');
                           	$('#vmob').val('');
                           	$('#vemail').val('');
                           	$('#vcountry').val('');
                           	$('#vstate').val('');
                           	$('#vdistrict').val('');
                           	$('#vcurrent').val('');
                           	$('#cred_deb').val('');
                            $('#vmob2').val('');
                            $('#vemail2').val('');
                            $('#vaddress').val('');
                            $('#vpin').val('');
                            $('#gstNo').val('');
                           	$("#marketingdiv123").load("vender.php #marketingdiv123");   
                            datat2();                    
                      }
                   }); 
    	    }

        }
        
        
    	
    	    	
    	function delete_vendor(id)
    	{
    		var result = confirm("Want to delete?");
			if (result) 
			{
     		$.ajax({
			type: "POST",
			url: "ajaxmarket.php",
			data: {
			btn_delete_vendor: 1,
			id:id
			},
			cache: true,
			success: function(res)
			{
			      $("#marketingdiv123").load("vender.php #marketingdiv123");
			      datat();
         	
			}  
			});
   			}
    	}
    	
    	
    	function edit_vendor(id)
    	{
    		$.ajax({
			type: "POST",
			url: "ajaxmarket.php",
			data: {
			btn_edit_market: 1,
			id:id
			},
			cache: true,
			success: function(res)
			{
			
	         	$("#marketingdiv2").load("vender.php?idd2="+id+" #marketingdiv2"); 	
			}  
			});
    	}
    	
    	
function state_change(str)
{
var xmlhttp;
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("vdistrict").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","ajaxmarket.php?state_idd="+str,true);
xmlhttp.send();
}
    </script>
    
  </head>
  <body class="hold-transition skin-blue sidebar-mini">
     <div class="wrapper">
  <?php include("head.php");
    include("left.php"); ?> 
	 
      <!-- Content Wrapper. Contains page content -->
      <div class="content-wrapper" >
        <!-- Content Header (Page header) -->
        <section class="content-header">
          <h1> Vendor
          	<small>- Control panel</small>
          	</h1>
          <ol class="breadcrumb">
            <li><a href="index.php"><i class="fa fa-dashboard"></i> Home</a></li>
            <li class="active">Vendor</li> 
          </ol>
        </section>
  <!-- Main content -->
        <section class="content" >
          <div class="row" >
            <div class="col-xs-12" >





   <div class="box-body" id="marketingdiv2">
  <?php

    if(empty($_GET)){
        
      //$idd2 = strip_tags(base64_decode($_GET['idd2']));
      $comp1='';
      $contact1='';
      $mob1='';
      $mob2='';
      $email1='';
      $email2='';
      $address1='';
      $pin1='';
      $curntbal1='';
      $type1='';
      $status1='';
    }else{
      $idd2 = strip_tags(base64_decode($_GET['idd2']));
	    $sq = mysqli_query($con, "SELECT * FROM `p_vendor` WHERE `vid`='$idd2' " );
	    $rs = mysqli_fetch_assoc($sq);
      $comp1=$rs['v_company'];
      $contact1=$rs['v_contact'];
      $mob1=$rs['v_mob'];
      $mob2=$rs['v_mob2'];
      $email1=$rs['v_email'];
      $email2=$rs['v_email2'];
      $address1=$rs['v_addres'];
      $pin1=$rs['v_pin'];	
      $curntbal1=$rs['v_curntbal'];
      $type1=$rs['v_type'];
      $status1=$rs['v_status'];
      }  
 ?>	 	
			  	
	<div class="box-body" >
 <div class="row" >	
<div class="col-md-12" style="" >
	
<div class="col-md-3"  style="padding-left: 2px; padding-right: 0px;">					
<div class="form-group">
	<input type="text" name="vcompany" id="vcompany" class="form-control" placeholder="Company Name" value="<?php echo $comp1; ?>"/>	
</div></div>

<div class="col-md-3" style="padding-left: 2px; padding-right: 0px;">					
  <div class="form-group">
	<input type="text" name="vcontact" id="vcontact" class="form-control" placeholder="Contact Person" value="<?php echo $contact1; ?>"/>	
 </div></div>
	
 <div class="col-md-3" style="padding-left: 2px; padding-right: 0px;">					
  <div class="form-group">
	<input type="text" name="vmob" id="vmob" onkeypress="return isNumber(event)" class="form-control" placeholder="Mobile 1" value="<?php echo $mob1; ?>"/>	
 </div></div>	

 <div class="col-md-3" style="padding-left: 2px; padding-right: 0px;">          
  <div class="form-group">
  <input type="text" name="vmob2" id="vmob2" onkeypress="return isNumber(event)" class="form-control" placeholder="Mobile 2" value="<?php echo $mob2; ?>"/>  

 </div></div> 
  <div class="col-md-6"  style=" padding-left: 2px; padding-right: 0px; ">     
<div class="form-group">
<textarea name="vaddress" id="vaddress" class="form-control" placeholder="Address" style=" height: 83px;"><?php echo $address1; ?></textarea>  
</div></div>

  <div class="col-md-3" style="padding-left: 2px; padding-right: 0px;">					
  <div class="form-group">
	<input type="text" name="vemail" id="vemail" class="form-control" placeholder="Email 1" value="<?php echo $email1; ?>"/>	
 </div></div>
 
 <div class="col-md-3" style="padding-left: 2px; padding-right: 0px;">          
  <div class="form-group">
  <input type="text" name="vemail2" id="vemail2" class="form-control" placeholder="Email 2" value="<?php echo $email2; ?>"/> 
 </div></div>



<div class="col-md-3" style="padding-left: 2px; padding-right: 0px;">          
  <div class="form-group">
  <input type="text" name="vpin" id="vpin" class="form-control" placeholder="Pin No"  value="<?php echo $pin1; ?>"/> 
 </div></div>
 
<div class="col-md-3" style="padding-left: 2px; padding-right: 0px;">
<div class="form-group">	
<select name="vcountry" id="vcountry" class="form-control">
	<option value="" >Country</option>
		<?php
	$sq2 = mysqli_query($con,"SELECT id,country_name FROM `countries` ");
	while($res2 = mysqli_fetch_array($sq2)){
	   if($res2['country_name'] == 'India'){ ?>	
	<option value="<?php echo $res2['country_name']; ?>" selected><?php echo ucfirst($res2['country_name']); ?></option>
	<?php } else if($rs['v_country'] == $res2['country_name']) { ?>
	<option value="<?php echo $res2['country_name']; ?>" selected><?php echo ucfirst($res2['country_name']); ?></option>
	<?php } else { ?>
		<option value="<?php echo $res2['country_name']; ?>"><?php echo ucfirst($res2['country_name']); ?></option>
    <?php } } ?>
</select>
</div>	
</div>
  
 	
 	</div>	
</div>	


<div class="row" >	
<div class="col-md-12" style="" >
	
	
		
		
<div class="col-md-2" style=" padding-left: 2px; padding-right: 0px; ">			
<div class="form-group">
  <select class="form-control" id="vstate" name="vstate" onchange="state_change(this.value);">
  <option value="">State</option>
        <?php
        $stmt01 = mysqli_query($con,"SELECT * FROM `states` ");
        while($res01 = mysqli_fetch_array($stmt01)) {
        	if($res01['state_name'] == 'KERALA'){ ?>
       <option value="<?php echo $res01['state_name']; ?>" selected><?php echo $res01['state_name']; ?></option> 		
        	<?php } else if($rs['v_state'] == $res01['state_name']){ ?>
        <option value="<?php echo $res01['state_name']; ?>" selected><?php echo $res01['state_name']; ?></option>
	    <?php } else { ?>		 
         <option value="<?php echo $res01['state_name']; ?>"><?php echo $res01['state_name']; ?></option>
        <?php } } ?>
  </select> 
</div></div>


<div class="col-md-2" style="padding-left: 2px; padding-right: 0px;">					
<div class="form-group">
    <select class="form-control" id="vdistrict" name="vdistrict">
    <option value="">District</option>
     <?php 
     $dis = $rs['v_district'];
	 $sta = $rs['v_state'];
	  if($sta == ''){
	 	$sta = 'Kerala';
	 }
	 $stmt01 = mysqli_query($con,"SELECT * FROM `cities` WHERE `state_name`='$sta' ");
        while($res01 = mysqli_fetch_array($stmt01)) {
        	 if($res01['cities_name'] == 'Thrissur'){ ?> 
        <option value="<?php echo $res01['cities_name']; ?>" selected><?php echo $res01['cities_name']; ?></option> 	 	
        <?php } else if($res01['cities_name'] == $dis){ ?> 
        <option value="<?php echo $res01['cities_name']; ?>" selected><?php echo $res01['cities_name']; ?></option>	
        <?php } else { ?>	
        <option value="<?php echo $res01['cities_name']; ?>"><?php echo $res01['cities_name']; ?></option>		
       <?php } } ?>
    </select>
</div></div>

<div class="col-md-2" style="padding-left: 2px; padding-right: 0px;" >					
<div class="form-group">
   <input type="text" class="form-control" placeholder="Current Balance" name="vcurrent" id="vcurrent" value="<?php echo $curntbal1; ?>"/>
</div></div>

<div class="col-md-2" style="padding-left: 2px; padding-right: 0px;">			
<div class="form-group">
  <select class="form-control" id="cred_deb" name="cred_deb">
    <option value="">Type</option>
    <option value="Credit" <?php if($type1 == 'Credit'){ ?> selected <?php } ?>>Credit</option>
    <option value="Debit" <?php if($type1 == 'Debit'){ ?> selected <?php } ?>>Debit</option>     
  </select> 
</div></div>


<div class="col-md-2" style="padding-left: 2px; padding-right: 0px;">					
<div class="form-group">
     <select name="vstatus" id="vstatus" class="form-control">
  	<option value="1" <?php if($status1 == '1'){ ?> selected <?php } ?>>Active</option>
  	<option value="0" <?php if($status1 == '0'){ ?> selected <?php } ?>>InActive</option>  	
  </select>	
</div></div>

	<div class="col-md-2" style="padding-left: 2px; padding-right: 0px;" >         
<div class="form-group">
   <input type="text" class="form-control" placeholder="Gst No" name="gstNo" id="gstNo" value="<?php echo $curntbal1; ?>"/>
</div></div>

<div class="col-md-1"  style=" padding-left: 2px; padding-right: 0px; ">				
<div class="form-group">
  <?php if(!empty($_GET)){ ?>
	<input type="hidden" name="hidvall" id="hidvall" value="<?php echo $rs['vid']; ?>" />
<input type="submit" class="btn btn-primary" name="frasubmit" id="frasubmit" value="Update" onclick="edit_venders();" style=" float: right; margin-right: 10px; " /> 

<?php } else { ?>
<input type="submit" class="btn btn-primary" name="frasubmit" id="frasubmit" value="Submit" onclick="add_new_vendor();" style=" float: right; margin-right: 10px; " />	
<?php } ?> 
</div></div>

</div>




</div>



	
	

</div>
  </div>
  
  
  
  
  
  
<div id="marketingdiv123">


<div class="box" >
   <div class="box-body"  style="padding-left: 10px;padding-right: 10px" >
        <div class="box-body table-responsive no-padding" >
   
  	                 	
                  <table id="example1" class="table table-bordered table-striped" >
                    <thead >
                    <tr >
<th>#</th>                    	
<th>Company</th>
<th>Contact Person</th>
<th>Mobile</th>
<th>State</th>
<th>Status</th>
<th></th>
</tr>
                    </thead>
                    <tbody>
<?php 
$sqq = mysqli_query($con, "SELECT * FROM `p_vendor` ORDER BY vid DESC ");
$p=1;
while($res = mysqli_fetch_assoc($sqq)){
?>
<tr>
	<td><?php echo $p; ?></td>
	<td><?php echo $res['v_company']; ?></td>
	<td><?php echo $res['v_contact']; ?></td>
	<td><?php echo $res['v_mob']; ?></td>
	<td><?php echo $res['v_state']; ?></td>
	<td><?php if($res['v_status'] == '1'){ echo "Active"; } else { echo "InActive"; } ?></td>
	<td>
	&nbsp;  <a href="" data-toggle="modal" data-target="#myModal<?php echo $res['vid']; ?>" style=" cursor: pointer;"><span class="glyphicon glyphicon-eye-open" style="font-size:14px;"></span></a> &nbsp;                	
    <a onClick="edit_vendor('<?php echo base64_encode($res['vid']); ?>');" style=" cursor: pointer;" ><span class="fa fa-pencil" style="font-size:14px;"></span></a> &nbsp;
    <a onClick="delete_vendor('<?php echo base64_encode($res['vid']); ?>');" style=" cursor: pointer;" ><span class="fa fa-trash-o" style="font-size:14px;"></span></a> &nbsp;
	</td>
</tr>



<div class="modal fade" id="myModal<?php echo $res['vid']; ?>" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header" style=" background-color: #E8E8E8;">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title" id="myModalLabel">Vendor Details</h4>
      </div>
      <div class="modal-body" id="myModal2">
  
 <div style=" width:550px; ">
   <div style=" float:left; width:150px;  font-size:14px; color:#0000FF; ">Company Name</div><div style="width:375px; ">: &nbsp;&nbsp; <?php echo $res["v_company"]; ?></div>
   
    <div style=" float:left; width:150px;font-size:14px;color:#0000FF;">Contact Person </div><div style="width:375px;">: &nbsp;&nbsp; <?php echo $res["v_contact"]; ?></div>
     <div style=" float:left; width:150px;font-size:14px;color:#0000FF;">Mobile </div><div style="width:375px;">: &nbsp;&nbsp; <?php echo $res["v_mob"]; ?></div>
      <div style=" float:left; width:150px;font-size:14px;color:#0000FF;">Email </div><div style="width:375px;">: &nbsp;&nbsp; <?php echo $res["v_email"]; ?></div>
        <div style=" float:left; width:150px;font-size:14px;color:#0000FF;">Country </div><div style="width:375px;">: &nbsp;&nbsp; <?php echo $res["v_country"]; ?></div>
   <div style=" float:left; width:150px;font-size:14px;color:#0000FF;">State </div><div style="width:375px;">: &nbsp;&nbsp; <?php echo $res["v_state"]; ?></div>
   <div style=" float:left; width:150px;font-size:14px;color:#0000FF;">District </div><div style="width:375px;">: &nbsp;&nbsp; <?php echo $res["v_district"]; ?></div>
   
   <div style=" float:left; width:150px;font-size:14px;color:#0000FF;">Current Balance </div><div style="width:375px;">: &nbsp;&nbsp; <?php echo $res["v_curntbal"]; ?></div>
   <div style=" float:left; width:150px;font-size:14px;color:#0000FF;">Type </div><div style="width:375px;">: &nbsp;&nbsp; <?php echo $res["v_type"]; ?></div>
   
   <div style=" float:left; width:150px;font-size:14px;color:#0000FF;">Status </div><div style="width:375px;">: &nbsp;&nbsp; <?php if($res["v_status"] == '1'){ echo "Active"; } else { echo "InActive"; } ?></div>
        

 </div>
  
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
       
      </div>
    </div>
  </div>
</div>   
<?php $p=$p+1; } ?>
                    </tbody>
                    </table>
  
         		  </div>
                </div><!-- /.box-body -->
              </div><!-- /.box -->
	
	
</div>
	
		
			
			
			








                           
            </div><!-- /.col -->
          </div><!-- /.row -->
        </section><!-- /.content -->
  </div><!-- /.content-wrapper -->
  </div>
	
    <!-- jQuery 2.1.4 -->
    <script src="<?php echo $sujpath; ?>plugins/jQuery/jQuery-2.1.4.min.js"></script>
    <!-- Bootstrap 3.3.5 -->
    <script src="<?php echo $sujpath; ?>bootstrap/js/bootstrap.min.js"></script>
    <!-- DataTables -->
	<script src="<?php echo $sujpath; ?>plugins/datatables/jquery.dataTables.min.js"></script>
    <script src="<?php echo $sujpath; ?>plugins/datatables/dataTables.bootstrap.min.js"></script>
    <!-- SlimScroll -->
    <script src="<?php echo $sujpath; ?>plugins/slimScroll/jquery.slimscroll.min.js"></script>
    <!-- FastClick -->
    <script src="<?php echo $sujpath; ?>plugins/fastclick/fastclick.min.js"></script>
    <!-- AdminLTE App -->
    <script src="<?php echo $sujpath; ?>dist/js/app.min.js"></script>
    <!-- AdminLTE for demo purposes -->
    <script src="<?php echo $sujpath; ?>dist/js/demo.js"></script>
    <!-- page script -->
    
  <script type="text/javascript">
    function PreviewImage(no) {
    	var oFReader = new FileReader();
        oFReader.readAsDataURL(document.getElementById("uploadImage"+no).files[0]);
        oFReader.onload = function (oFREvent) {
            document.getElementById("uploadPreview"+no).src = oFREvent.target.result;
        };
    }
</script>

<style>
label.filebutton {
    width:120px;
    height:80px;
    overflow:hidden;
    position:relative;
}
label span input {
    z-index: 999;
    line-height: 0;
    font-size: 50px;
    position: absolute;
    top: -2px;
    left: -700px;
    opacity: 0;
    filter: alpha(opacity = 0);
    -ms-filter: "alpha(opacity=0)";
    cursor: pointer;
    _cursor: hand;
    margin: 0;
    padding:0;
}
</style>



    <script>
      $(document).ready(function() {
        $("#example1").DataTable();
      });
      
	function datat(){
	  alert("Data Deleted Successfully.");
      $(document).ready(function() {
        $("#example1").DataTable();
       
      });
    }
    function datat2(){
	  alert("Data Added Successfully");
      $(document).ready(function() {
        $("#example1").DataTable();
       
      });
    }
    function datat3(){
	  alert("Updated Successfully");
      $(document).ready(function() {
        $("#example1").DataTable();
       
      });
    }
   </script>  
   
   
   
  </body>
</html>
