<?php
session_start();
	include("connect.php");	
	header("Access-Control-Allow-Origin: *");

	/* $lower = $_SESSION['qtdtlower'];
	$upper = $_SESSION['qtdtupper']; */
	$cmpmid = $_SESSION['linkarisecmpmid'];
	$brmid=$_SESSION['linkarisebranchid'];
		$umid = $_SESSION['linkariseumid'];
		//$lower = $_SESSION['qtdtlower'];
	$tt=" and addedby=$umid";
	if($_SESSION['linkariseutype']=='Admin')
	{
		$tt="";
	}	
	 $eve = "select * from res_quotation_master where cmpmid=$cmpmid and followup='Yes' $tt  ORDER BY followdate asc";
	
	$re = mysqli_query($conn, $eve);
	$response = array();
	$posts = array();
	
	date_default_timezone_set("Asia/Kolkata");
	$mdate1= date('Y-m-d');

	$result="0";

	if(mysqli_num_rows($re) > 0)
	{
		$sno=0;
		 while($rtgby2 = mysqli_fetch_assoc($re))
		 {
				$sno++;
				$qmno=$rtgby2['qmno'];
					$qmid=$rtgby2['qmid'];
					
					

					$qedit="<a href='quotationfollowupedit.php?id=".$qmid."' data-toggle='tooltip' data-placement='top' title='Edit' class='fa fa-edit fa-lg'> </a>";
					//$tdelete="<a href='typedelete.php?id=".$rt['tmid']."' > Delete </a>";
					$qdelete="<a href='quotationfollowupdelete.php?id=".$qmid."' 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>";
					$view="<a href='quotationfollowupstatus.php?id=".$qmid."' data-toggle='tooltip' data-placement='top' title='View' class='fa fa-eye fa-lg' >  </a>";

					$op=$view."&nbsp;&nbsp;&nbsp; ".$qedit."&nbsp;&nbsp;&nbsp;".$qdelete;

					$qrefno=$rtgby2['qrefno'];
					$qrefno=$qrefno;
					
					$qdate=implode('-', array_reverse(explode('-', $rtgby2['qdate'])));
					$fdate=implode('-', array_reverse(explode('-', $rtgby2['followdate'])));
					
					$qnofordisplay=$rtgby2['qnofordisplay'];
					$grossamount=$rtgby2['qgrossamount'];
					$qnetamount=$rtgby2['qnetamount'];
					$fremarks=$rtgby2['followremarks'];
					$qstatus=$rtgby2['qstatus'];
					$partymid=$rtgby2['partymid'];
					//$fstatus=$rtgby2['fstatus'];
					$followupstatus="<button data-toggle='modal' data-target='#view-modal' data-id='$qmid' id='getUser' class='btn btn-sm btn-warning'>Click Here</button>";

					
					if($qstatus=="In Review")
					{

						$qstatus1 = "<span class='label label-sm label-warning'>In Review</span>";
					}
					else if($qstatus=="Cancelled")
					{
						$qstatus1 = "<span class='label label-sm label label-danger '>Cancelled</span>";
					}
					else if($qstatus=="Converted To Sales")
					{
						$qstatus1 = "<span class='label label-sm label label-info '>Converted</span>";
					}
					else if($qstatus=="Previous")
					{
						$qstatus1 = "<span class='label label-sm label label-info '>Previous</span>";

					}
					else
					{
						$qstatus1 = "<span class='label label-sm label label-info '>$qstatus</span>";

					}

					$preview = "<a href='quotationmasterstatus.php?id=$qmid'> <i class='fa fa-search'></i> </a>";


					$gstcount=0;
					$subcount=0;
					$totalcount=0;
					
					

					 $eve7="select * from res_party_master where partymid=$partymid";
					$partyname="";
					$partycpname="";
					$re7 = mysqli_query($conn, $eve7);
					while($rt7 = mysqli_fetch_assoc($re7))
					{
						$partyname=$rt7['partyname'];
						$partycpname=$rt7['partycpname']."-".$rt7['partymobile'];
					}

					$sname="";
					$revise = "";
					
					$copy="<a href='quotationgenerate.php?copyid=$qmid'> Copy </a>";

					$detail="<button data-toggle='modal' data-target='#view-modal' data-id='$qmid' id='getUser' class='btn btn-xs btn-default'><i class='fa fa-bars'></i></button> <a href='quotationproductexport.php?id=$qmid' target='_blank'><i class='fa fa-download'></i></a>";
					
					if($rtgby2['followdate']<$mdate1)
					{
						$fdate= "<span class='label label-sm label-danger'>$fdate</span>";
					}
					else{
						$fdate= "<span class='label label-sm label-info'>$fdate</span>";
					}
					
					 $op="<a href='#' data-bs-toggle='modal' data-id='".$qmid."' data-bs-target='#kt_modal_followup' class='btn btn-sm btn-primary align-self-center' id='getfollowup'>$fdate</a>";

				$posts[] = array('qmid'=> $qmid, 'sno'=> $sno, 'qmno'=> $qnofordisplay, 'fdate'=> $fdate, 'fremarks'=> $fremarks, 'partyname'=> $partyname,'partycpname'=> $partycpname,'qnetamount'=> $qnetamount,'op'=>$op);




		 }

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


?>
