<?php
session_start();
	include("connect.php");	
	header("Access-Control-Allow-Origin: *");
$cmpmid=$_SESSION['linkarisecmpmid'];
	//$lower = $_SESSION['qtdtlower'];
	//$upper = $_SESSION['qtdtupper'];
	//$status = $_SESSION['qtstatus'];
	$umid = $_SESSION['linkariseumid'];
	$tt='';
	if($_SESSION['linkariseutype']=='User'){
		$tt="and addedby='$umid'";
	}
	
		/* if($status=='All'){
		$eve = "select * from res_quotation_master where cmpmid='$cmpmid' $tt ORDER BY qmid desc";
		}
		else{ */
		$eve = "select * from res_quotation_master where  cmpmid='$cmpmid' $tt ORDER BY qmid desc";
		
	
	$re = mysqli_query($conn, $eve);


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

	$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='quotationgenerate.php?id=".$rtgby2['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='quotationdelete.php?id=".$rtgby2['qmid']."' 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>";
					$view="<a href='quotationmasterstatus.php?id=".$rtgby2['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;
					$qno=$rtgby2['qnofordisplay'];
					//$qno="<a href='download/$qno.pdf' download> $qno </a>";

					$qdate=implode('-', array_reverse(explode('-', $rtgby2['qdate'])));
					$totalitem=$rtgby2['qtotalitem'];
					$total=$rtgby2['qtotalamount'];
					$grossamount=$rtgby2['qgrossamount'];
					$qnetamount=$rtgby2['qnetamount'];
					$qstatus=$rtgby2['qstatus'];
					$partymid=$rtgby2['partymid'];

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

						$qstatus1 = "<div class='badge badge-light-primary fw-bold'>In Review</div>";
					}
					else if($qstatus=="Cancelled")
					{
						$qstatus1 = "<div class='badge badge-light-danger fw-bold'>Cancelled</div>";
					}
					else if($qstatus=="Converted To Sales")
					{
						$qstatus1 = "<div class='badge badge-light-success fw-bold'>Converted To Sales</div>";
					}
					else if($qstatus=="Previous")
					{
						$qstatus1 = "<div class='badge badge-light-primary fw-bold'>Previous</div>";

					}
					else
					{
						$qstatus1 = "<div class='badge badge-light-primary fw-bold'>$qstatus</div>";

					}

					$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";
					$cname="";
					$cmobile="";
					$re7 = mysqli_query($conn, $eve7);
					while($rt7 = mysqli_fetch_assoc($re7))
					{
							$cname=$rt7['partyname'];
							$cmobile=$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>";

				$posts[] = array('qmid'=> $qmid, 'sno'=> $sno, 'qno'=> $qno, 'qdate'=> $qdate,'qrefno'=> $qrefno,'cname'=> $cname,'cmobile'=> $cmobile,'subcount'=> $subcount,'qnetamount'=> $qnetamount,'totalcount'=> $totalcount,'sname'=> $sname,'qstatus'=> $qstatus1,'detail'=> $detail,'revise'=> $revise,'copy'=> $copy,'preview'=> $preview,'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);


?>
