<?php
include("common/connection.php");
login_check();

$Lead_Pa_Id=base64_decode($_REQUEST['Lid']);
$user_type_sql="select User_Type from user_master where User_Name='".$_SESSION['user']."'";
$user_type_query=mysqli_query($con,$user_type_sql);
$user_type=mysqli_fetch_array($user_type_query);
?>
<!doctype html>
<html class="no-js" lang="en">

<head>
    <meta charset="utf-8">
    <meta http-equiv="x-ua-compatible" content="ie=edge">
    <title>Qualified Leads | Buurtzorg</title>
 
    <script type="text/javascript">
	
	function delete_lead(per) 
	{
	  var response = confirm("Are You Sure to Delete Lead!");
	  if (response == true) 
	  {
		$.ajax({
		url:"ajax_delete_lead.php",
		type:"POST",
		data:{'per':per},
		success:function(data)
		{
 			//alert('Lead '+data+' Deleted Successfully');
		}
		});
	  } 
	  else 
	  {
		alert('Lead Not Deleted');
	  }
	}
	</script>
    <script >
	function update_callconnect(Status,Lead_Id)
	{
	 //alert(Status);
	 
	 $.ajax({
		url:"ajax_updatecall_lead.php",
		type:"POST",
		data:{'Status':Status,'Lead_Id':Lead_Id},
		success:function(data)
		{
		//alert(data)
			if(Status=='Call Connected')
			{
			
			  window.location.href='call_connected.php?Lid='+Lead_Id;
			}
			else
			{
			  window.location.href='current_leads.php';
			}
		}
		})
	}
	</script>
    
    <script type="text/javascript">
	function getrate()
	{
		
		var Hours=$('#Duration').val();
		
		
	$.ajax ({
		url:'ajax_patient_agreement.php',
		type:'POST',
		data: 'Hours=' + Hours ,
		success:function(f)
		{
		$("#Rate").val(f);
		}
		})
	}
	</script>
    <script type="text/javascript">
	function keyup()
	{
		var total=$('#numdays2').val();
		
	$.ajax({
			url:'ajax-total-value-agreement.php',
			type:'POST',
			data:'numdays2=' + numdays2,
			success:function(f)
			{
				$('#numdays2').val(f);
			}
		  })
	}
	</script>

    
    
    
    <?php include("headerlink.php"); ?>
    <?php
		//---------user type check-------// 
		$user_sql="select User_Type as type,Location from user_master where User_Name='".$_SESSION['user']."'";
		$user_query=mysqli_query($con,$user_sql);
		$user=mysqli_fetch_array($user_query);
		
		//---------all leads fetching by condition-------// 
		$all_leads_sql="select count(Lead_ID) as total_leads from lead_master";
		
		if($user['type']!='Super Admin')
		{
		//$all_leads_sql.=" where Lead_Referred_To='".$_SESSION['user']."'";
		$all_leads_sql.=" where Control_Location='".$user['Location']."'";
		}
		$all_leads_query=mysqli_query($con,$all_leads_sql);
		$all_leads=mysqli_fetch_array($all_leads_query);
		
		
		//---------fresh leads fetching by condition-------// 
		$fresh_leads_sql="select count(Lead_ID) as fresh_leads from lead_master where Status ='Yet to be Called'";
		
		if($user['type']!='Super Admin')
		{
		//$fresh_leads_sql.=" and Lead_Referred_To='".$_SESSION['user']."'";
		 $fresh_leads_sql.=" and Control_Location='".$user['Location']."'";
		}
		
		$fresh_leads_query=mysqli_query($con,$fresh_leads_sql);
		$fresh_leads=mysqli_fetch_array($fresh_leads_query);
		
		//---------fresh leads fetching by condition-------// 
		$progress_leads_sql="select count(Lead_ID) as progress_leads from lead_master where (Status !='Yet to be Called' and Status !='')";
		
		if($user['type']!='Super Admin')
		{
		//$progress_leads_sql.=" and Lead_Referred_To='".$_SESSION['user']."'";
		 $progress_leads_sql.=" and Control_Location='".$user['Location']."'";
		}
		
		$progress_leads_query=mysqli_query($con,$progress_leads_sql);
		$progress_leads=mysqli_fetch_array($progress_leads_query);
		
		//---------today leads fetching by condition-------// 
		$today_leads_sql="select count(Lead_ID) as today_leads from communication_master where (Status !='Yet to be Called' and Status !='') and Date_Of_Communication LIKE'".date('Y-m-d')."%'";
		
		if($user['type']!='Super Admin')
		{
		$today_leads_sql.=" and Communicator_ID='".$_SESSION['user']."'";
		}
		//echo $today_leads_sql;
		$today_leads_query=mysqli_query($con,$today_leads_sql);
		$today_leads=mysqli_fetch_array($today_leads_query);		
		?>
     	<link rel="stylesheet" href="css/data-table/bootstrap-table.css">
    	<link rel="stylesheet" href="css/data-table/bootstrap-editable.css">
        
        <link rel="stylesheet" href="css/datapicker/datepicker3.css">
         
        
        
        
     
