/beta/accounting/MakeDoc.asp

http://github.com/khaneh/Orders · ASP · 530 lines · 473 code · 44 blank · 13 comment · 74 complexity · 182cc04109d1cdd7675792d2628e74b4 MD5 · raw file

  1. <%@LANGUAGE="VBSCRIPT" CODEPAGE="1256"%><%
  2. 'Accounting (8)
  3. PageTitle= " "
  4. SubmenuItem=9
  5. if not Auth(8 , "C") then NotAllowdToViewThisPage()
  6. if request.querystring("act")="showItems" then
  7. response.buffer = false
  8. end if
  9. %>
  10. <!--#include file="top.asp" -->
  11. <!--#include File="../include_farsiDateHandling.asp"-->
  12. <!--#include File="../include_JS_InputMasks.asp"-->
  13. <STYLE>
  14. .RepTable {font-family:tahoma; font-size:9pt; direction: RTL; }
  15. .RepTable td {padding:5;border:1pt solid gray;}
  16. .RepTable a {text-decoration:none; color:#222288;}
  17. .RepTable a:hover {text-decoration:underline;}
  18. .RepTableTitle {background-color: #CCCCFF; text-align: center; height:50;}
  19. .RepTableHeader {background-color: #BBBBBB; text-align: center; font-weight:bold;}
  20. .RepTableFooter {background-color: #BBBBBB; direction: LTR; }
  21. .RepTD1 {width:50px;}
  22. .RepTR1 {background-color: #DDDDDD;}
  23. .RepTR2 {background-color: #FFFFFF;}
  24. .RepGeneralInput {width:70px; font-family:tahoma; font-size:8pt; border:1pt solid gray; background:transparent; direction: LTR; }
  25. .RepGLInput {width:35px; font-family:tahoma; font-size:8pt; border:none; background:#FFCCCC;d:transparent;}
  26. .RepGLInput2 {width:35px; font-family:tahoma; font-size:8pt; border:none; background:transparent;}
  27. .RepAccountInput {width:50px; font-family:tahoma; font-size:8pt; text-align:left; border:none; background:#FFCCCC;d:transparent;}
  28. .RepAccountInput2 {width:50px; font-family:tahoma; font-size:8pt; text-align:left; border:none; background:transparent;}
  29. </STYLE>
  30. <%
  31. Dim Descriptions(10)
  32. ' type 10 is defined ' '
  33. Descriptions(10)=" "
  34. if request.querystring("act")="SubmitDoc" then
  35. ' response.write request("DocDate")
  36. DocDate = sqlSafe(request.form("DocDate"))
  37. '---- Checking wether EffectiveDate is valid in current open GL
  38. if (DocDate < session("OpenGLStartDate")) OR (DocDate > session("OpenGLEndDate")) then
  39. Conn.close
  40. response.redirect "?errMsg=" & Server.URLEncode("! .")
  41. end if
  42. '----
  43. '----- Check GL is closed
  44. if (session("IsClosed")="True") then
  45. Conn.close
  46. response.redirect "AccountInfo.asp?errMsg=" & Server.URLEncode("! .")
  47. end if
  48. '----
  49. 'session.Timeout=20
  50. if request.form("Items").count > 0 then
  51. '--- Checking if these lines are already updated in GL
  52. ARItems="0"
  53. APItems="0"
  54. AOItems="0"
  55. for i=1 to request.form("Items").count
  56. n=request.form("Items")(i)
  57. sys=request.form("Sys"&n)
  58. Item=request.form("Item"&n)
  59. select case sys
  60. case "AR":
  61. ARItems = ARItems & ", " & Item
  62. case "AP":
  63. APItems = APItems & ", " & Item
  64. case "AO":
  65. AOItems = AOItems & ", " & Item
  66. end select
  67. next
  68. errMsg=Server.URLEncode("! <br> . <br><br> .")
  69. Set RS1=Conn.Execute ("SELECT * FROM ARItems WHERE ID IN("& ARItems & ") AND (GL_Update=0)")
  70. if not RS1.eof then
  71. Conn.close
  72. response.redirect "?errMsg=" & errMsg
  73. end if
  74. RS1.Close
  75. Set RS1=Conn.Execute ("SELECT * FROM APItems WHERE ID IN("& APItems & ") AND (GL_Update=0)")
  76. if not RS1.eof then
  77. Conn.close
  78. response.redirect "?errMsg=" & errMsg
  79. end if
  80. RS1.Close
  81. Set RS1=Conn.Execute ("SELECT * FROM AOItems WHERE ID IN("& AOItems & ") AND (GL_Update=0)")
  82. if not RS1.eof then
  83. Conn.close
  84. response.redirect "?errMsg=" & errMsg
  85. end if
  86. RS1.Close
  87. '--- End of Checking if the lines are already updated in GL
  88. DocNo=request.form("DocNo")
  89. creationDate=ShamsiToday()
  90. WarningMsg=""
  91. Set RS1=Conn.Execute ("SELECT GLDocID FROM GLDocs WHERE (GLDocID='"& DocNo & "') AND (GL='"& request.form("GL") & "')")
  92. if not RS1.eof then
  93. Set RS1= Conn.Execute("SELECT Max(GLDocID) AS MaxGLDocID FROM GLDocs WHERE (GL='"& request.form("GL") & "')")
  94. DocNo=RS1("MaxGLDocID")+1
  95. WarningMsg=" .<br> <B>"& DocNo & "</B> ."
  96. end if
  97. RS1.Close
  98. mySQL="INSERT INTO GLDocs (GL, GLDocID, GLDocDate, CreatedDate, CreatedBy, IsTemporary, BySubSystem) VALUES ("&_
  99. request.form("GL") & ", " & DocNo & ", N'" & DocDate & "', N'" & creationDate & "', " & session("ID") & ", 1, 1)"
  100. Conn.Execute(mySQL)
  101. Set RS1 = Conn.Execute("SELECT MAX(ID) AS MaxID FROM GLDocs WHERE (GL="& request.form("GL") & ") AND (GLDocID="& DocNo & ") AND (CreatedDate=N'"& creationDate & "')")
  102. GLDocID=RS1("MaxID")
  103. for i=1 to request.form("Items").count
  104. n=request.form("Items")(i)
  105. sys=request.form("Sys"&n)
  106. Item=request.form("Item"&n)
  107. Lines=request.form("Lines"&n)
  108. for j=1 to Lines
  109. Account=request.form("Account"&n)(j)
  110. GLAccount=request.form("GLAccount"&n)(j)
  111. Description=request.form("Description"&n)(j)
  112. Ref1=request.form("Ref1"&n)(j)
  113. Ref2=request.form("Ref2"&n)(j)
  114. Amount=request.form("Amount"&n)(j)
  115. IsCredit=request.form("IsCredit"&n)(j)
  116. if IsCredit="True" then
  117. IsCredit=1
  118. else
  119. IsCredit=0
  120. end if
  121. if Account="" or Account="0" then
  122. mySQL="INSERT INTO GLRows (GLDoc, GLAccount, Amount, Description, Ref1, Ref2, SYS, Link, IsCredit) VALUES ("&_
  123. GLDocID & ", " & GLAccount & ", " & Amount & ", N'" & Description & "', N'" & Ref1 & "', N'" & Ref2 & "', '" & sys & "', " & Item & ", " & IsCredit & ")"
  124. else
  125. mySQL="INSERT INTO GLRows (GLDoc, Tafsil, GLAccount, Amount, Description, Ref1, Ref2, SYS, Link, IsCredit) VALUES ("&_
  126. GLDocID & ", " & Account & ", " & GLAccount & ", " & Amount & ", N'" & Description & "', N'" & Ref1 & "', N'" & Ref2 & "', '" & sys & "', " & Item & ", " & IsCredit & ")"
  127. end if
  128. Conn.Execute(mySQL)
  129. next
  130. Conn.Execute("UPDATE "& sys & "Items SET GL_Update =0 WHERE ("& sys & "Items.ID='"& Item & "')")
  131. next
  132. Conn.Close
  133. response.redirect "GLMemoDocShow.asp?id="& GLDocID &"&msg="& Server.URLEncode(" .") &"&errmsg="& Server.URLEncode(WarningMsg)
  134. end if
  135. elseif request("act")="showItems" then
  136. ' session.Timeout=120
  137. Set RS1= Conn.Execute("SELECT Max(GLDocID) AS MaxGLDocID FROM GLDocs WHERE (GL='"& OpenGL & "')")
  138. DocNo=RS1("MaxGLDocID")+1
  139. RS1.Close
  140. Set RS1= Nothing
  141. %>
  142. <BR>
  143. <input type="hidden" Name='tmpDlgArg' value=''>
  144. <input type="hidden" Name='tmpDlgTxt' value=''>
  145. <FORM METHOD=POST ACTION="?act=SubmitDoc" onsubmit="return checkValidation();" >
  146. <TABLE class="RepTable" width='90%' align='center'>
  147. <TR>
  148. <TD dir='rtl' align='center'>
  149. <table width='100%'>
  150. <tr>
  151. <td style="border:none;width:60px;text-align:left;"> :</td>
  152. <td style="border:none;width:60px;">
  153. <INPUT NAME="GL" TYPE="Hidden" Value="<%=OpenGL%>">
  154. <INPUT NAME="DocNo" TYPE="text" Class="RepGeneralInput" Value="<%=DocNo%>"></td>
  155. <td style="border:none;width:*;"></td>
  156. <td style="border:none;width:60px;text-align:left;">:</td>
  157. <td style="border:none;width:60px;">
  158. <INPUT NAME="DocDate" TYPE="text" Class="RepGeneralInput" Value="" onBlur="acceptDate(this);"></td>
  159. </tr>
  160. <tr>
  161. <td style="border:none;text-align:left;">:</td>
  162. <td colspan='4' style="border:none;width:60px;">
  163. <INPUT NAME="SearchBox" TYPE="Text" style="border:1 solid black;width:150px;" Value="" onKeyPress="return handleSearch();"></td>
  164. </tr>
  165. </table>
  166. </TD>
  167. </TR>
  168. </TABLE>
  169. <div align='center' id='errors'></div>
  170. <SCRIPT LANGUAGE="JavaScript">
  171. <!--
  172. function documentKeyDown() {
  173. var theKey = window.event.keyCode;
  174. var obj = window.event.srcElement;
  175. if (theKey == 114) {
  176. if (obj.name=="SearchBox"){document.all.SearchBox.select();};
  177. window.event.keyCode=0;
  178. document.all.SearchBox.focus();
  179. return false;
  180. }
  181. }
  182. document.onkeydown = documentKeyDown;
  183. function checkValidation(){
  184. try{
  185. foundErr=false;
  186. totalItems=document.getElementsByName("Items").length
  187. var checkedCounter = 0;
  188. for (i=0;i<totalItems;i++){
  189. tmpRow=document.getElementsByName("Items")[i].parentNode.parentNode;
  190. if (tmpRow.getElementsByTagName("Input")[0].checked) {
  191. checkedCounter ++;
  192. gla=txt2val(tmpRow.getElementsByTagName("TD")[3].getElementsByTagName("INPUT")[0].value);
  193. if (gla==0){
  194. foundErr=true;
  195. errObj=tmpRow.getElementsByTagName("TD")[3].getElementsByTagName("INPUT")[0];
  196. errMsg=" "
  197. break;
  198. }
  199. rows=tmpRow.getElementsByTagName("TD")[0].rowSpan
  200. for (t=1;t<rows;t++){
  201. tmpRow=tmpRow.nextSibling;
  202. box=tmpRow.getElementsByTagName("TD")[1].getElementsByTagName("INPUT")[0];
  203. check(box);
  204. gla=txt2val(box.value);
  205. if (gla==0){
  206. foundErr=true;
  207. errObj=tmpRow.getElementsByTagName("TD")[1].getElementsByTagName("INPUT")[0];
  208. errMsg=" "
  209. break;
  210. }
  211. }
  212. if (foundErr) break;
  213. }
  214. }
  215. if (checkedCounter==0){
  216. foundErr=true;
  217. errObj=document.all.SearchBox;
  218. errMsg=" ."
  219. }
  220. if (foundErr) {
  221. tmpCol=errObj.style.backgroundColor;
  222. errObj.style.backgroundColor="red";
  223. errObj.focus();
  224. alert("! \n\n"+errMsg);
  225. errObj.style.backgroundColor=tmpCol;
  226. return false;
  227. }
  228. docDate=document.all.DocDate;
  229. if (docDate.value!='' && docDate.value!=null){
  230. if (!acceptDate(docDate))
  231. return false;
  232. }
  233. else{
  234. docDate.focus();
  235. return false;
  236. }
  237. }catch(e){
  238. //alert(" ");
  239. alert(e);
  240. return false;
  241. }
  242. }
  243. function selectAll(src){
  244. totalItems=document.getElementsByName("Items").length
  245. checked=src.checked
  246. for (i=0;i<totalItems;i++)
  247. document.getElementsByName("Items")[i].checked=checked;
  248. }
  249. var lastFund = 0;
  250. var lastSrch = "";
  251. function handleSearch(){
  252. var theKey=event.keyCode;
  253. if (theKey==13){
  254. event.keyCode=0;
  255. srch=document.all.SearchBox.value;
  256. if (srch == '') {
  257. return;
  258. }
  259. if (srch!=lastSrch){
  260. lastFund = 0;
  261. lastSrch=srch;
  262. }
  263. var found = false;
  264. var text = document.body.createTextRange();
  265. found=text.findText(srch)
  266. for (var i=0; i<=lastFund && found ; i++) {
  267. found=text.findText(srch)
  268. text.moveStart("character", 1);
  269. text.moveEnd("textedit");
  270. }
  271. if (found) {
  272. text.moveStart("character", -1);
  273. text.findText(srch);
  274. text.select();
  275. lastFund++;
  276. theRow=text.parentElement();
  277. while(theRow.nodeName!='TR'){
  278. theRow=theRow.parentNode;
  279. }
  280. // alert(theRow.innerHTML);
  281. if(theRow.getElementsByTagName("input")[0]){
  282. if(theRow.getElementsByTagName("input")[0].type=='checkbox'){
  283. theRow.getElementsByTagName("input")[0].checked=true;
  284. selectRow(theRow);
  285. }
  286. }
  287. theRow.scrollIntoView();
  288. }
  289. else{
  290. if (lastFund == '0'){
  291. alert(' "' + srch +'" .');
  292. }
  293. else{
  294. alert(' "' + srch +'" .');
  295. }
  296. lastFund=0;
  297. lastSrch="";
  298. }
  299. }
  300. }
  301. function selectRow(src){
  302. if (src.getElementsByTagName("Input")[0].checked) {
  303. src.getElementsByTagName("TD")[0].setAttribute("bgColor","yellow")
  304. src.getElementsByTagName("TD")[1].setAttribute("bgColor","yellow")
  305. rows=src.getElementsByTagName("TD")[0].rowSpan
  306. tmpRow=src;
  307. for (i=1;i<rows;i++){
  308. tmpRow=tmpRow.nextSibling;
  309. tmpRow.getElementsByTagName("TD")[1].setAttribute("bgColor","yellow");
  310. tmpRow.getElementsByTagName("TD")[2].setAttribute("bgColor","yellow");
  311. }
  312. }else{
  313. src.getElementsByTagName("TD")[0].setAttribute("bgColor","")
  314. src.getElementsByTagName("TD")[1].setAttribute("bgColor","")
  315. rows=src.getElementsByTagName("TD")[0].rowSpan
  316. tmpRow=src;
  317. for (i=1;i<rows;i++){
  318. tmpRow=tmpRow.nextSibling;
  319. tmpRow.getElementsByTagName("TD")[1].setAttribute("bgColor","");
  320. tmpRow.getElementsByTagName("TD")[2].setAttribute("bgColor","");
  321. }
  322. }
  323. }
  324. function check(src,writeResponse){
  325. badCode = false;
  326. if (window.XMLHttpRequest) {
  327. var objHTTP=new XMLHttpRequest();
  328. } else if (window.ActiveXObject) {
  329. var objHTTP = new ActiveXObject("Microsoft.XMLHTTP");
  330. }
  331. objHTTP.open('GET','xml_GLAccount.asp?id='+src.value,false)
  332. objHTTP.send()
  333. tmpStr = unescape(objHTTP.responseText)
  334. if (tmpStr == ' ')
  335. src.value='';
  336. if (writeResponse)
  337. src.parentNode.nextSibling.innerText=tmpStr;
  338. }
  339. function mask(src,writeResponse){
  340. var theKey=event.keyCode;
  341. if (theKey==32){
  342. event.keyCode=0;
  343. dialogActive=true;
  344. document.all.tmpDlgArg.value="#"
  345. document.all.tmpDlgTxt.value=" :"
  346. var myTinyWindow = window.showModalDialog('../dialog_GenInput.asp',document.all.tmpDlgTxt,'dialogHeight:200px; dialogWidth:440px; dialogTop:; dialogLeft:; edge:None; center:Yes; help:No; resizable:No; status:No;');
  347. dialogActive=false;
  348. if (document.all.tmpDlgTxt.value !="") {
  349. var myTinyWindow = window.showModalDialog('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;');
  350. if (document.all.tmpDlgArg.value!="#"){
  351. Arguments=document.all.tmpDlgArg.value.split("#")
  352. src.value=Arguments[0];
  353. // src.title=Arguments[1];
  354. if (Arguments[1] == ' ')
  355. src.value='';
  356. if (writeResponse)
  357. src.parentNode.nextSibling.innerText=Arguments[1];
  358. }
  359. }
  360. }
  361. else if (theKey >= 48 && theKey <= 57 ) // [0]-[9] are acceptible
  362. return true;
  363. else
  364. return false;
  365. }
  366. //-->
  367. </SCRIPT>
  368. <%
  369. tempCounter = 0
  370. ItemLinks=sqlSafe(trim(replace(request.form("ItemLinks"),vbCrLf," ")))
  371. Do While right(ItemLinks ,1)=","
  372. ItemLinks=left(ItemLinks,len(ItemLinks)-1)
  373. Loop
  374. ItemLinks=replace(ItemLinks," "," ")
  375. ItemLinks=replace(ItemLinks," "," ")
  376. ItemLinks=replace(ItemLinks,", ",",")
  377. ItemLinks=replace(ItemLinks," ,",",")
  378. ItemLinks=replace(ItemLinks,",,",",")
  379. ItemLinks=replace(ItemLinks,",,",",")
  380. ItemLinksArray=split(ItemLinks,",")
  381. sysChequeGLAccountB = "17001"
  382. sysChequeGLAccountBName = " ( )"
  383. sysChequeGLAccountA = "17002"
  384. sysChequeGLAccountAName = " ( )"
  385. sysCashGLAccountB = "11005"
  386. sysCashGLAccountBName = " "
  387. sysCashGLAccountA = "11007"
  388. sysCashGLAccountAName = " "
  389. 'sysCashGLAccountA = "11005"
  390. 'sysCashGLAccountAName = " "
  391. sysVatAccount = "49010"
  392. sysVatAccountName = " "
  393. sys="AR"
  394. sysName=""
  395. sysDefaultGLAccount = "13003"%>
  396. <!--#include file="include_MakeDocItemRows.asp" -->
  397. <% sys="AP"
  398. sysName=""
  399. sysDefaultGLAccount = "41001"%>
  400. <!--#include file="include_MakeDocItemRows.asp" -->
  401. <% sys="AO"
  402. sysName=""
  403. sysDefaultGLAccount = "18001"%>
  404. <!--#include file="include_MakeDocItemRows.asp" -->
  405. </FORM>
  406. <%
  407. someItemsRemained=False
  408. errorMessageText=""
  409. for i=0 to ubound(ItemLinksArray)
  410. if ItemLinksArray(i)<>0 then
  411. someItemsRemained=True
  412. errorMessageText=errorMessageText & " "& ItemLinksArray(i) & " .<br>"
  413. end if
  414. next
  415. if someItemsRemained then
  416. %>
  417. <SCRIPT LANGUAGE="JavaScript">
  418. <!--
  419. document.all.errors.innerHTML='<br><div style="width:60%;font-size:10pt;background-color=yellow;border:2 solid black;"><b>!</b><br><%=errorMessageText%><br></div><br>';
  420. //-->
  421. </SCRIPT>
  422. <%
  423. end if
  424. else
  425. %>
  426. <SCRIPT LANGUAGE="JavaScript">
  427. <!--
  428. function commaNumberMask(src){
  429. var theKey=event.keyCode;
  430. if (theKey==13 || theKey==9 || theKey==32 ){ // [Enter] or [Tab] or [Space]
  431. return true;
  432. }
  433. else if (theKey >= 48 && theKey <= 57) { // [0-9]
  434. return true;
  435. }
  436. else if (theKey == 44 || theKey == 1608) { // comma [,] or [] (the same key)
  437. event.keyCode=44;
  438. return true;
  439. }
  440. return false;
  441. }
  442. //-->
  443. </SCRIPT>
  444. <BR><BR>
  445. <FORM METHOD=POST ACTION="?act=showItems">
  446. <TABLE width='500' align='center' style='border:1 solid black;'>
  447. <TR height='25'>
  448. <TD style="width:200px;text-align:left;"> :</TD>
  449. <TD style="width:60px;">
  450. <INPUT NAME="FromDate" TYPE="text" Class="RepGeneralInput" Value="" onBlur="acceptDate(this);"></TD>
  451. <TD style="width:40px;text-align:left;"> :</TD>
  452. <TD style="width:60px;">
  453. <INPUT NAME="ToDate" TYPE="text" Class="RepGeneralInput" Value="" onBlur="acceptDate(this);"></TD>
  454. </TR>
  455. <TR>
  456. <TD colspan='4' style="text-align:center;">
  457. <table ><tr>
  458. <% Set rs=Conn.Execute("SELECT * FROM AXItemTypes")
  459. Do While not rs.eof
  460. %>
  461. <td><INPUT TYPE="checkbox" NAME="ItemTypes" Value="<%=rs("ID")%>"><%=rs("Name")%>
  462. </td>
  463. <%
  464. rs.MoveNext
  465. Loop%>
  466. </tr></table>
  467. </TD>
  468. </TR>
  469. <TR>
  470. <TD colspan='4' style="text-align:center;">
  471. <span id='ItemNumbers'>
  472. <TEXTAREA style='width:100%;direction:LTR' NAME="ItemLinks" ROWS="3" onChange="document.getElementsByName('ItemTypes')[0].checked=true;" onkeypress="return commaNumberMask(this)"></TEXTAREA><br>
  473. <span style="FONT-SIZE:7pt">* (: [ 81001,81002,81003 ] )</span>
  474. </span>
  475. </TD>
  476. </TR>
  477. <TR height='25'>
  478. <td colspan='4' style="border:none;text-align:center;">
  479. <INPUT TYPE="Submit" style="font-family:tahoma;border:1 solid black; width:50px;" Value=""></td>
  480. </TR>
  481. </TABLE>
  482. <%
  483. end if
  484. conn.Close
  485. %>
  486. <!--#include file="tah.asp" -->