<% Response.Expires = -1 %>
<!-- #include file="datefunc2.inc.asp" -->
<!-- #include file="dealerconfig\adminsetup.asp" -->
<!-- #include file="dealerconfig\usermodules.asp" -->
<!-- #include file="dataconn.inc.asp" -->
<!-- #include file="displayinfo.inc.asp" -->
<!-- #include file="encrypt2.inc.asp" -->
<!-- #include file="dealerconfig\sst.asp" -->

<%
Function checkmoduleaccess(fmodule)
	checkmoduleaccess=0
	'Response.write fmodule
	If (USales="y" AND INSTR(UCASE(role_sales_modules),"|" & fmodule & "")>0) OR (USupport="y" AND INSTR(UCASE(role_support_modules),"|" & fmodule & "")>0) OR (UFinance="y" AND INSTR(UCASE(role_finance_modules),"|" & fmodule & "")>0) OR (ULogistics="y" AND INSTR(UCASE(role_logistics_modules),"|" & fmodule & "")>0) OR (UPromo="y" AND INSTR(UCASE(role_promo_modules),"|" & fmodule & "")>0) OR (UMan="y" AND INSTR(UCASE(role_manager_modules),"|" & fmodule & "")>0) OR (UGGM="y" AND INSTR(UCASE(role_ggm_modules),"|" & fmodule & "")>0) OR (UAccountant="y" AND INSTR(UCASE(role_accountant_modules),"|" & fmodule & "")>0) OR (UFull="y" AND INSTR(UCASE(role_admin_modules),"|" & fmodule & "")>0) OR (Udg1="y" AND INSTR(UCASE(role_udg1_modules),"|" & fmodule & "")>0) OR (Udg2="y" AND INSTR(UCASE(role_udg2_modules),"|" & fmodule & "")>0) OR (Udg3="y" AND INSTR(UCASE(role_udg3_modules),"|" & fmodule & "")>0) OR (Udg4="y" AND INSTR(UCASE(role_udg4_modules),"|" & fmodule & "")>0) OR (Udg5="y" AND INSTR(UCASE(role_udg5_modules),"|" & fmodule & "")>0) OR (Udg6="y" AND INSTR(UCASE(role_udg6_modules),"|" & fmodule & "")>0) OR (Udg7="y" AND INSTR(UCASE(role_udg7_modules),"|" & fmodule & "")>0) OR (Udg8="y" AND INSTR(UCASE(role_udg8_modules),"|" & fmodule & "")>0) OR (Udg9="y" AND INSTR(UCASE(role_udg9_modules),"|" & fmodule & "")>0) OR (Udg10="y" AND INSTR(UCASE(role_udg10_modules),"|" & fmodule & "")>0) OR (UPos="y" AND INSTR(UCASE(role_pos_modules),"|" & fmodule & "")>0) Then 
		checkmoduleaccess=1
	End If
End Function

Function checkreportaccess(fmodule)
	checkreportaccess=0
	'Response.write fmodule
	If (USales="y" AND INSTR(UCASE(role_sales_reports),"|" & fmodule & "")>0) OR (USupport="y" AND INSTR(UCASE(role_support_reports),"|" & fmodule & "")>0) OR (UFinance="y" AND INSTR(UCASE(role_finance_reports),"|" & fmodule & "")>0) OR (ULogistics="y" AND INSTR(UCASE(role_logistics_reports),"|" & fmodule & "")>0) OR (UPromo="y" AND INSTR(UCASE(role_promo_reports),"|" & fmodule & "")>0) OR (UMan="y" AND INSTR(UCASE(role_manager_reports),"|" & fmodule & "")>0) OR (UGGM="y" AND INSTR(UCASE(role_ggm_reports),"|" & fmodule & "")>0) OR (UAccountant="y" AND INSTR(UCASE(role_accountant_reports),"|" & fmodule & "")>0) OR (UFull="y" AND INSTR(UCASE(role_admin_reports),"|" & fmodule & "")>0) OR (Udg1="y" AND INSTR(UCASE(role_udg1_reports),"|" & fmodule & "")>0) OR (Udg2="y" AND INSTR(UCASE(role_udg2_reports),"|" & fmodule & "")>0) OR (Udg3="y" AND INSTR(UCASE(role_udg3_reports),"|" & fmodule & "")>0) OR (Udg4="y" AND INSTR(UCASE(role_udg4_reports),"|" & fmodule & "")>0) OR (Udg5="y" AND INSTR(UCASE(role_udg5_reports),"|" & fmodule & "")>0) OR (Udg6="y" AND INSTR(UCASE(role_udg6_reports),"|" & fmodule & "")>0) OR (Udg7="y" AND INSTR(UCASE(role_udg7_reports),"|" & fmodule & "")>0) OR (Udg8="y" AND INSTR(UCASE(role_udg8_reports),"|" & fmodule & "")>0) OR (Udg9="y" AND INSTR(UCASE(role_udg9_reports),"|" & fmodule & "")>0) OR (Udg10="y" AND INSTR(UCASE(role_udg10_reports),"|" & fmodule & "")>0) OR (UPos="y" AND INSTR(UCASE(role_pos_reports),"|" & fmodule & "")>0) Then 
		checkreportaccess=1
	End If