</head>

<body onLoad="getrate()">
	<?php 
		//query for allocation_master
		$sqlag="select * from allocation_master where service_provide='Yes'";
		$agres=mysqli_query($con,$sqlag);
		$agrow=mysqli_fetch_array($agres);
		
		//query for service_master
		$sqlags="select * from service_master where Active='Yes'";
		$ags=mysqli_query($con,$sqlags);
		$count=mysqli_num_rows($ags);
		
		//query for Service_Rate_Master
		$pasql="select * from service_rate_master";
	 	$pares=mysqli_query($con,$pasql);
		$pacount=mysqli_num_rows($pares);
		

	?>
    
    <div class="row">
    <form id="t_size" method="post" onSubmit="return validate1form()" enctype="multipart/form-data" action="">
                <div class="col-md-12 fix-pad" id="org_div">
                
               	<!-- <div class="col-md-4">
               <div class="form-group">
                  <label>Lead id</label>
                  <input class="form-control radius_5" name="li" id="li" placeholder="li" onKeyPress="return isNumberKey(event,1)" autocomplete="off" value="<?php echo $agrow['Lead_ID']; ?>">
                    
                </div>
                </div>-->
                
                <div class="col-md-4">
               <div class="form-group">
                  <label>Scope Of Services</label>
                  <input class="form-control radius_5" name="sos" id="sos" placeholder="Scope of services" onKeyPress="return isNumberKey(event,1)" autocomplete="off" required>
                    
                </div>
                </div>
                
                <div class="col-md-4">
               	<div class="form-group">
                  <label>Patient Name</label>
                  <input class="form-control radius_5" name="pName" id="pName" placeholder="R. K. Agarwal" onBlur="no_color_border('tyre_name')" autocomplete="off" value="<?php echo $agrow['patient_name']; ?>" required>
                </div>
                </div>
                
                <div class="col-md-4">
               <div class="form-group">
                  <label>Service Type </label>
                  <select class="form-control radius_5" name="service" id="Nursing">
                  <option value="">Select Care </option>
                 <?php while ($agsrow=mysqli_fetch_array($ags))
                 	{
                 	?>
                    <option value="<?php echo $agsrow['SLN']; ?>"><?php echo $agsrow['Service'] ?></option>
                    <?php
                    }
					?>
                  </select>
                </div>
                </div>
         
                
                
                <div class="col-md-4">
                <div class="form-group">
                  <label>Start Date </label>
                 <input name="stdate" id="start12" type="text" style="border:0px; border: 1px solid rgb(204, 204, 204); background-color:#ebe7e7; width:100%; height:40px; padding-left:10px;" placeholder="Visit Date" class="form-control txtbox_div" data-rule-required="true" data-msg-required="Please Select Visit date" requered onChange="showDays()">
                    
                </div>
                </div>
                
                <div class="col-md-4">
               <div class="form-group">
                  <label> End Date</label>
                  <input name="ndate" id="finish12" type="text" style="border:0px; border: 1px solid rgb(204, 204, 204); background-color:#ebe7e7; width:100%; height:40px; padding-left:10px;" placeholder="End Date" class="form-control txtbox_div" data-rule-required="true" data-msg-required="Please Select Visit date" onChange="showDays()">
                    
                </div>
                </div>
                
                <div class="col-md-4">
               <div class="form-group">
                  <label>Service Duration/Day</label>
                  <select class="form-control radius_5" name="perhr" id="Duration" placeholder="Service Duration/Day" onKeyPress="return isNumberKey(event,1)" autocomplete="off" onChange="getrate()">
                  	<?php
						while($parow=mysqli_fetch_array($pares))
						{
					 ?>
                  	<option value="<?php echo $parow['Sln']; ?>"><?php echo $parow['Hours']; ?></option>
                    <?php 
						}					
					?>
                    </select>
                </div>
                </div>
                
                <div class="col-md-4">
               <div class="form-group">
                  <label> Rate Per Day</label>
                  <input class="form-control radius_5" name="rpd" id="Rate" placeholder="Rate Per Day" onKeyPress="return isNumberKey(event,1)" autocomplete="off" onChange="keyup()" required>
                    
                </div>
                </div>
               	<div class="col-md-4">
               	<div class="form-group">
                  <label>Total Payable</label>
                  <input class="form-control radius_5" name="Payable" id="numdays2" placeholder="Total Payable" onKeyPress="return isNumberKey(event,1)" autocomplete="off"  value="<?php echo $days ?>" readonly >
                 
               
                </div>
                </div>
                
                </div>
                
                <div class="col-md-3" id="banner_image_main_div" style="display:none; padding-top:25px; padding-bottom:20px;">
                <input type="file" class="radius_5" name="tyre_new_image" id="tyre_new_image">
                  <div class="img_tyre" id="banner_image_div" style="display:none;">
                  
                  </div>
                  <div class="" id="banner_new_image_div" style="display:none;">
                  
                  </div>
                </div>
                
                
                <div class="col-md-12 fix-pad"> 
						
                    
                  <div class="col-md-3"><button type="submit" class="btn btn-block btn-warning" name="tyre_submit" onClick="agreement">ADD</button></div>
               </div>
                   </script>
               	<?php 
					
					if(isset($_REQUEST['tyre_submit'])!="")
					{
						$sqla="insert into  `patient_agreement` (`patient_name`,`service_type`,`start_date`,`end_date`,`service_duration`,`rate_per_day`,`total_payable`,`Scope_Of_Services`,`Lead_ID`) 
							values('".$_REQUEST['pName']."','".$_REQUEST['service']."','".$_REQUEST['stdate']."','".$_REQUEST['ndate']."','".$_REQUEST['perhr']."','".					$_REQUEST['rpd']."','".$payable."','".$_REQUEST['sos']."','".$Lead_Pa_Id."')";
						$pares=mysqli_query($con,$sqla);
						?>
                        <script>
						alert('submited successsfully');
                        	//window.parent.location.href="Pending_Agreement.php";
                        </script>
					<?php 
					}
					?>
                    
                    <!--<script>
        				function Multiply() 
					{
            			var a = document.getElementById("Duration").value;
            			var b = document.getElementById("Rate").value;
						var c = document.getElementById("Payable").value;
            			var result = parseInt(a) * parseInt(b) * parseInt(c);
            			alert(result);
						
        			}
    </script>-->
                </form>
    </div>

    <!-- jquery
		============================================ -->
    <script src="js/vendor/jquery-1.12.4.min.js"></script>
    <!-- bootstrap JS
		============================================ -->
    <script src="js/bootstrap.min.js"></script>
    <!-- wow JS
		============================================ -->
    <script src="js/wow.min.js"></script>
    <!-- price-slider JS
		============================================ -->
    <script src="js/jquery-price-slider.js"></script>
    <!-- meanmenu JS
		============================================ -->
    <script src="js/jquery.meanmenu.js"></script>
    <!-- owl.carousel JS
		============================================ -->
    <script src="js/owl.carousel.min.js"></script>
    <!-- sticky JS
		============================================ -->
    <script src="js/jquery.sticky.js"></script>
    <!-- scrollUp JS
		============================================ -->
    <script src="js/jquery.scrollUp.min.js"></script>
    
    
    <!-- data table JS
		============================================ -->
    <script src="js/data-table/bootstrap-table.js"></script>
    <script src="js/data-table/tableExport.js"></script>
    <script src="js/data-table/data-table-active.js"></script>
    <script src="js/data-table/bootstrap-table-editable.js"></script>
    <script src="js/data-table/bootstrap-editable.js"></script>
    <script src="js/data-table/bootstrap-table-resizable.js"></script>
    <script src="js/data-table/colResizable-1.5.source.js"></script>
    <script src="js/data-table/bootstrap-table-export.js"></script>
    
    
    
    <!-- mCustomScrollbar JS
		============================================ -->
    <script src="js/scrollbar/jquery.mCustomScrollbar.concat.min.js"></script>
    <script src="js/scrollbar/mCustomScrollbar-active.js"></script>
    <!-- metisMenu JS
		============================================ -->
    <script src="js/metisMenu/metisMenu.min.js"></script>
    <script src="js/metisMenu/metisMenu-active.js"></script>
    <!-- peity JS
		============================================ -->
    <script src="js/peity/jquery.peity.min.js"></script>
    <script src="js/peity/peity-active.js"></script>
    <!-- sparkline JS
		============================================ -->
    <script src="js/sparkline/jquery.sparkline.min.js"></script>
    <script src="js/sparkline/sparkline-active.js"></script>
    <!-- tab JS
		============================================ -->
    <script src="js/tab.js"></script>
    <!-- plugins JS
		============================================ -->
    <script src="js/plugins.js"></script>
    <!-- main JS
		============================================ -->
    <script src="js/main.js"></script>
    <!-- tawk chat JS
		============================================ -->
        
         <script>
