PageRenderTime 33ms CodeModel.GetById 16ms app.highlight 9ms RepoModel.GetById 1ms app.codeStats 0ms

/beta/AR/InvoiceEdit.asp.bak

http://github.com/khaneh/Orders
Unknown | 1259 lines | 1107 code | 152 blank | 0 comment | 0 complexity | 44c0cb31e8220a0d7c87bf5490a17a1a MD5 | raw file

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

Large files files are truncated, but you can click here to view the full file