End Function

defaultbankcode="UOB"
saveservicerecs="N"
'defuserpass="Polaris@2005"

authenkey = TRIM(Request("authenkey"))
qsupuserid = TRIM(Request("u"))
qsuppass = TRIM(Request("p"))
qmobile = TRIM(Request("qmobile"))
transtype = TRIM(Request("transtype"))
isemailapproval = TRIM(Request("isemailapproval"))

If hidesecqty="N" Then
	str2ndfactor=",qty9, u_measure9, sndfactor "
	str2nduom2=", icitem.u_measure2 "
ELSE
	str2ndfactor=", 0 as qty9, '' as u_measure9, 0 as sndfactor "
	str2nduom2=", '' as u_measure2 "
End If


If qmobile = "Y" Then
	Ref = EnDeCrypt(authenkey, psw4)
	UniqueNo = Ref
ELSE
	OrderID = EnDeCrypt(authenkey, psw4)
End If

UserName = EnDeCrypt(qsupuserid, psw3)

If sys_approvals_email_autologin="Y" Then
	Password = EnDeCrypt(qsuppass, psw4)
	'response.write UserName & "hi<br>"
	'response.write Password & "hello<br>"
	'response.write OrderID & "hhey"
	
ELSE
	'redirect to login page
	If 1=1 Then
		IF isemailapproval="Y" Then
			If OrderID<> "" AND TransType<>"" Then
				If TransType="PV" Then
					path = "paymentvouchersc.asp?rv_no=" & Server.URLENCODE(OrderID) & endvar
				ELSEIf TransType="CUSTOMER" Then
					path = "customersc.asp?ID=" & Server.URLENCODE(OrderID) & endvar
				ELSE
					If sys_tran_approval_email_extralinks="Y" AND (TransType="IN" OR TransType="CA") Then
						path = "approvals.asp?TransType=" & TransType & "&Ref1=" & Server.URLENCODE(OrderID)& "&doaction=" & Server.URLENCODE(TRIM(Request("doaction"))) & endvar
					ELSE
						path = TranCodetoURL(TransType) & "?OrderID=" & OrderID & "" & endvar
					End If
				End If
			ELSE		
				path = "noaccess.asp"
			End If
			If Session("loginUserID")<>"" Then
				Response.redirect path
			ELSE
				Response.redirect "adminlogin.asp?return_url=" & Server.URLENCODE(path)
			End If
		End If		
	End If	
End If

Set oConn = Server.CreateObject("ADODB.Connection")
Call dataconn

'insert GST 0, sales
Set rsVis = Server.CreateObject("ADODB.Recordset")
' Create and open an ADO recordset object.
sql = "SELECT code, desc1, desc2, country, type, gtaxcode, gtaxrate, moduleref " & _
	  "FROM stax " & _
	  "WHERE UPPER(code) = 'SR-0' "

rsVis.Open sql, oConn, adOpenDynamic, adLockOptimistic
' Login user
If rsVis.EOF Then
	rsVis.AddNew
		rsVis("code") = "SR-0"
		rsVis("desc1") ="Standard-rated supplies with GST charges 0%"
		rsVis("desc2") = "Standard-rate supplies"
		rsVis("country") = "M"
		rsVis("type") = "S"
		rsVis("gtaxcode") = "SR"
		rsVis("gtaxrate") = 0
		rsVis("moduleref") = 0
	
	rsVis.Update
