<?php
error_reporting(0);
include('cocoon_config.php');
$title = _('Comprative');
if ($_REQUEST['FinalQuot']) {

	$item = array();
	$prefix_sql = DB_query("Select * from prefix_tbl where prefix_name='" . $_REQUEST['frmid'] . "' and module_id='" . $_REQUEST['modid'] . "' ", $db);
	$prefix_row = DB_fetch_array($prefix_sql);
	$prefix1 = $prefix_row['prefix_code'];
	$financial = substr($_SESSION['YearStart'], -2) . "-" . substr($_SESSION['YearEnd1'], -2);
	$sql = "Select comparative_no from comprative where site='" . $_REQUEST['sitecode'] . "' 
	and INSTR(`comparative_no`, '$financial') > 0 order by id desc limit 0,1";

	$result = DB_query($sql, $db);
	$myrow = DB_fetch_array($result);
	//echo DB_num_rows($result);
	if (DB_num_rows($result) > 0) {
		//$Reqno=$myrow['Reqno'];
		//$req_part1=substr($Reqno,-4);
		$ExplBill = explode("/", $myrow['comparative_no']);
		$maxval = $ExplBill[3];
		//echo $req_part1;
		$req_final = $maxval + 1;
		//echo "<br>".$req_final;
	} else {
		$req_final = "1";
	}

	$string = $_REQUEST['sitecode'] . "/" . $financial . "/" . $prefix1 . "/";
	$final_string = $string . str_pad($req_final, 4, "0", STR_PAD_LEFT);
	//exit;

	$data['indentprno'] = $_REQUEST['RequisitionNo'];
	$data['site'] = $_REQUEST['sitecode'];
	$data['comparative_no'] = $final_string;
	$data['comparative_date'] = date('Y-m-d');
	$data['CompanyId'] = $_SESSION['ACGCompanyId'];
	$data['compared_by'] = $_SESSION['UserID'];
	$data['include_gst'] = '1';
	$s->RecordInsert('comprative', $data);			//INSERT INTO PARENT TABLE
	//$last_id = DB_Last_Insert_ID($db, 'comprative', 'id'); // GET LAST INSERT ID
	$last_id = mysqli_insert_id($db);
	$item = array();
	$ven = array();

	for ($i = 0; $i <= count($_REQUEST['mst_itemid']); $i++) {
		if ($_REQUEST['ACGProductOrder'][$i] == 1) {
			if ($_REQUEST['assign_qty'][$i] != '') {
				$dataArr['parant_id'] = $last_id;
				$dataArr['mst_itemid'] = $_REQUEST['mst_itemid'][$i];
				$dataArr['sppliersId'] = $_REQUEST['sppliersId'][$i];
				$dataArr['currency'] = $_REQUEST['currency'][$i];
				$dataArr['assign_qty'] = $_REQUEST['assign_qty'][$i];
				$dataArr['quotationid'] = $_REQUEST['quotationid'][$i];
				$dataArr['quotation_details_id'] = $_REQUEST['quotation_details_id'][$i];
				$dataArr['indentprno'] = $_REQUEST['RequisitionNo'];
				$dataArr['brand_id'] = $_REQUEST['brand_id'][$i];
				$dataArr['free_qty'] = $_REQUEST['free_qty'][$i];


				//echo "<pre>";
				//print_r($dataArr);
				$s->RecordInsert('comprative_detail', $dataArr);

				$item[$_REQUEST['mst_itemid'][$i]][] = $_REQUEST['assign_qty'][$i];
				$i1[] = $_REQUEST['mst_itemid'][$i];
				$vender[] = $_REQUEST['venderqty'][$i];
				$ven[] = $_REQUEST['quotationid'][$i];
			}
		}
	}


	$da1 = array_unique($ven);
	$da11 = array_values($da1);

	$da2 = array_unique($i1);
	$da3 = array_values($da2);
	$val = array_unique($vender);
	//print_r($vender);

	for ($j = 0; $j < count($vender); $j++) {

		$t = $da3[$j];
		$total = array_sum($item[$t]);
		if ($val[$j] == $total) {

			//echo "update venderquotations set com_status=1 where id='".$da11[$j]."'";

			$update = DB_query("update venderquotations set com_status=1 where id='" . $da11[$j] . "'", $db);
		}
	}


	//exit;
	$s->pageLocation("index.php?route=POModule/process_purchase_order_gst" . $rurl);
}


