<%Response.Expires = 0%>
<!-- #include file="security.inc.asp" -->
<!-- #include file="adovbs.inc" -->
<!-- #include file="fieldvalidation.asp" -->
<!-- #include file="transjava.inc.asp" -->
<!-- #include file="transaction.inc.asp" -->
<!-- #include file="options.inc.asp" -->
<!-- #include file="foxexportso.inc.asp" -->
<!-- #include file="summarypages.inc.asp" -->
<!-- #include file="global_var.inc.asp" -->
<!--#include file="clsUpload.asp"-->

<html>
<head>
<link rel="stylesheet" type="text/css" href="style1.css">
<script type="text/javascript" src="cal2.js"></script>
<script type="text/javascript" src="cal_conf2.js"></script>
<script type="text/javascript" src="DynamicText/ajax.js"></script>
<script type="text/javascript" src="DynamicText/ajax-dynamic-list.js"></script>
<style>
#overlay {
  position: fixed; /* Sit on top of the page content */
  display: none; /* Hidden by default */
  width: 100%; /* Full width (cover the whole page) */
  height: 100%; /* Full height (cover the whole page) */
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(0,0,0,0.5); /* Black background with opacity */
  z-index: 2; /* Specify a stack order in case you're using a different order for other elements */
  cursor: pointer; /* Add a pointer on hover */
}

	.hl1 {
		background:#578Fff;
	}
	.hd {
		display:none;
	}
	.nw {
		font-style:italic;
		color:#DDDDDD;
		width:34px;
		text-align:center;
	}
	.nw2 {
		font-style:italic;
		color:#00FF99;
		width:34px;
		text-align:center;
	}
	.tw2 {
		width:34px;
		background: #5587B4;
		color:#00FF99;
	}
	.tw {
		width:34px;
		background: #5587B4;
		color:#FFFFFF;
	}
	.tnw {
		width:34px;
		background: #5587B4;
		color:#DDDDDD;
	}
	.op{
		font: 11px Arial;
        color:#333399;
		text-decoration:none;
		cursor:pointer
	}

	#ajax_listOfOptions{
		position:absolute;	/* Never change this one */
		width:200px;	/* Width of box */
		height:250px;	/* Height of box */
		overflow:auto;	/* Scrolling features */
		border:1px solid #317082;	/* Dark green border */
		background-color:#FFF;	/* White background color */
		text-align:left;
		font-size:11px;
		font-family:Arial, Helvetica, sans-serif;
		z-index:100;
	}
	#ajax_listOfOptions div{	/* General rule for both .optionDiv and .optionDivSelected */
		margin:1px;
		padding:1px;
		cursor:pointer;
		font-size:11px;
	}
	#ajax_listOfOptions .optionDiv{	/* Div for each item in list */

	}
	#ajax_listOfOptions .optionDivSelected{ /* Selected item in the list */
		background-color:#578FFF;
		color:#FFF;
	}
	#ajax_listOfOptions_iframe{
		background-color:#F00;
		position:absolute;
		z-index:5;
	}
</style>
<%

' Create and open ADO connection object.
Set oConn = Server.CreateObject("ADODB.Connection")
Call dataconn


Set oConn4 = Server.CreateObject("ADODB.Connection")
Call dataconninvmysql(sqlinvdb)


Category = Trim(Request("Category"))
TransType = Trim(Request("TransType"))
Ref1 = Trim(Request("Ref1"))
If TransType="IN" AND ishabacus="Y" Then
	totlines=11
	maxlen=110
ELSE
	totlines=22
	maxlen=60
End If
notes1=Trim(Request("notes1"))
If TransType="PO" AND notes1="" Then
	notes1="Please acknowledge receipt of this PO."
