<?php
session_start();
$brmid = $_SESSION['linkarisebranchid'];
$cmpmid = $_SESSION['linkarisecmpmid'];
	$umid = $_SESSION['linkariseumid'];
	if(!isset($_SESSION['linkarisecrm']))
	{
		header('Location: index.php');
		return;
	}
	include("connect.php");	header("Access-Control-Allow-Origin: *");
		date_default_timezone_set("Asia/Singapore");
				$mdate1= date('Y-m-d');
//$lower = $_SESSION['qtdtlower'];

	$response = array();
	$posts = array();

	$result="0";
	
	$tt='';
	if($_SESSION['linkariseutype']=='User'){
		$tt="and umid='$umid'";
	}
	  $eve = "select * from res_party_master where partytype='Inquiry' and cmpmid='$cmpmid' $tt and followup='Yes'  ORDER BY followupdate ASC";
	$re = mysqli_query($conn, $eve);

	if(mysqli_num_rows($re) > 0)
	{
		$i=0;
		while($rt = mysqli_fetch_assoc($re))
		{
				$i++;
			 	//$inqfdid=$rt['fdid'];
			 	//$imid=$rt['imid'];
			 	$partymid=$rt['partymid'];
			 	$idetails=$rt['partyrequirement'];
			 	$idate=date("d-m-Y",strtotime($rt['partyinqdate']));
			 	$inqfdate=date("d-m-y",strtotime($rt['followupdate']));
			 	$inqfremarks=$rt['stageremark'];
			 	$inqfollowremarks=$rt['followupremark'];
			 	$istatus=$rt['partyinqstatus'];
			 	$istage=$rt['partystage'];
			 	$_SESSION['stage']=$rt['partystage'];
				
		$stage="";
				if($istage=="New")
				{
					
					$stage="<span class='label label-sm label-success'>New </span>";
				}
				else if($istage=="Completed")
				{
					
					$stage="<span class='label label-sm label-success'>Completed</span>";
				}
				else if($istage=="Hold")
				{
					
					$stage="<span class='label label-sm label-danger'>Hold</span>";
				}
				else if($istage=="In Progress")
				{
					
					$stage="<span class='label label-sm label-warning'>In Progress</span>";
				}
				
				
					$partyno=$rt['partyno'];
					$cmpname=$rt['partyname'];
					$cname=$rt['partycpname']; 
					//$cemail=$rt_category['email']; 
					$cmobile=$rt['partymobile']; 
					
				
				
			
			 	$inqfstatus1= "<span class='label label-sm label-success'>$istatus</span>";
				
				$inqaddfollowup= "<a href='inquiryfollowupaddnext.php?id=$partymid'><i class='fa fa-pencil' title=' Add New Inquiry Follow-Up'></i></a>";
				
				$inqfstatus="aa";
				$fdelete="";
				if($inqfstatus=="Pending"){
				$fdelete="<a href='inquiryfollowupdelete.php?id=".$inqfdid."' data-toggle='tooltip' data-placement='top' title='Delete' class='fa fa-trash-o fa-lg' onclick='return confirm(&#39;Are you sure you want to delete ?&#39;);' >  </a>";
			}
			else{
				$fdelete;
			}
			$stageedit="";
				 $op1="<a href='#' data-bs-toggle='modal' data-id='".$partymid."' data-bs-target='#kt_modal_followup' class='btn btn-sm btn-primary align-self-center' id='getfollowup'>$inqfdate</a>";
				 $cmpnamecontact=$cmobile;
					$op=$op1;
		

				$posts[] = array('i'=> $i,'imid'=> $partyno, 'op'=> $op,'inqfremarks'=> $inqfremarks,'inqfstatus'=> $inqfstatus,'cmpname'=>$cmpname,'cmpnamecontact'=>$cmpnamecontact,'inqfstatus1'=>$stage,'fdelete'=>$fdelete,'idetails'=>$idetails,'idate'=>$idate,'inqfollowremarks'=>$inqfollowremarks);

			//$i++;


		}

		$response['posts'] = $posts;
		echo stripslashes(json_encode( array('data' => $posts)));
		mysqli_close($conn);
		return;
	}

   else
	{
		$result="0";
		$msg="Invalid Error";

		$posts[] = array('p1'=> $result,'p2'=> $msg);

		$response['posts'] = $posts;
		echo stripslashes(json_encode( array('item' => $posts)));
	}

	mysqli_close($conn);
	
	
?>