$id = $_REQUEST['id'];
$RequisitionNo = $_REQUEST['RequisitionNo'];
$lsqlvend = "SELECT * FROM venderquotations WHERE indent_prno='" . $RequisitionNo . "'";
$lresultvand = DB_query($lsqlvend, $db);
$lvendorid = DB_fetch_array($lresultvand);
$vander_code = $lvendorid['vendercode'];
$vander_id = $lvendorid['id'];
$REQ_SQL = "Select * from materialrequisitions where requisitionno='" . $RequisitionNo . "'";
$REQ_Result = DB_query($REQ_SQL, $db);
$REQ_Result_Row = DB_fetch_array($REQ_Result);
$month_year = $REQ_Result_Row['month_year'];
$ReqFarmCode = $REQ_Result_Row['Reqno'];
$prdate = $REQ_Result_Row['prdate'];
?>

<!-- JS PART AMITSINGH  02-05-2013 -->

<script type="text/javascript">
	function checkItems(id) {
		var count_items = document.getElementById("count1_" + id).value;

		if (document.getElementById("final_Quot_" + id).checked == true) {
			for (var k = 1; k < count_items; k++) {
				document.getElementById("ACGProductOrder_" + id + "" + k).disabled = false;
				document.getElementById("assign_qty_" + id + "" + k).disabled = false;
			}
		} else {
			for (var k = 1; k < count_items; k++) {
				document.getElementById("ACGProductOrder_" + id + "" + k).disabled = true;
				document.getElementById("ACGProductOrder_" + id + "" + k).checked = false;
				document.getElementById("assign_qty_" + id + "" + k).value = '';
				document.getElementById("assign_qty_" + id + "" + k).disabled = true;
			}
		}
	}

	function FinalQuotation(str, id) {
		if (document.getElementById("ACGProductOrder_" + id).checked == true) {
			document.getElementById("assign_qty_" + id).value = document.getElementById("venderqty_" + id).value;
			var data = check1(id);
			document.getElementById("Savebutton").style.display = 'block';
		} else if (document.getElementById("ACGProductOrder_" + id).checked == false) {
			document.getElementById("assign_qty_" + id).value = '';
			//document.getElementById("Savebutton").style.display='none';
		}

	}


	function check(i, t, pending) {


		var x = checkQty();
		//	alert(x+"  = "+pending);
		if (parseFloat(x) > parseFloat(pending)) {
			alert("Assign Quantity cannot be greater than Quantity");
		}

		var vid = document.getElementById("viddata").value;
		var k = 0;
		var j;
		for (var m = 0; m < vid; m++) {
			if (document.getElementById("ACGProductOrder_" + m + "" + t).checked == true && (document.getElementById("ACGProductOrder_" + i + "" + t).value == document.getElementById("ACGProductOrder_" + m + "" + t).value)) {
				if (i == m) {
					var k = k + parseFloat(document.getElementById("assign_qty_" + i + "" + t).value);
					var j = parseFloat(document.getElementById("venderqty_" + i + "" + t).value);
					break;
				} else {
					var k = k + parseFloat(document.getElementById("assign_qty_" + m + "" + t).value);
					var j = parseFloat(document.getElementById("venderqty_" + m + "" + t).value);
				}
			}
		}
		if (k > j) {
			alert("Assign Qty Cannot Greater Then Actual Qty");
			document.getElementById("assign_qty_" + i + "" + t).value = '';
			document.getElementById("assign_qty_" + i + "" + t).focus;
		}
	}


	function check1(id) {


		var t = id.substr(1, 1);
		var i = id.substr(0, 1);
		var vid = document.getElementById("viddata").value;
		var k = 0;
		var j;
		for (var m = 0; m < vid; m++) {
			if (document.getElementById("ACGProductOrder_" + m + "" + t).checked == true && (document.getElementById("ACGProductOrder_" + i + "" + t).value == document.getElementById("ACGProductOrder_" + m + "" + t).value)) {
				if (i == m) {
					var k = k + parseFloat(document.getElementById("assign_qty_" + i + "" + t).value);
					var j = parseFloat(document.getElementById("venderqty_" + i + "" + t).value);
					break;
				} else {
					var k = k + parseFloat(document.getElementById("assign_qty_" + m + "" + t).value);
					var j = parseFloat(document.getElementById("venderqty_" + m + "" + t).value);
				}
			}
		}
		if (k > j) {
			alert("Assign Qty Cannot Greater Then Actual Qty");
			document.getElementById("assign_qty_" + i + "" + t).value = '';
			document.getElementById("assign_qty_" + i + "" + t).focus;
		}
	}

	function checkQty() {
		var total = 0;
		jQuery('input[id^=assign_qty_]').each(function() {
			if (jQuery(this).val() != '')
				total += parseFloat(jQuery(this).val());
		});
		return total;
	}

	function checkdata1() {
		var t = 0;
		var k = 0;
		var vid = document.getElementById("viddata").value;
		for (var m = 0; m < vid; m++) {
			if (document.getElementById("final_Quot_" + m).checked == true) {
				var counter = document.getElementById("count1_" + m).value;
				for (var j = 1; j < counter; j++) {
					if (document.getElementById("ACGProductOrder_" + m + "" + j).checked == true) {
						var value = document.getElementById("ACGProductOrder_" + m + "" + j).value;
						var items = (document.getElementById("items_" + m + "-" + value).value).split('-');
						var t = parseFloat(document.getElementById("venderqty_" + m + "" + j).value);
						if (items[0] == document.getElementById("ACGProductOrder_" + (m + 1) + "" + j).value) {
							var k = k + parseFloat(document.getElementById("assign_qty_" + m + "" + j).value);
						}
					}
				}
			}
		}
		alert(k);
		alert(t);
		if (k > t) {
			alert("Assign Qty Cannot Greater Then Actual Qty");
			return false;
		}
		return false;
	}


	function isNumberKey(sender, evt) {
		var txt = sender.value;
		//alert(evt.which);
		var dotcontainer = txt.split('.');
		var charCode = (evt.which) ? evt.which : event.keyCode;
		//alert(event.keyCode);
		if (!(dotcontainer.length == 1 && charCode == 46) && charCode > 31 && (charCode < 48 || charCode > 57))
			return false;

		return true;
	}