End If
notes2=Trim(Request("notes2"))
notes3=Trim(Request("notes3"))
notes4=Trim(Request("notes4"))
notes5=Trim(Request("notes5"))
notes6=Trim(Request("notes6"))
notes7=Trim(Request("notes7"))
notes8=Trim(Request("notes8"))
notes9=Trim(Request("notes9"))
notes10=Trim(Request("notes10"))
notes11=Trim(Request("notes11"))
notes12=Trim(Request("notes12"))
notes13=Trim(Request("notes13"))
notes14=Trim(Request("notes14"))
notes15=Trim(Request("notes15"))
notes16=Trim(Request("notes16"))
notes17=Trim(Request("notes17"))
notes18=Trim(Request("notes18"))
notes19=Trim(Request("notes19"))
notes20=Trim(Request("notes20"))
notes21=Trim(Request("notes21"))
notes22=Trim(Request("notes22"))
notes23=Trim(Request("notes23"))
notes24=Trim(Request("notes24"))
notes25=Trim(Request("notes25"))
'If notes1<>"" Then
	notes=notes1
'End If
'If notes2<>"" Then
	notes=notes & "<br>" & notes2
'End If
'If notes3<>"" Then
	notes=notes & "<br>" & notes3
'End If
'If notes4<>"" Then
	notes=notes & "<br>" & notes4
'End If
'If notes5<>"" Then
	notes=notes & "<br>" & notes5
'End If
'If notes6<>"" Then
	notes=notes & "<br>" & notes6
'End If
'If notes7<>"" Then
	notes=notes & "<br>" & notes7
'End If
'If notes8<>"" Then
	notes=notes & "<br>" & notes8
'End If

notes=notes & "<br>" & notes9
notes=notes & "<br>" & notes10
notes=notes & "<br>" & notes11
notes=notes & "<br>" & notes12
notes=notes & "<br>" & notes13
notes=notes & "<br>" & notes14
notes=notes & "<br>" & notes15
notes=notes & "<br>" & notes16
notes=notes & "<br>" & notes17
notes=notes & "<br>" & notes18
notes=notes & "<br>" & notes19
notes=notes & "<br>" & notes20
notes=notes & "<br>" & notes21
notes=notes & "<br>" & notes22
notes=notes & "<br>" & notes23
notes=notes & "<br>" & notes24
notes=notes & "<br>" & notes25
doaction=TRIM(Request("doaction"))

