PageRenderTime 44ms CodeModel.GetById 26ms app.highlight 12ms RepoModel.GetById 2ms app.codeStats 0ms

/beta/cashReg/Close.asp

http://github.com/khaneh/Orders
ASP | 645 lines | 536 code | 56 blank | 53 comment | 70 complexity | 77112d854d7d021e21f06447867039a0 MD5 | raw file
  1<%@LANGUAGE="VBSCRIPT" CODEPAGE="1256"%><%
  2'CashRegister (9)
  3PageTitle="���� �����"
  4SubmenuItem=4
  5if not Auth(9 , 4) then NotAllowdToViewThisPage()
  6
  7%>
  8<!--#include file="top.asp" -->
  9<!--#include File="../include_farsiDateHandling.asp"-->
 10<!--#include File="../include_JS_InputMasks.asp"-->
 11<STYLE>
 12	.CClosTable {font-family:tahoma; font-size:9pt; direction: RTL; }
 13	.CClosTable td {padding:5;border:1pt solid gray;}
 14	.CClosTable a {text-decoration:none; color:#222288;}
 15	.CClosTable a:hover {text-decoration:underline;}
 16
 17	.CClosTableTitle {background-color: #CCCCFF; text-align: center; font-weight:bold; height:50;}
 18	.CClosTableHeader {background-color: #BBBBBB; text-align: center; font-weight:bold;}
 19	.CClosTableFooter {background-color: #BBBBBB; direction: LTR; }
 20	.CClosTR1 {background-color: #DDDDDD;}
 21	.CClosTR2 {background-color: #FFFFFF;}
 22	.CClosTR3 {background-color: #EEEEFF;}
 23	.CClosInpTable { font-family:tahoma; font-size: 9pt; padding:0; direction: RTL; width:100%;}
 24	.CClosInpTable Tr {Height:25px; border: 1px solid black;}
 25	.CClosInpTable Input { font-family:tahoma; font-size: 9pt; border: 1px solid black; direction: LTR;}
 26	.CClosInpTable Select { font-family:tahoma; font-size: 9pt; border: 1px solid black; }
 27
 28	.GenInput { font-family:tahoma; font-size: 9pt;}
 29	.GenButton { font-family:tahoma; font-size: 9pt; border: 1px solid black; }
 30</STYLE>
 31<%
 32
 33
 34function Link2Trace(OrderNo)
 35	Link2Trace="<A HREF='../order/TraceOrder.asp?act=show&order="& OrderNo & "' target='_balnk'>"& OrderNo & "</A>"
 36end function
 37
 38
 39if request("act")="Report" AND request("CashReg")<>"" then 
 40	CashRegID=request("CashReg")
 41	if not isnumeric(CashRegID) then
 42		response.write "<br>" 
 43		call showAlert ("���� ������ ���� �����",CONST_MSG_ERROR) 
 44		response.end
 45	end if
 46'	response.write cashRegID
 47	mySQL="SELECT CashRegisters.*, Users.RealName FROM CashRegisters INNER JOIN Users ON CashRegisters.Cashier = Users.ID WHERE (CashRegisters.IsOpen=1) AND (CashRegisters.ID='"& CashRegID & "')"
 48	Set RS1= conn.Execute(mySQL)
 49'	response.write mySQL
 50	if RS1.eof then 
 51		response.write "<br>" 
 52		call showAlert ("���� ������ ���� �����",CONST_MSG_ERROR) 
 53		response.end
 54	else
 55		CashRegName=RS1("NameDate")
 56		theCSRName=RS1("RealName")
 57		OpenningDate=RS1("OpenDate")
 58		OpenningAmount=cdbl(RS1("OpeningAmount"))
 59		cashAmountA=cdbl(RS1("cashAmountA"))
 60		cashAmountB=cdbl(RS1("cashAmountB"))
 61		chequeAmount=cdbl(RS1("chequeAmount"))
 62		chequeQtty=cdbl(RS1("chequeQtty"))
 63
 64		Set RS1=nothing
 65	end if
 66
 67	if OpenningDate > session("OpenGLEndDate") then
 68'		response.write session("OpenGLEndDate")
 69		response.write "<br>" 
 70		call showAlert ("����� ����� �� ��� ���� ��� �� ��� ���.",CONST_MSG_ERROR) 
 71		response.end
 72	end if
 73	'----- Check GL is closed
 74	if (session("IsClosed")="True") then
 75		Conn.close
 76		response.redirect "?errMsg=" & Server.URLEncode("���! ��� ���� ���� ���� ��� � ��� ���� �� ����� �� �� ������.")
 77	end if 
 78	'----
 79	mySQL="SELECT ReceivedCheques.ChequeNo, ReceivedCheques.ChequeDate, ReceivedCheques.Description, ReceivedCheques.BankOfOrigin,  receivedCheques.Amount, CashRegisterLines.* FROM ReceivedCheques INNER JOIN Receipts ON ReceivedCheques.Receipt = Receipts.ID INNER JOIN CashRegisterLines ON Receipts.ID = CashRegisterLines.Link WHERE (CashRegisterLines.CashReg = '"& CashRegID & "') AND (CashRegisterLines.Type = 1) ORDER BY CashRegisterLines.[Date], CashRegisterLines.[Time]"
 80	Set RS1 = conn.execute(mySQL)
 81	
 82	Remained = 0
 83    Totalcredit = 0
 84    TotalDebit = 0
 85	tempCounter = 0
 86
 87	if true then 'Not RS1.EOF OR OpenningAmount<>0 then
 88%>
 89		<br>
 90		<TABLE class="CClosTable" align='center'>
 91		<TR>
 92			<TD class="CClosTableTitle" colspan=9 dir='rtl' align='center'><br><B>����� ����� <span dir='LTR'><%=CashRegName%></span> - <%=theCSRName%> <INPUT TYPE="hidden" Name="CashRegID" Value="<%=CashRegID%>"></B><br><br>
 93			</TD>
 94		</TR>
 95<%
 96		Remained = OpenningAmount
 97		Credit = OpenningAmount
 98		Totalcredit = OpenningAmount
 99		tempCounter = 0
100%>		<TR class='CClosTR3'>
101			<td colspan='6' align='right'>����� ����� �����:</td>
102			<td dir='LTR' align='right'><%=Separate(Credit)%>&nbsp;</td>
103		</TR>
104		<TR>
105			<TD colspan='5' class="CClosTableFooter" align="right">:����� ���</td>
106			<TD colspan="2" class="CClosTableFooter" align='left'>
107				<span style="padding:10px;color:red;">���: </span>
108				<span id='cashAmountA'><%=cashAmountA%></span>
109				<span style="padding:10px;color:red;">�: </span> 
110				<span id='cashAmountB'><%=cashAmountB%></span>
111			</TD>
112		</TR>
113		<TR>
114			<TD colspan='6' class="CClosTableFooter" style='direction:RTL;text-align=left;'>����� �� (<span id='chequeQtty'><%=Separate(chequeQtty)%></span> ����) :</td>
115			<TD class="CClosTableFooter" align='right'><%=Separate(chequeAmount)%></TD>
116		</TR>
117		<TR>
118
119			<TD colspan='6' class="CClosTableFooter">: ���</td>
120			<TD class="CClosTableFooter" align='right'><%=Separate(cashAmountA + cashAmountB + chequeAmount)%></td>
121		</TR>
122		<TR class='CClosTR3'>
123			<td colspan='7' align='right'>���� �� ��:</td>
124		</TR>
125		<TR class="CClosTableHeader">
126			<TD>#</TD>
127			<TD width="100px">����� ������</TD>
128			<TD width="50px">�����</TD>
129			<TD width="50px">����</TD>
130			<TD width="70px">����� ��</TD>
131			<TD width="220px">�������</TD>
132			<TD width="70px">����</TD>
133		</TR>
134<%
135		While Not (RS1.EOF)
136			tempCounter=tempCounter+1
137
138			sourceLink="../AR/AccountReport.asp?act=showReceipt&receipt="& RS1("Link")
139			Description = "������ "
140			myAND=""
141
142			Amount=Separate(RS1("Amount"))
143
144			if RS1("Voided") then
145				tempCounter=tempCounter-1%>
146				<TR class='CClosTR4'>
147					<td>-</td>
148					<td dir='LTR'><A HREF='<%=sourceLink%>' target='_blank'><%=RS1("Date") & " @ " & RS1("Time")%></A></td>
149					<td><%=RS1("ChequeNo")%></td>
150					<td><%=RS1("BankOfOrigin")%></td>
151					<td dir='LTR'><%=RS1("ChequeDate")%></td>
152					<td><%=RS1("Description")%></td>
153					<td dir='LTR'>
154						<div style="position:absolute;width:600;"><hr style="color:red;"></div><div align='right'><%=Amount%></div>
155<%			else%>						
156				<TR class='<%if tempCounter MOD 2 = 0 then response.write "CClosTR1" else response.write "CClosTR2"%>'>
157					<td><%=tempCounter%></td>
158					<td dir='LTR'><A HREF='<%=sourceLink%>' target='_blank'><%=RS1("Date") & " @ " & RS1("Time")%></A></td>
159					<td><%=RS1("ChequeNo")%></td>
160					<td><%=RS1("BankOfOrigin")%></td>
161					<td dir='LTR'><%=RS1("ChequeDate")%></td>
162					<td><%=RS1("Description")%></td>
163					<td dir='LTR' align='right'>
164						<%=Amount%>
165<%			end if
166%>					</td>
167				</TR>
168<%
169			RS1.MoveNext
170		Wend
171		if Remained>=0 then
172			remainedColor="green"
173		else
174			remainedColor="red"
175		end if
176%>
177		<TR class='CClosTR3'>
178			<td colspan='7' align='right'>������� ���� ���� ���� �����:</td>
179		</TR>
180			<TR>
181				<TD colspan='7' style='border:2 dashed blue;'>
182					<table width='100%' class='CClosInpTable'>
183					<FORM METHOD=POST ACTION="?act=submitClose" onsubmit="return formValidation();">
184					<tr>
185						<td>�� ����� ���� ��/���� ��Ͽ</td>
186						<td colspan='3'><INPUT TYPE="text" NAME="ShortOverAmount"  onKeyPress="return maskNumber(this);" onblur="setPrice(this);"> &nbsp; ���� &nbsp;
187						<SELECT NAME="ShortOver" onchange="setPrice(this);">
188							<OPTION id='opt0' VALUE="">-------</OPTION>
189							<OPTION id='opt1' VALUE="1">��</OPTION>
190							<OPTION id='opt2' VALUE="3">����</OPTION>
191						</SELECT></td>
192					</tr>
193					<tr>
194						<td>�� �� �� �� ���� ����� �� ��Ͽ</td>
195						<td><SELECT NAME="ChequesNewBanker" onchange="document.all.ChequesNewBankerPass.focus();">
196							<OPTION VALUE="">----------------</OPTION>
197<%						mySQL="SELECT Bankers.ID, Bankers.Name, Users.RealName FROM Bankers INNER JOIN Users ON Bankers.Responsible = Users.ID WHERE (IsBankAccount = 0) ORDER BY Bankers.Name"
198						Set RS1 = conn.execute(mySQL)
199						while not RS1.eof
200%>							<OPTION VALUE="<%=RS1("ID")%>"><%=RS1("Name")%> (<%=RS1("RealName")%>)</OPTION>
201<%							RS1.MoveNext
202						wend
203%>						</SELECT></td>
204						<td>���� ����:</td>
205						<td><INPUT TYPE="password" NAME="ChequesNewBankerPass" onkeyDown="return myKeyDownHandler();" onKeyPress="return myKeyPressHandler();"></td>
206					</tr>
207					<tr>
208						<td><INPUT checked TYPE="checkbox" style='width:20px;border:0;' NAME="AutoNewCashReg" onclick="checkAutoGen(this);"> �������� ����� ���� ����� ���</td>
209						<td><span id="Sp1" >����� �����: <INPUT TYPE="text" style="text-align:left;width:80px;" Name="NameDate" value="<%=shamsiToday()%>"  onblur="acceptDate(this)"></span></td>
210						<td><span id="Sp2">����� �����: </span></td>
211						<td><span id="Sp3"><INPUT TYPE="text" NAME="OpeningAmount" readonly Value='0'> &nbsp; ���� &nbsp;</span></td>
212					</tr>
213					<tr>
214						<td colspan="4"> �� ����� ��� ����� ���: &nbsp;
215						<INPUT readonly tabIndex="98" TYPE="text" style="text-align:left;width:100px; background: transparent;font-weight:bold;" Name="totalRemainedCashA" value="<%=cashAmountA%>"> &nbsp; ���� &nbsp;
216						 �� ����� ��� ����� �: &nbsp;							
217						<INPUT readonly tabIndex="99" TYPE="text" style="text-align:left;width:100px; background: transparent;font-weight:bold;" Name="totalRemainedCashB" value="<%=cashAmountB%>"> &nbsp; ���� &nbsp;
218						</td>
219					</tr>
220					<tr>
221						<td>��� ��� ��� �� �� ��� ����� �� ��Ͽ</td>
222						<td><SELECT NAME="CashAcceptor" onchange="document.all.CashAcceptorPass.focus();">
223							<OPTION VALUE="">---------------</OPTION>
224<%						mySQL="SELECT * FROM Users WHERE Display=1 ORDER BY RealName"
225						Set RS1 = conn.execute(mySQL)
226						while not RS1.eof
227%>							<OPTION VALUE="<%=RS1("ID")%>"><%=RS1("RealName")%></OPTION>
228<%							RS1.MoveNext
229						wend
230
231%>						</SELECT></td>
232						<td>���� ����:</td>
233						<td><INPUT TYPE="password" NAME="CashAcceptorPass" onkeyDown="return myKeyDownHandler();" onKeyPress="return myKeyPressHandler();"></td>
234					</tr>
235					<tr>
236						<td colspan="4" align="center">
237							<INPUT TYPE="hidden" Name="TempCashAmountA" Value="<%=cashAmountA%>">
238							<INPUT TYPE="hidden" Name="TempCashAmountB" Value="<%=cashAmountB%>">
239							<INPUT TYPE="hidden" Name="TempChequeAmount" Value="<%=ChequeAmount%>">
240							<INPUT TYPE="hidden" Name="TempChequeQtty" Value="<%=ChequeQtty%>">
241
242							<INPUT TYPE="hidden" Name="CashRegID" Value="<%=CashRegID%>">
243							<INPUT TYPE="submit" VALUE="�����" style="width:50px;">
244						</td>
245					</tr>
246					</FORM>
247					</table>
248				</TD>
249			</TR>
250		</TABLE>
251		<SCRIPT LANGUAGE="JavaScript">
252		<!--
253		document.all.ShortOverAmount.focus();
254		//-->
255		</SCRIPT>
256		<br>
257<%	end if
258elseif request("act")="submitClose" then
259
260	CashRegID=request.form("CashRegID")
261	if not isnumeric(CashRegID) then
262		response.redirect "?errmsg=" & Server.URLEncode("����� ����� ������ ����")
263	end if
264	mySQL="SELECT * FROM CashRegisters WHERE (IsOpen=1) AND (ID='" & CashRegID & "')"
265	Set RS1=conn.execute(mySQL)
266	if RS1.eof then
267		Conn.close
268		response.redirect "?errmsg=" & Server.URLEncode("����� ����� ������ ����")
269	end if
270
271	CashAmountA=cdbl(RS1("cashAmountA"))
272	CashAmountB=cdbl(RS1("cashAmountB"))
273	ChequeAmount=cdbl(RS1("chequeAmount"))
274	ChequeQtty=cdbl(RS1("chequeQtty"))
275	nameDate = RS1("NameDate")
276
277	if NOT (CashAmountA = cdbl(request.form("TempCashAmountA")) AND CashAmountB = cdbl(request.form("TempCashAmountB")) AND ChequeAmount = cdbl(request.form("TempChequeAmount")) AND ChequeQtty = cdbl(request.form("TempChequeQtty")) ) then
278		Conn.close
279		response.redirect "?act=Report&CashReg=" & CashRegID & "&errmsg=" & Server.URLEncode("������� �� ���� ���� ����� ����� ���� ���.<br><br> ���� ������ �� ����.")
280	end if
281
282	theCashier=RS1("Cashier")
283	theBanker=RS1("Banker")
284	RS1.close
285	Set RS1=nothing
286
287	closeDate = shamsiToday()	
288	closeTime = currentTime10()
289
290	if request.form("AutoNewCashReg")="on" then
291		AutoNewCashReg = 1
292	else
293		AutoNewCashReg = 0
294	end if
295
296	CashAcceptor = 0
297	ChequesNewBanker = -1
298	RemainedCashMemo = 0
299	ShortOverMemo = 0
300
301	totalRemainedCashA=text2value(request.form("totalRemainedCashA"))
302	totalRemainedCashB=text2value(request.form("totalRemainedCashB"))
303	if CDbl(totalRemainedCashA) < 0 or CDbl(totalRemainedCashB) < 0 then
304		response.redirect "?act=Report&CashReg=" & CashRegID &"&errmsg=" & Server.URLEncode("�� �����<br>���� �� ����� �!�!�!�!�!� �� �� !<br>���� ��� ���� �ѐ�� ����� ��.")
305	elseif totalRemainedCashA > 0 or totalRemainedCashB then
306		CashAcceptor = clng(request.form("CashAcceptor")) 
307		mySQL="SELECT Users.Password, Users.Account FROM Users INNER JOIN Accounts ON Users.Account = Accounts.ID WHERE Users.ID='" & CashAcceptor & "' AND Users.Password='" & sqlSafe(request.form("CashAcceptorPass")) & "' "
308
309		Set RS1=conn.execute(mySQL)
310		If RS1.EOF Then
311			conn.close
312			response.redirect "?act=Report&CashReg=" & CashRegID &"&errmsg=" & Server.URLEncode("���� ������ ��� �� ������ ���")
313		elseif RS1("Password")<>request.form("CashAcceptorPass") then
314			conn.close
315			response.redirect "?act=Report&CashReg=" & CashRegID &"&errmsg=" & Server.URLEncode("���� ���� ������ ��� �� ������ ���")
316		end if
317		cashAcceptorAccount=RS1("Account")
318		RS1.close
319		Set RS1=Nothing
320	end if
321
322	ShortOverAmount=text2value(request.form("ShortOverAmount"))
323	if ShortOverAmount < 0 then
324		response.redirect "?act=Report&CashReg=" & CashRegID &"&errmsg=" & Server.URLEncode("��� ... ����� �� / ���� ���� ���.")
325	elseif ShortOverAmount > 0 then
326		if request.form("ShortOver")=3 then 
327			'3 means Over
328			isCredit=1
329			ShortOverDescription ="����� ����� ��� ����� � " & nameDate
330		elseif request.form("ShortOver")=1 then
331			'1 means Short
332			isCredit=0
333			ShortOverDescription ="����� ���� ��� ����� � " & nameDate
334		else
335			conn.close
336			response.redirect "?act=Report&CashReg=" & CashRegID &"&errmsg=" & Server.URLEncode("��� ... �� �� ���Ͽ")
337		end if
338	end if
339
340	if ChequeQtty > 0 then
341		ChequesNewBanker = sqlSafe(request.form("ChequesNewBanker")) 
342		mySQL="SELECT Users.Password, Users.Account  FROM Bankers INNER JOIN Users ON Bankers.Responsible = Users.ID WHERE (Bankers.ID = '"& ChequesNewBanker & "') AND (Users.Password = N'"& sqlSafe(request.form("ChequesNewBankerPass")) & "')"
343		Set RS1=conn.execute(mySQL)
344		If RS1.EOF Then
345			conn.close
346			response.redirect "?act=Report&CashReg=" & CashRegID &"&errmsg=" & Server.URLEncode("���� ���� ������ �� �� ������ ���")
347		elseif RS1("Password")<>request.form("ChequesNewBankerPass") then
348			conn.close
349			response.redirect "?act=Report&CashReg=" & CashRegID &"&errmsg=" & Server.URLEncode("���� ���� ������ �� �� ������ ���")
350		end if
351	end if
352
353	'*************************************************************************
354	'*****			Handing the Remained Cash to an Account A
355	'*************************************************************************
356	if totalRemainedCashA > 0 then
357			
358		' AOMemoType = 1 means (miscellaneous)
359		mySQL="INSERT INTO AOMemo (CreatedDate, CreatedBy, Type, Account, IsCredit, Amount, Description) VALUES (N'"& closeDate & "' , "& session("ID") & ", 1, "& cashAcceptorAccount & ", 0, "& totalRemainedCashA & ", N'����� ������ ��� ����� ��� " & nameDate & "');SELECT @@Identity AS NewMemoID"
360		set RS1 = Conn.execute(mySQL).NextRecordSet
361		cashMemoA = RS1 ("NewMemoID")
362		RemainedCashMemo = cashMemoA
363		RS1.close
364
365		'**************************** Creating AOItem for Memo  ****************
366		'*** Type = 3 means AOItem is a Memo
367		'*** Reason = 5 means (Borrow) and Sys=AO 
368
369		firstGLAccount=	"18001"	'This must be changed... GLAccount For Reason=5	(Misc. Debitors)
370		GLAccountA=			"11007"		'This must be changed� (Cashier A)
371		GLAccountB=			"11005"		'This must be changed� (Cashier B)
372
373		mySQL="INSERT INTO AOItems (GLAccount, GL, FirstGLAccount, Account, EffectiveDate, IsCredit, Reason, Type, Link, AmountOriginal, CreatedDate, CreatedBy, RemainedAmount) VALUES ('" &_
374		GLAccountA & "', '"& OpenGL & "', '"& firstGLAccount & "', '"& cashAcceptorAccount & "', '"& closeDate & "', 0, 5, 3, '"& cashMemoA & "', '"& totalRemainedCashA & "', N'"& closeDate & "', '"& session("ID") & "', '"& totalRemainedCashA & "')"	
375		conn.Execute(mySQL)
376		'***------------------------- Creating AOItem for Memo  ----------------
377
378		'**************************** Updating Account AO Balance  ****************
379		mySQL="UPDATE Accounts SET AOBalance = AOBalance - '"& totalRemainedCashA & "' WHERE (ID='"& cashAcceptorAccount & "')"
380		conn.Execute(mySQL)
381		'***------------------------- Updating Account AO Balance  ----------------
382	end if
383	
384	'*************************************************************************
385	'*****			Handing the Remained Cash to an Account B
386	'*************************************************************************
387	if  totalRemainedCashB > 0 then
388		' AOMemoType = 1 means (miscellaneous)
389		mySQL="INSERT INTO AOMemo (CreatedDate, CreatedBy, Type, Account, IsCredit, Amount, Description) VALUES (N'"& closeDate & "' , "& session("ID") & ", 1, "& cashAcceptorAccount & ", 0, "& totalRemainedCashB & ", N'����� ������ ��� ����� � " & nameDate & "');SELECT @@Identity AS NewMemoID"
390		set RS1 = Conn.execute(mySQL).NextRecordSet
391		cashMemoB = RS1 ("NewMemoID")
392		RemainedCashMemo = cashMemoB
393		RS1.close
394
395		'**************************** Creating AOItem for Memo  ****************
396		'*** Type = 3 means AOItem is a Memo
397		'*** Reason = 5 means (Borrow) and Sys=AO 
398
399		firstGLAccount=	"18001"	'This must be changed... GLAccount For Reason=5	(Misc. Debitors)
400		GLAccountA=			"11007"		'This must be changed� (Cashier A)
401		GLAccountB=			"11005"		'This must be changed� (Cashier B)
402
403		mySQL="INSERT INTO AOItems (GLAccount, GL, FirstGLAccount, Account, EffectiveDate, IsCredit, Reason, Type, Link, AmountOriginal, CreatedDate, CreatedBy, RemainedAmount) VALUES ('" &_
404		GLAccountB & "', '"& OpenGL & "', '"& firstGLAccount & "', '"& cashAcceptorAccount & "', '"& closeDate & "', 0, 5, 3, '"& cashMemoB & "', '"& totalRemainedCashB & "', N'"& closeDate & "', '"& session("ID") & "', '"& totalRemainedCashB & "')"	
405		conn.Execute(mySQL)
406		'***------------------------- Creating AOItem for Memo  ----------------
407
408		'**************************** Updating Account AO Balance  ****************
409		mySQL="UPDATE Accounts SET AOBalance = AOBalance - '"& totalRemainedCashB & "' WHERE (ID='"& cashAcceptorAccount & "')"
410		conn.Execute(mySQL)
411		'***------------------------- Updating Account AO Balance  ----------------
412	end if
413	
414	'*************************************************************************
415	'*****			Applying the Cash Register Short / Over Amount to Cashier's Account
416	'*************************************************************************
417	if ShortOverAmount > 0 then
418
419		mySQL="SELECT Account FROM Users WHERE (ID = '"& theCashier & "')"
420		set RS1=conn.execute(mySQL)
421		cashierAccount=RS1("Account")
422		RS1.close
423		set RS1=nothing
424
425		' AOMemoType = 6 means (Short of Cash)
426		mySQL="INSERT INTO AOMemo (CreatedDate, CreatedBy, Type, Account, IsCredit, Amount, Description) VALUES (N'"& closeDate & "' , "& session("ID") & ", 6, "& cashierAccount & ", '"& isCredit & "', "& ShortOverAmount & ", N'"& ShortOverDescription & "');SELECT @@Identity AS NewMemoID"
427
428		set RS1 = Conn.execute(mySQL).NextRecordSet
429		MemoID = RS1 ("NewMemoID")
430		ShortOverMemo = MemoID
431		RS1.close
432
433		'**************************** Creating AOItem for Memo  ****************
434		'*** Type = 3 means AOItem is a Memo
435		'*** Reason = 5 means (Borrow) and Sys=AO 
436
437		firstGLAccount=	"18001"	'This must be changed... GLAccount For Reason=5	(Misc. Debitors)
438
439		GLAccount=		"11005"	'This must be changed... (Cashier B)
440
441		mySQL="INSERT INTO AOItems (GLAccount, GL, FirstGLAccount, Account, EffectiveDate, IsCredit, Reason, Type, Link, AmountOriginal, CreatedDate, CreatedBy, RemainedAmount) VALUES ('"&_
442		GLAccount & "', '"& OpenGL & "', '"& firstGLAccount & "', '"& cashierAccount & "', '"& closeDate & "', '"& isCredit & "', 5, 3, '"& MemoID & "', '"& ShortOverAmount & "', N'"& closeDate & "', '"& session("ID") & "', '"& ShortOverAmount & "')"	
443		conn.Execute(mySQL)
444		'***------------------------- Creating AOItem for Memo  ----------------
445
446		'**************************** Updating Account AO Balance  ****************
447		if isCredit=0 then
448			mySQL="UPDATE Accounts SET AOBalance = AOBalance - '"& ShortOverAmount & "' WHERE (ID='"& cashierAccount & "')"
449		else
450			mySQL="UPDATE Accounts SET AOBalance = AOBalance + '"& ShortOverAmount & "' WHERE (ID='"& cashierAccount & "')"
451		end if
452			conn.Execute(mySQL)
453		'***------------------------- Updating Account AO Balance  ----------------
454	end if
455
456	'*************************************************************************
457	'*****		Handing Cheques to a Banker  
458	'*************************************************************************
459	if ChequeQtty > 0 then
460		'****************************************************
461		'***			UPDATING  ReceivedCheques 
462		'***		Set New Banker , and New Status
463		'***	Status : 1 (in open cash) --> 6 (received)
464		'****************************************************
465		mySQL="UPDATE ReceivedCheques SET LastBanker ='"& sqlSafe(request.form("ChequesNewBanker")) & "', LastStatus = 6 WHERE (ID IN (SELECT ReceivedCheques.ID FROM ReceivedCheques INNER JOIN Receipts ON ReceivedCheques.Receipt = Receipts.ID INNER JOIN CashRegisterLines ON Receipts.ID = CashRegisterLines.Link WHERE (CashRegisterLines.CashReg = '"& CashRegID & "') AND (CashRegisterLines.Type = 1) AND (CashRegisterLines.Voided = 0)))"
466		conn.execute(mySQL)
467	end if
468
469	'*************************************************************************
470	'*****		Closing the Cash Register
471	'*************************************************************************
472	if cashMemoA="" then cashMemoA="null"
473	if cashMemoB="" then cashMemoB="null"
474	mySQL="UPDATE CashRegisters SET CloseDate=N'"& closeDate & "', CloseTime=N'"& closeTime & "', ClosedBy='"& session("ID") & "', IsOpen = '0', CashAcceptor='" & CashAcceptor & "', RemainedCashMemo='" & RemainedCashMemo & "', ChequesNewBanker = '" & ChequesNewBanker & "', ShortOverAmount='"& ShortOverAmount & "', ShortOverMemo='" & ShortOverMemo & "',cashMemoA=" & cashMemoA & ",cashMemoB=" & cashMemoB & " WHERE (ID='"& CashRegID & "')"
475	conn.Execute(mySQL)
476	theResultReport="����� �� ������ ���� ��.<br>"
477
478	if AutoNewCashReg = 1 then
479		OpeningAmount=text2value(request("OpeningAmount"))
480		'*********************************************************************
481		'*****		Creating New Cash Register
482		'*********************************************************************
483		mySQL="INSERT INTO CashRegisters (Cashier, Banker, OpenDate, NameDate, OpenedBy, IsOpen, IsApproved, OpeningAmount, CashAmountB, CashAmountA, ChequeAmount, ChequeQtty, ShortOverAmount) VALUES ('" &_ 
484		theCashier & "', '"& theBanker & "', N'"& closeDate & "', N'"& request("NameDate") & "', '"& session("ID") & "', 1, 0, '"& OpeningAmount & "', '"& OpeningAmount & "', 0, 0, 0, 0)"
485		conn.Execute(mySQL)
486		theResultReport=theResultReport+"����� ���� �� ����� ��."
487	end if
488
489%>
490	<br>
491	<TABLE width=70% align='center'>
492	<TR>
493		<TD align=center bgcolor=#EEFF66 style='border: dashed 1pt Green'><BR><%=theResultReport%><BR><BR></TD>
494	</TR>
495	</TABLE>
496<%
497else
498	'mySQL="SELECT * FROM CashRegisters WHERE (IsOpen=1) AND (Cashier='"& session("ID") & "')"
499	mySQL="SELECT CashRegisters.ID, CashRegisters.NameDate, Users.RealName FROM CashRegisters INNER JOIN Users ON CashRegisters.Cashier = Users.ID WHERE (CashRegisters.IsOpen=1)"
500	Set RS1= conn.Execute(mySQL)
501	if RS1.eof then 
502	%><br><br>
503		<TABLE width='70%' align='center'>
504		<TR>
505			<TD align=center bgcolor=#FFBBBB style='border: solid 1pt black'><BR><b>��� ����� ���� ���� ����� ... <br><br>�� ��� �� ���� ���� ��� �� ��� ��� <br>������."</b><BR><BR></TD>
506		</TR>
507		</TABLE>
508	<%	conn.close
509		response.end
510	else
511	%>
512	<FORM METHOD=POST ACTION="?act=Report">
513		<br><br>
514		&nbsp;&nbsp;����� ���� ����� ��� �� ���� ���� ������ ����: <SELECT NAME="CashReg" class="GenButton" onchange="submit();">
515			<OPTION VALUE="">--------------------------</OPTION>
516<%		Do 
517%>			<OPTION VALUE="<%=RS1("ID")%>"><%=RS1("NameDate") & " (" & RS1("RealName")& ")"%></OPTION>
518<%			Rs1.moveNext
519		Loop while not RS1.eof
520%>
521		</SELECT> <INPUT TYPE="submit" value="����">
522	</FORM>
523	<%	Set RS1=nothing
524	end if
525end if
526conn.Close
527%>
528</font>
529<SCRIPT LANGUAGE="JavaScript">
530<!--
531function setPrice(src){
532	if (src.name!='ShortOver'){
533		src.value=val2txt(txt2val(src.value));
534	}
535	if (src.name=='ShortOverAmount'){
536		if (txt2val(src.value) != 0)
537			document.all.opt1.selected=true;
538		else
539			document.all.opt0.selected=true;
540	}		
541	else if (src.name=='ShortOver'){
542		if (txt2val(document.all.ShortOver.value)==0){
543			document.all.ShortOverAmount.value=0;
544		}
545		else if (txt2val(document.all.ShortOverAmount.value)==0){
546			document.all.opt0.selected=true;
547			document.all.ShortOverAmount.focus();
548		}
549	}
550	setTotalRemainedCash();
551//	alert(src.name+'='+src.value);
552}
553
554function setTotalRemainedCash(){
555	with (document.all){
556		if (AutoNewCashReg.checked)
557			totalRemainedCashB.value=val2txt((ShortOver.value - 2) * txt2val(ShortOverAmount.value) + txt2val(cashAmountB.innerText) - txt2val(OpeningAmount.value))
558			//totalRemainedCashA.value=val2txt((ShortOver.value - 2) * txt2val(ShortOverAmount.value) + txt2val(cashAmountB.innerText) - txt2val(OpeningAmount.value))
559		else
560			totalRemainedCashB.value=val2txt((ShortOver.value - 2) * txt2val(ShortOverAmount.value) + txt2val(cashAmountB.innerText)
561	}
562}
563function checkAutoGen(src){
564	if (src.checked){
565		document.getElementById("Sp1").style.visibility='visible';
566		document.getElementById("Sp2").style.visibility='visible';
567		document.getElementById("Sp3").style.visibility='visible';
568		document.getElementById("Sp3").getElementsByTagName("Input")[0].focus();
569	}
570	else{
571		document.getElementById("Sp1").style.visibility='hidden';
572		document.getElementById("Sp2").style.visibility='hidden';
573		document.getElementById("Sp3").style.visibility='hidden';
574	}
575	setTotalRemainedCash();
576}
577
578function formValidation(){
579	with (document.all){
580		setTotalRemainedCash();
581		if (txt2val(chequeQtty.innerText) != 0)
582			if (!ChequesNewBanker.value){
583				alert(":���� ���� ����\n" + "�� �� �� ��� ����� �� ���Ͽ");
584				ChequesNewBanker.focus();
585				return false;
586			}
587			else if (!ChequesNewBankerPass.value){
588				alert("���� ���� �� ���� ����");
589				ChequesNewBankerPass.focus();
590				return false;
591			}
592
593		if (totalRemainedCashA.value != 0 || totalRemainedCashB.value != 0)
594			if (!CashAcceptor.value){
595				alert(":���� ���� ����\n" + "��� ��� ��� �� �� ��� ����� �� ����Ͽ");
596				CashAcceptor.focus();
597				return false;
598			}
599			else if (!CashAcceptorPass.value){
600				alert("���� ���� �� ���� ����");
601				CashAcceptorPass.focus();
602				return false;
603			}
604		
605	}
606	return true;
607}
608//-->
609</SCRIPT>
610<SCRIPT LANGUAGE="JavaScript">
611<!--
612var tempKeyBuffer;
613function myKeyDownHandler(){
614	tempKeyBuffer=window.event.keyCode;
615}
616function myKeyPressHandler(){
617//	alert (tempKeyBuffer)
618	if (tempKeyBuffer>=65 && tempKeyBuffer<=90){
619		window.event.keyCode=tempKeyBuffer+32;
620	}
621	else if(tempKeyBuffer==186){
622		window.event.keyCode=59;
623	}
624	else if(tempKeyBuffer==188){
625		window.event.keyCode=44;
626	}
627	else if(tempKeyBuffer==190){
628		window.event.keyCode=46;
629	}
630	else if(tempKeyBuffer==191){
631		window.event.keyCode=47;
632	}
633	else if(tempKeyBuffer==192){
634		window.event.keyCode=96;
635	}
636	else if(tempKeyBuffer>=219 && tempKeyBuffer<=221){
637		window.event.keyCode=tempKeyBuffer-128;
638	}
639	else if(tempKeyBuffer==222){
640		window.event.keyCode=39;
641	}
642}
643//-->
644</SCRIPT>
645<!--#include file="tah.asp" -->