PageRenderTime 14ms CodeModel.GetById 2ms app.highlight 6ms RepoModel.GetById 2ms app.codeStats 0ms

/beta/accounting/SubsysDocsEdit.asp

http://github.com/khaneh/Orders
ASP | 464 lines | 398 code | 39 blank | 27 comment | 49 complexity | 666343d78509ef4351e8855671680b63 MD5 | raw file
  1<%@LANGUAGE="VBSCRIPT" CODEPAGE="1256"%><%
  2'Accounting (8)
  3PageTitle= "��� ��� ��� �����"
  4SubmenuItem=9
  5if not Auth(8 , "C") then NotAllowdToViewThisPage() ' this is the same as viewing subsystem memos
  6%>
  7<!--#include file="top.asp" -->
  8<!--#include File="../include_farsiDateHandling.asp"-->
  9<!--#include File="../include_JS_InputMasks.asp"-->
 10<STYLE>
 11	.GLTable {font-family:tahoma; background-color:#330099;border:solid 1px Black;}
 12	.GLTable TR {background-color:#F0F0F0;}
 13	.HeaderTD {font-size:12pt;font-weight:bold;background-color:#FFCC66;}
 14	.RowsTD {font-size:9pt;padding-bottom:10px;}
 15	.GeneralInput {width:70px; font-family:tahoma; font-size:8pt; border:1pt solid gray; background:transparent; direction: LTR; }
 16</STYLE>
 17<%
 18if request("act")="submitEdit" then
 19
 20	id=request("id")
 21	if id="" or not isnumeric(id) then
 22		call showAlert ("����� ��� ��� ���.",CONST_MSG_ERROR) 
 23		Conn.close
 24		response.end
 25	end if
 26	'----- Check GL is closed
 27	if (session("IsClosed")="True") then
 28		Conn.close
 29		response.redirect "?errMsg=" & Server.URLEncode("���! ��� ���� ���� ���� ��� � ��� ���� �� ����� �� �� ������.")
 30	end if 
 31	'----
 32	mySQL="SELECT * FROM GLDocs WHERE id="& id & " and  (GLDocs.GL = "& OpenGL & ")"
 33	set RS1=conn.execute(mySQL)
 34	errMessage=""
 35	if RS1.eof then
 36		errMessage="���! ���� ����  �� ��� ��� ���� ���� �����."
 37	else
 38		GLMemoNo=RS1("GLDocID")
 39		GLMemoDate=RS1("GLDocDate")
 40		if RS1("IsTemporary") then
 41			IsTemporary=1
 42		else
 43			IsTemporary=0
 44		end if
 45
 46		if not RS1("BySubSystem") then
 47			errMessage="��� �� ��� �������� ����."
 48		elseif RS1("deleted") OR RS1("IsRemoved") then
 49			errMessage="��� ��� ��� ��� � ����� ������ �� ���� �����."
 50		elseif RS1("IsFinalized") then
 51			errMessage="��� ��� ���� ��� � ����� ������ �� ���� �����."
 52		elseif RS1("IsChecked") then
 53			errMessage="��� ��� ����� ��� � ����� ������ �� ���� �����."
 54		end if 
 55	end if
 56
 57	if errMessage<>"" then
 58		response.write "<br><br>"
 59		call showAlert (errMessage,CONST_MSG_ERROR) 
 60		Conn.close
 61		response.end
 62	end if
 63	RS1.close
 64
 65
 66	GLDoc = id
 67	creationDate = shamsiToday()
 68
 69	totalRows = request.form("GLDocRows").count
 70	'--- Checking For Errors:
 71	if totalRows > 0 then
 72		mySQL="SELECT DISTINCT LEFT(Description, 5) AS Des, SYS, Link FROM GLRows INNER JOIN GLDocs ON GLRows.GLDoc = GLDocs.ID WHERE (GLRows.ID IN ("
 73		for i=1 to totalRows - 1
 74			mySQL = mySQL & request.form("GLDocRows")(i) & ", "
 75		next
 76		mySQL = mySQL & request.form("GLDocRows")(i) & ")) AND (GLDocs.ID = '"& GLDoc & "') AND (GLDocs.GL = '"& OpenGL & "') AND (GLRows.Deleted = 0)"
 77	else
 78		response.write "<br>��� ��� ������ ����..."
 79		response.end
 80	end if
 81
 82	set RS1=conn.execute(mySQL)
 83
 84	errorFound = false
 85	Do While not RS1.eof AND not errorFound 
 86		if RS1("Des")<>"�����" then
 87			mySQL2="SELECT Voided, GL_Update FROM "& trim(RS1("SYS")) & "Items WHERE (ID = "& RS1("Link") & ")"
 88			set RS2=conn.execute(mySQL2)
 89			if RS2("Voided") AND not RS2("GL_Update") then
 90				errSYS=RS1("SYS")
 91				errLink=RS1("Link")
 92				errorFound = true
 93				RS2.close
 94				exit do
 95			end if
 96			RS2.close
 97		end if
 98		RS1.moveNext
 99	Loop
100	RS1.close
101	
102	if errorFound then
103		response.write "<br>Error Found!:<br>" 
104		response.write "<br>SYS:" & errSYS
105		response.write "<br>Link:" & errLink
106		response.end
107	end if
108	'--- End of checking for errors.
109	'--- 
110
111	'--- Actual Deleting 
112	set RS1=conn.execute(mySQL)
113	Do While not RS1.eof 
114		tempDes =	RS1("Des")
115		tempSYS =	trim(RS1("SYS"))
116		tempLink=	RS1("Link")
117		if tempDes="�����" then
118			' This is a reverse memo
119			mySQL2="SELECT * FROM GLRows WHERE (SYS = '"& tempSYS & "') AND (Link = "& tempLink & ") AND (deleted = 0) AND (Description NOT Like N'�����%')"
120			set RS2=conn.execute(mySQL2)
121			if RS2.eof then
122				' No Direct Memo, No need to Update GL
123				tempGL_Update=0
124			else
125				' Has A Direct Memo. Must be added to GL later
126				tempGL_Update=1
127			end if
128		else
129			' This is a direct memo
130			mySQL2="SELECT Voided, GL_Update FROM "& tempSYS & "Items WHERE (ID = "& tempLink & ")"
131			set RS2=conn.execute(mySQL2)
132			if RS2("Voided") then
133				' Item is voided. No need to Update GL
134				tempGL_Update=0
135			else
136				' Item is not voided. Must be added to GL later
137				tempGL_Update=1
138			end if
139			RS2.close
140		end if
141
142		mySQL2="UPDATE "& tempSYS & "Items SET GL_Update="& tempGL_Update & " WHERE (ID = "& tempLink & ")"
143		Conn.Execute (mySQL2)
144
145		mySQL2="UPDATE GLRows SET deleted = 1 WHERE (GLDoc='"& GLDoc & "') AND (deleted = 0) AND (SYS = '"& tempSYS & "') AND (Link = "& tempLink & ")"
146		Conn.Execute (mySQL2)
147
148		RS1.moveNext
149	Loop
150	RS1.close
151	'--- End of actual deleting 
152	'--- 
153
154	mySQL = "SELECT * FROM GLRows WHERE (GLDoc='"& GLDoc & "') AND (deleted = 0)"
155	set RS1 = Conn.execute(mySQL)
156	if RS1.eof then
157		RS1.close
158
159		mySQL="SELECT MIN(GLDocID) AS MinGLDocID FROM GLDocs WHERE (GL = "& OpenGL & ")"
160		set RS1=conn.execute(mySQL)
161		RemovedGLDocID = clng(RS1("MinGLDocID")) - 1
162		RS1.close
163		Conn.Execute("UPDATE GLDocs SET IsRemoved=1, RemovedDate=N'"& shamsiToday() & "', RemovedBy='"& session("ID") & "', OldGLDocID=GLDocID, GLDocID="& RemovedGLDocID & "  WHERE (ID = "& GLDoc & ")")
164
165		response.redirect "GLMemoDocShow.asp?id=" & GLDoc & "&msg=" & Server.URLEncode("��� ��� �������� ����� ��.")
166	else
167		RS1.close
168		'---- Creating a new GLDoc 
169		mySQL="INSERT INTO GLDocs (GL, GLDocID, GLDocDate, CreatedDate, createdBy, BySubSystem, IsTemporary) VALUES ("& openGL & " , "& GLMemoNo & ", N'"& GLMemoDate & "' , N'"& creationDate & "', "& session("ID") & ", 1, "& IsTemporary & ");SELECT @@Identity AS NewGLDoc"
170		set RS1 = Conn.execute(mySQL).NextRecordSet
171		NewGLDoc = RS1("NewGLDoc")
172		RS1.close
173		'---- 
174
175		'---- Inserting new GLRows 
176		mySQL="INSERT INTO GLRows ( GLDoc, GLAccount, Tafsil, Amount, Description, Ref1, Ref2, SYS, Link, IsCredit, deleted) SELECT '"& NewGLDoc & "' AS GLDoc, GLAccount, Tafsil, Amount, Description, Ref1, Ref2, SYS, Link, IsCredit, deleted FROM GLRows WHERE (GLDoc = "& GLDoc & ") AND (Deleted=0) "
177		conn.Execute(mySQL)
178
179		'---- Marking old GLDoc and its remaining GLRows as DELETED
180		conn.Execute("UPDATE GLRows SET deleted = 1 WHERE (GLDoc = "& GLDoc & ")")
181		conn.Execute("UPDATE GLDocs SET deleted = 1 WHERE (ID = "& GLDoc & ")")
182		'---- 
183
184		response.redirect "GLMemoDocShow.asp?id=" & NewGLDoc & "&msg=" & Server.URLEncode("������ ��� �������� ����� ��.")
185	end if
186
187	'---- 
188
189'-----------------------------------------------------------------------------------------------------
190'--------------------------------------------------------------------------------------- Show a GL Doc
191'-----------------------------------------------------------------------------------------------------
192elseif request("act")="show" then
193
194	id=request("id")
195	if id="" or not isnumeric(id) then
196		call showAlert ("����� ��� ��� ���.",CONST_MSG_ERROR) 
197		Conn.close
198		response.end
199	end if
200
201	mySQL="SELECT * FROM GLDocs WHERE id="& id & " and  (GLDocs.GL = "& OpenGL & ")"
202	set RS1=conn.execute(mySQL)
203	errMessage=""
204	if RS1.eof then
205		errMessage="���! ���� ����  �� ��� ��� ���� ���� �����."
206	else
207		GLMemoNo=RS1("GLDocID")
208		GLMemoDate=RS1("GLDocDate")
209		if RS1("IsTemporary") then
210			IsTemporary=1
211		else
212			IsTemporary=0
213		end if
214
215		if not RS1("BySubSystem") then
216			errMessage="��� �� ��� �������� ����."
217		elseif RS1("deleted") OR RS1("IsRemoved") then
218			errMessage="��� ��� ��� ��� � ����� ������ �� ���� �����."
219		elseif RS1("IsFinalized") then
220			errMessage="��� ��� ���� ��� � ����� ������ �� ���� �����."
221		elseif RS1("IsChecked") then
222			errMessage="��� ��� ����� ��� � ����� ������ �� ���� �����."
223		end if 
224	end if
225
226	if errMessage<>"" then
227		response.write "<br><br>"
228		call showAlert (errMessage,CONST_MSG_ERROR) 
229		Conn.close
230		response.end
231	end if
232	RS1.close
233
234
235	mySQL="SELECT GLDocs.GLDocID, GLDocs.ID, GLDocs.GLDocDate, GLDocs.CreatedBy, GLRows.ID AS RowID, GLRows.GLAccount, GLRows.Tafsil, GLRows.Amount, GLRows.Description, GLRows.SYS, GLRows.Link, GLRows.IsCredit, GLAccounts.Name FROM GLDocs INNER JOIN GLRows ON GLDocs.ID = GLRows.GLDoc INNER JOIN GLAccounts ON GLRows.GLAccount = GLAccounts.ID WHERE (GLDocs.id="& id & ") AND (GLRows.deleted = 0) AND (GLDocs.GL = "& OpenGL & ") AND (GLAccounts.GL = "& OpenGL & ") ORDER BY GLRows.ID"
236	set RS1=conn.execute(mySQL)
237
238	GLDocID = RS1("GLDocID")
239	Creator = RS1("CreatedBy")
240%>
241	<SCRIPT LANGUAGE="JavaScript">
242	<!--
243	var selectedRowsBalance=0;
244	function selectRow(srcRow){
245		check = srcRow.getElementsByTagName("INPUT")[0];
246		sysLinkName=srcRow.getElementsByTagName("INPUT")[1].name;
247
248		if (check.checked){
249			if (sysLinkName!='SysLink'){
250				for (j=0;j<document.getElementsByName(sysLinkName).length;j++){
251					tempRow = document.getElementsByName(sysLinkName)[j].parentNode.parentNode
252					tempRow.getElementsByTagName("INPUT")[0].checked=true
253
254					selectedRowsBalance = selectedRowsBalance + parseInt(tempRow.getElementsByTagName("INPUT")[2].value);
255
256					for(i=0; i<tempRow.getElementsByTagName("TD").length; i++){
257						tempRow.getElementsByTagName("TD")[i].setAttribute("bgColor","yellow")
258					}
259				}
260			}else{
261				selectedRowsBalance = selectedRowsBalance + parseInt(srcRow.getElementsByTagName("INPUT")[2].value);
262				for(i=0; i<srcRow.getElementsByTagName("TD").length; i++){
263					srcRow.getElementsByTagName("TD")[i].setAttribute("bgColor","yellow")
264				}
265			}
266		}else{
267			if (sysLinkName!='SysLink'){
268				for (j=0;j<document.getElementsByName(sysLinkName).length;j++){
269					tempRow = document.getElementsByName(sysLinkName)[j].parentNode.parentNode
270					tempRow.getElementsByTagName("INPUT")[0].checked=false
271
272					selectedRowsBalance = selectedRowsBalance - parseInt(tempRow.getElementsByTagName("INPUT")[2].value);
273
274					for(i=0; i<tempRow.getElementsByTagName("TD").length; i++){
275						tempRow.getElementsByTagName("TD")[i].setAttribute("bgColor","")
276					}
277				}
278			}else{
279				selectedRowsBalance = selectedRowsBalance - parseInt(srcRow.getElementsByTagName("INPUT")[2].value);
280				for(i=0; i<srcRow.getElementsByTagName("TD").length; i++){
281					srcRow.getElementsByTagName("TD")[i].setAttribute("bgColor","")
282				}
283			}
284		}
285	}
286
287	function selectAll(src){
288		if(src.checked){
289			checks = document.getElementsByName("GLDocRows");
290			selectedRowsBalance = 0;
291			for(j=0; j< checks.length; j++){
292				tempRow=checks[j].parentNode.parentNode
293				tempRow.getElementsByTagName("INPUT")[0].checked=true;
294				selectedRowsBalance = selectedRowsBalance + parseInt(tempRow.getElementsByTagName("INPUT")[2].value);
295				for(i=0; i<tempRow.getElementsByTagName("TD").length; i++){
296					tempRow.getElementsByTagName("TD")[i].setAttribute("bgColor","yellow")
297				}
298			}
299		}
300		else{
301			selectedRowsBalance = 0;
302			for(j=0; j< checks.length; j++){
303				tempRow=checks[j].parentNode.parentNode
304				tempRow.getElementsByTagName("INPUT")[0].checked=false;
305				for(i=0; i<tempRow.getElementsByTagName("TD").length; i++){
306					tempRow.getElementsByTagName("TD")[i].setAttribute("bgColor","")
307				}
308			}
309		}
310	}
311
312	function checkAndSubmit(action){
313		if (action=='Edit'){
314			if (selectedRowsBalance != 0){
315				alert("�� ��� ������ ��� ���� ������!");
316				return false;
317			}
318		}else if (action=='Delete'){
319			if (confirm('��� ����� ����� �� �� ������ ��� ��� �� �� ��� ���� ��� ���Ͽ')){
320				checkBox=document.getElementsByName('checkAll')[0]
321				checkBox.checked=true;
322				selectAll(checkBox);
323				checkAndSubmit('Edit');
324			}
325			return false;
326		}
327		document.all.act.value="submit"+action;
328		document.forms[0].submit();
329	}
330	//-->
331	</SCRIPT>
332	<br><br>
333	<FORM METHOD=POST ACTION="?">
334		<INPUT TYPE="hidden" name="id" value="<%=id%>">
335
336		<TABLE Border="0" width='90%' align=center Cellspacing="1" Cellpadding="5" class="GLTable">
337		<TBODY Id="RowsTable">
338		<tr style='height:70px;background-color:#FFFFDD;'>
339			<td class='HeaderTD' colspan='7' align='center'> ������ ��� �������� ��� ����� <br></td>
340		</tr>
341		<tr style='height:1px;background-color:black;'>
342			<td colspan=7 ></td>
343		</tr>
344		<tr style='height:30px;background-color:#EEEEEE;'>
345			<td colspan='3'>��� ����� <%=GLDocID%></td>
346			<td colspan='2'>����� ���: <%=RS1("id")%></td>
347			<td colspan='2'>����� ���: <span dir=ltr><%= RS1("GLDocDate")%></span></td>
348		</tr>
349		<tr style='height:1px;background-color:black;'>
350			<td colspan=7 ></td>
351		</tr>
352		<tr style='height:40px;background-color:#DDDDDD;'>
353			<td style="width:26; border-right:none;"> # </td>
354			<td style="width:50; ">������</td>
355			<td style="width:50; ">����</td>
356			<td style="width:170;">��� ���� ����</td>
357			<td style="width:500;">���</td>
358			<td style="width:80;">������</td>
359			<td style="width:80;">��������</td>
360		</tr>
361<%
362		Do while not RS1.eof
363			i = i + 1
364			GLAccount = RS1("GLAccount")
365			accTitle = RS1("name")
366			theDescription = RS1("Description")
367			Amount = RS1("Amount")
368			IsCredit = RS1("IsCredit")
369			Tafsil = RS1("Tafsil")
370
371			credit = ""
372			debit = ""
373			if IsCredit  then 
374				credit = Separate(Amount)
375				totalCredit = totalCredit + cdbl(Amount)
376			else
377				debit = Separate(Amount)
378				totalDebit = totalDebit + cdbl(Amount)
379				Amount = -1 * cdbl(Amount)
380			end if
381%>
382			<tr>
383				<td class='RowsTD' align='center' style='font-size:9pt;color:gray;'><%=i%><br>
384					<INPUT TYPE="checkbox" NAME="GLDocRows" Value='<%=RS1("RowID")%>' onclick='selectRow(this.parentNode.parentNode);'>
385					<INPUT TYPE="hidden" Name='SysLink<%=RS1("Sys")&RS1("Link")%>'>
386					<INPUT TYPE="hidden" Name='Amount' value='<%=Amount%>'>
387				</td>
388				<td class='RowsTD'><%=Tafsil%></td>
389				<td class='RowsTD'><%=GLAccount%></td>
390				<td class='RowsTD'><%=accTitle%></td>
391				<td class='RowsTD'><%=theDescription%></td>
392				<td class='RowsTD'><%=debit%></td>
393				<td class='RowsTD'><%=credit%></td>
394			</tr>
395<%
396		RS1.movenext
397		loop	
398%>
399		<tr style='height:1px;background-color:black;'>
400			<td colspan=7 ></td>
401		</tr>
402		<tr style="height:50px;">
403			<td class='RowsTD' colspan='2' style='font-size:7pt;'>
404				<INPUT TYPE="checkbox" NAME='checkAll' onclick='selectAll(this);'>&nbsp; ������ ���</td>
405			<td class='RowsTD' colspan='3' align='left'><B>��� :</B></td>
406			<td class='RowsTD' style="width:80;"><%=Separate(totalDebit)%></td>
407			<td class='RowsTD' style="width:80;"><%=Separate(totalCredit)%></td>
408		</tr>
409		<tr style='height:1px;background-color:black;'>
410			<td colspan=7 ></td>
411		</tr>
412		<tr style="height:50px;">
413			<td class='HeaderTD' colspan='7' align='center'>
414				<INPUT TYPE="hidden" name="act" value="" >
415				<TABLE width='100%'>
416				<TR>
417					<TD class='HeaderTD'><INPUT TYPE="button" value="��� ��� ��� ������ ���" class="GenButton" onclick="checkAndSubmit('Edit');"></TD>
418					<TD class='HeaderTD' align='left'><INPUT TYPE="button" value="������" class="GenButton" onclick="window.location='GLMemoDocShow.asp?id=<%=id%>';"></TD>
419					<TD class='HeaderTD' align='left'><INPUT TYPE="button" value="��� ���� ��� (��� ��� ��)" class="GenButton" Style='border-color:red' onclick="checkAndSubmit('Delete');"></TD>
420				</TR>
421				</TABLE>
422			</td>
423		</tr>
424		</TBODY>
425		</TABLE>
426	</FORM>
427	<BR>
428<%
429	if request("SysLink")<>"" then
430%>
431		<SCRIPT LANGUAGE="JavaScript">
432		<!--
433			sysLinkName='SysLink<%=request("SysLink")%>';
434			a=document.getElementsByName(sysLinkName)[0].parentNode.getElementsByTagName("INPUT")[0];
435			a.checked=true;
436			selectRow(a.parentNode.parentNode);
437			a.focus();
438		//-->
439		</SCRIPT>
440<%
441	end if
442'-----------------------------------------------------------------------------------------------------
443'--------------------------------------------------------------------------------------- Show a GL Doc
444'-----------------------------------------------------------------------------------------------------
445elseif request("act")="find" then
446	
447	sys=left(request("link"),2)
448	lnk=right(request("link"),len(request("link"))-2)
449	sys=sqlSafe(sys)
450	lnk=clng(lnk)
451
452	mySQL="SELECT DISTINCT GLDoc FROM EffectiveGLRows WHERE (GL = "& OpenGL & ") AND (Link = " & lnk & ") AND (SYS = '" & sys & "')"
453	set RS1=conn.execute(mySQL)
454	if RS1.eof then
455		conn.close
456		response.redirect "?errMsg="&Server.URLEncode("���! ��� ���� ���.")
457	else
458		GLDoc= RS1("GLDoc")
459	end if
460	RS1.close
461	conn.close
462	response.redirect "SubsysDocsEdit.asp?act=show&id=" & GLDoc & "&SysLink=" & sys & lnk
463end if %>
464<!--#include file="tah.asp" -->