If doaction<>"" Then
	oConn.BeginTrans
	Set rsItmg = Server.CreateObject("ADODB.Recordset")
	sql = "SELECT TransType, OrderID, notes, recordedby, timestamp " & _
		  "FROM Orders " & _
		  "WHERE (TransType = '" & TRIM(stripforsql(TransType)) & "') AND (OrderID = '" & TRIM(stripforsql(Ref1)) & "') ORDER BY id "
	'response.write sql
	rsItmg.Open sql, oConn, adOpenDynamic, adLockOptimistic
	If Not rsItmg.EOF Then
		rsItmg("notes")=notes
		rsItmg("recordedby")=curuser
		rsItmg("timestamp")=NOW()		
		message="Notes record updated."
		rsItmg.Update
	End If
	rsItmg.Close
	Set rsItmg=Nothing
	
	If po_save_notes_tobody="Y" AND TransType="PO" Then
		' Delete OrdersLine 1st
		sql = "DELETE FROM OrdersLine WHERE (OrderID =  '" & TRIM(stripforsql(Ref1)) & "') AND (TransType = 'PO') AND (dmarking2 =  '|X|')  "
		Oconn.execute sql
		
		'Get last notes entry
		n=0
		For n=0 to totlines
			notesvalue=""
			If INSTR(notes,"<br>")>0 Then
				arrnotes=SPLIT(notes,"<br>")
				If n<=UBound(arrnotes) Then
					notesvalue=arrnotes(n)
					If notesvalue<>"" Then
						lastnode=n
					End If
				End If
			End If
		Next
		
		lastrow=0
		Set rsItmg = Server.CreateObject("ADODB.Recordset")
		sql = "SELECT rownumber " & _
			  "FROM Ordersline " & _
			  "WHERE (TransType = '" & TRIM(stripforsql(TransType)) & "') AND (OrderID = '" & TRIM(stripforsql(Ref1)) & "') ORDER BY rownumber DESC LIMIT 1 "
		'response.write sql
		rsItmg.Open sql, oConn, adOpenStatic, adLockReadOnly	
		If Not rsItmg.EOF Then
			lastrow=returnnumeric(TRIM(rsItmg("rownumber")))	
		End If
		rsItmg.Close
		Set rsItmg=Nothing		
	
		Set rsItmg = Server.CreateObject("ADODB.Recordset")
		sql = "SELECT TransType, OrderID, EntryType, desc1, dmarking2, rownumber " & _
			  "FROM Ordersline " & _
			  "WHERE (TransType = '" & TRIM(stripforsql(TransType)) & "') AND (OrderID = '" & TRIM(stripforsql(Ref1)) & "') AND (1=2) ORDER BY rownumber "
		'response.write sql
		rsItmg.Open sql, oConn, adOpenDynamic, adLockOptimistic
		If rsItmg.EOF Then
			n=0
			For n=0 to lastnode
				lastrow=lastrow+1
				rsItmg.AddNew
					rsItmg("TransType") = "PO"
					rsItmg("OrderID") = Ref1
					rsItmg("RowNumber") = lastrow
					rsItmg("EntryType") = "C"	
					rsItmg("desc1")=Trim(Request("notes" & n+1 ))
					rsItmg("dmarking2")="|X|"		
				rsItmg.Update
				rsItmg.MoveNext
			Next
		End If
		rsItmg.Close
		Set rsItmg=Nothing	
		
		' Update All Row Nos to be in Sequence
		rowcount = 0
		Set rsItm = Server.CreateObject("ADODB.Recordset")
		sql = "SELECT OrderID, RowNumber, TransType " & _
			  "FROM OrdersLine " & _
			  "WHERE (OrderID = '" & TRIM(stripforsql(Ref1)) & "') AND (TransType = 'PO') " & _
			  "ORDER BY RowNumber "
		rsItm.Open sql, oConn, adOpenDynamic, adLockOptimistic
		Do While Not rsItm.EOF
			rowcount = rowcount + 1 ' Update Row No Counter
			rsItm("RowNumber") = rowcount
			rsItm.Update
			rsItm.MoveNext
		Loop
		rsItm.Close
		Set rsItm = nothing		
	End If
	
	If err.Number <> 0 OR errormarker <> 0 Then
		oConn.RollBackTrans
	ELSE
		oConn.CommitTrans
	End If

End If

	requested=""
	Set rsItmg = Server.CreateObject("ADODB.Recordset")
	sql = "SELECT TransType, OrderID, notes " & _
		  "FROM Orders " & _
		  "WHERE (TransType = '" & TRIM(stripforsql(TransType)) & "') AND (OrderID = '" & TRIM(stripforsql(Ref1)) & "') ORDER BY id "
	'response.write sql
	rsItmg.Open sql, oConn, adOpenStatic, adLockReadOnly
	If Not rsItmg.EOF Then
		notes=TRIM(rsItmg("notes"))
	End If
	rsItmg.Close
	Set rsItmg=Nothing	






qstring = REquest.ServerVariables("QUERY_STRING")
%>
<script language="javascript">
function getconfirm(faction){
	answer = confirm('Are you sure you want to ' + faction + '?');
	if(answer){
		return true;
	} else {
		return false;
	}
}

function copypaste() {
                var longString = document.getElementById("mainbox").value;
                var ks = longString.split("\n");
				var lines=<%=totlines+1%>;

				//alert(ks.length);
				for (i = 1; i <= lines; i++) {
					//alert(ks[i]);
					if(i<=(ks.length)) {
						eval('theForm.notes'+i+'.value=ks[i-1].substring(0, 60);');
					} else {
						eval('theForm.notes'+i+'.value="";');
					}
				}
}

function onoverlay1() {
  document.getElementById("overlay").style.display = "block";
}

function offoverlay1() {
  document.getElementById("overlay").style.display = "none";
} 
</script>
</head>
<body style="margin-top:10px; ">
<%
replacementref=Ref1
If TransType="PQ" Then
	If potopqreffield="Y" Then
		Set rsItm = Server.CreateObject("ADODB.Recordset")
			sql = "SELECT transtype, orderid, void, reference " & _
				  "FROM Orders " & _
				"WHERE transtype='PQ' AND orderid='" & stripforsql(Ref1) & "' " & _
				  "ORDER BY orderid "
		rsItm.Open sql, oConn, adOpenStatic, adLockReadOnly
		If Not rsItm.EOF Then
			replacementref=(rsItm("reference"))
		End If
		rsItm.Close
		Set rsItm = Nothing	
	End If	
