PageRenderTime 22ms CodeModel.GetById 8ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 1ms

/beta/AO/MemoVoid.asp

http://github.com/khaneh/Orders
ASP | 209 lines | 138 code | 35 blank | 36 comment | 15 complexity | e5d79f60b76e41e7cd10a25a8d44514a MD5 | raw file
  1<%@LANGUAGE="VBSCRIPT" CODEPAGE="1256"%>
  2<!--#include file="../config.asp" -->
  3<!--#include File="../include_farsiDateHandling.asp"-->
  4<%
  5if request("act")="VoidMemo" then
  6	Sys=request("Sys")
  7	MemoID=request("Memo")
  8	notAllowed=true
  9	if sys="AR" then
 10		if Auth(6 , "H") then ' Has the Priviledge to VOID the AR_MEMO
 11			notAllowed=false
 12		end if
 13	elseif sys="AP" then
 14		if Auth(7 , 8 ) then ' Has the Priviledge to VOID the AP_MEMO
 15			notAllowed=false
 16		end if
 17	elseif sys="AO" then
 18		if Auth("B" , 6 ) then ' Has the Priviledge to VOID the AO_MEMO
 19			notAllowed=false
 20		end if
 21	else
 22		conn.close 
 23		response.redirect "top.asp?errMsg=" & Server.URLEncode("��� �� ��� ��������")
 24	end if
 25
 26	if notAllowed then
 27		response.redirect "top.asp?errMsg=" & Server.URLEncode("��� ���� �� ����� ������� ������")
 28	end if
 29
 30	if MemoID="" or not(isnumeric(MemoID)) then
 31		conn.close 
 32		response.redirect "top.asp?errMsg=" & Server.URLEncode("��� �� ����� �������")
 33	end if
 34	MemoID=clng(MemoID)
 35
 36	mySQL="SELECT * FROM "& sys & "Memo WHERE (ID='"& MemoID & "')"
 37	Set RS1 = conn.Execute(mySQL)
 38	if RS1.eof then
 39		conn.close 
 40		response.redirect "top.asp?errMsg=" & Server.URLEncode("���� ��� ")
 41	else
 42		voided=			RS1("Voided")
 43		voidedDate=		RS1("VoidedDate")
 44		Account=		RS1("Account")
 45		isCredit=		RS1("isCredit")
 46		Amount=			RS1("Amount")
 47		memoType=		RS1("Type")
 48
 49		if voided then
 50		'-- Memo already voided
 51			conn.close 
 52			response.redirect "../"& sys & "/AccountReport.asp?act=showMemo&sys="& sys & "&memo="& MemoID & "&errMsg=" & Server.URLEncode("��� ������� ����  �� ����� <span dir='LTR'>"& voidedDate & "</span> ���� ��� ���")
 53		elseif memoType=8 then
 54		'-- This memo is a part of a Compound Memo and cannot be voided
 55			conn.close 
 56			response.redirect "../"& sys & "/AccountReport.asp?act=showMemo&sys="& sys & "&memo="& MemoID & "&errMsg=" & Server.URLEncode("��� ������� ���� �� �� ��� ���� ���.<BR> ���� ����� �� �� ��� ������ ��� ���� ������ ����.")
 57		end if
 58
 59	end if
 60
 61	voidDate = shamsiToday()
 62
 63	' ----
 64	' Voiding Memo
 65
 66	call voidMemo
 67
 68	' End of voiding memo
 69	' ----
 70
 71	message=""
 72
 73  if memoType=7 then ' It's a TRANSFER memo --> the other side must also be voided.
 74	
 75	message="&msg=" & Server.URLEncode("��� �� ������� ������ ��� �� ���� ��.<br><br>")
 76
 77	firstMemoID	= MemoID
 78	firstSYS	= sys
 79	if isCredit then
 80		mySQL="SELECT FromItemType, FromItemLink FROM InterMemoRelation WHERE (ToItemType = '"& sys & "') AND (ToItemLink = '"& MemoID & "')"
 81		Set RS1=conn.Execute(mySQL)
 82		MemoID	= RS1("FromItemLink")
 83		sys		= RS1("FromItemType")
 84	else
 85		mySQL="SELECT ToItemType, ToItemLink FROM InterMemoRelation WHERE (FromItemType = '"& sys & "') AND (FromItemLink = '"& MemoID & "')"
 86		Set RS1=conn.Execute(mySQL)
 87		MemoID	= RS1("ToItemLink")
 88		sys		= RS1("ToItemType")
 89	end if
 90	RS1.close()
 91	
 92	select case sys
 93	case "AR":
 94		subSys=" �� ����� ���� "
 95	case "AP":
 96		subSys=" �� ����� ���� "
 97	case "AO":
 98		subSys=" �� ���� "
 99	end select 