End If
rsVis.Close
Set rsVis = Nothing

'insert GST 0, purchases
Set rsVis = Server.CreateObject("ADODB.Recordset")
' Create and open an ADO recordset object.
sql = "SELECT code, desc1, desc2, country, type, gtaxcode, gtaxrate, moduleref " & _
	  "FROM stax " & _
	  "WHERE UPPER(code) = 'TX-0' "

rsVis.Open sql, oConn, adOpenDynamic, adLockOptimistic
' Login user
If rsVis.EOF Then
	rsVis.AddNew
		rsVis("code") = "TX-0"
		rsVis("desc1") ="Purchases with GST incurred at 0% and directry attributable to taxable suppliers"
		rsVis("desc2") = "Purchases with GST"
		rsVis("country") = "M"
		rsVis("type") = "P"
		rsVis("gtaxcode") = "ZP"
		rsVis("gtaxrate") = 0
		rsVis("moduleref") = 0
	
	rsVis.Update
End If
rsVis.Close
Set rsVis = Nothing


'insert SST 6%, sales
Set rsVis = Server.CreateObject("ADODB.Recordset")
' Create and open an ADO recordset object.
sql = "SELECT code, desc1, desc2, country, type, gtaxcode, gtaxrate, moduleref " & _
	  "FROM stax " & _
	  "WHERE UPPER(code) = 'SST' "

rsVis.Open sql, oConn, adOpenDynamic, adLockOptimistic
' Login user
If rsVis.EOF Then
	rsVis.AddNew
		rsVis("code") = "SST"
		rsVis("desc1") ="Government Service tax or Sales Tax"
		rsVis("desc2") = "Government Service tax or Sales Tax"
		rsVis("country") = "M"
		rsVis("type") = "S"
		rsVis("gtaxcode") = "SR"
		rsVis("gtaxrate") = 6
		rsVis("moduleref") = 0
	
	rsVis.Update
End If
rsVis.Close
Set rsVis = Nothing
'Response.write USACDATE
'after 1st June 2018, change the default codes
If DateDiff("d","2018-06-01",ConvertMYSQL(USACDATE))>=0 AND enableGSTZero="Y" Then
	gstctaxcodesdef="SR-0"
	gstctaxcodepdef="TX-0"
	gsttaxcodesdef="SR-0"
	gsttaxcodepdef="TX-0"
	gstdefrate=0
End If

'after 1st Sept 2018, change the default codes
If DateDiff("d","2018-09-01",ConvertMYSQL(USACDATE))>=0 AND enableSST="Y" Then
	'gstctaxcodesdef="SR-0"
	'gstctaxcodepdef="TX-0"
	'gsttaxcodesdef="SR-0"
	'gsttaxcodepdef="TX-0"
	'gstdefrate=0
End If

'after 1st Dec 2023, change the tax rate for SG
If DateDiff("d","2023-01-01",ConvertMYSQL(USACDATE))>=0 AND gstCountry="S" Then
	'gstctaxcodesdef="SR-0"
	'gstctaxcodepdef="TX-0"
	'gsttaxcodesdef="SR-0"
	'gsttaxcodepdef="TX-0"
	
	gstdefrate=8
	updategstnow=""
	Set rsVis = Server.CreateObject("ADODB.Recordset")
	' Create and open an ADO recordset object.
	sql = "SELECT code, desc1, desc2, country, type, gtaxcode, gtaxrate, moduleref " & _
	  "FROM stax " & _
	  "WHERE country = 'S' AND gtaxrate=8 ORDER BY code LIMIT 1 "

	rsVis.Open sql, oConn, adOpenDynamic, adLockOptimistic
	' Login user
	If rsVis.EOF Then
		updategstnow="Y"
	End If
	rsVis.Close
	Set rsVis = Nothing	
	
	If updategstnow="Y" Then
		Set oConn3 = Server.CreateObject("ADODB.Connection")
		Call dataconnaccmysql(sqlaccdb)
		
		cmd="UPDATE stax SET gtaxrate=8 WHERE country='S' AND gtaxrate=7 "
		oConn.Execute(cmd)
		cmd="UPDATE stax SET gtaxrate=8 WHERE country='S' AND gtaxrate=7 "
		oConn3.Execute(cmd)
		
		oConn3.Close
		Set oConn3=Nothing
	End If