End If
%>

<h1>Notes for <%=Server.HTMLENCODE(TransType)%>: <%=Server.HTMLENCODE(replacementref)%></h1>

<p class="opsholder">
	<%If TransType<>"" AND Ref1<>"" Then 
			'get linkage to transactions forms
			linkfound=0
			OrderID=""
			rv_no=""
			thetype=""
			theformtype=""
			Set rsItm = Server.CreateObject("ADODB.Recordset")
			sql = "SELECT transtype, orderid, transsubtype " & _
				  "FROM orders WHERE transtype='" & TransType & "' AND orderid = '" & TRIM(Ref1) & "' "
			'Response.write sql & "<br>"
			rsItm.Open sql, oConn, adOpenStatic, adLockReadOnly
			If Not rsItm.EOF Then
				linkfound=1
				OrderID = TRIM(rsItm("orderid"))
				If TRIM(rsItm("transsubtype"))="CASH SALES" Then
					thetype = "CA"
				ELSE
					thetype = TransType
				End If
			End if
			rsItm.Close
			Set rsItm = nothing	

			If linkfound=0 Then
				If multipleac_OR="Y" AND TransType="OR" Then
					multi=""	
					Set rsItm = Server.CreateObject("ADODB.Recordset")
					sql = "SELECT transtype, rv_no, formtype as theformtype " & _
						  "FROM collections_group WHERE transtype='OR' AND position(rv_no IN '" & TRIM(Ref1) & "')=1 "
					'Response.write sql & "<br>"
					rsItm.Open sql, oConn, adOpenStatic, adLockReadOnly
					If Not rsItm.EOF Then
						multi="Y"
					End if
					rsItm.Close
					Set rsItm = nothing							  
				End If
				Set rsItm = Server.CreateObject("ADODB.Recordset")
				IF (TransType="OR" OR TransType="RC") AND multi<>"Y" Then
					sql = "SELECT transtype, rv_no, '' as theformtype " & _
						  "FROM collections WHERE transtype='" & TransType & "' AND position(rv_no IN '" & TRIM(Ref1) & "')>0 "				
				ELSE
					sql = "SELECT transtype, rv_no, formtype as theformtype " & _
						  "FROM collections_group WHERE transtype='" & TransType & "' AND position(rv_no IN '" & TRIM(Ref1) & "')=1 "
				End If
				'Response.write sql
				rsItm.Open sql, oConn, adOpenStatic, adLockReadOnly
				If Not rsItm.EOF Then
					theformtype= TRIM(rsItm("theformtype"))
					linkfound=1
					rv_no = TRIM(rsItm("rv_no"))
					IF TransType="OR" OR TransType="RC" OR TransType="PV" Then
						thetype = TransType
					ELSE
						thetype = "GJ" & TransType
					End If
				End if
				rsItm.Close
				Set rsItm = nothing	
			End If
			
			opentourl=""
			frominventory=""
			If linkfound=1 Then
				If OrderID<>"" Then
					opentourl=TranCodetoURL(thetype) & "?OrderID=" & OrderID & "&WithinFrame=y" & endvar
					frominventory="Y"
				ELSEIF rv_no<>"" AND len(thetype)=4 Then
					opentourl=TranCodetoURL(thetype) & "?rv_no=" & rv_no & "&TransType=" & RIGHT(thetype,2) & "&WithinFrame=y" & endvar
				ELSEIF rv_no<>"" Then
					opentourl=TranCodetoURL(thetype) & "?rv_no=" & rv_no & "&WithinFrame=y" & endvar
				End If
			End If	
	
	%>
		<%If TransType="CUSTOMER" Then%>
			<a class="optionstext" href="#" onClick="window.location.href = 'customersc.asp?ID=<%=Ref1%>';">Back to Data Entry Form</a>
		<%ELSEIf TransType="SUPPLIER" Then %>
			<a class="optionstext" href="#" onClick="window.location.href = 'suppliersc.asp?ID=<%=Ref1%>';">Back to Data Entry Form</a>
		<%ELSEIf TransType="ITEM" Then %>
			<a class="optionstext" href="#" onClick="window.location.href = 'itemsc.asp?item_no=<%=Server.URLENCODE(Ref1)%>';">Back to Data Entry Form</a>
		<%ELSE%>
			<a class="optionstext" href="#" onClick="window.location.href = '<%=opentourl%>';">Back to Data Entry Form</a>
		<%End If%>
	<%End If%>
