PageRenderTime 16ms CodeModel.GetById 2ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 1ms

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