End If

' Determine which button the Web visitor clicked and take appropriate action.
If (OrderID <> "" OR Ref <> "") AND (qsupuserid<>"" AND qsuppass<>"") Then
	

   rsp11 = "df6g"

   psw = UCASE(username) & UKACDATE & rsp11
   txt = Request.ServerVariables("REMOTE_HOST") & UCASE(username)

   strTemp = EnDeCrypt(txt, psw)

   for x = 1 to len(strTemp)
      DayPass = DayPass & right(string(2,"0") & hex(asc(mid(strTemp, x, 1))),2) & ""
      if x mod 26 = 0 then response.write vbCRLF
   next

		If username <> "" Then
		Set rsVis = Server.CreateObject("ADODB.Recordset")
		' Create and open an ADO recordset object.
		sql = "SELECT UserID, Password, DayPass, PassTS, LoggedIn, ActiveRec, sessionid, ipaddress, lastactivetime, location, username " & _
			  "FROM users " & _
			  "WHERE UPPER(UserID) = '" & UCASE(CleanseInput3(username)) & "'"
		rsVis.Open sql, oConn, adOpenDynamic, adLockOptimistic
		' Login user
		If rsVis.EOF Then
			message = "User ID not found. You are not authorised to enter the secure area."
			loginfailure = loginfailure + 1
		Else
			If CleanseInput(Password) = rsVis("Password") Then
				Session("uniquesession") = UCASE(username) & uautoid
				activerec = TRIM(rsVis("activerec"))
				rsVis("DayPass") = DayPass
				rsVis("PassTS") = uautoid
				rsVis("LoggedIn") = "y"
				rsVis("sessionid") = TRIM(Session("uniquesession"))
				rsVis("ipaddress") = TRIM(Request.ServerVariables("remote_addr"))
				rsVis("lastactivetime") = Now()
				rsVis.Update
				loggedin = True
				Session("loginUserID") = UCASE(username)
			Else
				message = "Password and/or User ID error. You are not authorised to enter the secure area."
				loginfailure = loginfailure + 1
			End If
		End If
		rsVis.Close
		Set rsVis = Nothing
	End If ' validate userid in sql
End If


usertype = TRIM(RIGHT(WHOISUSER(UCASE(username)),3))

	' Get and set time/date settings
	Set rsVis = Server.CreateObject("ADODB.Recordset")
	sql = "SELECT CompanyName, LCID, companyurl as peppolid " & _
		  "FROM companies " & _
		  "WHERE companyid <> '' "
	rsVis.Open sql, oConn, adOpenStatic, adLockReadOnly
	If Not rsVis.EOF Then
		CompanyName = rsVis("CompanyName")
		Upeppolid = rsVis("peppolid")
		strLCID = rsVis("LCID")
		If DefCompanyDesc="" Then
			DefCompanyDesc=CompanyName
		End If
	Else
		CompanyName = ""
		strLCID = 1033  ' Default to English(United States)
	End If
	rsVis.Close
	Set rsVis = Nothing
	
