/beta/AR/InvoiceEdit.asp

http://github.com/khaneh/Orders · ASP · 1514 lines · 1127 code · 171 blank · 216 comment · 162 complexity · f93a5fdcfb1610c18b07624add893b81 MD5 · raw file

Large files are truncated click here to view the full 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. div.InvHead {background-color: #CC8;text-align: center;padding: 5px 0;}
  24. div.InvHead2 {background-color: #AC7;text-align: center;padding: 5px 0;}
  25. div.InvHead3 {background-color: #F0F0F0;text-align: center;padding: 5px 0;}
  26. div.InvHead4 {background-color: #F90;text-align: center;padding: 5px 0;}
  27. div.InvLine {background-color: #F0F0F0;text-align: right;}
  28. div.InvLine2 {background-color: #F0FFF0;text-align: right;}
  29. div.InvLine4 {background-color: #FFD3A8;text-align: right;}
  30. .InvRowInput { font-family:tahoma; font-size: 9pt; border: none; background-color: #F0F0F0; text-align:right;}
  31. .InvHeadInput { font-family:tahoma; font-size: 9pt; border: none; background-color: #CCCC88; text-align:center;}
  32. .InvRowInput2 { font-family:tahoma; font-size: 9pt; border: none; background-color: #F0FFF0; text-align:right; height: 22px; margin: 0;padding: 0;}
  33. .InvRowInput4 { font-family:tahoma; font-size: 9pt; border: none; background-color: #FFD3A8; direction:LTR; text-align:right;}
  34. .InvHeadInput2 { font-family:tahoma; font-size: 9pt; border: none; background-color: #AACC77; text-align:center;}
  35. .InvHeadInput3 { font-family:tahoma; font-size: 9pt; border: none; background-color: #F0F0F0; text-align:right;}
  36. .InvHeadInput4 { font-family:tahoma; font-size: 9pt; border: none; background-color: #FF9900; text-align:center;}
  37. .InvGenInput { font-family:tahoma; font-size: 9pt; border: none; }
  38. .InvGenButton { font-family:tahoma; font-size: 9pt; border: 1px solid black; }
  39. .order {background-color: #C3C300;font-weight: bold;padding: 6px 10px 6px 10px;}
  40. .quote {background-color: #AAAAEE;font-weight: bold;padding: 6px 10px 6px 10px;}
  41. #header {width: 100%;border-left: 1px solid #585;border-right: 1px solid #585;}
  42. #header div {padding: 5px 2px;float: right;border-left: 1px solid #585; text-align: center;}
  43. div.invRow {clear: both;float: none;width: 100%;}
  44. div.invRow div {padding: 5px 2px 0 2px;float: right;border-bottom: 1px solid #585;border-left: 1px solid #585;text-align: right;height: 22px;}
  45. table.invTable {border-collapse:collapse; width:100%;}
  46. #tbody{height:60px;overflow-y:auto;width:100%;background:yellow;border-top: 1px solid #585;}
  47. td[class*="td"] {padding: 1px 2px;border-left: 1px solid red;border-bottom: 1px solid red;}
  48. div.td15{width: 15px;}
  49. td.td15{width: 15px;}
  50. div.td40{width: 40px;}
  51. td.td40{width: 40px;}
  52. div.td170{width: 170px;}
  53. td.td170{width: 170px;}
  54. div.td60{width: 60px;}
  55. td.td60{width: 60px;}
  56. div.td80{width: 80px;}
  57. td.td80{width: 80px;}
  58. div.td35{width: 35px;}
  59. td.td35{width: 35px;}
  60. div.td25{width: 25px;}
  61. td.td25{width: 25px;}
  62. div.td55{width: 55px;}
  63. td.td55{width: 55px;}
  64. div.td50{width: 50px;}
  65. td.td50{width: 50px;}
  66. div.td75{width: 75px;}
  67. td.td75{width: 75px;}
  68. </style>
  69. <SCRIPT LANGUAGE="JavaScript">
  70. <!--
  71. var okToProceed=false;
  72. var currentRow=0;
  73. //-->
  74. </SCRIPT>
  75. <%
  76. if request("act")="search" then
  77. if isnumeric(request("order")) then
  78. OrderID = clng(request("order"))
  79. 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)"
  80. Set RS1=Conn.Execute(mySQL)
  81. if RS1.eof then
  82. Conn.close
  83. response.redirect "?errmsg=" & Server.URLEncode(" .")
  84. else
  85. theInvoice=RS1("Invoice")
  86. Conn.close
  87. response.redirect "?act=editInvoice&invoice=" & theInvoice
  88. end if
  89. elseif isnumeric(request("invoice")) then
  90. response.redirect "?act=editInvoice&invoice=" & request("invoice")
  91. else
  92. response.redirect "?errmsg=" & Server.URLEncode(" .")
  93. end if
  94. '-----------------------------------------------------------------------------------------------------
  95. '---------------------------------------------------------------------------------------- Edit Invoice
  96. '-----------------------------------------------------------------------------------------------------
  97. elseif request("act")="editInvoice" then
  98. if isnumeric(request("invoice")) then
  99. InvoiceID=clng(request("invoice"))
  100. mySQL="SELECT * FROM Invoices WHERE (ID='"& InvoiceID & "')"
  101. Set RS1 = conn.Execute(mySQL)
  102. if RS1.eof then
  103. conn.close
  104. response.redirect "?errmsg=" & Server.URLEncode(" .")
  105. end if
  106. else
  107. response.redirect "?errmsg=" & Server.URLEncode(" .")
  108. end if
  109. customerID= RS1("Customer")
  110. creationDate= RS1("CreatedDate")
  111. IssuedDate= RS1("IssuedDate")
  112. totalPrice= cdbl(RS1("totalPrice"))
  113. totalDiscount= cdbl(RS1("totalDiscount"))
  114. totalReverse= cdbl(RS1("totalReverse"))
  115. totalVat = cdbl(RS1("totalVat"))
  116. Voided= RS1("Voided")
  117. Issued= RS1("Issued")
  118. Approved= RS1("Approved")
  119. isReverse= RS1("IsReverse")
  120. IsA= RS1("IsA")
  121. InvoiceNo= RS1("Number")
  122. mySQL="SELECT ID,AccountTitle FROM Accounts WHERE (ID='"& customerID & "')"
  123. Set RS1 = conn.Execute(mySQL)
  124. AccountNo=RS1("ID")
  125. customerName=RS1("AccountTitle")
  126. RS1.close
  127. if isReverse then
  128. 'Check for permission for EDITTING Rev. Invoice
  129. if not Auth(6 , 5) then NotAllowdToViewThisPage()
  130. itemTypeName=" ѐ"
  131. HeaderColor="#FF9900"
  132. else
  133. 'Check for permission for EDITTING Invoice
  134. if not Auth(6 , 3) then NotAllowdToViewThisPage()
  135. itemTypeName=""
  136. HeaderColor="#C3C300"
  137. end if
  138. if Voided then
  139. Conn.close
  140. response.redirect "AccountReport.asp?act=showInvoice&invoice="& InvoiceID & "&errmsg=" & Server.URLEncode(" .")
  141. elseif Issued then
  142. if Auth(6 , "A") then
  143. ' Has the Priviledge to change the Invoice
  144. response.write "<BR>"
  145. if Auth(6,"N") then
  146. set rs=Conn.Execute("select * from effectiveGlrows where sys='AR' and link in (select id from arItems where type=1 and reason=1 and link=" & invoiceID & ")")
  147. if rs.eof then
  148. call showAlert (" .<br>э ύ <br> Ͽ",CONST_MSG_INFORM)
  149. else
  150. response.redirect "AccountReport.asp?act=showInvoice&invoice="& InvoiceID & "&errmsg=" & Server.URLEncode(" ϡ <br> ϡ .")
  151. end if
  152. else
  153. call showAlert (" .<br>э <br> Ͽ",CONST_MSG_INFORM)
  154. end if
  155. else
  156. Conn.close
  157. response.redirect "AccountReport.asp?act=showInvoice&invoice="& InvoiceID & "&errmsg=" & Server.URLEncode(" .")
  158. end if
  159. end if
  160. %>
  161. <!-- -->
  162. <br>
  163. <input type="hidden" Name='tmpDlgArg' value=''>
  164. <input type="hidden" Name='tmpDlgTxt' value=''>
  165. <input type="hidden" name="VatRate" id="VatRate" value="<%=session("VatRate")%>">
  166. <FORM METHOD=POST ACTION="?act=submitEdit">
  167. <table Border="0" align="center" Width="100%" Cellspacing="1" Cellpadding="0" Dir="RTL" bgcolor="#558855">
  168. <tr bgcolor='<%=HeaderColor%>'>
  169. <td colspan='2'>
  170. <TABLE width='100%'>
  171. <TR>
  172. <TD align="left" > <%=itemTypeName%>:</TD>
  173. <TD align="right" width='15%'>&nbsp;<INPUT readonly class="InvGenInput" NAME="InvoiceID" value="<%=InvoiceID%>" style="direction:ltr" TYPE="text" maxlength="10" size="10"></TD>
  174. </TR>
  175. </TABLE></td>
  176. </tr>
  177. <tr bgcolor='<%=HeaderColor%>'>
  178. <td colspan="2">
  179. <TABLE Border="0" Width="100%" Cellspacing="1" Cellpadding="0" Dir="RTL">
  180. <TR>
  181. <TD><table>
  182. <tr>
  183. <td align="left">:</td>
  184. <td align="right">
  185. <span id="customer"><%' after any changes in this span "./Customers.asp" must be revised%>
  186. <INPUT TYPE="hidden" NAME="customerID" value="<%=customerID%>"><span><%=CustomerName%></span>.
  187. </span></td>
  188. <td></td>
  189. </tr>
  190. </table></TD>
  191. <TD align="left"><table>
  192. <tr>
  193. <td align="left"> :</td>
  194. <td dir="LTR">
  195. <INPUT <%'if not Auth(6,"N") then response.write " readonly='readonly' "%> class="InvGenInput" NAME="issueDate" TYPE="text" maxlength="10" size="10" value="<%=IssuedDate%>" onblur="acceptDate(this)"></td>
  196. <td dir="RTL"><%=""%></td>
  197. </tr>
  198. </table></TD>
  199. </TR></TABLE>
  200. </td>
  201. </tr>
  202. <tr bgcolor='<%=HeaderColor%>'>
  203. <TD align="right" width="50%">
  204. /():
  205. <%
  206. mySQL="SELECT * FROM InvoiceOrderRelations inner join Orders on InvoiceOrderRelations.[order]=orders.id WHERE (Invoice='"& InvoiceID & "')"
  207. Set RS1 = conn.Execute(mySQL)
  208. if not rs1.eof then
  209. if rs1("isOrder")="True" then
  210. isOrder="order"
  211. else
  212. isOrder="quote"
  213. end if
  214. end if
  215. %>
  216. <span id="orders" class="<%=isOrder%>">
  217. <%
  218. tempWriteAnd=""
  219. while not(RS1.eof)
  220. response.write tempWriteAnd & Link2Trace(RS1("Order"))
  221. tempWriteAnd=" "
  222. RS1.moveNext
  223. wend
  224. %> </span>&nbsp;
  225. </TD>
  226. <TD align="left"><table>
  227. <tr>
  228. <td align="left">:</td>
  229. <td dir="LTR">
  230. <INPUT class="InvGenInput" NAME="InvoiceNo" value="<%=InvoiceNo%>" style="border:1px solid black;" TYPE="text" maxlength="10" size="10"></td>
  231. <td dir="RTL">
  232. <INPUT TYPE="checkbox" value="on" NAME="IsA" onClick='checkIsA();'
  233. <% if IsA then response.write " checked='checked' "
  234. if Issued and not Auth(6,"N") then response.write " disabled='disabled' "%>> &nbsp;
  235. </td>
  236. </tr>
  237. </table></TD>
  238. </tr>
  239. <tr bgcolor='#CCCC88'>
  240. <TD colspan="10">
  241. <div id="header">
  242. <div class="td15 InvHead">#</div>
  243. <div class="td40 InvHead2"></div>
  244. <div class="td170 InvHead2"></div>
  245. <div class="td25 InvHead2"></div>
  246. <div class="td25 InvHead2"></div>
  247. <div class="td25 InvHead2"></div>
  248. <div class="td25 InvHead2"></div>
  249. <div class="td50 InvHead"> </div>
  250. <div class="td40 InvHead"></div>
  251. <div class="td50 InvHead"></div>
  252. <div class="td50 InvHead"></div>
  253. <div class="td40 InvHead">ѐ</div>
  254. <div class="td50 InvHead4"></div>
  255. <div class="td75 InvHead2"> </div>
  256. </div>
  257. <div id="tbody">
  258. <%
  259. i=0
  260. mySQL="SELECT *,InvoiceLines.ID as lineID,isnull(invoiceItems.fee,0) as ItemFee FROM InvoiceLines LEFT OUTER JOIN invoiceItems ON InvoiceLines.item = invoiceItems.id WHERE (Invoice='"& InvoiceID & "') "
  261. Set RS1 = conn.Execute(mySQL)
  262. while not(RS1.eof)
  263. if RS1("Item") <> 39999 then
  264. i=i+1
  265. %>
  266. <div class="invRow">
  267. <div class="td15 InvLine"><%=i%></div>
  268. <div class="td40 InvLine2"><%=RS1("Item")%>
  269. <input type='hidden' name='hasVat' value='<%=text2value(RS1("hasVat"))%>'>
  270. <input type='hidden' name='lineID' value='<%=RS1("lineID")%>'>
  271. </div>
  272. <div class="td170 InvLine2" style="padding:2px 2px 3px 2px;">
  273. <INPUT class="InvRowInput2" TYPE="text" NAME="Descriptions" value="<%=RS1("Description")%>" size="30">
  274. </div>
  275. <div class="td25 InvLine2"><%=RS1("Length")%></div>
  276. <div class="td25 InvLine2"><%=RS1("Width")%></div>
  277. <div class="td25 InvLine2"><%=RS1("Qtty")%></div>
  278. <div class="td25 InvLine2"><%=RS1("Sets")%></div>
  279. <div class="td50 InvLine"><%=Separate(RS1("AppQtty"))%></div>
  280. <div class="td40 InvLine"><%=Separate(RS1("Price")/RS1("AppQtty"))%></div>
  281. <div class="td50 InvLine"><%=Separate(RS1("Price"))%></div>
  282. <div class="td50 InvLine"><%=Separate(RS1("Discount"))%></div>
  283. <div class="td40 InvLine"><%=Separate(RS1("Reverse"))%></div>
  284. <div class="td50 InvLine4"><%=Separate(RS1("Vat"))%></div>
  285. <div class="td75 InvLine2"><%=Separate(RS1("Price") - RS1("Discount") - RS1("Reverse") + RS1("Vat"))%></div>
  286. </div>
  287. <%
  288. end if
  289. RS1.moveNext
  290. wend
  291. RS1.close
  292. %>
  293. </div>
  294. </TD>
  295. </TR>
  296. <tr bgcolor='#CCCC88'>
  297. <TD colspan="10"><div>
  298. <TABLE Border="0" Cellspacing="1" Cellpadding="0" Dir="RTL" bgcolor="#CCCC88">
  299. <tr bgcolor='#CCCC88'>
  300. <td colspan='9' width='500px'>*** ***</td>
  301. <td dir="LTR"><INPUT readonly class="InvHeadInput3" Name="TotalPrice" value="<%=Separate(totalPrice)%>" TYPE="text" size="9"></td>
  302. <!-- S A M -->
  303. <td dir="LTR"><INPUT readonly class="InvHeadInput3" Name="TotalDiscount" value="<%=Separate(totalDiscount)%>" TYPE="text" size="7"></td>
  304. <td dir="LTR"><INPUT readonly class="InvHeadInput3" Name="TotalReverse" value="<%=Separate(totalReverse)%>" TYPE="text" size="5"></td>
  305. <td dir="LTR"><INPUT readonly class="InvHeadInput3" Name="TotalVat" value="<%=Separate(totalVat)%>" TYPE="text" size="6"></td>
  306. <td dir="LTR"><INPUT readonly class="InvHeadInput3" Name="Payable" value="<%=Separate(totalPrice - totalDiscount - totalReverse + totalVat)%>" TYPE="text" size="9"></td>
  307. </tr>
  308. <tr bgcolor='#CCCC88'>
  309. <td colspan="9"> &nbsp; </td>
  310. <td dir="LTR"><INPUT readonly class="InvHeadInput" TYPE="text" size="9"></td>
  311. <!-- S A M -->
  312. <td dir="LTR"><INPUT readonly class="InvHeadInput3" TYPE="text" Name="TPDiscount" value="<%=Pourcent(totalDiscount,totalPrice) & "%"%>" size="7"></td>
  313. <td dir="LTR"><INPUT readonly class="InvHeadInput3" TYPE="text" Name="TPReverse" value="<%=Pourcent(totalReverse,totalPrice) & "%ѐ"%>" size="5"></td>
  314. <td dir="LTR"><INPUT readonly calss="InvHeadINput" TYPE="text" size="6" value="<%=session("VatRate")%>%"></td>
  315. <td dir="LTR"><INPUT readonly class="InvHeadInput" TYPE="text" size="9" value=" "></td>
  316. </tr>
  317. </TABLE></div></TD>
  318. </TR>
  319. </table>
  320. <TABLE Border="0" Cellspacing="5" Cellpadding="0" Dir="RTL" align='left'>
  321. <tr>
  322. <td align='center'>&nbsp;<!-- <INPUT class="InvGenButton" TYPE="button" value=" " onclick="ApproveInvoice();"> --></td>
  323. <td width="40">&nbsp;</td>
  324. <td align='center'>&nbsp;<!-- <INPUT class="InvGenButton" TYPE="button" value=" " onclick="IssueInvoice();"> --></td>
  325. <td width="40">&nbsp;</td>
  326. <td align='center'><INPUT class="InvGenButton" TYPE="button" value=" " onclick="submitOperations();"></td>
  327. <td align='center'><INPUT class="InvGenButton" TYPE="button" value="" onclick="window.location='AccountReport.asp?act=showInvoice&invoice=<%=InvoiceID%>';"></td>
  328. </tr>
  329. </TABLE>
  330. </FORM>
  331. <SCRIPT LANGUAGE="JavaScript">
  332. <!--
  333. //document.getElementsByName("Items")[0].focus();
  334. //-->
  335. </SCRIPT>
  336. <%
  337. elseif request("act")="submitEdit" then
  338. '******************** Checking and Preparing Input ****************
  339. errorFound=false
  340. ON ERROR RESUME NEXT
  341. InvoiceID= clng(request.form("InvoiceID"))
  342. CustomerID= clng(request.form("CustomerID"))
  343. issueDate= request.form("issueDate")
  344. ' response.write "is A: " & request.form("IsA")
  345. if request.form("IsA") = "on" then
  346. IsA=1
  347. InvoiceNo=request.form("InvoiceNo")
  348. if InvoiceNo <> "" then InvoiceNo = cdbl(InvoiceNo)
  349. else
  350. set rs = Conn.Execute("select * from invoices where id=" & invoiceID)
  351. IsA=0
  352. InvoiceNo=""
  353. if rs("issued") and not auth(6,"N") then
  354. if rs("isA") then
  355. IsA=1
  356. InvoiceNo=request.form("InvoiceNo")
  357. if InvoiceNo <> "" then InvoiceNo = cdbl(InvoiceNo)
  358. end if
  359. end if
  360. end if
  361. ' response.write "<br>is A now:" & IsA
  362. ' response.end
  363. for i=1 to request.form("selectedOrders").count
  364. theOrder = clng(request.form("selectedOrders")(i))
  365. mySQL="SELECT ID FROM Orders WHERE ID=" & theOrder
  366. Set rs=conn.Execute(mySQL)
  367. if rs.eof then
  368. errorFound=True
  369. exit for
  370. end if
  371. rs.close
  372. next
  373. for i=1 to request.form("selectedQuotes").count
  374. theQuote= clng(request.form("selectedQuotes")(i))
  375. mySQL="SELECT ID FROM Quotes WHERE ID=" & theQuote
  376. Set rs=conn.Execute(mySQL)
  377. if rs.eof then
  378. errorFound=True
  379. exit for
  380. end if
  381. rs.close
  382. next
  383. Set rs= Nothing
  384. mySQL="SELECT * FROM Invoices WHERE (ID='"& InvoiceID & "')"
  385. Set rs= conn.Execute(mySQL)
  386. if NOT rs.eof then
  387. voided= rs("Voided")
  388. issued= rs("Issued")
  389. approved= rs("Approved")
  390. isReverse= rs("IsReverse")
  391. ApprovedBy= rs("ApprovedBy")
  392. if issued and not auth(6 , "N") then isA=rs("isA")
  393. else
  394. errorFound=True
  395. end if
  396. if Err.Number<>0 then
  397. Err.clear
  398. errorFound=True
  399. end if
  400. if NOT errorFound then
  401. TotalPrice = 0
  402. TotalDiscount = 0
  403. TotalReverse = 0
  404. TotalReceivable = 0
  405. TotalVat = 0
  406. RFD = 0
  407. for i=1 to request.form("Items").count
  408. theItem = clng(text2value(request.form("Items")(i)))
  409. mySQL="SELECT ID FROM InvoiceItems WHERE ID=" & theItem
  410. Set rs=conn.Execute(mySQL)
  411. if rs.eof then
  412. errorFound=True
  413. exit for
  414. end if
  415. rs.close
  416. theDescription = left(sqlSafe(request.form("Descriptions")(i)),100)
  417. theAppQtty = cdbl(text2value(request.form("AppQttys")(i)))
  418. thePrice = clng(text2value(request.form("Prices")(i)))
  419. theDiscount = text2value(request.form("Discounts")(i))
  420. theReverse = text2value(request.form("Reverses")(i))
  421. theLength = text2value(request.form("Lengths")(i))
  422. theWidth = text2value(request.form("Widths")(i))
  423. theQtty = text2value(request.form("Qttys")(i))
  424. theSets = text2value(request.form("Sets")(i))
  425. theVat = text2value(request.form("Vat")(i))
  426. 'theHasVat = text2value(request.form("hasVat")(i))
  427. if theDiscount <>"" then theDiscount= clng(theDiscount)
  428. if theReverse <> "" then theReverse = clng(theReverse)
  429. if theLength <> "" then theLength = cdbl(theLength)
  430. if theWidth <> "" then theWidth = cdbl(theWidth)
  431. if theQtty <> "" then theQtty = clng(theQtty)
  432. if theSets <> "" then theSets = clng(theSets)
  433. TotalPrice = TotalPrice + thePrice
  434. TotalDiscount = TotalDiscount + theDiscount
  435. TotalReverse = TotalReverse + theReverse
  436. TotalReceivable = TotalReceivable + (thePrice - theDiscount - theReverse + theVat)
  437. TotalVat = TotalVat + theVat
  438. next
  439. RFD = TotalReceivable - fix(TotalReceivable / 1000) * 1000
  440. 'RFD = RFD / 1.03
  441. TotalReceivable = TotalReceivable - RFD
  442. TotalDiscount = TotalDiscount + RFD
  443. end if
  444. if Err.Number<>0 then
  445. Err.clear
  446. errorFound=True
  447. end if
  448. ON ERROR GOTO 0
  449. if errorFound then
  450. response.write "<br>"
  451. call showAlert (" ",CONST_MSG_ERROR)
  452. response.end
  453. end if
  454. '^^^^---------------- Checking Input ------------^^^^
  455. if isReverse then
  456. 'Check for permission for EDITTING Rev. Invoice
  457. if not Auth(6 , 5) then NotAllowdToViewThisPage()
  458. itemType=4
  459. else
  460. 'Check for permission for EDITTING Invoice
  461. if not Auth(6 , 3) then NotAllowdToViewThisPage()
  462. itemType=1
  463. end if
  464. if voided then
  465. Conn.close
  466. response.redirect "AccountReport.asp?act=showInvoice&invoice="& InvoiceID & "&errmsg=" & Server.URLEncode(" .")
  467. elseif issued then
  468. if Auth(6 , "A") then
  469. ' Has the Priviledge to change the Invoice / Reverse Invoice
  470. 'mySQL="SELECT ID FROM ARItems WHERE (Type='"& itemType & "') AND (GL_Update=1) AND (Link='"& InvoiceID & "')"
  471. 'Changed by Kid ! 831124
  472. 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 & "')"
  473. Set RS2 = conn.Execute(mySQL)
  474. if RS2.eof then
  475. Conn.close
  476. response.redirect "AccountReport.asp?act=showInvoice&invoice="& InvoiceID & "&errmsg=" & Server.URLEncode(" !! <br><br> .")
  477. else
  478. if RS2("GL_Update") = False then
  479. tmpGL=RS2("GL")
  480. tmpGLDoc=RS2("GLDocID")
  481. Conn.close
  482. response.redirect "AccountReport.asp?act=showInvoice&invoice="& InvoiceID & "&errmsg=" & Server.URLEncode(" .<br><br> :"& tmpGL & " : "& tmpGLDoc & " .")
  483. else
  484. ARItemID=RS2("ID")
  485. IssuedButEdit=true
  486. end if
  487. end if
  488. RS2.close
  489. else
  490. Conn.close
  491. response.redirect "AccountReport.asp?act=showInvoice&invoice="& InvoiceID & "&errmsg=" & Server.URLEncode(" .")
  492. end if
  493. elseif approved then
  494. call UnApproveInvoice ( InvoiceID , ApprovedBy )
  495. end if
  496. '******************* Editing *******************
  497. ' ****
  498. if IssuedButEdit then
  499. ' Only Updating IssuedDate, Number & no IsA
  500. ' and related Orders
  501. '---- Checking wether issueDate is valid in current open GL
  502. If Not CheckDateFormat(issueDate) Then
  503. Conn.close
  504. response.redirect "AccountReport.asp?act=showInvoice&invoice="& InvoiceID & "&errmsg=" & Server.URLEncode(" .")
  505. end if
  506. if (issueDate < session("OpenGLStartDate")) OR (issueDate > session("OpenGLEndDate")) then
  507. Conn.close
  508. response.redirect "AccountReport.asp?act=showInvoice&invoice="& InvoiceID & "&errmsg=" & Server.URLEncode("!<br> . <br>( )")
  509. end if
  510. '----
  511. '----- Check GL is closed
  512. if (session("IsClosed")="True") then
  513. Conn.close
  514. response.redirect "?errMsg=" & Server.URLEncode("! .")
  515. end if
  516. '----
  517. mySQL="UPDATE Invoices SET IssuedDate=N'" & issueDate & "', Number='"& InvoiceNo & "', IsA='"&IsA&"',issuedDate_en=dbo.udf_date_solarToDate(cast(substring('" & issueDate & "',1,4) as int),cast(substring('" & issueDate & "',6,2) as int),cast(substring('" & issueDate & "',9,2) as int)) WHERE (ID='"& InvoiceID & "')"
  518. 'response.write mySQL
  519. 'response.end
  520. conn.Execute(mySQL)
  521. '---------------------------------------------------------------------------------------------------
  522. for i=1 to request.form("Items").count
  523. if request.form("lineID") <> "" then
  524. 'response.write text2value(request.form("lineID")(i))
  525. theID = clng(text2value(request.form("lineID")(i)))
  526. theItem = clng(text2value(request.form("Items")(i)))
  527. theDescription = left(sqlSafe(request.form("Descriptions")(i)),100)
  528. 'theAppQtty = cdbl(text2value(request.form("AppQttys")(i)))
  529. theLength = text2value(request.form("Lengths")(i))
  530. theWidth = text2value(request.form("Widths")(i))
  531. theQtty = text2value(request.form("Qttys")(i))
  532. theSets = text2value(request.form("Sets")(i))
  533. if theLength <> "" then theLength = cdbl(theLength)
  534. if theWidth <> "" then theWidth = cdbl(theWidth)
  535. if theQtty <> "" then theQtty = clng(theQtty)
  536. if theSets <> "" then theSets = clng(theSets)
  537. mySQL="UPDATE InvoiceLines SET Item='" & theItem & "', Description=N'" & theDescription & "', Length='" & theLength & "', Width='" & theWidth & "', Qtty='" & theQtty & "', Sets='" & theSets & "' WHERE ID = " & theID
  538. conn.Execute(mySQL)
  539. 'response.write "<br>" & mySQL
  540. 'response.end
  541. end if
  542. next
  543. '---------------------------------------------------------------------------------------------------
  544. if IsA then
  545. GLAccount= "91001" 'This must be changed... (Sales A)
  546. else
  547. GLAccount= "91002" 'This must be changed... (Sales B)
  548. end if
  549. ' Changed By Kid 860118 , seasing to use Sales B
  550. 'GLAccount= "91001" 'This must be changed... (Sales A)
  551. conn.Execute("UPDATE ARItems SET GL='"& OpenGL & "', EffectiveDate='" & issueDate & "', GLAccount='"& GLAccount & "' WHERE (ID='" & ARItemID & "')")
  552. '**************** Updating Invoice-Order Relations ****************
  553. 'mySQL="UPDATE Orders SET Closed=0 WHERE ID IN (SELECT [Order] FROM InvoiceOrderRelations WHERE (Invoice= '" & InvoiceID & "'))"
  554. 'Changed By Kid ! 840509
  555. 'set orders which are ONLY related to this invoice, "Open"
  556. 'that means, orders which are related to this invoice and are NOT related to any OTHER issued invoices.
  557. 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 & "'))))"
  558. conn.Execute(mySQL)
  559. ' mySQL ="DELETE FROM InvoiceOrderRelations WHERE (Invoice='" & InvoiceID & "')"
  560. ' '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 & "')))"
  561. ' conn.Execute(mySQL)
  562. '
  563. ' for i=1 to request.form("selectedOrders").count
  564. ' theOrder= clng(request.form("selectedOrders")(i))
  565. ' mySQL="INSERT INTO InvoiceOrderRelations (Invoice,[Order]) VALUES ('" & InvoiceID & "', '" & theOrder & "')"
  566. ' conn.Execute(mySQL)
  567. ' next
  568. conn.Execute("UPDATE Orders SET Closed=1 WHERE ID IN (SELECT [Order] FROM InvoiceOrderRelations WHERE (Invoice='" & InvoiceID & "'))")
  569. '^^^^------------ Updating Invoice-Order Relations ------------^^^^
  570. '**************** Updating Invoice-Quote Relations ****************
  571. 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 & "'))))"
  572. conn.Execute(mySQL)
  573. mySQL ="DELETE FROM InvoiceQuoteRelations WHERE (Invoice='" & InvoiceID & "')"
  574. conn.Execute(mySQL)
  575. for i=1 to request.form("selectedQuotes").count
  576. theQuote= clng(request.form("selectedQuotes")(i))
  577. mySQL="INSERT INTO InvoiceQuoteRelations (Invoice,[Quote]) VALUES ('" & InvoiceID & "', '" & theQuote & "')"
  578. conn.Execute(mySQL)
  579. next
  580. conn.Execute("UPDATE Quotes SET Closed=1 WHERE ID IN (SELECT [Quote] FROM InvoiceQuoteRelations WHERE (Invoice='" & InvoiceID & "'))")
  581. '^^^^------------ Updating Invoice-Quote Relations ------------^^^^
  582. mySQL = "SELECT * FROM ARItems WHERE Type=1 AND Link=" & InvoiceID
  583. set RSSS=conn.Execute(mySQL)
  584. if RSSS.eof or not Auth(6 , "N") then
  585. response.redirect "AccountReport.asp?act=showInvoice&invoice=" & InvoiceID & "&msg=" &Server.URLEncode(" .")
  586. else
  587. if RSSS("GL_Update") then
  588. ' In this secssion we update all issued invoice has not GLs
  589. '---------------------------------------------------------------------------------------------------
  590. '---------------------------------------------------------------------------------------------------
  591. '---------------------------------------------------------------------------------------------------
  592. '---------------------------------------------------------------------------------------------------
  593. '---------------------------------------------------------------------------------------------------
  594. set RSinvoice=conn.Execute("SELECT * FROM Invoices WHERE ID="&InvoiceID)
  595. 'response.write TotalReceivable & "<br>"
  596. 'response.write totalVat & "<br>"
  597. 'response.write TotalPrice & "<br>"
  598. 'response.write TotalDiscount & "<br>"
  599. 'response.end
  600. if (not RSinvoice.eof) and (clng(RSinvoice("TotalReceivable"))<>TotalReceivable or Cdbl(RSinvoice("TotalVat"))<>TotalVat) then
  601. oldTotalReceivable = CLng(RSinvoice("TotalReceivable"))
  602. mySQL="UPDATE Invoices SET Customer='"& CustomerID & "', Number='"& InvoiceNo & "', TotalPrice='"& TotalPrice & "', TotalDiscount='"& TotalDiscount & "', TotalReverse='"& TotalReverse & "', TotalReceivable='"& TotalReceivable & "' , IsA="& IsA & ", TotalVat='" & totalVat & "' WHERE (ID='"& InvoiceID & "')"
  603. conn.Execute(mySQL)
  604. mySQL="DELETE FROM InvoiceLines WHERE (Invoice='"& InvoiceID & "')"
  605. conn.Execute(mySQL)
  606. '**************************** Inserting Invoice Lines ****************
  607. for i=1 to request.form("Items").count
  608. theItem = clng(text2value(request.form("Items")(i)))
  609. theDescription = left(sqlSafe(request.form("Descriptions")(i)),100)
  610. theAppQtty = cdbl(text2value(request.form("AppQttys")(i)))
  611. thePrice = clng(text2value(request.form("Prices")(i)))
  612. theDiscount = text2value(request.form("Discounts")(i))
  613. theReverse = text2value(request.form("Reverses")(i))
  614. theLength = text2value(request.form("Lengths")(i))
  615. theWidth = text2value(request.form("Widths")(i))
  616. theQtty = text2value(request.form("Qttys")(i))
  617. theSets = text2value(request.form("Sets")(i))
  618. theVat = clng(text2value(request.form("Vat")(i)))
  619. theHasVat = text2value(request.form("hasVat")(i))
  620. if theDiscount <>"" then theDiscount= clng(theDiscount)
  621. if theReverse <> "" then theReverse = clng(theReverse)
  622. if theLength <> "" then theLength = cdbl(theLength)
  623. if theWidth <> "" then theWidth = cdbl(theWidth)
  624. if theQtty <> "" then theQtty = clng(theQtty)
  625. if theSets <> "" then theSets = clng(theSets)
  626. 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 &")"
  627. conn.Execute(mySQL)
  628. next
  629. if RFD > 0 then
  630. theItem = 39999
  631. theDescription = " "
  632. theAppQtty = 0
  633. thePrice = 0
  634. theDiscount = RFD
  635. theReverse = 0
  636. theLength = 0
  637. theWidth = 0
  638. theQtty = 0
  639. theSets = 0
  640. theVat = 0
  641. 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 & "')"
  642. conn.Execute(mySQL)
  643. end if
  644. mySQL="UPDATE ARItems SET AmountOriginal='"& TotalReceivable &"', RemainedAmount='"& TotalReceivable &"' ,Vat='"& totalVat &"', FullyApplied = 0 WHERE ID=" & RSSS("ID")
  645. Conn.Execute(mySQL)
  646. Conn.Execute("Delete from ARItemsRelations where DebitARItem = " & RSSS("ID"))
  647. Conn.Execute(mySQL)
  648. mySQL="UPDATE Accounts SET ARBalance=ARBalance - "&TotalReceivable - oldTotalReceivable&" WHERE id=" & CustomerID
  649. conn.Execute(mySQL)
  650. end if
  651. 'end if
  652. '****
  653. '^^^^--------------- Editing ---------------^^^^
  654. '--------------------------------------------------------------------------------------------------
  655. '---------------------------------------------------------------------------------------------------
  656. '---------------------------------------------------------------------------------------------------
  657. response.redirect "AccountReport.asp?act=showInvoice&invoice=" & InvoiceID & "&msg=" &Server.URLEncode(" ύ ")
  658. '---------------------------------------------------------------------------------------------------
  659. '---------------------------------------------------------------------------------------------------
  660. '---------------------------------------------------------------------------------------------------
  661. '---------------------------------------------------------------------------------------------------
  662. else
  663. response.redirect "AccountReport.asp?act=showInvoice&invoice=" & InvoiceID & "&msg=" &Server.URLEncode(" .")
  664. end if
  665. end if
  666. conn.close
  667. response.redirect "AccountReport.asp?act=showInvoice&invoice=" & InvoiceID & "&msg=" &Server.URLEncode(" .<br>э <br> .")
  668. else
  669. ' S A M
  670. 'response.write(totalDiscount)
  671. 'response.end
  672. mySQL="UPDATE Invoices SET Customer='"& CustomerID & "', Number='"& InvoiceNo & "', TotalPrice='"& TotalPrice & "', TotalDiscount='"& TotalDiscount & "', TotalReverse='"& TotalReverse & "', TotalReceivable='"& TotalReceivable & "' , IsA='"& IsA & "', TotalVat='" & totalVat & "' WHERE (ID='"& InvoiceID & "')"
  673. conn.Execute(mySQL)
  674. mySQL="DELETE FROM InvoiceLines WHERE (Invoice='"& InvoiceID & "')"
  675. conn.Execute(mySQL)
  676. '**************************** Inserting Invoice Lines ****************
  677. for i=1 to request.form("Items").count
  678. theItem = clng(text2value(request.form("Items")(i)))
  679. theDescription = left(sqlSafe(request.form("Descriptions")(i)),100)
  680. theAppQtty = cdbl(text2value(request.form("AppQttys")(i)))
  681. thePrice = clng(text2value(request.form("Prices")(i)))
  682. theDiscount = text2value(request.form("Discounts")(i))
  683. theReverse = text2value(request.form("Reverses")(i))
  684. theLength = text2value(request.form("Lengths")(i))
  685. theWidth = text2value(request.form("Widths")(i))
  686. theQtty = text2value(request.form("Qttys")(i))
  687. theSets = text2value(request.form("Sets")(i))
  688. theVat = clng(text2value(request.form("Vat")(i)))
  689. theHasVat = text2value(request.form("hasVat")(i))
  690. if theDiscount <>"" then theDiscount= clng(theDiscount)
  691. if theReverse <> "" then theReverse = clng(theReverse)
  692. if theLength <> "" then theLength = cdbl(theLength)
  693. if theWidth <> "" then theWidth = cdbl(theWidth)
  694. if theQtty <> "" then theQtty = clng(theQtty)
  695. if theSets <> "" then theSets = clng(theSets)
  696. 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 &")"
  697. conn.Execute(mySQL)
  698. next
  699. if RFD > 0 then
  700. theItem = 39999
  701. theDescription = " "
  702. theAppQtty = 0
  703. thePrice = 0
  704. theDiscount = RFD
  705. theReverse = 0
  706. theLength = 0
  707. theWidth = 0
  708. theQtty = 0
  709. theSets = 0
  710. theVat = 0
  711. 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 & "')"
  712. conn.Execute(mySQL)
  713. end if
  714. '**************** Updating Invoice-Order Relations ****************
  715. ' mySQL="DELETE FROM InvoiceOrderRelations WHERE (Invoice='" & InvoiceID & "')"
  716. ' conn.Execute(mySQL)
  717. ' response.write "aaaa:"
  718. ' response.write request.form("selectedOrders").count
  719. ' for i=1 to request.form("selectedOrders").count
  720. ' theOrder= clng(request.form("selectedOrders")(i))
  721. ' mySQL="INSERT INTO InvoiceOrderRelations (Invoice,[Order]) VALUES ('" & InvoiceID & "', '" & theOrder & "')"
  722. ' '--------------------------SAM------------------------------
  723. ' ' response.write mySQL
  724. ' '-----------------------------------------------------------
  725. ' conn.Execute(mySQL)
  726. ' next
  727. '^^^^------------ Updating Invoice-Order Relations ------------^^^^
  728. ' '**************** Updating Invoice-Quote Relations ****************
  729. ' mySQL="DELETE FROM InvoiceQuoteRelations WHERE (Invoice='" & InvoiceID & "')"
  730. ' conn.Execute(mySQL)
  731. ' for i=1 to request.form("selectedQuotes").count
  732. ' theQuote= clng(request.form("selectedQuotes")(i))
  733. ' mySQL="INSERT INTO InvoiceQuoteRelations (Invoice,[Quote]) VALUES ('" & InvoiceID & "', '" & theQuote & "')"
  734. ' conn.Execute(mySQL)
  735. ' next
  736. '^^^^------------ Updating Invoice-Quote Relations ------------^^^^
  737. end if
  738. '****
  739. '^^^^--------------- Editing ---------------^^^^
  740. response.redirect "AccountReport.asp?act=showInvoice&invoice=" & InvoiceID
  741. '--------------------------------------------------------------------------------------------------------------------
  742. elseif request("act")="approveInvoice" then
  743. if not Auth(6 , "C") then
  744. 'Doesn't have the Priviledge to APPROVE the Invoice
  745. response.write "<br>"
  746. call showAlert (" ",CONST_MSG_ERROR)
  747. response.end
  748. end if
  749. if request("invoice")<>"" then
  750. InvoiceID=request("invoice")
  751. if not(isnumeric(request("invoice"))) then
  752. ShowErrorMessage("")
  753. response.end
  754. end if
  755. mySQL="SELECT * FROM Invoices WHERE (ID='"& InvoiceID & "')"
  756. Set RS1 = conn.Execute(mySQL)
  757. if RS1.eof then
  758. ShowErrorMessage(" ")
  759. response.end
  760. else
  761. '-------------------------------------------------------------------------
  762. '---- CHECK pickup list
  763. '-------------------------------------------------------------------------
  764. mySQL="select distinct sales.item, sales.description, sales.appQtty,pik.itemID,pik.itemName,pik.qtty from (select invoiceLines.item,max(invoiceLines.description) as description,sum(invoiceLines.appQtty) as appQtty, InventoryInvoiceRelations.inventoryItem from InvoiceLines inner join Invoices on invoices.ID=invoiceLines.Invoice inner join InventoryInvoiceRelations on InventoryInvoiceRelations.invoiceItem=invoiceLines.Item WHERE Invoices.id=" & InvoiceID & " group by invoiceLines.item, InventoryInvoiceRelations.inventoryItem) as sales full outer join (SELECT InventoryPickuplistItems.itemID, max(InventoryPickuplistItems.ItemName) AS ItemName, sum(InventoryPickuplistItems.Qtty) AS Qtty, InventoryInvoiceRelations.invoiceItem FROM InventoryPickuplistItems INNER JOIN InventoryPickuplists ON InventoryPickuplistItems.pickupListID = InventoryPickuplists.id INNER JOIN InvoiceOrderRelations ON InventoryPickuplistItems.Order_ID = InvoiceOrderRelations.[Order] inner join invoices on InvoiceOrderRelations.invoice=invoices.id inner join InventoryInvoiceRelations on InventoryInvoiceRelations.inventoryItem=InventoryPickuplistItems.itemID WHERE NOT InventoryPickuplists.Status = N'del' and InventoryPickuplistItems.CustomerHaveInvItem=0 and Invoices.id=" & InvoiceID & " group by InventoryPickuplistItems.itemID, InventoryInvoiceRelations.invoiceItem ) as pik on pik.itemID=sales.inventoryItem or pik.invoiceItem=sales.item"
  765. set rs=Conn.Execute (mySQL)
  766. errmsg=""
  767. msg=""
  768. while not rs.eof
  769. skeepNext=0
  770. if IsNull(rs("appQtty")) then
  771. errmsg = errmsg & " " & rs("itemName") & " <br>"
  772. else
  773. if IsNull(rs("qtty")) then
  774. errmsg = errmsg & " " & rs("description") & " <br>"
  775. else
  776. if CDbl(rs("qtty")) <> CDbl(rs("appQtty")) then
  777. item=rs("item")
  778. appQtty=CDbl(rs("appQtty"))
  779. desc=rs("description")
  780. itemName=""
  781. sumQtty=0
  782. do
  783. skeepNext=0
  784. if item<>rs("item") then exit do
  785. sumQtty=sumQtty+cdbl(rs("qtty"))
  786. if itemName="" then
  787. itemName = rs("itemName")
  788. else
  789. itemName=itemName & ", " & rs("itemName")
  790. end if
  791. rs.moveNext
  792. skeepNext=1
  793. if rs.eof then exit do
  794. loop while item=rs("item")
  795. 'rs.MovePrevious
  796. if appQtty<>sumQtty then errmsg = errmsg & " <b>" & itemName & "</b> <b>" & desc & "</b> .<br>"
  797. end if
  798. end if
  799. end if
  800. if skeepNext=0 then rs.moveNext
  801. wend
  802. set rs=nothing
  803. '-------------------------------------------------------------------------
  804. '---- CHECK out Service
  805. '-------------------------------------------------------------------------
  806. mySQL="select * from (SELECT PurchaseOrders.TypeID,max(PurchaseRequests.TypeName) as TypeName, sum(PurchaseOrders.Qtty) as Qtty FROM PurchaseOrders FULL OUTER JOIN PurchaseRequestOrderRelations RIGHT OUTER JOIN PurchaseRequests INNER JOIN InvoiceOrderRelations ON PurchaseRequests.Order_ID = InvoiceOrderRelations.[Order] ON PurchaseRequestOrderRelations.Req_ID = PurchaseRequests.ID ON PurchaseOrders.ID = PurchaseRequestOrderRelations.Ord_ID WHERE (InvoiceOrderRelations.Invoice =" & InvoiceID & ") and PurchaseRequests.Status<> 'del' and PurchaseOrders.Status<>'CANCEL' and PurchaseOrders.IsService=1 group by PurchaseOrders.TypeID) as outService full outer join (select InvoiceItems.RelatedInventoryItemID,max(description) as description,sum(appQtty) as appQtty from InvoiceLines inner join InvoiceItems on InvoiceItems.ID=invoiceLines.Item and InvoiceItems.Type=5 where Invoice=" & InvoiceID & " group by InvoiceItems.RelatedInventoryItemID) as sales on sales.RelatedInventoryItemID=outService.TypeID"
  807. set rs=Conn.Execute (mySQL)
  808. while not rs.eof
  809. if IsNull(rs("appQtty")) then
  810. errmsg = errmsg & " " & rs("typeName") & " <br>"
  811. else
  812. if IsNull(rs("qtty")) then
  813. errmsg = errmsg & " " & rs("description") & " <br>"
  814. else
  815. if CDbl(rs("qtty")) <> CDbl(rs("appQtty")) then msg = msg & " <b>" & rs("typeName") & "</b> <b>" & rs("description") & "</b> .<br>"
  816. end if
  817. end if
  818. rs.moveNext
  819. wend
  820. set rs=nothing
  821. if (errmsg<>"") then
  822. Conn.close
  823. response.redirect "?errMsg=" & Server.URLEncode(errmsg)
  824. end if
  825. '-------------------------------------------------------------------------
  826. '---------------------------------------------
  827. '-------------------------------------------------------------------------
  828. if RS1("Voided") = True then
  829. Conn.close
  830. response.redirect "AccountReport.asp?act=showInvoice&invoice="& InvoiceID & "&errmsg=" & Server.URLEncode(" .")
  831. elseif RS1("Issued") = True then
  832. Conn.close
  833. response.redirect "AccountReport.asp?act=showInvoice&invoice="& InvoiceID & "&errmsg=" & Server.URLEncode(" .")
  834. elseif RS1("Approved") = True then
  835. Conn.close
  836. response.redirect "AccountReport.asp?act=showInvoice&invoice="& InvoiceID & "&errmsg=" & Server.URLEncode(" .")
  837. end if
  838. end if
  839. else
  840. ShowErrorMessage("")
  841. response.end
  842. end if
  843. '--------------------SAM, Iqnore multi invoice in one order
  844. 'mySQL="SELECT COUNT(*) AS OrderCount FROM InvoiceOrderRelations WHERE [Order] IN (SELECT [Order] FROM InvoiceOrderRelations WHERE Invoice=" & InvoiceID &")"-----------SAM coorect this on 9 mar 2011
  845. 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"
  846. set RS1= conn.Execute(mySQL)
  847. ' response.write rs1("OrderCount")
  848. ' response.end
  849. if RS1("OrderCount")>1 then
  850. conn.close
  851. response.redirect "AccountReport.asp?act=showInvoice&invoice="& InvoiceID & "&errmsg=" & Server.URLEncode(" ! .")
  852. end if
  853. '------------------------------------------------
  854. mySQL="UPDATE Invoices SET Approved=1, ApprovedDate=N'"& shamsiToday() & "', ApprovedBy='"& session("ID") & "' WHERE (ID='"& InvoiceID & "')"
  855. conn.Execute(mySQL)
  856. response.redirect "AccountReport.asp?act=showInvoice&invoice="& InvoiceID & "&msg=" & Server.URLEncode(msg)
  857. '-------------------------------------------------------------------------------------------------------
  858. elseif request("act")="IssueInvoice" then
  859. if not Auth(6 , "D") then
  860. 'Doesn't have the Priviledge to ISSUE the Invoice
  861. response.write "<br>"
  862. call showAlert (" ",CONST_MSG_ERROR)
  863. response.end
  864. end if
  865. ON ERROR RESUME NEXT
  866. InvoiceID= clng(request("Invoice"))
  867. if Err.Number<>0 then
  868. Err.clear
  869. conn.close
  870. response.redirect "top.asp?errMsg=" & Server.URLEncode("!")
  871. end if
  872. ON ERROR GOTO 0
  873. creationDate= shamsiToday()
  874. issueDate= SqlSafe(request("issueDate"))
  875. if issueDate="" then issueDate=creationDate
  876. if issueDate<>creationDate then
  877. if Auth(6 , "I") then
  878. ' can ISSUE the Invoice / Rev. Invoice on another Date
  879. '---- Checking wether issueDate is valid in current open GL
  880. If Not CheckDateFormat(issueDate) Then
  881. Conn.close
  882. response.redirect "AccountReport.asp?act=showInvoice&invoice="& InvoiceID & "&errmsg=" & Server.URLEncode(" .")
  883. end if
  884. if (issueDate < session("OpenGLStartDate")) OR (issueDate > session("OpenGLEndDate")) then
  885. Conn.close
  886. response.redirect "AccountReport.asp?act=showInvoice&invoice="& InvoiceID & "&errmsg=" & Server.URLEncode("!<br> . <br>( )")
  887. end if
  888. '----
  889. else
  890. 'Doesn't have the Priviledge to ISSUE the Invoice on another Date
  891. response.write "<br>"
  892. call showAlert (" ",CONST_MSG_ERROR)
  893. response.end
  894. end if
  895. end if
  896. '----- Check GL is closed
  897. if (session("IsClosed")="True") then
  898. Conn.close
  899. response.redirect "?errMsg=" & Server.URLEncode("! .")
  900. end if
  901. '----
  902. '---- Checking wether issueDate is valid in current open GL
  903. If Not CheckDateFormat(issueDate) Then
  904. Conn.close
  905. response.redirect "AccountReport.asp?act=showInvoice&invoice="& InvoiceID & "&errmsg=" & Server.URLEncode("!<br> .")
  906. end if
  907. if (issueDate < session("OpenGLStartDate")) OR (issueDate > session("OpenGLEndDate")) then
  908. Conn.close
  909. response.redirect "AccountReport.asp?act=showInvoice&invoice=" & InvoiceID & "&errmsg=" & Server.URLEncode("!<br> . <br>( )")
  910. end if
  911. '----
  912. '---- CHECK pickup list
  913. mySQL="select distinct sales.item, sales.description, sales.appQtty,pik.itemID,pik.itemName,pik.qtty from (select invoiceLines.item,max(invoiceLines.description) as description,sum(invoiceLines.appQtty) as appQtty, InventoryInvoiceRelations.inventoryItem from InvoiceLines inner join Invoices on invoices.ID=invoiceLines.Invoice inner join InventoryInvoiceRelations on InventoryInvoiceRelations.invoiceItem=invoiceLines.Item WHERE Invoices.id=" & InvoiceID & " group by invoiceLines.item, InventoryInvoiceRelations.inventoryItem) as sales full outer join (SELECT InventoryPickuplistItems.itemID, max(InventoryPickuplistItems.ItemName) AS ItemName, sum(InventoryPickuplistItems.Qtty) AS Qtty, InventoryInvoiceRelations.invoiceItem FROM InventoryPickuplistItems INNER JOIN InventoryPickuplists ON InventoryPickuplistItems.pickupListID = InventoryPickuplists.id INNER JOIN InvoiceOrderRelations ON InventoryPickuplistItems.Order_ID = InvoiceOrderRelations.[Order] inner join invoices on InvoiceOrderRelations.invoice=invoices.id inner join InventoryInvoiceRelations on InventoryInvoiceRelations.inventoryItem=InventoryPickuplistItems.itemID WHERE NOT InventoryPickuplists.Status = N'del' and InventoryPickuplistItems.CustomerHaveInvItem=0 and Invoices.id=" & InvoiceID & " group by InventoryPickuplistItems.itemID, InventoryInvoiceRelations.invoiceItem ) as pik on pik.itemID=sales.inventoryItem or pik.invoiceItem=sales.item"
  914. set rs=Conn.Execute (mySQL)
  915. errMsg=""
  916. while not rs.eof
  917. if IsNull(rs("appQtty")) then
  918. errMsg = errMsg & " " & rs("itemName") & " <br>"
  919. else
  920. if IsNull(rs("qtty")) then
  921. errMsg = errMsg & " " & rs("description") & " <br>"
  922. else
  923. if CDbl(rs("qtty")) <> CDbl(rs("appQtty")) then
  924. 'errMsg = errMsg & " <b>" & rs("itemName") & "</b> <b>" & rs("description") & "</b> .<br>"
  925. item=rs("item")
  926. appQtty=CDbl(rs("appQtty"))
  927. desc=rs("description")
  928. itemName=""
  929. sumQtty=0
  930. do
  931. skeepNext=0
  932. if item<>rs("item") then exit do
  933. sumQtty=sumQtty+cdbl(rs("qtty"))
  934. if itemName="" then
  935. itemName = rs("itemName")
  936. else
  937. itemName=itemName & ", " & rs("itemName")
  938. end if
  939. rs.moveNext
  940. skeepNext=1
  941. if rs.eof then exit do
  942. loop while item=rs("item")
  943. 'rs.MovePrevious
  944. if appQtty<>sumQtty then errmsg = errmsg & " <b>" & itemName & "</b> <b>" & desc & "</b> .<br>"
  945. end if
  946. end if
  947. end if
  948. rs.moveNext
  949. wend
  950. set rs=nothing
  951. '----
  952. '---- CHECK out Service
  953. mySQL="select * from (SELECT PurchaseOrders.TypeID,max(PurchaseRequests.TypeName) as TypeName, sum(PurchaseOrders.Qtty) as Qtty FROM PurchaseOrders FULL OUTER JOIN PurchaseRequestOrderRelations RIGHT OUTER JOIN PurchaseRequests INNER JOIN InvoiceOrderRelations ON PurchaseRequests.Order_ID = InvoiceOrderRelations.[Order] ON PurchaseRequestOrderRelations.Req_ID…