/beta/cashReg/CashPaymentInput.asp

http://github.com/khaneh/Orders · ASP · 371 lines · 316 code · 28 blank · 27 comment · 28 complexity · f8b7df3e6e69ba3213d4d3e21252d8a3 MD5 · raw file

  1. <%@LANGUAGE="VBSCRIPT" CODEPAGE="1256"%><%
  2. 'CashRegister (9)
  3. PageTitle=" "
  4. SubmenuItem=2
  5. if not Auth(9 , 2) then NotAllowdToViewThisPage()
  6. %>
  7. <!--#include file="top.asp" -->
  8. <!--#include File="../include_farsiDateHandling.asp"-->
  9. <!--#include File="../include_JS_InputMasks.asp"-->
  10. <%
  11. function Link2Trace(OrderNo)
  12. Link2Trace="<A HREF='../order/orderEdit.asp?e=n&radif="& OrderNo & "' target='_balnk'>"& OrderNo & "</A>"
  13. end function
  14. %>
  15. <style>
  16. .CPayTable { font-family:tahoma; font-size: 9pt; border:0; padding:0; }
  17. .CPayMainTable { font-family:tahoma; font-size: 9pt; border:0; padding:0; background-color: #558855; text-align:right; direction: RTL;}
  18. .CPayMainTable TH { background-color: #C3C300; font-size: 9pt; font-weight:normal;}
  19. .CPayMainTableTR { background-color: #CCCC88; border: 0; }
  20. .CPayInput1 { font-family:tahoma; font-size: 9pt; border: 1px solid black; background-color: #F0F0F0; direction:RTL;}
  21. .CPayInput2 { font-family:tahoma; font-size: 9pt; border: none; text-align:right; direction:LTR;}
  22. .GenButton { font-family:tahoma; font-size: 9pt; border: 1px solid black; }
  23. </style>
  24. <SCRIPT LANGUAGE="JavaScript">
  25. <!--
  26. var okToProceed=false;
  27. var currentRow=null;
  28. //-->
  29. </SCRIPT>
  30. <font face="tahoma">
  31. <%
  32. mySQL="SELECT * FROM CashRegisters WHERE (IsOpen=1) AND (Cashier='"& session("ID") & "')"
  33. Set RS1= conn.Execute(mySQL)
  34. if RS1.eof then
  35. %><br><br>
  36. <TABLE width='70%' align='center'>
  37. <TR>
  38. <TD align=center bgcolor=#FFBBBB style='border: solid 1pt black'><BR><b> <%=CSRName%> ... <br><br> <br>."</b><BR><BR></TD>
  39. </TR>
  40. </TABLE>
  41. <% conn.close
  42. response.end
  43. else
  44. CashRegID=RS1("ID")
  45. theBanker=RS1("Banker")
  46. CashRegName=RS1("NameDate")
  47. cashAmountA=cdbl(RS1("cashAmountA"))
  48. cashAmountB=cdbl(RS1("cashAmountB"))
  49. if cashAmountA=0 and cashAmountB=0 then
  50. %><br><br>
  51. <TABLE width='70%' align='center'>
  52. <TR>
  53. <TD align=center bgcolor=#FFBBBB style='border: solid 1pt black'><BR><b> !</b><BR><BR></TD>
  54. </TR>
  55. </TABLE>
  56. <%
  57. conn.close
  58. response.end
  59. end if
  60. Set RS1=nothing
  61. end if
  62. if request("act")="submitsearch" then
  63. if request("CustomerNameSearchBox") <> "" then
  64. SA_TitleOrName=request("CustomerNameSearchBox")
  65. SA_Action="return true;"
  66. SA_SearchAgainURL=""
  67. SA_StepText=" : "
  68. %>
  69. <FORM METHOD=POST ACTION="?act=getPayment">
  70. <!--#include File="../AR/include_SelectAccount.asp"-->
  71. </FORM>
  72. <%
  73. end if
  74. elseif request("act")="selectOrder" then
  75. if request("selectedCustomer") <> "" then
  76. SO_Customer=request("selectedCustomer")
  77. SO_Action="return true;"
  78. SO_StepText=" :"
  79. %>
  80. <FORM METHOD=POST ACTION="?act=getPayment">
  81. <!--#include File="../AR/include_SelectOrder.asp"-->
  82. </FORM>
  83. <%
  84. end if
  85. elseif request("act")="getPayment" then
  86. if not isnumeric(request("selectedCustomer")) then
  87. response.write "EORROR"
  88. response.end
  89. end if
  90. if request("Reason")="" then
  91. Reason=1
  92. else
  93. Reason=cint(request("Reason"))
  94. end if
  95. if Reason=1 then
  96. sys="AR"
  97. elseif Reason=2 then
  98. sys="AP"
  99. else
  100. sys="AO"
  101. end if
  102. AccountID=clng(request("selectedCustomer"))
  103. mySQL="SELECT * FROM Accounts WHERE (ID='"& AccountID & "')"
  104. Set RS1 = conn.Execute(mySQL)
  105. AccountNo=RS1("ID")
  106. customerName=RS1("AccountTitle")
  107. %>
  108. <br><div dir='rtl'><B> : </B>
  109. </div>
  110. <!-- -->
  111. <hr>
  112. <input type="hidden" Name='tmpDlgArg' value=''>
  113. <input type="hidden" Name='tmpDlgTxt' value=''>
  114. <table class="CPayMainTable" Cellspacing="1" Cellpadding="0" Width="500" align="center">
  115. <FORM METHOD=POST ACTION="?act=submitCashPayment" onsubmit="if (document.all.AccountTitle.value=='') return false;">
  116. <tr>
  117. <th colspan="10" align='center' height='25px'> <span dir='LTR'><%=CashRegName%></span> - <%=CSRName%> <INPUT TYPE="hidden" Name="CashRegID" Value="<%=CashRegID%>">
  118. </th>
  119. </tr>
  120. <tr>
  121. <th colspan="10"><TABLE Border="0" Width="100%" Cellspacing="1" Cellpadding="0" Dir="RTL"><TR>
  122. <TD><table>
  123. <tr>
  124. <td align="left">:</td>
  125. <td align="right">
  126. <span id="customer">
  127. <INPUT TYPE="hidden" NAME="AccountID" value="<%=AccountID%>"><span><%=CustomerName%></span>.
  128. </span></td>
  129. </tr>
  130. </table></TD>
  131. <TD><table>
  132. <tr>
  133. <td align="left"> :</td>
  134. <td align="right">
  135. <SELECT NAME="Reason" style='font-family:Tahoma;font-size:8pt;height:25px;width:100px;' onchange="changeSystem();">
  136. <% mySQL="SELECT * FROM AXItemReasons WHERE Display=1 ORDER BY ID"
  137. Set RS1=Conn.Execute(mySQL)
  138. Do while not RS1.eof
  139. if Reason = RS1("ID") then
  140. ifSelected="selected"
  141. else
  142. ifSelected=""
  143. end if
  144. response.write "<OPTION value='"& RS1("ID") & "' "& ifSelected & ">"& RS1("Name") & "</option>"
  145. RS1.MoveNext
  146. Loop
  147. %> </SELECT>
  148. </td>
  149. </tr>
  150. </table></TD>
  151. <td>
  152. <input name="isA" type="checkbox"
  153. <%
  154. if cashAmountA=0 or cashAmountB=0 then
  155. if cashAmountB=0 then
  156. response.write " checked='checked' "
  157. response.write " onclick='this.checked=true;' "
  158. response.write " title=' ' "
  159. else
  160. response.write " onclick='this.checked=false;' "
  161. response.write " title=' ' "
  162. end if
  163. else
  164. response.write " checked='checked' "
  165. end if
  166. %>
  167. >
  168. </td>
  169. <TD align="left"><table>
  170. <tr>
  171. <td align="left">:</td>
  172. <td dir="LTR">
  173. <INPUT class="CPayInput2" style="text-align:left;direction:LTR;" NAME="PaymentDate" TYPE="text" maxlength="10" size="10" value="<%=shamsiToday()%>" onblur="acceptDate(this)"></td>
  174. <td dir="RTL"><%=weekdayname(weekday(date))%></td>
  175. </tr>
  176. </table></TD>
  177. </TR></TABLE>
  178. <input type="hidden" Name='InvoiceID' value='<%=InvoiceID%>'>
  179. </th>
  180. </tr>
  181. <tr class="CPayMainTableTR">
  182. <TD colspan="10" ><div>
  183. <TABLE class="CPayTable" Cellspacing="1" Cellpadding="0" Dir="RTL">
  184. <tr height="40">
  185. <td colspan="1" align="left"> : </td>
  186. <td colspan="1"><INPUT dir="LTR" class="CPayInput1" TYPE="text" Name="CashAmount" size="15" onKeyPress="return maskNumber(this);" onBlur="setPrice(this)"></td>
  187. </tr>
  188. <tr height="40">
  189. <td colspan="1" align="left"> : </td>
  190. <td colspan="1"><INPUT dir="LTR" class="CPayInput1" TYPE="text" Name="Description" size="60"></td>
  191. </tr>
  192. </TABLE></div></TD>
  193. </tr>
  194. <tr>
  195. <th colspan="10" align='center' height='25px'>
  196. <INPUT class="GenButton" style="text-align:center" TYPE="button" value="" onclick="if (document.getElementsByName('CashAmount')[0].value!='0') submit();">
  197. <INPUT class="GenButton" style="text-align:center" TYPE="button" value="" onclick="window.location='';">
  198. </th>
  199. </table>
  200. </FORM>
  201. <SCRIPT LANGUAGE="JavaScript">
  202. <!--
  203. document.all.CashAmount.focus();
  204. function changeSystem(){
  205. window.location='?act=getPayment&selectedCustomer=<%=AccountID%>&Reason='+document.all.Reason.value;
  206. }
  207. //-->
  208. </SCRIPT>
  209. <%elseif request("act")="submitCashPayment" then
  210. ON ERROR RESUME NEXT
  211. Reason= cint(request.form("Reason"))
  212. AccountID= clng(request.form("AccountID"))
  213. CashAmount= cdbl(text2value(request.form("CashAmount")))
  214. if Err.Number<>0 then
  215. Err.clear
  216. conn.close
  217. response.redirect "top.asp?errMsg=" & Server.URLEncode("!")
  218. end if
  219. ON ERROR GOTO 0
  220. if request("isA")="on" then
  221. isA=1
  222. else
  223. isA=0
  224. end if
  225. mySQL="SELECT * FROM AXItemReasons WHERE (ID="& Reason & ")"
  226. Set RS1=Conn.execute(mySQL)
  227. if RS1.eof then
  228. conn.close
  229. response.redirect "top.asp?errMsg=" & Server.URLEncode("!")
  230. else
  231. Sys= RS1("Acron")
  232. firstGLAccount= RS1("GLAccount")
  233. end if
  234. RS1.close
  235. Description=sqlSafe(request.form("Description"))
  236. creationDate= shamsiToday()
  237. creationTime= CurrentTime10()
  238. if isA=0 then
  239. GLAccount= "11005" 'This must be changed... (Cashier B)
  240. else
  241. GLAccount= "11007" 'This must be changed... (Cashier A)
  242. end if
  243. effectiveDate= sqlSafe(request.form("PaymentDate"))
  244. '---- Checking wether EffectiveDate is valid in current open GL
  245. if (effectiveDate < session("OpenGLStartDate")) OR (effectiveDate > session("OpenGLEndDate")) then
  246. Conn.close
  247. response.redirect "?act=getPayment&selectedCustomer="& AccountID & "&Reason="& Reason & "&errMsg=" & Server.URLEncode("!<br> .")
  248. end if
  249. '----
  250. '----- Check GL is closed
  251. if (session("IsClosed")="True") then
  252. Conn.close
  253. response.redirect "?errMsg=" & Server.URLEncode("! .")
  254. end if
  255. '------- Check total cash A or B amount larger than this payment :)
  256. if isA=1 then
  257. if cashAmountA < CashAmount then
  258. Conn.close
  259. response.redirect "?errMsg=" & Server.URLEncode("! ")
  260. end if
  261. else
  262. if cashAmountB < CashAmount then
  263. Conn.close
  264. response.redirect "?errMsg=" & Server.URLEncode("! ")
  265. end if
  266. end if
  267. '----
  268. ' #########################################################
  269. ' INSERTING PAYMENT ...
  270. ' #########################################################
  271. ' NUMBER must be Payment Number
  272. NUMBER =0
  273. mySQL="INSERT INTO Payments (SYS, Account, CashAmount, ChequeAmount, CreatedBy, CreationDate, CreationTime, EffectiveDate) VALUES ('"& Sys & "', '" &_
  274. AccountID & "', '"& CashAmount & "', 0, '"& session("ID") & "', N'"& creationDate & "', N'"& creationTime & "', N'"& effectiveDate & "');SELECT @@Identity AS NewPayment"
  275. set RS1 = Conn.execute(mySQL).NextRecordSet
  276. paymentID = RS1 ("NewPayment")
  277. RS1.close
  278. ' #########################################################
  279. ' INSERTING CASH ...
  280. ' #########################################################
  281. mySQL="INSERT INTO PaidCash (Payment, Description, Amount, Banker) VALUES ('"&_
  282. PaymentID & "', N'" & Description & "', '" & CashAmount & "', '" & theBanker & "')"
  283. conn.Execute(mySQL)
  284. ' #########################################################
  285. ' INSERTING PAYMENT INTO CASH REGISTER LINES ...
  286. ' Note: Inserted CashRegisterLineType is '2'
  287. ' That means "Payment"
  288. ' #########################################################
  289. mySQL="INSERT INTO CashRegisterLines (CashReg, [Date], [Time], Type, Link,isA) VALUES ('"& CashRegID & "', N'"& creationDate & "', N'"& creationTime & "', '2', '"& PaymentID & "',"& isA &")"
  290. conn.Execute(mySQL)
  291. ' #########################################################
  292. ' UPDATING CASH REGISTERS ...
  293. ' #########################################################
  294. if isA then
  295. mySQL="UPDATE CashRegisters SET CashAmountA=CashAmountA-'"& CashAmount & "' WHERE ID='"& CashRegID & "'"
  296. else
  297. mySQL="UPDATE CashRegisters SET CashAmountB=CashAmountB-'"& CashAmount & "' WHERE ID='"& CashRegID & "'"
  298. end if
  299. conn.Execute(mySQL)
  300. '**************************** Creating AN Item for Payment ****************
  301. '*** Type = 5 means Item is a Payment
  302. mySQL="INSERT INTO "& Sys & "Items (GLAccount, GL, FirstGLAccount, Account, EffectiveDate, Reason, IsCredit, Type, Link, AmountOriginal, CreatedDate, CreatedBy, RemainedAmount) VALUES ('" &_
  303. GLAccount & "', '"& OpenGL & "', '"& firstGLAccount & "', '"& AccountID & "', '"& effectiveDate & "', '"& Reason & "', 0, 5, '"& PaymentID & "', '"& CashAmount & "', N'"& creationDate & "', '"& session("ID") & "', '"& CashAmount & "')"
  304. conn.Execute(mySQL)
  305. '***-------------------End of Creating Item for Payment ----------------
  306. ' #########################################################
  307. ' UPDATING Account Balance ...
  308. ' #########################################################
  309. mySQL="UPDATE Accounts SET "& Sys & "Balance = "& Sys & "Balance - '"& CashAmount & "' WHERE (ID='"& AccountID & "')"
  310. conn.Execute(mySQL)
  311. Conn.close
  312. response.redirect "../"& Sys & "/AccountReport.asp?Sys="& Sys & "&act=showPayment&payment="& PaymentID & "&msg=" & Server.URLEncode(" .")
  313. else%>
  314. <!-- --><BR><BR>
  315. <FORM METHOD=POST ACTION="?act=submitsearch" onsubmit="if (document.all.CustomerNameSearchBox.value=='') return false;">
  316. <div dir='rtl'>&nbsp;<B> : </B>
  317. <INPUT TYPE="text" NAME="CustomerNameSearchBox">&nbsp;
  318. <INPUT class="GenButton" TYPE="submit" value=""><br>
  319. </div>
  320. </FORM>
  321. <SCRIPT LANGUAGE="JavaScript">
  322. <!--
  323. document.all.CustomerNameSearchBox.focus();
  324. //-->
  325. </SCRIPT>
  326. <%
  327. end if
  328. conn.Close
  329. %>
  330. </font>
  331. </BODY>
  332. </HTML>
  333. <% if request("act")="getPayment" then %>
  334. <script language="JavaScript">
  335. <!--
  336. function setPrice(src){
  337. /* src.value=val2txt(txt2val(src.value)); */
  338. $(src).val(echoNum(getNum($(src).val())));
  339. }
  340. //-->
  341. </script>
  342. <%end if%>
  343. <!--#include file="tah.asp" -->