PageRenderTime 27ms CodeModel.GetById 15ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 0ms

/beta/admin/manageGL.asp

http://github.com/khaneh/Orders
ASP | 411 lines | 293 code | 47 blank | 71 comment | 27 complexity | 1304c456c57159c38302a95ee65784f7 MD5 | raw file
  1<%@LANGUAGE="VBSCRIPT" CODEPAGE="1256"%><%
  2' Admin
  3PageTitle= "������ ���� ��"
  4SubmenuItem=9
  5
  6
  7%>
  8<!--#include file="top.asp" -->
  9<!--#include File="../include_farsiDateHandling.asp"-->
 10<!--#include File="../include_JS_InputMasks.asp"-->
 11
 12<%
 13'-----------------------------------------------------------------------------------------------------
 14'---------------------------------------------------------------------------- Submit Change Default GL
 15'-----------------------------------------------------------------------------------------------------
 16if request("act")="delRow" then
 17	rowNo =request("rowNo")
 18	mySQL="UPDATE UserDefaults SET WorkingGL=Null WHERE ([User]="& rowNo & ")"
 19	conn.Execute(mySQL)
 20
 21	Set RS2 = conn.Execute("SELECT GLs.EndDate, GLs.StartDate, GLs.Name, GLs.ID, GLs.FiscalYear, UserDefaults.[User] FROM GLs INNER JOIN UserDefaults ON GLs.ID = UserDefaults.WorkingGL WHERE (UserDefaults.[User] = '"& session("id") & "') OR (UserDefaults.[User] = 0) ORDER BY ABS(UserDefaults.[User]) DESC")
 22	session("OpenGL")=RS2("id")
 23	session("FiscalYear")=RS2("FiscalYear")
 24	session("OpenGLName")=RS2("name")
 25	session("OpenGLStartDate")=RS2("StartDate")
 26	session("OpenGLEndDate")=RS2("EndDate")
 27	RS2.movenext
 28	session("differentGL") = False
 29	RS2.close
 30	
 31	response.redirect "?act=select"
 32
 33'-----------------------------------------------------------------------------------------------------
 34'---------------------------------------------------------------------------- Submit Change Default GL
 35'-----------------------------------------------------------------------------------------------------
 36elseif request("act")="change" then
 37
 38	newOpenGL=request("OpenGL")
 39	forWhom=request("forWhom")
 40
 41	if forWhom = 0 then
 42
 43		conn.Execute("UPDATE GLs SET IsDefault = 0")
 44		conn.Execute("UPDATE GLs SET IsDefault = 1 , LastChangedBy="& session("ID")& " , LastChangedDate=N'"& shamsiToday() & "', LastChange=N'set to default' WHERE (ID = "& newOpenGL & ")")
 45
 46		'Changed 13282/01/09 for using UserDefaults table instead
 47		'Set RS2 = conn.Execute("SELECT FiscalYear, name, ID FROM GLs WHERE (IsDefault = 1) ORDER BY ID DESC")
 48
 49		mySQL="UPDATE UserDefaults SET WorkingGL='"& newOpenGL & "' WHERE ([User]=0)"
 50		conn.Execute(mySQL)
 51		responseRedirectAddress = "AccountInfo.asp?msg=" & Server.URLEncode("��� ���� ����� ���� ��� ������� ����� ���.")
 52	
 53	else
 54		Set RS2 = conn.Execute("SELECT [User] as ID, WorkingGL FROM UserDefaults WHERE ([User] = "& forWhom & ") OR (UserDefaults.[User] = 0) ORDER BY ABS(UserDefaults.[User]) DESC")
 55
 56		if RS2("id")="0" then
 57			mySQL="INSERT INTO UserDefaults ([User], WorkingGL) VALUES ("& forWhom & ","& newOpenGL & ")"
 58			conn.Execute(mySQL)
 59		else
 60			mySQL="UPDATE UserDefaults SET WorkingGL='"& newOpenGL & "' WHERE ([User]="& forWhom & ")"
 61			conn.Execute(mySQL)
 62		end if
 63
 64		responseRedirectAddress = "AccountInfo.asp?msg=" & Server.URLEncode("��� ���� ����� ���� ��� (" & forWhom & ") ����� ���")
 65	end if
 66
 67	Set RS2 = conn.Execute("SELECT GLs.EndDate, GLs.StartDate, GLs.Name, GLs.ID, GLs.FiscalYear, UserDefaults.[User] FROM GLs INNER JOIN UserDefaults ON GLs.ID = UserDefaults.WorkingGL WHERE (UserDefaults.[User] = '"& session("id") & "') OR (UserDefaults.[User] = 0) ORDER BY ABS(UserDefaults.[User]) DESC")
 68	session("OpenGL")=RS2("id")
 69	session("FiscalYear")=RS2("FiscalYear")
 70	session("OpenGLName")=RS2("name")
 71	session("OpenGLStartDate")=RS2("StartDate")
 72	session("OpenGLEndDate")=RS2("EndDate")
 73	RS2.movenext
 74	session("differentGL") = False
 75	if not RS2.EOF then
 76		temp=RS2("id")
 77		if temp <> session("OpenGL") then
 78			session("differentGL") = True
 79		end if
 80	end if
 81	RS2.close
 82
 83	response.redirect responseRedirectAddress
 84
 85'-----------------------------------------------------------------------------------------------------
 86'-------------------------------------------------------------------------------- Submit Create New GL
 87'-----------------------------------------------------------------------------------------------------
 88elseif request("act")="submitNew" then
 89
 90	name=request.form("name")
 91	FiscalYear=request.form("FiscalYear")
 92	copy = request.form("copy")
 93	OpenGL = request.form("OpenGL")
 94
 95
 96	CurrentDate = shamsiToday()
 97	tempStartDate=	FiscalYear & "/01/01" 'left(CurrentDate,4)&"/01/01"
 98	tempEndDate= FiscalYear & "/12/30" 'left(CurrentDate,4)&"/12/30"
 99
