PageRenderTime 37ms CodeModel.GetById 13ms app.highlight 9ms RepoModel.GetById 2ms app.codeStats 1ms

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