/beta/AO/AO.asp

http://github.com/khaneh/Orders · ASP · 517 lines · 454 code · 36 blank · 27 comment · 79 complexity · 166a9e4252cecd1e6bd86e813cc2dd8b MD5 · raw file

  1. <%@LANGUAGE="VBSCRIPT" CODEPAGE="1256"%><%
  2. 'A0 (11 [=B])
  3. PageTitle= " - "
  4. SubmenuItem=2
  5. if not Auth("B" , 2) then NotAllowdToViewThisPage()
  6. %>
  7. <!--#include file="top.asp" -->
  8. <!--#include File="../include_farsiDateHandling.asp"-->
  9. <!--#include File="../include_JS_InputMasks.asp"-->
  10. <%
  11. '---------------------------------------------
  12. '---------------------------- ShowErrorMessage
  13. '---------------------------------------------
  14. function ShowErrorMessage(msg)
  15. response.write "<table align='center' cellpadding='5'><tr><td bgcolor='#FFCCCC' dir='rtl' align='center'> ! <br>"& msg & "<br></td></tr></table><br>"
  16. end function
  17. %>
  18. <style>
  19. Table { font-size: 9pt;}
  20. .InvHeadInput { font-family:tahoma; font-size: 9pt; border: none; background-color: #CCCC88; text-align:center;}
  21. .InvRowInput { font-family:tahoma; font-size: 9pt; border: none; background-color: #F0F0F0; text-align:right; width:100%;}
  22. .InvRowInput2 { font-family:tahoma; font-size: 9pt; border: none; background-color: #F0F0F0; direction:RTL; width:100%;}
  23. .InvHeadInput2 { font-family:tahoma; font-size: 9pt; border: none; background-color: #AACC77; text-align:center;}
  24. .InvHeadInput3 { font-family:tahoma; font-size: 9pt; border: none; background-color: #F0F0F0; text-align:right; direction: right-to-left;}
  25. .InvGenInput { font-family:tahoma; font-size: 9pt; border: none; }
  26. .InvGenButton { font-family:tahoma; font-size: 9pt; border: 1px solid black; }
  27. .GLInput1 { font-family:tahoma; font-size: 9pt; border: 1px solid black; direction:RTL;}
  28. .GLInput2 { font-family:tahoma; font-size: 9pt; border: 1px solid black; direction:LTR;}
  29. .GLTable1 { border: none; direction:RTL; border:1px dashed red ;}
  30. .GLTable1 tr {height:20; background-color: #CCCC88; }
  31. .GLTable2 { border: none; direction:RTL;}
  32. .GLTable2 tr {height:20; text-align:center; background-color: #C3C300; }
  33. .GLTable2 td {border-bottom: 1px solid black; border-right: 1px solid black;}
  34. .GLTable3 tr {background-color: #F0F0F0}
  35. .GLTR1 { font-family:tahoma; font-size: 9pt; height:30; text-align:center; vertical-align:top; background-color: #C3C300; }
  36. ' .GLTR2 { height:20; text-align:center; background-color: #C3C300; }
  37. .GLTD1 { font-family:tahoma; font-size: 9pt; height:20; text-align:center; }
  38. </style>
  39. <SCRIPT LANGUAGE="JavaScript">
  40. <!--
  41. var okToProceed=false;
  42. var currentRow=0;
  43. var IsTaraz = false
  44. //-->
  45. </SCRIPT>
  46. <%
  47. '-----------------------------------------------------------------------------------------------------
  48. '--------------------------------------------------------------------------------- Input a new AO MEMO
  49. '-----------------------------------------------------------------------------------------------------
  50. if request("act")="" then
  51. %>
  52. <!-- -->
  53. <script language="JavaScript">
  54. <!--
  55. function setCurrentRow(rowNo){
  56. if (rowNo == -1) rowNo=0;
  57. MemosTbl=document.getElementById("AOMemos");
  58. theTD=MemosTbl.getElementsByTagName("tr")[currentRow].getElementsByTagName("td")[0];
  59. theTD.setAttribute("bgColor", '#F0F0F0');
  60. currentRow=rowNo;
  61. MemosTbl=document.getElementById("AOMemos");
  62. theTD=MemosTbl.getElementsByTagName("tr")[currentRow].getElementsByTagName("td")[0];
  63. theTD.setAttribute("bgColor", '#FFB0B0');
  64. }
  65. function delRow(rowNo){
  66. rowsCount=document.getElementsByName("Accounts").length;
  67. if(rowsCount<2){
  68. alert(" ");
  69. return false;
  70. }
  71. MemosTbl=document.getElementById("AOMemos");
  72. theRow=MemosTbl.getElementsByTagName("tr")[rowNo];
  73. MemosTbl.removeChild(theRow);
  74. rowsCount=document.getElementsByName("Accounts").length;
  75. for (rowNo=0; rowNo < rowsCount ; rowNo++){
  76. tempTD=MemosTbl.getElementsByTagName("tr")[rowNo].getElementsByTagName("td")[0]
  77. tempTD.bgColor= '#F0F0F0';
  78. tempTD.innerText= rowNo+1;
  79. }
  80. event.cancelBubble=true;
  81. setCurrentRow(currentRow);
  82. if (currentRow!=rowsCount){
  83. tempTD=MemosTbl.getElementsByTagName("tr")[currentRow].getElementsByTagName("INPUT")[0];
  84. tempTD.select();
  85. tempTD.focus();
  86. }
  87. }
  88. function addRow(){
  89. rowNo = currentRow;
  90. MemosTbl=document.getElementById("AOMemos");
  91. theRow=MemosTbl.getElementsByTagName("tr")[rowNo];
  92. theRow.getElementsByTagName("td")[0].bgColor= '#F0F0F0';
  93. rowsCount=document.getElementsByName("Accounts").length;
  94. if (currentRow==rowsCount)
  95. newRow=theRow.previousSibling.cloneNode(true);
  96. else
  97. newRow=theRow.cloneNode(true);
  98. MemosTbl.insertBefore(newRow,theRow);
  99. rowsCount=document.getElementsByName("Accounts").length;
  100. for (rowNo=0; rowNo < rowsCount ; rowNo++){
  101. tempTD=MemosTbl.getElementsByTagName("tr")[rowNo].getElementsByTagName("td")[0]
  102. tempTD.innerText= rowNo+1;
  103. }
  104. event.cancelBubble=true;
  105. setCurrentRow(currentRow);
  106. tempTD=MemosTbl.getElementsByTagName("tr")[currentRow].getElementsByTagName("INPUT")[0]
  107. tempTD.select();
  108. tempTD.focus();
  109. // document.all.dddd2.innerText=MemosTbl.innerHTML
  110. }
  111. var dialogActive=false;
  112. function rowMask(src){
  113. var theKey=event.keyCode;
  114. if (theKey == 45 && event.ctrlKey) {
  115. addRow();
  116. }
  117. else if (theKey == 46 && event.ctrlKey) {
  118. delRow(currentRow)
  119. setCurrentRow(currentRow);
  120. }
  121. }
  122. function mask(src){
  123. var theKey=event.keyCode;
  124. if (src.name=="Accounts"){
  125. if (theKey==32){
  126. event.keyCode=0;
  127. dialogActive=true;
  128. document.all.tmpDlgArg.value="#"
  129. document.all.tmpDlgTxt.value=" :"
  130. window.showModalDialog('../dialog_GenInput.asp',document.all.tmpDlgTxt,'dialogHeight:200px; dialogWidth:440px; dialogTop:; dialogLeft:; edge:None; center:Yes; help:No; resizable:No; status:No;');
  131. dialogActive=false;
  132. if (document.all.tmpDlgTxt.value !="") {
  133. dialogActive=true;
  134. window.showModalDialog('../AR/dialog_selectAccount.asp?act=select&search='+escape(document.all.tmpDlgTxt.value),document.all.tmpDlgArg,'dialogHeight:300px; dialogWidth:600px; dialogTop:; dialogLeft:; edge:Raised; center:Yes; help:No; resizable:Yes; status:No;');
  135. dialogActive=false;
  136. if (document.all.tmpDlgArg.value!="#"){
  137. Arguments=document.all.tmpDlgArg.value.split("#")
  138. src.value=Arguments[0];
  139. src.title=Arguments[1];
  140. }
  141. }
  142. }
  143. else if (theKey >= 48 && theKey <= 57 )
  144. return true;
  145. else
  146. return false;
  147. }
  148. else if(src.name=="GLAccounts" || src.name=="firstGLAccounts"){
  149. if (theKey==32){
  150. event.keyCode=0;
  151. dialogActive=true;
  152. document.all.tmpDlgArg.value="#"
  153. document.all.tmpDlgTxt.value=" :"
  154. window.showModalDialog('../dialog_GenInput.asp',document.all.tmpDlgTxt,'dialogHeight:200px; dialogWidth:440px; dialogTop:; dialogLeft:; edge:None; center:Yes; help:No; resizable:No; status:No;');
  155. dialogActive=false;
  156. if (document.all.tmpDlgTxt.value !="") {
  157. dialogActive=true;
  158. window.showModalDialog('../accounting/dialog_selectGL.asp?act=select&name='+escape(document.all.tmpDlgTxt.value),document.all.tmpDlgArg,'dialogHeight:500px; dialogWidth:380px; dialogTop:; dialogLeft:; edge:Raised; center:Yes; help:No; resizable:Yes; status:No;');
  159. dialogActive=false;
  160. if (document.all.tmpDlgArg.value!="#"){
  161. Arguments=document.all.tmpDlgArg.value.split("#")
  162. src.value=Arguments[0];
  163. src.title=Arguments[1];
  164. }
  165. }
  166. }
  167. else if (theKey >= 48 && theKey <= 57 ) // [0]-[9] are acceptible
  168. return true;
  169. else
  170. return false;
  171. }
  172. else if(src.name=="Amounts"){
  173. if (theKey >= 48 && theKey <= 57 ) // [0]-[9] are acceptible
  174. return true;
  175. else
  176. return false;
  177. }
  178. }
  179. function check(src){
  180. if (src.name=="Accounts"){
  181. if (!dialogActive){
  182. if (window.XMLHttpRequest) {
  183. var objHTTP=new XMLHttpRequest();
  184. } else if (window.ActiveXObject) {
  185. var objHTTP = new ActiveXObject("Microsoft.XMLHTTP");
  186. }
  187. objHTTP.open('GET','../accounting/xml_CustomerAccount.asp?id='+src.value,false)
  188. objHTTP.send()
  189. tmpStr = unescape( objHTTP.responseText)
  190. src.title=tmpStr;
  191. if (tmpStr==" "){
  192. src.value="";
  193. }
  194. }
  195. }
  196. else if(src.name=="GLAccounts" || src.name=="firstGLAccounts"){
  197. if (!dialogActive){
  198. if (window.XMLHttpRequest) {
  199. var objHTTP=new XMLHttpRequest();
  200. } else if (window.ActiveXObject) {
  201. var objHTTP = new ActiveXObject("Microsoft.XMLHTTP");
  202. }
  203. objHTTP.open('GET','../accounting/xml_GLAccount.asp?id='+src.value,false)
  204. objHTTP.send()
  205. tmpStr = unescape( objHTTP.responseText)
  206. src.title=tmpStr;
  207. if (tmpStr==" "){
  208. src.value="";
  209. }
  210. }
  211. }
  212. else if(src.name=="debits" || src.name=="credits"){
  213. src.value=val2txt(txt2val(src.value));
  214. if (''+src.value=="NaN" || src.value=="0") src.value = ""
  215. rowNo=src.parentNode.parentNode.rowIndex;
  216. if (src.value!=""){
  217. if (src.name=="credits")
  218. document.getElementsByName("debits")[rowNo].value = "";
  219. else
  220. document.getElementsByName("credits")[rowNo].value = "";
  221. }
  222. var totalCredit = 0;
  223. var totalDebit = 0;
  224. for (rowNo=0; rowNo < lastRow; rowNo++){
  225. totalCredit += parseInt(txt2val(document.getElementsByName("credits")[rowNo].value));
  226. totalDebit += parseInt(txt2val(document.getElementsByName("debits")[rowNo].value));
  227. }
  228. document.all.totalCredit.value = val2txt(totalCredit);
  229. document.all.totalDebit.value = val2txt(totalDebit);
  230. if (totalDebit == totalCredit && totalCredit != 0){
  231. IsTaraz = true
  232. document.all.tarazDiv.innerHTML = "<FONT COLOR='#008833'> </FONT>"
  233. }
  234. else{
  235. IsTaraz = false
  236. document.all.tarazDiv.innerHTML = "<FONT COLOR='#FF3300'> </FONT>"
  237. }
  238. }
  239. else if(src.name=="Amounts"){
  240. src.value=val2txt(txt2val(src.value));
  241. }
  242. }
  243. function isEmpty()
  244. {
  245. if (document.all.Accounts.value=="" )
  246. {
  247. alert(" ")
  248. return false
  249. }
  250. return true
  251. }
  252. //-->
  253. </script>
  254. <br>
  255. <br>
  256. <%
  257. if session("id")=-1 then
  258. %>
  259. <SCRIPT LANGUAGE="JavaScript">
  260. <!--
  261. function importBulk(){
  262. //alert('asd?');
  263. src=escape(document.all.BulkInput.value)
  264. Rows = src.split("%0D%0A") // Line Break
  265. for (i=0;i<Rows.length;i++){
  266. if (Rows[i]!=''){
  267. Cols=Rows[i].split("%09"); // Tab
  268. setCurrentRow(currentRow+1);
  269. addRow();
  270. MemosTbl=document.getElementById("AOMemos");
  271. theRow=MemosTbl.getElementsByTagName("tr")[currentRow];
  272. theRow.getElementsByTagName("INPUT")[0].value= Cols[0];
  273. theRow.getElementsByTagName("INPUT")[1].value= Cols[1];
  274. theRow.getElementsByTagName("SELECT")[0].value= Cols[2];
  275. theRow.getElementsByTagName("INPUT")[2].value= Cols[3];
  276. theRow.getElementsByTagName("INPUT")[3].value= unescape(Cols[4]);
  277. theRow.getElementsByTagName("INPUT")[4].value= Cols[5];
  278. theRow.getElementsByTagName("INPUT")[5].value= Cols[6];
  279. }
  280. }
  281. }
  282. //-->
  283. </SCRIPT>
  284. <TABLE align=center style='border:2 dashed green;width:' width='300px;'>
  285. <TR>
  286. <TD>
  287. </TD>
  288. </TR>
  289. <TR>
  290. <TD>
  291. <TEXTAREA NAME="BulkInput" ROWS="5" COLS="50"></TEXTAREA>
  292. </TD>
  293. </TR>
  294. <TR>
  295. <TD align=center>
  296. <INPUT TYPE="button" value="Import" style='border:1 solid black;' onclick='importBulk();'>
  297. </TD>
  298. </TR>
  299. </TABLE>
  300. <br><br>
  301. <%
  302. end if
  303. %>
  304. <input type="hidden" Name='tmpDlgArg' value=''>
  305. <input type="hidden" Name='tmpDlgTxt' value=''>
  306. <table class="GLTable1" align="center" Cellspacing="0" Cellpadding="0">
  307. <FORM METHOD=POST ACTION="?act=submitMemo" onsubmit="return isEmpty();">
  308. <tr style="background-color:black;height:1px;">
  309. <TD></TD>
  310. </tr>
  311. <tr class="GLTR2"><TD>
  312. <TABLE class="GLTable2" Cellspacing="0" Cellpadding="0" >
  313. <tr>
  314. <td style="width:26; border-right:none;"> # </td>
  315. <td style="width:60;"></td>
  316. <td style="width:40;"></td>
  317. <td style="width:80;"> / </td>
  318. <td style="width:80;"></td>
  319. <td style="width:250;"></td>
  320. <td style="width:60;"> </td>
  321. <td style="width:70;"></td>
  322. <td style="width:20;"></td>
  323. </tr>
  324. </TABLE></TD>
  325. </tr>
  326. <tr><TD>
  327. <div style="overflow:auto; height:250px; width:*;">
  328. <TABLE Border="0" Cellspacing="1" Cellpadding="0" Dir="RTL" bgcolor="#558855" class="GLTable3">
  329. <Tbody id="AOMemos">
  330. <TR bgColor=#f0f0f0 onclick="setCurrentRow(this.rowIndex);" onKeyDown="rowMask(this);">
  331. <td width='25' align=center> 1 </td>
  332. <td width="60">
  333. <INPUT class='InvRowInput' TYPE='text' NAME='Accounts' maxlength=6 title="" onKeyPress='return mask(this);' onBlur='check(this);'></td>
  334. <td width="40">
  335. <INPUT class='InvRowInput2' TYPE='text' NAME='firstGLAccounts' maxlength=5 title="" onKeyPress='return mask(this);' onBlur='check(this);'></td>
  336. <td width="80">
  337. <SELECT class='InvRowInput2' NAME='isCredits'>
  338. <option Value="1"></option>
  339. <option Value="0"></option>
  340. </SELECT></td>
  341. <td width="80" dir="LTR">
  342. <INPUT class='InvRowInput2' TYPE='text' NAME='Amounts' onKeyPress='return mask(this);' onBlur='check(this)' onfocus='this.select()'></td>
  343. <td width="250">
  344. <INPUT class='InvRowInput2' TYPE='text' NAME='Descriptions'></td>
  345. <td width="60">
  346. <INPUT class='InvRowInput2' TYPE='text' NAME='GLAccounts' onKeyPress='return mask(this);' onBlur='check(this);' maxlength=5 ></td>
  347. <td width="70">
  348. <INPUT class='InvRowInput2' style='direction:LTR;text-align:left;width:70' TYPE='text' NAME='EffectiveDates' onblur="acceptDate(this)" maxlength=10></td>
  349. </TR>
  350. <TR bgcolor='#F0F0F0' onclick="setCurrentRow(this.rowIndex);" >
  351. <td colspan="8">
  352. <INPUT class="InvGenButton" TYPE="button" value="" onkeyDown="if(event.keyCode==9) {setCurrentRow(this.parentNode.parentNode.rowIndex); return false;};" onClick="addRow();">
  353. </td>
  354. </TR>
  355. </Tbody>
  356. </TABLE></div>
  357. </TD>
  358. </tr>
  359. </table>
  360. <TABLE Border="0" Cellspacing="5" Cellpadding="10" Dir="RTL" align='left'>
  361. <tr>
  362. <td align='center'><INPUT class="InvGenButton" TYPE="submit" value=" "></td>
  363. </tr>
  364. </TABLE>
  365. </FORM>
  366. <SCRIPT LANGUAGE="JavaScript">
  367. <!--
  368. setCurrentRow(0);
  369. document.getElementById("AOMemos").getElementsByTagName("INPUT")[0].focus();
  370. //-->
  371. </SCRIPT>
  372. <%
  373. '-----------------------------------------------------------------------------------------------------
  374. '---------------------------------------------------------------------------------- Submit new AO MEMO
  375. '-----------------------------------------------------------------------------------------------------
  376. elseif request("act")="submitMemo" then
  377. creationDate=shamsiToday()
  378. errMsg=""
  379. successCount=0
  380. for i=1 to request.form("Accounts").count
  381. errorFound=false
  382. ON ERROR RESUME NEXT
  383. Account = clng(text2value(request.form("Accounts")(i)))
  384. firstGLAccount= clng(text2value(request.form("firstGLAccounts")(i)))
  385. GLAccount = clng(text2value(request.form("GLAccounts")(i)))
  386. Amount = cdbl(text2value(request.form("Amounts")(i)))
  387. Description= sqlSafe(request.form("Descriptions")(i))
  388. EffectiveDate = sqlSafe(request.form("EffectiveDates")(i))
  389. if request.form("isCredits")(i) then
  390. isCredit = 1
  391. else
  392. isCredit = 0
  393. end if
  394. if Err.Number<>0 then
  395. Err.clear
  396. errorFound=True
  397. end if
  398. if NOT errorFound then
  399. ' checking firstGLAccount is valid
  400. mySQL = "SELECT ID FROM GLAccounts WHERE (HasAppendix = 1) AND (GL = "& openGL & ") AND (ID = "& firstGLAccount & ")"
  401. Set RS1=Conn.execute(mySQL)
  402. if RS1.eof then
  403. errorFound=True
  404. end if
  405. RS1.close
  406. mySQL = "SELECT ItemReason FROM AXItemReasonGLAccountRelations WHERE (GL = "& openGL & ") AND (GLAccount = "& firstGLAccount & ")"
  407. Set RS1=Conn.execute(mySQL)
  408. if RS1.eof then
  409. 'Using default reason (sys: AO, reason: Misc.)
  410. Reason=6
  411. else
  412. Reason= cint(RS1("ItemReason"))
  413. end if
  414. RS1.close
  415. mySQL="SELECT * FROM AXItemReasons WHERE (ID="& Reason & ")"
  416. Set RS1=Conn.execute(mySQL)
  417. sys= RS1("Acron")
  418. ReasonName = RS1("Name")
  419. RS1.close
  420. ' ---------
  421. '---- Checking wether EffectiveDate is valid in current open GL
  422. if (effectiveDate < session("OpenGLStartDate")) OR (effectiveDate > session("OpenGLEndDate")) then
  423. errorFound=True
  424. end if
  425. '----
  426. end if
  427. ON ERROR GOTO 0
  428. '----- Check GL is closed
  429. if (session("IsClosed")="True") then
  430. 'Conn.close
  431. errMsg="! ." & "<br>"
  432. errorFound=True
  433. end if
  434. '----
  435. if errorFound then
  436. response.write "<br>"
  437. errMsg= errMsg & "!<br> :<br>"
  438. errMsg=errMsg& ":" & firstGLAccount & "-" & Account & "<br>"
  439. errMsg=errMsg& ":" & Amount & "<br>"
  440. errMsg=errMsg& ":" & Description & "<br>"
  441. errMsg=errMsg& " :" & GLAccount & "<br>"
  442. errMsg=errMsg& " :" & effectiveDate & "<br>"
  443. call showAlert (errMsg,CONST_MSG_ERROR)
  444. else
  445. '**************************** Creating Memo ****************
  446. 'MemoType = 1 means Misc. Memo
  447. mySQL="INSERT INTO "& sys & "Memo (CreatedDate, CreatedBy, Type, Account, IsCredit, Amount, Description) VALUES (N'"& effectiveDate & "' , "& session("id") & ", 1, "& Account & ", "& IsCredit & ", "& Amount & ", N'"& Description & "');SELECT @@Identity AS NewMemo"
  448. Set RS1 = conn.Execute(mySQL).NextRecordSet
  449. MemoID=RS1("NewMemo")
  450. RS1.close
  451. '**************************** Creating an Item for Memo ****************
  452. '*** Type = 3 means Item is a Memo
  453. mySQL="INSERT INTO "& sys & "Items (GLAccount, GL, FirstGLAccount, Account, EffectiveDate, Link, Reason, CreatedDate, CreatedBy, Type, IsCredit, AmountOriginal, RemainedAmount) VALUES ("&_
  454. GLAccount & ", "& OpenGL & ", "& firstGLAccount & ", "& Account & ", N'"& effectiveDate & "', "& MemoID & ", "& Reason & ", N'"& creationDate & "' , "& session("id") & ", 3, "& IsCredit & ", "& Amount & ","& Amount & ")"
  455. conn.Execute(mySQL)
  456. if IsCredit then
  457. mySQL="UPDATE Accounts SET "& sys & "Balance = "& sys & "Balance + '"& Amount & "' WHERE (ID='"& Account & "')"
  458. else
  459. mySQL="UPDATE Accounts SET "& sys & "Balance = "& sys & "Balance - '"& Amount & "' WHERE (ID='"& Account & "')"
  460. end if
  461. conn.Execute(mySQL)
  462. '***------------------------- Creating an Item for Memo ----------------
  463. successCount = successCount + 1
  464. msg=" <A Href='../"& sys & "/AccountReport.asp?act=showMemo&sys="& sys & "&memo=" & MemoID &"' target='_blank'>"& MemoID & "</a> ."
  465. response.write "<br>"
  466. call showAlert (msg,CONST_MSG_INFORM)
  467. end if
  468. next
  469. response.write "<br>"
  470. response.write "<hr width='70%'>"
  471. response.write "<br>"
  472. call showAlert (successCount & " .",CONST_MSG_INFORM)
  473. '-----------------------------------------------------------------------------------------------------
  474. '-----------------------------------------------------------------------------------------------------
  475. '-----------------------------------------------------------------------------------------------------
  476. end if
  477. conn.Close
  478. %>
  479. </font>
  480. <!--#include file="tah.asp" -->