100	message= message & Server.URLEncode("�� ���� ����� ��� �������� ������� <a target='_blank' href='" & "../"& sys & "/AccountReport.asp?act=showMemo&sys="& sys & "&Memo="& MemoID &"'>"& MemoID &"</a> <b>"& subSys & "</b>��� ���� ���� �� ��.<br>")
101
102	mySQL="SELECT * FROM "& sys & "Memo WHERE (ID='"& MemoID & "')"
103	Set RS1 = conn.Execute(mySQL)
104	if not RS1.eof then
105		voided=			RS1("Voided")
106		voidedDate=		RS1("VoidedDate")
107		Account=		RS1("Account")
108		isCredit=		RS1("isCredit")
109		Amount=			RS1("Amount")
110		memoType=		RS1("Type")
111		RS1.close()
112
113		if voided then
114			conn.close 
115			response.redirect "../"& sys & "/AccountReport.asp?act=showMemo&sys="& sys & "&memo="& MemoID & "&errMsg=" & Server.URLEncode("��� ������� ����  �� ����� <span dir='LTR'>"& voidedDate & "</span> ���� ��� ���.")
116		end if
117
118		' ----
119		' Voiding Related Memo
120
121		call voidMemo
122
123		' End of voiding related memo
124		' ----
125
126		message= message & Server.URLEncode("<br>������� ��� �� ���� ��.")
127	else
128		' Other side Memo Not Found
129		RS1.close()
130		message= message & Server.URLEncode("<br><FONT COLOR='red'>��� ������� ������ ���� ���.</FONT>")
131	end if
132
133'   We should NOT delete the relation between VOIDED memos ... they are not DELETED, just VOIDED
134'	
135'	if isCredit then
136'		mySQL="DELETE FROM InterMemoRelation WHERE (ToItemType = '"& sys & "') AND (ToItemLink = '"& MemoID & "')"
137'		conn.Execute(mySQL)
138'	else
139'		mySQL="DELETE FROM InterMemoRelation WHERE (FromItemType = '"& sys & "') AND (FromItemLink = '"& MemoID & "')"
140'		conn.Execute(mySQL)
141'	end if
142
143	MemoID =	firstMemoID
144	sys  =		firstSYS
145  end if
146
147	response.redirect "../"& sys & "/AccountReport.asp?act=showMemo&sys="& sys & "&Memo="& MemoID & message
148end if
149
150sub voidMemo
151
152	mySQL="UPDATE "& sys & "Memo SET Voided=1, VoidedDate=N'"& voidDate & "', VoidedBy='"& session("ID") & "' WHERE (ID='"& MemoID & "')"
153	conn.Execute(mySQL)
154
155  '**************************** Voiding A*Item of the MEMO ****************
156  '*** Type = 3 means the Item is a Memo
157  '***
158	'*********  Finding the Item of the Memo
159	mySQL="SELECT ID FROM "& sys & "Items WHERE (Type = 3) AND (Link='"& MemoID & "')"
160	Set RS1=conn.Execute(mySQL)
161	voidedItem=RS1("ID")
162	'*********  Finding other Items related to this Item
163	if isCredit then
164		mySQL="SELECT ID AS RelationID, Debit"& sys & "Item, Amount FROM "& sys & "ItemsRelations WHERE (Credit"& sys & "Item = '"& voidedItem & "')"
165		Set RS1=conn.Execute(mySQL)
166		Do While not (RS1.eof)
167			'*********  Adding back the amount in the relation, to the debit Item ...
168			conn.Execute("UPDATE "& sys & "Items SET RemainedAmount=RemainedAmount+ '"& RS1("Amount") & "', FullyApplied=0 WHERE (ID = '"& RS1("Debit"& sys & "Item") & "')")
169
170			'*********  Deleting the relation
171			conn.Execute("DELETE FROM "& sys & "ItemsRelations WHERE ID='"& RS1("RelationID") & "'")
172			
173			RS1.movenext
174		Loop
175	else
176		mySQL="SELECT ID AS RelationID, Credit"& sys & "Item, Amount FROM "& sys & "ItemsRelations WHERE (Debit"& sys & "Item = '"& voidedItem & "')"
177		Set RS1=conn.Execute(mySQL)
178		Do While not (RS1.eof)
179			'*********  Adding back the amount in the relation, to the credit Item ...
180			conn.Execute("UPDATE "& sys & "Items SET RemainedAmount=RemainedAmount+ '"& RS1("Amount") & "', FullyApplied=0 WHERE (ID = '"& RS1("Credit"& sys & "Item") & "')")
181
182			'*********  Deleting the relation
183			conn.Execute("DELETE FROM "& sys & "ItemsRelations WHERE ID='"& RS1("RelationID") & "'")
184			
185			RS1.movenext
186		Loop
187	end if
188
189	'*********  Voiding A*Item 
190	conn.Execute("UPDATE "& sys & "Items SET RemainedAmount=0, FullyApplied=0, Voided=1 WHERE (ID = '"& voidedItem & "')")
191
192	'**************************************************************
193	'*				Affecting Account's A* Balance  
194	'**************************************************************
195	if isCredit then
196		mySQL="UPDATE Accounts SET "& sys & "Balance = "& sys & "Balance - '"& Amount & "' WHERE (ID='"& Account & "')"
197	else
198		mySQL="UPDATE Accounts SET "& sys & "Balance = "& sys & "Balance + '"& Amount & "' WHERE (ID='"& Account & "')"
199	end if
200
201	conn.Execute(mySQL)
202	
203	'***
204	'***---------------- End of  Voiding A*Item of Memo ----------------
205
206	' ----
207end sub
208conn.Close
209%>