/beta/AO/INCLUDE_ITEMSRELATION.ASP

http://github.com/khaneh/Orders · ASP · 640 lines · 520 code · 58 blank · 62 comment · 54 complexity · a5a5bc3db94af45411bde6c46e8ba5ce MD5 · raw file

  1. <%
  2. '---------------------------------------------
  3. '---------------------------------- Link2Trace
  4. '---------------------------------------------
  5. function Link2Trace(OrderNo)
  6. Link2Trace="<A HREF='../order/orderEdit.asp?e=n&radif="& OrderNo & "' target='_balnk'>"& OrderNo & "</A>"
  7. end function
  8. %>
  9. <style>
  10. .GenTable { font-family:tahoma; font-size: 9pt; border:0; padding:0; }
  11. .GenInput { font-family:tahoma; font-size: 9pt; border: none; text-align:right; direction: LTR;}
  12. .GenButton { font-family:tahoma; font-size: 9pt; border: 1px solid black; }
  13. .GrayOutLine .rowName {border: 1px solid gray; }
  14. .RelInput { font-family:tahoma; font-size: 8pt; border: none; text-align:right; direction: LTR; background: transparent;}
  15. </style>
  16. <%
  17. '-----------------------------------------------------------------------------------------------------
  18. '------------------------------------------------------------------------------------ 2 Select Account
  19. '-----------------------------------------------------------------------------------------------------
  20. if request("act")="submitsearch" then
  21. if request("CustomerNameSearchBox") <> "" then
  22. SA_TitleOrName=request("CustomerNameSearchBox")
  23. SA_Action="return true;"
  24. SA_SearchAgainURL="ItemsRelation.asp"
  25. SA_StepText="&nbsp; : "
  26. %>
  27. <FORM METHOD=POST ACTION="ItemsRelation.asp?act=relate">
  28. <!--#include File="../AR/include_SelectAccount.asp"-->
  29. </FORM>
  30. <%
  31. end if
  32. '-----------------------------------------------------------------------------------------------------
  33. '------------------------------------------------------------------------------------ Relates to Items
  34. '-----------------------------------------------------------------------------------------------------
  35. elseif request("act")="relate" then
  36. TopNo = "" '"TOP 20"
  37. dim typeNamesArray(6)
  38. typeNamesArray(1) = ""
  39. typeNamesArray(2) = ""
  40. typeNamesArray(3) = ""
  41. typeNamesArray(4) = "ѐ"
  42. typeNamesArray(5) = ""
  43. typeNamesArray(6) = " "
  44. if request("selectedCustomer") <> "" then
  45. Customer = request("selectedCustomer")
  46. sys = request("sys")
  47. if sys = "" then sys = "AR"
  48. if not fixSys = "-" then sys = fixSys
  49. %>
  50. <br>
  51. <CENTER>
  52. <% if fixSys = "-" then %>
  53. <FORM METHOD="POST" ACTION="ItemsRelation.asp?act=relate">
  54. <INPUT TYPE="hidden" name="selectedCustomer" value="<%=Customer%>">
  55. <INPUT TYPE="radio" NAME="sys" value="AR" <% if sys="AR" then %>checked <% end if %> onclick="submit()">
  56. <INPUT TYPE="radio" NAME="sys" value="AP" <% if sys="AP" then %>checked <% end if %> onclick="submit()">
  57. <INPUT TYPE="radio" NAME="sys" value="AO" <% if sys="AO" then %>checked <% end if %> onclick="submit()">
  58. </FORM>
  59. <% else
  60. response.write "<br><br>"
  61. sys = fixSys
  62. end if
  63. %>
  64. </CENTER>
  65. <FORM METHOD="POST" ACTION="ItemsRelation.asp?act=submitRelation">
  66. <INPUT TYPE="hidden" name="sys" value="<%=sys%>">
  67. <INPUT TYPE="hidden" name="Customer" value="<%=Customer%>">
  68. <TABLE class="GenTable" align="center" cellspacing="2" cellpadding="0" dir="RTL">
  69. <tbody id="MainTable">
  70. <%
  71. mySQL="SELECT * From Accounts WHERE (ID='"& Customer & "')"
  72. Set RS1 = conn.Execute(mySQL)
  73. if (RS1.eof) then
  74. call showAlert( " ." , CONST_MSG_ERROR)
  75. response.end
  76. else
  77. AccountTitle=RS1("AccountTitle")
  78. end if
  79. noJavaScript=false
  80. %>
  81. <tr bgcolor='#DDDDFF' height="50">
  82. <td align='center' colspan="3" style="font-weight:bold; font-size:9pt;border:1 solid black;"> <br><%=AccountTitle%>
  83. <input type="hidden" id="selectedCreditItem" value="">
  84. <input type="hidden" id="selectedDebitItem" value="">
  85. </td>
  86. </tr>
  87. <tr height="10">
  88. <td align='center' colspan="3"></td>
  89. </tr>
  90. <tr height="30">
  91. <td bgColor="#FFC0C0" style="border:1px solid black;" width="300">&nbsp;&nbsp;&nbsp; <b></b>
  92. <td width="50" rowspan="4" onclick="unselect();">&nbsp;</td>
  93. <td bgColor="#C0EEC0" style="border:1px solid black;" width="300">&nbsp;&nbsp;&nbsp; <b></b>
  94. </td>
  95. </tr>
  96. <tr>
  97. <td valign="top">
  98. <%
  99. mySQL="SELECT "& TopNo & " * From "& sys & "Items WHERE (Account='"& Customer & "' AND IsCredit=0 AND FullyApplied=0 AND Voided=0) ORDER BY EffectiveDate DESC, ID DESC"
  100. Set RS1 = conn.Execute(mySQL)
  101. if (RS1.eof) then
  102. call showAlert( " " , CONST_MSG_ALERT)
  103. noJavaScript=true
  104. else
  105. '******************** Debit Items
  106. %>
  107. <TABLE class="GenTable" align="center" cellspacing="5" cellpadding="2" dir="RTL" border="0" width="100%">
  108. <Tbody ID="DebitsTable" name='DebitsTable'>
  109. <% TotalDebit=0
  110. while Not (RS1.EOF)
  111. description = ""
  112. '================================== Type = 1
  113. '==================================
  114. if RS1("Type")=1 then
  115. sourceLink="<a style='text-decoration:none; color:green;' href='AccountReport.asp?act=showInvoice&invoice="& RS1("Link") & "' target='_blank'>" & " " & RS1("Link") & "</a>"
  116. '================================== Type = 2
  117. '==================================
  118. elseif RS1("Type")=2 then
  119. sourceLink="<a style='text-decoration:none; color:green;' href='AccountReport.asp?act=showReceipt&receipt="& RS1("Link") & "' target='_blank'>" & " " & RS1("Link") & "</a>"
  120. Set RST = conn.Execute("select * from ReceivedCash where Receipt=" & RS1("Link"))
  121. if RST.EOF then
  122. description = " ! "
  123. else
  124. description = RST("Description")
  125. end if
  126. '================================== Type = 3
  127. '==================================
  128. elseif RS1("Type")=3 then
  129. sourceLink="<a style='text-decoration:none; color:green;' href='AccountReport.asp?act=showMemo&sys="& sys & "&memo="& RS1("Link") & "' target='_blank'>" & " "& RS1("Link") & "</a>"
  130. Set RST = conn.Execute("select * from "& sys & "memo where ID=" & RS1("Link"))
  131. if RST.EOF then
  132. description = " ! "
  133. else
  134. description = RST("Description")
  135. end if
  136. '================================== Type = 4
  137. '==================================
  138. elseif RS1("Type")=4 then
  139. sourceLink="<a style='text-decoration:none; color:green;' href='AccountReport.asp?act=showInvoice&invoice="& RS1("Link") & "' target='_blank'>" & "ѐ " & RS1("Link") & "</a>"
  140. '================================== Type = 5
  141. '==================================
  142. elseif RS1("Type")=5 then
  143. sourceLink="<a style='text-decoration:none; color:green;' href='AccountReport.asp?act=showPayment&payment="& RS1("Link") & "' target='_blank'>" & " "& RS1("Link") & "</a>"
  144. mySQL="SELECT ISNULL(PaidCash.Description,'') AS CashDesc, PaidCheques.Description AS CheqDesc FROM PaidCheques RIGHT OUTER JOIN Payments ON PaidCheques.Payment = Payments.ID LEFT OUTER JOIN PaidCash ON Payments.ID = PaidCash.Payment WHERE (Payments.ID = "& RS1("Link") & ")"
  145. Set RST = conn.Execute(mySQL)
  146. if RST.EOF then
  147. description = " ! "
  148. else
  149. description = RST("CashDesc")
  150. Do Until RST.eof
  151. description = description + " " + RST("CheqDesc")
  152. RST.moveNext
  153. Loop
  154. end if
  155. RST.close
  156. '================================== Type = 6
  157. '==================================
  158. elseif RS1("Type")=6 then
  159. sourceLink="<a style='text-decoration:none; color:green;' href='AccountReport.asp?act=showVoucher&voucher="& RS1("Link") & "' target='_blank'>" & " "& RS1("Link") & "</a>"
  160. mySQL="SELECT Title FROM Vouchers WHERE (id = "& RS1("Link") & ")"
  161. Set RST = conn.Execute(mySQL)
  162. if RST.EOF then
  163. description = " ! "
  164. else
  165. description = replace(RST("Title"), "/", ".")
  166. end if
  167. RST.close
  168. '================================== Unknown
  169. '==================================
  170. else
  171. sourceLink="<a href='javascript:void(0);'>" & "" & "</a>"
  172. end if
  173. %> <tr class="unsel" bgcolor="white" height='70' valign='top' onclick="slctDdit(this)"><td class="GrayOutLine">
  174. <input type='hidden' name='DebitItems' value='<%=RS1("ID")%>'>
  175. <table class='GenTable' width="300" cellspacing='4' cellpadding='1'>
  176. <tr bgcolor='#FFDDDD'>
  177. <td class="rowName"><%=sourceLink%></td>
  178. <td class="GrayOutLine"><span dir='LTR'><%=RS1("EffectiveDate")%></span></td>
  179. <td class="GrayOutLine"> : <INPUT class='RelInput' readonly value='<%=Separate(RS1("AmountOriginal"))%>' size='10'></td>
  180. </tr>
  181. <tr>
  182. <td colspan="3">
  183. <a disabled><%=description%></a><BR>
  184. <span class="desc">
  185. <%
  186. mySQL2="SELECT * From "& sys & "ItemsRelations INNER JOIN "&sys & "Items ON "& sys & "ItemsRelations.Credit"& sys & "Item = "& sys & "Items.ID WHERE ("& sys & "ItemsRelations.Debit"& sys & "Item = "& RS1("id") & ") "
  187. Set RS2 = conn.Execute(mySQL2)
  188. while Not (RS2.EOF)
  189. response.write "<span disabled><input class='RelInput' size='10' readonly value=' " & separate(RS2("Amount")) & " '> " & " "& typeNamesArray(cint(RS2("Type"))) & " "& RS2("Link") & "</span><br>"
  190. RS2.movenext
  191. wend
  192. if RS1("voided") then response.write "<b> </b>"
  193. %>
  194. &nbsp;</span></td>
  195. </tr>
  196. <tr>
  197. <td class="GrayOutLine" colspan="2">: <span><INPUT class='RelInput' readonly Name='DebitRemained' value='<%=Separate(RS1("RemainedAmount"))%>' size='10'></span></td>
  198. <td align="center"><span class="isPass" style="visibility:hidden;color:red;"><b> </b></span></td>
  199. </tr>
  200. </table></td>
  201. </tr>
  202. <%
  203. TotalDebit = TotalDebit + cdbl(RS1("RemainedAmount"))
  204. RS1.movenext
  205. wend
  206. %>
  207. </Tbody>
  208. </TABLE>
  209. <%
  210. end if
  211. %>
  212. </td>
  213. <td valign="top">
  214. <%
  215. mySQL="SELECT "& TopNo & " * From "& sys & "Items WHERE (Account='"& Customer & "' AND IsCredit=1 AND FullyApplied=0 AND Voided=0) ORDER BY EffectiveDate DESC, ID DESC"
  216. Set RS1 = conn.Execute(mySQL)
  217. if (RS1.eof) then
  218. call showAlert( " " , CONST_MSG_ALERT)
  219. noJavaScript=true
  220. else
  221. '******************** Credit Items
  222. %>
  223. <TABLE class="GenTable" align="center" cellspacing="5" cellpadding="2" dir="RTL" border="1" width="100%">
  224. <Tbody ID="CreditsTAble" name='CreditsTable'>
  225. <% TotalCredit=0
  226. while Not (RS1.EOF)
  227. description = ""
  228. '================================== Type = 1
  229. '==================================
  230. if RS1("Type")=1 then
  231. sourceLink="<a style='text-decoration:none; color:green;' href='AccountReport.asp?act=showInvoice&invoice="& RS1("Link") & "' target='_blank'>" & " " & RS1("Link") & "</a>"
  232. '================================== Type = 2
  233. '==================================
  234. elseif RS1("Type")=2 then
  235. sourceLink="<a style='text-decoration:none; color:green;' href='AccountReport.asp?act=showReceipt&receipt="& RS1("Link") & "' target='_blank'>" & " " & RS1("Link") & "</a>"
  236. Set RST = conn.Execute("select * from ReceivedCash where Receipt=" & RS1("Link"))
  237. if RST.EOF then
  238. description = " ! "
  239. else
  240. description = RST("Description")
  241. end if
  242. '================================== Type = 3
  243. '==================================
  244. elseif RS1("Type")=3 then
  245. sourceLink="<a style='text-decoration:none; color:green;' href='AccountReport.asp?act=showMemo&sys="& sys & "&memo="& RS1("Link") & "' target='_blank'>" & " "& RS1("Link") & "</a>"
  246. Set RST = conn.Execute("select * from "& sys & "memo where ID=" & RS1("Link"))
  247. if RST.EOF then
  248. description = " ! "
  249. else
  250. description = RST("Description")
  251. end if
  252. '================================== Type = 4
  253. '==================================
  254. elseif RS1("Type")=4 then
  255. sourceLink="<a style='text-decoration:none; color:green;' href='AccountReport.asp?act=showInvoice&invoice="& RS1("Link") & "' target='_blank'>" & "ѐ " & RS1("Link") & "</a>"
  256. '================================== Type = 5
  257. '==================================
  258. elseif RS1("Type")=5 then
  259. sourceLink="<a style='text-decoration:none; color:green;' href='AccountReport.asp?act=showPayment&payment="& RS1("Link") & "' target='_blank'>" & " " & RS1("Link") & "</a>"
  260. mySQL="SELECT ISNULL(PaidCash.Description,'') AS CashDesc, PaidCheques.Description AS CheqDesc FROM PaidCheques RIGHT OUTER JOIN Payments ON PaidCheques.Payment = Payments.ID LEFT OUTER JOIN PaidCash ON Payments.ID = PaidCash.Payment WHERE (Payments.ID = "& RS1("Link") & ")"
  261. Set RST = conn.Execute(mySQL)
  262. if RST.EOF then
  263. description = " ! "
  264. else
  265. description = RST("CashDesc")
  266. Do Until RST.eof
  267. description = description + " " + RST("CheqDesc")
  268. RST.moveNext
  269. Loop
  270. end if
  271. RST.close
  272. '================================== Type = 6
  273. '==================================
  274. elseif RS1("Type")=6 then
  275. sourceLink="<a style='text-decoration:none; color:green;' href='AccountReport.asp?act=showVoucher&voucher="& RS1("Link") & "' target='_blank'>" & " "& RS1("Link") & "</a>"
  276. mySQL="SELECT Title FROM Vouchers WHERE (id = "& RS1("Link") & ")"
  277. Set RST = conn.Execute(mySQL)
  278. if RST.EOF then
  279. description = " ! "
  280. else
  281. description = replace(RST("Title"), "/", ".")
  282. end if
  283. RST.close
  284. '================================== Unknown
  285. '==================================
  286. else
  287. sourceLink="<a href='javascript:void(0);'>" & "" & "</a>"
  288. end if
  289. %> <tr class="unsel" bgcolor="white" height='70' valign='top' onclick="slctCrdit(this)"><td class="GrayOutLine">
  290. <input type='hidden' name='CreditItems' value='<%=RS1("ID")%>'>
  291. <table class='GenTable' width="300" cellspacing='4' cellpadding='1'>
  292. <tr bgcolor='#CCEECC'>
  293. <td class="rowName"><%=sourceLink%></td>
  294. <td class="GrayOutLine"><span dir='LTR'><%=RS1("EffectiveDate")%></span></td>
  295. <td class="GrayOutLine"> : <INPUT class='RelInput' readonly value='<%=Separate(RS1("AmountOriginal"))%>' size='10'></td>
  296. </tr>
  297. <tr>
  298. <td colspan="3">
  299. <a disabled><%=description%></a><BR>
  300. <span class="desc">
  301. <%
  302. mySQL2="SELECT * From "& sys & "ItemsRelations INNER JOIN "&sys & "Items ON "& sys & "ItemsRelations.Debit"& sys & "Item = "& sys & "Items.ID WHERE ("& sys & "ItemsRelations.Credit"& sys & "Item = "& RS1("id") & ") "
  303. Set RS2 = conn.Execute(mySQL2)
  304. while Not (RS2.EOF)
  305. response.write "<span disabled><input class='RelInput' size='10' readonly value=' " & separate(RS2("Amount")) & " '> " & " "& typeNamesArray(cint(RS2("Type"))) & " "& RS2("Link") & "</span><br>"
  306. RS2.movenext
  307. wend
  308. if RS1("voided") then response.write "<b> </b>"
  309. %>
  310. &nbsp;</span></td>
  311. </tr>
  312. <tr>
  313. <td class="GrayOutLine" colspan="2">: <span><INPUT class='RelInput' readonly Name='CreditRemained' value=<%=Separate(RS1("RemainedAmount"))%> size='10'></span></td>
  314. <td align="center"><span class="isPass" style="visibility:hidden;color:green;"><b> </b></span></td>
  315. </tr>
  316. </table></td>
  317. </tr>
  318. <%
  319. TotalCredit= TotalCredit + cdbl(RS1("RemainedAmount"))
  320. RS1.movenext
  321. wend
  322. %>
  323. </Tbody>
  324. </TABLE>
  325. <%
  326. end if
  327. %>
  328. </td>
  329. </tr>
  330. <tr height="5">
  331. <td dir='LTR' align='left' colspan="3"><span id="Relations"></span></td>
  332. </tr>
  333. <tr style="padding:4">
  334. <td class="GrayOutLine" bgColor="#FFC0C0"> : <span>&nbsp;&nbsp;<INPUT class='RelInput' readonly Name='TotalDebitRemained' value='<%=Separate(TotalDebit)%>' size='10'></span></td>
  335. <td class="GrayOutLine" bgColor="#C0EEC0"> : <span>&nbsp;&nbsp;<INPUT class='RelInput' readonly Name='TotalCreditRemained' value='<%=Separate(TotalCredit)%>' size='10'></span></td>
  336. </tr>
  337. <tr height="10">
  338. <td align='center' colspan="3"><input name="selectedCustomer" type="hidden" value="<%=Customer%>"></td>
  339. </tr>
  340. <tr>
  341. <td align='left'><input class="GenButton" type="button" style="font-family:Tahoma" value="" onclick="window.location='ItemsRelation.asp';" >&nbsp;</td>
  342. <td align='center'>&nbsp;<input class="GenButton" type="button" style="font-family:Tahoma" value=" " onclick="this.disabled=true;submit();" >&nbsp;</td>
  343. <td align='right'><input class="GenButton" type="button" style="font-family:Tahoma" value=" " onclick="window.location='ItemsRelation.asp?act=relate&selectedCustomer=<%=Customer%>'" >&nbsp;</td>
  344. </tr>
  345. </Tbody>
  346. </TABLE><br>
  347. </FORM>
  348. <%
  349. end if
  350. '-----------------------------------------------------------------------------------------------------
  351. '----------------------------------------------------------------------------------- submits Relations
  352. '-----------------------------------------------------------------------------------------------------
  353. elseif request("act")="submitRelation" then
  354. sys = request("sys")
  355. selectedCustomer = request("selectedCustomer")
  356. 'response.write request.form("CreditItems")
  357. 'response.write "<br>"
  358. 'response.write request.form("DebitItems")
  359. 'response.write "<br>"
  360. 'response.end
  361. if sys = "" then sys = "AR"
  362. for i=1 to request.form("CreditItems").count
  363. remained=text2value(request.form("CreditRemained")(i))
  364. mySQL="UPDATE "& sys & "Items SET RemainedAmount='"& remained & "' WHERE (ID='"& request.form("CreditItems")(i) & "')"
  365. conn.Execute(mySQL)
  366. ' response.write mySQL & "<br>"
  367. next
  368. for i=1 to request.form("DebitItems").count
  369. remained=text2value(request.form("DebitRemained")(i))
  370. mySQL="UPDATE "& sys & "Items SET RemainedAmount='"& remained & "' WHERE (ID='"& request.form("DebitItems")(i) & "')"
  371. conn.Execute(mySQL)
  372. ' response.write mySQL & "<br>"
  373. next
  374. mySQL="UPDATE "& sys & "Items SET FullyApplied='1' WHERE (RemainedAmount='0')"
  375. conn.Execute(mySQL)
  376. ' response.write mySQL & "<br>"
  377. for i=1 to request.form("CreditARItem").count
  378. amount = cdbl(request.form("Amount")(i))
  379. mySQL="INSERT INTO "& sys & "ItemsRelations (CreatedDate, CreatedBy, Credit"& sys & "Item, Debit"& sys & "Item, Amount) VALUES (N'"& ShamsiToday() & "', '"& session("ID") & "', '"& request.form("CreditARItem")(i) &"', '"& request.form("DebitARItem")(i) &"', '"& amount &"')"
  380. conn.Execute(mySQL)
  381. ' response.write mySQL & "<br>"
  382. next
  383. conn.Close
  384. 'response.write request.form("CreditARItem").count
  385. response.redirect "ItemsRelation.asp?sys=" & sys & "&act=relate&selectedCustomer=" & selectedCustomer
  386. 'response.end
  387. '-----------------------------------------------------------------------------------------------------
  388. '---------------------------------------------------------------------------------- Tear a Relation
  389. '-----------------------------------------------------------------------------------------------------
  390. elseif request("act")="unrelate" then
  391. relation=clng(request("relation"))
  392. sys= ucase(request("sys"))
  393. if NOT (sys = "AR" OR sys = "AP" OR sys = "AO" ) then
  394. conn.close
  395. response.redirect "top.asp?errMsg="& Server.URLEncode("!")
  396. end if
  397. mySQL="SELECT * FROM "& sys & "ItemsRelations WHERE (ID = '"& relation & "')"
  398. Set RS1=conn.Execute(mySQL)
  399. If not RS1.eof then
  400. '********* Adding back the amount in the relation, to the debit Item ...
  401. conn.Execute("UPDATE "& sys & "Items SET RemainedAmount=RemainedAmount+ '"& RS1("Amount") & "', FullyApplied=0 WHERE (ID = '"& RS1("Debit"& sys & "Item") & "')")
  402. '********* Adding back the amount in the relation, to the credit Item ...
  403. conn.Execute("UPDATE "& sys & "Items SET RemainedAmount=RemainedAmount+ '"& RS1("Amount") & "', FullyApplied=0 WHERE (ID = '"& RS1("Credit"& sys & "Item") & "')")
  404. '********* Deleting the relation
  405. conn.Execute("DELETE FROM "& sys & "ItemsRelations WHERE (ID = '"& relation & "')")
  406. End if
  407. RS1.close
  408. conn.close
  409. response.redirect Request.ServerVariables("HTTP_REFERER")&"&msg=" &Server.URLEncode(" .")
  410. '-----------------------------------------------------------------------------------------------------
  411. '---------------------------------------------------------------------------------- Search for account
  412. '-----------------------------------------------------------------------------------------------------
  413. else%>
  414. <!-- --><BR><BR>
  415. <FORM METHOD=POST ACTION="ItemsRelation.asp?act=submitsearch" onsubmit="if (document.all.CustomerNameSearchBox.value=='') return false;">
  416. <div dir='rtl'>&nbsp;<B> : </B>
  417. <INPUT TYPE="text" NAME="CustomerNameSearchBox">&nbsp;
  418. <INPUT class="GenButton" TYPE="submit" value=""><br>
  419. </div>
  420. </FORM>
  421. <SCRIPT LANGUAGE="JavaScript">
  422. <!--
  423. document.all.CustomerNameSearchBox.focus();
  424. //-->
  425. </SCRIPT>
  426. <%
  427. end if
  428. conn.Close
  429. if not (noJavaScript=true) then %>
  430. <script language="JavaScript">
  431. <!--
  432. //---------------------------------------------
  433. //---------------------------------------------
  434. //---------------------------------------------
  435. var slctRowClr='#FFFF00'
  436. function slctCrdit(srcRow){
  437. var e = $(srcRow);
  438. if (getNum(e.find("input[name=CreditRemained]").val())==0)
  439. return 0;
  440. $("[name=CreditsTable]").css("cursor","auto");
  441. /* $("#selectedCreditItem").val(e.index()); // must check. may be no more needed! */
  442. $("[name=CreditItems]").parent().parent().prop("bgColor","#FFFFFF");
  443. $("[name=CreditItems]").parent().parent().prop("selected","no");
  444. e.prop("bgColor",slctRowClr);
  445. e.removeClass("unsel");
  446. e.addClass("sel");
  447. if ($("[name=DebitsTable] tr.sel").size()!=0){
  448. var dstRow = $("[name=DebitsTable] tr.sel");
  449. var dstSpan = dstRow.find("span.desc");
  450. var dstName = dstRow.find("td.rowName").text();
  451. var dstRemained = dstRow.find("input[name=DebitRemained]");
  452. var srcSpan = e.find("span.desc");
  453. var srcName = e.find("td.rowName").text();
  454. var srcRemained = e.find("input[name=CreditRemained]");
  455. var suggest = Math.min(getNum(srcRemained.val()),getNum(dstRemained.val()));
  456. var amount = getNum(prompt(" ",suggest));
  457. if (amount != 0 && amount <= suggest){
  458. srcRemained.val(echoNum(getNum(srcRemained.val()) - parseInt(amount)));
  459. dstRemained.val(echoNum(getNum(dstRemained.val()) - parseInt(amount)));
  460. srcSpan.append("<input class='RelInput' readonly value='"+echoNum(amount)+"' size='10'>"+" "+dstName +"<br>&nbsp;");
  461. dstSpan.append("<input class='RelInput' readonly value='"+echoNum(amount)+"' size='10'>"+" "+srcName +"<br>&nbsp;");
  462. $("#Relations").append("<input type='hidden' name='CreditARItem' value='"+e.find("input[name=CreditItems]").val()+"'>");
  463. $("#Relations").append("<input type='hidden' name='DebitARItem' value='"+dstRow.find("input[name=DebitItems]").val()+"'>");
  464. $("#Relations").append("<input type='hidden' name='Amount' value='"+amount+"'>");
  465. setRemained();
  466. }
  467. if (getNum(dstRemained.val())==0){
  468. dstRow.find("span.isPass").css("visibility","visible");
  469. dstRow.removeClass("sel");
  470. dstRow.removeClass("unsel");
  471. dstRow.addClass("unsel");
  472. dstRow.prop("bgColor","#FFFFFF");
  473. }
  474. if (getNum(srcRemained.val()==0)){
  475. e.find("span.isPass").css("visibility","visible");
  476. e.removeClass("sel");
  477. e.removeClass("unsel");
  478. e.addClass("unsel");
  479. e.prop("bgColor","#FFFFFF");
  480. }
  481. } else {
  482. $("[name=DebitsTable]").css("cursor","crosshair");
  483. }
  484. }
  485. //---------------------------------------------
  486. //---------------------------------------------
  487. //---------------------------------------------
  488. function slctDdit(dstRow){
  489. var e = $(dstRow);
  490. if (getNum(e.find("input[name=DebitRemained]").val())==0)
  491. return 0;
  492. $("[name=DebitsTable]").css("cursor","auto");
  493. /* document.all.selectedDebitItem.value=dstRow.rowIndex */
  494. $("[name=DebitItems]").parent().parent().prop("bgColor","#FFFFFF");
  495. $("[name=DebitItems]").parent().parent().prop("selected","yes");
  496. e.prop("bgColor",slctRowClr);
  497. e.removeClass("unsel");
  498. e.addClass("sel");
  499. if ($("[name=CreditsTable] tr.sel").size()!=0){
  500. var dstSpan = e.find("span.desc");
  501. var dstName = e.find("td.rowName").text();
  502. var dstRemained = e.find("input[name=DebitRemained]");
  503. var srcRow = $("[name=CreditsTable] tr.sel");
  504. var srcSpan = srcRow.find("span.desc");
  505. var srcName = srcRow.find("td.rowName").text();
  506. var srcRemained = srcRow.find("input[name=CreditRemained]");
  507. var suggest = Math.min(getNum(srcRemained.val()),getNum(dstRemained.val()));
  508. var amount = getNum(prompt(" ",suggest));
  509. if (amount != 0 && amount <= suggest){
  510. srcRemained.val(echoNum(getNum(srcRemained.val()) - parseInt(amount)));
  511. dstRemained.val(echoNum(getNum(dstRemained.val()) - parseInt(amount)));
  512. srcSpan.append("<input class='RelInput' readonly value='"+echoNum(amount)+"' size='10'>"+" "+dstName +"<br>&nbsp;");
  513. dstSpan.append("<input class='RelInput' readonly value='"+echoNum(amount)+"' size='10'>"+" "+srcName +"<br>&nbsp;");
  514. $("#Relations").append("<input type='hidden' name='CreditARItem' value='"+srcRow.find("input[name=CreditItems]").val()+"'>");
  515. $("#Relations").append("<input type='hidden' name='DebitARItem' value='"+e.find("input[name=DebitItems]").val()+"'>");
  516. $("#Relations").append("<input type='hidden' name='Amount' value='"+amount+"'>");
  517. setRemained();
  518. }
  519. if (getNum(srcRemained.val())==0){
  520. srcRow.find("span.isPass").css("visibility","visible");
  521. srcRow.removeClass("sel");
  522. srcRow.removeClass("unsel");
  523. srcRow.addClass("unsel");
  524. srcRow.prop("bgColor","#FFFFFF");
  525. }
  526. if (getNum(dstRemained.val())==0){
  527. e.find("span.isPass").css("visibility","visible");
  528. e.removeClass("sel");
  529. e.removeClass("unsel");
  530. e.addClass("unsel");
  531. e.prop("bgColor","#FFFFFF");
  532. }
  533. } else {
  534. $("[name=CreditsTable]").css("cursor","crosshair");
  535. }
  536. }
  537. //---------------------------------------------
  538. //---------------------------------------------
  539. //---------------------------------------------
  540. function setRemained(){
  541. var totalDebit = 0;
  542. var totalCredit = 0
  543. $("input[name=DebitRemained]").each(function(i){
  544. totalDebit += getNum($(this).val());
  545. });
  546. $("input[name=CreditRemained]").each(function(i){
  547. totalCredit += getNum($(this).val());
  548. });
  549. $("input[name=TotalDebitRemained]").val(echoNum(totalDebit));
  550. $("input[name=TotalCreditRemained]").val(echoNum(totalCredit));
  551. }
  552. //---------------------------------------------
  553. //---------------------------------------------
  554. //---------------------------------------------
  555. function unselect(){
  556. $("[name=DebitsTable]").css("cursor","auto");
  557. $("[name=CreditsTable]").css("cursor","auto");
  558. $("[name=DebitsTable] tr.sel").prop("bgColor","#fff");
  559. $("[name=DebitsTable] tr.sel").addClass("unsel");
  560. $("[name=DebitsTable] tr.sel").removeClass("sel");
  561. $("[name=CreditsTable] tr.sel").prop("bgColor","#fff");
  562. $("[name=CreditsTable] tr.sel").addClass("unsel");
  563. $("[name=CreditsTable] tr.sel").removeClass("sel");
  564. }
  565. //---------------------------------------------
  566. //---------------------------------------------
  567. //---------------------------------------------
  568. function delRelation(src){
  569. srcRow=src.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode
  570. alert(srcRow)
  571. }
  572. //-->
  573. </script>
  574. <%else%>
  575. <script language="JavaScript">
  576. <!--
  577. function slctCrdit(srcRow){}
  578. function slctDdit(dstRow){}
  579. function unselect(){}
  580. //-->
  581. </script>
  582. <%end if%>