If loggedin Then
	
	Session("loginUserID") = UCASE(username)

	usertype = TRIM(RIGHT(WHOISUSER(UCASE(Session("loginUserID"))),3))
	curuser = CLEANSEINPUT(Session("loginUserID"))

	Session.LCID = strLCID

	If usertype = "[E]" AND sys_approvals_email_autologin="Y" Then

		IF isemailapproval="Y" Then	
			If OrderID<> "" AND TransType<>"" Then
				
				If TransType="PV" Then
					path = "paymentvouchersc.asp?rv_no=" & Server.URLENCODE(OrderID) & endvar
				ELSEIf TransType="CUSTOMER" Then
					path = "customersc.asp?ID=" & Server.URLENCODE(OrderID) & endvar
				ELSE				
					If sys_tran_approval_email_extralinks="Y" AND (TransType="IN" OR TransType="CA") Then
						path = "approvals.asp?TransType=" & TransType & "&Ref1=" & Server.URLENCODE(OrderID)& "&doaction=" & Server.URLENCODE(TRIM(Request("doaction"))) & "&linkapprove=Y" & endvar				
					ELSE
						path = TranCodetoURL(TransType) & "?OrderID=" & OrderID & "" & endvar
						
					End If
				End If
			End If
		ELSEIf qmobile = "Y" Then
			path = "foxcussoprint.asp?Ref=" & Ref & "&UniqueNo=" & UniqueNo & "&type=SO" & endvar
		ELSE
			If OrderID<> "" Then
				If transtype="CR" Then
					path = "cnreqcartall.asp?OrderID=" & OrderID & endvar
				ELSE
					If transtype="DR" Then
						path = "dnreqcartall.asp?OrderID=" & OrderID & endvar
					ELSE
						path = "ordercartall.asp?OrderID=" & OrderID & endvar
					End If
				End If
			Else
				path = "noaccess.asp"
			End If
		End If	
		
		If Session("loginUserID") <> "" Then
			'response.write Session("loginUserID") & "<br>"
			'response.write Session("uniquesession") & "<br>"
			'oConn.Execute("111")		
			Response.redirect path
			
			'oConn.Execute("111")
		ELSE
			Response.redirect path
			
			'oConn.Execute("111")		
		End If
	End If	
End If

'Response.write "GOGO" & Session("loginUserID")
'oConn.Execute("111")
If Session("loginUserID") <> "" Then
	'lengthuser = len(Session("loginUserID"))
	curuser = CLEANSEINPUT(Session("loginUserID"))
	company = ""
	department = ""
	location = ""
	If Session("uniquesession") <> "" Then
		Set rsVis = Server.CreateObject("ADODB.Recordset")
		' Create and open an ADO recordset object.
		sql = "SELECT UserID, Password, DayPass, PassTS, LoggedIn, ActiveRec, sessionid, ipaddress, lastactivetime " & _
			  "FROM users " & _
			  "WHERE UPPER(sessionid) = '" & UCASE(CleanseInput3(Session("uniquesession"))) & "'"
		rsVis.Open sql, oConn, adOpenDynamic, adLockOptimistic
		' Login user
		If rsVis.EOF Then
			stillloggedin="n"
			message = "Session has expired. Please login again. Code: 100"
		Else
			stillloggedin=TRIM(rsVis("LoggedIn"))
			If stillloggedin="y" Then
				rsVis("lastactivetime") = Now()
			End If
			rsVis.Update
		End If
		rsVis.Close
		Set rsVis = Nothing
	ELSE
		stillloggedin="n"
		message = "Session has expired. Please login again. Code: 101"
	End If
	
	If stillloggedin="n" Then
		Session("uniquesession")=""
		Session("loginUserID")=""
		Response.write "<Script Language=""JavaScript"">"
		Response.write "parent.parent.location.href='anotlogin.asp';"
		Response.write "</Script>"
		Response.redirect "anotlogin.asp?"	 & endvar
	End If
ELSE
	Response.write "<Script Language=""JavaScript"">"
	Response.write "parent.parent.location.href='anotlogin.asp';"
	Response.write "</Script>"
	Response.redirect "anotlogin.asp?"	 & endvar
End If

If curuser = "" Then
	Response.write "<Script Language=""JavaScript"">"
	Response.write "parent.parent.location.href='anotlogin.asp';"
	Response.write "</Script>"
	Response.redirect "anotlogin.asp?" & endvar
	If dbverify = "y" Then
		Response.Redirect "anotlogin.asp?"	 & endvar
	End If
End If