100	Set RS2 = conn.Execute("SELECT * FROM GLs WHERE ID=" & OpenGL)
101	SourceGL = RS2("ID")
102	SourceGL_Name = RS2("Name")
103	RS2.close
104
105	conn.Execute("INSERT INTO GLs (Name, FiscalYear, StartDate, EndDate, IsDefault, IsClosed, LastChangedBy, LastChangedDate, LastChange) VALUES ( N'"& name & "', N'"& FiscalYear & "', N'"& tempStartDate & "', N'"& tempEndDate & "', 0, 0, "& session("id") & ", N'"& CurrentDate & "', N'Created')")
106
107	Call showAlert ("���� �� ���� ����� ��",CONST_MSG_INFORM)
108
109	if copy="on" then
110		Set RS2 = conn.Execute("SELECT * from GLs where FiscalYear=" & FiscalYear & " order by id DESC")
111		GLID=RS2("id")
112		conn.Execute("INSERT INTO GLAccountSuperGroups SELECT ID, Name, " & GLID & " AS GL, Type FROM GLAccountSuperGroups WHERE (GL = "& SourceGL & ")")
113		conn.Execute("INSERT INTO GLAccountGroups SELECT ID, GLSuperGroup, Name, " & GLID & " AS GL FROM GLAccountGroups WHERE (GL = "& SourceGL & ")")
114		conn.Execute("INSERT INTO GLAccounts SELECT ID, GLGroup, Name, " & GLID & " AS GL,HasAppendix, IsChequeAccount, accountType FROM GLAccounts WHERE (GL = "& SourceGL & ")")
115		response.write "<BR><BR>"
116		Call showAlert ("���� �� � ���� �� �� " & SourceGL_Name & " ߁� ��",CONST_MSG_INFORM)
117
118
119		conn.Execute("INSERT INTO AXItemReasonGLAccountRelations (ItemReason, GLAccount, GL) SELECT ItemReason, GLAccount, " & GLID & " AS GL FROM AXItemReasonGLAccountRelations WHERE (GL = " & SourceGL & ")")
120		response.write "<BR><BR>"
121		Call showAlert ("AXItemReasonGLAccountRelations �� " & SourceGL_Name & " ߁� ��",CONST_MSG_INFORM)
122
123		conn.Execute("INSERT INTO BankerCheqStatusGLAccountRelation (Banker, CheqStatus, GLAccount, GL) SELECT Banker, CheqStatus, GLAccount, " & GLID & " AS GL FROM BankerCheqStatusGLAccountRelation WHERE (GL = " & SourceGL & ") ORDER BY Banker, CheqStatus, GLAccount")
124		response.write "<BR><BR>"
125		Call showAlert ("BankerCheqStatusGLAccountRelation �� " & SourceGL_Name & " ߁� ��",CONST_MSG_INFORM)
126
127	end if
128
129
130
131'"INSERT INTO GLAccounts SELECT ID, GLGroup, Name, 3 AS GL FROM GLAccounts WHERE (GL = 1)"
132
133'-----------------------------------------------------------------------------------------------------
134'------------------------------------------------------------------------------- Close an open GL Form
135'-----------------------------------------------------------------------------------------------------
136elseif request("act")="new" then
137%>
138<CENTER>
139<BR><BR><BR><BR>
140<FORM METHOD=POST ACTION="manageGL.asp?act=submitNew">
141<TABLE>
142<TR>
143	<TD colspan=2 align=center><H3>����� ���� �� ����</H3></TD>
144</TR>
145<TR>
146	<TD align=left>����� ����: </TD>
147	<TD><INPUT TYPE="text" NAME="name"></TD>
148</TR>
149<TR>
150	<TD align=left>��� ����: </TD>
151	<TD><INPUT TYPE="text" NAME="FiscalYear" onkeypress="return maskNumber(this)" maxlength=4></TD>
152</TR>
153<TR>
154	<TD colspan=2><BR></TD>
155</TR>
156<TR>
157	<TD align=left><INPUT TYPE="checkbox" NAME="copy" checked> ߁� ���� �� � ���� �� �� </TD>
158	<TD>
159		<%
160		set RSSX=Conn.Execute ("SELECT * from GLs where IsClosed=0 order by id desc")
161		%>
162		<SELECT NAME="OpenGL" style="font-family:tahoma" class="GenButton">
163		<%
164		Do while not RSSX.eof
165		%>
166		<option <%	if cint(OpenGL)=cint(RSSX("ID")) then 
167						response.write "selected"
168						GLname = RSSX("name")
169					end if %> value="<%=RSSX("ID")%>" ><%=RSSX("name")%> - ��� ���� <%=RSSX("FiscalYear")%></option>
170		<% 
171
172		RSSX.moveNext
173		Loop
174		RSSX.close
175		%>
176		</SELECT>
177	</TD>
178</TR>
179<TR>
180	<TD colspan=2 align=center> 
181		<BR><BR>
182		<INPUT TYPE="submit" value="�����"class="GenButton">
183		<INPUT TYPE="button" value="������"class="GenButton" onclick="window.location='AccountInfo.asp'">
184	</TD>
185</TR>
186</TABLE>
187<%
188'-----------------------------------------------------------------------------------------------------
189'------------------------------------------------------------------------------- Close an open GL Form
190'-----------------------------------------------------------------------------------------------------
191elseif request("act")="close" then
192%>
193<CENTER>
194<BR><BR>
195<% call showAlert ("<B>����: </B><BR>���� �� �� ���� �ѐ�� �ǁ��� ���<BR>� ���� �� ��� �� ��� �� ��� ��� ����<BR>�� �� ����� ���� �����.<BR>",CONST_MSG_INFORM)%>
196
197<BR>
198<% call showAlert ("���� �� ���� �� ��� �� ����� ���� ��� ��� ���� ��� ���� ���",CONST_MSG_INFORM)%>
199
200<BR><BR>
201<%
202set RSSX=Conn.Execute ("SELECT * from GLs where IsClosed=0 and IsDefault=0 order by id desc")
203%>
204<FORM METHOD=POST ACTION="manageGL.asp?act=submitClose">
205
206<B>���� ���� �� </B><SELECT NAME="OpenGL" style="font-family:tahoma" class="GenButton">
207<%
208Do while not RSSX.eof
209%>
210<option <%	if cint(OpenGL)=cint(RSSX("ID")) then 
211				response.write "selected"
212				GLname = RSSX("name")
213			end if %> value="<%=RSSX("ID")%>" ><%=RSSX("name")%> - ��� ���� <%=RSSX("FiscalYear")%></option>
214<% 
215
216RSSX.moveNext
217Loop
218RSSX.close
219%>
220</SELECT><BR><BR>
221<INPUT TYPE="submit" value="����"class="GenButton">
222<INPUT TYPE="button" value="������"class="GenButton" onclick="window.location='AccountInfo.asp'">
223</FORM>
224</CENTER>
225
226<%
227
228'-----------------------------------------------------------------------------------------------------
229'--------------------------------------------------------------------------------- submit Closing a GL
230'-----------------------------------------------------------------------------------------------------
231elseif request("act")="submitClose" then
232	conn.Execute("UPDATE GLs SET IsClosed = 1 , LastChangedBy="& session("ID")& " , LastChangedDate=N'"& shamsiToday() & "', LastChange=N'Closed' WHERE (ID = "& request("OpenGL") & ")")
233
234	response.redirect "AccountInfo.asp"
235
236
237'-----------------------------------------------------------------------------------------------------
238'-------------------------------------------------------------------------------- Show GLs Changes Log
239'-----------------------------------------------------------------------------------------------------
240elseif request("act")="showLog" then
241	set RSSX=Conn.Execute ("SELECT Users.RealName, GLLog.ChangedDate, GLLog.Change, GLs.Name ,GLs.id , GLs.FiscalYear  FROM GLLog INNER JOIN GLs ON GLLog.GLID = GLs.ID INNER JOIN Users ON GLLog.ChangedBy = Users.ID ORDER BY GLLog.id DESC")
242	%>
243	<TABLE dir=rtl align=center width=600>
244	<TR >
245		<TD colspan=6 align=center>
246			<BR><H3>����� ������� ���� ��</H3><BR>
247		</TD>
248	</TR>
249	<TR bgcolor="eeeeee" >
250		<TD><SMALL> # </SMALL></TD>
251		<TD><SMALL> ���� </SMALL></TD>
252		<TD><SMALL> ��� ����</SMALL></TD>
253		<TD><SMALL> ����� ����� </SMALL></TD>
254		<TD><SMALL> ����� ����� </SMALL></TD>
255		<TD><SMALL> ����� </SMALL></TD>
256	</TR>
257	<%
258	tmpCounter=0
259	Do while not RSSX.eof
260		tmpCounter = tmpCounter + 1
261		if tmpCounter mod 2 = 1 then
262			tmpColor="#FFFFFF"
263			tmpColor2="#FFFFBB"
264		Else
265			tmpColor="#DDDDDD"
266			tmpColor2="#EEEEBB"
267		End if 
268		%>
269		<TR bgcolor="<%=tmpColor%>" >
270			<TD><%=RSSX("id")%> </TD>
271			<TD><%=RSSX("Name")%> </TD>
272			<TD><%=RSSX("FiscalYear")%></TD>
273			<TD><span dir=ltr><%=RSSX("ChangedDate")%></span></TD>
274			<TD><%=RSSX("RealName")%></TD>
275			<TD><%=RSSX("Change")%></TD>
276			</TD>
277		</TR>
278		<%
279		RSSX.moveNext
280	Loop
281	%>
282	</TABLE><br>
283	<CENTER><INPUT TYPE="button" value="�ѐ��"class="GenButton" onclick="window.location='AccountInfo.asp'"></CENTER><BR><BR>
284
285	<%
286	set RSSX = nothing
287
288'-----------------------------------------------------------------------------------------------------
289'---------------------------------------------------------------------- Select Another Default GL Form
290'-----------------------------------------------------------------------------------------------------
291elseif request("act")="select" or request("act")="" then
292%>
293<CENTER>
294<BR><BR><BR>
295<% call showAlert ("<B>����: </B><BR>����� ���� �� ��� ��� �� ��� ����<BR> ���� �� ��� �� ��� �� ���� ������ �� <BR> �� ������� ��� ����",CONST_MSG_INFORM)%>
296<BR><BR>
297<% call showAlert ("����� ���� ��  �� ����� �������� �� �����<BR> �� ����� ����� ��� ����� ���� ����.",CONST_MSG_INFORM)%>
298<BR><BR>
299<% call showAlert ("�������� �� �� ����� ��� ������� ���� �� ���� <BR>���� ��� �� ���� �� ��� ��� ����� <BR>������� ��� ����.",CONST_MSG_INFORM)%>
300<BR><BR>
301<%
302set RSSX=Conn.Execute ("SELECT * from GLs where IsClosed=0 order by id desc")
303set RS_UsersList=Conn.Execute ("SELECT Users.ID, Users.RealName, GLs.Name FROM Users LEFT OUTER JOIN UserDefaults ON Users.ID = UserDefaults.[User] LEFT OUTER JOIN GLs ON UserDefaults.WorkingGL = GLs.ID ORDER BY Users.RealName")
304%>
305<TABLE>
306<TR>
307	<TD colspan=3>
308		<FORM METHOD=POST ACTION="manageGL.asp?act=change">
309		<B>����� ���� �� �� </B><SELECT NAME="OpenGL" style="font-family:tahoma" class="GenButton">
310		<%
311		Do while not RSSX.eof
312		%>
313		<option <%	if cint(OpenGL)=cint(RSSX("ID")) then 
314						response.write "selected"
315						GLname = RSSX("name")
316					end if %> value="<%=RSSX("ID")%>" ><%=RSSX("name")%> - ��� ���� <%=RSSX("FiscalYear")%></option>
317		<% 
318		RSSX.moveNext
319		Loop
320		RSSX.close
321		%>
322		</SELECT><BR><BR>
323	</TD>
324</TR>
325<%
326Do while not RS_UsersList.eof
327%>
328<TR>
329	<TD>
330		<% if RS_UsersList("id")="0" then%>
331			<INPUT TYPE="radio" NAME="forWhom" value="0"><FONT COLOR="red"><B>���� �� ��� ��� �����</B></FONT><br>
332		<% else 
333			UsersRealName = RS_UsersList("RealName")
334			UsersID = RS_UsersList("id")
335			%>
336			<INPUT TYPE="radio" NAME="forWhom" <% if UsersID=session("id") then %>checked <% end if %> value="<%=UsersID%>">��� ���� ����� <%=UsersRealName%>
337		<% end if %>
338	</TD>
339	<TD align=left width=120>
340		<%=RS_UsersList("Name")%> &nbsp;&nbsp;
341	</TD>
342	<TD align=right>
343		<% if not RS_UsersList("id")="0" and not isNull(RS_UsersList("Name")) then%>
344			<A HREF="?act=delRow&rowNo=<%=RS_UsersList("id")%>" title="�� ��� ��� ��� ��� ����� ��� �� ��� �� �� ���� �� ��� ��� ����� ������� ����� ���.">[���]</A>
345		<% else %>
346		 &nbsp;
347		<% end if %>
348	</TD>
349</TR>
350<% 
351RS_UsersList.moveNext
352Loop
353RS_UsersList.close
354%>
355</TABLE><BR><BR>
356<INPUT TYPE="submit" value="�����"class="GenButton">
357<INPUT TYPE="button" value="������"class="GenButton" onclick="window.location='AccountInfo.asp'">
358</FORM>
359</CENTER>
360
361<%
362end if
363%>
364<!--#include file="tah.asp" -->
365
366<%
367	'------------- Related Triggers ----------------
368	'
369	'	CREATE TRIGGER [setDefaultGL] ON [dbo].[GLs] 
370	'	FOR INSERT, UPDATE
371	'	AS 
372	'	DECLARE 
373	'		@IsDefault binary,
374	'		@id int
375	'		SELECT 
376	'			@IsDefault = IsDefault, 
377	'			@id = [id]
378	'		FROM inserted 
379	'	if @IsDefault = 1
380	'	begin
381	'	UPDATE GLs SET 
382	'		IsDefault = 0
383	'	UPDATE GLs SET 
384	'		IsDefault = 1
385	'	WHERE ID = @id
386	'	end
387	'
388	'----------------------------------------------
389	'
390	'	CREATE TRIGGER Trig_GLLOGGER ON [dbo].[GLs] 
391	'	FOR INSERT, UPDATE
392	'	AS 
393	'	DECLARE 
394	'		@GLID int,
395	'		@LastChange nvarchar(100),
396	'		@LastChangedDate nvarchar(10),
397	'		@LastChangedBy int
398	'		SELECT 
399	'			@GLID=[ID], 
400	'			@LastChange = LastChange, 
401	'			@LastChangedDate = LastChangedDate, 
402	'			@LastChangedBy = LastChangedBy
403	'		FROM inserted
404	'	IF UPDATE (LastChange)
405	'	INSERT INTO GLLog (GLID, Change, ChangedDate, ChangedBy)
406	'			VALUES (@GLID, @LastChange, @LastChangedDate, @LastChangedBy)
407	'
408	'
409	'----------------------------------------------
410
411%>