/beta/accounting/SubsysDocsEdit.asp

http://github.com/khaneh/Orders · ASP · 464 lines · 398 code · 39 blank · 27 comment · 49 complexity · 666343d78509ef4351e8855671680b63 MD5 · raw file

  1. <%@LANGUAGE="VBSCRIPT" CODEPAGE="1256"%><%
  2. 'Accounting (8)
  3. PageTitle= " "
  4. SubmenuItem=9
  5. if not Auth(8 , "C") then NotAllowdToViewThisPage() ' this is the same as viewing subsystem memos
  6. %>
  7. <!--#include file="top.asp" -->
  8. <!--#include File="../include_farsiDateHandling.asp"-->
  9. <!--#include File="../include_JS_InputMasks.asp"-->
  10. <STYLE>
  11. .GLTable {font-family:tahoma; background-color:#330099;border:solid 1px Black;}
  12. .GLTable TR {background-color:#F0F0F0;}
  13. .HeaderTD {font-size:12pt;font-weight:bold;background-color:#FFCC66;}
  14. .RowsTD {font-size:9pt;padding-bottom:10px;}
  15. .GeneralInput {width:70px; font-family:tahoma; font-size:8pt; border:1pt solid gray; background:transparent; direction: LTR; }
  16. </STYLE>
  17. <%
  18. if request("act")="submitEdit" then
  19. id=request("id")
  20. if id="" or not isnumeric(id) then
  21. call showAlert (" .",CONST_MSG_ERROR)
  22. Conn.close
  23. response.end
  24. end if
  25. '----- Check GL is closed
  26. if (session("IsClosed")="True") then
  27. Conn.close
  28. response.redirect "?errMsg=" & Server.URLEncode("! .")
  29. end if
  30. '----
  31. mySQL="SELECT * FROM GLDocs WHERE id="& id & " and (GLDocs.GL = "& OpenGL & ")"
  32. set RS1=conn.execute(mySQL)
  33. errMessage=""
  34. if RS1.eof then
  35. errMessage="! ."
  36. else
  37. GLMemoNo=RS1("GLDocID")
  38. GLMemoDate=RS1("GLDocDate")
  39. if RS1("IsTemporary") then
  40. IsTemporary=1
  41. else
  42. IsTemporary=0
  43. end if
  44. if not RS1("BySubSystem") then
  45. errMessage=" ."
  46. elseif RS1("deleted") OR RS1("IsRemoved") then
  47. errMessage=" ."
  48. elseif RS1("IsFinalized") then
  49. errMessage=" ."
  50. elseif RS1("IsChecked") then
  51. errMessage=" ."
  52. end if
  53. end if
  54. if errMessage<>"" then
  55. response.write "<br><br>"
  56. call showAlert (errMessage,CONST_MSG_ERROR)
  57. Conn.close
  58. response.end
  59. end if
  60. RS1.close
  61. GLDoc = id
  62. creationDate = shamsiToday()
  63. totalRows = request.form("GLDocRows").count
  64. '--- Checking For Errors:
  65. if totalRows > 0 then
  66. mySQL="SELECT DISTINCT LEFT(Description, 5) AS Des, SYS, Link FROM GLRows INNER JOIN GLDocs ON GLRows.GLDoc = GLDocs.ID WHERE (GLRows.ID IN ("
  67. for i=1 to totalRows - 1
  68. mySQL = mySQL & request.form("GLDocRows")(i) & ", "
  69. next
  70. mySQL = mySQL & request.form("GLDocRows")(i) & ")) AND (GLDocs.ID = '"& GLDoc & "') AND (GLDocs.GL = '"& OpenGL & "') AND (GLRows.Deleted = 0)"
  71. else
  72. response.write "<br> ..."
  73. response.end
  74. end if
  75. set RS1=conn.execute(mySQL)
  76. errorFound = false
  77. Do While not RS1.eof AND not errorFound
  78. if RS1("Des")<>"" then
  79. mySQL2="SELECT Voided, GL_Update FROM "& trim(RS1("SYS")) & "Items WHERE (ID = "& RS1("Link") & ")"
  80. set RS2=conn.execute(mySQL2)
  81. if RS2("Voided") AND not RS2("GL_Update") then
  82. errSYS=RS1("SYS")
  83. errLink=RS1("Link")
  84. errorFound = true
  85. RS2.close
  86. exit do
  87. end if
  88. RS2.close
  89. end if
  90. RS1.moveNext
  91. Loop
  92. RS1.close
  93. if errorFound then
  94. response.write "<br>Error Found!:<br>"
  95. response.write "<br>SYS:" & errSYS
  96. response.write "<br>Link:" & errLink
  97. response.end
  98. end if
  99. '--- End of checking for errors.
  100. '---
  101. '--- Actual Deleting
  102. set RS1=conn.execute(mySQL)
  103. Do While not RS1.eof
  104. tempDes = RS1("Des")
  105. tempSYS = trim(RS1("SYS"))
  106. tempLink= RS1("Link")
  107. if tempDes="" then
  108. ' This is a reverse memo
  109. mySQL2="SELECT * FROM GLRows WHERE (SYS = '"& tempSYS & "') AND (Link = "& tempLink & ") AND (deleted = 0) AND (Description NOT Like N'%')"
  110. set RS2=conn.execute(mySQL2)
  111. if RS2.eof then
  112. ' No Direct Memo, No need to Update GL
  113. tempGL_Update=0
  114. else
  115. ' Has A Direct Memo. Must be added to GL later
  116. tempGL_Update=1
  117. end if
  118. else
  119. ' This is a direct memo
  120. mySQL2="SELECT Voided, GL_Update FROM "& tempSYS & "Items WHERE (ID = "& tempLink & ")"
  121. set RS2=conn.execute(mySQL2)
  122. if RS2("Voided") then
  123. ' Item is voided. No need to Update GL
  124. tempGL_Update=0
  125. else
  126. ' Item is not voided. Must be added to GL later
  127. tempGL_Update=1
  128. end if
  129. RS2.close
  130. end if
  131. mySQL2="UPDATE "& tempSYS & "Items SET GL_Update="& tempGL_Update & " WHERE (ID = "& tempLink & ")"
  132. Conn.Execute (mySQL2)
  133. mySQL2="UPDATE GLRows SET deleted = 1 WHERE (GLDoc='"& GLDoc & "') AND (deleted = 0) AND (SYS = '"& tempSYS & "') AND (Link = "& tempLink & ")"
  134. Conn.Execute (mySQL2)
  135. RS1.moveNext
  136. Loop
  137. RS1.close
  138. '--- End of actual deleting
  139. '---
  140. mySQL = "SELECT * FROM GLRows WHERE (GLDoc='"& GLDoc & "') AND (deleted = 0)"
  141. set RS1 = Conn.execute(mySQL)
  142. if RS1.eof then
  143. RS1.close
  144. mySQL="SELECT MIN(GLDocID) AS MinGLDocID FROM GLDocs WHERE (GL = "& OpenGL & ")"
  145. set RS1=conn.execute(mySQL)
  146. RemovedGLDocID = clng(RS1("MinGLDocID")) - 1
  147. RS1.close
  148. Conn.Execute("UPDATE GLDocs SET IsRemoved=1, RemovedDate=N'"& shamsiToday() & "', RemovedBy='"& session("ID") & "', OldGLDocID=GLDocID, GLDocID="& RemovedGLDocID & " WHERE (ID = "& GLDoc & ")")
  149. response.redirect "GLMemoDocShow.asp?id=" & GLDoc & "&msg=" & Server.URLEncode(" .")
  150. else
  151. RS1.close
  152. '---- Creating a new GLDoc
  153. mySQL="INSERT INTO GLDocs (GL, GLDocID, GLDocDate, CreatedDate, createdBy, BySubSystem, IsTemporary) VALUES ("& openGL & " , "& GLMemoNo & ", N'"& GLMemoDate & "' , N'"& creationDate & "', "& session("ID") & ", 1, "& IsTemporary & ");SELECT @@Identity AS NewGLDoc"
  154. set RS1 = Conn.execute(mySQL).NextRecordSet
  155. NewGLDoc = RS1("NewGLDoc")
  156. RS1.close
  157. '----
  158. '---- Inserting new GLRows
  159. mySQL="INSERT INTO GLRows ( GLDoc, GLAccount, Tafsil, Amount, Description, Ref1, Ref2, SYS, Link, IsCredit, deleted) SELECT '"& NewGLDoc & "' AS GLDoc, GLAccount, Tafsil, Amount, Description, Ref1, Ref2, SYS, Link, IsCredit, deleted FROM GLRows WHERE (GLDoc = "& GLDoc & ") AND (Deleted=0) "
  160. conn.Execute(mySQL)
  161. '---- Marking old GLDoc and its remaining GLRows as DELETED
  162. conn.Execute("UPDATE GLRows SET deleted = 1 WHERE (GLDoc = "& GLDoc & ")")
  163. conn.Execute("UPDATE GLDocs SET deleted = 1 WHERE (ID = "& GLDoc & ")")
  164. '----
  165. response.redirect "GLMemoDocShow.asp?id=" & NewGLDoc & "&msg=" & Server.URLEncode(" .")
  166. end if
  167. '----
  168. '-----------------------------------------------------------------------------------------------------
  169. '--------------------------------------------------------------------------------------- Show a GL Doc
  170. '-----------------------------------------------------------------------------------------------------
  171. elseif request("act")="show" then
  172. id=request("id")
  173. if id="" or not isnumeric(id) then
  174. call showAlert (" .",CONST_MSG_ERROR)
  175. Conn.close
  176. response.end
  177. end if
  178. mySQL="SELECT * FROM GLDocs WHERE id="& id & " and (GLDocs.GL = "& OpenGL & ")"
  179. set RS1=conn.execute(mySQL)
  180. errMessage=""
  181. if RS1.eof then
  182. errMessage="! ."
  183. else
  184. GLMemoNo=RS1("GLDocID")
  185. GLMemoDate=RS1("GLDocDate")
  186. if RS1("IsTemporary") then
  187. IsTemporary=1
  188. else
  189. IsTemporary=0
  190. end if
  191. if not RS1("BySubSystem") then
  192. errMessage=" ."
  193. elseif RS1("deleted") OR RS1("IsRemoved") then
  194. errMessage=" ."
  195. elseif RS1("IsFinalized") then
  196. errMessage=" ."
  197. elseif RS1("IsChecked") then
  198. errMessage=" ."
  199. end if
  200. end if
  201. if errMessage<>"" then
  202. response.write "<br><br>"
  203. call showAlert (errMessage,CONST_MSG_ERROR)
  204. Conn.close
  205. response.end
  206. end if
  207. RS1.close
  208. mySQL="SELECT GLDocs.GLDocID, GLDocs.ID, GLDocs.GLDocDate, GLDocs.CreatedBy, GLRows.ID AS RowID, GLRows.GLAccount, GLRows.Tafsil, GLRows.Amount, GLRows.Description, GLRows.SYS, GLRows.Link, GLRows.IsCredit, GLAccounts.Name FROM GLDocs INNER JOIN GLRows ON GLDocs.ID = GLRows.GLDoc INNER JOIN GLAccounts ON GLRows.GLAccount = GLAccounts.ID WHERE (GLDocs.id="& id & ") AND (GLRows.deleted = 0) AND (GLDocs.GL = "& OpenGL & ") AND (GLAccounts.GL = "& OpenGL & ") ORDER BY GLRows.ID"
  209. set RS1=conn.execute(mySQL)
  210. GLDocID = RS1("GLDocID")
  211. Creator = RS1("CreatedBy")
  212. %>
  213. <SCRIPT LANGUAGE="JavaScript">
  214. <!--
  215. var selectedRowsBalance=0;
  216. function selectRow(srcRow){
  217. check = srcRow.getElementsByTagName("INPUT")[0];
  218. sysLinkName=srcRow.getElementsByTagName("INPUT")[1].name;
  219. if (check.checked){
  220. if (sysLinkName!='SysLink'){
  221. for (j=0;j<document.getElementsByName(sysLinkName).length;j++){
  222. tempRow = document.getElementsByName(sysLinkName)[j].parentNode.parentNode
  223. tempRow.getElementsByTagName("INPUT")[0].checked=true
  224. selectedRowsBalance = selectedRowsBalance + parseInt(tempRow.getElementsByTagName("INPUT")[2].value);
  225. for(i=0; i<tempRow.getElementsByTagName("TD").length; i++){
  226. tempRow.getElementsByTagName("TD")[i].setAttribute("bgColor","yellow")
  227. }
  228. }
  229. }else{
  230. selectedRowsBalance = selectedRowsBalance + parseInt(srcRow.getElementsByTagName("INPUT")[2].value);
  231. for(i=0; i<srcRow.getElementsByTagName("TD").length; i++){
  232. srcRow.getElementsByTagName("TD")[i].setAttribute("bgColor","yellow")
  233. }
  234. }
  235. }else{
  236. if (sysLinkName!='SysLink'){
  237. for (j=0;j<document.getElementsByName(sysLinkName).length;j++){
  238. tempRow = document.getElementsByName(sysLinkName)[j].parentNode.parentNode
  239. tempRow.getElementsByTagName("INPUT")[0].checked=false
  240. selectedRowsBalance = selectedRowsBalance - parseInt(tempRow.getElementsByTagName("INPUT")[2].value);
  241. for(i=0; i<tempRow.getElementsByTagName("TD").length; i++){
  242. tempRow.getElementsByTagName("TD")[i].setAttribute("bgColor","")
  243. }
  244. }
  245. }else{
  246. selectedRowsBalance = selectedRowsBalance - parseInt(srcRow.getElementsByTagName("INPUT")[2].value);
  247. for(i=0; i<srcRow.getElementsByTagName("TD").length; i++){
  248. srcRow.getElementsByTagName("TD")[i].setAttribute("bgColor","")
  249. }
  250. }
  251. }
  252. }
  253. function selectAll(src){
  254. if(src.checked){
  255. checks = document.getElementsByName("GLDocRows");
  256. selectedRowsBalance = 0;
  257. for(j=0; j< checks.length; j++){
  258. tempRow=checks[j].parentNode.parentNode
  259. tempRow.getElementsByTagName("INPUT")[0].checked=true;
  260. selectedRowsBalance = selectedRowsBalance + parseInt(tempRow.getElementsByTagName("INPUT")[2].value);
  261. for(i=0; i<tempRow.getElementsByTagName("TD").length; i++){
  262. tempRow.getElementsByTagName("TD")[i].setAttribute("bgColor","yellow")
  263. }
  264. }
  265. }
  266. else{
  267. selectedRowsBalance = 0;
  268. for(j=0; j< checks.length; j++){
  269. tempRow=checks[j].parentNode.parentNode
  270. tempRow.getElementsByTagName("INPUT")[0].checked=false;
  271. for(i=0; i<tempRow.getElementsByTagName("TD").length; i++){
  272. tempRow.getElementsByTagName("TD")[i].setAttribute("bgColor","")
  273. }
  274. }
  275. }
  276. }
  277. function checkAndSubmit(action){
  278. if (action=='Edit'){
  279. if (selectedRowsBalance != 0){
  280. alert(" !");
  281. return false;
  282. }
  283. }else if (action=='Delete'){
  284. if (confirm(' Ͽ')){
  285. checkBox=document.getElementsByName('checkAll')[0]
  286. checkBox.checked=true;
  287. selectAll(checkBox);
  288. checkAndSubmit('Edit');
  289. }
  290. return false;
  291. }
  292. document.all.act.value="submit"+action;
  293. document.forms[0].submit();
  294. }
  295. //-->
  296. </SCRIPT>
  297. <br><br>
  298. <FORM METHOD=POST ACTION="?">
  299. <INPUT TYPE="hidden" name="id" value="<%=id%>">
  300. <TABLE Border="0" width='90%' align=center Cellspacing="1" Cellpadding="5" class="GLTable">
  301. <TBODY Id="RowsTable">
  302. <tr style='height:70px;background-color:#FFFFDD;'>
  303. <td class='HeaderTD' colspan='7' align='center'> <br></td>
  304. </tr>
  305. <tr style='height:1px;background-color:black;'>
  306. <td colspan=7 ></td>
  307. </tr>
  308. <tr style='height:30px;background-color:#EEEEEE;'>
  309. <td colspan='3'> <%=GLDocID%></td>
  310. <td colspan='2'> : <%=RS1("id")%></td>
  311. <td colspan='2'> : <span dir=ltr><%= RS1("GLDocDate")%></span></td>
  312. </tr>
  313. <tr style='height:1px;background-color:black;'>
  314. <td colspan=7 ></td>
  315. </tr>
  316. <tr style='height:40px;background-color:#DDDDDD;'>
  317. <td style="width:26; border-right:none;"> # </td>
  318. <td style="width:50; "></td>
  319. <td style="width:50; "></td>
  320. <td style="width:170;"> </td>
  321. <td style="width:500;"></td>
  322. <td style="width:80;"></td>
  323. <td style="width:80;"></td>
  324. </tr>
  325. <%
  326. Do while not RS1.eof
  327. i = i + 1
  328. GLAccount = RS1("GLAccount")
  329. accTitle = RS1("name")
  330. theDescription = RS1("Description")
  331. Amount = RS1("Amount")
  332. IsCredit = RS1("IsCredit")
  333. Tafsil = RS1("Tafsil")
  334. credit = ""
  335. debit = ""
  336. if IsCredit then
  337. credit = Separate(Amount)
  338. totalCredit = totalCredit + cdbl(Amount)
  339. else
  340. debit = Separate(Amount)
  341. totalDebit = totalDebit + cdbl(Amount)
  342. Amount = -1 * cdbl(Amount)
  343. end if
  344. %>
  345. <tr>
  346. <td class='RowsTD' align='center' style='font-size:9pt;color:gray;'><%=i%><br>
  347. <INPUT TYPE="checkbox" NAME="GLDocRows" Value='<%=RS1("RowID")%>' onclick='selectRow(this.parentNode.parentNode);'>
  348. <INPUT TYPE="hidden" Name='SysLink<%=RS1("Sys")&RS1("Link")%>'>
  349. <INPUT TYPE="hidden" Name='Amount' value='<%=Amount%>'>
  350. </td>
  351. <td class='RowsTD'><%=Tafsil%></td>
  352. <td class='RowsTD'><%=GLAccount%></td>
  353. <td class='RowsTD'><%=accTitle%></td>
  354. <td class='RowsTD'><%=theDescription%></td>
  355. <td class='RowsTD'><%=debit%></td>
  356. <td class='RowsTD'><%=credit%></td>
  357. </tr>
  358. <%
  359. RS1.movenext
  360. loop
  361. %>
  362. <tr style='height:1px;background-color:black;'>
  363. <td colspan=7 ></td>
  364. </tr>
  365. <tr style="height:50px;">
  366. <td class='RowsTD' colspan='2' style='font-size:7pt;'>
  367. <INPUT TYPE="checkbox" NAME='checkAll' onclick='selectAll(this);'>&nbsp; </td>
  368. <td class='RowsTD' colspan='3' align='left'><B> :</B></td>
  369. <td class='RowsTD' style="width:80;"><%=Separate(totalDebit)%></td>
  370. <td class='RowsTD' style="width:80;"><%=Separate(totalCredit)%></td>
  371. </tr>
  372. <tr style='height:1px;background-color:black;'>
  373. <td colspan=7 ></td>
  374. </tr>
  375. <tr style="height:50px;">
  376. <td class='HeaderTD' colspan='7' align='center'>
  377. <INPUT TYPE="hidden" name="act" value="" >
  378. <TABLE width='100%'>
  379. <TR>
  380. <TD class='HeaderTD'><INPUT TYPE="button" value=" " class="GenButton" onclick="checkAndSubmit('Edit');"></TD>
  381. <TD class='HeaderTD' align='left'><INPUT TYPE="button" value="" class="GenButton" onclick="window.location='GLMemoDocShow.asp?id=<%=id%>';"></TD>
  382. <TD class='HeaderTD' align='left'><INPUT TYPE="button" value=" ( )" class="GenButton" Style='border-color:red' onclick="checkAndSubmit('Delete');"></TD>
  383. </TR>
  384. </TABLE>
  385. </td>
  386. </tr>
  387. </TBODY>
  388. </TABLE>
  389. </FORM>
  390. <BR>
  391. <%
  392. if request("SysLink")<>"" then
  393. %>
  394. <SCRIPT LANGUAGE="JavaScript">
  395. <!--
  396. sysLinkName='SysLink<%=request("SysLink")%>';
  397. a=document.getElementsByName(sysLinkName)[0].parentNode.getElementsByTagName("INPUT")[0];
  398. a.checked=true;
  399. selectRow(a.parentNode.parentNode);
  400. a.focus();
  401. //-->
  402. </SCRIPT>
  403. <%
  404. end if
  405. '-----------------------------------------------------------------------------------------------------
  406. '--------------------------------------------------------------------------------------- Show a GL Doc
  407. '-----------------------------------------------------------------------------------------------------
  408. elseif request("act")="find" then
  409. sys=left(request("link"),2)
  410. lnk=right(request("link"),len(request("link"))-2)
  411. sys=sqlSafe(sys)
  412. lnk=clng(lnk)
  413. mySQL="SELECT DISTINCT GLDoc FROM EffectiveGLRows WHERE (GL = "& OpenGL & ") AND (Link = " & lnk & ") AND (SYS = '" & sys & "')"
  414. set RS1=conn.execute(mySQL)
  415. if RS1.eof then
  416. conn.close
  417. response.redirect "?errMsg="&Server.URLEncode("! .")
  418. else
  419. GLDoc= RS1("GLDoc")
  420. end if
  421. RS1.close
  422. conn.close
  423. response.redirect "SubsysDocsEdit.asp?act=show&id=" & GLDoc & "&SysLink=" & sys & lnk
  424. end if %>
  425. <!--#include file="tah.asp" -->