Set rsItm = Server.CreateObject("ADODB.Recordset")
sql = "SELECT users.PriceRec, users.StockRec, users.FullRec, users.ActiveRec, users.ManagerRec, users.SalesRec, users.SupportRec, users.FinanceRec, users.LogisticsRec, users.Email, users.Superior, users.Location, users.SecurityCode, users.Subordinates, users.Subordinates2, users.ggmrec, users.accountantrec, users.promorec, users.acc_bills, users.acc_runnoset, users.default_rv_acc, users.default_pv_acc, users.default_gj_acc, users.hsource, users.hjob, print_bills, print_runnoset, users.costmrrec, users.costfcrec, users.costmurec, users.costoprec, users.costreportrec, pricearec, pricebrec, posrec, posmultipayrec, bin, porec, podetailsrec, day1, day1_ftime, day1_ttime, day2, day2_ftime, day2_ttime, day3, day3_ftime, day3_ttime, day4, day4_ftime, day4_ttime, day5, day5_ftime, day5_ttime, day6, day6_ftime, day6_ttime, day7, day7_ftime, day7_ttime, accessexpiry, udg1rec, udg2rec, udg3rec, udg4rec, udg5rec, udg6rec, udg7rec, udg8rec, udg9rec, udg10rec " & _
      "FROM users " & _
      "WHERE (UPPER(users.UserID)='" & UCASE(CleanseInput3(curuser)) & "') " & _
      "ORDER BY users.UserID "
rsItm.Open sql, oConn, adOpenStatic, adLockReadOnly
If rsItm.EOF Then
	Response.write "<Script Language=""JavaScript"">"
	Response.write "parent.location.href='anotlogin.asp?" & endvar
	Response.write "</Script>"
	Response.redirect "anotlogin.asp?" & endvar
Else
	UPrice = TRIM(rsItm("PriceRec"))
	UStock = TRIM(rsItm("StockRec"))
	USales = TRIM(rsItm("SalesRec"))
	USupport = TRIM(rsItm("SupportRec"))
	UFinance = TRIM(rsItm("FinanceRec"))
	ULogistics = TRIM(rsItm("LogisticsRec"))
	UMan = TRIM(rsItm("ManagerRec"))
	UFull = TRIM(rsItm("FullRec"))
	UActive = TRIM(rsItm("ActiveRec"))
	UEmail = TRIM(rsItm("Email"))
	USuperior = TRIM(rsItm("Superior"))
	ULocation = TRIM(rsItm("Location"))
	UBin = TRIM(rsItm("Bin"))
	USecurityCode = TRIM(rsItm("SecurityCode"))
	USubordinates = TRIM(rsItm("Subordinates"))
	USubordinates2 = TRIM(rsItm("Subordinates2"))
	UGGM = TRIM(rsItm("GGMRec"))
	UAccountant = TRIM(rsItm("AccountantRec"))
	UPromo = TRIM(rsItm("PromoRec"))
	Uacc_bills = TRIM(rsItm("acc_bills"))
	Uacc_runnoset = TRIM(rsItm("acc_runnoset"))
	Udefault_rv_acc = TRIM(rsItm("default_rv_acc"))
	Udefault_pv_acc = TRIM(rsItm("default_pv_acc"))
	Udefault_gj_acc = TRIM(rsItm("default_gj_acc")) 
	UHsource = TRIM(rsItm("hsource"))
	UHjob = TRIM(rsItm("hjob"))
	Uprint_bills = TRIM(rsItm("print_bills"))
	Uprint_runnoset = TRIM(rsItm("print_runnoset"))	
	Ucostmr = TRIM(rsItm("costmrrec"))
	Ucostfc = TRIM(rsItm("costfcrec"))
	Ucostmu = TRIM(rsItm("costmurec"))
	Ucostop = TRIM(rsItm("costoprec"))
	Ucostreport = TRIM(rsItm("costreportrec"))
	Upricea = TRIM(rsItm("pricearec"))
	Upriceb = TRIM(rsItm("pricebrec"))
	UPos = TRIM(rsItm("posrec"))
	Uposmultipayrec = TRIM(rsItm("posmultipayrec"))
	Uporec = TRIM(rsItm("porec"))
	Upodetailsrec = TRIM(rsItm("podetailsrec"))
	Udg1 = TRIM(rsItm("udg1rec"))
	Udg2 = TRIM(rsItm("udg2rec"))
	Udg3 = TRIM(rsItm("udg3rec"))
	Udg4 = TRIM(rsItm("udg4rec"))
	Udg5 = TRIM(rsItm("udg5rec"))
	Udg6 = TRIM(rsItm("udg6rec"))
	Udg7 = TRIM(rsItm("udg7rec"))
	Udg8 = TRIM(rsItm("udg8rec"))
	Udg9 = TRIM(rsItm("udg9rec"))
	Udg10 = TRIM(rsItm("udg10rec"))	
	If sys_daytime_access_control="Y" Then
		IF ISDATE(TRIM(rsItm("accessexpiry"))) Then
			accessexpiry=TRIM(rsItm("accessexpiry"))
		End If
		If accessexpiry<>"" Then
			If DateDiff("d",ConvertMYSQL(USACDATE),ConvertMYSQL(accessexpiry))>=0 Then
				'valid date access
			ELSE
				killdayaccess="Y"
			End IF
		End If
		thisweekday=WeekDay(Now())
		If thisweekday>=0 AND thisweekday<=7 Then
			dayaccess=TRIM(rsItm("day" & thisweekday))
			day_ftime=TRIM(rsItm("day" & thisweekday & "_ftime"))
			day_ttime=TRIM(rsItm("day" & thisweekday & "_ttime"))	
			If dayaccess="y" Then
				thishour = Right("00" & Hour(NOW()), 2)
				thismin = Right("00" & Minute(NOW()), 2)
				thistime = thishour & ":" & thismin
				If day_ftime<>"" AND day_ttime<>"" Then
					If thistime>=day_ftime AND thistime<=day_ttime Then
						'valid time access
					ELSE
						'kill access
						killdayaccess="Y"				
					End If
				End If
			ELSE
				'kill access
				killdayaccess="Y"
			End If
		End If
	End If
	
