PageRenderTime 43ms CodeModel.GetById 28ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 1ms

/beta/admin/InvItemMng.asp

http://github.com/khaneh/Orders
ASP | 355 lines | 327 code | 23 blank | 5 comment | 22 complexity | 432b75ac08e1e60449a0209f2681410c MD5 | raw file
  1<%@LANGUAGE="VBSCRIPT" CODEPAGE="1256"%><%
  2' Admin
  3PageTitle="���� ��� ������"
  4SubmenuItem=6
  5%>
  6<!--#include file="top.asp" -->
  7<!--#include File="../include_farsiDateHandling.asp"-->
  8<!--#include File="../include_JS_InputMasks.asp"-->
  9<%
 10if request("act")="del" then
 11
 12	mySQL="DELETE FROM InvoiceItemCategoryRelations WHERE (InvoiceItem = '" & sqlSafeNoEnter(request("item")) & "') AND (InvoiceItemCategory = '" & sqlSafeNoEnter(request("cat")) & "')"
 13	Conn.Execute (mySQL)
 14	response.redirect "?act=search&search_box=" & Server.URLEncode(request("nam"))
 15
 16end if
 17
 18function sqlSafeNoEnter (s)
 19  st=s
 20  st=replace(St,"'","`")
 21  st=replace(St,chr(34),"`")
 22  st=replace(St,vbCrLf," ")
 23  sqlSafeNoEnter=st
 24end function
 25
 26function getTypeName(t)
 27	result="����"
 28	select case t
 29	case 0:
 30		result = "����"
 31	case 1
 32		result = "����� x ��� x ��"
 33	case 2
 34		result = "������ ���� �������"
 35	case 3
 36		result = "��� x ��� x ����� x ��� x ��"
 37	case 4
 38		result = "���� ����"
 39	case 5
 40		result = "����� ������"
 41	end select
 42	getTypeName = result
 43end function
 44%>
 45<style>
 46	Input { font-family: Tahoma;font-size: 8pt;height:25px;}
 47	TextArea { font-family: Tahoma;font-size: 9pt;}
 48</style>
 49<SCRIPT LANGUAGE="JavaScript">
 50<!--
 51var noNextField = false;
 52var xmlDoc = null;
 53function loadXML(xmlFile) 
 54{ 
 55 try //Internet Explorer
 56 {
 57	xmlDoc = new ActiveXObject("Microsoft.XMLDOM")
 58	xmlDoc.async=false; 
 59	xmlDoc.onreadystatechange=verify; 
 60	xmlDoc.load(xmlFile); 
 61	xmlObj=xmlDoc.documentElement; 
 62 }
 63 catch(e) 
 64 {
 65	try // Firefox
 66	{
 67	xmlDoc = document.implementation.createDocument("","",null);
 68	xmlDoc.async=false; 
 69	xmlDoc.load(xmlFile); 
 70	//alert(xmlFile);
 71	//alert(xmlDoc.hasChildNodes());
 72	}
 73	catch (e) {alert(e.message)}
 74 }
 75 try
 76 {
 77	// xmlDoc.async=false; 
 78	// xmlDoc.onreadystatechange=verify; 
 79	 //xmlDoc.load(xmlFile); 
 80	 //xmlObj=xmlDoc.documentElement; 
 81 }
 82 catch(e) {alert(e.message)}
 83}
 84
 85function verify() 
 86{ 
 87 // 0 Object is not initialized 
 88 // 1 Loading object is loading data 
 89 // 2 Loaded object has loaded data 
 90 // 3 Data from object can be worked with 
 91 // 4 Object completely initialized 
 92 if (xmlDoc.readyState != 4) 
 93 { 
 94   return false; 
 95 } 
 96}
 97function copyInfo(index){
 98	var myObj=document.getElementsByTagName("table")['result'].getElementsByTagName("tr")[index];
 99	document.all.name_box.value			= myObj.getElementsByTagName("td").item(1).innerText;
100	document.all.enbl_box.checked		= document.getElementsByName("theEnbl")[index-1].checked;
101	document.all.vat_box.checked		= document.getElementsByName("theVat")[index-1].checked;
102	document.all.fee_box.value			= myObj.getElementsByTagName("td").item(4).innerText;
103	document.all.id_box.value			= myObj.getElementsByTagName("input").item(0).value;
104	document.all.type_box.selectedIndex	= myObj.getElementsByTagName("input").item(1).value;
105	document.all.InvItm_box.value		= myObj.getElementsByTagName("td").item(5).innerText;
106	document.all.categories_box.innerHTML="";
107
108	loadXML('xml_InvoiceItemCategories.asp?id='+document.all.id_box.value)
109	
110	if(xmlDoc.hasChildNodes()){
111	
112		for (i = 0 ; i < xmlDoc.childNodes[1].childNodes.length ; i++){
113			document.all.categories_box.innerHTML += "<A HREF='?act=del&item=" + document.all.id_box.value + "&cat=" + xmlDoc.childNodes[1].childNodes[i].getAttribute("id") + "&nam=" + escape (document.all.name_box.value) + "' title='���' style='text-decoration:none;color:red;'><B>x</B></A> " + xmlDoc.childNodes[1].childNodes[i].text + "<BR>";
114		}
115	}
116	else{
117		document.all.categories_box.innerHTML="<FONT COLOR='red'>Error</FONT>";
118	}
119	document.all.name_box.select();
120	document.all.name_box.focus();
121}
122function checkValidation(){
123	return true;
124}
125//-->
126</SCRIPT>
127<br>
128<font face="tahoma">
129<TABLE border="0" cellspacing="0" cellpadding="2" dir="RTL" width="700" align="center">
130<TR bgcolor="#AACCCC">
131	<TD><FORM METHOD=POST ACTION="?act=search"><TABLE>
132	<TR><%'---------------------------------------------------SAM----------------------------------------------------------------%>
133		<TD>���:</TD>
134		<TD><INPUT TYPE="text" NAME="search_box" maxlength="50" size="25" tabIndex="2" value=<%=request.form("search_box")%>></TD>
135		<TD>�� �����</TD>
136		<TD><INPUT TYPE="text" NAME="from_box" value='<%=request.form("from_box")%>' size="10" tabIndex="3"></TD>
137		<TD>�� �����</TD>
138		<TD><INPUT TYPE="text" NAME="to_box" value='<%=request.form("to_box")%>' size="10" tabIndex="4"></TD>
139		<TD>��� ����� ���� ����� ���� ����</TD>
140		<TD><INPUT type='checkbox' <%if request.form("enable_chk") = "on" then response.write("checked='checked'")%> name='enable_chk'></TD>
141		<TD><INPUT TYPE="submit" Name="Submit" Value="�����" style="width:100px; font-family:tahoma,arial;"></TD>
142	</TR>
143	</TABLE></TD></FORM>
144</TR>
145
146<TR bgcolor="#CCCCAA">
147	<TD><FORM METHOD=POST ACTION="?act=add" onSubmit="return checkValidation();">
148	<TABLE width="100%" >
149	<TR>
150		<TD>��� ����</TD>
151		<TD><INPUT checked disabled TYPE="checkbox">����</TD>
152		<TD>��� (���� �����)</TD>
153		<TD>����</TD>
154	</TR>
155	<TR>
156		<TD valign='top'>
157			<TEXTAREA NAME="name_box" rows="3" cols="30"></TEXTAREA>
158		</TD>
159		<TD valign='top'><INPUT TYPE="checkbox" NAME="enbl_box"></TD>
160		<TD valign='top'>
161			<SELECT NAME="type_box" style="font-family:tahoma;width:200px;">
162				<OPTION Value="0" >����</OPTION>
163				<OPTION Value="1" >����� x ��� x ��</OPTION>
164				<OPTION Value="2" >������ ���� �������</OPTION>
165				<OPTION Value="3" >��� x ��� x ����� x ��� x ��</OPTION>
166				<OPTION Value="4" >���� ����</OPTION>
167				<OPTION Value="5" >����� ������</OPTION>
168			</SELECT>
169		</TD>
170		<TD valign='top'><INPUT TYPE="Text" NAME="fee_box"></TD>
171	</TR>
172	<TR>
173		<TD>
174			�� ����: &nbsp;<INPUT TYPE="Text" NAME="id_box">
175		</TD>
176		<TD>�� ����/����� �����: </TD>
177		<TD><INPUT TYPE="Text" NAME="InvItm_box" dir=LTR style="text-align:right"></TD>
178		<TD align='center'>������ �� ���� ������: <INPUT type='checkbox' name='vat_box'></TD>
179	</TR>
180	<TR>
181		<TD colspan=4><hr></TD>
182	</TR>
183	<TR>
184		<TD valign=top align=left>���� ���� ��� ����:</TD>
185		<TD colspan=3>
186			<div id="categories_box">		
187			</div>
188		</TD>
189	</TR>
190	<TR>
191		<TD align=left>������ ���� ����:</TD>
192		<TD>
193			<SELECT NAME="cat_box" style="font-family:tahoma;width:200px;">
194			<OPTION Value="0" >-- ������ ���� --</OPTION>
195<%
196			mySQL="SELECT * FROM InvoiceItemCategories ORDER BY [Name]" 
197			set RS=Conn.Execute(mySQL)
198			
199			Do While NOT RS.eof
200%>
201				<OPTION Value="<%=RS("id")%>" ><%=RS("name")%></OPTION>
202<%
203				RS.MoveNext
204			Loop
205%>			</SELECT>
206		</TD>
207		<TD valign='top' align=left colspan=2>
208			<INPUT TYPE="submit" Name="Submit" Value="�����" style="width:100px; font-family:tahoma,arial;">
209		</TD>
210	</TR>
211	</TABLE></TD></FORM>
212</TR>
213</TABLE>
214<%
215
216myCriteria= "REPLACE([name], ' ', '') LIKE REPLACE(N'%"& sqlSafeNoEnter(request("search_box")) & "%', ' ', '')"
217if request("act")="add" AND request.form("name_box")<>"" AND isnumeric(request.form("id_box")) then
218	
219	if request.form("enbl_box")="on" then
220		enable=1
221	else
222		enable=0
223	end if
224
225	ItemCategory =			clng(request.form("cat_box"))
226	ItemID =				clng(request.form("id_box"))
227	ItemName =				sqlSafeNoEnter(request.form("name_box"))
228	ItemType =				sqlSafeNoEnter(request.form("type_box"))
229	ItemFee =				sqlSafeNoEnter(request.form("fee_box"))
230	RelatedInventoryItem =	request.form("InvItm_box")
231	If request.form("vat_box")="on" Then 
232		ItemVat = 1
233	Else
234		ItemVat = 0 
235	End If 
236
237	if isnumeric(RelatedInventoryItem) then 
238		RelatedInventoryItem = clng(RelatedInventoryItem) 
239	else
240		RelatedInventoryItem = 0
241	End if
242	if RelatedInventoryItem=0 then RelatedInventoryItem=-1
243
244
245	mySQL="SELECT ID FROM InvoiceItems WHERE ([ID]='"& ItemID & "')"
246	set RS1=Conn.Execute (mySQL)
247	If ItemVat Then 
248		hasVat = 1 
249	Else 
250		hasVat = 0
251	End If 
252	if RS1.eof then
253		mySQL="INSERT INTO InvoiceItems ([ID], [name], [Enabled], [Type], [Fee], [RelatedInventoryItemID], hasVat) VALUES ("&_
254			ItemID & ", N'"& ItemName& "', '" & enable & "','" & ItemType & "', '" & ItemFee & "', '" & RelatedInventoryItem & "', " & hasVat & ") "
255	else
256		mySQL="UPDATE InvoiceItems SET [Name]=N'" & ItemName & "',[Enabled]='" & enable & "', [Type]='" & ItemType & "', [Fee]='" & ItemFee & "', [RelatedInventoryItemID]='" & RelatedInventoryItem & "', hasVat= '" & hasVat & "' WHERE ([ID]='"& ItemID & "')"
257	end if
258	RS1.close
259
260	Conn.Execute (mySQL)
261
262	if ItemCategory<>0 then
263
264		mySQL="SELECT * FROM InvoiceItemCategoryRelations WHERE (InvoiceItem = '" & ItemID & "' AND InvoiceItemCategory='" & ItemCategory & "')"
265		set RS1=Conn.Execute (mySQL)
266		if RS1.eof then
267			mySQL="INSERT INTO InvoiceItemCategoryRelations (InvoiceItem, InvoiceItemCategory) VALUES ('" & ItemID & "', '" & ItemCategory & "')"
268			Conn.Execute (mySQL)
269		end if
270		RS1.close
271	end if
272
273	response.write "<B>Updated�</B><BR>"
274
275	myCriteria= "[name] LIKE N'"& ItemName & "'"
276end if
277if request("act")="search" OR request("act")="add" then
278	'---------------------------------------------------------------SAM------------------------------------------------------
279	fromCode = 0
280	toCode = 0
281	isEnabled = ""
282	if isnumeric(request.form("from_box")) Then fromCode = cdbl(request.form("from_box"))
283	if isnumeric(request.form("to_box")) then toCode = cdbl(request.form("to_box"))
284	'if fromCode < 30000 then fromCode = 30000
285	if toCode > 999999 then toCode = 99999
286	if request.form("enable_chk") = "on" then isEnabled = " AND (Enabled = 1) "
287	'response.write(toCode)
288	mySQL="SELECT * FROM InvoiceItems WHERE ("& myCriteria & ") AND ([ID] BETWEEN " & fromCode & " AND " & toCode & ")" & isEnabled & "ORDER BY [ID]"
289	set RS1=Conn.Execute (mySQL)
290	if not RS1.eof then
291		tmpCounter=0
292%>
293		<center>
294		<br>
295		<TABLE border="1" cellspacing="0" cellpadding="2" dir="RTL" borderColor="#555588" width="60%" id="result">
296			<TR bgcolor="#CCCCFF">
297				<TD style="height:50px;">�� ����</TD>
298				<TD>��� ����</TD>
299				<TD>����</TD>
300				<TD width=120>��� ���� �����</TD>
301				<TD>����</TD>
302				<TD>�� ����/�����</TD>
303				<TD>������ �� ���� ������</TD>
304			</TR>
305<%
306		MaxListItems=9999
307		Do while (not RS1.eof AND tmpCounter < MaxListItems)
308			tmpCounter = tmpCounter + 1
309			if tmpCounter mod 2 = 1 then
310				tmpColor="#FFFFFF"
311				tmpColor2="#FFFFBB"
312			Else
313				tmpColor="#DDDDDD"
314				tmpColor2="#EEEEBB"
315			End if 
316			'alert(this.getElementByTagName('td').items(0).data);
317%>
318			<TR bgcolor="<%=tmpColor%>" style="cursor: pointer;" onMouseOver="this.style.backgroundColor='<%=tmpColor2%>'" onMouseOut="this.style.backgroundColor='<%=tmpColor%>'" onclick="copyInfo(this.rowIndex)">
319				<TD style="height:50px;"><%=RS1("ID")%>
320					<input type="hidden" value="<%=RS1("ID")%>">
321					<input type="hidden" value="<%=RS1("Type")%>">
322					</TD>
323				<TD><span id="theName"><%=RS1("name")%>&nbsp;</span></TD>
324				<TD align="center" dir="LTR"><INPUT disabled TYPE="checkbox" Name="theEnbl" <%if RS1("Enabled") then response.write "checked"%>></TD>
325				<TD><%=getTypeName(RS1("Type"))%>&nbsp;</TD>
326				<TD dir=LTR align=right><%=RS1("Fee")%>&nbsp;</TD>
327				<TD dir=LTR align=right><%=RS1("RelatedInventoryItemID")%>&nbsp;</TD>
328				<TD align='center'><INPUT disabled type='checkbox' name='theVat' <%if RS1("hasVat") then response.write "checked" %>></TD>
329			</TR>
330<%			RS1.moveNext
331		Loop
332		if not RS1.eof then
333%>
334			<TR bgcolor="#CCCCFF" >
335				<TD style="height:50px;">*</TD>
336				<TD colspan="3">����� ���� �� ���� ���.<br> ����� �� ������� ����.</TD>
337			</TR>
338
339<%		End if
340%>
341		</TABLE>
342		</center>
343<%		
344	End if
345end if
346Conn.Close
347%>
348
349</font>
350<SCRIPT LANGUAGE="JavaScript">
351<!--
352document.all.search_box.focus();
353//-->
354</SCRIPT>
355<!--#include file="tah.asp" -->