<%@ Language=VBScript %>
<%
	'	Requisition Approval Reasons
	'	Owner: Coen Mooijman
	'	$Revision: $
%>
<!-- #include file="../../include/General.asp" -->
<!-- #INCLUDE FILE="../../include/Utilities.asp" -->
<!-- #INCLUDE FILE="../../include/PageUtil.asp" -->
<!-- #INCLUDE FILE="../../include/Format.asp" -->
<!-- #include file = "../../include/EETable.asp" -->
<!-- #include file = "../include/LabelsRequisition.asp" -->
<!-- #include file = "../include/RequisitionUtility.asp" -->
<!-- #include file="../../include/Labels.asp" -->
<HTML>
<HEAD>
</HEAD> 
 
 <%
 
 dim gView
 'gView = getASPParameter("view")  109576.o
 
 '109576.sn
 if getOptionalASPParameter("view") <> "" then
		gView = ucase(getOptionalASPParameter("view"))
 else
		gView = ucase(Request.Form("view"))
 end if
 
 '109576.en
 
 'If the Form Button is pressed then the necessary actions are taken
 'Here the main action is to insert the Reasons in the ApprovalEntry Table
    
 if(Request.Form.Count<>0) then
 
	Dim lQuery
	
	lQuery = "UPDATE APPROVALENTRY SET REASONS = '" & SQLEncode(GetFormValue("REASONS")) _
				& "' WHERE REQUISITIONID = " & SQLEncode(GetFormValue("requisitionid")) _
				& " and REQUISITIONLINENUMBER= " & SQLEncode(GetFormValue("requisitionlinenumber")) _
				& " and APPROVALID= " & SQLEncode(GetFormValue("approvalid"))

    getConnection().execute(lQuery)
  
                           
    call Response.Redirect(getMSCSPage.URL("e-requisition/enduser/RequisitionLine_list.asp", _
                                           "mode", "APPROVAL", _
                                           "view", gView))

 end if
 %>
 <%
    ' Declaring the local Variables
    
    dim iRequisitionid
    dim iRequisitionerprefix
    dim iRequisitionlinenumber
    dim iApprovalid
    dim lFieldCode
    dim sql
    dim lrs
    dim gConnection
    dim lreqdetail
    
    
	iRequisitionid= getASPParameter("requisitionid")
	iRequisitionerprefix= getASPParameter("requisitionerprefix")
	iRequisitionlinenumber= getASPParameter("requisitionlinenumber")
	iApprovalid= getASPParameter("approvalid")
	
	
	lreqdetail=irequisitionid&"-"&trim(irequisitionerprefix)&"-"&trim(irequisitionlinenumber)
	set lrs=server.CreateObject("adodb.connection")
    sql = "SELECT * FROM APPROVALENTRY WHERE REQUISITIONID = " & irequisitionid & " and REQUISITIONLINENUMBER= " & irequisitionlinenumber & " and APPROVALID= " & iapprovalid
	set lrs = getConnection().execute(sql)
		
	'<BODY> tag is generated by setPageAttributes()
	gEETableForEndUser = true
	call setPageAttributes()
	
	'todo add labels
	call putExplainHeader("Approval Review","")

 %>
 	
 
		<FORM method="post" action="<%=getMSCSPage.URL("E-Requisition/Enduser/ApprovalReasons.asp")%>" id=form1 name=form1>
	   
<%
		
	        call TableBeginProp(I18N(Lbl_Approvals))
			 call TableHeaderCell(I18N(Lbl_ReqLineReq))
				lFieldCode = "<input type=text size=30 maxsize=30 name='REQUISITION'"
				lFieldCode = lFieldCode & " value='" & lreqdetail & "'"
				lFieldCode = lFieldCode & " disabled"
				lFieldCode = lFieldCode & ">"
		     call TableCell(lFieldCode)
			
			
			 call TableNewRow()
			 call TableHeaderCell(I18N(Lbl_ReqLineRequisitioner))
				lFieldCode = "<input type=text size=50 maxsize=50 name='REQUISITIONER'"
				lFieldCode = lFieldCode & " value='" & getRequisitioner(iRequisitionid, iRequisitionerprefix) & "'"
				lFieldCode = lFieldCode & " disabled"
				lFieldCode = lFieldCode & ">"
			 call TableCell(lFieldCode)
			
												
             call TableNewRow()
			 call TableHeaderCell(I18N(Lbl_ShowReasons))
				lFieldCode = "<Textarea name=REASONS id=REASONS rows=5 cols=50>" & lrs("REASONS") & "</Textarea>"
			 call TableCell(lFieldCode)
			
			 		
	       call TableEnd()
	       Response.Write("<BR>"& "<BR>")
          ' Response.Write(formButton("Add", I18NGif("BtnAdd.gif"),  "")) #IT 98.o
            Response.Write(formButton("Update", I18NGif("BtnUpdate.gif"),  ""))'#IT 98.n
	   

	       ' Passing all the key values through the form
	       'The values are passed as hidden values
	   
	        Response.Write(formhidden("requisitionid", irequisitionid))
	        Response.Write(formhidden("requisitionlinenumber", irequisitionlinenumber))
	        Response.Write(formhidden("approvalid", iapprovalid))
	        Response.Write(formhidden("view", gView))'109576.n
	   
	         
	    
       %>
       
       
      </form>
      
    
<%
  ' Gets the Requisitioner name using the values RquisitionId and the RequisitionerPrefix
   
   function getRequisitioner(iReqID, iReqPrefix)
		Dim lRS
		set lRS = getrecordset("SELECT USERID FROM REQUISITIONHEADER WHERE REQUISITIONID=" & iReqID)
		if not lRS.Eof then
			getRequisitioner = lRS("USERID").Value
		else
			getRequisitioner = ""
		end if
   end function

  		
Private Function getConnection()
		if ( IsEmpty(gConnection) or IsNull(gConnection) ) then
			Set gConnection = Server.CreateObject("ADODB.Connection")
			gConnection.ConnectionTimeout = Application("EProcurementConnection_ConnectionTimeout")
			gConnection.CommandTimeout = Application("EProcurementConnection_CommandTimeout")
			gConnection.CursorLocation = Application("EProcurementConnection_CursorLocation")
			gConnection.Open Application("EProcurementConnection_ConnectionString"), Application("EProcurementConnection_RuntimeUserName"), Application("EProcurementConnection_RuntimePassword")
			if Err.number<>0 then
				Err.Source = "RequisitionBusinessRules/getConnection"
				GenerateError
			End If
		end if
		Set getConnection = gConnection
	End Function
%>	

</BODY>
</HTML>