</script>


<!-- JS PART AMITSINGH 02-05-2013  -->


<link href="css/new_mxerp.css" rel="stylesheet" type="text/css" />
<div class="body_contain">
	<div class="tab_div">
		<h1>Comparative</h1>
		<form action="" method="post" name="finalqt">
			<table width="100%" border="0" cellpadding="3" cellspacing="0">
				<tr class="row1">
					<td width="13%" align="right"><strong>Comparative No.:</strong></td>
					<td width="35%">Auto Generated <input type="hidden" name="comprativeno" size="30" readonly="" value="Auto Generated" /></td>
					<td width="13%" align="right"><strong>Date:</strong></td>
					<td><?php echo date("d/m/Y"); ?> <input type="hidden" name="comprative_date" size="30" value="<?php echo date("d/m/Y"); ?>" /></td>
				</tr>
				<tr class="row1">
					<td align="right"><strong>Site Name:</strong></td>
					<td><?php echo $s->GetFieldValue('locations', "loccode='" . $lvendorid['Site'] . "'", 'locationname'); ?> <input type="hidden" name="sitecode" id="sitecode" value="<?php echo $lvendorid['Site']; ?>" /></td>
					<td align="right"><strong>Requisition No.:</strong></td>
					<td><?php echo $ReqFarmCode; ?> <input type="hidden" name="reqno" id="reqno" value="<?php echo $RequisitionNo; ?>" /></td>
				</tr>
				<tr class="row1">
					<td align="right"><strong>Requisition Date:</strong></td>
					<td colspan="3"><?php echo ConvertSQLDate($prdate); ?> <input type="hidden" name="reqno_date" id="reqno_date" value="<?php echo ConvertSQLDate($prdate); ?>" /></td>
				</tr>
			</table>
			<br>
			<h3>Vendor Quotations Details</h3>

			<?php
			$data = DB_query("select mapped_vendor from indentpr_mapping where id='" . $_REQUEST['mapid'] . "'", $db);
			$data_row = DB_fetch_array($data);
			$map_ven = explode(",", $data_row['mapped_vendor']);
			$man_ven1 = implode("','", $map_ven);
			$suppsqlvend = "SELECT venderquotations.*,suppliers.vendor_name,suppliers.id  as venderid 
		FROM  venderquotations INNER JOIN suppliers ON suppliers.id=venderquotations.mst_supplierno 
		INNER JOIN vendorquotationdetails ON vendorquotationdetails.parant_id=venderquotations.id 
		WHERE venderquotations.indent_prno=" . $RequisitionNo . " and  com_status=0
 		and venderquotations.mst_supplierno in('" . $man_ven1 . "')    group by id";
			$suppresultvand = DB_query($suppsqlvend, $db);
			$i = 1;
			$vid = 0;
			$k = 1;
			if (DB_num_rows($suppresultvand) > 0) {
				//echo DB_num_rows($suppresultvand);
				while ($suppvendorid = DB_fetch_array($suppresultvand)) {
					$net = 0;
					$tot = 0;
					$basic = 0;
					$tax = 0; ?>

					<?php if ($vid != 0) { ?>
						<table width="100%">
							<tr>
								<td colspan="12">&nbsp;</td>
							</tr>
						</table>
					<?php } ?>
					<table cellpadding="3" cellspacing="0" border="0" width="100%" class="thborder">
						<tr>
							<th width="4%" height="35">&nbsp;</th>
							<th width="16%">Quot. No.</th>
							<th width="8%">Quot. Date</th>
							<th width="10%">Vendor Quot. No.</th>
							<th width="15%">Vendor Quot. Date</th>
							<th>Vendor Name</th>
						</tr>
						<tr>
							<td><input id="final_Quot_<?php echo $vid; ?>" type="checkbox" name="VendorQuotaionId[]" value="<?php echo $suppvendorid['id']; ?>" onclick="checkItems('<?php echo $vid; ?>')" /></td>
							<td><?php echo $suppvendorid['quotation_no']; ?> <input type="hidden" name="Vendorqtnid" id="Vendorqtnid" value="<?php echo $suppvendorid['id']; ?>" /></td>
							<td><?php echo ConvertSQLDate($suppvendorid['Quotation_Date']); ?></td>
							<td><?php echo $suppvendorid['party_Quo_no']; ?>
							<td><?php echo ConvertSQLDate($suppvendorid['party_Quo_date']); ?></td>
							<td><?php echo $suppvendorid['vendor_name']; ?></td>
						</tr>
					</table>
					<br>
					<table width="100%" border="0" cellpadding="3" cellspacing="0" class="thborder">
						<tr>
							<th width="4%"></th>
							<th width="12%">Item Code</th>
							<th>Item Name</th>
							<th width="14%">Brand</th>
							<th width="10%" class="text-right">Quantity</th>
							<th width="10%" class="text-center">Assign Qty</th>
							<th width="9%" class="text-right">Rate</th>
							<th width="12%" class="text-right">Discount Amount</th>
							<th width="12%" class="text-right">Amount</th>
							<!--<td>Special Discount Amount</strong></td>-->
							<!--<td>Basic Amt</strong></td>
			<td>Taxable Amt</strong></td>
			<td>Total</strong></td>-->
						</tr>
						<?php
						$dis = 0;
						//echo "select * from vendor_quotes_ammendment where requisition_id='".$_REQUEST['RequisitionNo']."' and mst_supplierno='".$suppvendorid['mst_supplierno']."'  order by vendor_quotes_ammendment.revision_no DESC limit 1";
						$sqlcheck = DB_query("select * from vendor_quotes_ammendment where requisition_id='" . $_REQUEST['RequisitionNo'] . "' and mst_supplierno='" . $suppvendorid['mst_supplierno'] . "'  order by vendor_quotes_ammendment.revision_no DESC limit 1", $db);
						$numrowcheck = DB_num_rows($sqlcheck);
						$row5 = DB_fetch_array($sqlcheck);
						if ($numrowcheck > 0) {
							$sql = 'SELECT vendor_quotes_ammendment.*, vendor_quotes_ammendment_details.* 
FROM  vendor_quotes_ammendment INNER JOIN vendor_quotes_ammendment_details ON vendor_quotes_ammendment.id=vendor_quotes_ammendment_details.vendor_quotes_ammendment_id 
WHERE vendor_quotes_ammendment.requisition_id=' . $RequisitionNo . ' and vendor_quotes_ammendment.old_quotetion_no=' . $suppvendorid['id'] . ' and  vendor_quotes_ammendment.revision_no=' . $row5['revision_no'] . '';
							$result = DB_query($sql, $db);
							$numdata = DB_num_rows($result);
							$j = 1;
							while ($myrow = DB_fetch_array($result)) {

								$brndSql = "select id,brand_desc from branditems where id='" . $myrow['brand_id'] . "'";
								$brand_sql = mysqli_query($link1, $brndSql);
								$brand_row = mysqli_fetch_array($brand_sql);
								$brnadName = $brand_row['brand_desc'];
								$rowid = 'row' . $suppvendorid['venderid'] . $myrow['mst_itemid'] . $myrow['brand_id'];
						?>
								<tr>
									<td><input name="ACGProductOrder[<?php echo $suppvendorid['id']; ?>][<?php echo $j; ?>]" id="ACGProductOrder_<?php echo $vid; ?><?php echo $j; ?>" type="checkbox" value="<?php echo $myrow['item_id'];  ?>" onclick="FinalQuotation(this.value,'<?php echo $vid . $j; ?>')" disabled="disabled" /> <input type="hidden" id="items_<?php echo $vid; ?>-<?php echo $myrow['item_id']; ?>" value="<?php echo  $myrow['item_id'];  ?>" /></td>
									<td><?php echo $myrow['item_code']; ?></td>
									<td><?php echo $myrow['item_name']; ?> <input type="hidden" name="vender_detail_id[<?php echo $myrow['item_id']; ?>][<?php echo $suppvendorid['id']; ?>]" value="<?php echo $myrow['id'];  ?>"></td>
									<td><?php echo $brnadName; ?> <input type="hidden" name="brand_id[<?php echo $k; ?>]" value="<?php echo $myrow['brand_id'];  ?>"></td>
									<td class="text-right"><?php echo $myrow['quantity']; ?>
										<input type="hidden" name="venderqty[<?php echo $myrow['item_id']; ?>][<?php echo $suppvendorid['id']; ?>]" value="<?php echo $myrow['quantity']; ?>" id="venderqty_<?php echo $vid; ?><?php echo $j; ?>" />
									</td>
									<td><input type="text" name="assign_qty[<?php echo $myrow['item_id']; ?>][<?php echo $suppvendorid['id']; ?>]" onchange="check(<?php echo $vid; ?>,<?php echo $j; ?>)" id="assign_qty_<?php echo $vid; ?><?php echo $j; ?>" value="<?php echo $myrow['quantity']; ?>" disabled="disabled"></td>
									<td class="text-right"><?php echo $myrow['rate']; ?></td>
									<td class="text-right"><?php echo $myrow['discount_amount']; ?></td>
									<td class="text-right"><?php echo $myrow['sub_total']; ?></td>
									<!--<td><?php //echo $myrow['special_discount_amount']; 
											?></td>-->
									<!--<td><?php echo $myrow['basic_amount']; ?></td>
<td><?php if ($myrow['tax_type'] == 'NonExcisable') {
									echo $myrow['taxvalue'];
								} else {
									if ($myrow['tax_type'] == 'Excisable') {
										echo $myrow['taxable_amt'] + $myrow['taxvalue'];
									} else {
										echo "IncludeTax";
									}
								}
	?></td>
<td><?php echo $myrow['total_amount']; ?></td>-->
								</tr>
							<?php $j++;
							} ?>
							<input type="hidden" name="count1" id="count1_<?php echo $vid; ?>" value="<?php echo $j; ?>" />
							<input type="hidden" name="quotation_type[]" value="AMD" />
							<?php
						} else {

							$sql = 'SELECT venderquotations.*, vendorquotationdetails.*, vendorquotationdetails.id as detailsId 
	FROM  venderquotations INNER JOIN vendorquotationdetails ON vendorquotationdetails.parant_id=venderquotations.id 
	WHERE include_gst="1" and venderquotations.indent_prno=' . $RequisitionNo . '  and venderquotations.id=' . $suppvendorid['id'];
							$result = DB_query($sql, $db);
							$j = 1;
							while ($myrow = DB_fetch_array($result)) {

								//echo "select sum(assign_qty) SumAsignQty from comprative_detail
								//          inner join comprative on comprative.id=comprative_detail.parant_id
								//where  comprative_detail.indentprno='".$_REQUEST['RequisitionNo']."' and mst_itemid='".$myrow['mst_itemid']."' and status_active=0";

								$sqla = DB_query("select sum(assign_qty) SumAsignQty from comprative_detail
                inner join comprative on comprative.id=comprative_detail.parant_id
 where  comprative_detail.indentprno='" . $_REQUEST['RequisitionNo'] . "' and mst_itemid='" . $myrow['mst_itemid'] . "' and status_active=0 and po_del_status=0 and sppliersId='" . $myrow['mst_supplierno'] . "'", $db);
								if (DB_num_rows($sqla) > 0) {
									$abc = DB_fetch_array($sqla);
									$pendingqty = $myrow['Quantity'] - $abc['SumAsignQty'];
								} else {
									$pendingqty = $myrow['Quantity'];
								}

								$brndSql = "select id,brand_desc from branditems where id='" . $myrow['brand_id'] . "'";
								$brand_sql = mysqli_query($link1, $brndSql);
								$brand_row = mysqli_fetch_array($brand_sql);
								$brnadName = $brand_row['brand_desc'];
								$rowid = 'row_' . $j . '_' . $suppvendorid['venderid'] . '_' . $myrow['mst_itemid'] . $myrow['brand_id'];
								$sql_minRate = 'SELECT vendorquotationdetails.TotalAmount as minRate, vendorquotationdetails.id as minId
	FROM  venderquotations INNER JOIN vendorquotationdetails ON vendorquotationdetails.parant_id=venderquotations.id 
	WHERE venderquotations.indent_prno=' . $RequisitionNo . '  and venderquotations.id=' . $suppvendorid['id'] . ' and vendorquotationdetails.mst_itemid=' . $myrow['mst_itemid'] . ' ORDER BY vendorquotationdetails.TotalAmount ASC LIMIT 1';
								$result_minRate = DB_query($sql_minRate, $db);
								$data_minRate = DB_fetch_array($result_minRate);
								//echo "<pre>"; print_r($myrow); echo "</pre>";
							?>
								<tr id="<?php echo $rowid; ?>">
									<td align="center"><?php //echo $data_minRate['minId'].' '.$myrow['detailsId']; 
														?>
										<input type="checkbox" name="ACGProductOrder[<?php echo $k; ?>]" id="ACGProductOrder_<?php echo $vid; ?><?php echo $j; ?>" value="1" onclick="FinalQuotation(this.value,'<?php echo $vid . $j; ?>')" disabled="disabled" /><input type="hidden" name="mst_itemid[<?php echo $k; ?>]" id="items_<?php echo $vid; ?>-<?php echo $myrow['mst_itemid']; ?>" value="<?php echo $myrow['mst_itemid'];  ?>" />
										<?php //echo $rowid; 
										?> <input type="hidden" name="sppliersId[<?php echo $k; ?>]" value="<?php echo $suppvendorid['venderid']; ?>" />
									</td>
									<td><?php echo $s->GetFieldValue('item_master', "id='" . $myrow['mst_itemid'] . "'", 'StockId'); ?><input type="hidden" name="currency[<?php echo $k; ?>]" value="<?php echo $myrow['currency'] ?>" /></td>
									<td><?php echo $s->GetFieldValue('item_master', "id='" . $myrow['mst_itemid'] . "'", 'item_name'); ?><input type="hidden" name="quotation_details_id[<?php echo $k; ?>]" value="<?php echo $myrow['id'];  ?>"><input type="hidden" name="quotationid[<?php echo $k; ?>]" value="<?php echo $suppvendorid['id'];  ?>"></td>
									<td><?php echo $brnadName; ?><input type="hidden" name="brand_id[<?php echo $k; ?>]" value="<?php echo $myrow['brand_id'];  ?>"></td>
									<td class="text-right"><?php echo $pendingqty; ?><input type="hidden" name="venderqty[<?php echo $k; ?>]" value="<?php echo $pendingqty; ?>" id="venderqty_<?php echo $vid; ?><?php echo $j; ?>" /><input type="hidden" name="free_qty[<?php echo $k; ?>]" value="<?php echo $myrow['free_qty']; ?>" id="freeqty_<?php echo $vid; ?><?php echo $j; ?>" /></td>
									<td><!-- <input  onkeypress='javascript:return isNumberKey(this,event)' type="text" name="assign_qty[<?php //echo $k;
																																			?>]" size="10px" onkeyup="check(<?php //echo $vid; 
																																															?>,<?php //echo $j; 
																																																				?>,<?php //echo $pendingqty; 
																																																									?>)" id="assign_qty_<?php  //echo $vid; 
																																																																					?><?php //echo $j; 
																																																																										?>" value="" disabled="disabled"  > -->
										<input onkeypress='javascript:return isNumberKey(this,event)' type="text" data-totQty="<?php echo $pendingqty; ?>" class="<?php echo 'c' . $myrow['mst_itemid']; ?>" name="assign_qty[<?php echo $k; ?>]" size="10px" onkeyup="check(<?php echo $vid; ?>,<?php echo $j; ?>,<?php echo $pendingqty; ?>)" id="assign_qty_<?php echo $vid; ?><?php echo $j; ?>" value="" disabled="disabled">
									</td>
									<td class="text-right"><?php echo $myrow['Rate']; ?></td>
									<td class="text-right"><?php echo $myrow['Discount'];
															$dis += $myrow['Discount']; ?></td>
									<td class="text-right rate<?php //if($data_minRate['minId']==$myrow['detailsId']){ echo 'rate'; } 
																?>" data-colorid="<?php echo $rowid; ?>" data-item="<?php echo $myrow['mst_itemid']; ?>" data-brand="<?php echo $myrow['brand_id']; ?>" data-rate="<?php echo $myrow['totalPrice']; ?>"><?php echo $myrow['totalPrice'];
																																																																																$net += $myrow['totalPrice']; ?></td>
									<!--<td><?php //echo $myrow['SpecialDiscounted_Amt']; 
											?></td>-->
									<!--<td><?php echo $myrow['basic_Amt'];
											$basic += $myrow['basic_Amt']; ?></td>
		<td><?php echo $myrow['taxable_amt'];
								$tax += $myrow['taxable_amt']; ?></td>
		<td><?php echo $myrow['TotalAmount'];
								$tot += $myrow['TotalAmount'];; ?></td>-->
								</tr>

							<?php $j++;
								$k++;
							} ?>
							<tr>
								<td colspan="7" style="text-align: right; padding-right: 5px"><strong>Total</strong></td>
								<td class="text-right"><?php echo $dis; ?></td>
								<td class="text-right"><?php echo $net; ?></td>
								<!--<td><?php echo $basic; ?></td>
        <td><?php echo $tax; ?></td>
        <td><?php echo $tot; ?></td>-->
							</tr>
							<input type="hidden" name="count1" id="count1_<?php echo $vid; ?>" value="<?php echo $j; ?>" />
							<input type="hidden" name="quotation_type[]" value="WithoutAmd" />

						<?php  } ?>
					<?php $i++;
					$vid++;
				} ?>
					<input type="hidden" name="viddata" value="<?php echo $vid; ?>" id="viddata" />
					</table>
				<?php } else { ?>
					<p class="text-center"><strong>VENDOR QUOTATION HAS BEEN MADE AGAINST THIS REQUISITION</strong></p>
				<?php
			}
				?>


				<p id="Savebutton" class="text-center" style="display:none;">
					<input type="submit" class="search" name="FinalQuot" value="Order For Purchase" />
					<input type="reset" class="search" name="Submit2" value="Cancel" onclick="javascript:history.go(-1)">
				</p>
		</form>
	</div>
