<?php
if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'delete') {
	$del = DB_query("delete from comprative where id='" . $_REQUEST['id'] . "'", $db);
	$del1 = DB_query("delete from comprative_detail where parant_id='" . $_REQUEST['id'] . "'", $db);
	prnMsg(_('Record delete Successfully'), 'success');
	echo "<script>location.href='index.php?route=POModule/process_purchase_order&modid=" . $_REQUEST['modid'] . "&frmid=" . $_REQUEST['frmid'] . "'</script>";
}
?>

<?php
$sql = "SELECT c.id AS PID, c.comparative_no, c.comparative_date, c.site, cd.sppliersId FROM comprative c
INNER JOIN comprative_detail cd ON c.id = cd.parant_id WHERE c.status_active = 0 AND c.po_del_status = 0 GROUP BY c.id, cd.sppliersId ORDER BY c.id DESC";

$PurchOrdersResult = DB_query($sql, $db); ?>
<link rel="stylesheet" href="css/new_mxerp.css">
<div class="body_contain">
	<div class="tab_div">
		<h1>PROCESS PURCHASE ORDER</h1>
		<table border="0" width="100%" cellspacing="0" cellpadding="3" class="thborder">
			<tr>
				<th width="14%">Comparison Number</th>
				<th width="12%">Comparison Date</th>
				<th>Vendor</th>
				<th width="12%">PO Status</th>
				<th width="13%" style="text-align:center;">Process PO/View</th>
				<th width="5%" style="text-align:center;">Delete</th>
			</tr>
			<?php
			$j = 1;
			$k = 0; //row colour counter
			$poStatus = 0;
			if (DB_num_rows($PurchOrdersResult) > 0) {
				while ($row = DB_fetch_array($PurchOrdersResult)) {
					$ChkPO = DB_query("SELECT * FROM purchorders where comperativeId='" . $row['PID'] . "' and vendorId='" . $row['sppliersId'] . "'", $db);
					if (DB_num_rows($ChkPO) > 0) {
						//$poStatus='1';
						continue;
					} else {
						$poStatus = '0';
					}
			?>
					<tr>
						<td><?php echo $row['comparative_no']; ?></td>
						<td><?php echo ConvertSQLDate($row['comparative_date']); ?></td>
						<td><?php echo  $s->GetFieldValue('suppliers', "id='" . $row['sppliersId'] . "'", 'vendor_name');; ?></td>
						<td><?php
							if ($poStatus == '1') {
								echo 'PO Generated';
							} else {
								echo 'Not Generated';
							}
							?></td>
						<td style="text-align:center;">
							<?php
							if ($poStatus != '1') { ?>
								<a href="index.php?route=POModule/create_process_po_order_gst<?php echo $rurl; ?>&CPID=<?php echo $row['PID'] ?>&SupplierId=<?php echo $row['sppliersId'] ?>&site=<?php echo $row['site']; ?>"><input type="button" value="Create Purchase Order" class="search" /></a>
							<?php } else { ?>
								<input type="button" value="PO Generated" class="search" />
							<?php } ?>
						</td>
						<td style="text-align:center;">
							<a href="index.php?route=POModule/process_purchase_order_gst&modid=<?php echo $_REQUEST['modid']; ?>&frmid=<?php echo $_REQUEST['frmid']; ?>&action=delete&id=<?php echo $row['PID']; ?>" onclick="return confirm('This record will be deleted. Are you sure?')"><img src="images/Icon_Delete.png" height="15" width="15" title="Delete" /></a>
						</td>
					</tr>
				<?php $j++;
				}
			} else { ?>
				<tr>
					<td colspan="6">
						<font color="#FF0000">No Record Found!</font>
					</td>
				</tr>
			<?php } ?>
		</table>

	</div>
</div>