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

$brmid=$_SESSION['linkarisebranchid'];
	$cmpmid=$_SESSION['linkarisecmpmid'];
	$umid = $_SESSION['linkariseumid'];


	//$lower = $_SESSION['qtdtlower'];
	//$upper = $_SESSION['qtdtupper'];
	//$status = $_SESSION['qtstatus'];
		//if($status=='All'){
		$eve = "select * from res_grn_master where cmpmid='$cmpmid' ORDER BY grnmid desc";
		//}
		//else{
		//$eve = "select * from res_grn_master where date(res_grn_master.grndate) between '$lower' and '$upper' and grnstatus='$status' and cmpmid='$cmpmid' ORDER BY grnmid 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++;
				$grnmid=$rtgby2['grnmid'];
				$grnmno=$rtgby2['grnmno'];


					
					$qedit="<a href='grngenerate.php?id=".$rtgby2['grnmid']."'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='grndelete.php?id=".$rtgby2['grnmid']."' 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='grnstatus.php?id=".$rtgby2['grnmid']."'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;

					$invoicefordisplay=$rtgby2['grnfordisplay'];
					$invoicestatus=$rtgby2['grnstatus'];
					$invoicenetamount=$rtgby2['grnnetamount'];

					$invoicedate=date("d-m-Y", strtotime($rtgby2['grndate']));
					$suppliermid=$rtgby2['suppliermid'];
					$grnno=$rtgby2['grnmno'];

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

				$cname='';
				$cmobile='';
				
				$eve1 = "select * from res_party_master where partymid ='$suppliermid'";

				$re1 = mysqli_query($conn, $eve1);
																			
				if(mysqli_num_rows($re1) > 0)

				{											
																				
				while($rt1 = mysqli_fetch_assoc($re1))
				{	
					$cname=$rt1['partyname'];
					$cmobile=$rt1['partymobile'];
						
				}
																				 
				}
					

				$posts[] = array('sno'=> $sno,'grnmid'=> $grnmid, 'invoicefordisplay'=> $invoicefordisplay, 'invoicedate'=> $invoicedate, 'invoicestatus'=> $invoicestatus,'cname'=> $cname,'cmobile'=> $cmobile,'invoicenetamount'=> $invoicenetamount,'grnno'=>$grnno,'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);


?>