</div>

<script type="text/javascript">
	jQuery('document').ready(function() {
		var coloIds = [];
		var items = [];
		jQuery('.rate').each(function() {
			var t = jQuery(this);
			var colorId = t.attr('data-colorid');
			var itm = t.attr('data-item');
			var brand = '';
			//var brand=t.attr('data-brand');
			var rate = t.attr('data-rate');
			var itmCode = itm + brand;
			var item = [];
			item['colorId'] = colorId;
			item['itm'] = itm;
			item['brand'] = brand;
			item['rate'] = rate;
			item['itmCode'] = itmCode;
			if (coloIds.length > 0) {
				var check = 1;
				for (var i = coloIds.length - 1; i >= 0; i--) {
					if (coloIds[i]['itmCode'] == itmCode) {
						var check = 0;
						if (parseFloat(rate) < parseFloat(coloIds[i]['rate'])) {
							item['color'] = '#c1e3c2';
							coloIds[i] = item;
							item = '';
						}
						if (parseFloat(coloIds[i]['rate']) == parseFloat(rate) && coloIds[i]['colorId'] != colorId) {
							coloIds[i]['color'] = 'yellow';
							item['color'] = 'yellow';
							coloIds.push(item);
							item = '';
						}
					}
				}
				if (check == 1) {
					item['color'] = '#c1e3c2';
					coloIds.push(item);
					item = '';
				}
			} else {
				item['color'] = '#c1e3c2';
				coloIds.push(item);
				item = '';
			}
		});
		for (var i = coloIds.length - 1; i >= 0; i--) {
			jQuery('#' + coloIds[i]['colorId']).css("background-color", coloIds[i]['color']);
		}
	});
</script>