PageRenderTime 22ms CodeModel.GetById 10ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/beta/AR/InvoiceInput.asp

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