	<?php
	include('cocoon_config.php');
	$query = DB_query("select uploaded_file from purchorders where id='" . $_REQUEST['id'] . "'", $db);
	$sql = DB_fetch_array($query);
	$upload = $sql['uploaded_file'];
	if (isset($_REQUEST['Update'])) {
		if ($_FILES['file_attach']['name'] != '') {
			$name = $_FILES['file_attach']['name'];
			$tmp_name = $_FILES['file_attach']['tmp_name'];
			$name_brk = explode('.', $name);
			//$type=$name_brk[1];
			$new_name = $name . '.' . $type;
			$path = "uploaded_docs/" . $new_name;
			//$file_copy=copy($tmp_name,$path);	
			$file_copy = move_uploaded_file($tmp_name, $path);
			$new_namee = $new_name;
		} else {
			$new_namee = $upload;
		}

		$data['uploaded_file']        = $new_namee;
		$data['doc_name']             = $_REQUEST['docname'];
		$data['po_date'] = FormatDateForSQL($_REQUEST['po_date']);
		$data['contact_person'] = $_REQUEST['contact_person'];
		$data['mobileNo'] = $_REQUEST['mobile_no'];
		$data['po_category'] = $_REQUEST['purch_ord_category'];
		$data['delivery_date'] = FormatDateForSQL($_REQUEST['delivery_date']);
		$data['payment_terms'] = $_REQUEST['PaymentTerm'];
		$data['payment_mod'] = $_REQUEST['payment_mod'];
		$data['valid_till'] = FormatDateForSQL($_REQUEST['valid_till']);
		$data['biiling_Address'] = $_REQUEST['billing_Address'];
		$data['biiling_Address1'] = $_REQUEST['billing_Address1'];
		$data['biiling_Address2'] = $_REQUEST['billing_Address2'];
		$data['biiling_Country'] = $_REQUEST['billing_country'];
		$data['biiling_State'] = $_REQUEST['billing_state'];
		$data['biiling_City'] = $_REQUEST['billing_city'];
		$data['biiling_PostalCode'] = $_REQUEST['biiling_PostalCode'];
		$data['sippiling_Address'] = $_REQUEST['sippiling_Address'];
		$data['sippiling_Address1'] = $_REQUEST['sippiling_Address1'];
		$data['sippiling_Address2'] = $_REQUEST['sippiling_Address2'];
		$data['sippiling_Country'] = $_REQUEST['shipping_country'];
		$data['sippiling_State'] = $_REQUEST['shipping_state'];
		$data['sippiling_City'] = $_REQUEST['shipping_city'];
		$data['sippiling_PostalCode'] = $_REQUEST['sippiling_PostalCode'];
		$data['remarks'] = $_REQUEST['remarks'];
		$data['modified_by'] = $_SESSION['UserID'];
		$data['modified_date'] = date('Y-m-d H:i:s');
		$data['include_gst'] = '1';
		$data['discount_amt'] = $_REQUEST['discount_total'];
		$data['tot_tax_amt'] = $_REQUEST['tot_taxable_amt'];
		$con = "id = '" . $_REQUEST['id'] . "'";

		$s->RecordEdit('purchorders', $data, $con);
		$select_pdid_delete = "delete from purchorderdetails where parantId  ='" . $_REQUEST['id'] . "'";
		$select_pdid_res = DB_query($select_pdid_delete, $db);

		for ($i = 0; $i <= count($_REQUEST['mst_itemid']); $i++) {
			if ($_REQUEST['mst_itemid'][$i] != '') {
				$unitid = $s->getField('item_master', 'id', $_REQUEST['mst_itemid'][$i], 'mst_unitid');

				$dataArr['parantId'] = $_REQUEST['id'];
				$dataArr['mst_itemid'] = $_REQUEST['mst_itemid'][$i];
				$dataArr['itemgrade'] = $_REQUEST['itemgrade'][$i];
				$dataArr['itemsize'] = $_REQUEST['itemsize'][$i];
				$dataArr['Quantity'] = $_REQUEST['Quantity'][$i];
				$dataArr['remarks'] = $_REQUEST['item_remarks'][$i];
				$dataArr['Rate'] = $_REQUEST['Rate'][$i];
				$dataArr['currnecy'] = $_REQUEST['currency'][$i];
				$dataArr['totalPrice'] = $_REQUEST['totalPrice'][$i];
				$dataArr['DiscountType'] = $_REQUEST['DiscountType'][$i];
				$dataArr['unitwisedis'] = $_REQUEST['unitdiscount'][$i];
				$dataArr['Discount'] = $_REQUEST['Discount'][$i];
				$dataArr['discounted_amount'] = $_REQUEST['discounted_amount'][$i];
				$dataArr['NetRate'] = $_REQUEST['NetRate'][$i];
				$dataArr['basic_Amt'] = $_REQUEST['basic_Amt'][$i];
				$dataArr['Excise_type'] = $_REQUEST['Excise_type'][$i];
				$excise_id = explode("#", $_REQUEST['Excise_Duty'][$i]);
				$dataArr['Excise_Duty'] = $excise_id[0];
				$dataArr['exciseValue'] = $_REQUEST['exciseValue'][$i];
				$ecess_id = explode("#", $_REQUEST['Cess_ID'][$i]);
				$dataArr['Cess_ID'] = $ecess_id[0];
				$dataArr['ECessValue'] = $_REQUEST['ECessValue'][$i];
				$shecess_id = explode("#", $_REQUEST['SHECess_ID'][$i]);
				$dataArr['SHECess_ID'] = $shecess_id[0];
				$dataArr['SAHCessValue'] = $_REQUEST['SAHCessValue'][$i];
				$dataArr['taxable_amt'] = $_REQUEST['taxable_amt'][$i];
				$dataArr['freight'] = $_REQUEST['freightItem'][$i];
				//$dataArr['vat_id']=$_REQUEST['inputVat'][$i];
				$dataArr['vat_value'] = $_REQUEST['taxvalue1'][$i];
				$dataArr['pkg_amt'] = $_REQUEST['pkg_Amt'][$i];
				//$dataArr['sur_per']=$_REQUEST['surchargeper'][$i];
				$dataArr['sur_amt'] = $_REQUEST['surchargeamt'][$i];
				$dataArr['mst_unitid'] = $unitid;
				$dataArr['gst_percent'] = $_REQUEST['gstpercent'][$i];
				$dataArr['free_qty'] = $_REQUEST['freeQuantity'][$i];


				//$dataArr['cuntomDuty_Flag']=$_REQUEST['cuntomDuty_Flag'][$i];
				//$dataArr['Custon_Duty']=$_REQUEST['Custon_Duty'][$i];
				//$dataArr['CustomDutyAmt']=$_REQUEST['CustomDutyAmt'][$i];
				$dataArr['TotalAmount'] = $_REQUEST['TotalAmount'][$i];
				//echo "<pre>";
				//print_r($dataArr);

				$s->RecordInsert('purchorderdetails', $dataArr); //INSERT INTO CHIELD TABLE
			}
		}

		DB_query("delete from direct_po_terms_conditions where  frm_id='" . $_REQUEST['frmid'] . "' and parant_id='" . $_REQUEST['id'] . "'", $db);
		for ($k = 0; $k < count($_REQUEST['Terms_Condition']); $k++) {
			if ($_REQUEST['Terms_Condition'][$k] != '') {
				$dataterm['parant_id']    = $_REQUEST['id'];
				$dataterm['termsid']      = $_REQUEST['terms'][$k];
				$dataterm['condid']       = $_REQUEST['Terms_Condition'][$k];
				$dataterm['frm_id']       = $_REQUEST['frmid'];
				$dataterm['company_id']   = $_SESSION['ACGCompanyId'];
				//$dataterm['type']         ="quotation";
				$s->RecordInsert('direct_po_terms_conditions', $dataterm);
			}
		}
		$s->pageLocation("index.php?route=POModule/view_purchase_order_gst" . $rurl);
	}

	?>
	<script src="POModule/po_calculation_gst_purchase.js" type="text/javascript" language="javascript"></script>
	<script type="text/javascript" language="javascript">
		function GetSatateCountry(str) {
			if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari
				xmlhttp = new XMLHttpRequest();
			} else { // code for IE6, IE5
				xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			}
			xmlhttp.onreadystatechange = function() {
				if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
					var data = xmlhttp.responseText.split("__");
					//alert(xmlhttp.responseText);
					document.getElementById("billing_state").value = data[0];
					document.getElementById("billing_country").value = data[1];
					document.getElementById("billing_state1").value = data[2];
					document.getElementById("billing_country1").value = data[3];
				}
			}
			xmlhttp.open("GET", "SateCountryName.php?CityId=" + str, true);
			xmlhttp.send();
		}

		function GetSatateCountry1(str) {
			if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari
				xmlhttp = new XMLHttpRequest();
			} else { // code for IE6, IE5
				xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			}
			xmlhttp.onreadystatechange = function() {
				if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
					var data = xmlhttp.responseText.split("__");
					document.getElementById("shipping_state").value = data[0];
					document.getElementById("shipping_country").value = data[1];
					document.getElementById("shipping_state1").value = data[2];
					document.getElementById("shipping_country1").value = data[3];
				}
			}
			xmlhttp.open("GET", "SateCountryName.php?CityId=" + str, true);
			xmlhttp.send();
		}

		//$.noConflict();
		/*$(document).ready(function(){	
				//var cnt=document.getElementById("count").value;
				$('input[name=profile_popup]').click(function(){
				var tt=this.id;
				var tt1=tt.split("_");
				var tt2=tt1[1];
				var site=document.getElementById("site").value;
				//var LeaveType=document.getElementById("LeaveType_"+tt2).value;
				$("#PickedItems").dialog({
						title:'Item List',
						modal: true,
						resizable: false,
						width:1000,
						height:400,
						closeText: 'fechar',
						draggable: true,
						show: 'fade',
						hide: 'fade',
						dialogClass: 'main-dialog-class',
						buttons: {
							Exit: function()
							{
								$(this).dialog("close");
							}
						}
						
					});
				GetitemListForDirectPO(site);
				});
			});*/

		$(document).ready(function() {

			$('input[name=profile_popup]').click(function() {
				var vend = document.getElementById("vendor_id").value;
				var vf = document.getElementById("vend_itm_flag").value;
				if (vend == '000' && vf == 1) {
					alert("Please select vendor");
					return false;
				}

				var tt = this.id;
				var tt1 = tt.split("_");
				var tt2 = tt1[1];
				var site = document.getElementById("site").value;
				//var LeaveType=document.getElementById("LeaveType_"+tt2).value;
				$("#PickedItems").dialog({
					title: 'Item List',
					modal: true,
					resizable: false,
					width: 1000,
					height: 400,
					closeText: 'fechar',
					draggable: true,
					show: 'fade',
					hide: 'fade',
					dialogClass: 'main-dialog-class',
					buttons: {
						Exit: function() {
							$(this).dialog("close");
						}
					}
				});
				GetitemListForDirectPO(site, vend, vf);
				//$('.ui-widget-content .ui-helper-clearfix').append('<div style="float:left;">Displaying latest 10 records </div>');
			});
		});

		/*function GetitemListForDirectPO(str)
		{
			if (window.XMLHttpRequest)
			{// code for IE7+, Firefox, Chrome, Opera, Safari
			xmlhttp=new XMLHttpRequest();
			}
			else
			{// code for IE6, IE5
			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
			}
			xmlhttp.onreadystatechange=function()
			{
			if (xmlhttp.readyState==4 && xmlhttp.status==200)
			{
				document.getElementById("PickedItems").innerHTML=xmlhttp.responseText;
			}
			}
			xmlhttp.open("GET","direct_po_item12.php?site="+str,true);
			xmlhttp.send();
		}*/

		function GetitemListForDirectPO(str, vend, vend_flg) {
			//$('#PickedItems').html('<center><span style="font-size:20px;"><strong>Loading...</strong></span></center>');
			//alert(vend_flg)
			//alert(vend)
			if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari
				xmlhttp = new XMLHttpRequest();
			} else { // code for IE6, IE5
				xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			}
			xmlhttp.onreadystatechange = function() {
				if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
					document.getElementById("PickedItems").innerHTML = xmlhttp.responseText;
				}
			}
			//alert("direct_po_items12.php?site="+str+"&vend="+vend+"&vend_flg="+vend_flg);
			xmlhttp.open("GET", "direct_po_items12.php?site=" + str + "&vend=" + vend + "&vend_flg=" + vend_flg, true);
			xmlhttp.send();
		}

		function GetMobileNo(id) {
			if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari
				xmlhttp = new XMLHttpRequest();
			} else { // code for IE6, IE5
				xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			}
			xmlhttp.onreadystatechange = function() {
				if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
					document.getElementById("mobile_no").value = xmlhttp.responseText;
				}
			}
			xmlhttp.open("GET", "GetContactNo.php?contactId=" + id, true);
			xmlhttp.send();
		}
	</script>

	<div id="PickedItems" style="display:none">
	</div>

	<div id="div_id" style="display:none"></div>

	<div id="div_idEcess" style="display:none"></div>

	<link rel="stylesheet" href="css/new_mxerp.css">
	<div class="body_contain">
		<div class="tab_div">
			<h1>Purchase Order</h1>
			<form action="" method="post" enctype="multipart/form-data">
				<!--GENERAL DETAILS-->
				<?php
				$show_query = "select * from purchorders where id = '" . $_REQUEST['id'] . "'";
				$show_query_res = DB_query($show_query, $db) or die(DB_error());
				$show_query_result = DB_fetch_array($show_query_res);

				$query_edit = "select *,discount_amt*100/total_amount AS dis_per from purchorders where id='" . $_REQUEST['id'] . "'";
				$query_edit_res = DB_query($query_edit, $db) or die(DB_error());
				$query_edit_result = DB_fetch_array($query_edit_res);

				$flag = 0;
				$view_flag = 0;
				//echo '<pre>';
				//print_r($query_edit_result);
				//exit;
				if ($query_edit_result['indentPRno'] == "") {
					$flag = 1;
				}
				if ($_REQUEST['modify'] == 'viewonly') {
					$view_flag = 1;
				}
				?>
				<h3>General Details</h3>
				<table width="100%" border="0" cellspacing="0" cellpadding="3">
					<tr class="row1">
						<td width="13%" align="right"><strong>Branch:</strong></td>
						<td width="20%" align="left"><?php
														$ss1 = "Select loccode,locationname from locations where CompanyId='" . $_SESSION['ACGCompanyId'] . "' and loccode ='" . $query_edit_result['site'] . "' ";
														$site_sql = DB_query($ss1, $db);
														$site_row = DB_fetch_array($site_sql) ?>
							<input type="text" readonly value="<?php echo $site_row['locationname']; ?>">
							<input id="site" type="hidden" readonly value="<?php echo $query_edit_result['site']; ?>">
						</td>
						<td width="13%" align="right"><strong>PO No.:</strong></td>
						<td width="20%" align="left"><input type="text" value="<?php echo $query_edit_result['purchase_ordNo']; ?>" disabled="disabled" /></td>
						<td width="13%" align="right"><strong>Date:</strong></td>
						<td align="left"><input type="text" name="po_date" id="po_date" value="<?php echo date("d/m/Y", strtotime($query_edit_result['po_date'])); ?>" class="datepicker" /></td>
					</tr>
					<tr class="row1">
						<td align="right"><strong>Vendor:</strong></td>
						<td align="left"><?php
											$SQLV = "Select id,vendor_name from suppliers where CompanyId='" . $_SESSION['ACGCompanyId'] . "' and id=" . $query_edit_result['vendorId'] . " ";
											$VDetails = DB_fetch_array(DB_query($SQLV, $db)); ?>
							<input type="text" readonly value="<?php echo $VDetails['vendor_name']; ?>">
						</td>
						<td align="right"><strong>Quote No.:</strong></td>
						<td align="left">
							<?php
							$qno = $s->GetFieldValue('venderquotations', "id='" . $query_edit_result['quotationId'] . "'", 'quotation_no');
							?>
							<input type="text" name="quote_No" id="quote_No" value="<?php echo $qno;; ?>" readonly="" disabled="disabled" />
						</td>
						<td align="right"><strong>Quote Date:</strong></td>
						<td align="left"><input type="text" name="quote_date" id="quote_date" class="datepicker" value="<?php echo ConvertSQlDate($query_edit_result['qutation_date']); ?>" /></td>
					</tr>
					<tr class="row1">
						<td align="right"><strong>P O Type: <font style="color:red;">*</font></strong></td>
						<td align="left">
							<?php if ($query_edit_result['purchase_ord_Type'] == "IO") {
								$po_type = "Import Order";
							}
							if ($query_edit_result['purchase_ord_Type'] == "DO") {
								$po_type = "Domestic Order";
							} ?>

							<input type="text" readonly value="<?php echo $po_type; ?>">
						</td>
						<td align="right"><strong>Category: <font style="color:red;">*</font></strong></td>
						<td align="left"><select name="purch_ord_category" id="purch_ord_category">
								<option value="0">Select</option>
								<option value='AT' <?php if ($query_edit_result['po_category'] == "AT") {
														echo "selected";
													} ?>>Asset</option>
								<option value='MT' <?php if ($query_edit_result['po_category'] == "MT") {
														echo "selected";
													} ?>>Material</option>
								<option value='SV' <?php if ($query_edit_result['po_category'] == "SV") {
														echo "selected";
													} ?>>Service</option>
							</select></td>
						<td align="right"><strong>Delivery Date:</strong></td>
						<td align="left"><input type="text" name="delivery_date" id="delivery_date" value="<?php echo date("d/m/Y", strtotime($query_edit_result['delivery_date'])); ?>" class="datepicker" onchange="checkvalidate()" /></td>
					</tr>
					<tr class="row1">
						<td align="right"><strong>Payment Terms:</strong></td>
						<td align="left"><select name="PaymentTerm" id="PaymentTerm">
								<option value="000">Select Payment Terms</option>
								<?php
								$sql = "select * from paymentterms";
								$result = DB_query($sql, $db);
								while ($myrow = DB_fetch_array($result)) {
									$p = '';
									if ($query_edit_result['payment_terms'] == $myrow['termsindicator'])
										$p = "selected";
								?>
									<option value="<?php echo $myrow['termsindicator']; ?>" <?php echo $p; ?>><?php echo $myrow['terms']; ?></option>
								<?php } ?>
							</select></td>
						<td align="right"><strong>Payment Mode:</strong></td>
						<td align="left"><select name="payment_mod" id="payment_mod">
								<option value="000">Select Payment Mode</option>
								<?php
								$sql = 'SELECT paymentmethods.paymentid, paymentmethods.paymentname FROM paymentmethods';
								$result = DB_query($sql, $db);
								while ($myrow = DB_fetch_array($result)) {
									$p = '';
									if ($query_edit_result['payment_mod'] == $myrow['paymentid'])
										$p = "selected";
								?>
									<option value="<?php echo $myrow['paymentid']; ?>" <?php echo $p; ?>><?php echo $myrow['paymentname']; ?></option>
								<?php 	} ?>
							</select></td>
						<td align="right"><strong>Valid Upto:</strong></td>
						<td align="left"><input type="text" class="datepicker" name="valid_till" id="valid_till" value="<?php echo date("d/m/Y", strtotime($query_edit_result['valid_till'])); ?>" onchange="checktilldate()" /></td>
					</tr>
					<?php
					$vend_itm_flag = DB_fetch_assoc(DB_query("select * from vendorItemMap_flag where company_id ='" . $_SESSION['ACGCompanyId'] . "'", $db));
					?>
					<input type="hidden" id="vend_itm_flag" value="<?php echo $vend_itm_flag['map_flag'] ?>">
					<tr class="row1">
						<td align="right"><strong>Contact Person:</strong></td>
						<td align="left" id="CPerson">
							<select name="contact_person" id="contact_person" onchange="GetMobileNo(this.value)">
								<option value="">Select</option>
								<?php
								$sqlConPerSon = DB_query("select * from contact_information_master where master_code='" . $query_edit_result['vendorId'] . "' and master_prefix='S'", $db);
								while ($ConPerDetails = DB_fetch_array($sqlConPerSon)) {
									if ($flag == '1' || $view_flag == 1) {
										$p = "";
										if ($query_edit_result['contact_person'] == $ConPerDetails['id']) {
											$p = "selected";
										}
									}
								?>
									<option value="<?php echo $ConPerDetails['id']; ?>" <?php echo $p; ?>><?php echo $ConPerDetails['person']; ?></option>
								<?php
								}
								?>
							</select>
						</td>
						<td align="right"><strong>Mobile No.:</strong></td>
						<td align="left"><input type="text" name="mobile_no" readonly id="mobile_no" value="<?php echo $query_edit_result['mobileNo']; ?>"> </td>
						<td align="left">&nbsp;</td>
						<td align="left">&nbsp;</td>
					</tr>
				</table>

				<h3>Address Details (Check If both Address are Same <?php if ($view_flag != 1) { ?><input type="checkbox" name="shipping_data" id="shipping_data" onclick="ship_data()"><?php } ?>)</h3>
				<table width="100%" border="1" cellspacing="0" cellpadding="3" style="border:#808080 1px solid;">
					<tr>
						<th colspan="3" style="text-align:center;">Billing Address</th>
						<th width="14%" style="text-align:center;">City</th>
						<th width="14%" style="text-align:center;">State</th>
						<th width="14%" style="text-align:center;">Country</th>
						<th width="10%" style="text-align:center;">Postal Code</th>
					</tr>
					<tr bgcolor="#fff">
						<td><input type="text" name="billing_Address" id="billing_Address" value="<?php echo $query_edit_result['biiling_Address']; ?>" /></td>
						<td><input type="text" name="billing_Address1" id="billing_Address1" value="<?php echo $query_edit_result['biiling_Address1']; ?>" /></td>
						<td><input type="text" name="billing_Address2" id="billing_Address2" value="<?php echo $query_edit_result['biiling_Address2']; ?>" /></td>
						<td><select name="billing_city" id="billing_city" onchange="GetSatateCountry(this.value)">
								<option value="">Select</option>
								<?php
								$city_sql = DB_query("select * from city_master", $db);
								while ($city_row = DB_fetch_array($city_sql)) {
									$p = "";
									if ($query_edit_result['biiling_City'] == $city_row['id'])
										$p = "selected";
								?>
									<option value="<?php echo $city_row['id']; ?>" <?php echo $p; ?>><?php echo $city_row['city']; ?></option>
								<?php } ?>
							</select></td>
						<td><input type="hidden" name="billing_state" id="billing_state" value="<?php echo $query_edit_result['biiling_State']; ?>" />
							<?php $STname = $s->GetFieldValue('state_master', "id='" . $query_edit_result['biiling_State'] . "'", 'state'); ?>
							<input type="text" name="billing_state1" id="billing_state1" value="<?php echo $STname; ?>" />
						</td>
						<td><input type="hidden" name="billing_country" id="billing_country" value="<?php echo $query_edit_result['biiling_Country']; ?>" />
							<?php $Conname = $s->GetFieldValue('country_master', "id='" . $query_edit_result['biiling_Country'] . "'", 'country'); ?>
							<input type="text" name="billing_country1" id="billing_country1" value="<?php echo $Conname; ?>" />
						</td>
						<td><input type="text" name="biiling_PostalCode" id="zipcode" value="<?php echo $query_edit_result['biiling_PostalCode']; ?>" /></td>
					</tr>
					<tr>
						<th colspan="3" style="text-align:center;">Delivery Address </th>
						<th width="14%" style="text-align:center;">City</th>
						<th width="14%" style="text-align:center;">State</th>
						<th width="14%" style="text-align:center;">Country</th>
						<th width="10%" style="text-align:center;">Postal Code</th>
					</tr>
					<tr bgcolor="#fff">
						<td id="CODE"><input type="text" id="Shipping_address" name="sippiling_Address" value="<?php echo $query_edit_result['sippiling_Address']; ?>" /></td>
						<td width="14%" id="CODE"><input type="text" id="Shipping_address1" name="sippiling_Address1" value="<?php echo $query_edit_result['sippiling_Address1']; ?>" /></td>
						<td width="14%" id="CODE"><input type="text" id="Shipping_address2" name="sippiling_Address2" value="<?php echo $query_edit_result['sippiling_Address2']; ?>" /></td>
						<td><select name="shipping_city" id="shipping_city" onchange="GetSatateCountry1(this.value)">
								<option value="">Select</option>
								<?php
								$city_sql = DB_query("select * from city_master", $db);
								while ($city_row = DB_fetch_array($city_sql)) {
									$p = "";
									if ($query_edit_result['sippiling_City'] == $city_row['id'])
										$p = "selected";
								?>
									<option value="<?php echo $city_row['id']; ?>" <?php echo $p; ?>><?php echo $city_row['city']; ?></option>
								<?php
								}
								?>
							</select></td>
						<td><input type="hidden" name="shipping_state" id="shipping_state" value="<?php echo $query_edit_result['sippiling_State']; ?>" />
							<?php $STname = $s->GetFieldValue('state_master', "id='" . $query_edit_result['sippiling_State'] . "'", 'state'); ?>
							<input type="text" name="shipping_state1" id="shipping_state1" value="<?php echo $STname; ?>" />
						</td>
						<td><input type="hidden" name="shipping_country" id="shipping_country" value="<?php echo $query_edit_result['sippiling_Country']; ?>" />
							<?php $Conname = $s->GetFieldValue('country_master', "id='" . $query_edit_result['sippiling_Country'] . "'", 'country'); ?>
							<input type="text" name="shipping_country1" id="shipping_country1" value="<?php echo $Conname; ?>" />
						</td>
						<td><input type="text" name="sippiling_PostalCode" id="Shipping_zipcode" value="<?php echo $query_edit_result['sippiling_PostalCode']; ?>" /></td>
					</tr>
				</table>
				<br>
				<!--OTHER DETAILS-->

				<h3>Items Details:</h3>
				<?php if ($query_edit_result['purchase_ord_Type'] == 'IO') {  ?>

					<table width="100%" cellpadding="3" cellspacing="0" border="1" style="border:#808080 1px solid; border-collapse:collapse;">
						<tr>
							<th width="3%">S. No.</th>
							<th width="1"></th>
							<th width="7%">Item Code</th>
							<th>Item Name</th>
							<th width="3%">UOM</th>
							<th colspan="2"><!--Specification--></th>
							<th width="3%">Qty.</th>
							<th width="3%">Free Qty.</th>
							<th width="4%">Rate</th>
							<th width="7%">Total Price</th>
							<th colspan="2">Discount</th>
							<th width="7%">Discount Amount</th>
							<th width="7%">Basic Amount</th>
							<th width='7%'>Currency</th>
							<th width='7%'>Remarks</th>
						</tr>
						<tbody id="dataTable">
							<?php
							$i = 0;
							$item_detail_query = "select * from purchorderdetails where parantId='" . $_REQUEST['id'] . "'";
							$item_detail_res = DB_query($item_detail_query, $db) or die(DB_error());
							while ($item_detail_result = DB_fetch_array($item_detail_res)) {
								$mst_item_id = $item_detail_result['mst_itemid'];
								$mst_item_query = "select * from item_master where id='" . $mst_item_id . "'";
								$mst_item_res = DB_query($mst_item_query, $db) or die(DB_error());
								$mst_item_result = DB_fetch_array($mst_item_res);
								$unit = $s->GetFieldValue('unitsofmeasure', "unitid='" . $mst_item_result['mst_unitid'] . "'", 'unitname');
								//echo $mst_item_result['StockID'];
								//echo $mst_item_result['item_name'];
								//echo $mst_item_result['mst_unitid'];
								$i++;
							?>
								<tr bgcolor="#fff">
									<td><input name="checkbox" type='checkbox' id="delitem[]" /></td>
									<td><input type='hidden' name='mst_itemid[]' id='itemid_<?php echo $i; ?>' value="<?php echo $mst_item_id; ?>" /></td>
									<td><input type='text' id='itemcode_<?php echo $i; ?>' value="<?php echo $mst_item_result['StockID']; ?>" readonly='true' /></td>
									<td><input type='text' id='itemname_<?php echo $i; ?>' value="<?php echo $mst_item_result['item_name']; ?>" readonly='true' /></td>
									<td><input type="text" name="" readonly="" id="itemunit_<?php echo $i; ?>" value="<?php echo $unit; ?>" /><input type="hidden" name="mstunitid[]" value="<?php echo $mst_item_result['mst_unitid']; ?>"></td>
									<td width="1"><!--<select  name="itemgrade[]"  id=""><option value="" >select</option>
			<?php
								$grade_sql = DB_query("SELECT * FROM product_grade ", $db);
								while ($grade_res = DB_fetch_assoc($grade_sql)) {

			?>
	                <option value="<?php echo  $grade_res['id'] ?>"  <?php echo ($grade_res['id'] == $item_detail_result['itemgrade']) ? "selected" : ""; ?>  ><?php echo  $grade_res['grade'] ?></option>
	                <?php } ?>
	                </select>--></td>
									<td width="1"><!--<select  name="itemsize[]" id=""><option value="" >select</option>
			<?php
								$size_sql = DB_query("SELECT * FROM size_master WHERE CompanyId='" . $_SESSION['ACGCompanyId'] . "'", $db);
								while ($size_res = DB_fetch_assoc($size_sql)) { ?>
	                <option value="<?php echo  $size_res['id'] ?>" <?php echo ($size_res['id'] == $item_detail_result['itemsize']) ? "selected" : ""; ?>  ><?php echo  $size_res['size'] ?></option>
	                <?php } ?>
	                </select>--></td>
									<td><input onkeyup='calculateFull_import(this);' type='text' name='Quantity[]' id='Quantity_<?php echo $i; ?>' value="<?php echo $item_detail_result['Quantity']; ?>" onkeypress="javascript:return isNumberKey(this,event)" maxlength="11" onblur="javascript:validate_floating(this.value,this.id)" /></td>
									<td><input onkeyup='calculateFull_import(this);' type='text' name='freeQuantity[]' id='freeQuantity_<?php echo $i; ?>' value="<?php echo $item_detail_result['free_qty']; ?>" onkeypress="javascript:return isNumberKey(this,event)" maxlength="11" onblur="javascript:validate_floating(this.value,this.id)" /></td>


									<td><input onkeypress="javascript:return isNumberKey(this,event)" type='text' name='Rate[]' id='Rate_<?php echo $i; ?>' value="<?php echo $item_detail_result['Rate']; ?>" onkeyup='calculateFull_import(this);' /></td>
									<td><input type='text' name='totalPrice[]' onkeypress="javascript:return isNumberKey(this,event)" id='totalValue_<?php echo $i; ?>' value="<?php echo $item_detail_result['totalPrice']; ?>" /></td>
									<td width="5%"><select onchange='calculateFull_import(this);' name='DiscountType[]' id='PerAmo_<?php echo $i; ?>'>
											<option value='Amount' <?php if ($item_detail_result['DiscountType'] == "Amount") {
																		echo "selected";
																	} ?>>Amount</option>
											<option value='PercentAmt' <?php if ($item_detail_result['DiscountType'] == "PercentAmt") {
																			echo "selected";
																		} ?>>%</option>
										</select></td>
									<td width="5%"><input type='text' onkeypress="javascript:return isNumberKey(this,event)" onkeyup='calculateFull_import(this);' name='Discount[]' id='Discount_<?php echo $i; ?>' value="<?php echo $item_detail_result['Discount']; ?>" />
									</td>
									<td><input type='text' name='discounted_amount[]' id='discounted_amount_<?php echo $i; ?>' value="<?php echo $item_detail_result['discounted_amount']; ?>" onkeypress="javascript:return isNumberKey(this,event)" />
									</td>
									<td><input type='text' name='basic_Amt[]' id='basic_<?php echo $i; ?>' value="<?php echo $item_detail_result['basic_Amt']; ?>" readonly='true' class="total_item_amount" />
									</td>
									<td><select name="currency[]">
											<option value="0">Select</option>
											<?php
											$sql_currency = DB_query("select * from currency_master where  CompanyId='" . $_SESSION['ACGCompanyId'] . "'", $db);
											while ($row_currency = DB_fetch_array($sql_currency)) {
												$p1 = '';
												if ($item_detail_result['currnecy'] == $row_currency['id'])
													$p1 = "selected='selected'";
											?>
												<option value="<?php echo $row_currency['id']; ?>" <?php echo $p1; ?>><?php echo $row_currency['abbreviation']; ?></option>
											<?php } ?>
										</select></td>
									<td><input type='text' name='item_remarks[]' id='item_remarks_<?php echo $i; ?>' value="<?php echo $item_detail_result['remarks']; ?>" class="total_item_amount" />
									</td>

								</tr>
							<?php  } ?>
						</tbody>
					</table>
				<?php } else {  ?>
					<div style="width:100%; overflow:auto; margin:0 auto;">
						<table width="100%" cellpadding="3" cellspacing="0" id='tableDataProduction' border="1" style="border:#808080 1px solid; border-collapse:collapse;">
							<?php
							$data3 .= "<tr>";
							$data3 .= '<th width="2%">S. No.</th>';
							$data3 .= "<th width='1'></th>";
							$data3 .= "<th width='6%'>Item Code</th>";
							$data3 .= '<th>Item Name</th>';
							$data3 .= '<th width="6%">Brand</th>';
							$data3 .= '<th width="3%">UOM</th>';
							$data3 .= '<th width="3%">Qty.</th>';
							$data3 .= '<th width="3%">Free Qty.</th>';
							$data3 .= '<th width="3%">Quoted Rate </th>';
							$data3 .= '<th width="4%">Total Price</th>';
							$data3 .= '<th colspan="2" >Discount</th>';
							$data3 .= '<th width="3%">Discount Amount</th>';
							$data3 .= '<th width="3%">Basic Amount</th>';
							$data3 .= '<th width="3%">Pkg Charges</th>';
							/* $data3.='<th width="4%">Excise flag</th>';
                                        $data3.='<th width="4%">Excise</th>';
                                        $data3.='<th width="4%">Excise Value</th>';
                                        $data3.='<th width="3%">E-Cess</th>';
                                        $data3.='<th width="3%">E-Cess Value</th>';
                                        $data3.='<th width="3%">SAH-E Cess</th>';
                                        $data3.='<th width="3%">SAH-E Cess Value</th>'; */
							$data3 .= '<th width="3%">Taxable Amt.</th>';
							$data3 .= '<th width="3%">Freight and P&S</th>';
							$data3 .= '<th>Input GST</th>';
							$data3 .= '<th width="3%">Value</th>';
							//$data3.='<th width="3%">Surcharge %</th>';
							$data3 .= '<th width="3%">Surcharge Amt</th>';
							$data3 .= '<th width="3%">Total Amt.</th>';
							$data3 .= "</tr>";

							$data3 .= "<tbody id='dataTable'>";
							echo $data3;
							$i = 0;
							$data1 = '';
							$item_detail_query = "select * from purchorderdetails where parantId='" . $_REQUEST['id'] . "'";
							$item_detail_res = DB_query($item_detail_query, $db) or die(DB_error());
							while ($item_detail_result = DB_fetch_array($item_detail_res)) {
								$brndSql = "select id,brand_desc from branditems where id='" . $item_detail_result['brand_id'] . "'";
								$brand_sql = mysqli_query($link1, $brndSql);
								$brand_row = mysqli_fetch_array($brand_sql);
								$brnadName = $brand_row['brand_desc'];

								$mst_item_id = $item_detail_result['mst_itemid'];
								$mst_item_query = "select * from item_master where id='" . $mst_item_id . "'";
								$mst_item_res = DB_query($mst_item_query, $db) or die(DB_error());
								$mst_item_result = DB_fetch_array($mst_item_res);
								$unit = $s->GetFieldValue('unitsofmeasure', "unitid='" . $item_detail_result['mst_unitid'] . "'", 'unitname');
								//echo $mst_item_result['StockID'];
								//echo $mst_item_result['item_name'];
								//echo $mst_item_result['mst_unitid'];
								$i++;
								$data1 .= "<tr bgcolor='#fff'>";
								$data1 .= "<td id='first_row'><input type='checkbox'  /></td>";
								$data1 .= "<td><input type='hidden'  name='mst_itemid[]' value='" . $mst_item_id . "' id='itemid_" . $i . "'  /></td>";
								$data1 .= "<td><input type='text' value='" . $mst_item_result['StockID'] . "'   id='itemcode_" . $i . "' readonly='' /></td>";
								$data1 .= "<td><input type='text' value='" . $mst_item_result['item_name'] . "'  id='itemname_" . $i . "' readonly='' /></td>";
								$data1 .= "<td><input type='text' value='" . $brnadName . "'  id='brandId_" . $i . "' readonly='' /></td>";
								$data1 .= "<td><input type='text' value='" . $unit . "'  id='itemunit_" . $i . "' readonly='' /></td>";
								$data1 .= "<td ><input onkeyup='calculateFull_itemwise(this);' autocomplete='off' type='text' name='Quantity[]' id='Quantity_" . $i . "' value='" . $item_detail_result['Quantity'] . "' onkeypress='return isNumberKey(event)'  class='get_tot' /></td>";
								$data1 .= "<td ><input onkeyup='calculateFull_itemwise(this);' autocomplete='off' type='text' name='freeQuantity[]' id='freeQuantity_" . $i . "' value='" . $item_detail_result['free_qty'] . "' onkeypress='return isNumberKey(event)'  class='get_tot_free' /></td>";
								$data1 .= "<td><input value='" . $item_detail_result['Rate'] . "' autocomplete='off' onkeyup='calculateFull_itemwise(this);'  onkeypress='return isNumberKey(event)' type='text' name='Rate[]' id='Rate_" . $i . "' class='' /></td>";
								$data1 .= "<td><input value='" . $item_detail_result['totalPrice'] . "' type='text' name='totalPrice[]' id='totalValue_" . $i . "' readonly='true' class='tot_price'/></td>";
								$data1 .= "<td width='3%'><select name='DiscountType[]' id='PerAmo_" . $i . "' class='item_PerAmo' onchange='calculateFull_itemwise(this);' >";
								$s1 = "";
								$s2 = "";
								if ($item_detail_result['DiscountType'] == 'Amount') {
									$s1 = 'selected';
									$s2 = "";
								} elseif ($item_detail_result['DiscountType'] == 'PercentAmt') {
									$s2 = 'selected';
									$s1 = '';
								}
								$data1 .= "<option " . $s1 . " value='Amount'>Amt</option>";
								$data1 .= "<option " . $s2 . " value='PercentAmt'>%</option>";
								$data1 .= "</select></td>";
								$data1 .= "<td width='3%'><input type='text' value='" . $item_detail_result['Discount'] . "' onkeyup='calculateFull_itemwise(this);' autocomplete='off' name='Discount[]' onkeypress='return isNumberKey(event)' id='Discount_" . $i . "' class='discount_item'  /></td>";
								$data1 .= "<td><input type='text' name='discounted_amount[]' value='" . $item_detail_result['discounted_amount'] . "'  id='discounted_amount_" . $i . "'   class='discounted_item_price' readonly/></td>";
								$data1 .= "<td><input type='text' id='TotalSpecial_" . $i . "' name='basic_Amt[]' class='basic' readonly   value='" . $item_detail_result['basic_Amt'] . "' class='total_item_amount'/></td>";
								$data1 .= "<td><input type='text' id='pkgamt_" . $i . "' name='pkg_Amt[]'   value='" . $item_detail_result['pkg_amt'] . "'  class='pkgamt'/></td>";
								/*  $data1.="<td><select name='Excise_type[]' id='hid_billing_type_".$i."'    
					           onchange='calculateFull_itemwise(this)'>
					           <option value=''>Select</option>";
					            $s2="";$s3="";
                    	if($item_detail_result['Excise_type']=='Excisable')
                    	{
                    		$s2='selected';
                    		$s4='';
                    		$s3='';
                    	}
                    	elseif($item_detail_result['Excise_type']=='NonExcisable')
                    	{
                    		$s3='selected';
                    		$s2='';
                    		$s4='';
                    	}
                    	elseif($item_detail_result['Excise_type']=='IncludeTax')
                    	{
                    		$s4='selected';
                    		$s2='';
                    		$s3='';
                    	}
					$data1.="<option ".$s3." value='NonExcisable'>NonExcisable</option>";
					$data1.="<option ".$s2." value='Excisable'>Excisable</option>";
					$data1.="<option ".$s4." value='IncludeTax'>IncludeTax</option>						
							  </select></td>";	
			 $data1.="<td><select name='Excise_Duty[]' id='exciseDuty_".$i."' 
                               onchange='calculateFull_itemwise(this)'>
                             <option value=''>Select</option>";           
      $excise_sql=DB_query("select * from excise_tax where ledgertype like'%excisetax%' and form_type='Purchase' group by caption",$db); 
      while($excise_row=DB_fetch_array($excise_sql))
      {
      $g='';
      if($item_detail_result['Excise_Duty']==$excise_row['id'])
      {$g='selected';} 
        $data1.="<option value='".$excise_row['id'].'#'.$excise_row['def_rate']."' ".$g.">".$excise_row['caption']."</option>";
      }  
         $data1.="</select></td>";
	    $data1.="<td><input name='exciseValue[]' class='excise' id='exciseValue_".$i."' value='".$item_detail_result['exciseValue']."' type='text' /></td>";
	    $cessLedgerSql1=DB_query("Select * from excise_tax where ledgertype like '%cess%' group by caption   ",$db);   
	    $cessLedgerSql2=DB_query("Select * from excise_tax where ledgertype like'%scess%' group by caption ",$db);  
	  $data1.="<td><select name='Cess_ID[]' id='cess_ID1_".$i."' onchange='calEcessonchange(this.id,this.value)'>";
	  $cessLedger1=DB_fetch_array($cessLedgerSql1);
	  if(DB_num_rows($cessLedgerSql1)>0)
	  $data1.="<option value=".$cessLedger1['id'].'#'.$cessLedger1['def_rate'].">".$cessLedger1['caption']."</option>"; 
	  else
	  $data1.="<option value=''></option>"; 	
	  $data1.="</select></td>";        
	  $data1.="<td><input name='ECessValue[]' class='ecess' readonly value='".$item_detail_result['ECessValue']."' id='ECessValue_".$i."' type='text' readonly /></td>";
	  $data1.="<td><select name='SHECess_ID[]' id='cess_ID2_".$i."' onchange='calSHEcessonchange(this.id,this.value)'>";
	  $cessLedger2=DB_fetch_array($cessLedgerSql2);
	  if(DB_num_rows($cessLedgerSql2)>0)
	  $data1.="<option value=".$cessLedger2['id'].'#'.$cessLedger2['def_rate'].">".$cessLedger2['caption']."</option>";
	  else
       $data1.="<option value=''></option>"; 
	   $data1.="</select></td>";
	  $data1.="<td><input name='SAHCessValue[]' class='shecess' value='".$item_detail_result['SAHCessValue']."' id='SAHCessValue_".$i."' type='text' readonly /></td>"; */
								$data1 .= "<td><input type='text' name='taxable_amt[]' value='" . $item_detail_result['taxable_amt'] . "' id='taxable_amt_" . $i . "' onfocus='calculateTaxable(this.id)'
	   readonly/></td>";
								$data1 .= "<td><input type='text' name='freightItem[]' value='" . $item_detail_result['freight'] . "' class='freight' id='freightItem_" . $i . "' 
	   onkeyup='calculateFull_itemwise(this)' /></td>";
								//$vatdesc=$s->getField('sales_tax_master','salestax_id',$item_detail_result['vat_id'],'taxrate');
								//$data1.="<td width='3%'><input type='text' name='' value='".$vatdesc."' id='vatdes_".$i."' readonly ></td>";
								$data1 .= "<td width='3%'><input type='text' value='" . $item_detail_result['gst_percent'] . "' readonly name='gstpercent[]' id='gstpercent_" . $i . "'></td>";
								$data1 .= "<td><input type='text' name='taxvalue1[]' class='vat' id='taxvalue_" . $i . "' value='" . $item_detail_result['vat_value'] . "' readonly='true'/></td>";
								// $data1.="<td><input type='text' name='surchargeper[]'  id='surchargeper_".$i."' value='".$item_detail_result['sur_per']."' readonly='true'/></td>";
								$data1 .= "<td><input type='text' name='surchargeamt[]' class='surcharge' id='surchargeamt_" . $i . "' value='" . $item_detail_result['sur_amt'] . "'/></td>";
								$data1 .= "<td><input type='text' id='TotalSpecial_" . $i . "' name='TotalAmount[]' readonly class='TotalSpecial' value='" . $item_detail_result['TotalAmount'] . "' /></td>";
								$data1 .= "</tr>";
							}
							$data1 .= "</tbody>";
							echo $data1;
							?>
						</table>
					</div>

				<?php } ?>
				<input type="hidden" name="Input" id="hiditemcount" value="<?php echo $i; ?>" />
				<input type="hidden" name="Input" id="edit_cnt" value="<?php echo $i; ?>" />
				<input type="hidden" name="Input" id="rowcount1" value="<?php echo $i; ?>" />
				<br>
				<table border="0" width="100%" cellpadding="3" cellspacing="0">
					<tr>
						<td width="60%" valign="top">
							<?php $data6 .= '<table width="100%" border="0" cellspacing="0" cellpadding="3" align="left">
		<tr class="row1" ><td width="13%" style="text-align:right;"><strong>Remarks:</strong></td><td><textarea name="remarks">' . $show_query_result['remarks'] . '</textarea></td></tr>
			<tr class="row1">
				<td style="text-align:center;" colspan="2"><strong>Terms and Conditions</strong></td>
			</tr>';
							//$data2= "SELECT * FROM terms_condition where parant_id=0 and frm_id='".$_REQUEST['frmid']."' and CompanyId='".$_SESSION['ACGCompanyId']."'";
							$i = 0;
							$SQLTerms = DB_query("SELECT * FROM terms_condition where parant_id=0 and frm_id='" . $_REQUEST['frmid'] . "' and CompanyId='" . $_SESSION['ACGCompanyId'] . "'", $db);
							while ($TermsAndCond = DB_fetch_array($SQLTerms)) {
								$data6 .= '<tr class="row1">
				<td>' . $TermsAndCond['terms_conditions'] . '
				<input type="hidden" name="terms[]" id="terms" value="' . $TermsAndCond['id'] . '" />
				</td>
				<td><select name="Terms_Condition[]" id="Terms_Condition">
						<option value="">Select</option>';
								$SQLCond = DB_query("SELECT * FROM terms_condition where parant_id='" . $TermsAndCond['id'] . "' and frm_id='" . $_REQUEST['frmid'] . "' and CompanyId='" . $_SESSION['ACGCompanyId'] . "'", $db);
								while ($GetCond = DB_fetch_array($SQLCond)) {
									$ter_con = DB_fetch_assoc(DB_query("select * from po_terms_cond where company_id='" . $_SESSION['ACGCompanyId'] . "' and frm_id='" . $_REQUEST['frmid'] . "' and parant_id='" . $_REQUEST['id'] . "' and termsid='" . $TermsAndCond['id'] . "' ", $db));
									if ($ter_con['condid'] == $GetCond['id']) {
										$sel = 'selected';
									} else {
										$sel = '';
									}
									$data6 .= '<option value="' . $GetCond['id'] . '" ' . $sel . ' >' . $GetCond['terms_conditions'] . '</option>';
								}
								$data6 .= '</select></td> </tr>';
								$i++;
							}
							$data6 .= '</table>';
							echo $data6; ?></td>
						<td valign="top">
							<div id="basicamtdetails">
								<?php if ($query_edit_result['purchase_ord_Type'] == 'IO') { ?>
									<table width="100%" border="0" cellspacing="0" cellpadding="3">
										<tr class="row1">
											<td width="40%" align="right"><strong>Basic Amount:</strong></td>
											<td><input name='basic_amt' id='total_item_amount' value='<?php echo $query_edit_result['total_amount'] ?>' readonly></td>
										</tr>
										<tr class="row1">
											<td align="right"><strong>Discount:</strong></td>
											<td><input type='text' name='' placeholder='Percent' value='<?php echo $query_edit_result['dis_per'] ?>' id='discount_percent' onkeyup='cal_po_charges_import(this)' onkeypress='javascript:return isNumberKey(this,event)' maxlength='11' onblur='javascript:validate_floating(this.value,this.id)' style="width:30%; float:left; margin-right:3px;" />
												<input type='text' name='discount_amt' id='discount_amt' placeholder='Amount' onkeyup='cal_po_charges_import(this)' value='<?php echo $query_edit_result['discount_amt'] ?>' onkeypress='javascript:return isNumberKey(this,event)' maxlength='11' onblur='javascript:validate_floating(this.value,this.id)' style="width:68%; float:left;" />
											</td>
										</tr>
										<tr class="row1">
											<td align="right"><strong>Discounted Amount:</strong></td>
											<td><input name='discounted_amt' id='discnted_amt' readonly="" value='<?php echo $query_edit_result['discounted_amt'] ?>'> <input name='total_po_amt' value='<?php echo $query_edit_result['total_po_amt'] ?>' id='total_po_amt' type='hidden' readonly /></td>
										</tr>
										<tr class="row1">
											<td align="right"><strong>Round Off:</strong></td>
											<td><input type="text" name="pluMin" value="<?php echo $query_edit_result['pluMin']  ?>" readonly id="pluMin" style="width:30%; float:left; margin-right:3px;" /><input type="text" value="<?php echo $query_edit_result['roundVal']  ?>" name="roundVal" readonly id="roundVal" style="width:67%; float:left;" /></td>
										</tr>

										<tr class="row1">
											<td align="right"><strong>Grand Total:</strong></td>
											<td><input type="text" name="GrandTotal" readonly="" value="<?php echo $query_edit_result['GrandTotal']; ?>" id="GrandTotal" /></td>
										</tr>
									</table> <?php } else {  ?>
									<?php


												$data2 .= "<table width='100%' border='0' cellspacing='0' cellpadding='3'>
                <tr class='row1'>
                  <td width='40%' align='right'><strong>TOTAL AMOUNT:</strong></td>
                  <td ><input type='text' name='basic_amt' readonly id='total_item_amount' value='" . $query_edit_result['total_amount'] . "' /></td>
               </tr>
               <tr class='row1'>
                  <td width='40%' align='right'><strong>Discount AMOUNT:</strong></td>
                  <td ><input type='text' name='discount_total' readonly id='discount_total' value='" . $query_edit_result['discount_amt'] . "' /></td>
               </tr>       
         <tr class='row1'>
        <td align='right'><strong>Pkg Charges:</strong></td>
        <td> <input name='pkg_charges' readonly id='pkg_charges' type='text' value='" . $query_edit_result['pkg_charges'] . "' /></td>
         </tr>    
           <tr class='row1'>
        <td align='right'><strong>Taxable Amount:</strong></td>
        <td> <input name='tot_taxable_amt' readonly id='taxable_amt' type='text' value='" . $query_edit_result['tot_tax_amt'] . "' /></td>
         </tr>      
      
          <tr class='row1'>
        <td align='right'><strong>Freight And P&amp;S:</strong></td>
        <td><input type='text' name='Freight' id='TotalCharge' value='" . $query_edit_result['Freight'] . "'  readonly='true'/></td>
        </tr>
        <tr class='row1'>
        <td align='right'><strong>GST Value:</strong></td>
        <td><div id='taxval'><input type='text' value='" . $query_edit_result['vat_amt'] . "' name='vat_amt' id='taxvalue'   readonly='true'/></div></td>
        </tr>
           <tr class='row1'>
        <td align='right'><strong>Surcharge:</strong></td>
        <td> <input name='surcharge_amt' readonly id='surcharge_amt' type='text' value='" . $query_edit_result['surcharge_amt'] . "' /></td>
         </tr>        
        <tr class='row1'>
        <td align='right'><strong>Insurance:</strong></td>
        <td><input name='insr_amt' value='" . $query_edit_result['insurancecharges_amt'] . "' id='insurance' type='text' onkeyup='cal_grandtotal()' readonly='true' /></td>
      </tr>
       <tr class='row1'>
       <td align='right'><strong>Miscellaneous:</strong></td>
       <td><input type='text' value='" . $query_edit_result['other_amt'] . "'  name='other_amt' id='miscellaneous' onkeyup='cal_grandtotal()'  readonly='true' /></td>
       </tr>	             
     <tr class='row1'>
	<td align='right'><strong>Grand Total:</strong></td>
    <td><input type='text' name='GrandTotal' readonly id='GrandTotal'  value='" . $query_edit_result['GrandTotal'] . "' />
		</td></tr></table>";

												echo $data2;
									?>

								<?php } ?>
						</td>
					</tr>
				</table>
				<br>
				<table width="100%" border="0" cellspacing="0" cellpadding="3">
					<tr class="row1">
						<td width="13%" align='right'><strong>Doc Name:</strong></td>

						<td><input type="text" value="<?php echo $query_edit_result['doc_name']; ?>" name="docname" style="width:40%; float:left;"> <input type="file" name="file_attach"
								value="Attach File" id="filename" onchange="Checkfiles()" style="width:40%; float:left;" />
							<?php if ($query_edit_result['uploaded_file'] != '') { ?>
								<a href="uploaded_docs/<?php echo $query_edit_result['uploaded_file']; ?>">Download
									<?php echo $query_edit_result['uploaded_file']; ?></a> <?php } else {
																							echo "File Not Attach";
																						} ?>
						</td>
					</tr>
					<?php if (!isset($_REQUEST['modify'])) { ?>

						<tr class="row1">
							<td colspan="6" style="text-align:center;"><input name="Update" type="submit" value="Update" class="search" onclick="return validate();" /></td>
						</tr>
					<?php } ?>
				</table>
			</form>

		</div>
	</div>

	<script language="JavaScript">
		function cal_po_charges1(obj, value) {
			var basic = document.getElementById('total_item_amount').value;
			if (basic != '' && value != '') {
				if (parseFloat(value) > parseFloat(basic)) {
					alert('Discount amount should be less then basic amount');
					document.getElementById('discount_percent').value = '0.00';
					document.getElementById('discount_amt').value = '0.00';

				}
			} else {
				document.getElementById('discount_percent').value = '0.00';
				document.getElementById('discount_amt').value = '0.00';
			}
			cal_po_charges(obj);
		}

		function cal_po_charges2(obj, value) {
			if (value != '') {

				if (parseFloat(value) > 100) {
					alert('Discount percent cannot be greater then 100%');
					document.getElementById('discount_percent').value = '0.00';
					document.getElementById('discount_amt').value = '0.00';
				}
			} else {
				document.getElementById('discount_percent').value = '0.00';
				document.getElementById('discount_amt').value = '0.00';
			}
			cal_po_charges(obj);
		}

		function getdata1() {
			$('#ItemListDiv').html('<center><span style="font-size:20px;"><strong>Loading...</strong></span></center>');
			var xmlhttp;
			if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari
				xmlhttp = new XMLHttpRequest();
			} else { // code for IE6, IE5
				xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			}
			xmlhttp.onreadystatechange = function() {
				if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
					document.getElementById("ItemListDiv").innerHTML = xmlhttp.responseText;
				}
			}
			var site = document.getElementById("site").value;
			var code = document.getElementById("srch_code").value;
			var name = document.getElementById("srch_name").value;
			var category = document.getElementById("srch_cateory").value;
			var subcat = document.getElementById("srch_subcateory").value;

			xmlhttp.open("GET", "ajax_item_list_srch.php?code=" + code + "&site=" + site + "&name=" + name + "&cat=" + category + "&subcat=" + subcat, true);
			xmlhttp.send();
			//xmlhttp.open("GET","getSort.php?s="+str+"&cat="+cat,true);
		}

		function getSubCategory() {
			//$('#PickedItems').html('<center><span style="font-size:20px;"><strong>Loading...</strong></span></center>'); 
			var xmlhttp;
			if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari
				xmlhttp = new XMLHttpRequest();
			} else { // code for IE6, IE5
				xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			}
			xmlhttp.onreadystatechange = function() {
				if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
					document.getElementById("srch_subcateory").innerHTML = xmlhttp.responseText;
					// getdata1();
				}
			}
			var category = document.getElementById("srch_cateory").value;
			if (category == "")
				return;
			xmlhttp.open("GET", "ajax_subcategory.php?cat=" + category, true);
			xmlhttp.send();
			//xmlhttp.open("GET","getSort.php?s="+str+"&cat="+cat,true);
		}


		function checkvalidate() {

			var curr_date2 = '';
			var curr_month2 = '';
			var d = new Date();
			//alert(d.format("m/dd/yy"));
			var curr_date = d.getDate();
			var curr_month1 = d.getMonth();
			var curr_year = d.getFullYear();
			var curr_month = curr_month1 + 1;
			var t = curr_month;
			var d = curr_date;
			if (t != 10 || t != 11 || t != 12) {
				curr_month2 = "0" + curr_month;
			} else {
				curr_month2 = curr_month;
			}
			if (d == 1 || d == 2 || d == 3 || d == 4 || d == 5 || d == 6 || d == 7 || d == 8 || d == 9) {
				curr_date2 = "0" + curr_date;
			} else {
				curr_date2 = curr_date;
			}


			var datedat = (curr_date2 + "/" + curr_month2 +
				"/" + curr_year);
			var del = document.getElementById("delivery_date").value;
			if (del < datedat) {
				alert("Delivery  Date Not less then current  Date");
				//document.getElementById("delivery_date").value='';
				document.getElementById("delivery_date").focus;
				return false;
			}


		}

		function checktilldate() {
			var curr_date2 = '';
			var curr_month2 = '';
			var d = new Date();
			//alert(d.format("m/dd/yy"));
			var curr_date = d.getDate();
			var curr_month1 = d.getMonth();
			var curr_year = d.getFullYear();
			var curr_month = curr_month1 + 1;
			var t = curr_month;
			var d = curr_date;
			if (t != 10 || t != 11 || t != 12) {
				curr_month2 = "0" + curr_month;
			} else {
				curr_month2 = curr_month;
			}
			if (d == 1 || d == 2 || d == 3 || d == 4 || d == 5 || d == 6 || d == 7 || d == 8 || d == 9) {
				curr_date2 = "0" + curr_date;
			} else {
				curr_date2 = curr_date;
			}
			var datedat = (curr_date2 + "/" + curr_month2 +
				"/" + curr_year);
			var del1 = document.getElementById("valid_till").value;
			if (del1 < datedat) {
				alert("Valid Till Date Not less then current  Date");
				//document.getElementById("valid_till").value='';
				document.getElementById("valid_till").focus;
				return false;
			}


		}









		function ship_data() {

			if (document.getElementById("shipping_data").checked == true) {
				document.getElementById('Shipping_address').value = document.getElementById('billing_Address').value;
				document.getElementById('shipping_city').value = document.getElementById('billing_city').value;
				document.getElementById('shipping_state').value = document.getElementById('billing_state').value;
				document.getElementById('shipping_country').value = document.getElementById('billing_country').value;
				document.getElementById('shipping_state1').value = document.getElementById('billing_state1').value;
				document.getElementById('shipping_country1').value = document.getElementById('billing_country1').value;
				document.getElementById('Shipping_zipcode').value = document.getElementById('zipcode').value;

			} else {
				document.getElementById('Shipping_address').value = '';
				document.getElementById('shipping_state').value = '';
				document.getElementById('shipping_city').value = '';
				document.getElementById('shipping_country').value = '';
				document.getElementById('shipping_state1').value = '';
				document.getElementById('shipping_country1').value = '';
				document.getElementById('Shipping_zipcode').value = '';
			}
		}





		function addRow(tableID) {

			if (document)
				var table = document.getElementById(tableID);
			var rowCount = table.rows.length;
			var rowCount = table.rows.length;
			if (document.getElementById("hiditemcount").value == '')
				r = rowCount + 1;
			else {
				var t = document.getElementById("edit_cnt").value;
				var t1 = document.getElementById("hiditemcount").value;
				r = parseInt(t1);
				r1 = parseInt(t1) + 1;
			}
			var row1 = document.getElementById("rowcount1").value;
			var rr = parseInt(row1) + 1;
			document.getElementById("rowcount1").value = rr;
			var row = table.insertRow(rowCount);
			document.getElementById("hiditemcount").value = rr;
			document.getElementById("edit_cnt").value = rr;
			var colCount = table.rows[0].cells.length;
			for (var i = 0; i < colCount; i++) {
				var newcell = row.insertCell(i);
				//newcell.style.background='#e7e7e7';
				newcell.className = 'tabledata';
				newcell.innerHTML = table.rows[0].cells[i].innerHTML;
				//alert(newcell.childNodes[0].type);
				switch (newcell.childNodes[0].type) {
					case "text":
						newcell.childNodes[0].value = "";
						var nod_id = newcell.childNodes[0].id.split("_");
						if (!isNaN(nod_id[1]))
							newcell.childNodes[0].id = nod_id[0] + '_' + rr;
						else
							newcell.childNodes[0].id = nod_id[0] + '_' + nod_id[1] + '_' + rr;
						break;
					case "hidden":
						newcell.childNodes[0].value = "";
						var nod_id = newcell.childNodes[0].id.split("_");
						if (!isNaN(nod_id[1]))
							newcell.childNodes[0].id = nod_id[0] + '_' + rr;
						else
							newcell.childNodes[0].id = nod_id[0] + '_' + nod_id[1] + '_' + rr;
						break;
					case "button":
						var nod_id = newcell.childNodes[0].id.split("_");
						if (!isNaN(nod_id[1]))
							newcell.childNodes[0].id = nod_id[0] + '_' + rr;
						else
							newcell.childNodes[0].id = nod_id[0] + '_' + nod_id[1] + '_' + rr;
						break;
					case "checkbox":
						newcell.childNodes[0].checked = false;
						var nod_id = newcell.childNodes[0].id.split("_");
						if (!isNaN(nod_id[1]))
							newcell.childNodes[0].id = nod_id[0] + '_' + rr;
						else
							newcell.childNodes[0].id = nod_id[0] + '_' + nod_id[1] + '_' + rr;
						break;
					case "select-one":
						newcell.childNodes[0].selectedIndex = 0;
						var nod_id = newcell.childNodes[0].id.split("_");
						if (!isNaN(nod_id[1]))
							newcell.childNodes[0].id = nod_id[0] + '_' + rr;
						else
							newcell.childNodes[0].id = nod_id[0] + '_' + nod_id[1] + '_' + rr;
						break;
				}
				//document.getElementById("stock_perunit_"+rowCount).value=1;
			}
			//document.getElementById(countid).innerHTML=rowCount;

		}


		function deleteRow(tableID) {
			try {
				var table = document.getElementById(tableID);
				var rowCount = table.rows.length;
				//alert(rowCount);
				for (var i = 0; i < rowCount; i++) {
					var row = table.rows[i];
					var chkbox = row.cells[0].childNodes[0];
					if (null != chkbox && true == chkbox.checked) {
						if (rowCount <= 1) {
							alert("Cannot delete all the rows.");
							break;
						}
						table.deleteRow(i);
						rowCount--;
						i--;
					}

				}
				document.getElementById("hiditemcount").value = parseInt(rowCount);
				document.getElementById("edit_cnt").value = parseInt(rowCount);
				document.getElementById("ro").value = parseInt(rowCount);
			} catch (e) {
				//	alert(e);
			}

		}


		function getItemsList(id, code, shade, current, s_unit, ctr, unit, vatid, surrate) {



			var dup = 'empty';
			var itemcount = parseInt(document.getElementById('rowcount1').value) + 1;
			var counter = 1;

			//alert(counter);
			//IF WE CHECK THE CHECK BOX FOR SELECT ANY ITEM***********************START HERE******************************************

			if (document.getElementById("row_id_" + ctr).checked == true) {

				for (var i = counter; i <= itemcount; i++) {
					if (!document.getElementById('itemid_' + i)) {
						addRow('dataTable');
					}

					if (document.getElementById('itemid_' + i)) {
						if (document.getElementById('itemid_' + i).value == '') { //var data= addRow('dataTable');
							document.getElementById('itemid_' + i).value = id;
							document.getElementById('itemcode_' + i).value = code;
							document.getElementById('itemname_' + i).value = shade;
							document.getElementById('itemunit_' + i).value = s_unit;
							document.getElementById('vatdes_' + i).value = unit;
							document.getElementById('inputVat_' + i).value = vatid;
							document.getElementById('surchargeper_' + i).value = surrate;
							//document.getElementById('total_stock_'+i).value = current;			

							break;
						} else {
							continue;
						}
					}

				}
			} else {


				for (var i = counter; i < itemcount; i++) {
					if (document.getElementById('itemid_' + i)) {
						if (document.getElementById('itemid_' + i).value == document.getElementById("row_id_" + ctr).value) {
							document.getElementById('itemid_' + i).value = '';
							document.getElementById('itemcode_' + i).value = '';
							document.getElementById('itemname_' + i).value = '';
							document.getElementById('itemunit_' + i).value = '';
							document.getElementById('total_stock_' + i).value = '';
							document.getElementById('vatdes_' + i).value = '';
							document.getElementById('inputVat_' + i).value = '';
							document.getElementById('surchargeper_' + i).value = '';
						}
					}
				}

			}
			//IF WE UNCHECK THE CHECK BOX FOR DESELECT ANY ITEM***********************END HERE******************************************
		}

		function isNumberKey(evt) {
			var charCode = (evt.which) ? evt.which : event.keyCode;
			if (charCode != 46 && charCode > 31 &&
				(charCode < 48 || charCode > 57))
				return false;

			return true;
		}

		function validate_floating(val, id) {
			var data = id.split("_");
			var val1 = parseFloat(val);

			if (val == "" || val1 == 0) {
				document.getElementById(id).value = "";
				document.getElementById(id).focus();
			} else {
				document.getElementById(id).value = val1.toFixed(2);
			}
		}

		function cal_grandtotal() {

			var basic_amt = document.getElementById("total_item_amount").value;
			var excise_amt = document.getElementById("excise_duty_val").value;
			var ecess_amt = document.getElementById("ecess_val").value;
			var shecess_amt = document.getElementById("shecess_val").value;
			var TotalCharge = document.getElementById("TotalCharge").value;
			var taxvalue = document.getElementById("taxvalue").value;
			var pkg = document.getElementById("pkg_charges").value;

			var insurance = document.getElementById("insurance").value;
			var miscellaneous = document.getElementById("miscellaneous").value;
			if (basic_amt == '') basic_amt = 0;
			if (insurance == '') insurance = 0;
			if (miscellaneous == '') miscellaneous = 0;
			if (excise_amt == '') excise_amt = 0;
			if (ecess_amt == '') ecess_amt = 0;
			if (shecess_amt == '') shecess_amt = 0;
			if (TotalCharge == '') TotalCharge = 0;
			if (taxvalue == '') taxvalue = 0;
			if (pkg == '') pkg = 0;

			var total = parseFloat(basic_amt) + parseFloat(insurance) + parseFloat(miscellaneous) + parseFloat(excise_amt) + parseFloat(ecess_amt) + parseFloat(shecess_amt) + parseFloat(TotalCharge) + parseFloat(taxvalue) + parseFloat(pkg);

			document.getElementById("GrandTotal").value = total.toFixed(2);


		}


		function Checkfiles() {
			var fup = document.getElementById('filename');
			var fileName = fup.value;
			var ext = fileName.substring(fileName.lastIndexOf('.') + 1);
			if (ext == "pdf" || ext == "txt" || ext == "docx") {
				return true;
			} else {
				alert("Upload pdf/text/word  files only");
				fup.value = '';
				fup.focus();
				return false;
			}
		}
	</script>