<?php
session_start();
if(!isset($_SESSION['linkarisecrm']))
	{
		header('Location: index.php');
		return;
	}
	include("connect.php");	
	include("removespecial.php");	
	header("Access-Control-Allow-Origin: *");
		$brmid=$_SESSION['linkarisebranchid'];
		$cmpmid=$_SESSION['linkarisecmpmid'];
			$umid = $_SESSION['linkariseumid'];

	
		$tt="";
		if($_SESSION['linkariseutype']<>'Admin')
		{
			$tt=" and umid=$umid";
		}
	 $eve = "select * from res_party_master where cmpmid=$cmpmid and partytype='Supplier' $tt order by partymid desc";

	$re = mysqli_query($conn, $eve);


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

	$result="0";

	if(mysqli_num_rows($re) > 0)
	{
		$i=1;
		while($rt = mysqli_fetch_assoc($re))
		{
			 	$partymid=$rt['partymid'];
			 	$partyno=$rt['partyno'];
			 	$umid=$rt['umid'];

				$iedit="<a href='supplieredit.php?id=".$rt['partymid']."'data-toggle='tooltip' data-placement='top' title='Edit' class='fa fa-edit fa-lg' >  </a>";
				//$iedit="<a href='supplieredit.php?id=".$rt['partymid']."' data-toggle='tooltip' data-placement='top' title='Edit' class='fa fa-edit fa-lg'>  </a>";
				$idelete="<a href='supplierdelete.php?id=".$rt['partymid']."' onclick='return confirm(&#39;Are you sure you want to delete ?&#39;);' data-toggle='tooltip' data-placement='top' title='Delete' class='far fa-trash-alt fa-lg'>  </a>";
				//$idelete="<a href='inquirydelete.php?id=".$rt['partymid']."' 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>";
				
				$idetail="<a href='supplierdetail.php?id=".$rt['partymid']."' data-toggle='tooltip' data-placement='top' title='Detail' class='fa fa-eye fa-lg'>  </a>";
			//$idetail="<a href='inquirystatus.php?id=".$rt['partymid']."' data-toggle='tooltip' data-placement='top' title='Detail' class='fa fa-eye fa-lg'>  </a>";
			

				$op=$idetail."&nbsp;&nbsp;&nbsp;".$iedit."&nbsp;&nbsp;&nbsp;".$idelete;



				$isname=$rt['partyinqsource'];
				$bumid=$rt['partymid'];
				$cmpname=$rt['partyname'];
				$cname=$rt['partycpname'];
				$mobilenumber=$rt['partymobile'];
				$email=$rt['partyemail'];
				$mobile=$rt['partymobile'];
				$partystate=$rt['partystate'];
				$mobilenumber=$rt['partycpname'].'-'.$rt['partymobile'];
				$idate=date("d-m-Y", strtotime($rt['partyinqdate']));  
				$itype=$rt['partytype'];
				$partygstno=$rt['partygstno'];
				$partyaddress=removespecialchar($rt['partyaddress']);
				$idetails=$rt['partyrequirement'];
				$idetails=substr($idetails,0,100);
				if(strlen($idetails)>=99)
				{
					$idetails=$idetails."...";
				}
				$partyinqstatus=$rt['partyinqstatus'];
				$ibudge=$rt['partyinqbudget'];
				$partyinqstatus2="<a href='inquirystatus.php?id=$partymid' >Click Here</a>";
				$uname="";
				$eve7="select * from res_user_master where umid=$umid";
					$re7 = mysqli_query($conn, $eve7);
					while($rt7 = mysqli_fetch_assoc($re7))
					{
						$uname=$rt7['uname'];
						
					}

				$idetails=str_replace ("'","'",$idetails);
				$idetails=str_replace ('"','\"',$idetails);
				$partyinqstatus1="";
				if($partyinqstatus=="Pending")
				{

					$partyinqstatus1="<span class='label label-sm label-info'>Pending <span class='fa fa-edit fa-lg'></span></span>";
				}
				else if($partyinqstatus=="Converted To Sales")
				{

					$partyinqstatus1="<span class='label label-sm label-success'>Converted <span class='fa fa-edit fa-lg'></span></span>";
				}
				else
				{
					$partyinqstatus1="<span class='label label-sm label label-danger '>$partyinqstatus  <span class='fa fa-edit fa-lg'></span> </span>";
				}
				$partyinqstatus1="<a href='inquiryfollowupaddnext.php?id=".$rt['partymid']."' data-toggle='tooltip' data-placement='top' title='Detail' >$partyinqstatus1  </a>";


			//$imid1="@".$imid;
			$imid1="$i";

				$posts[] = array('partymid'=> $partymid,'partyno'=> $partyno, 'op'=> $op,'cname'=> $cname,'cmpname'=> $cmpname,'idate'=> $idate,'itype'=> $itype,'idetails'=> $idetails,'partyinqstatus1'=> $partyinqstatus1,'isname'=> $isname,'email'=>$email,'mobile'=>$mobile,'ibudge'=>$ibudge,'istatus2'=>$partyinqstatus2,'mobilenumber'=>$mobilenumber,'uname'=>$uname,'partystate'=>$partystate,'partygstno'=>$partygstno,'partyaddress'=>$partyaddress);

			$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);
?>
