<?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_po_master where  cmpmid=$cmpmid ORDER BY pomid desc";
		//}
		/* else{
		$eve = "select * from res_po_master where date(res_po_master.podate) between '$lower' and '$upper' and postatus='$status' and cmpmid=$cmpmid ORDER BY pomid 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++;
				$pomid=$rtgby2['pomid'];
				$pomno=$rtgby2['pomno'];


					
							$qedit="<a href='purchaseordergenerate.php?id=".$rtgby2['pomid']."'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='purchaseorderdelete.php?id=".$rtgby2['pomid']."' 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='purchaseorderstatus.php?id=".$rtgby2['pomid']."'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;

					$pofordisplay=$rtgby2['pofordisplay'];
					$invoicestatus=$rtgby2['postatus'];
					$invoicenetamount=$rtgby2['ponetamount'];
					$invoicedate=date("d-m-Y", strtotime($rtgby2['podate']));
					$suppliermid=$rtgby2['suppliermid'];

					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($invoicestatus=="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 '>$invoicestatus</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, 'pofordisplay'=> $pofordisplay, 'invoicedate'=> $invoicedate, 'invoicestatus'=> $invoicestatus,'cname'=> $cname,'cmobile'=> $cmobile,'invoicenetamount'=> $invoicenetamount,'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);


?>