End If
rsItm.Close
set rsItm = nothing

If killdayaccess="Y" Then
    Session("loginUserID") = ""
    Session("sCartID") = ""
    Session("sCustomerID") = ""
    Session("sDiscount2") = ""
	Session("slevel") = ""
	Session("SupplierID") = ""
	Response.write "<Script Language=""JavaScript"">"
	Response.write "parent.location.href='anotlogin.asp?" & endvar
	Response.write "</Script>"
	Response.redirect "anotlogin.asp?message=You are not allowed access at this day and time. System has terminated your session." & endvar
End If

' Get path of accounting DB
Set RS = Server.CreateObject("ADODB.Recordset")
sql = "SELECT AccDBPath, ScriptPath " & _
      "FROM companies " & _
      "WHERE (CompanyID <>'') "
RS.Open sql, oconn, adOpenStatic, adLockReadOnly
If Not RS.EOF Then
	arrprod = RS.GetRows
	AccDBPath = arrprod(0,0)
	'ScriptPath = arrprod(1,0)
	StrScriptPath = Request.ServerVariables("SCRIPT_NAME")
	arrscript = SPLIT(StrScriptPath,"/")
	ScriptPath = "/" & TRIM(arrscript(1)) & "/"

End If
RS.close
set RS = nothing

'get current financial year
Set rsItmgg = Server.CreateObject("ADODB.Recordset")
	sql = "SELECT code, fromdate, todate, currfy, glstockcodes, seq " & _
		  "FROM financialyears WHERE deleted <> 'Y' AND currfy='Y' " & _
		  "ORDER BY code LIMIT 1 "
'response.write sql & "<br>"
rsItmgg.Open sql, oConn, adOpenStatic, adLockReadOnly
If Not rsItmgg.EOF Then
	FYSTARTDATE=USTOUKDATE(TRIM(rsItmgg("fromdate")))
	FYENDDATE=USTOUKDATE(TRIM(rsItmgg("todate")))
End If
rsItmgg.Close
Set rsItmgg = Nothing

' Script Paths
prescriptname = ScriptPath
lenprescriptname = len(prescriptname)
sn = Request.ServerVariables("SCRIPT_NAME")
lensn = len(sn)
scriptname = RIGHT(sn,lensn-lenprescriptname)
rsp11 = "df6g"

If UActive <> "y" Then
	If scriptname = "sidemenusales.asp" OR scriptname = "sidemenu.asp" OR scriptname = "passmaintc.asp" Then
		'do nothing
	Else
		Response.write "<Script Language=""JavaScript"">"
		Response.write "parent.parent.location.href='anotlogin.asp';"
		Response.write "</Script>"
		Response.redirect "anotlogin.asp?" & endvar
	End If
End If

securityname = WHOISUSER(UCASE(curuser))
securitytype = TRIM(RIGHT(securityname,3))

oConn.Close
Set oConn = Nothing

taxdisp = "hidden"
%>