$(document).ready(function() {
   $("body").tooltip({ 
   	selector: '[data-toggle=tooltip]' 
	 });
});
 
</script>

  <script src="js/main.js"></script>

    <script src="js/datepicker/jquery-ui.min.js"></script>
    <script src="js/datepicker/datepicker-active.js"></script>
    
     <script src="js/form-validation/jquery.form.min.js"></script>
    <script src="js/form-validation/jquery.validate.min.js"></script>
    <script src="js/form-validation/form-active.js"></script>
    <!------------------------Fancybox---------------------------------->
 
 <script type="text/javascript" src="lib/jquery.mousewheel.pack.js"></script>

<script type="text/javascript" src="source/jquery.fancybox.pack.js?v=2.1.5"></script>
	<link rel="stylesheet" type="text/css" href="source/jquery.fancybox.css" media="screen" />

<style type="text/css">
	.fancybox-custom .fancybox-skin {
		box-shadow: 0 0 50px #222;
	}
</style> 
<script>
$(document).ready(function() {
	$(".various").fancybox({
		maxWidth	: 380,
		maxHeight	: 410,
		fitToView	: true,
		width		: '100%',
		height		: '100%',
		autoSize	: false,
		closeClick	: false,
		openEffect	: 'none',
		closeEffect	: 'none',
		
		
		
		
	});
	
	$(".various5").fancybox({

		maxWidth	: 700,

		maxHeight	: 530,

		fitToView	: false,

		width		: '100%',

		height		: '100%',

		autoSize	: false,

		closeClick	: false,

		openEffect	: 'none',

		closeEffect	: 'none'

	});
	
 
});

</script>

<script type="text/javascript">
$("#manual").validate({
          
      showErrors: function(errorMap, errorList) {
          // Clean up any tooltips for valid elements
          $.each(this.validElements(), function (index, element) {
              var $element = $(element);
              $element.data("title", "") // Clear the title - there is no error associated anymore
                  .removeClass("error")
                  .tooltip("destroy");
          });
          // Create new tooltips for invalid elements
          $.each(errorList, function (index, error) {
              var $element = $(error.element);

              $element.tooltip("destroy") // Destroy any pre-existing tooltip so we can repopulate with new tooltip content
                  .data("title", error.message)
                  .addClass("error")
                  .tooltip(); // Create a new tooltip based on the error messsage we just set in the title
          });
      },

     
	  
});
</script> 
<!--    <script src="js/tawk-chat.js"></script>-->
</body>

</html>