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