/beta/AR/InvoiceInput.asp

http://github.com/khaneh/Orders · ASP · 609 lines · 517 code · 64 blank · 28 comment · 49 complexity · a96c78c175ef7bb0df35c5ac70e8e3fc MD5 · raw file

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