/beta/AP/voucherEdit.asp

http://github.com/khaneh/Orders · ASP · 489 lines · 390 code · 54 blank · 45 comment · 36 complexity · f6565c504c77732682513f7d58494225 MD5 · raw file

  1. <%@LANGUAGE="VBSCRIPT" CODEPAGE="1256"%><%
  2. 'AP (7)
  3. PageTitle= " "
  4. SubmenuItem=1
  5. ' ATTENTION: This is the permission for VERIFY not EDIT
  6. if not Auth(7 , 2) then NotAllowdToViewThisPage()
  7. %>
  8. <!--#include file="top.asp" -->
  9. <!--#include File="../include_farsiDateHandling.asp"-->
  10. <!--#include File="../include_JS_InputMasks.asp"-->
  11. <%
  12. if request("act")="editVoucher" and isnumeric(request("VoucherID")) then
  13. VoucherID=clng(request("VoucherID"))
  14. mySQL = "SELECT * FROM Vouchers WHERE (ID="& VoucherID & ")"
  15. Set RS1=Conn.execute(mySQL)
  16. if RS1.eof then
  17. conn.close
  18. response.redirect "?errMsg=" & Server.URLEncode(" .")
  19. else
  20. VendorID= RS1("VendorID")
  21. Title= RS1("Title")
  22. CreationDate= RS1("CreationDate")
  23. CreationTime= RS1("CreationTime")
  24. SavedFileName= RS1("SavedFileName")
  25. Comment= RS1("Comment")
  26. TotalPrice= RS1("TotalPrice")
  27. Verified= RS1("Verified")
  28. Paid= RS1("Paid")
  29. EffectiveDate= RS1("EffectiveDate")
  30. number = RS1("Number")
  31. totalVat = RS1("TotalVat")
  32. end if
  33. RS1.close
  34. if Verified then
  35. conn.close
  36. response.redirect "AccountReport.asp?act=showVoucher&voucher=" & VoucherID & "&errMsg=" & Server.URLEncode(" .<br> .")
  37. end if
  38. %>
  39. <input type="hidden" Name='tmpDlgArg' value=''>
  40. <input type="hidden" Name='tmpDlgTxt' value=''>
  41. <SCRIPT LANGUAGE="JavaScript">
  42. <!--
  43. function selectVendor(button){
  44. document.all.tmpDlgArg.value="#"
  45. document.all.tmpDlgTxt.value=" :"
  46. window.showModalDialog('../dialog_GenInput.asp',document.all.tmpDlgTxt,'dialogHeight:200px; dialogWidth:440px; dialogTop:; dialogLeft:; edge:None; center:Yes; help:No; resizable:No; status:No;');
  47. if (document.all.tmpDlgTxt.value !="") {
  48. window.showModalDialog('../AP/dialog_SelectAccount.asp?act=select&search='+escape(document.all.tmpDlgTxt.value), document.all.tmpDlgArg, 'dialogWidth:780px; dialogHeight:500px; dialogTop:; dialogLeft:; edge:Raised; center:Yes; help:No; resizable:Yes; status:No;');
  49. if (document.all.tmpDlgArg.value!="#"){
  50. Arguments=document.all.tmpDlgArg.value.split("#")
  51. button.parentNode.getElementsByTagName("input")[0].value=Arguments[0];
  52. button.parentNode.getElementsByTagName("input")[1].innerText=Arguments[1]+"["+Arguments[0]+"]";
  53. }
  54. }
  55. }
  56. //-->
  57. </SCRIPT>
  58. <BR><BR>
  59. <FORM METHOD=POST ACTION="?act=submitEdit">
  60. <TABLE align=center>
  61. <TR height=30>
  62. <TD width=100 align=left></td>
  63. <TD width=320>
  64. <% set RSV=Conn.Execute ("SELECT * FROM Accounts where ID = " & VendorID)
  65. if RSV.eof then
  66. response.redirect "voucherInput.asp?act=search"
  67. end if
  68. %>
  69. <INPUT TYPE="hidden" NAME="VendorID" value="<%=VendorID%>">
  70. <INPUT TYPE="text" readonly size=50 NAME="vendorName" value="<%=RSV("AccountTitle")%>" style="height:20;border: 1 solid black;">
  71. <INPUT TYPE="Button" value=""style="width:40;height:20;border: 1 solid black;" onClick="selectVendor(this);">
  72. <%
  73. RSV.close
  74. %>
  75. </TD>
  76. <TD width=150>
  77. &nbsp; <INPUT TYPE="text" size=10 NAME="EffectiveDate" style="direction:LTR; text-align:right" onKeyPress="return maskDate(this);" onblur="acceptDate(this)" maxlength="10" value="<%=EffectiveDate%>">
  78. </TD>
  79. </TR>
  80. <TR height=40>
  81. <TD align=left> </TD>
  82. <TD>
  83. <INPUT TYPE="text" size=60 NAME="title" style="direction:LTR; text-align:right" Value="<%=Title%>">
  84. </TD>
  85. <TD>
  86. &nbsp; :
  87. <%=VoucherID%>
  88. <INPUT TYPE="hidden" NAME="VoucherID" value="<%=VoucherID%>">
  89. </TD>
  90. </TR>
  91. <TR>
  92. <TD align='left'> ǘ </TD>
  93. <TD><input type='text' size='14' name='Number' value='<%=Number%>'></TD>
  94. </TR>
  95. <TR>
  96. <TD align=left VALIGN=TOP> </TD>
  97. <TD colspan=2 VALIGN=TOP>
  98. <%
  99. if VendorID="-1" then
  100. response.write "<hr><br><br>"
  101. else
  102. set RSS=Conn.Execute ("SELECT * FROM purchaseOrders WHERE (Status <> 'CANCEL' and HasVoucher = 0 and Vendor_ID="& VendorID& ") order by OrdDate" )
  103. %>
  104. <TABLE dir=rtl style="border:2 solid #333399;">
  105. <TR bgcolor="eeeeee" >
  106. <TD></TD>
  107. <TD><SMALL></SMALL></TD>
  108. <TD><SMALL> </SMALL></TD>
  109. <TD><SMALL> ()</SMALL></TD>
  110. <TD><SMALL></SMALL></TD>
  111. <TD> </SMALL></TD>
  112. </TR>
  113. <TR bgcolor="#5555BB" height="2">
  114. <TD colspan=7></TD>
  115. </TR>
  116. <%
  117. tmpCounter=0
  118. Do while not RSS.eof
  119. tmpCounter = tmpCounter + 1
  120. if tmpCounter mod 2 = 1 then
  121. tmpColor="#FFFFFF"
  122. tmpColor2="#FFFFBB"
  123. Else
  124. tmpColor="#DDDDDD"
  125. tmpColor2="#EEEEBB"
  126. End if
  127. %>
  128. <TR bgcolor="<%=tmpColor%>" >
  129. <TD><INPUT TYPE="hidden" name=color1 value="<%=tmpColor%>"><INPUT TYPE="hidden" name=color2 value="<%=tmpColor2%>"><INPUT TYPE="checkbox" onclick="setPrice(this)" name="pcheck" id="<%=tmpCounter-1%>" value="<%=RSS("id")%>" ><!checked></TD>
  130. <TD><INPUT TYPE="hidden" name="purchaseOrderID" value="0"><A HREF="../purchase/outServiceTrace.asp?od=<%=RSS("id")%>"><%=RSS("id")%></A></TD>
  131. <TD><INPUT TYPE="text" NAME="TypeName" style="border:none; background: transparent" size=40 value="<%=RSS("TypeName")%>"></TD>
  132. <TD><INPUT TYPE="text" NAME="price" style="border:none; background: transparent " onblur="setPrice(this)" onKeyPress="return maskNumber(this);" size=8 value="<%=Separate(RSS("price"))%>"></TD>
  133. <TD><INPUT TYPE="text" NAME="qtty" style="border:none; background: transparent " onKeyPress="return maskNumber(this);" size=3 value="<%=RSS("qtty")%>"></TD>
  134. <TD align=left><span dir=ltr><%=RSS("OrdDate")%></span></TD>
  135. </TR>
  136. <%
  137. RSS.moveNext
  138. Loop
  139. set RS1=Conn.Execute ("SELECT VoucherLines.*, PurchaseOrders.OrdDate FROM VoucherLines INNER JOIN PurchaseOrders ON VoucherLines.RelatedPurchaseOrderID = PurchaseOrders.ID WHERE (Voucher_ID = "& VoucherID & ")" )
  140. '--- Already Selected Orders
  141. totalprice=0
  142. Do while not RS1.eof
  143. totalprice = totalprice + cdbl(RS1("price"))
  144. tmpCounter = tmpCounter + 1
  145. if tmpCounter mod 2 = 1 then
  146. tmpColor="#FFFFFF"
  147. tmpColor2="#FFFFBB"
  148. Else
  149. tmpColor="#DDDDDD"
  150. tmpColor2="#EEEEBB"
  151. End if
  152. RelatedPurchaseOrderID = RS1("RelatedPurchaseOrderID")
  153. %>
  154. <TR bgcolor="<%=tmpColor2%>" >
  155. <TD><INPUT TYPE="hidden" name=color1 value="<%=tmpColor%>"><INPUT TYPE="hidden" name=color2 value="<%=tmpColor2%>"><INPUT TYPE="checkbox" onclick="setPrice(this)" name="pcheck" id="<%=tmpCounter-1%>" value="<%=RelatedPurchaseOrderID%>" checked></TD>
  156. <TD><INPUT TYPE="hidden" name="purchaseOrderID" value="<%=RelatedPurchaseOrderID%>"><A HREF="../purchase/outServiceTrace.asp?od=<%=RelatedPurchaseOrderID%>"><%=RelatedPurchaseOrderID%></A></TD>
  157. <TD><INPUT TYPE="text" NAME="TypeName" style="border:none; background: transparent" size=40 value="<%=RS1("LineTitle")%>"></TD>
  158. <TD><INPUT TYPE="text" NAME="price" style="border:none; background: transparent " onblur="setPrice(this)" onKeyPress="return maskNumber(this);" size=8 value="<%=Separate(RS1("price"))%>"></TD>
  159. <TD><INPUT TYPE="text" NAME="qtty" style="border:none; background: transparent " onKeyPress="return maskNumber(this);" size=3 value="<%=RS1("qtty")%>"></TD>
  160. <TD align=left><span dir=ltr><%=RS1("OrdDate")%></span></TD>
  161. </TR>
  162. <%
  163. RS1.moveNext
  164. Loop
  165. '---
  166. %>
  167. <TR bgcolor="#5555BB" height="2">
  168. <TD colspan=7></TD>
  169. </TR>
  170. <TR bgcolor="#eeeeee" height="2">
  171. <TD colspan='3' align='left'> : </TD>
  172. <TD colspan=4><INPUT style="border:none; background:transparent;" TYPE="text" NAME="totalVat" size=16 value="<%=totalVat%>" onchange='setPrice(this)'> </td>
  173. </TR>
  174. <TR bgcolor="#eeeeee" height="2">
  175. <TD colspan=3 align=left> </TD>
  176. <TD colspan=3><INPUT style="border:none; background:transparent;" TYPE="text" NAME="totalPrice" readonly size=16 value="<%=Separate(cdbl(totalPrice) + cdbl(totalVat))%>"> </td>
  177. </TR>
  178. </TABLE><br>
  179. <%
  180. end if
  181. %>
  182. </TD>
  183. </TR>
  184. <TR disabled>
  185. <TD align=left VALIGN=TOP> </TD>
  186. <TD colspan=2 VALIGN=TOP>
  187. <INPUT TYPE="Text" size=62 NAME="ImageFile" Value="<%=SavedFileName%>"><BR><BR>
  188. </TD>
  189. </TR>
  190. <TR>
  191. <TD align=left VALIGN=TOP></TD>
  192. <TD colspan=2 VALIGN=TOP>
  193. <TEXTAREA NAME="comment" ROWS="7" COLS="48"><%=Comment%></TEXTAREA>
  194. </TD>
  195. </TR>
  196. <TR>
  197. <TD colspan=3 align=center VALIGN=TOP>
  198. <br>
  199. <INPUT class=inputBut TYPE="submit" Name="Submit" Value=" " style="width:125px;" <%if VendorID="-1" then response.write " disabled " %>>
  200. </TD>
  201. </TR>
  202. </TABLE>
  203. </FORM>
  204. <SCRIPT LANGUAGE="JavaScript">
  205. <!--
  206. function setPrice(obj)
  207. {
  208. a= obj.type
  209. if (a=="text")
  210. obj.value=val2txt(txt2val(obj.value))
  211. else
  212. {
  213. ii=parseInt(obj.id)
  214. if(obj.checked)
  215. {
  216. document.getElementsByName("purchaseOrderID")[ii].value = obj.value
  217. theTR = obj.parentNode.parentNode
  218. theTR.setAttribute("bgColor",document.getElementsByName("color2")[ii].value)
  219. }
  220. else
  221. {
  222. document.getElementsByName("purchaseOrderID")[ii].value = 0
  223. theTR = obj.parentNode.parentNode
  224. theTR.setAttribute("bgColor",document.getElementsByName("color1")[ii].value)
  225. }
  226. }
  227. totalPrice = 0;
  228. checkBoxList = document.getElementsByName("pcheck")
  229. for(i=0;i<document.getElementsByName("price").length;i++) {
  230. if(checkBoxList[i].checked)
  231. totalPrice = totalPrice + txt2val(document.getElementsByName("price")[i].value);
  232. }
  233. totalPrice = totalPrice + txt2val(document.getElementsByName("totalVat")[0].value);
  234. document.all.totalPrice.value = val2txt(totalPrice) ;
  235. }
  236. //-->
  237. </SCRIPT>
  238. <%
  239. '-----------------------------------------------------------------------------------------------------
  240. '------------------------------------------------------------ Submit an Inventory Item request For Buy
  241. '-----------------------------------------------------------------------------------------------------
  242. elseif request("act") = "submitEdit" then
  243. VoucherID = clng(request.Form("VoucherID"))
  244. VendorID = clng(request.Form("VendorID"))
  245. Title = sqlSafe(request.Form("title"))
  246. Totalprice = text2value(request.Form("Totalprice"))
  247. Comment = sqlSafe(request.Form("Comment"))
  248. EffectiveDate = sqlSafe(request.Form("EffectiveDate"))
  249. number = sqlSafe(request.form("number"))
  250. totalVat = text2value(request.form("totalVat"))
  251. EditDate = shamsiToday()
  252. EditBy = session("id")
  253. if title = "" then title = "-"
  254. if comment = "" then comment = "-"
  255. '---- Checking wether EffectiveDate is valid in current open GL
  256. if (EffectiveDate < session("OpenGLStartDate")) OR (EffectiveDate > session("OpenGLEndDate")) then
  257. Conn.close
  258. response.redirect "?act=editVoucher&VoucherID="& VoucherID & "&errMsg=" & Server.URLEncode("!<br> .")
  259. end if
  260. '----
  261. '----- Check GL is closed
  262. if (session("IsClosed")="True") then
  263. Conn.close
  264. response.redirect "?errMsg=" & Server.URLEncode("! .")
  265. end if
  266. '----
  267. mySQL = "SELECT * FROM Accounts WHERE (ID="& VendorID & ")"
  268. Set RS1=Conn.execute(mySQL)
  269. if RS1.eof then
  270. conn.close
  271. response.redirect "?errMsg=" & Server.URLEncode(" .")
  272. end if
  273. RS1.close
  274. mySQL = "SELECT * FROM Vouchers WHERE (ID="& VoucherID & ")"
  275. Set RS1=Conn.execute(mySQL)
  276. if RS1.eof then
  277. conn.close
  278. response.redirect "?errMsg=" & Server.URLEncode(" .")
  279. else
  280. OldVendorID= RS1("VendorID")
  281. Verified= RS1("Verified")
  282. end if
  283. RS1.close
  284. if Verified then
  285. conn.close
  286. response.redirect "AccountReport.asp?act=showVoucher&voucher=" & VoucherID & "&errMsg=" & Server.URLEncode(" .<br> .")
  287. end if
  288. mysql = "UPDATE Vouchers SET VendorID='" & VendorID & "', Title=N'"& Title & "', TotalPrice='"& Totalprice & "', comment=N'"& Comment & "', LastEditDate=N'"& EditDate & "', LastEditBy='"& EditBy & "', EffectiveDate=N'"& EffectiveDate & "', Number=N'" & number &"', TotalVat=N'" & totalVat & "' WHERE (ID='"& VoucherID & "')"
  289. Conn.Execute (mysql)
  290. '===================================================
  291. ' Removing old voucherLines AND releasing Purchase Orders
  292. '===================================================
  293. mysql = "UPDATE PurchaseOrders SET HasVoucher=0 WHERE (ID IN (SELECT RelatedPurchaseOrderID FROM VoucherLines WHERE (Voucher_ID = "& VoucherID & ")))"
  294. Conn.Execute (mysql)
  295. mySQL = "DELETE FROM VoucherLines WHERE (Voucher_ID = "& VoucherID & ")"
  296. Conn.Execute (mysql)
  297. '===================================================
  298. ' Adding new voucherLines
  299. '===================================================
  300. for i=1 to request.Form("purchaseOrderID").count
  301. POrderID = request.Form("purchaseOrderID")(i)
  302. OTypeName = sqlSafe(request.Form("TypeName")(i))
  303. price = text2value(request.Form("price")(i))
  304. qtty = request.Form("qtty")(i)
  305. if POrderID <>"0" then
  306. mysql = "INSERT INTO VoucherLines(Voucher_ID, RelatedPurchaseOrderID, LineTitle, price, qtty) VALUES ("& VoucherID & ", "& POrderID & ",N'"& OTypeName & "',"& price & ","& qtty & ")"
  307. Conn.Execute (mysql)
  308. mysql = "UPDATE PurchaseOrders SET HasVoucher = 1 WHERE (ID = "& POrderID & ")"
  309. Conn.Execute (mysql)
  310. end if
  311. next
  312. '===================================================
  313. response.redirect "AccountReport.asp?act=showVoucher&voucher=" & VoucherID & "&msg=" &Server.URLEncode(" ")
  314. elseif request("act") = "delVoucher" and isnumeric(request("VoucherID")) then
  315. VoucherID=clng(request("VoucherID"))
  316. mySQL = "SELECT * FROM Vouchers WHERE (ID="& VoucherID & ")"
  317. Set RS1=Conn.execute(mySQL)
  318. if RS1.eof then
  319. conn.close
  320. response.redirect "?errMsg=" & Server.URLEncode(" .")
  321. else
  322. VendorID= RS1("VendorID")
  323. Title= RS1("Title")
  324. CreationDate= RS1("CreationDate")
  325. CreationTime= RS1("CreationTime")
  326. SavedFileName= RS1("SavedFileName")
  327. Comment= RS1("Comment")
  328. TotalPrice= RS1("TotalPrice")
  329. Verified= RS1("Verified")
  330. Paid= RS1("Paid")
  331. end if
  332. RS1.close
  333. if Verified then
  334. conn.close
  335. response.redirect "AccountReport.asp?act=showVoucher&voucher=" & VoucherID & "&errMsg=" & Server.URLEncode(" .<br> .")
  336. end if
  337. '===================================================
  338. ' Removing voucherLines AND releasing Purchase Orders
  339. '===================================================
  340. mysql = "UPDATE PurchaseOrders SET HasVoucher=0 WHERE (ID IN (SELECT RelatedPurchaseOrderID FROM VoucherLines WHERE (Voucher_ID = "& VoucherID & ")))"
  341. Conn.Execute (mysql)
  342. mySQL = "DELETE FROM VoucherLines WHERE (Voucher_ID = "& VoucherID & ")"
  343. Conn.Execute (mysql)
  344. '===================================================
  345. ' Deleting Voucher
  346. '===================================================
  347. 'mySQL = "DELETE FROM Vouchers WHERE (ID = "& VoucherID & ")"
  348. 'Changed By Kid 830929
  349. mySQL = "UPDATE Vouchers SET Voided=1 WHERE (ID = "& VoucherID & ")"
  350. Conn.Execute (mysql)
  351. '===================================================
  352. conn.close
  353. response.redirect "top.asp?msg=" & Server.URLEncode(" .")
  354. elseif request("act") = "voidVoucher" then
  355. if NOT Auth(7 , 9) then
  356. 'Doesn't have the Priviledge to APPROVE the Voucher
  357. response.write "<br>"
  358. call showAlert (" ",CONST_MSG_ERROR)
  359. response.end
  360. end if
  361. ON ERROR RESUME NEXT
  362. VoucherID = clng(request("VoucherID"))
  363. if Err.Number<>0 then
  364. Err.clear
  365. conn.close
  366. response.redirect "top.asp?errMsg=" & Server.URLEncode(" .")
  367. end if
  368. ON ERROR GOTO 0
  369. mySQL = "SELECT * FROM Vouchers WHERE (ID="& VoucherID & ")"
  370. Set RS1=Conn.execute(mySQL)
  371. if RS1.eof then
  372. conn.close
  373. response.redirect "?errMsg=" & Server.URLEncode(" .")
  374. else
  375. VendorID= RS1("VendorID")
  376. Title= RS1("Title")
  377. CreationDate= RS1("CreationDate")
  378. CreationTime= RS1("CreationTime")
  379. SavedFileName= RS1("SavedFileName")
  380. Comment= RS1("Comment")
  381. TotalPrice= RS1("TotalPrice")
  382. Verified= RS1("Verified")
  383. Paid= RS1("Paid")
  384. if RS1("Voided") then
  385. response.redirect "AccountReport.asp?act=showVoucher&voucher=" & VoucherID & "&errMsg=" & Server.URLEncode(" <span dir='LTR'>"& RS1("VoidedDate") & "</span> .")
  386. end if
  387. end if
  388. RS1.close
  389. if NOT Verified then
  390. conn.close
  391. response.redirect "AccountReport.asp?act=showVoucher&voucher=" & VoucherID & "&errMsg=" & Server.URLEncode(" .<br> .")
  392. end if
  393. '===================================================
  394. ' Voiding Voucher
  395. '===================================================
  396. mySQL="UPDATE Vouchers SET Voided=1, VoidedDate=N'"& shamsiToday() & "', VoidedBy='"& session("ID") & "' WHERE (ID = "& VoucherID & ")"
  397. conn.Execute(mySQL)
  398. '===================================================
  399. ' releasing Purchase Orders
  400. '===================================================
  401. mysql = "UPDATE PurchaseOrders SET HasVoucher=0 WHERE (ID IN (SELECT RelatedPurchaseOrderID FROM VoucherLines WHERE (Voucher_ID = "& VoucherID & ")))"
  402. Conn.Execute (mysql)
  403. '********************************** Voiding APItem of Voucher **************************
  404. '*** Type = 6 means APItem is a Voucher
  405. '***
  406. '********* Finding the APItem of Voucher
  407. mySQL="SELECT ID FROM APItems WHERE (Type = 6) AND (Link='"& VoucherID & "')"
  408. Set RS1=conn.Execute(mySQL)
  409. voidedAPItem=RS1("ID")
  410. '********* Finding other APItems related to this Item
  411. mySQL="SELECT ID AS RelationID, DebitAPItem, Amount FROM APItemsRelations WHERE (CreditAPItem = '"& voidedAPItem & "')"
  412. Set RS1=conn.Execute(mySQL)
  413. Do While not (RS1.eof)
  414. '********* Adding back the amount in the relation, to the debit APItem ...
  415. conn.Execute("UPDATE APItems SET RemainedAmount=RemainedAmount+ '"& RS1("Amount") & "', FullyApplied=0 WHERE (ID = '"& RS1("DebitAPItem") & "')")
  416. '********* Deleting the relation
  417. conn.Execute("DELETE FROM APItemsRelations WHERE ID='"& RS1("RelationID") & "'")
  418. RS1.movenext
  419. Loop
  420. RS1.close
  421. '********* Voiding APItem
  422. mySQL="UPDATE APItems SET RemainedAmount=0, FullyApplied=0, Voided=1 WHERE (ID = '"& voidedAPItem & "')"
  423. conn.Execute(mySQL)
  424. '********* Affecting Account's AP Balance
  425. mySQL="UPDATE Accounts SET APBalance = APBalance - "& TotalPrice & " WHERE (ID = "& VendorID & ")"
  426. conn.Execute(mySQL)
  427. '***
  428. '***----------------------------- End of Voiding APItem of Voucher ------------------------
  429. response.redirect "AccountReport.asp?act=showVoucher&voucher=" & VoucherID
  430. else
  431. response.write "<br><br>"
  432. call showAlert (" ! ",CONST_MSG_ERROR)
  433. end if
  434. %>
  435. <!--#include file="tah.asp" -->