</p>
<p class="messagetext"><%=message%></p>
<form name="theForm" method="GET" action="notes.asp?<%=endvar%>">
<input type="hidden" name="TransType" value="<%=Server.HTMLENCODE(TransType)%>">
<input type="hidden" name="Ref1" value="<%=Server.HTMLENCODE(Ref1)%>">
<input type="hidden" name="Category" value="<%=Server.HTMLENCODE(Category)%>">
<input type="hidden" name="doaction" value="Y">
<table class="table1" width="800">
	<tr>
		<td class="ifieldnamestext" width="120">Notes</td>
		<td class="fieldinfotext">
			<%
			
			n=0
			For n=0 to totlines
				notesvalue=""
				If INSTR(notes,"<br>")>0 Then
					arrnotes=SPLIT(notes,"<br>")
					If n<=UBound(arrnotes) Then
						notesvalue=arrnotes(n)
					End If
				ELSE
					If n=0 Then
						notesvalue=notes
					End If
				End If
				
			%>
				<input type="textbox" class="text-input" name="notes<%=n+1%>" size="100"  value="<%=SERVER.HTMLENCODE(notesvalue)%>" maxlength="<%=maxlen%>"><br>
			<%
			Next
			%>
		</td>
	</tr>		
	<!--
	<tr>
		<td class="ifieldnamestext">Last Action By</td>
		<td class="fieldinfotext"><%=recordedby%></td>
	</tr>	
	<tr>
		<td class="ifieldnamestext">Last Action Date/Time</td>
		<td class="fieldinfotext">
		<%
		If daterecorded<>"" Then
			Response.write USTOUKDATE(FormatDateTime(daterecorded,2)) & " " & FormatDateTime(daterecorded,4) 
        End If			
		
		%>
		</td>
	</tr>
	
	<tr>
		<td class="ifieldnamestext">Remarks</td>
		<td class="fieldinfotext">
			<textarea style="width:180px; height:85px;" wrap="physical" name="sign_remarks"><%=(sign_remarks)%></textarea>
		</td>
	</tr>	
	-->
</table>

<br>


<%
If TransType<>"" AND Ref1<>"" AND checkmoduleaccess("NOTES[VAE")=1 Then %>
	<input type="button" onClick="theForm.submit();" value="Save">&nbsp;
<%
End If
%>
	<input type="button" onClick="onoverlay1();" value="Copy & Paste">&nbsp;
<%
oConn4.Close
Set oConn4 = Nothing

oConn.Close
Set oConn = Nothing
%>
<div id="overlay">
	
	<p align=right><a href="#copypaste" onclick="offoverlay1();"><font color="white"><b>X Close</b></font></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</p>
	<table align="center" valign="middle" width="600" style="#FFFFFF;color: black" class="fixed_header">
		<thead align="center">
			<tr>
				<td width="600" colspan="3" class="messagetext" height="20"><b>Copy or Paste</b></td>
			</tr>		
			<tr class="ifieldinfotext">
				<td width="600" align="center"><b>Text</b><br><font color="red">(Each row should only have <%=maxlen%> characters. Extra characters will be removed.)</font></td>
			</tr>
		</thead>
		<tbody align="center">
		
		<tr>
			<td colspan="3" class="blacktextcolour2">
				<textarea class="def-txt-input" id="mainbox" rows="22" cols="100" onBlur="copypaste();"><%=Replace(notes,"<br>",CHR(10))%></textarea>			
			</td>
		</tr>		
		</tbody>
	</table>
</div> 
</form>

</body>
</html>