PageRenderTime 40ms CodeModel.GetById 25ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 1ms

/beta/Inquiry/InquiryEdit.asp

http://github.com/khaneh/Orders
ASP | 971 lines | 756 code | 119 blank | 96 comment | 86 complexity | 1679f95e03ad56dadb5c837ce02468e1 MD5 | raw file
  1<%@LANGUAGE="VBSCRIPT" CODEPAGE="1256"%><%
  2'AR (6)
  3PageTitle="����� ������ "
  4SubmenuItem=1
  5'if not Auth(6 , 1) then NotAllowdToViewThisPage()
  6
  7%>
  8<!--#include file="top.asp" -->
  9<!--#include File="../include_farsiDateHandling.asp"-->
 10<!--#include File="../include_JS_InputMasks.asp"-->
 11
 12<%
 13function ShowErrorMessage(msg)
 14	response.write "<table align='center' cellpadding='5'><tr><td bgcolor='#FFCCCC' dir='rtl' align='center'> ��� ! <br>"& msg & "<br></td></tr></table><br>"
 15end function
 16
 17function Link2Trace(OrderNo)
 18	Link2Trace="<A HREF='../order/TraceOrder.asp?act=show&order="& OrderNo & "' target='_balnk'>"& OrderNo & "</A>"
 19end function
 20
 21%>
 22<style>
 23	Table { font-size: 9pt;}
 24	.InvRowInput { font-family:tahoma; font-size: 9pt; border: none; background-color: #F0F0F0; text-align:right;}
 25	.InvHeadInput { font-family:tahoma; font-size: 9pt; border: none; background-color: #CCCC88; text-align:center;}
 26	.InvRowInput2 { font-family:tahoma; font-size: 9pt; border: none; background-color: #F0FFF0; text-align:right;}
 27	.InvRowInput4 { font-family:tahoma; font-size: 9pt; border: none; background-color: #FFD3A8; direction:LTR; text-align:right;}
 28	.InvHeadInput2 { font-family:tahoma; font-size: 9pt; border: none; background-color: #AACC77; text-align:center;}
 29	.InvHeadInput3 { font-family:tahoma; font-size: 9pt; border: none; background-color: #F0F0F0; text-align:right;}
 30	.InvHeadInput4 { font-family:tahoma; font-size: 9pt; border: none; background-color: #FF9900; text-align:center;}
 31	.InvGenInput  { font-family:tahoma; font-size: 9pt; border: none; }
 32	.InvGenButton { font-family:tahoma; font-size: 9pt; border: 1px solid black; }
 33</style>
 34<SCRIPT LANGUAGE="JavaScript">
 35<!--
 36var okToProceed=false;
 37var currentRow=0;
 38//-->
 39</SCRIPT>
 40<%
 41if request("act")="search" then
 42	if isnumeric(request("order")) then
 43		OrderID = clng(request("order"))
 44		mySQL="SELECT InquiryOrderRelations.Inquiry FROM InquiryOrderRelations INNER JOIN Inquiries ON InquiryOrderRelations.Inquiry = Inquiries.ID WHERE (InquiryOrderRelations.[Order] = '"& OrderID & "') AND (Inquiries.IsReverse = 0) AND (Inquiries.Voided = 0)"
 45		Set RS1=Conn.Execute(mySQL)
 46		if RS1.eof then
 47			Conn.close
 48			response.redirect "?errmsg=" & Server.URLEncode("��� ����� ���� ������ ���� ���.")
 49		else
 50			theInquiry=RS1("Inquiry")
 51			Conn.close
 52			response.redirect "?act=editInquiry&inquiry=" & theInquiry
 53		end if
 54	elseif isnumeric(request("inquiry")) then
 55		response.redirect "?act=editInquiry&inquiry=" & request("inquiry")
 56	else
 57		response.redirect "?errmsg=" & Server.URLEncode("����� ����� ���� ���� ��� ����.")
 58	end if
 59'-----------------------------------------------------------------------------------------------------
 60'---------------------------------------------------------------------------------------- Edit Inquiry
 61'-----------------------------------------------------------------------------------------------------
 62elseif request("act")="editInquiry" then
 63	if isnumeric(request("inquiry")) then
 64		InquiryID=clng(request("inquiry"))
 65		mySQL="SELECT * FROM Inquiries WHERE (ID='"& InquiryID & "')"
 66		Set RS1 = conn.Execute(mySQL)
 67		if RS1.eof then
 68			conn.close
 69			response.redirect "?errmsg=" & Server.URLEncode("������ ���� ���.")
 70		end if
 71	else
 72		response.redirect "?errmsg=" & Server.URLEncode("����� ������ ���� ���� ��� ����.")
 73	end if
 74
 75	customerID=		RS1("Customer")
 76	creationDate=	RS1("CreatedDate")
 77	IssuedDate=		RS1("IssuedDate")
 78	totalPrice=		cdbl(RS1("totalPrice"))
 79	totalDiscount=	cdbl(RS1("totalDiscount"))
 80	totalReverse=	cdbl(RS1("totalReverse"))
 81	totalVat =		cdbl(RS1("totalVat"))
 82	Voided=			RS1("Voided")
 83	Issued=			RS1("Issued")
 84	Approved=		RS1("Approved")
 85	isReverse=		RS1("IsReverse")
 86	IsA=			RS1("IsA")
 87	InquiryNo=		RS1("Number")
 88
 89	mySQL="SELECT ID,AccountTitle FROM Accounts WHERE (ID='"& customerID & "')"
 90	Set RS1 = conn.Execute(mySQL)
 91	AccountNo=RS1("ID")
 92	customerName=RS1("AccountTitle")
 93
 94	RS1.close
 95
 96	if isReverse then
 97		'Check for permission for EDITTING Rev. Inquiry
 98		if not Auth(6 , 5) then NotAllowdToViewThisPage()
 99		itemTypeName="�ǘ��� �ѐ��"
100		HeaderColor="#FF9900"
101	else
102		'Check for permission for EDITTING Inquiry
103		if not Auth(6 , 3) then NotAllowdToViewThisPage()
104		itemTypeName="�ǘ���"
105		HeaderColor="#C3C300"
106	end if
107
108	if Voided then
109		Conn.close
110		response.redirect "AccountReport.asp?act=showInquiry&inquiry="& InquiryID & "&errmsg=" & Server.URLEncode("��� ������ ���� ��� ���.")
111	elseif Issued then
112		if Auth(6 , "A") then
113			' Has the Priviledge to change the Inquiry
114			response.write "<BR>"
115			call showAlert ("��� ������ ���� ��� ���.<br>�э�� �� ��� ����� ����� �� ��� �ǘ��� �� ����� �����<br>������ �Ԙ��� ������� �� �� �����Ͽ",CONST_MSG_INFORM) 
116		else
117			Conn.close
118			response.redirect "AccountReport.asp?act=showInquiry&inquiry="& InquiryID & "&errmsg=" & Server.URLEncode("��� ������ ���� ��� ���.")
119		end if
120	end if 
121%>
122<!-- ���� ������� ������ -->
123	<br>
124	<input type="hidden" Name='tmpDlgArg' value=''>
125	<input type="hidden" Name='tmpDlgTxt' value=''>
126		<table Border="0" align="center" Width="100%" Cellspacing="1" Cellpadding="0" Dir="RTL" bgcolor="#558855">
127		<FORM METHOD=POST ACTION="?act=submitEdit">
128			<tr bgcolor='<%=HeaderColor%>'>
129			<td colspan='2'>
130				<TABLE width='100%'>
131				<TR>
132					<TD align="left" >����� <%=itemTypeName%>:</TD>
133					<TD align="right" width='15%'>&nbsp;<INPUT readonly class="InvGenInput" NAME="InquiryID" value="<%=InquiryID%>" style="direction:ltr" TYPE="text" maxlength="10" size="10"></TD>
134				</TR>
135				</TABLE></td>
136			</tr>
137			<tr bgcolor='<%=HeaderColor%>'>
138			<td colspan="2">
139				<TABLE Border="0" Width="100%" Cellspacing="1" Cellpadding="0" Dir="RTL">
140				<TR>
141					<TD><table>
142						<tr>
143							<td align="left">����:</td>
144							<td align="right">
145								<span id="customer"><%' after any changes in this span "./Customers.asp" must be revised%>
146									<INPUT TYPE="hidden" NAME="customerID" value="<%=customerID%>"><span><%=CustomerName%></span>.
147								</span></td>
148							<td><INPUT class="InvGenButton" TYPE="button" value="�����" onClick="selectCustomer();"></td>
149						</tr>
150						</table></TD>
151					<TD align="left"><table>
152						<tr>
153							<td align="left">����� ����:</td>
154							<td dir="LTR">
155								<INPUT class="InvGenInput" NAME="issueDate" TYPE="text" maxlength="10" size="10" value="<%=IssuedDate%>"  onblur="acceptDate(this)"></td>
156							<td dir="RTL"><%="�����"%></td>
157						</tr>
158						</table></TD>
159				</TR></TABLE>
160			</td>
161			</tr>
162			<tr bgcolor='<%=HeaderColor%>'>
163				<TD align="right" width="50%">
164					����� �� �����(���):
165					<span id="orders">
166<%
167					tempWriteAnd=""
168
169					mySQL="SELECT * FROM InquiryOrderRelations WHERE (Inquiry='"& InquiryID & "')"
170					Set RS1 = conn.Execute(mySQL)
171					while not(RS1.eof) 
172						response.write "<input type='hidden' name='selectedOrders' value='"& RS1("Order") & "'>"
173						response.write tempWriteAnd & Link2Trace(RS1("Order"))
174						tempWriteAnd=" � "
175						RS1.moveNext
176					wend
177%>					</span>&nbsp;
178					<INPUT class="InvGenButton" TYPE="button" value="�����" onClick="selectOrder();">
179				</TD>
180				<TD align="left"><table>
181					<tr>
182						<td align="left">�����:</td>
183						<td dir="LTR">
184							<INPUT class="InvGenInput" NAME="InquiryNo" value="<%=InquiryNo%>" style="border:1px solid black;" TYPE="text" maxlength="10" size="10"></td>
185						<td dir="RTL"><INPUT TYPE="checkbox" onClick="checkIsA();" NAME="IsA" <%if IsA then response.write "checked"%>> ��� &nbsp;</td>
186					</tr>
187					</table></TD>
188			</tr>
189			<tr bgcolor='#CCCC88'>
190			<TD colspan="10"><div>
191			<TABLE Border="0" Cellspacing="1" Cellpadding="0" Dir="RTL" bgcolor="#558855">
192			<tr bgcolor='#CCCC88'>
193				<td align='center' width="25px"> # </td>
194				<td><INPUT class="InvHeadInput" readonly TYPE="text" value="����" size="3" ></td>
195				<td><INPUT class="InvHeadInput2" readonly TYPE="text" value="�������" size="30"></td>
196				<td><INPUT class="InvHeadInput2" readonly TYPE="text" Value="���" size="2"></td>
197				<td><INPUT class="InvHeadInput2" readonly TYPE="text" Value="���" size="2"></td>
198				<td><INPUT class="InvHeadInput2" readonly TYPE="text" Value="�����" size="3"></td>
199				<td><INPUT class="InvHeadInput2" readonly TYPE="text" Value="���" size="2"></td>
200				<td><INPUT class="InvHeadInput" readonly TYPE="text" Value="����� ����" size="6"></td>
201				<td><INPUT class="InvHeadInput" readonly TYPE="text" Value="��" size="7"></td>
202				<td><INPUT class="InvHeadInput" readonly TYPE="text" Value="����" size="9"></td>
203				<td><INPUT class="InvHeadInput" readonly TYPE="text" Value="�����"size="7"></td><!-- S A M -->
204				<td><INPUT class="InvHeadInput" readonly TYPE="text" Value="�ѐ��" size="5"></td><!-- S A M -->
205				<td><INPUT class="InvHeadInput4" readonly TYPE="text" Value="������" size="6"></td><!-- S A M -->
206				<td><INPUT class="InvHeadInput2" readonly TYPE="text" Value="���� ������" size="9"></td>
207			</tr>
208			</TABLE></div></TD>
209			</TR>
210			<tr bgcolor='#CCCC88'>
211			<TD colspan="10"><div style="overflow:auto; height:190px; width:*;">
212			<TABLE Border="0" Cellspacing="1" Cellpadding="0" Dir="RTL" bgcolor="#558855">
213			<Tbody id="InquiryLines">
214
215<%		
216	i=0
217	mySQL="SELECT * FROM InquiryLines LEFT OUTER JOIN invoiceItems ON InquiryLines.item = invoiceItems.id WHERE (Inquiry='"& InquiryID & "') "
218	Set RS1 = conn.Execute(mySQL)
219	while not(RS1.eof) 
220	if RS1("Item") <> 39999 then
221		i=i+1
222%>
223			<tr bgcolor='#F0F0F0' onclick="setCurrentRow(this.rowIndex);" >
224				<td align='center' width="25px"><%=i%></td>
225				<td dir="LTR"><INPUT class="InvRowInput" TYPE="text" NAME="Items" value="<%=RS1("Item")%>" size="3" Maxlength="6" onKeyPress="return mask(this);" onfocus="setCurrentRow(this.parentNode.parentNode.rowIndex);" onChange='return check(this);'>
226				<INPUT TYPE="hidden" name="type" value="<%=RS1("type")%>">
227				<INPUT TYPE="hidden" name="fee" value="<%=RS1("fee")%>">
228				<input type='hidden' name='hasVat' value='<%=text2value(RS1("hasVat"))%>'>
229				</td>
230				<td dir="RTL"><INPUT class="InvRowInput2" TYPE="text" NAME="Descriptions" value="<%=RS1("Description")%>" size="30"></td>
231				<td dir="LTR"><INPUT class="InvRowInput2" TYPE="text" NAME="Lengths" value="<%=RS1("Length")%>" size="2" onBlur="setFeeQtty(this);"></td>
232				<td dir="LTR"><INPUT class="InvRowInput2" TYPE="text" NAME="Widths" value="<%=RS1("Width")%>" size="2" onBlur="setFeeQtty(this);"></td>
233				<td dir="LTR"><INPUT class="InvRowInput2" TYPE="text" NAME="Qttys" value="<%=RS1("Qtty")%>" size="3" onBlur="setFeeQtty(this);"></td>
234				<td dir="LTR"><INPUT class="InvRowInput2" TYPE="text" NAME="Sets" value="<%=RS1("Sets")%>" size="2" onBlur="setFeeQtty(this);"></td>
235				<td dir="LTR"><INPUT class="InvRowInput" TYPE="text" NAME="AppQttys" value="<%=Separate(RS1("AppQtty"))%>" size="6" onBlur="setPrice(this);"></td>
236				<td dir="LTR"><INPUT class="InvRowInput" TYPE="text" NAME="Fees" value="<%if RS1("AppQtty") <> 0 then response.write Separate(RS1("Price")/RS1("AppQtty")) else response.write "0"%>" size="7" onBlur="setPrice(this);"></td>
237				<td dir="LTR"><INPUT class="InvRowInput" TYPE="text" NAME="Prices" value="<%=Separate(RS1("Price"))%>" size="9" readonly tabIndex="9999"></td>
238				<td dir="LTR"><INPUT class="InvRowInput" TYPE="text" NAME="Discounts" value="<%=Separate(RS1("Discount"))%>" size="7" onBlur="setPrice(this);"></td><!-- S A M -->
239				<td dir="LTR"><INPUT class="InvRowInput" TYPE="text" NAME="Reverses" value="<%=Separate(RS1("Reverse"))%>" size="5" onBlur="setPrice(this);" onfocus="setCurrentRow(this.parentNode.parentNode.rowIndex);"></td><!-- S A M -->
240				<td dir="LTR"><INPUT class="InvRowInput4" TYPE="text" Name="Vat" value="<%=Separate(RS1("Vat"))%>" size="6" readonly></td><!-- S A M -->
241				<td dir="LTR"><INPUT class="InvRowInput2" TYPE="text" NAME="AppPrices" value="<%=Separate(RS1("Price") - RS1("Discount") - RS1("Reverse") + RS1("Vat"))%>" size="9" readonly tabIndex="9999"></td><!-- S A M -->
242			</tr>
243<%
244	end if
245		RS1.moveNext
246	wend
247	RS1.close
248%>
249			<tr bgcolor='#F0F0F0' onclick="setCurrentRow(this.rowIndex);" >
250				<td colspan="15">
251					<INPUT class="InvGenButton" TYPE="button" value="�����" onkeyDown="if(event.keyCode==9) {setCurrentRow(this.parentNode.parentNode.rowIndex); return false;};" onClick="addRow();">
252				</td>
253			</tr>
254			</Tbody></TABLE></div>
255			</TD>
256			</tr>
257			<tr bgcolor='#CCCC88'>
258			<TD colspan="10"><div>
259			<TABLE Border="0" Cellspacing="1" Cellpadding="0" Dir="RTL" bgcolor="#CCCC88">
260			<tr bgcolor='#CCCC88'>
261				<td colspan='9' width='500px'>***����� ��� �ǘ��� ��� �� ��� ��� ����� ��***</td>
262				<!--td align='center' width="25px"> &nbsp; </td>
263				<td><INPUT readonly class="InvHeadInput" TYPE="text" size="3" ></td>
264				<td><INPUT readonly class="InvHeadInput" TYPE="text" size="30"></td>
265				<td><INPUT readonly class="InvHeadInput" TYPE="text" size="2"></td>
266				<td><INPUT readonly class="InvHeadInput" TYPE="text" size="2"></td>
267				<td><INPUT readonly class="InvHeadInput" TYPE="text" size="3"></td>
268				<td><INPUT readonly class="InvHeadInput" TYPE="text" size="2"></td>
269				<td><INPUT readonly class="InvHeadInput" TYPE="text" size="6"></td>
270				<td><INPUT readonly class="InvHeadInput" TYPE="text" size="7"></td-->
271				<td dir="LTR"><INPUT readonly class="InvHeadInput3" Name="TotalPrice" value="<%=Separate(totalPrice)%>" TYPE="text" size="9"></td>
272				<!-- S A M -->
273				<td dir="LTR"><INPUT readonly class="InvHeadInput3" Name="TotalDiscount" value="<%=Separate(totalDiscount)%>" TYPE="text" size="7"></td>
274				<td dir="LTR"><INPUT readonly class="InvHeadInput3" Name="TotalReverse" value="<%=Separate(totalReverse)%>" TYPE="text" size="5"></td>
275				<td dir="LTR"><INPUT readonly class="InvHeadInput3" Name="TotalVat" value="<%=Separate(totalVat)%>" TYPE="text" size="6"></td>
276				<td dir="LTR"><INPUT readonly class="InvHeadInput3" Name="Payable" value="<%=Separate(totalPrice - totalDiscount - totalReverse + totalVat)%>" TYPE="text" size="9"></td>
277			</tr>
278			<tr bgcolor='#CCCC88'>
279				<td colspan="9"> &nbsp; </td>
280				<td dir="LTR"><INPUT readonly class="InvHeadInput" TYPE="text" size="9"></td>
281				<!-- S A M -->
282				<td dir="LTR"><INPUT readonly class="InvHeadInput3" TYPE="text" Name="TPDiscount" value="<%=Pourcent(totalDiscount,totalPrice) & "%�����"%>" size="7"></td>
283				<td dir="LTR"><INPUT readonly class="InvHeadInput3" TYPE="text" Name="TPReverse" value="<%=Pourcent(totalReverse,totalPrice) & "%�ѐ��"%>" size="5"></td>
284				<td dir="LTR"><INPUT readonly calss="InvHeadINput" TYPE="text" size="6" value="3%������"></td>
285				<td dir="LTR"><INPUT readonly class="InvHeadInput" TYPE="text" size="9" value="��� ���"></td>
286			</tr>
287			</TABLE></div></TD>
288			</TR>
289		</table>
290		<TABLE Border="0" Cellspacing="5" Cellpadding="0" Dir="RTL" align='left'>
291		<tr>
292			<td align='center'>&nbsp;<!-- <INPUT class="InvGenButton" TYPE="button" value="����� ������" onclick="ApproveInvoice();"> --></td>
293			<td width="40">&nbsp;</td>
294			<td align='center'>&nbsp;<!-- <INPUT class="InvGenButton" TYPE="button" value="���� ������" onclick="IssueInvoice();"> --></td>
295			<td width="40">&nbsp;</td>
296			<td align='center'><INPUT class="InvGenButton" TYPE="button" value="����� " onclick="submitOperations();"></td>
297			<td align='center'><INPUT class="InvGenButton" TYPE="button" value="������" onclick="window.location='AccountReport.asp?act=showInquiry&inquiry=<%=InquiryID%>';"></td>
298		</tr>
299		</TABLE>
300		</FORM>
301		<SCRIPT LANGUAGE="JavaScript">
302		<!--
303			//document.getElementsByName("Items")[0].focus();
304		//-->
305		</SCRIPT>
306
307<%
308elseif request("act")="submitEdit" then
309
310	'******************** Checking and Preparing Input ****************
311	errorFound=false
312	ON ERROR RESUME NEXT
313
314		InquiryID=		clng(request.form("InquiryID"))
315		CustomerID=		clng(request.form("CustomerID"))
316
317		issueDate=	request.form("issueDate")
318
319		if request.form("IsA") = "on" then 
320			IsA=1 
321			InquiryNo=request.form("InquiryNo")
322			if InquiryNo <> "" then InquiryNo = clng(InquiryNo)
323		else 
324			IsA=0
325			InquiryNo=""
326		end if
327			
328		for i=1 to request.form("selectedOrders").count
329			theOrder=		clng(request.form("selectedOrders")(i))
330			mySQL="SELECT ID FROM Orders WHERE ID=" & theOrder 
331			Set rs=conn.Execute(mySQL)
332			if rs.eof then
333				errorFound=True
334				exit for
335			end if
336			rs.close
337		next
338
339		Set rs= Nothing
340
341		mySQL="SELECT * FROM Inquiries WHERE (ID='"& InquiryID & "')"
342		Set rs= conn.Execute(mySQL)
343		if NOT rs.eof then
344			voided=		rs("Voided")
345			issued=		rs("Issued")
346			approved=	rs("Approved")
347			isReverse=	rs("IsReverse")
348			ApprovedBy=	rs("ApprovedBy")
349		else
350			errorFound=True
351		end if
352
353		if Err.Number<>0 then
354			Err.clear
355			errorFound=True
356		end if
357
358		if NOT errorFound AND NOT issued then
359			TotalPrice	=		0
360			TotalDiscount =		0
361			TotalReverse =		0
362			TotalReceivable =	0
363			TotalVat =			0
364			RFD =				0
365
366			for i=1 to request.form("Items").count 
367
368				theItem =			clng(text2value(request.form("Items")(i)))
369				mySQL="SELECT ID FROM InvoiceItems WHERE ID=" & theItem 
370				Set rs=conn.Execute(mySQL)
371				if rs.eof then
372					errorFound=True
373					exit for
374				end if
375				rs.close
376
377				theDescription =	left(sqlSafe(request.form("Descriptions")(i)),100)
378
379				theAppQtty =		cdbl(text2value(request.form("AppQttys")(i)))
380				thePrice =			clng(text2value(request.form("Prices")(i)))
381
382				theDiscount =		text2value(request.form("Discounts")(i))
383				theReverse =		text2value(request.form("Reverses")(i))
384
385				theLength =			text2value(request.form("Lengths")(i))
386				theWidth =			text2value(request.form("Widths")(i))
387				theQtty =			text2value(request.form("Qttys")(i))
388				theSets =			text2value(request.form("Sets")(i))
389				theVat =			text2value(request.form("Vat")(i))
390				'theHasVat =			text2value(request.form("hasVat")(i))
391
392				if theDiscount <>"" then theDiscount= clng(theDiscount)
393				if theReverse <> "" then theReverse = clng(theReverse)
394
395				if theLength <>	"" then  theLength	= cdbl(theLength)
396				if theWidth <> ""  then	 theWidth	= cdbl(theWidth) 
397				if theQtty <> ""   then	 theQtty	= clng(theQtty)
398				if theSets <> ""   then	 theSets	= clng(theSets)
399
400				TotalPrice	=		TotalPrice + thePrice
401				TotalDiscount =		TotalDiscount + theDiscount
402				TotalReverse =		TotalReverse + theReverse
403				TotalReceivable =	TotalReceivable + (thePrice - theDiscount - theReverse + theVat)
404				TotalVat =			TotalVat + theVat
405
406			next
407		RFD = TotalReceivable - fix(TotalReceivable / 1000) * 1000
408		'RFD = RFD / 1.03
409		TotalReceivable = TotalReceivable - RFD
410		TotalDiscount = TotalDiscount + RFD
411		end if
412
413		if Err.Number<>0 then
414			Err.clear
415			errorFound=True
416		end if
417
418	ON ERROR GOTO 0
419
420	if errorFound then
421		response.write "<br>" 
422		call showAlert ("��� �� �����",CONST_MSG_ERROR) 
423		response.end
424	end if
425	'^^^^---------------- Checking Input ------------^^^^
426
427	if isReverse then
428		'Check for permission for EDITTING Rev. Invoice
429		if not Auth(6 , 5) then NotAllowdToViewThisPage()
430		itemType=4 
431	else
432		'Check for permission for EDITTING Inquiry
433		if not Auth(6 , 3) then NotAllowdToViewThisPage()
434		itemType=1
435	end if
436
437	if voided then
438		Conn.close
439		response.redirect "AccountReport.asp?act=showInquiry&inquiry="& InquiryID & "&errmsg=" & Server.URLEncode("��� ������ ���� ���� ��� ���.")
440	elseif issued then
441		if Auth(6 , "A") then
442			' Has the Priviledge to change the Inquiry / Reverse Inquiry
443
444			'mySQL="SELECT ID FROM ARItems WHERE (Type='"& itemType & "') AND (GL_Update=1) AND (Link='"& InvoiceID & "')"
445			'Changed by Kid ! 831124
446			mySQL="SELECT ARItems.ID, ARItems.GL_Update, EffGLRows.GL, EffGLRows.GLDocID FROM ARItems LEFT OUTER JOIN (SELECT Link, GL, GLDocID FROM EffectiveGLRows WHERE SYS = 'AR') EffGLRows ON ARItems.ID = EffGLRows.Link WHERE (ARItems.Type = '"& itemType & "') AND (ARItems.Link = '"& InquiryID & "')"
447
448			Set RS2 = conn.Execute(mySQL)
449
450			if RS2.eof then
451				Conn.close
452				response.redirect "AccountReport.asp?act=showInquiry&inquiry="& InquiryID & "&errmsg=" & Server.URLEncode("��� !! <br><br> ���� ���.")
453			else
454				if RS2("GL_Update") = False  then
455					tmpGL=RS2("GL")
456					tmpGLDoc=RS2("GLDocID")
457					Conn.close
458					response.redirect "AccountReport.asp?act=showInquiry&inquiry="& InquiryID & "&errmsg=" & Server.URLEncode("���� ���� ��� ������ ��� �������� ���� ��� ���.<br><br>���� ��:"& tmpGL & " ��� �����: "& tmpGLDoc & " .")
459				else
460					ARItemID=RS2("ID")
461					IssuedButEdit=true
462				end if
463			end if
464			RS2.close
465		else
466			Conn.close
467			response.redirect "AccountReport.asp?act=showInquiry&inquiry="& InquiryID & "&errmsg=" & Server.URLEncode("��� ������ ���� ���� ��� ���.")
468		end if
469	elseif approved then 
470		call UnApproveInquiry ( InquiryID , ApprovedBy )
471	end if
472	
473
474	'******************* Editing  *******************
475	' ****
476	if IssuedButEdit then
477		' Only Updating  IssuedDate, Number & IsA
478		'				 and related Orders
479
480		'---- Checking wether issueDate is valid in current open GL
481		If Not CheckDateFormat(issueDate) Then
482			Conn.close
483			response.redirect "AccountReport.asp?act=showInquiry&inquiry="& InquiryID & "&errmsg=" & Server.URLEncode("����� ���� ��� ����� ����.")
484		end if
485
486		if (issueDate < session("OpenGLStartDate")) OR (issueDate > session("OpenGLEndDate")) then
487			Conn.close
488			response.redirect "AccountReport.asp?act=showInquiry&inquiry="& InquiryID & "&errmsg=" & Server.URLEncode("���!<br>����� ���� ��� ����� ����. <br>(�� ��� ���� ���� ����)")
489		end if 
490		'----
491
492		mySQL="UPDATE Inquiries SET IssuedDate=N'" & issueDate & "', Number='"& InquiryNo & "', IsA='"& IsA & "' WHERE (ID='"& InquiryID & "')"
493		conn.Execute(mySQL)
494
495		'if IsA then
496		'	GLAccount=	"91001"	'This must be changed... (Sales A)
497		'else
498		'	GLAccount=	"91002"	'This must be changed... (Sales B)
499		'end if
500		'
501		' Changed By Kid 860118 , seasing to use Sales B
502
503		GLAccount=	"91001"	'This must be changed... (Sales A)
504
505		conn.Execute("UPDATE ARItems SET GL='"& OpenGL & "', EffectiveDate='" & issueDate & "', GLAccount='"& GLAccount & "' WHERE (ID='" & ARItemID & "')")
506
507		'**************** Updating Inquiry-Order Relations ****************
508		'mySQL="UPDATE Orders SET Closed=0 WHERE ID IN (SELECT [Order] FROM InvoiceOrderRelations WHERE (Invoice= '" & InvoiceID & "'))"
509		'Changed By Kid ! 840509 
510		'set orders which are ONLY related to this invoice, "Open"
511		'that means, orders which are related to this invoice and are NOT related to any OTHER issued invoices.
512		mySQL ="UPDATE Orders SET Closed=0 WHERE ID IN (SELECT [Order] FROM InquiryOrderRelations WHERE (Inquiry = '" & InquiryID & "') AND ([Order] NOT IN (SELECT InquiryOrderRelations.[ORDER] FROM Inquiries INNER JOIN InquiryOrderRelations ON Inquiries.ID = InquirieOrderRelations.Inquiry WHERE (Inquiries.Issued = 1) AND (Inquiries.Voided = 0) AND (Inquiries.isReverse = 0) AND (Inquiries.ID <> '" & InquiryID & "'))))"
513		conn.Execute(mySQL)
514
515		mySQL ="DELETE FROM InquiryOrderRelations WHERE (Inquiry='" & InquiryID & "')"
516		'mySQL ="DELETE FROM InvoiceOrderRelations WHERE (Invoice = '" & InvoiceID & "') AND ([Order] NOT IN (SELECT InvoiceOrderRelations.[ORDER] FROM Invoices INNER JOIN InvoiceOrderRelations ON Invoices.ID = InvoiceOrderRelations.Invoice WHERE (Invoices.Issued = 1) AND (Invoices.Voided = 0) AND (Invoices.isReverse = 0) AND (Invoices.ID <> '" & InvoiceID & "')))"
517		conn.Execute(mySQL)
518		
519
520		for i=1 to request.form("selectedOrders").count
521			theOrder=	clng(request.form("selectedOrders")(i))
522			mySQL="INSERT INTO InquiryOrderRelations (Inquiry,[Order]) VALUES ('" & InquiryID & "', '" & theOrder & "')"
523			conn.Execute(mySQL)
524		next
525
526		conn.Execute("UPDATE Orders SET Closed=1 WHERE ID IN (SELECT [Order] FROM InquiryOrderRelations WHERE (Inquiry='" & InquiryID & "'))")
527		'^^^^------------ Updating Inquiry-Order Relations ------------^^^^
528
529		conn.close
530		response.redirect "AccountReport.asp?act=showInquiry&inquiry=" & InquiryID & "&msg=" &Server.URLEncode("��� ������ ���� ���� ��� ���.<br>�э�� �� ��� ����� ����� �� ��� �ǘ��� �� ����� �����<br>���� ��� �� ��� ��� �� ʘ��� �����.")
531	else
532' S A M
533'response.write(totalDiscount)
534'response.end
535		mySQL="UPDATE Inquiries SET Customer='"& CustomerID & "', Number='"& InquiryNo & "', TotalPrice='"& TotalPrice & "', TotalDiscount='"& TotalDiscount & "', TotalReverse='"& TotalReverse & "', TotalReceivable='"& TotalReceivable & "' , IsA='"& IsA & "', TotalVat='" & totalVat & "' WHERE (ID='"& InquiryID & "')"
536		conn.Execute(mySQL)
537
538		mySQL="DELETE FROM InquiryLines WHERE (Inquiry='"& InquiryID & "')"
539		conn.Execute(mySQL)
540
541		'**************************** Inserting Inquiry Lines ****************
542		for i=1 to request.form("Items").count 
543			theItem =			clng(text2value(request.form("Items")(i)))
544			theDescription =	left(sqlSafe(request.form("Descriptions")(i)),100)
545
546			theAppQtty =		cdbl(text2value(request.form("AppQttys")(i)))
547			thePrice =			clng(text2value(request.form("Prices")(i)))
548
549			theDiscount =		text2value(request.form("Discounts")(i))
550			theReverse =		text2value(request.form("Reverses")(i))
551
552			theLength =			text2value(request.form("Lengths")(i))
553			theWidth =			text2value(request.form("Widths")(i))
554			theQtty =			text2value(request.form("Qttys")(i))
555			theSets =			text2value(request.form("Sets")(i))
556			theVat =			clng(text2value(request.form("Vat")(i)))
557			theHasVat =			text2value(request.form("hasVat")(i))
558
559			if theDiscount <>"" then theDiscount= clng(theDiscount)
560			if theReverse <> "" then theReverse = clng(theReverse)
561
562			if theLength <>	"" then  theLength	= cdbl(theLength)
563			if theWidth <> ""  then	 theWidth	= cdbl(theWidth) 
564			if theQtty <> ""   then	 theQtty	= clng(theQtty)
565			if theSets <> ""   then	 theSets	= clng(theSets)
566
567			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 &")"
568			conn.Execute(mySQL)
569		next 
570		if RFD > 0 then
571			theItem =			39999
572			theDescription =	"����� ��� �ǘ���"
573
574			theAppQtty =		0
575			thePrice =			0
576
577			theDiscount =		RFD
578			theReverse =		0
579
580			theLength =			0
581			theWidth =			0
582			theQtty =			0
583			theSets =			0
584			theVat =			0
585			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 & "')"
586			conn.Execute(mySQL)
587		end if
588
589		'**************** Updating Inquiry-Order Relations ****************
590		mySQL="DELETE FROM InquiryOrderRelations WHERE (Inquiry='" & InquiryID & "')"
591		conn.Execute(mySQL)
592		for i=1 to request.form("selectedOrders").count
593			theOrder=	clng(request.form("selectedOrders")(i))
594			mySQL="INSERT INTO InquiryOrderRelations (Inquiry,[Order]) VALUES ('" & InquiryID & "', '" & theOrder & "')"
595			conn.Execute(mySQL)
596		next
597		'^^^^------------ Updating Inquiry-Order Relations ------------^^^^
598
599	end if
600	'****
601	'^^^^--------------- Editing  ---------------^^^^
602
603	response.redirect "AccountReport.asp?act=showInquiry&inquiry=" & InquiryID
604
605elseif request("act")="approveInquiry" then
606
607	if not Auth(6 , "C") then		
608		'Doesn't have the Priviledge to APPROVE the Inquiry 
609		response.write "<br>" 
610		call showAlert ("��� ���� �� ����� ������ ������",CONST_MSG_ERROR) 
611		response.end
612	end if
613
614	if request("inquiry")<>"" then
615
616		InquiryID=request("inquiry")
617		if not(isnumeric(request("inquiry"))) then
618			ShowErrorMessage("���")
619			response.end
620		end if
621		mySQL="SELECT * FROM Inquiries WHERE (ID='"& InquiryID & "')"
622		Set RS1 = conn.Execute(mySQL)
623		if RS1.eof then
624			ShowErrorMessage("���� ��� ")
625			response.end
626		else
627			if RS1("Voided") = True then
628				Conn.close
629				response.redirect "AccountReport.asp?act=showInquiry&inquiry="& InquiryID & "&errmsg=" & Server.URLEncode("��� ������ ���� ���� ��� ���.")
630			elseif RS1("Issued") = True then
631				Conn.close
632				response.redirect "AccountReport.asp?act=showInquiry&inquiry="& InquiryID & "&errmsg=" & Server.URLEncode("��� ������ ���� ���� ��� ���.")
633			elseif RS1("Approved") = True then
634				Conn.close
635				response.redirect "AccountReport.asp?act=showInquiry&inquiry="& InquiryID & "&errmsg=" & Server.URLEncode("��� ������ ���� ����� ��� ���.")
636			end if
637		end if
638	else
639		ShowErrorMessage("���")
640		response.end
641	end if
642	
643	mySQL="UPDATE Inquiries SET Approved=1, ApprovedDate=N'"& shamsiToday() & "', ApprovedBy='"& session("ID") & "' WHERE (ID='"& InquiryID & "')"
644	conn.Execute(mySQL)
645
646	response.redirect "AccountReport.asp?act=showInquiry&inquiry="& InquiryID 
647
648elseif request("act")="IssueInquiry" then
649
650	if not Auth(6 , "D") then		
651		'Doesn't have the Priviledge to ISSUE the Inquiry
652		response.write "<br>" 
653		call showAlert ("��� ���� �� ���� ������ ������",CONST_MSG_ERROR) 
654		response.end
655	end if
656
657	ON ERROR RESUME NEXT
658		InquiryID=		clng(request("Inquiry"))
659
660		if Err.Number<>0 then
661			Err.clear
662			conn.close
663			response.redirect "top.asp?errMsg=" & Server.URLEncode("���!")
664		end if
665	ON ERROR GOTO 0
666
667	creationDate=	shamsiToday() 
668	issueDate=		SqlSafe(request("issueDate"))
669	if issueDate="" then issueDate=creationDate
670
671	if issueDate<>creationDate then
672		if Auth(6 , "I") then
673			' can ISSUE the Inquiry / Rev. Inquiry on another Date
674
675			'---- Checking wether issueDate is valid in current open GL
676			If Not CheckDateFormat(issueDate) Then
677				Conn.close
678				response.redirect "AccountReport.asp?act=showInquiry&inquiry="& InquiryID & "&errmsg=" & Server.URLEncode("����� ���� ��� ����� ����.")
679			end if
680
681			if (issueDate < session("OpenGLStartDate")) OR (issueDate > session("OpenGLEndDate")) then
682				Conn.close
683				response.redirect "AccountReport.asp?act=showInquiry&inquiry="& InquiryID & "&errmsg=" & Server.URLEncode("���!<br>����� ���� ��� ����� ����. <br>(�� ��� ���� ���� ����)")
684			end if 
685			'----
686		else
687			'Doesn't have the Priviledge to ISSUE the Inquiry on another Date
688			response.write "<br>" 
689			call showAlert ("��� ���� �� ���� ������ �� ��� ����� ������",CONST_MSG_ERROR) 
690			response.end
691		end if
692	end if
693
694	'---- Checking wether issueDate is valid in current open GL
695	If Not CheckDateFormat(issueDate) Then
696		Conn.close
697		response.redirect "AccountReport.asp?act=showInquiry&inquiry="& InquiryID & "&errmsg=" & Server.URLEncode("���!<br>����� ���� ����� ����.")
698	end if
699
700	if (issueDate < session("OpenGLStartDate")) OR (issueDate > session("OpenGLEndDate")) then
701		Conn.close
702		response.redirect "AccountReport.asp?act=showInquiry&inquiry="& InquiryID & "&errmsg=" & Server.URLEncode("���!<br>����� ���� ����� ����. <br>(�� ��� ���� ���� ����)")
703	end if 
704	'----
705
706	mySQL="SELECT * FROM Inquiries WHERE (ID='"& InquiryID & "')"
707	Set RS1 = conn.Execute(mySQL)
708	if RS1.eof then
709		conn.close
710		response.redirect "top.asp?errMsg=" & Server.URLEncode("���! ������ �� �����" & InquiryID & " ���� ���.")
711	else
712		voided=			RS1("Voided")
713		issued=			RS1("Issued")
714		approved=		RS1("Approved")
715		isReverse=		RS1("IsReverse")
716		customerID=		RS1("Customer")
717		inquiryFee=		RS1("TotalReceivable")
718		IsA =			RS1("IsA")
719		Vat =			RS1("TotalVat")' sam
720
721		if voided then
722			Conn.close
723			response.redirect "AccountReport.asp?act=showInquiry&inquiry="& InquiryID & "&errmsg=" & Server.URLEncode("��� ������ ���� ���� ��� ���.")
724		elseif issued then
725			Conn.close
726			response.redirect "AccountReport.asp?act=showInquiry&inquiry="& InquiryID & "&errmsg=" & Server.URLEncode("��� ������ ���� ���� ��� ���.")
727		elseif not approved then
728			Conn.close
729			response.redirect "?act=editInquiry&inquiry="& InquiryID & "&errmsg=" & Server.URLEncode("��� ������ ����� ���� ���.")
730		end if
731	end if
732
733	mySQL="UPDATE Inquiries SET Issued=1, IssuedDate=N'"& issueDate & "', IssuedBy='"& session("ID") & "' WHERE (ID='"& InquiryID & "')"
734	conn.Execute(mySQL)
735
736	if isReverse then
737		isCredit=1
738		itemType=4 
739	else
740		isCredit=0
741		itemType=1
742		'----------------------- Declaring the related orders as closed --------------
743		conn.Execute("UPDATE Orders SET Closed=1 WHERE ID IN (SELECT [Order] FROM InquiryOrderRelations WHERE (Inquiry='" & InquiryID & "'))")
744	end if
745
746	'**************************** Creating ARItem for Inquiry / Reverse Inquiry  ****************
747	'*** Type = 1 means ARItem is an Inquiry
748	'*** Type = 4 means ARItem is a Reverse Inquiry
749
750	firstGLAccount=	"13003"	'This must be changed... (Business Debitors)
751	'if IsA then
752	'	GLAccount=	"91001"	'This must be changed... (Sales A)
753	'else
754	'	GLAccount=	"91002"	'This must be changed... (Sales B)
755	'end if
756	'
757	' Changed By Kid 860118 , seasing to use Sales B
758
759	GLAccount=	"91001"	'This must be changed... (Sales A)
760	
761	mySQL="INSERT INTO ARItems (GLAccount, GL, FirstGLAccount, Account, EffectiveDate, IsCredit, Type, Link, AmountOriginal, CreatedDate, CreatedBy, RemainedAmount, Vat) VALUES ('" &_
762	GLAccount & "', '"& OpenGL & "', '"& firstGLAccount & "', '"& CustomerID & "', N'"& issueDate & "', '"& isCredit & "', '"& itemType & "', '"& InquiryID & "', '"& inquiryFee & "', N'"& creationDate & "', '"& session("ID") & "', '"& inquiryFee & "', '" & Vat & "')"
763	conn.Execute(mySQL)
764
765	if isReverse then
766		'*** ATTENTION: Increasing AR Balance ....
767		mySQL="UPDATE Accounts SET ARBalance = ARBalance + '"& inquiryFee & "' WHERE (ID='"& CustomerID & "')"
768	else
769		'*** ATTENTION: Decreasing AR Balance ....
770		mySQL="UPDATE Accounts SET ARBalance = ARBalance - '"& inquiryFee & "' WHERE (ID='"& CustomerID & "')"
771	end if
772	conn.Execute(mySQL)
773	conn.close
774	response.redirect "AccountReport.asp?act=showInquiry&inquiry="& InquiryID 
775
776elseif request("act")="voidInquiry" then
777	if not Auth(6 , "F") then		
778		'Doesn't have the Priviledge to VOID the Inquiry 
779		response.write "<br>" 
780		call showAlert ("��� ���� �� ����� ������ ������",CONST_MSG_ERROR) 
781		response.end
782	end if
783
784	comment=sqlSafe(request("comment"))
785
786	InquiryID=request("inquiry")
787	if InquiryID="" or not(isnumeric(InquiryID)) then
788		response.write "<br>" 
789		call showAlert ("��� �� ����� ������",CONST_MSG_ERROR) 
790		response.end
791	end if
792
793	InquiryID=clng(InquiryID)
794	
795	mySQL="SELECT * FROM Inquiries WHERE (ID='"& InquiryID & "')"
796	Set RS1 = conn.Execute(mySQL)
797	if RS1.eof then
798		ShowErrorMessage("���� ��� ")
799		response.end
800	else
801		voided=			RS1("Voided")
802		issued=			RS1("Issued")
803		issuedBy=		RS1("IssuedBy")
804		isReverse=		RS1("IsReverse")
805		customerID=		RS1("Customer")
806		inquiryFee=		RS1("TotalReceivable")
807		IsA =			RS1("IsA")
808		if voided then
809			ShowErrorMessage("��� ������ ���� �� ����� <span dir='LTR'>"& RS1("VoidedDate") & "</span> ���� ��� ���.")
810			response.end
811		end if
812	end if
813	
814	mySQL="UPDATE Inquiries SET Voided=1, VoidedDate=N'"& shamsiToday() & "', VoidedBy='"& session("ID") & "' WHERE (ID='"& InquiryID & "')"
815	conn.Execute(mySQL)
816	
817	if isReverse then
818		isCredit=1
819		itemType=4 
820		itemTypeName="������ �ѐ�� �� ����"
821	else
822		isCredit=0
823		itemType=1
824		itemTypeName="������"
825		'---------- Declaring the related orders as Open  -------------------
826		'mySQL="UPDATE Orders SET Closed=0 WHERE ID IN (SELECT [Order] FROM InvoiceOrderRelations WHERE (Invoice= '" & InvoiceID & "'))"
827		'Changed By Kid ! 840509 
828		'set orders which are ONLY related to this invoice, "Open"
829		'that means, orders which are related to this invoice and are NOT related to any OTHER issued invoices.
830		mySQL ="UPDATE Orders SET Closed=0 WHERE ID IN (SELECT [Order] FROM InquiryOrderRelations WHERE (Inquiry = '" & InquiryID & "') AND ([Order] NOT IN (SELECT InquiryOrderRelations.[ORDER] FROM Inquiries INNER JOIN InquiryOrderRelations ON Inquiries.ID = InquiryOrderRelations.Inquiry WHERE (Inquiries.Issued = 1) AND (Inquiries.Voided = 0) AND (Inquiries.isReverse = 0) AND (Inquiries.ID <> '" & InquiryID & "'))))"
831		conn.Execute(mySQL)
832
833	end if
834
835  '**************************** Voiding ARItem of Inquiry / Reverse Inquiry ****************
836  '*** Type = 1 means ARItem is an Inquiry
837  '*** Type = 4 means ARItem is a Reverse Inquiry
838  '***
839	'*********  Finding the ARItem of Inquiry / Reverse Inquiry
840	mySQL="SELECT ID FROM ARItems WHERE (Type = '"& itemType & "') AND (Link='"& InquiryID & "')"
841	Set RS1=conn.Execute(mySQL)
842	voidedARItem=RS1("ID")
843	'*********  Finding other ARItems related to this Item
844	if isReverse then
845		mySQL="SELECT ID AS RelationID, DebitARItem, Amount FROM ARItemsRelations WHERE (CreditARItem = '"& voidedARItem & "')"
846		Set RS1=conn.Execute(mySQL)
847		Do While not (RS1.eof)
848			'*********  Adding back the amount in the relation, to the credit ARItem ...
849			conn.Execute("UPDATE ARItems SET RemainedAmount=RemainedAmount+ '"& RS1("Amount") & "', FullyApplied=0 WHERE (ID = '"& RS1("DebitARItem") & "')")
850
851			'*********  Deleting the relation
852			conn.Execute("DELETE FROM ARItemsRelations WHERE ID='"& RS1("RelationID") & "'")
853			
854			RS1.movenext
855		Loop
856	else
857		mySQL="SELECT ID AS RelationID, CreditARItem, Amount FROM ARItemsRelations WHERE (DebitARItem = '"& voidedARItem & "')"
858		Set RS1=conn.Execute(mySQL)
859		Do While not (RS1.eof)
860			'*********  Adding back the amount in the relation, to the credit ARItem ...
861			conn.Execute("UPDATE ARItems SET RemainedAmount=RemainedAmount+ '"& RS1("Amount") & "', FullyApplied=0 WHERE (ID = '"& RS1("CreditARItem") & "')")
862
863			'*********  Deleting the relation
864			conn.Execute("DELETE FROM ARItemsRelations WHERE ID='"& RS1("RelationID") & "'")
865			
866			RS1.movenext
867		Loop
868	end if
869
870	'*********  Voiding ARItem 
871	conn.Execute("UPDATE ARItems SET RemainedAmount=0, FullyApplied=0, Voided=1 WHERE (ID = '"& voidedARItem & "')")
872
873	'**************************************************************
874	'*				Affecting Account's AR Balance  
875	'**************************************************************
876	if isReverse then
877		mySQL="UPDATE Accounts SET ARBalance = ARBalance - '"& inquiryFee & "' WHERE (ID='"& CustomerID & "')"
878	else
879		mySQL="UPDATE Accounts SET ARBalance = ARBalance + '"& inquiryFee & "' WHERE (ID='"& CustomerID & "')"
880	end if
881
882	conn.Execute(mySQL)
883	
884	'***
885	'***---------------- End of  Voiding ARItem of Inquiry / Reverse Inquiry ----------------
886
887	' Sending a Message to Issuer ...
888	if trim(comment)<>"" then comment = chr(13) & chr(10) & "[" & comment & "]"
889	MsgTo			=	issuedBy
890	msgTitle		=	"Inquiry Voided"
891
892	msgBody			=	"�ǘ��� ��� ���� "& session("CSRName") & " ���� ��." & comment
893	RelatedTable	=	"inquiries"
894	relatedID		=	inquiryID
895	replyTo			=	0
896	IsReply			=	0
897	urgent			=	1
898	MsgFrom			=	session("ID")
899	MsgDate			=	shamsiToday()
900	MsgTime			=	currentTime10()
901	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 & ")")
902
903
904	' Copying the PreInquiry Data...
905	response.redirect "InquiryInput.asp?act=copyInquiry&inquiry="& InquiryID & "&msg=" & Server.URLEncode(itemTypeName & " ����� "& InquiryID & " ���� ��.")
906
907elseif request("act")="removePreInquiry" then
908	response.write "<br>" 
909
910	if not Auth(6 , "G") then		
911		'Doesn't have the Priviledge to REMOVE the Pre-Inquiry 
912		call showAlert ("��� ���� �� ��� ��� ���� ������",CONST_MSG_ERROR) 
913		response.end
914	end if
915
916	InquiryID=request("inquiry")
917	if InquiryID="" or not(isnumeric(InquiryID)) then
918		call showAlert ("��� �� ����� ��� ����",CONST_MSG_ERROR) 
919		response.end
920	end if
921	InquiryID=clng(InquiryID)
922
923	mySQL="SELECT * FROM Inquiries WHERE (ID='"& InquiryID & "')"
924	Set RS1 = conn.Execute(mySQL)
925	if RS1.eof then
926		call showAlert ("��� ���� ���� ���.",CONST_MSG_ERROR) 
927	else
928		voided=			RS1("Voided")
929		issued=			RS1("Issued")
930		isReverse=		RS1("IsReverse")
931		customerID=		RS1("Customer")
932		IsA =			RS1("IsA")
933		if issued then
934			call showAlert ("��� ������ ���� ��� ���.",CONST_MSG_ERROR) 
935		elseif voided then
936			call showAlert ("��� ������ ���� ��� ���.",CONST_MSG_ERROR) 
937		else
938			Conn.execute("DELETE FROM InquiryOrderRelations Where (Inquiry='" & InquiryID & "')")
939
940			'Conn.execute("DELETE FROM InvoiceLines Where (Invoice='" & InvoiceID & "')")
941			'Conn.execute("DELETE FROM Invoices Where (ID='" & InvoiceID & "')")
942			'Changed By Kid 830929
943			'Conn.execute("UPDATE Invoices SET Voided=1 Where (ID='" & InvoiceID & "')")
944			'Changed By Kid 8400502 also adding VoidedBy & VoidedDate
945			Conn.execute("UPDATE Inquiries SET Voided=1, VoidedDate=N'"& shamsiToday() & "', VoidedBy='"& session("ID") & "' WHERE (ID='"& InquiryID & "')")
946
947			call showAlert ("��� ���� ��� ��.",CONST_MSG_INFORM) 
948		end if
949	end if
950	response.end
951end if
952conn.Close
953%>
954<!--#include file="include_JS_for_Inquiries.asp" -->
955<SCRIPT LANGUAGE="JavaScript">
956<!--
957function ApproveInquiry(){
958	if (confirm("��� ����� ����� �� �� ������ ��� ������ �� '�����' ���Ͽ\n\n(����: ������� ����� ��� ����)\n"))
959		window.location="?act=approveInquiry&inquiry=<%=InquiryID%>";
960}
961function IssueInquiry(){
962	if (confirm("��� ����� ����� �� �� ������ ��� ������ �� '����' ���Ͽ\n\n(����: ������� ����� ��� ����)\n"))
963		window.location="?act=IssueInquiry&inquiry=<%=InquiryID%>";
964}
965function VoidInquiry(){
966	if (confirm("��� ����� ����� �� �� ������ ��� ������ �� '����' ���Ͽ\n"))
967		window.location="?act=voidInquiry&inquiry=<%=InquiryID%>";
968}
969//-->
970</SCRIPT>
971<!--#include file="tah.asp" -->