/beta/cashReg/ReceiptInput.asp

http://github.com/khaneh/Orders · ASP · 847 lines · 736 code · 57 blank · 54 comment · 83 complexity · f44a3437a8e1c27a619bfe89e1dc2930 MD5 · raw file

  1. <%@LANGUAGE="VBSCRIPT" CODEPAGE="1256"%><%
  2. 'CashRegister (9)
  3. PageTitle=""
  4. SubmenuItem=1
  5. if not Auth(9 , 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 Link2Trace(OrderNo)
  12. Link2Trace="<A HREF='../order/orderEdit.asp?e=n&radif="& OrderNo & "' target='_balnk'>"& OrderNo & "</A>"
  13. end function
  14. %>
  15. <style>
  16. .RcpTable { font-family:tahoma; font-size: 9pt; border:0; padding:0; }
  17. .RcpMainTable { font-family:tahoma; font-size: 9pt; border:0; padding:0; background-color: #558855; text-align:right; direction: RTL;}
  18. .RcpMainTableTH { background-color: #C3C300;}
  19. .RcpMainTableTR { background-color: #CCCC88; border: 0; }
  20. .RcpRowInput { font-family:tahoma; font-size: 9pt; border: none; background-color: #F0F0F0; text-align:right;}
  21. .RcpRowInput2 { font-family:tahoma; font-size: 9pt; border: 1px solid black; background-color: #F0F0F0; text-align:right;}
  22. .RcpHeadInput { font-family:tahoma; font-size: 9pt; border: none; background-color: #CCCC88; text-align:center;}
  23. .RcpHeadInput2 { font-family:tahoma; font-size: 9pt; border: none; background-color: #AACC77; text-align:center;}
  24. .RcpHeadInput3 { font-family:tahoma; font-size: 9pt; border: 1px solid black; background-color: #D0E0FF; text-align:right; direction: right-to-left;}
  25. .RcpGenInput { font-family:tahoma; font-size: 9pt; border: none; text-align:right; direction: LTR;}
  26. .GenTable { font-family:tahoma; font-size: 9pt; border:0; padding:0; }
  27. .GenButton { font-family:tahoma; font-size: 9pt; border: 1px solid black; }
  28. .GrayOutLine {border: 1px solid gray; }
  29. </style>
  30. <SCRIPT LANGUAGE="JavaScript">
  31. <!--
  32. var okToProceed=false;
  33. var currentRow=null;
  34. //-->
  35. </SCRIPT>
  36. <!--#include File="../include_UtilFunctions.asp"-->
  37. <%
  38. if request("act")="ShowReceipt" then
  39. Receipt=clng(request("id"))
  40. %>
  41. <SCRIPT LANGUAGE="JavaScript">
  42. <!--
  43. var status = -1;
  44. var timeoutID= 0;
  45. function openCashDrawer()
  46. {
  47. drawerPresent = true;
  48. try
  49. {
  50. document.getElementById('Drawer').OpenUPort(1);
  51. }
  52. catch(e)
  53. {
  54. drawerPresent = false;
  55. }
  56. if ( drawerPresent )
  57. {
  58. //document.getElementById('Drawer').OpenUPort(1);
  59. status = document.getElementById('Drawer').UCashDrawerStatus(1);
  60. if (status>-1)
  61. {
  62. document.getElementById('Drawer').OpenUCashDrawer(1);
  63. }
  64. //document.getElementById('Drawer').CloseUPort(1);
  65. }
  66. }
  67. function closeCashDrawer()
  68. {
  69. drawerPresent = true;
  70. try
  71. {
  72. document.getElementById('Drawer').OpenUPort(1);
  73. }
  74. catch(e)
  75. {
  76. drawerPresent = false;
  77. }
  78. if ( drawerPresent )
  79. {
  80. //document.getElementById('Drawer').OpenUPort(1);
  81. document.getElementById('Drawer').OpenUPort(1);
  82. // Status: 1:Open, 0:Close
  83. while ( document.getElementById('Drawer').UCashDrawerStatus(1)==1 )
  84. {
  85. alert(' ');
  86. }
  87. //document.getElementById('Drawer').CloseUPort(1);
  88. }
  89. }
  90. //-->
  91. </SCRIPT>
  92. <OBJECT ID="Drawer" WIDTH="1" HEIGHT="1" CLASSID="CLSID:A46E44C7-AC96-4EFE-B8D7-EE7D67990B6F">
  93. </OBJECT>
  94. <BR><BR><BR>
  95. <CENTER>
  96. <% ReportLogRow = PrepareReport ("Receipt.rpt", "Recept_ID", Receipt, "/beta/dialog_printManager.asp?act=Fin") %>
  97. <INPUT TYPE="button" value=" ǁ " Class="GenButton" style="border:1 solid blue;" onclick="openCashDrawer();closeCashDrawer();printThisReport(this,<%=ReportLogRow%>);">
  98. </CENTER>
  99. <BR><iframe name=f1 id=f1 src="/CRReports/?Id=<%=ReportLogRow%>" align=center style="width:700; height:410; border-style: none" border=0 FRAMEBORDER=0 scrollbars=no ></iframe>
  100. <BR>
  101. <BR>
  102. <%
  103. response.end
  104. end if
  105. mySQL="SELECT * FROM CashRegisters WHERE (IsOpen=1) AND (Cashier='"& session("ID") & "')"
  106. Set RS1= conn.Execute(mySQL)
  107. if RS1.eof then
  108. %><br><br>
  109. <TABLE width='70%' align='center'>
  110. <TR>
  111. <TD align=center bgcolor=#FFBBBB style='border: solid 1pt black'><BR><b> <%=CSRName%> <br><br> <br>."</b><BR><BR></TD>
  112. </TR>
  113. </TABLE>
  114. <% conn.close
  115. response.end
  116. else
  117. CashRegID=RS1("ID")
  118. theBanker=RS1("Banker")
  119. CashRegName=RS1("NameDate")
  120. Set RS1=nothing
  121. end if
  122. if request("act")="submitsearch" then
  123. if isnumeric(request("SearchBox")) then
  124. orderID=clng(request("SearchBox"))
  125. mySQL="SELECT Invoices.Issued, Invoices.Approved, Invoices.ID, Invoices.TotalReceivable, Invoices.Customer FROM InvoiceOrderRelations INNER JOIN Invoices ON InvoiceOrderRelations.Invoice = Invoices.ID WHERE ([Order] = '"& orderID & "')"
  126. Set RS1=Conn.Execute(mySQL)
  127. if RS1.eof then
  128. Conn.close
  129. response.redirect "?errmsg=" & Server.URLEncode(" .")
  130. else
  131. theInvoice=RS1("ID")
  132. theCustomer=RS1("Customer")
  133. if RS1("Issued") then
  134. Conn.close
  135. response.redirect "?act=getReceipt&selectedCustomer=" & theCustomer & "&selectedInvoice=" & theInvoice
  136. else
  137. response.write "<br><br>"
  138. if RS1("Approved") then
  139. extraDesc="<br>(э )"
  140. end if
  141. call showAlert ("<b> ."& extraDesc & " <br>(: "& Separate(RS1("TotalReceivable")) & ")",CONST_MSG_ALERT)
  142. response.write "<Blockquote>"
  143. response.write "<br><br> Ͽ<br></b>"
  144. response.write "<br><br><li><A target='_blank' HREF='../AR/AccountReport.asp?act=showInvoice&invoice="& theInvoice & "'> </A>"
  145. response.write "<br><br><li><A HREF='?act=getReceipt&selectedCustomer=" & theCustomer & "'> .</A>"
  146. if RS1("Approved") then
  147. response.write "<br><br><li> <A target='_blank' HREF='../AR/InvoiceEdit.asp?act=search&order="& request("SearchBox") & "'> </A> "
  148. response.write " <A HREF='?act=submitsearch&SearchBox="& request("SearchBox") & "'> .</A>"
  149. end if
  150. response.write "</Blockquote>"
  151. end if
  152. end if
  153. elseif request("SearchBox") <> "" then
  154. SA_TitleOrName=request("SearchBox")
  155. SA_Action="return true;"
  156. SA_SearchAgainURL="ReceiptInput.asp"
  157. SA_StepText=" : "
  158. %>
  159. <FORM METHOD=POST ACTION="?act=getReceipt">
  160. <!--#include File="../AR/include_SelectAccount.asp"-->
  161. </FORM>
  162. <%
  163. else
  164. response.redirect "?errmsg=" & Server.URLEncode(" .")
  165. end if
  166. elseif request("act")="getReceipt" then
  167. if not isnumeric(request("selectedCustomer")) then
  168. response.write "EORROR"
  169. response.end
  170. end if
  171. if request("Reason")="" then
  172. Reason=1
  173. else
  174. Reason=cint(request("Reason"))
  175. end if
  176. if Reason=1 then
  177. sys="AR"
  178. elseif Reason=2 then
  179. sys="AP"
  180. else
  181. sys="AO"
  182. end if
  183. customerID=clng(request("selectedCustomer"))
  184. selectedInvoice=request.queryString("selectedInvoice")
  185. mySQL="SELECT * FROM Accounts WHERE (ID='"& CustomerID & "')"
  186. Set RS1 = conn.Execute(mySQL)
  187. AccountNo=cdbl(RS1("ID"))
  188. customerName=RS1("AccountTitle")
  189. creationDate=shamsiToday()
  190. %>
  191. <br><div dir='rtl'><B> : </B>
  192. </div>
  193. <!-- -->
  194. <hr>
  195. <input type="hidden" Name='tmpDlgArg' value=''>
  196. <input type="hidden" Name='tmpDlgTxt' value=''>
  197. <input type="hidden" id="maxChequeDay" value="<%=rs1("maxChequeDay")%>"/>
  198. <input type="hidden" id="maxChequeAmount" value="<%=rs1("maxChequeAmount")%>"/>
  199. <input type="hidden" id="customerRemainCheque" />
  200. <FORM METHOD=POST ACTION="?act=submitReceipt" onsubmit="return submitCeck2();" id="form1">
  201. <TABLE Cellspacing="0" Cellpadding="10" align="center">
  202. <TR><TD valign='top'>
  203. <table class="RcpMainTable" Cellspacing="1" Cellpadding="0" Width="500" align="center">
  204. <tr class="RcpMainTableTH">
  205. <td colspan="10" align='center' height='25px'> <span dir='LTR'><%=CashRegName%></span> - <%=CSRName%>
  206. <INPUT TYPE="hidden" Name="CashRegID" Value="<%=CashRegID%>">
  207. </td>
  208. </tr>
  209. <tr class="RcpMainTableTH">
  210. <td colspan="10"><TABLE Border="0" Width="100%" Cellspacing="1" Cellpadding="0" Dir="RTL"><TR>
  211. <TD><table>
  212. <tr>
  213. <td align="left">:</td>
  214. <td align="right">
  215. <span id="customer">
  216. <INPUT TYPE="hidden" NAME="customerID" value="<%=customerID%>"><span><%=CustomerName%></span>.
  217. </span></td>
  218. </tr>
  219. </table></TD>
  220. <td><table>
  221. <tr>
  222. <td></td>
  223. <td><input name="isA" value="1" type="radio"></td>
  224. <td></td>
  225. <td><input name="isA" value="0" type="radio"></td>
  226. <td> </td>
  227. <td><input id="asInvoice" name="isA" value="-1" type="radio" checked="checked"></td>
  228. </tr>
  229. </table></td>
  230. <TD align="left"><table>
  231. <tr>
  232. <td align="left">:</td>
  233. <td dir="LTR">
  234. <INPUT class="RcpGenInput date" style="text-align:Left;" NAME="ReceiptDate" TYPE="text" maxlength="10" size="10" value="<%=CreationDate%>" ></td>
  235. <td dir="RTL"><%=weekdayname(weekday(date))%></td>
  236. </tr>
  237. </table></TD>
  238. </TR></TABLE>
  239. </td>
  240. </tr>
  241. <tr class="RcpMainTableTR">
  242. <TD colspan="10"><div>
  243. <TABLE class="RcpTable" Cellspacing="1" Cellpadding="0" Dir="RTL">
  244. <tr height="40">
  245. <td colspan="2" align="left"> : </td>
  246. <td colspan="15"><INPUT dir="LTR" class="RcpRowInput2" TYPE="text" Name="CashAmount" size="15" onKeyPress="return maskNumber(this);" onBlur="setPrice(this)"> : <INPUT dir="RTL" class="RcpRowInput2" TYPE="text" Name="CashDescription" size="50" ></td>
  247. </tr>
  248. <tr height="30">
  249. <td colspan="15"> : <br></td>
  250. </tr>
  251. </TABLE></div></TD>
  252. </TR>
  253. <tr class="RcpMainTableTR">
  254. <TD colspan="10"><div>
  255. <TABLE class="RcpTable" Cellspacing="1" Cellpadding="0" Dir="RTL" bgcolor="#558855">
  256. <tr>
  257. <td class="RcpHeadInput" align='center' width="25px"> # </td>
  258. <td class="RcpHeadInput"><INPUT class="RcpHeadInput" readonly TYPE="text" value=" " size="12" tabindex="9999"></td>
  259. <td class="RcpHeadInput"><INPUT class="RcpHeadInput" readonly TYPE="text" value="" size="10" tabindex="9999"></td>
  260. <td class="RcpHeadInput"><INPUT class="RcpHeadInput" readonly TYPE="text" Value="" size="10" tabindex="9999"></td>
  261. <td class="RcpHeadInput"><INPUT class="RcpHeadInput" readonly TYPE="text" Value="" size="20" tabindex="9999"></td>
  262. <td class="RcpHeadInput"><INPUT class="RcpHeadInput" readonly TYPE="text" Value="" size="15" tabindex="9999"></td>
  263. </tr>
  264. </TABLE></div></TD>
  265. </TR>
  266. <tr class="RcpMainTableTR">
  267. <TD colspan="10" dir="RTL"><div style="overflow:auto; height:130px;width:500px;">
  268. <TABLE class="RcpTable" Border="0" Cellspacing="1" Cellpadding="0" Dir="RTL" bgcolor="#558855">
  269. <Tbody id="ChequeLines">
  270. <%
  271. for i=1 to 1
  272. %>
  273. <tr bgcolor='#F0F0F0' onclick="currentRow=this.rowIndex;" >
  274. <td align='center' width="25px"><%=i%></td>
  275. <td dir="LTR"><INPUT class="RcpRowInput" TYPE="text" NAME="ChequeNos" size="12" onKeyPress="return maskNumber(this);"></td>
  276. <td dir="LTR"><INPUT class="RcpRowInput" style="text-align:left;" TYPE="text" NAME="ChequeDates" maxlength="10" size="10" onblur="chequeDate(this)"></td>
  277. <td dir="RTL"><INPUT class="RcpRowInput" TYPE="text" NAME="Banks" size="10"></td>
  278. <td dir="RTL"><INPUT class="RcpRowInput" TYPE="text" NAME="Descriptions" size="20"></td>
  279. <td dir="LTR"><INPUT class="RcpRowInput" TYPE="text" NAME="Amounts" size="15" onKeyPress="return maskNumber(this);" onBlur="setPrice(this);"></td>
  280. </tr>
  281. <%
  282. next
  283. %>
  284. <!--tr bgcolor='#F0F0F0' onclick="currentRow=this.rowIndex;" >
  285. <td colspan="15">
  286. <INPUT class="RcpGenInput" TYPE="button" value="" onkeyDown="if(event.keyCode==9) return false;" onClick="addRow(this.parentNode.parentNode.rowIndex);">
  287. </td>
  288. </tr-->
  289. </Tbody></TABLE></div>
  290. </TD>
  291. </tr>
  292. <tr class="RcpMainTableTR">
  293. <TD colspan="10"><div>
  294. <TABLE Border="0" Cellspacing="1" Cellpadding="0" Dir="RTL">
  295. <tr>
  296. <td class="RcpHeadInput" align='center' width="25px"> &nbsp; </td>
  297. <td class="RcpHeadInput" colspan=2> :</td>
  298. <td class="RcpHeadInput"><INPUT class="RcpHeadInput" readonly TYPE="text" size="10" tabindex="9999" name="SelectedTotalPrice" onclick="$('input[name=CashAmount]').val($('input[name=SelectedTotalPrice]').val());$('input[name=CashAmount]').focus();"></td>
  299. <td class="RcpHeadInput"><INPUT class="RcpHeadInput" readonly TYPE="text" Value=":" size="20" tabindex="9999"></td>
  300. <td class="RcpHeadInput"><INPUT class="RcpHeadInput3" readonly dir="LTR" TYPE="text" Name="TotalAmount" Value="" size="15" tabindex="9999"></td>
  301. </tr>
  302. </TABLE></div></TD>
  303. </TR>
  304. </table>
  305. <TABLE class="RcpTable" Border="0" Cellspacing="5" Cellpadding="1" Dir="RTL">
  306. <tr>
  307. <td align='center' bgcolor="#000000"><INPUT class="RcpGenInput" style="text-align:center" TYPE="button" value="" onclick="$('#form1').submit();"></td>
  308. <td align='center' bgcolor="#000000"><INPUT class="RcpGenInput" style="text-align:center" TYPE="button" value="" onclick="window.location='';"></td>
  309. </tr>
  310. </TABLE>
  311. </TD>
  312. <TD valign='top'>
  313. <span style='width:100%;font-size:12pt;text-align:center;background-color:#FFDDDD;border:1px red solid;height:25px;'> </span><br>
  314. <span style='width:100%;font-size:9pt;text-align:center;background-color:#FFDDDD;border:1px red solid;height:25px;'>
  315. <SELECT NAME="Reason" style='font-family:Tahoma;font-size:8pt;height:25px;width:100px;' onchange="changeSystem();">
  316. <% mySQL="SELECT * FROM AXItemReasons WHERE Display=1 ORDER BY ID"
  317. Set RS1=Conn.Execute(mySQL)
  318. Do while not RS1.eof
  319. if Reason = RS1("ID") then
  320. ifSelected="selected"
  321. else
  322. ifSelected=""
  323. end if
  324. response.write "<OPTION value='"& RS1("ID") & "' "& ifSelected & ">"& RS1("Name") & "</option>"
  325. RS1.MoveNext
  326. Loop
  327. %>
  328. </SELECT></span>
  329. <TABLE class="GenTable" align="center" cellspacing="0" cellpadding="2" dir="RTL" border="3">
  330. <Tbody ID="DebitsTAble">
  331. <% '----------------- The Debit Items
  332. if Sys="AR" then
  333. mySQL="SELECT * From "& Sys & "Items WHERE (Account='"& AccountNo & "' AND IsCredit='0' AND FullyApplied='0') ORDER BY EffectiveDate , Link "
  334. Set RS1 = conn.Execute(mySQL)
  335. if (RS1.eof) then
  336. response.write "<tr><td bgcolor=white width=150><br><table align='center' cellpadding='5'><tr><td bgcolor='#FFCCCC' dir='rtl' align='center'> <br></td></tr></table><br></td></tr>"
  337. else
  338. TotalDebit=0
  339. while Not (RS1.EOF)
  340. if RS1("Type")=1 then 'invoice
  341. set rs2 = conn.Execute("select * from Invoices where id=" & RS1("Link"))
  342. if rs2("isA") then
  343. isA="()"
  344. else
  345. isA="()"
  346. end if
  347. sourceLink="<a style='text-decoration:none; color:red;' href='../"& Sys & "/AccountReport.asp?act=showInvoice&invoice="& RS1("Link") & "' target='_blank'>" & " " & RS1("Link") & isA & "</a>"
  348. rs2.close
  349. elseif RS1("Type")=2 then 'receipt
  350. sourceLink="<a style='text-decoration:none; color:red;' href='../"& Sys & "/AccountReport.asp?act=showReceipt&receipt="& RS1("Link") & "' target='_blank'>" & " " & RS1("Link") & "</a>"
  351. elseif RS1("Type")=3 then 'memo
  352. sourceLink="<a style='text-decoration:none; color:red;' href='../"& Sys & "/AccountReport.asp?act=showMemo&Sys="& Sys & "&memo="& RS1("Link") & "' target='_blank'>" & " " & RS1("Link") & "</a>"
  353. else ' i dunno
  354. sourceLink="<a style='text-decoration:none; color:red;' href='javascript:void(0);'>" & " [T:" & RS1("Type")& "] [L:"& RS1("Link") & "]</a>"
  355. end if
  356. %> <tr bgcolor="white" valign='top'><td class="GrayOutLine">
  357. <table class='GenTable' cellspacing='4' cellpadding='1' width='100%'>
  358. <%if RS1("Type")=1 and clng(RS1("Link"))=clng(selectedInvoice) then%>
  359. <tr bgcolor='#FFFFBB'>
  360. <td class="GrayOutLine">
  361. <INPUT TYPE="checkbox" checked NAME="DebitItems" value='<%=RS1("ID")%>' onclick="setPrice2(this)"><%=sourceLink%></td>
  362. </tr>
  363. <%else%>
  364. <tr bgcolor='#FFDDDD'>
  365. <td class="GrayOutLine">
  366. <INPUT TYPE="checkbox" NAME="DebitItems" value='<%=RS1("ID")%>' onclick="setPrice2(this)"><%=sourceLink%></td>
  367. </tr>
  368. <%end if%>
  369. <tr>
  370. <td class="GrayOutLine">: <%=Separate(RS1("RemainedAmount"))%><INPUT TYPE="hidden" name="price2" value="<%=RS1("RemainedAmount")%>"></td>
  371. </tr>
  372. </table></td></tr>
  373. <%
  374. TotalDebit = TotalDebit + cdbl(RS1("RemainedAmount"))
  375. RS1.movenext
  376. wend
  377. end if
  378. '----------------- End of The Debit Items
  379. end if
  380. %>
  381. </Tbody>
  382. </TABLE>
  383. </TD>
  384. </TR>
  385. </TABLE>
  386. </FORM>
  387. <SCRIPT LANGUAGE="JavaScript">
  388. <!--
  389. $(document).ready(function(){
  390. $('input[name=CashAmount]').focus();
  391. });
  392. tmpColor="#FFDDDD"
  393. tmpColor2="#FFFFBB"
  394. function changeSystem(){
  395. window.location='?act=getReceipt&selectedCustomer=<%=customerID%>&Reason='+document.all.Reason.value;
  396. }
  397. function setPrice2(obj){
  398. document.getElementById('asInvoice').checked=true;
  399. $("#asInvoice").prop("checked",true)
  400. a= obj.type
  401. ii=parseInt(obj.id)
  402. ii = parseInt($(obj).val());
  403. if($(obj).is(":checked")){
  404. var theTR = $(obj).closest("tr");
  405. theTR.prop("bgColor",tmpColor2);
  406. }
  407. else{
  408. var theTR = $(obj).closest("tr");
  409. theTR.prop("bgColor",tmpColor);
  410. }
  411. addAllPrice2();
  412. }
  413. function addAllPrice2(){
  414. var totalPrice = 0 ;
  415. var va = "";
  416. var description = " ";
  417. $("input[name=DebitItems]").each(function(i){
  418. if ($(this).is(":checked")){
  419. totalPrice += getNum($($("input[name=price2]")[i]).val());
  420. description += va + $(this).closest("tr").find("a").text();
  421. va = " ";
  422. }
  423. });
  424. if (description == " ")
  425. description = "";
  426. $("input[name=SelectedTotalPrice]").val(echoNum(totalPrice));
  427. $("input[name=CashDescription]").val(description);
  428. }
  429. function submitCeck2(){
  430. if (parseInt($('input[name=TotalAmount]:first').val())==0) return false;
  431. if (parseInt($('input[name=SelectedTotalPrice]:first').val())==0) return true;
  432. //if (document.all.AccountTitle.value=='') return false;
  433. if (parseInt($('input[name=SelectedTotalPrice]:first').val())!=parseInt($('input[name=TotalAmount]:first').val()))
  434. return confirm(" . Ͽ");
  435. return true;
  436. }
  437. addAllPrice2();
  438. //-->
  439. </SCRIPT>
  440. <%
  441. elseif request("act")="submitReceipt" then
  442. ON ERROR RESUME NEXT
  443. Reason= cint(request.form("Reason"))
  444. CustomerID= clng(request.form("CustomerID"))
  445. TotalAmount= cdbl(text2value(request.form("TotalAmount")))
  446. CashAmount= cdbl(text2value(request.form("CashAmount")))
  447. DepositAmount= cdbl(text2value(request.form("DepositAmount")))
  448. if Err.Number<>0 then
  449. Err.clear
  450. conn.close
  451. response.redirect "top.asp?errMsg=" & Server.URLEncode("!")
  452. end if
  453. ON ERROR GOTO 0
  454. mySQL="SELECT * FROM AXItemReasons WHERE (ID="& Reason & ")"
  455. Set RS1=Conn.execute(mySQL)
  456. if RS1.eof then
  457. conn.close
  458. response.redirect "top.asp?errMsg=" & Server.URLEncode("!")
  459. else
  460. Sys= RS1("Acron")
  461. firstGLAccount= RS1("GLAccount")
  462. end if
  463. RS1.close
  464. CashDescription= SqlSafe(request.form("CashDescription"))
  465. CashDescription= left(CashDescription,500) ' The Description field in ReceivedCash table in DB is 500 Bytes
  466. creationDate= shamsiToday()
  467. creationTime= CurrentTime10()
  468. ' #########################################################
  469. ' Find Receipts Related A or B Invoice or set it as Default in Accounts
  470. ' #########################################################
  471. ' ------ All this added by SAM
  472. if request("DebitItems").count>0 then
  473. if sys="AR" then
  474. isAs=""
  475. for i=1 to request("DebitItems").count
  476. mySQL="select isnull(invoices.IsA,2) as isA from ARItems inner join Invoices on arItems.link=invoices.ID where arItems.type=1 and arItems.id=" & request("DebitItems")(i)
  477. set RSSS=conn.Execute(mySQL)
  478. if RSSS.eof then
  479. isAlast = 2
  480. else
  481. if RSSS("isA") = "True" then
  482. isAlast = 1
  483. elseif RSSS("isA") = "False" then
  484. isAlast = 0
  485. else
  486. isAlast = 2
  487. end if
  488. end if
  489. if isAlast =2 then
  490. if request("isA")<>"-1" then
  491. isA=CInt(request("isA"))
  492. else
  493. response.redirect "?errMsg=" & server.URLEncode("! Ȑ ")
  494. end if
  495. else
  496. isAs=isAs & CStr(isAlast)
  497. end if
  498. RSSS.close
  499. next
  500. ' response.write isAs
  501. ' response.end
  502. if isAlast = 1 then
  503. if InStr(isAs,"0")>0 then
  504. response.redirect "?errMsg=" & server.URLEncode("! ")
  505. else
  506. isA=1
  507. end if
  508. else
  509. if InStr(isAs,"1")>0 then
  510. response.redirect "?errMsg=" & server.URLEncode("! ")
  511. else
  512. isA=0
  513. end if
  514. end if
  515. else
  516. if request("isA")<>"-1" then
  517. isA=CInt(request("isA"))
  518. else
  519. response.redirect "?errMsg=" & server.URLEncode("! ʡ . Ȑ")
  520. end if
  521. end if
  522. else
  523. if request("isA")<>"-1" then
  524. isA=CInt(request("isA"))
  525. else
  526. response.redirect "?errMsg=" & server.URLEncode("! ϡ ")
  527. end if
  528. end if
  529. ' response.write isAs & ", " & isA
  530. ' response.end
  531. '###########################################################
  532. '###########################################################
  533. '###########################################################
  534. if isA then
  535. GLAccount= "11007" 'This must be changed (Cashier A)
  536. else
  537. GLAccount= "11005" 'This must be changed (Cashier B)
  538. end if
  539. effectiveDate= sqlSafe(request.form("ReceiptDate"))
  540. '---- Checking wether EffectiveDate is valid in current open GL
  541. if (effectiveDate < session("OpenGLStartDate")) OR (effectiveDate > session("OpenGLEndDate")) then
  542. Conn.close
  543. response.redirect "?act=getReceipt&selectedCustomer="& CustomerID & "&Reason="& Reason & "&errMsg=" & Server.URLEncode("!<br> .")
  544. end if
  545. '----
  546. '----- Check GL is closed
  547. if (session("IsClosed")="True") then
  548. Conn.close
  549. response.redirect "?errMsg=" & Server.URLEncode("! .")
  550. end if
  551. '----
  552. a = TotalAmount
  553. TotalAmountLetter = ConvertIT(a)
  554. ' #########################################################
  555. ' INSERTING RECEIPT
  556. ' #########################################################
  557. ' NUMBER must be Receipt Number
  558. NUMBER =0
  559. ' CHQAMOUNT
  560. CHQAMOUNT =0
  561. ' CHQQTTY must be Receipt Qtty of Cheques
  562. CHQQTTY =0
  563. ' Changed By Kid 821016
  564. mySQL="INSERT INTO Receipts (SYS, CreatedDate, CreatedBy, EffectiveDate, Number, Customer, CashAmount, DepositAmount, ChequeAmount, ChequeQtty, TotalAmount, TotalAmountLetter) VALUES ('"& Sys & "', N'" &_
  565. creationDate & "', '"& session("ID") & "', N'" & effectiveDate & "', '"& NUMBER & "', '"& CustomerID & "', '"& CashAmount & "', '"& DepositAmount & "', '"& CHQAMOUNT & "', '"& CHQQTTY & "', '"& TotalAmount & "', N'"& TotalAmountLetter & "');SELECT @@Identity AS NewReceipt"
  566. set RS1 = Conn.execute(mySQL).NextRecordSet
  567. ReceiptID=RS1("NewReceipt")
  568. RS1.close
  569. ' #########################################################
  570. ' INSERTING CASH
  571. ' #########################################################
  572. mySQL="INSERT INTO ReceivedCash (Receipt, Amount, Banker, Description) VALUES ('"&_
  573. ReceiptID & "', '" & CashAmount & "', '" & theBanker & "', N'"& CashDescription & "')"
  574. conn.Execute(mySQL)
  575. chequeCount=0
  576. totalChequeAmount=0
  577. firstStatus=1 '----------------- FIRST STATUS FOR CHEQUES
  578. for i=1 to request.form("ChequeNos").count
  579. theChequeNo = text2value(request.form("ChequeNos")(i))
  580. theChequeDate = request.form("ChequeDates")(i)
  581. theOriginBank = request.form("Banks")(i)
  582. theOriginBank = left(theOriginBank,50) ' The BankOfOrigin field in ReceivedCheques table in DB is 50 Bytes long
  583. theDescription = request.form("Descriptions")(i)
  584. theAmount = text2value(request.form("Amounts")(i))
  585. if theAmount <> 0 then
  586. ' #########################################################
  587. ' INSERTING CHEQUES
  588. ' (Note: There is a TRIGGER)
  589. ' #########################################################
  590. mySQL="INSERT INTO ReceivedCheques (Receipt, ChequeNo, ChequeDate, Description, BankOfOrigin, Amount, LastStatus, LastBanker, LastUpdatedDate, LastUpdatedBy) VALUES ('"&_
  591. ReceiptID & "', N'" & theChequeNo & "', N'" & theChequeDate & "', N'" & theDescription & "', N'" & theOriginBank & "', '" & theAmount & "', '" & firstStatus & "', '" & theBanker & "', N'" & creationDate & "', '" & session("ID") & "')"
  592. conn.Execute(mySQL)
  593. chequeCount = chequeCount + 1
  594. totalChequeAmount = totalChequeAmount + theAmount
  595. end if
  596. next
  597. ' #########################################################
  598. ' CREATING AN ITEM for RECEIPT
  599. ' #########################################################
  600. '*** Type = 2 means Item is a Receipt
  601. mySQL="INSERT INTO "& Sys & "Items (GLAccount, GL, FirstGLAccount, Account, EffectiveDate, Reason, IsCredit, Type, Link, AmountOriginal, CreatedDate, CreatedBy, RemainedAmount) VALUES ('" &_
  602. GLAccount & "', '"& OpenGL & "', '"& firstGLAccount & "', '"& CustomerID & "', '"& EffectiveDate & "', '"& Reason & "', 1, 2, '"& ReceiptID & "', '"& TotalAmount - DepositAmount & "', N'"& creationDate & "', '"& session("ID") & "', '"& TotalAmount - DepositAmount & "'); SELECT @@Identity AS NewItem;"
  603. Set RS1=conn.Execute(mySQL).NextRecordSet
  604. theReceiptItem=RS1("NewItem")
  605. RS1.close
  606. ' #########################################################
  607. ' CREATING ITEMS RELATIONS
  608. ' #########################################################
  609. response.write "<div dir=LTR>selected debit items count :<br>"
  610. OnHandAmount = TotalAmount
  611. for i = 1 to request.form("DebitItems").count
  612. mySQL="SELECT RemainedAmount FROM "& Sys & "Items WHERE (ID='"& request.form("DebitItems")(i) & "')"
  613. Set RS1=Conn.execute(mySQL)
  614. theAmount=cdbl(RS1("RemainedAmount"))
  615. if theAmount > cdbl(OnHandAmount) then theAmount=OnHandAmount
  616. OnHandAmount = OnHandAmount - theAmount
  617. mySQL="INSERT INTO "& Sys & "ItemsRelations (CreatedDate, CreatedBy, Credit"& Sys & "Item, Debit"& Sys & "Item, Amount) VALUES (N'"& creationDate & "', '"& session("ID") & "', '"& theReceiptItem &"', '"& request.form("DebitItems")(i) &"', '"& theAmount &"')"
  618. conn.Execute(mySQL)
  619. mySQL="UPDATE "& Sys & "Items SET RemainedAmount=RemainedAmount-'"& theAmount & "' WHERE (ID='"& request.form("DebitItems")(i) & "')"
  620. conn.Execute(mySQL)
  621. if OnHandAmount=0 then exit for
  622. next
  623. mySQL="UPDATE "& Sys & "Items SET RemainedAmount='"& OnHandAmount & "' WHERE (ID='"& theReceiptItem & "')"
  624. conn.Execute(mySQL)
  625. mySQL="UPDATE "& Sys & "Items SET FullyApplied=1 WHERE (RemainedAmount=0) AND (voided=0) AND (FullyApplied=0)"
  626. conn.Execute(mySQL)
  627. ' #########################################################
  628. ' INSERTING RECEIPT INTO CASH REGISTER LINES
  629. ' Note: Inserted CashRegisterLineType is '1'
  630. ' That means "Receipt"
  631. ' #########################################################
  632. mySQL="INSERT INTO CashRegisterLines (CashReg, [Date], [Time], Type, Link,isA) VALUES ('"& CashRegID & "', N'"& creationDate & "', N'"& creationTime & "', '1', '"& ReceiptID & "', '"& isA &"')"
  633. ' response.write mySQL
  634. conn.Execute(mySQL)
  635. ' #########################################################
  636. ' UPDATING CASH REGISTERS
  637. ' #########################################################
  638. if isA then
  639. mySQL="UPDATE CashRegisters SET CashAmountA=CashAmountA+'"& CashAmount & "', ChequeAmount=ChequeAmount+'"& totalChequeAmount & "', ChequeQtty=ChequeQtty+'"& chequeCount & "' WHERE ID='"& CashRegID & "'"
  640. else
  641. mySQL="UPDATE CashRegisters SET CashAmountB=CashAmountB+'"& CashAmount & "', ChequeAmount=ChequeAmount+'"& totalChequeAmount & "', ChequeQtty=ChequeQtty+'"& chequeCount & "' WHERE ID='"& CashRegID & "'"
  642. end if
  643. conn.Execute(mySQL)
  644. '*****************************************************************
  645. '*********** Creating Deposit if needed should go here ***********
  646. '*****************************************************************
  647. ' #########################################################
  648. ' UPDATING Account Balance
  649. ' #########################################################
  650. mySQL="UPDATE Accounts SET "& Sys & "Balance = "& Sys & "Balance + '"& TotalAmount - DepositAmount & "' WHERE (ID='"& CustomerID & "')"
  651. conn.Execute(mySQL)
  652. Conn.close
  653. response.redirect "ReceiptInput.asp?act=ShowReceipt&id=" & ReceiptID
  654. 'response.end
  655. else%>
  656. <!-- --><BR><BR>
  657. <FORM METHOD=POST ACTION="?act=submitsearch" onsubmit="if (document.all.SearchBox.value=='') return false;">
  658. <div dir='rtl'>&nbsp;<B> : </B>
  659. <INPUT TYPE="text" NAME="SearchBox">&nbsp;
  660. <INPUT class="GenButton" TYPE="submit" value=""><br>
  661. </div>
  662. </FORM>
  663. <SCRIPT LANGUAGE="JavaScript">
  664. <!--
  665. document.all.SearchBox.focus();
  666. //-->
  667. </SCRIPT>
  668. <%
  669. end if
  670. conn.Close
  671. %>
  672. <% if request("act")="getReceipt" then %>
  673. <script language="JavaScript">
  674. $(document).ready(function(){
  675. $.ajaxSetup({
  676. cache: false
  677. });
  678. $.getJSON("/service/json_getAccount.asp",
  679. {act:"chequeRemain",account:$("input[name=customerID]").val()},
  680. function (json){
  681. $("#customerRemainCheque").val(json.amount);
  682. });
  683. });
  684. <!--
  685. function delRow(rowNo){
  686. chqTable=document.getElementById("ChequeLines");
  687. theRow=chqTable.getElementsByTagName("tr")[rowNo];
  688. chqTable.removeChild(theRow);
  689. for (rowNo=0; rowNo < document.getElementsByName("ChequeNos").length; rowNo++){
  690. chqTable.getElementsByTagName("tr")[rowNo].getElementsByTagName("td")[0].innerText= rowNo+1;
  691. }
  692. }
  693. function addRow(rowNo){
  694. chqTable=document.getElementById("ChequeLines");
  695. theRow=chqTable.getElementsByTagName("tr")[rowNo];
  696. newRow=document.createElement("tr");
  697. newRow.setAttribute("bgColor", '#f0f0f0');
  698. tempTD=document.createElement("td");
  699. tempTD.innerHTML=rowNo+1
  700. tempTD.setAttribute("align", 'center');
  701. tempTD.setAttribute("width", '25');
  702. newRow.appendChild(tempTD);
  703. tempTD=document.createElement("td");
  704. tempTD.setAttribute("dir", 'LTR');
  705. tempTD.innerHTML='<INPUT class="RcpRowInput" TYPE="text" NAME="ChequeNos" size="12" onKeyPress="return maskNumber(this);">'
  706. newRow.appendChild(tempTD);
  707. tempTD=document.createElement("td");
  708. tempTD.setAttribute("dir", 'LTR');
  709. tempTD.innerHTML='<INPUT class="RcpRowInput" style="text-align:left;" TYPE="text" NAME="ChequeDates" maxlength="10" size="10" onblur="chequeDate(this)">'
  710. newRow.appendChild(tempTD);
  711. tempTD=document.createElement("td");
  712. tempTD.innerHTML='<INPUT class="RcpRowInput" TYPE="text" NAME="Banks" size="10">'
  713. newRow.appendChild(tempTD);
  714. tempTD=document.createElement("td");
  715. tempTD.innerHTML='<INPUT class="RcpRowInput" TYPE="text" NAME="Descriptions" size="20">'
  716. newRow.appendChild(tempTD);
  717. tempTD=document.createElement("td");
  718. tempTD.setAttribute("dir", 'LTR');
  719. tempTD.innerHTML='<INPUT class="RcpRowInput" TYPE="text" NAME="Amounts" size="15" onKeyPress="return maskNumber(this);" onBlur="setPrice(this);">'
  720. newRow.appendChild(tempTD);
  721. chqTable.insertBefore(newRow,theRow);
  722. chqTable.getElementsByTagName("tr")[rowNo].getElementsByTagName("td")[1].getElementsByTagName("Input")[0].focus();
  723. }
  724. function setPrice(src){
  725. /* echoNum(src); */
  726. if ($(src).attr("name")=="Amounts" && $(src).closest("tr").find("input[name=ChequeNos]").val()==''){
  727. $(src).val(0);
  728. }
  729. else{
  730. if (!isNaN(echoNum(getNum($(src).val()))))
  731. $(src).val(0);
  732. else
  733. $(src).val(echoNum(getNum($(src).val())));
  734. }
  735. if ($("input[name=CashAmount]:first").val()=="NaN") $("input[name=CashAmount]:first").val(0);
  736. cashAmount=getNum($("input[name=CashAmount]:first").val());
  737. totalAmount = cashAmount;
  738. $("input[name=Amounts]").each(function(i,amount){
  739. if ($(amount).val()!='NaN' && $(amount).val()!='')
  740. totalAmount += getNum($(amount).val());
  741. });
  742. $("input[name=TotalAmount]:first").val(echoNum(totalAmount));
  743. if ($(src).attr("name")=="Amounts"){
  744. if ((getNum($(src).val()) + parseInt($("#customerRemainCheque").val())) > getNum($("#maxChequeAmount").val())){
  745. var str=" " + echoNum($("#maxChequeAmount").val()) + " ";
  746. if ( parseInt($("#customerRemainCheque").val())>0)
  747. str += " " + echoNum(parseInt($("#customerRemainCheque").val())) + ". ";
  748. $(src).val("0");
  749. alert(str);
  750. $(src).focus();
  751. //$(this).closest("tr").find("input").val("");
  752. }
  753. }
  754. }
  755. function chequeDate(obj){
  756. var obj=$(obj);
  757. obj.attr("title","");
  758. if (obj.val()=="") {
  759. obj.attr("title"," ");
  760. obj.focus();
  761. }
  762. else if (obj.val()=="//") {
  763. var today = new Date();
  764. obj.val($.format.date(today,"yyyy/MM/dd"));
  765. } else {
  766. var rege=/^(13)?[7-9][0-9]\/[0-1]?[0-9]\/[0-3]?[0-9]$/;
  767. if( rege.test(obj.val()) ) {
  768. var SP = obj.val().split("/");
  769. if (SP[0].length == 2) SP[0] = "13" + SP[0] ;
  770. if (SP[1].length == 1) SP[1] = "0" + SP[1] ;
  771. if (SP[2].length == 1) SP[2] = "0" + SP[2] ;
  772. obj.val(SP.join("/"));
  773. }
  774. if(!rege.test(obj.val())||( SP[0]<'1376' || SP[1]>'12' || SP[2]>'31' )) {
  775. obj.attr("title"," YYYY/MM/DD .");
  776. obj.focus();
  777. };
  778. }
  779. var now = new Date();
  780. var chequeDate = $.jalaliCalendar.jalaliToGregorianStr(obj.val());
  781. var diff = Math.floor((Date( chequeDate ) - Date( now )) / 86400000);
  782. if (parseInt($("#maxChequeDay").val())<diff){
  783. alert(" " + $("#maxChequeDay").val() + " ");
  784. obj.val($.format.date(now,"yyyy/MM/dd"));
  785. }
  786. }
  787. //-->
  788. </script>
  789. <%end if%>
  790. <!--#include file="tah.asp" -->