/beta/cashReg/void.asp

http://github.com/khaneh/Orders · ASP · 291 lines · 172 code · 37 blank · 82 comment · 21 complexity · a87e38deddeb4690aa07003dc81dd617 MD5 · raw file

  1. <%@LANGUAGE="VBSCRIPT" CODEPAGE="1256"%>
  2. <!--#include file="../config.asp" -->
  3. <!--#include File="../include_farsiDateHandling.asp"-->
  4. <%
  5. 'CashRegister (9)
  6. act = request("act")
  7. if act = "voidReceipt" then
  8. ON ERROR RESUME NEXT
  9. ReceiptID = clng(request("Receipt"))
  10. if Err.Number<>0 then
  11. Err.clear
  12. conn.close
  13. response.redirect "top.asp?errMsg=" & Server.URLEncode(" .")
  14. end if
  15. ON ERROR GOTO 0
  16. '----------
  17. ' Findng Receipt
  18. '----------
  19. mySQL = "SELECT ISNULL(CashAmount, 0) AS CashAmount, ISNULL(ChequeAmount, 0) AS ChequeAmount, ChequeQtty, SYS, Voided FROM Receipts WHERE (ID = '"& ReceiptID & "')"
  20. Set RS1= conn.Execute(mySQL)
  21. if RS1.eof then
  22. conn.close
  23. response.redirect "top.asp?errmsg=" & Server.URLEncode("! <br> .")
  24. else
  25. VoidDate= ShamsiToday()
  26. Voided= RS1("Voided")
  27. CashAmount= cdbl(RS1("CashAmount"))
  28. ChequeAmount= cdbl(RS1("ChequeAmount"))
  29. ChequeQtty= RS1("ChequeQtty")
  30. SYS= RS1("SYS")
  31. RS1.close
  32. if Voided then
  33. conn.close
  34. response.redirect "../"& SYS& "/AccountReport.asp?act=showReceipt&receipt="& ReceiptID & "&errmsg=" & Server.URLEncode("! <br><br> .")
  35. end if
  36. ' mySQL="SELECT CashRegisterLines.ID AS CashRegLine, ISNULL(Receipts.CashAmount, 0) AS CashAmount, ISNULL(Receipts.ChequeAmount, 0) AS ChequeAmount, Receipts.ChequeQtty, Receipts.SYS, CashRegisterLines.CashReg, CashRegisterLines.Voided, CashRegisters.IsOpen, CashRegisters.Cashier FROM CashRegisters INNER JOIN CashRegisterLines ON CashRegisters.ID = CashRegisterLines.CashReg INNER JOIN Receipts ON CashRegisterLines.Link = Receipts.ID WHERE (CashRegisterLines.Type = 1) AND (CashRegisterLines.Link = '"& ReceiptID & "')"
  37. ' Changed By kid 821228
  38. '----------
  39. ' Finding the CashRegister Line for this Receipt
  40. ' (Type=1 means Receipt in CashRegisterLineTypes)
  41. '----------
  42. mySQL = "SELECT CashRegisterLines.ID AS CashRegLine, CashRegisterLines.isA, CashRegisterLines.CashReg, CashRegisters.IsOpen, CashRegisterLines.Voided, CashRegisters.Cashier FROM CashRegisters INNER JOIN CashRegisterLines ON CashRegisters.ID = CashRegisterLines.CashReg WHERE (CashRegisterLines.Type = 1) AND (CashRegisterLines.Link = '"& ReceiptID & "')"
  43. Set RS1= conn.Execute(mySQL)
  44. if NOT RS1.eof then
  45. ' There is a CashRegister Line for this Receipt
  46. HasCashRegLine = true
  47. CashRegLine = RS1("CashRegLine")
  48. CashReg = RS1("CashReg")
  49. IsOpen = RS1("IsOpen")
  50. Cashier = RS1("Cashier")
  51. isA = RS1("isA")
  52. else
  53. ' There is NOT a CashRegister Line for this Receipt
  54. HasCashRegLine = false
  55. end if
  56. RS1.close
  57. '------------Check cash sitll open before void receipt
  58. if (not isOpen) and (HasCashRegLine) then
  59. conn.close
  60. response.redirect "top.asp?errmsg=" & Server.URLEncode(" !<br> ")
  61. end if
  62. if NOT ( Auth(9 , 7) OR (IsOpen AND Cashier=session("ID")) ) then
  63. ' Doesn't Have the Priviledge to VOID the RECEIPT/PAYMENT
  64. conn.close
  65. response.redirect "top.asp?errmsg=" & Server.URLEncode("!<br> .")
  66. end if
  67. '**************************** Voiding (AR/AP/AO)Item of Receipt ****************
  68. '***
  69. '********* Finding the (AR/AP/AO)Item of Receipt
  70. '*** Type = 2 means (AR/AP/AO)Item is a Receipt
  71. mySQL="SELECT ID, Account FROM "& SYS & "Items WHERE (Type=2) AND (Link = '"& ReceiptID & "')"
  72. Set RS1=conn.Execute(mySQL)
  73. ItemID = RS1("ID")
  74. Account = RS1("Account")
  75. '********* Finding other (AR/AP/AO)Items related to this Item
  76. mySQL="SELECT ID AS RelationID, Debit"& SYS & "Item, Amount FROM "& SYS & "ItemsRelations WHERE (Credit"& SYS & "Item = '"& ItemID & "')"
  77. Set RS1=conn.Execute(mySQL)
  78. do while not (RS1.eof)
  79. '********* Adding back the amount in the relation, to the debit (AR/AP/AO)Item ...
  80. conn.Execute("UPDATE "& SYS & "Items SET RemainedAmount=RemainedAmount+ '"& RS1("Amount") & "', FullyApplied=0 WHERE (ID = '"& RS1("Debit"& SYS & "Item") & "')")
  81. '********* Deleting the relation
  82. conn.Execute("DELETE FROM "& SYS & "ItemsRelations WHERE ID='"& RS1("RelationID") & "'")
  83. RS1.movenext
  84. loop
  85. '********* Voiding the (AR/AP/AO)Item
  86. conn.Execute("UPDATE "& SYS & "Items SET RemainedAmount=0, FullyApplied=0, Voided=1 WHERE (ID = '"& ItemID & "')")
  87. '**************************************************************
  88. '* Decreasing Account's (AR/AP/AO) Balance
  89. '* ('because we have removed a CREDIT Item )
  90. '**************************************************************
  91. mySQL="UPDATE Accounts SET "& SYS & "Balance = "& SYS & "Balance - '"& CashAmount + ChequeAmount & "' WHERE (ID ='"& Account & "')"
  92. conn.Execute(mySQL)
  93. '***
  94. '***---------------- End of Voiding (AR/AP/AO)Item ----------------
  95. ' #########################################################
  96. ' SET ALL RECEIVED CHEQUES STATUS
  97. ' TO RETURNED
  98. ' #########################################################
  99. ' Status = 4 means Returned
  100. mySQL="UPDATE ReceivedCheques SET LastStatus = 4 , LastUpdatedDate =N'"& VoidDate & "', LastUpdatedBy = '"& session("ID") & "' WHERE (Receipt = '"& ReceiptID & "')"
  101. conn.Execute(mySQL)
  102. ' #########################################################
  103. ' VOID the RECEIPT ...
  104. ' #########################################################
  105. mySQL="UPDATE Receipts SET Voided=1,VoidedBy='"& session("ID") & "',VoidedDate=N'"& VoidDate & "' WHERE (ID = '"& ReceiptID & "')"
  106. conn.Execute(mySQL)
  107. if HasCashRegLine then
  108. ' #########################################################
  109. ' VOID the CASH REG LINE ...
  110. ' #########################################################
  111. mySQL="UPDATE CashRegisterLines SET Voided = 1 WHERE (ID = '"& CashRegLine & "')"
  112. conn.Execute(mySQL)
  113. ' #########################################################
  114. ' CHANGING CASH REGISTER BALANCE
  115. ' (decreasing)
  116. ' #########################################################
  117. if isA then
  118. mySQL="UPDATE CashRegisters SET CashAmountA = CashAmountA - '"& CashAmount & "', ChequeAmount = ChequeAmount - '"& ChequeAmount & "', ChequeQtty = ChequeQtty - '"& ChequeQtty & "' WHERE (ID ='"& CashReg & "')"
  119. else
  120. mySQL="UPDATE CashRegisters SET CashAmountB = CashAmountB - '"& CashAmount & "', ChequeAmount = ChequeAmount - '"& ChequeAmount & "', ChequeQtty = ChequeQtty - '"& ChequeQtty & "' WHERE (ID ='"& CashReg & "')"
  121. end if
  122. conn.Execute(mySQL)
  123. end if
  124. end if
  125. conn.close
  126. if HasCashRegLine then
  127. response.redirect "CashRegReport.asp"
  128. else
  129. response.redirect "../"& SYS & "/AccountReport.asp?act=showReceipt&receipt=" & ReceiptID
  130. end if
  131. elseif act = "voidPayment" then
  132. ON ERROR RESUME NEXT
  133. PaymentID = clng(request("Payment"))
  134. if Err.Number<>0 then
  135. Err.clear
  136. conn.close
  137. response.redirect "top.asp?errMsg=" & Server.URLEncode(" .")
  138. end if
  139. ON ERROR GOTO 0
  140. '----------
  141. ' Findng Payment
  142. '----------
  143. mySQL = "SELECT ISNULL(CashAmount, 0) AS CashAmount, ISNULL(ChequeAmount, 0) AS ChequeAmount, SYS, Voided FROM Payments WHERE (ID = '"& PaymentID & "')"
  144. Set RS1= conn.Execute(mySQL)
  145. if RS1.eof then
  146. conn.close
  147. response.redirect "top.asp?errmsg=" & Server.URLEncode("! <br> .")
  148. else
  149. VoidDate= ShamsiToday()
  150. Voided= RS1("Voided")
  151. CashAmount= cdbl(RS1("CashAmount"))
  152. ChequeAmount= cdbl(RS1("ChequeAmount"))
  153. SYS= RS1("SYS")
  154. RS1.close
  155. if Voided then
  156. conn.close
  157. response.redirect "../"& SYS& "/AccountReport.asp?act=showPayment&payment="& PaymentID & "&errmsg=" & Server.URLEncode("! <br><br> .")
  158. end if
  159. '----------
  160. ' Finding the CashRegister Line for this Payment
  161. ' (Type=2 means Payment in CashRegisterLineTypes)
  162. '----------
  163. mySQL = "SELECT CashRegisterLines.ID AS CashRegLine,CashRegisterLines.isA, CashRegisterLines.CashReg, CashRegisters.IsOpen, CashRegisterLines.Voided, CashRegisters.Cashier FROM CashRegisters INNER JOIN CashRegisterLines ON CashRegisters.ID = CashRegisterLines.CashReg WHERE (CashRegisterLines.Type = 2) AND (CashRegisterLines.Link = '"& PaymentID & "')"
  164. Set RS1= conn.Execute(mySQL)
  165. isOpen=false
  166. if NOT RS1.eof then
  167. ' There is a CashRegister Line for this Payment
  168. HasCashRegLine = true
  169. CashRegLine = RS1("CashRegLine")
  170. CashReg = RS1("CashReg")
  171. IsOpen = RS1("IsOpen")
  172. Cashier = RS1("Cashier")
  173. isA = RS1("isA")
  174. else
  175. ' There is NOT a CashRegister Line for this Payment
  176. HasCashRegLine = false
  177. end if
  178. RS1.close
  179. '------------Check cash sitll open before void payment
  180. 'response.write mySQL
  181. 'response.end
  182. if (not isOpen) and (HasCashRegLine) then
  183. conn.close
  184. response.redirect "top.asp?errmsg=" & Server.URLEncode(" !<br> ")
  185. end if
  186. if NOT ( Auth(9 , 7) OR (IsOpen AND Cashier=session("ID")) ) then
  187. ' Doesn't Have the Priviledge to VOID the RECEIPT/PAYMENT
  188. conn.close
  189. response.redirect "top.asp?errmsg=" & Server.URLEncode("!<br> .")
  190. end if
  191. '**************************** Voiding (AR/AP/AO)Item of Payment ****************
  192. '***
  193. '********* Finding the (AR/AP/AO)Item of Payment
  194. '*** Type = 5 means (AR/AP/AO)Item is a Payment
  195. mySQL="SELECT ID, Account FROM "& SYS & "Items WHERE (Type=5) AND (Link = '"& PaymentID & "')"
  196. Set RS1=conn.Execute(mySQL)
  197. ItemID = RS1("ID")
  198. Account = RS1("Account")
  199. '********* Finding other (AR/AP/AO)Items related to this Item
  200. mySQL="SELECT ID AS RelationID, Credit"& SYS & "Item, Amount FROM "& SYS & "ItemsRelations WHERE (Debit"& SYS & "Item = '"& ItemID & "')"
  201. Set RS1=conn.Execute(mySQL)
  202. do while not (RS1.eof)
  203. '********* Adding back the amount in the relation, to the debit (AR/AP/AO)Item ...
  204. conn.Execute("UPDATE "& SYS & "Items SET RemainedAmount=RemainedAmount+ '"& RS1("Amount") & "', FullyApplied=0 WHERE (ID = '"& RS1("Credit"& SYS & "Item") & "')")
  205. '********* Deleting the relation
  206. conn.Execute("DELETE FROM "& SYS & "ItemsRelations WHERE ID='"& RS1("RelationID") & "'")
  207. RS1.movenext
  208. loop
  209. '****************** Voiding the (AR/AP/AO)Item *****************
  210. '***
  211. conn.Execute("UPDATE "& SYS & "Items SET RemainedAmount=0, FullyApplied=0, Voided=1 WHERE (ID = '"& ItemID & "')")
  212. '**************************************************************
  213. '* Increasing Account's (AR/AP/AO) Balance
  214. '* ('because we have removed a DEBIT Item )
  215. '**************************************************************
  216. mySQL="UPDATE Accounts SET "& SYS & "Balance = "& SYS & "Balance + '"& CashAmount + ChequeAmount & "' WHERE (ID ='"& Account & "')"
  217. conn.Execute(mySQL)
  218. '***
  219. '***---------------- End of Voiding (AR/AP/AO)Item ----------------
  220. ' #########################################################
  221. ' VOID the PAYMENT ...
  222. ' #########################################################
  223. mySQL="UPDATE Payments SET Voided=1,VoidedBy='"& session("ID") & "',VoidedDate=N'"& VoidDate & "' WHERE (ID = '"& PaymentID & "')"
  224. conn.Execute(mySQL)
  225. if HasCashRegLine then
  226. ' #########################################################
  227. ' VOID the CASH REG LINE ...
  228. ' #########################################################
  229. mySQL="UPDATE CashRegisterLines SET Voided=1 WHERE (ID = '"& CashRegLine & "')"
  230. conn.Execute(mySQL)
  231. ' #########################################################
  232. ' CHANGING CASH REGISTER BALANCE
  233. ' (increasing)
  234. ' #########################################################
  235. if isA then
  236. mySQL="UPDATE CashRegisters SET CashAmountA = CashAmountA + "& CashAmount & " WHERE (ID ="& CashReg & ")"
  237. else
  238. mySQL="UPDATE CashRegisters SET CashAmountB = CashAmountB + "& CashAmount & " WHERE (ID ="& CashReg & ")"
  239. end if
  240. 'mySQL="UPDATE CashRegisters SET CashAmount = CashAmount + '"& CashAmount & "' WHERE (ID ='"& CashReg & "')"
  241. conn.Execute(mySQL)
  242. end if
  243. end if
  244. conn.close
  245. if HasCashRegLine then
  246. response.redirect "CashRegReport.asp"
  247. else
  248. response.redirect "../"& SYS & "/AccountReport.asp?act=showPayment&payment=" & PaymentID
  249. end if
  250. else
  251. conn.close
  252. response.redirect "top.asp?errMsg=" & Server.URLEncode(".")
  253. end if
  254. %>