PageRenderTime 86ms CodeModel.GetById 56ms app.highlight 11ms RepoModel.GetById 1ms app.codeStats 0ms

/beta/Inquiry/InquiryInput.asp

http://github.com/khaneh/Orders
ASP | 549 lines | 463 code | 60 blank | 26 comment | 40 complexity | 89e31d3ae46458ec71884df46c9252d4 MD5 | raw file
  1<%@LANGUAGE="VBSCRIPT" CODEPAGE="1256"%><%
  2'AR (6)
  3PageTitle="���� �������"
  4SubmenuItem=1
  5if not (Auth(6 , 1) OR Auth(6 , 4)) then NotAllowdToViewThisPage()
  6%>
  7<!--#include file="top.asp" -->
  8<!--#include File="../include_farsiDateHandling.asp"-->
  9<!--#include File="../include_JS_InputMasks.asp"-->
 10
 11<%
 12function ShowErrorMessage(msg)
 13	response.write "<table align='center' cellpadding='5'><tr><td bgcolor='#FFCCCC' dir='rtl' align='center'> ��� ! <br>"& msg & "<br></td></tr></table><br>"
 14end function
 15
 16function Link2Trace(OrderNo)
 17	Link2Trace="<A HREF='../order/TraceOrder.asp?act=show&order="& OrderNo & "' target='_balnk'>"& OrderNo & "</A>"
 18end function
 19
 20%>
 21<style>
 22	Table { font-size: 9pt;}
 23	.InvRowInput { font-family:tahoma; font-size: 9pt; border: none; background-color: #F0F0F0; text-align:right;}
 24	.InvHeadInput { font-family:tahoma; font-size: 9pt; border: none; background-color: #CCCC88; text-align:center;}
 25	.InvRowInput2 { font-family:tahoma; font-size: 9pt; border: none; background-color: #F0FFF0; text-align:right;}
 26	.InvRowInput4 { font-family:tahoma; font-size: 9pt; border: none; background-color: #FFD3A8; direction:LTR; text-align:right;}
 27	.InvHeadInput2 { font-family:tahoma; font-size: 9pt; border: none; background-color: #AACC77; text-align:center;}
 28	.InvHeadInput3 { font-family:tahoma; font-size: 9pt; border: none; background-color: #F0F0F0; text-align:right;}
 29	.InvHeadInput4 { font-family:tahoma; font-size: 9pt; border: none; background-color: #FF9900; text-align:center;}
 30	.InvGenInput  { font-family:tahoma; font-size: 9pt; border: none; }
 31	.InvGenButton { font-family:tahoma; font-size: 9pt; border: 1px solid black; }
 32</style>
 33<SCRIPT LANGUAGE="JavaScript">
 34<!--
 35var okToProceed=false;
 36var currentRow=0;
 37//-->
 38</SCRIPT>
 39<%
 40
 41if request("act")="submitsearch" then
 42	if trim(request("query")) <> "" then
 43		if isnumeric(request("query")) then
 44			SO_Order=clng(request("query"))
 45			SO_Action="return true;"
 46			SO_StepText="<br>��� ��� : ������ ����� ��� ������"
 47%>
 48			<FORM METHOD=POST ACTION="?act=getInquiry">
 49			<!--#include File="include_SelectOrdersByOrder.asp"-->
 50			</FORM>
 51<%if Auth(6 , "K") then ' Has the priviledge to create a ReverseInquiry without an ORDER %>
 52			<p align='center' style='font-size:9pt;' dir='RTL'><a href='?act=getInquiry&selectedCustomer=<%=SO_Customer%>'>����� �� ����� ���� ����...</a></p>
 53<%end if%>
 54			<br>
 55<%		else
 56			SA_TitleOrName=request("query")
 57			SA_Action="return true;"
 58			SA_SearchAgainURL="InquiryInput.asp"
 59			SA_StepText="��� ��� : ������ ����"
 60%>
 61			<FORM METHOD=POST ACTION="?act=selectOrder">
 62			<!--#include File="include_SelectAccount.asp"-->
 63			</FORM>
 64<%
 65		end if
 66	else
 67		response.redirect "?errmsg=" & Server.URLEncode("���� �э �������!")
 68	end if
 69elseif request("act")="selectOrder" then
 70	if request("selectedCustomer") <> "" then
 71		SO_Customer=request("selectedCustomer")
 72		SO_Action="return true;"
 73		SO_StepText="<br>��� ��� : ������ ����� ��� ������"
 74%>
 75		<FORM METHOD=POST ACTION="?act=getInquiry">
 76		<!--#include File="include_SelectOrder.asp"-->
 77		</FORM>
 78<%if Auth(6 , "K") then ' Has the priviledge to create a ReverseInquiry without an ORDER %>
 79			<p align='center' style='font-size:9pt;' dir='RTL'><a href='?act=getInquiry&selectedCustomer=<%=SO_Customer%>'>����� �� ����� ���� ����...</a></p>
 80<%end if%>
 81		<br>
 82<%
 83	end if
 84elseif request("act")="getInquiry" then
 85%>
 86<!--#include file="include_JS_for_Inquiries.asp" -->
 87<%
 88	'******************** Checking Input ****************
 89	errorFound=false
 90	ON ERROR RESUME NEXT
 91
 92		customerID=	clng(request("selectedCustomer"))
 93
 94		mySQL="SELECT * FROM Accounts WHERE (ID='"& CustomerID & "')"
 95		Set rs = conn.Execute(mySQL)
 96		if rs.eof then
 97			errorFound=True
 98		else
 99			customerName=rs("AccountTitle")
100		end if
101		rs.close
102		
103		if Err.Number<>0 then
104			Err.clear
105			errorFound=True
106		end if
107	ON ERROR GOTO 0
108
109	if errorFound then
110		response.write "<br>" 
111		call showAlert ("��� �� �����",CONST_MSG_ERROR) 
112		response.end
113	end if
114	'^^^^---------------- Checking Input ------------^^^^
115
116	
117	creationDate=shamsiToday()
118'	creationTime=Hour(creationTime)&":"&Minute(creationTime)
119'	if instr(creationTime,":")<3 then creationTime="0" & creationTime
120'	if len(creationTime)<5 then creationTime=Left(creationTime,3) & "0" & Right(creationTime,1)
121
122	InquiryLinesNo=1
123%>
124<!-- ���� ������� ������ -->
125	<br>
126	<input type="hidden" Name='tmpDlgArg' value=''>
127	<input type="hidden" Name='tmpDlgTxt' value=''>
128		<table Border="0" align="center" Width="100%" Cellspacing="1" Cellpadding="0" Dir="RTL" bgcolor="#558855">
129		<FORM METHOD=POST ACTION="?act=submitInquiry">
130			<tr bgcolor='#C3C300'>
131			<td colspan="2"><TABLE Border="0" Width="100%" Cellspacing="1" Cellpadding="0" Dir="RTL"><TR>
132				<TD><table>
133					<tr>
134						<td align="left">����:</td>
135						<td align="right">
136							<span id="customer"><%' after any changes in this span "./Customers.asp" must be revised%>
137								<INPUT TYPE="hidden" NAME="customerID" value="<%=customerID%>"><span><%=CustomerName%></span>.
138							</span></td>
139						<td><INPUT class="InvGenButton" TYPE="button" value="�����" onClick="selectCustomer();"></td>
140					</tr>
141					</table></TD>
142				<TD align="left"><table>
143					<tr>
144						<td align="left">�����:</td>
145						<td dir="LTR">
146							<INPUT class="InvGenInput" NAME="InquiryDate" TYPE="text" maxlength="10" size="10" value="<%=CreationDate%>"></td>
147						<td dir="RTL"><%=weekdayname(weekday(date))%></td>
148					</tr>
149					</table></TD>
150				</TR></TABLE>
151			</td>
152			</tr>
153			<tr bgcolor='#C3C300'>
154				<TD align="right" width="50%">
155					����� �� �����(���):
156					<span id="orders">
157<%
158					tempWriteAnd=""
159					for i=1 to request.form("selectedOrders").count
160						response.write "<input type='hidden' name='selectedOrders' value='"& request.form("selectedOrders")(i)& "'>"
161						response.write tempWriteAnd & Link2Trace(request.form("selectedOrders")(i))
162						tempWriteAnd=" � "
163					next
164%>
165					</span>&nbsp;
166					<INPUT class="InvGenButton" TYPE="button" value="�����" onClick="selectOrder();">
167				</TD>
168				<TD align="left"><table>
169					<tr>
170						<td align="left">�����:</td>
171						<td dir="LTR">
172							<INPUT class="InvGenInput" NAME="InquiryNo" style="border:1px solid black;" TYPE="text" maxlength="10" size="10"></td>
173						<td dir="RTL"><INPUT TYPE="checkbox" onClick="checkIsA();" NAME="IsA"> ��� &nbsp;</td>
174					</tr>
175					</table></TD>
176			</tr>
177			<tr bgcolor='#CCCC88'>
178			<TD colspan="10"><div>
179			<TABLE Border="0" Cellspacing="1" Cellpadding="0" Dir="RTL" bgcolor="#558855">
180			<tr bgcolor='#CCCC88'>
181				<td align='center' width="32px"> # </td>
182				<td><INPUT class="InvHeadInput" readonly TYPE="text" value="����" size="3" ></td>
183				<td><INPUT class="InvHeadInput2" readonly TYPE="text" value="�������" size="30"></td>
184				<td><INPUT class="InvHeadInput2" readonly TYPE="text" Value="���" size="2"></td>
185				<td><INPUT class="InvHeadInput2" readonly TYPE="text" Value="���" size="2"></td>
186				<td><INPUT class="InvHeadInput2" readonly TYPE="text" Value="�����" size="3"></td>
187				<td><INPUT class="InvHeadInput2" readonly TYPE="text" Value="���" size="2"></td>
188				<td><INPUT class="InvHeadInput" readonly TYPE="text" Value="����� ����" size="6"></td>
189				<td><INPUT class="InvHeadInput" readonly TYPE="text" Value="��" size="7"></td>
190				<td><INPUT class="InvHeadInput" readonly TYPE="text" Value="����" size="9"></td>
191				<td><INPUT class="InvHeadInput" readonly TYPE="text" Value="�����"size="7"></td><!-- S A M -->
192				<td><INPUT class="InvHeadInput" readonly TYPE="text" Value="�ѐ��" size="5"></td><!-- S A M -->
193				<td><INPUT class="InvHeadInput4" readonly TYPE="text" Value="������" size="6"></td><!-- S A M -->
194				<td><INPUT class="InvHeadInput2" readonly TYPE="text" Value="���� ������" size="9"></td>
195			</tr>
196			</TABLE></div></TD>
197			</TR>
198			<tr bgcolor='#CCCC88'>
199			<TD colspan="10"><div style="overflow:auto; height:250px; width:*;">
200			<TABLE Border="0" Cellspacing="1" Cellpadding="0" Dir="RTL" bgcolor="#558855">
201			<Tbody id="InquiryLines">
202
203<%		
204		for i=1 to 1
205%>
206			<tr bgcolor='#F0F0F0' onclick="setCurrentRow(this.rowIndex);" >
207				<td align='center' width="25px"><%=i%></td>
208				<td dir="LTR"><INPUT class="InvRowInput" TYPE="text" NAME="Items" size="3" Maxlength="6" onKeyPress="return mask(this);" onfocus="setCurrentRow(this.parentNode.parentNode.rowIndex);" onChange='return check(this);'>
209				<INPUT TYPE="hidden" name="type" value=0>
210				<INPUT TYPE="hidden" name="fee" value=0>
211				<INPUT type='hidden' name='hasVat' value=0>
212				</td>
213				<td dir="RTL"><INPUT class="InvRowInput2" TYPE="text" NAME="Descriptions" size="30"></td>
214				<td dir="LTR"><INPUT class="InvRowInput2" TYPE="text" NAME="Lengths" size="2" onBlur="setFeeQtty(this);"></td>
215				<td dir="LTR"><INPUT class="InvRowInput2" TYPE="text" NAME="Widths" size="2" onBlur="setFeeQtty(this);"></td>
216				<td dir="LTR"><INPUT class="InvRowInput2" TYPE="text" NAME="Qttys" size="3" onBlur="setFeeQtty(this);"></td>
217				<td dir="LTR"><INPUT class="InvRowInput2" TYPE="text" NAME="Sets" size="2" onBlur="setFeeQtty(this);"></td>
218				<td dir="LTR"><INPUT class="InvRowInput" TYPE="text" NAME="AppQttys" size="6" onBlur="setPrice(this);"></td>
219				<td dir="LTR"><INPUT class="InvRowInput" TYPE="text" NAME="Fees" size="7" onBlur="setPrice(this);"></td>
220				<td dir="LTR"><INPUT class="InvRowInput" TYPE="text" NAME="Prices" size="9" readonly tabIndex="9999"></td>
221				<td dir="LTR"><INPUT class="InvRowInput" TYPE="text" NAME="Discounts" size="7" onBlur="setPrice(this);"></td><!-- S A M -->
222				<td dir="LTR"><INPUT class="InvRowInput" TYPE="text" NAME="Reverses" size="5" onBlur="setPrice(this);" onfocus="setCurrentRow(this.parentNode.parentNode.rowIndex);"></td><!-- S A M -->
223				<td dir="LTR"><INPUT class="InvRowInput4" TYPE="text" NAME="Vat" size="6" readonly></td><!-- S A M -->
224				<td dir="LTR"><INPUT class="InvRowInput2" TYPE="text" NAME="AppPrices" size="9" readonly tabIndex="9999"></td>
225			</tr>
226<%
227		next
228%>
229			<tr bgcolor='#F0F0F0' onclick="setCurrentRow(this.rowIndex);" >
230				<td colspan="15">
231					<INPUT class="InvGenButton" TYPE="button" value="�����" onkeyDown="if(event.keyCode==9) {setCurrentRow(this.parentNode.parentNode.rowIndex); return false;};" onClick="addRow();">
232				</td>
233			</tr>
234			</Tbody></TABLE></div>
235			</TD>
236			</tr>
237			<tr bgcolor='#CCCC88'>
238			<TD colspan="10"><div>
239			<TABLE Border="0" Cellspacing="1" Cellpadding="0" Dir="RTL" bgcolor="#CCCC88">
240			<tr bgcolor='#CCCC88'>
241				
242				
243				<td colspan='9' width='500px'>***����� ��� �ǘ��� ��� �� ��� ��� ����� ��***</td>
244				<!--td><INPUT readonly class="InvHeadInput" TYPE="text" size="2"></td>
245				<td><INPUT readonly class="InvHeadInput" TYPE="text" size="2"></td>
246				<td><INPUT readonly class="InvHeadInput" TYPE="text" size="3"></td>
247				<td><INPUT readonly class="InvHeadInput" TYPE="text" size="2"></td>
248				<td><INPUT readonly class="InvHeadInput" TYPE="text" size="6"></td>
249				<td><INPUT readonly class="InvHeadInput" TYPE="text" size="7"></td-->
250				<td dir="LTR"><INPUT readonly class="InvHeadInput3" Name="TotalPrice" TYPE="text" size="9"></td>
251				<td dir="LTR"><INPUT readonly class="InvHeadInput3" Name="TotalDiscount" TYPE="text" size="7"></td><!-- S A M -->
252				<td dir="LTR"><INPUT readonly class="InvHeadInput3" Name="TotalReverse" TYPE="text" size="5"></td><!-- S A M -->
253				<td dir="LTR"><INPUT readonly class="InvHeadInput3" Name="TotalVat" TYPE="test" size="6"></td><!-- S A M -->
254				<td dir="LTR"><INPUT readonly class="InvHeadInput3" Name="Payable" TYPE="text" size="9"></td>
255			</tr>
256			<tr bgcolor='#CCCC88'>
257				<td colspan="9"> &nbsp; </td>
258				<td dir="LTR"><INPUT readonly class="InvHeadInput" TYPE="text" size="9"></td>
259				<td dir="LTR"><INPUT readonly class="InvHeadInput3" TYPE="text" Name="TPDiscount" size="7"></td><!-- S A M -->
260				<td dir="LTR"><INPUT readonly class="InvHeadInput3" TYPE="text" Name="TPReverse" size="5"></td><!-- S A M -->
261				<td dir="LTR"><INPUT readonly class="invHeadInput3" TYPE="text" size="6" value="3%������"></td><!-- S A M -->
262				<td dir="LTR"><INPUT readonly class="InvHeadInput" TYPE="text" size="9" value="��� ���"></td>
263			</tr>
264			</TABLE></div></TD>
265			</TR>
266		</table><br>
267		<TABLE Border="0" Cellspacing="5" Cellpadding="0" Dir="RTL" align='left'>
268		<tr>
269			<td align='center'><INPUT class="InvGenButton" TYPE="button" value="��� ��� ���� �������..." onclick="submitOperations();"></td>
270			<td align='center'><INPUT class="InvGenButton" TYPE="button" value="������" onclick="window.close();"></td>
271		</tr>
272		</TABLE>
273		</FORM>
274		<SCRIPT LANGUAGE="JavaScript">
275		<!--
276			document.getElementsByName("Items")[0].focus();
277		//-->
278		</SCRIPT>
279<%elseif request("act")="submitInquiry" then
280	'******************** Checking Input ****************
281	errorFound=false
282	ON ERROR RESUME NEXT
283
284		InquiryDate=	request.form("InquiryDate")
285
286		If Not CheckDateFormat(InquiryDate) Then
287			errorFound=True
288		end if
289
290		CustomerID=		clng(request.form("CustomerID"))
291
292		if request.form("IsA") = "on" then 
293			IsA=1 
294			InquiryNo=request.form("InquiryNo")
295			if InquiryNo <> "" then InquiryNo = clng(InquiryNo)
296		else 
297			IsA=0
298			InquiryNo=""
299		end if
300			
301		'OLD Code:
302		'TotalPrice=		cdbl(text2value(request.form("TotalPrice")))
303		'TotalDiscount=	cdbl(text2value(request.form("TotalDiscount")))
304		'TotalReverse=	cdbl(text2value(request.form("TotalReverse")))
305		'TotalReceivable=cdbl(text2value(request.form("TotalAppPrice")))
306		'
307		'Changed By Kid 831021: calculating totals ServerSide
308		TotalPrice	=		0
309		TotalDiscount =		0
310		TotalReverse =		0
311		TotalReceivable =	0
312		TotalVat =			0
313		RFD	=				0
314
315		for i=1 to request.form("Items").count 
316
317			theItem =			clng(text2value(request.form("Items")(i)))
318			mySQL="SELECT ID FROM InvoiceItems WHERE ID=" & theItem 
319			Set rs=conn.Execute(mySQL)
320			if rs.eof then
321				errorFound=True
322				exit for
323			end if
324			rs.close
325
326			theDescription =	left(sqlSafe(request.form("Descriptions")(i)),100)
327
328			theAppQtty =		cdbl(text2value(request.form("AppQttys")(i)))
329			thePrice =			clng(text2value(request.form("Prices")(i)))
330
331			theDiscount =		text2value(request.form("Discounts")(i))
332			theReverse =		text2value(request.form("Reverses")(i))
333
334			theLength =			text2value(request.form("Lengths")(i))
335			theWidth =			text2value(request.form("Widths")(i))
336			theQtty =			text2value(request.form("Qttys")(i))
337			theSets =			text2value(request.form("Sets")(i))
338			theVat =			clng(text2value(request.form("Vat")(i)))
339
340			if theDiscount <>"" then theDiscount= clng(theDiscount)
341			if theReverse <> "" then theReverse = clng(theReverse)
342
343			if theLength <>	"" then  theLength	= cdbl(theLength)
344			if theWidth <> ""  then	 theWidth	= cdbl(theWidth) 
345			if theQtty <> ""   then	 theQtty	= clng(theQtty)
346			if theSets <> ""   then	 theSets	= clng(theSets)
347
348			TotalPrice	=		TotalPrice + thePrice
349			TotalDiscount =		TotalDiscount + theDiscount
350			TotalReverse =		TotalReverse + theReverse
351			TotalReceivable =	TotalReceivable + (thePrice - theDiscount - theReverse + theVat)
352			TotalVat = TotalVat + theVat
353
354		next 
355		RFD = TotalReceivable - fix(TotalReceivable / 1000) * 1000
356		'RFD = RFD / 1.03
357		TotalReceivable = TotalReceivable - RFD
358		TotalDiscount = TotalDiscount + RFD
359
360		for i = 1 to request.form("selectedOrders").count
361			theOrder=		clng(request.form("selectedOrders")(i))
362			mySQL = "SELECT ID FROM Orders WHERE ID=" & theOrder 
363			Set rs = conn.Execute(mySQL)
364			if rs.eof then
365				errorFound=True
366				exit for
367			end if
368			rs.close
369		next
370
371		Set rs = Nothing
372
373		if Err.Number<>0 then
374			Err.clear
375			errorFound=True
376		end if
377	ON ERROR GOTO 0
378
379	if errorFound then
380		response.write "<br>" 
381		call showAlert ("��� �� �����",CONST_MSG_ERROR) 
382		response.end
383	end if
384	'^^^^---------------- Checking Input ------------^^^^
385
386	'**************************** Inserting new Inquiry ****************
387	mySQL="INSERT INTO Inquiries (CreatedDate, CreatedBy, Customer, Number, TotalPrice, TotalDiscount, TotalReverse, TotalReceivable, IsA, TotalVat) VALUES (N'"& InquiryDate & "', '"& session("ID") & "', '"& CustomerID & "', '"& InquiryNo & "', '"& TotalPrice & "', '"& TotalDiscount & "', '"& TotalReverse & "', '"& TotalReceivable & "', '"& IsA & "', '" & TotalVat & "');SELECT @@Identity AS NewInquiry"
388	set RS1 = Conn.execute(mySQL).NextRecordSet
389	InquiryID = RS1 ("NewInquiry")
390	RS1.close	
391
392	'**************************** Inserting Inquiry Lines ****************
393	for i=1 to request.form("Items").count 
394		theItem =			clng(text2value(request.form("Items")(i)))
395		theDescription =	left(sqlSafe(request.form("Descriptions")(i)),100)
396
397		theAppQtty =		cdbl(text2value(request.form("AppQttys")(i)))
398		thePrice =			clng(text2value(request.form("Prices")(i)))
399
400		theDiscount =		text2value(request.form("Discounts")(i))
401		theReverse =		text2value(request.form("Reverses")(i))
402		theVat =			text2value(request.form("Vat")(i))
403		theHasVat =			text2value(request.form("hasVat")(i))
404
405		theLength =			text2value(request.form("Lengths")(i))
406		theWidth =			text2value(request.form("Widths")(i))
407		theQtty =			text2value(request.form("Qttys")(i))
408		theSets =			text2value(request.form("Sets")(i))
409
410		if theDiscount <>"" then theDiscount= clng(theDiscount)
411		if theReverse <> "" then theReverse = clng(theReverse)
412
413		if theLength <>	"" then  theLength	= cdbl(theLength)
414		if theWidth <> ""  then	 theWidth	= cdbl(theWidth) 
415		if theQtty <> ""   then	 theQtty	= clng(theQtty)
416		if theSets <> ""   then	 theSets	= clng(theSets)
417
418		mySQL="INSERT INTO InquiryLines (Inquiry, Item, Description, Length, Width, Qtty, Sets, AppQtty, Price, Discount, Reverse, Vat, hasVat) VALUES ('"& InquiryID & "', '" & theItem & "', N'" & theDescription & "', '" & theLength & "', '" & theWidth & "', '" & theQtty & "', '" & theSets & "', '" & theAppQtty & "', '" & thePrice & "', '" & theDiscount & "', '" & theReverse & "', '" & theVat & "', "&theHasVat&")"
419		conn.Execute(mySQL)
420	next 
421	if RFD > 0 then
422		theItem =			39999
423		theDescription =	"����� ��� �ǘ���"
424
425		theAppQtty =		0
426		thePrice =			0
427
428		theDiscount =		RFD
429		theReverse =		0
430		theVat =			0
431
432		theLength =			0
433		theWidth =			0
434		theQtty =			0
435		theSets =			0
436		mySQL="INSERT INTO InquiryLines (Inquiry, Item, Description, Length, Width, Qtty, Sets, AppQtty, Price, Discount, Reverse, Vat) VALUES ('"& InquiryID & "', '" & theItem & "', N'" & theDescription & "', '" & theLength & "', '" & theWidth & "', '" & theQtty & "', '" & theSets & "', '" & theAppQtty & "', '" & thePrice & "', '" & theDiscount & "', '" & theReverse & "', '" & theVat & "')"
437		conn.Execute(mySQL)
438	end if
439
440	'**************************** Making Inquiry-Order Relations ****************
441	for i=1 to request.form("selectedOrders").count
442		theOrder=		clng(request.form("selectedOrders")(i))
443		mySQL="INSERT INTO InquiryOrderRelations (Inquiry,[Order]) VALUES ('" & InquiryID & "', '" & theOrder & "')"
444		conn.Execute(mySQL)
445	next
446
447	response.redirect "AccountReport.asp?act=showInquiry&inquiry="	 & InquiryID
448
449elseif request("act")="copyInquiry" then
450	InquiryID=request.queryString("inquiry")
451	if InquiryID="" OR not isnumeric(InquiryID) then
452		conn.close
453		response.redirect "?errmsg=" & Server.URLEncode("����� ������� ���� ���� ��� ����.")
454	end if
455
456	InquiryID=clng(InquiryID)
457	mySQL="SELECT * FROM Inquiries WHERE (ID='"& InquiriID & "')"
458	Set RS1 = conn.Execute(mySQL)
459	if RS1.eof then
460		conn.close
461		response.redirect "?errmsg=" & Server.URLEncode("������ ���� ���.")
462	end if
463
464	customerID=		RS1("Customer")
465	creationDate=	shamsiToday()
466	totalPrice=		cdbl(RS1("totalPrice"))
467	totalDiscount=	cdbl(RS1("totalDiscount"))
468	totalReverse=	cdbl(RS1("totalReverse"))
469	totalVat =		cdbl(RS1("totalVat"))
470	TotalReceivable = totalPrice - totalDiscount - totalReverse + totalVat
471	Issued =		RS1("Issued") 
472	Voided =		RS1("Voided") 
473
474	if RS1("IsReverse") then
475		isReverse=	1
476	else
477		isReverse=	0
478	end if
479	if RS1("IsA") then
480		IsA=		1
481	else
482		IsA=		0
483	end if
484	InquiryNo=		RS1("Number")
485
486	RS1.close
487
488	if isReverse AND not Auth(6 , 4) then
489		'Doesn't have the permission for ADDING Rev. Inquiry
490		response.write "<br>" 
491		call showAlert ("��� ���� �� ���� ������� �ѐ�� ������",CONST_MSG_ERROR) 
492		response.end
493	elseif not Auth(6 , 1) then 
494		'Doesn't have the permission for ADDING Inquiry
495		response.write "<br>" 
496		call showAlert ("��� ���� �� ���� ������� ������",CONST_MSG_ERROR) 
497		response.end
498	end if
499
500	'Copying Inquiry ...
501	mySQL="INSERT INTO Inquiries (CreatedDate, CreatedBy, Customer, IsA, Number, TotalPrice, TotalDiscount, TotalReverse, TotalReceivable, IsReverse, TotalVat) VALUES (N'"& creationDate & "', '"& session("ID") & "', '"& CustomerID & "', '"& IsA & "', '"& InquiryNo & "', '"& TotalPrice & "', '"& TotalDiscount & "', '"& TotalReverse & "', '"& TotalReceivable & "', '"& IsReverse & "', '" & TotalVat & "'); SELECT @@Identity AS NewInquiry"
502	Set RS1 = conn.Execute(mySQL).NextRecordSet
503	NewInquiry = RS1("NewInquiry")
504
505	'Copying InquiryLines ...
506	mySQL="INSERT INTO InquiryLines (Inquiry, Item, Description, Length, Width, Qtty, Sets, AppQtty, Price, Discount, Reverse, Vat, hasVat) SELECT '"& NewInquiry & "' AS Inquiry, Item, Description, Length, Width, Qtty, Sets, AppQtty, Price, Discount, Reverse, Vat, hasVat FROM InquiryLines WHERE (Inquiry = '"& InquiryID & "')"
507	conn.Execute(mySQL)
508
509	'Copying InquiryOrderRelations ...
510	mySQL="INSERT INTO InquiryOrderRelations (Inquiry, [Order]) SELECT '"& NewInquiry & "' AS Inquiry, [Order] FROM InquiryOrderRelations WHERE (Inquiry = '"& InquiryID & "')"
511	conn.Execute(mySQL)
512
513	if Issued AND voided then
514	' if it's copied from a voided Inquiry, place a comment for the voided Inquiry 
515		MsgTo			=	0
516		msgTitle		=	"Inquiry Copied"
517		msgBody			=	"������� ����� "& NewInquiry & " �� ��� ������� ��� ߁� ��." 
518		RelatedTable	=	"Inquiries"
519		relatedID		=	InquiryID
520		replyTo			=	0
521		IsReply			=	0
522		urgent			=	0
523		MsgFrom			=	session("ID")
524		MsgDate			=	shamsiToday()
525		MsgTime			=	currentTime10()
526		Conn.Execute ("INSERT INTO Messages (MsgFrom, MsgTo, MsgTime, MsgDate, IsRead, MsgTitle, MsgBody, replyTo, IsReply, relatedID, RelatedTable, urgent) VALUES ( "& MsgFrom & ", "& MsgTo & ", N'"& MsgTime & "', N'"& MsgDate & "', 0, N'"& MsgTitle & "', N'"& MsgBody & "', "& replyTo & ", "& IsReply & ", "& relatedID & ", '"& RelatedTable & "', "& urgent & ")")
527		
528	end if	
529
530	' Place a comment for the new Inquiry 
531	MsgTo			=	0
532	msgTitle		=	"Inquiry Copied"
533	msgBody			=	"��� ���� �� ������� ����� "& InquiryID & " ߁� ��." 
534	RelatedTable	=	"Inquiries"
535	relatedID		=	NewInquiry 
536	replyTo			=	0
537	IsReply			=	0
538	urgent			=	0
539	MsgFrom			=	session("ID")
540	MsgDate			=	shamsiToday()
541	MsgTime			=	currentTime10()
542	Conn.Execute ("INSERT INTO Messages (MsgFrom, MsgTo, MsgTime, MsgDate, IsRead, MsgTitle, MsgBody, replyTo, IsReply, relatedID, RelatedTable, urgent) VALUES ( "& MsgFrom & ", "& MsgTo & ", N'"& MsgTime & "', N'"& MsgDate & "', 0, N'"& MsgTitle & "', N'"& MsgBody & "', "& replyTo & ", "& IsReply & ", "& relatedID & ", '"& RelatedTable & "', "& urgent & ")")
543
544	response.redirect "AccountReport.asp?act=showInquiry&inquiry=" & NewInquiry & "&msg=" & Server.URLEncode(request.queryString("msg") & "<br>��� ���� �� ��� ������� �� ������� ����� "& InquiryID & " ߁� ��.")
545
546end if
547conn.Close
548%>
549<!--#include file="tah.asp" -->