/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. <%
  5. if 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. if notAllowed then
  26. response.redirect "top.asp?errMsg=" & Server.URLEncode(" ")
  27. end if
  28. if MemoID="" or not(isnumeric(MemoID)) then
  29. conn.close
  30. response.redirect "top.asp?errMsg=" & Server.URLEncode(" ")
  31. end if
  32. MemoID=clng(MemoID)
  33. mySQL="SELECT * FROM "& sys & "Memo WHERE (ID='"& MemoID & "')"
  34. Set RS1 = conn.Execute(mySQL)
  35. if RS1.eof then
  36. conn.close
  37. response.redirect "top.asp?errMsg=" & Server.URLEncode(" ")
  38. else
  39. voided= RS1("Voided")
  40. voidedDate= RS1("VoidedDate")
  41. Account= RS1("Account")
  42. isCredit= RS1("isCredit")
  43. Amount= RS1("Amount")
  44. memoType= RS1("Type")
  45. if voided then
  46. '-- Memo already voided
  47. conn.close
  48. response.redirect "../"& sys & "/AccountReport.asp?act=showMemo&sys="& sys & "&memo="& MemoID & "&errMsg=" & Server.URLEncode(" <span dir='LTR'>"& voidedDate & "</span> ")
  49. elseif memoType=8 then
  50. '-- This memo is a part of a Compound Memo and cannot be voided
  51. conn.close
  52. response.redirect "../"& sys & "/AccountReport.asp?act=showMemo&sys="& sys & "&memo="& MemoID & "&errMsg=" & Server.URLEncode(" .<BR> .")
  53. end if
  54. end if
  55. voidDate = shamsiToday()
  56. ' ----
  57. ' Voiding Memo
  58. call voidMemo
  59. ' End of voiding memo
  60. ' ----
  61. message=""
  62. if memoType=7 then ' It's a TRANSFER memo --> the other side must also be voided.
  63. message="&msg=" & Server.URLEncode(" .<br><br>")
  64. firstMemoID = MemoID
  65. firstSYS = sys
  66. if isCredit then
  67. mySQL="SELECT FromItemType, FromItemLink FROM InterMemoRelation WHERE (ToItemType = '"& sys & "') AND (ToItemLink = '"& MemoID & "')"
  68. Set RS1=conn.Execute(mySQL)
  69. MemoID = RS1("FromItemLink")
  70. sys = RS1("FromItemType")
  71. else
  72. mySQL="SELECT ToItemType, ToItemLink FROM InterMemoRelation WHERE (FromItemType = '"& sys & "') AND (FromItemLink = '"& MemoID & "')"
  73. Set RS1=conn.Execute(mySQL)
  74. MemoID = RS1("ToItemLink")
  75. sys = RS1("ToItemType")
  76. end if
  77. RS1.close()
  78. select case sys
  79. case "AR":
  80. subSys=" "
  81. case "AP":
  82. subSys=" "
  83. case "AO":
  84. subSys=" "
  85. end select
  86. message= message & Server.URLEncode(" <a target='_blank' href='" & "../"& sys & "/AccountReport.asp?act=showMemo&sys="& sys & "&Memo="& MemoID &"'>"& MemoID &"</a> <b>"& subSys & "</b> .<br>")
  87. mySQL="SELECT * FROM "& sys & "Memo WHERE (ID='"& MemoID & "')"
  88. Set RS1 = conn.Execute(mySQL)
  89. if not RS1.eof then
  90. voided= RS1("Voided")
  91. voidedDate= RS1("VoidedDate")
  92. Account= RS1("Account")
  93. isCredit= RS1("isCredit")
  94. Amount= RS1("Amount")
  95. memoType= RS1("Type")
  96. RS1.close()
  97. if voided then
  98. conn.close
  99. response.redirect "../"& sys & "/AccountReport.asp?act=showMemo&sys="& sys & "&memo="& MemoID & "&errMsg=" & Server.URLEncode(" <span dir='LTR'>"& voidedDate & "</span> .")
  100. end if
  101. ' ----
  102. ' Voiding Related Memo
  103. call voidMemo
  104. ' End of voiding related memo
  105. ' ----
  106. message= message & Server.URLEncode("<br> .")
  107. else
  108. ' Other side Memo Not Found
  109. RS1.close()
  110. message= message & Server.URLEncode("<br><FONT COLOR='red'> .</FONT>")
  111. end if
  112. ' We should NOT delete the relation between VOIDED memos ... they are not DELETED, just VOIDED
  113. '
  114. ' if isCredit then
  115. ' mySQL="DELETE FROM InterMemoRelation WHERE (ToItemType = '"& sys & "') AND (ToItemLink = '"& MemoID & "')"
  116. ' conn.Execute(mySQL)
  117. ' else
  118. ' mySQL="DELETE FROM InterMemoRelation WHERE (FromItemType = '"& sys & "') AND (FromItemLink = '"& MemoID & "')"
  119. ' conn.Execute(mySQL)
  120. ' end if
  121. MemoID = firstMemoID
  122. sys = firstSYS
  123. end if
  124. response.redirect "../"& sys & "/AccountReport.asp?act=showMemo&sys="& sys & "&Memo="& MemoID & message
  125. end if
  126. sub voidMemo
  127. mySQL="UPDATE "& sys & "Memo SET Voided=1, VoidedDate=N'"& voidDate & "', VoidedBy='"& session("ID") & "' WHERE (ID='"& MemoID & "')"
  128. conn.Execute(mySQL)
  129. '**************************** Voiding A*Item of the MEMO ****************
  130. '*** Type = 3 means the Item is a Memo
  131. '***
  132. '********* Finding the Item of the Memo
  133. mySQL="SELECT ID FROM "& sys & "Items WHERE (Type = 3) AND (Link='"& MemoID & "')"
  134. Set RS1=conn.Execute(mySQL)
  135. voidedItem=RS1("ID")
  136. '********* Finding other Items related to this Item
  137. if isCredit then
  138. mySQL="SELECT ID AS RelationID, Debit"& sys & "Item, Amount FROM "& sys & "ItemsRelations WHERE (Credit"& sys & "Item = '"& voidedItem & "')"
  139. Set RS1=conn.Execute(mySQL)
  140. Do While not (RS1.eof)
  141. '********* Adding back the amount in the relation, to the debit Item ...
  142. conn.Execute("UPDATE "& sys & "Items SET RemainedAmount=RemainedAmount+ '"& RS1("Amount") & "', FullyApplied=0 WHERE (ID = '"& RS1("Debit"& sys & "Item") & "')")
  143. '********* Deleting the relation
  144. conn.Execute("DELETE FROM "& sys & "ItemsRelations WHERE ID='"& RS1("RelationID") & "'")
  145. RS1.movenext
  146. Loop
  147. else
  148. mySQL="SELECT ID AS RelationID, Credit"& sys & "Item, Amount FROM "& sys & "ItemsRelations WHERE (Debit"& sys & "Item = '"& voidedItem & "')"
  149. Set RS1=conn.Execute(mySQL)
  150. Do While not (RS1.eof)
  151. '********* Adding back the amount in the relation, to the credit Item ...
  152. conn.Execute("UPDATE "& sys & "Items SET RemainedAmount=RemainedAmount+ '"& RS1("Amount") & "', FullyApplied=0 WHERE (ID = '"& RS1("Credit"& sys & "Item") & "')")
  153. '********* Deleting the relation
  154. conn.Execute("DELETE FROM "& sys & "ItemsRelations WHERE ID='"& RS1("RelationID") & "'")
  155. RS1.movenext
  156. Loop
  157. end if
  158. '********* Voiding A*Item
  159. conn.Execute("UPDATE "& sys & "Items SET RemainedAmount=0, FullyApplied=0, Voided=1 WHERE (ID = '"& voidedItem & "')")
  160. '**************************************************************
  161. '* Affecting Account's A* Balance
  162. '**************************************************************
  163. if isCredit then
  164. mySQL="UPDATE Accounts SET "& sys & "Balance = "& sys & "Balance - '"& Amount & "' WHERE (ID='"& Account & "')"
  165. else
  166. mySQL="UPDATE Accounts SET "& sys & "Balance = "& sys & "Balance + '"& Amount & "' WHERE (ID='"& Account & "')"
  167. end if
  168. conn.Execute(mySQL)
  169. '***
  170. '***---------------- End of Voiding A*Item of Memo ----------------
  171. ' ----
  172. end sub
  173. conn.Close
  174. %>