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