/beta/purchase/default.asp

http://github.com/khaneh/Orders · ASP · 359 lines · 298 code · 47 blank · 14 comment · 38 complexity · 63c5688b1ed5dccd7aa8d043543771e7 MD5 · raw file

  1. <%@LANGUAGE="VBSCRIPT" CODEPAGE="1256"%><%
  2. 'Purchase (4)
  3. PageTitle=" "
  4. SubmenuItem=1
  5. if not Auth(4 , 1) then response.redirect "outServiceOrder.asp"
  6. if not Auth(4 , 1) then NotAllowdToViewThisPage()
  7. %>
  8. <!--#include file="top.asp" -->
  9. <!--#include File="../include_farsiDateHandling.asp"-->
  10. <!--#include File="../include_JS_InputMasks.asp"-->
  11. <SCRIPT LANGUAGE="JavaScript">
  12. <!--
  13. function hideIT()
  14. {
  15. if(document.all.tavafogh.checked)
  16. {
  17. document.all.priceTavafoghi.style.visibility= 'visible'
  18. }
  19. else
  20. {
  21. document.all.price.value= ''
  22. document.all.priceComment.value= ''
  23. document.all.priceTavafoghi.style.visibility= 'hidden'
  24. }
  25. }
  26. function hideIT2()
  27. {
  28. if(document.all.tavafogh2.checked)
  29. {
  30. document.all.priceTavafoghi2.style.visibility= 'visible'
  31. }
  32. else
  33. {
  34. document.all.orderID.value= ''
  35. document.all.priceTavafoghi2.style.visibility= 'hidden'
  36. }
  37. }
  38. //-->
  39. </SCRIPT>
  40. <%
  41. catItem1 = request("catItem")
  42. if catItem1="" then catItem1="-1"
  43. goodItem1 = request("goodItem")
  44. if goodItem1="" then goodItem1="-1"
  45. '-----------------------------------------------------------------------------------------------------
  46. '--------------------------------------------------- Delete an Inventory Request for Buy from an order
  47. '-----------------------------------------------------------------------------------------------------
  48. if request("di")="y" then
  49. myRequestID=request("i")
  50. set RSX=Conn.Execute ("SELECT * FROM purchaseRequests WHERE id = "& myRequestID )
  51. if RSX("status")="new" then
  52. Conn.Execute ("update purchaseRequests SET status = 'del' where id = "& myRequestID )
  53. end if
  54. response.redirect "default.asp?radif=" & request("r")
  55. end if
  56. '-----------------------------------------------------------------------------------------------------
  57. '------------------------------------------------------------ Submit an Inventory Item request For Buy
  58. '-----------------------------------------------------------------------------------------------------
  59. if request.form("Submit")=" " then
  60. priceComment = request.form("priceComment")
  61. item = request.form("item")
  62. comment = request.form("comment")
  63. price = request.form("price")
  64. qtty = request.form("qtty")
  65. CreatedBy = session("id")
  66. date1 = request.form("date1")
  67. orderID = request.form("orderID")
  68. if not item = "" then
  69. if price="" then
  70. price = 0
  71. end if
  72. if priceComment="" then
  73. priceComment = "-"
  74. end if
  75. if comment="" then
  76. comment = "-"
  77. end if
  78. if qtty="" then
  79. qtty = "0"
  80. end if
  81. if orderID="" then
  82. orderID = "-1"
  83. end if
  84. if item="-1" then
  85. response.write "<br><br><center>! "
  86. response.write "<br><br><A HREF='default.asp'>ѐ</A></center>"
  87. response.end
  88. end if
  89. set RS4 = conn.Execute ("SELECT * FROM InventoryItems where ID=" & item)
  90. if (RS4.eof) then
  91. otype="-unknown-"
  92. unit=RS4("unit")
  93. else
  94. otype=RS4("Name")
  95. unit=RS4("unit")
  96. end if
  97. RS4.close
  98. mySql="INSERT INTO purchaseRequests (OrderID, TypeName, TypeID, comment, ReqDate, Qtty, CreatedBy, Price, priceComment, DueDate, IsService) VALUES ( "& orderID & ", N'"& otype & "', "& item & " , N'"& comment & "',getDate(), "& Qtty & ", "& CreatedBy & " , "& Price & " , N'"& priceComment & "', dbo.udf_date_solarToDate(" & mid(date1,1,4) & "," & mid(date1,6,2) & "," & mid(date1,9,2) & "), 0 )"
  99. conn.Execute mySql
  100. 'RS1.close
  101. response.write "<center><br><br> </center><br>"
  102. end if
  103. end if
  104. '-----------------------------------------------------------------------------------------------------
  105. '------------------------------------------------------------ Main Inventory Item request For Buy Form
  106. '-----------------------------------------------------------------------------------------------------
  107. %>
  108. <center>
  109. <BR><BR>
  110. <TABLE width="*">
  111. <TR>
  112. <TD valign=top width=50%>
  113. <TABLE border="0" cellspacing="0" cellpadding="2" dir="RTL" align="center" width="350" >
  114. <TR >
  115. <TD align="right" colspan=2><H3> </H3></TD>
  116. </TR>
  117. <TR bgcolor="dddddd" ><td colspan=2>
  118. <FORM METHOD=POST ACTION="default.asp?Submit=<%=request("Submit")%>">
  119. <INPUT TYPE="hidden" name="radif" value="-1">
  120. <SELECT NAME="catItem" style='width:350;font-family: tahoma,arial ; font-size: 9pt; font-weight: bold' size="1" onchange="document.forms[0].submit()">
  121. <option value="-1"> : </option>
  122. <option value="-1">----------------------------------------------</option>
  123. <%
  124. set RS4 = conn.Execute ("SELECT * FROM InventoryItemCategories ORDER BY Replace([Name],' ','')")
  125. while not (RS4.eof) %>
  126. <OPTION value="<%=RS4("ID")%>"<%
  127. if trim(catItem1) = trim(RS4("ID")) then
  128. response.write " selected "
  129. end if
  130. %>>* <%=RS4("Name")%> </option>
  131. <% RS4.MoveNext
  132. wend
  133. RS4.close
  134. %>
  135. </SELECT><br><br>
  136. <%
  137. if not catItem1="-1" then
  138. %>
  139. <SELECT NAME="item" style='width:350;font-family: tahoma,arial ; font-size: 9pt; font-weight: bold' size="1">
  140. <option value="-1"> : </option>
  141. <option value="-1">----------------------------------------------</option>
  142. <%
  143. mySQL="SELECT InventoryItems.* FROM InventoryItemCategoryRelations INNER JOIN InventoryItems ON InventoryItemCategoryRelations.Item_ID = InventoryItems.ID WHERE (InventoryItemCategoryRelations.Cat_ID = " & catItem1 & ") ORDER BY Replace([Name],' ','')"
  144. set RS4 = conn.Execute (mySQL)
  145. while not (RS4.eof)
  146. %> <OPTION value='<%=RS4("ID")%>'<%
  147. if trim(goodItem1) = trim(RS4("ID")) then
  148. response.write " selected "
  149. end if
  150. %>>* <%=RS4("OldItemID")%> - <%=RS4("Name")%> (<%=RS4("Unit")%>)</option>
  151. <%
  152. RS4.MoveNext
  153. wend
  154. RS4.close
  155. %>
  156. </SELECT><br><br>
  157. <% end if %>
  158. : &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<INPUT TYPE="text" NAME="qtty" size=40 onKeyPress="return maskNumber(this);" dir="LTR"><br><br>
  159. <INPUT TYPE="checkbox" onclick="hideIT()" name="tavafogh"> <BR>
  160. <div name="priceTavafoghi" id="priceTavafoghi" style="visibility:'hidden'">: &nbsp;<INPUT TYPE="text" NAME="price" ID="price" size=5 onKeyPress="return maskNumber(this);"> : <INPUT TYPE="text" NAME="priceComment" id="priceComment" size=26 ></div>
  161. <INPUT TYPE="checkbox" onclick="hideIT2()" name="tavafogh2"> <BR>
  162. <div name="priceTavafoghi2" id="priceTavafoghi2" style="visibility:'hidden'"> : &nbsp;<INPUT TYPE="text" NAME="orderID" ID="orderID" size=10 onKeyPress="return maskNumber(this);"> </div>
  163. : <INPUT dir=ltr TYPE="text" NAME="date1" size=15 value="<%=shamsiToday()%>" onKeyPress="return maskDate(this);" onblur="acceptDate(this)" maxlength="10"><br><br>
  164. : <TEXTAREA NAME="comment" ROWS="7" COLS="32"></TEXTAREA>
  165. <br><center>
  166. <INPUT class=inputBut TYPE="submit" Name="Submit" Value=" " style="width:125px;" tabIndex="14"<%
  167. if catItem1="-1" then
  168. response.write " disabled "
  169. end if
  170. %>>
  171. </center>
  172. </FORM>
  173. </FONT></TD>
  174. </TR>
  175. <%
  176. 'Gets Request for services list from DB
  177. set RS3=Conn.Execute ("SELECT * FROM purchaseRequests WHERE (status='new' and IsService=0)")
  178. %>
  179. <%
  180. Do while not RS3.eof
  181. %>
  182. <TR bgcolor="#CCCCCC" title="<%
  183. Comment = RS3("Comment")
  184. if Comment<>"-" then
  185. response.write ": " & Comment
  186. else
  187. response.write " "
  188. end if
  189. %>">
  190. <TD align="right" valign=top><FONT COLOR="black">
  191. <INPUT TYPE="checkbox" NAME="outReq" VALUE="<%=RS3("id")%>" <%
  192. if RS3("status") = "new" then
  193. response.write " checked disabled "
  194. else
  195. response.write " disabled "
  196. end if
  197. %>><B><%=RS3("TypeName")%></B> &nbsp;&nbsp;<small dir=ltr>(: <%=RS3("qtty")%> - :<%=RS3("ReqDate")%>)</small></td>
  198. <td align=left width=5%><%
  199. if RS3("status") = "new" then
  200. %><a href="default.asp?di=y&i=<%=RS3("id")%>&r=<%=request("radif")%>"><b></b></a><%
  201. end if %></td>
  202. </tr>
  203. <%
  204. RS3.moveNext
  205. Loop
  206. %>
  207. </table>
  208. </TD>
  209. <TD valign=top width=50%>
  210. <FORM METHOD=POST ACTION="default.asp"><li><B> <br></B> <BR>
  211. <center>
  212. <INPUT class=inputBut TYPE="submit" name="submit" value=" ">
  213. </center>
  214. </FORM>
  215. <%
  216. if trim(request("Submit"))=trim(" ") then 'or request("Submit")="" then
  217. %>
  218. <TABLE width=95% align=center>
  219. <TR bgcolor=#66FFFF>
  220. <TD> </TD>
  221. <TD></TD>
  222. <TD></TD>
  223. <TD> </TD>
  224. <TD></TD>
  225. </TR>
  226. <%
  227. 'set RSX=Conn.Execute ("SELECT * FROM InventoryItems WHERE Qtty <= Minim")
  228. if session("id") = 104 then ' if User is Mr Koochaki, just show items in the 1 and 5 categories
  229. extraCondition = " and (InventoryItemCategoryRelations.Cat_ID = 1 or InventoryItemCategoryRelations.Cat_ID = 5)"
  230. else
  231. extraCondition = ""
  232. end if
  233. set RSX=Conn.Execute ("SELECT InventoryItems.*, InventoryItemCategoryRelations.Cat_ID FROM InventoryItems INNER JOIN InventoryItemCategoryRelations ON InventoryItems.ID = InventoryItemCategoryRelations.Item_ID WHERE (InventoryItems.Qtty < InventoryItems.Minim) " & extraCondition & " ORDER BY Replace([Name],' ','')")
  234. Do while not RSX.eof
  235. set RSK=Conn.Execute ("SELECT sum(qtty) as sumQtty FROM PurchaseOrders WHERE IsService=0 and TypeID="& RSX("ID") &" and Status<>'OK' and Status<>'CANCEL'" )
  236. %>
  237. <TR>
  238. <TD class=alak2><A HREF="default.asp?goodItem=<%=RSX("id")%>&catItem=<%=RSX("cat_ID")%>&Submit=<%=request("Submit")%>"><%=RSX("Name")%></A></TD>
  239. <TD><%=RSX("Qtty")%></TD>
  240. <TD><%=RSX("Minim")%></TD>
  241. <TD><%
  242. if not RSK.eof then
  243. response.write RSK("sumQtty") '& "(" & RSK("Status") &")"
  244. end if
  245. %></TD>
  246. <TD><%=RSX("Unit")%></TD>
  247. </TR>
  248. <TR>
  249. <TD colspan=5 bgcolor=red></TD>
  250. </TR>
  251. <%
  252. RSX.moveNext
  253. Loop
  254. RSX.close
  255. %>
  256. </TABLE>
  257. <%
  258. end if
  259. %>
  260. <FORM METHOD=POST ACTION="default.asp">
  261. <hr>
  262. <li><B> <br></B> ǐ .<BR>
  263. <center>
  264. <INPUT class=inputBut TYPE="submit" name="submit" value=" ">
  265. </center>
  266. </FORM>
  267. <%
  268. if trim(request("Submit"))=trim(" ") then 'or request("Submit")="" then
  269. %>
  270. <TABLE width=95% align=center>
  271. <TR bgcolor=#66FFFF>
  272. <TD> </TD>
  273. <TD></TD>
  274. <TD></TD>
  275. <TD></TD>
  276. <TD> </TD>
  277. <TD></TD>
  278. </TR>
  279. <%
  280. 'set RSX=Conn.Execute ("SELECT InventoryItems.id, InventoryItems.Unit, InventoryItems.Minim, InventoryItems.Qtty, InventoryItems.Name, DERIVEDTBL.sumQtty AS sumReqQtty, DERIVEDTBL_1.SQ, InventoryItemCategoryRelations.Cat_ID FROM (SELECT ItemID, SUM(Qtty) AS sumQtty FROM InventoryItemRequests WHERE (Status = N'new') GROUP BY ItemID) DERIVEDTBL INNER JOIN InventoryItems ON DERIVEDTBL.ItemID = InventoryItems.ID AND InventoryItems.Qtty - DERIVEDTBL.sumQtty < InventoryItems.Minim INNER JOIN InventoryItemCategoryRelations ON InventoryItems.ID = InventoryItemCategoryRelations.Item_ID LEFT OUTER JOIN (SELECT SUM(Qtty) AS SQ, typeID FROM PurchaseOrders WHERE (status <> N'ok' AND status <> N'cancel' AND status <> N'RETURN') GROUP BY typeID) DERIVEDTBL_1 ON InventoryItems.ID = DERIVEDTBL_1.typeID ")
  281. set RSX=Conn.Execute ("SELECT InventoryItems.ID, InventoryItems.Unit, InventoryItems.Minim, InventoryItems.Qtty, InventoryItems.Name, DERIVEDTBL_1.SQ, InventoryItemCategoryRelations.Cat_ID, InventoryItems.sumReqQtty FROM (SELECT SUM(Qtty) AS SQ, typeID FROM PurchaseOrders WHERE (status <> N'ok' AND status <> N'cancel' AND status <> N'RETURN') GROUP BY typeID) DERIVEDTBL_1 RIGHT OUTER JOIN (SELECT InventoryItems.ID, InventoryItems.Unit, InventoryItems.Minim, InventoryItems.Qtty, InventoryItems.Name, ISNULL(reqsDRVTABLE.sumQtty, 0) AS sumReqQtty FROM InventoryItems LEFT OUTER JOIN (SELECT InventoryItemRequests.ItemID, ISNULL(SUM(InventoryItemRequests.Qtty), 0) AS sumQtty FROM InventoryPickuplists INNER JOIN InventoryPickuplistItems ON InventoryPickuplists.id = InventoryPickuplistItems.pickupListID RIGHT OUTER JOIN InventoryItemRequests ON InventoryPickuplistItems.RequestID = InventoryItemRequests.ID WHERE (InventoryItemRequests.Status = N'new') OR (InventoryItemRequests.Status = N'pick') AND (InventoryPickuplists.Status = N'new') GROUP BY InventoryItemRequests.ItemID) reqsDRVTABLE ON InventoryItems.ID = reqsDRVTABLE.ItemID) InventoryItems INNER JOIN InventoryItemCategoryRelations ON InventoryItems.ID = InventoryItemCategoryRelations.Item_ID ON InventoryItems.ID = DERIVEDTBL_1.typeID WHERE (InventoryItems.Minim > InventoryItems.Qtty - InventoryItems.sumReqQtty) ORDER BY Replace([Name],' ','')")
  282. Do while not RSX.eof
  283. %>
  284. <TR>
  285. <TD class=alak2><A HREF="default.asp?goodItem=<%=RSX("id")%>&catItem=<%=RSX("cat_ID")%>&Submit=<%=request("Submit")%>"><%=RSX("Name")%></A></TD>
  286. <TD><%=RSX("sumReqQtty")%></TD>
  287. <TD><%=RSX("Qtty")%></TD>
  288. <TD><%=RSX("Minim")%></TD>
  289. <TD><%
  290. if not isnull( RSX("SQ")) then
  291. response.write RSX("SQ") '& "("& RSX("status") & ")"
  292. end if
  293. %></TD>
  294. <TD><%=RSX("Unit")%></TD>
  295. </TR>
  296. <TR>
  297. <TD colspan=6 bgcolor=red></TD>
  298. </TR>
  299. <%
  300. RSX.moveNext
  301. Loop
  302. RSX.close
  303. %>
  304. </TABLE>
  305. <%
  306. end if
  307. %>
  308. </TD>
  309. </TR>
  310. </TABLE>
  311. <br>
  312. <!--#include file="tah.asp" -->