PageRenderTime 20ms CodeModel.GetById 8ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 0ms

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