PageRenderTime 19ms CodeModel.GetById 6ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 1ms

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