PageRenderTime 28ms CodeModel.GetById 17ms app.highlight 5ms RepoModel.GetById 2ms app.codeStats 0ms

/beta/Inquiry/Rep_InvoiceItems.asp

http://github.com/khaneh/Orders
ASP | 626 lines | 554 code | 67 blank | 5 comment | 52 complexity | 5fc5280d3ab6755c680e946b541f83a5 MD5 | raw file
  1<%@LANGUAGE="VBSCRIPT" CODEPAGE="1256"%><%
  2'Order (2)
  3PageTitle="����� ����"
  4SubmenuItem=11
  5if not Auth("C" , 3) then NotAllowdToViewThisPage()
  6%>
  7<!--#include file="top.asp" -->
  8<!--#include File="../include_farsiDateHandling.asp"-->
  9<!--#include File="../include_JS_InputMasks.asp"-->
 10<STYLE>
 11	.CusTableHeader {background-color: #33AACC; text-align: center; font-weight:bold;}
 12	.CustTable {font-family:tahoma; width:80%; border:1 solid black; direction: RTL; background-color:black;}
 13	.CustTable td {padding:5;}
 14	.CustTable a {text-decoration:none;color:#000088}
 15	.CustTable a:hover {text-decoration:underline;}
 16	.CusTD1 {background-color: #CCCC66; text-align: left; font-weight:bold;}
 17	.CusTD2 {background-color: #DDDDDD; direction: LTR; text-align: right; font-size:9pt;}
 18	.CusTD3 {background-color: #DDDDDD; direction: LTR; text-align: center; font-size:9pt;}
 19	.CusTD4 {background-color: #CCCC66; direction: LTR; text-align: center; font-size:9pt;}
 20	.RepTable {font-family:tahoma; font-size:9pt; direction: RTL; }
 21	.RepTable th {font-size:9pt; padding:5px; background-color:#0080C0;height:25px;}
 22	.RepTable td {height:25px;}
 23	.RepTable input {font-family:tahoma; font-size:9pt; border:1 solid black;}
 24	.RepTable select {font-family:tahoma; font-size:9pt; border:1 solid black;}
 25</STYLE>
 26<%
 27if request("act")="show" then
 28
 29	ON ERROR RESUME NEXT
 30
 31		Category =		cint(request("Category"))
 32
 33		isA =			clng(request("isA"))
 34
 35		FromDate =		sqlSafe(request("FromDate"))
 36		ToDate =		sqlSafe(request("ToDate"))
 37
 38		ResultsInPage =	cint(request("ResultsInPage"))
 39		
 40		if FromDate="" AND ToDate="" then
 41			pageTitle="�� ���� ����"
 42		elseif FromDate="" then
 43			pageTitle="�� ����� �� ����� " & replace (ToDate,"/",".")
 44		elseif ToDate="" then
 45			pageTitle="�� ����� "& replace (FromDate,"/",".") & " �� ����� "
 46		else
 47			pageTitle="�� ����� "& replace (FromDate,"/",".") & " �� ����� " & replace (ToDate,"/",".")
 48		end if
 49	
 50		if ToDate = "" then ToDate = "9999/99/99"
 51		
 52		SalesAction =	request("SalesAction")
 53		SalesPerson =	request("SalesPerson")
 54
 55		if SalesAction="" then 
 56			SalesAction = 2 '�����
 57		else
 58			SalesAction = cint(SalesAction)
 59		end if
 60		if SalesPerson="" then 
 61			SalesPerson = 0 '���
 62		else
 63			SalesPerson = cint(SalesPerson)
 64		end if
 65
 66		if Err.Number<>0 then
 67			Err.clear
 68			conn.close
 69			response.redirect "OtherReports.asp?errMsg=" & Server.URLEncode("��� �� �����.")
 70		end if
 71	ON ERROR GOTO 0
 72
 73%>
 74<br>
 75	<FORM METHOD=POST ACTION="?act=show">
 76	<table class="RepTable" id="AInvoices" width="300" align=center>
 77	<tr>
 78		<th colspan="4">����� ���� ��� ����</td>
 79	</tr>
 80	<tr>
 81		<td align=left>��&nbsp;�����</td>
 82		<td><INPUT TYPE="text" NAME="FromDate" style="width:75px;direction:LTR;" maxlength=10 OnBlur="acceptDate(this);" Value="<%=FromDate%>"></td>
 83		<td align=left>��&nbsp;�����</td>
 84		<td><INPUT TYPE="text" NAME="ToDate" style="width:75px;direction:LTR;" maxlength=10 OnBlur="acceptDate(this);" <%if ToDate<>"9999/99/99" then response.write "Value='" & ToDate & "'" %>></td>
 85	</tr>
 86	<tr>
 87		<td align=left>����</td>
 88		<td align=left>
 89			<SELECT NAME="Category" style="width:150px;">
 90				<option value="">--- ������ ���� ---</option>
 91				<option value="0" <%if Category=0 then response.write "selected " : GroupName="[ ��� ] "%>>���</option>
 92<%
 93			mySQL = "SELECT * FROM InvoiceItemCategories"
 94			Set RS1 = Conn.Execute(mySQL)
 95			Do Until RS1.eof
 96%>				
 97				<option value="<%=RS1("ID")%>" <%if RS1("ID")=Category then response.write "selected " : GroupName="[" & RS1("Name") & "] "%>><%=RS1("Name")%></option>
 98<%
 99				RS1.moveNext
100			Loop
101			RS1.close
102			Set RS1 = Nothing
103
104			otherCriteria=""
105			if isA = 1 then
106				isAName = "�� ��� ���"
107				otherCriteria = " AND (isA=1) "
108			elseif isA = 2 then
109				isAName = "���� ��� ���"
110				otherCriteria = " AND (isA=0) "
111			end if
112
113			if Auth("C" , 6) then '����� ���� ��� ���� ����� �������
114				if SalesPerson <> 0 then
115					select case SalesAction
116					case 0:
117						otherCriteria = otherCriteria & " AND ((Invoices.CreatedBy=" & SalesPerson & ") OR (Invoices.ApprovedBy=" & SalesPerson & ") OR (Invoices.IssuedBy=" & SalesPerson & "))"
118					case 1:
119						otherCriteria = otherCriteria & " AND (Invoices.CreatedBy=" & SalesPerson & ")"
120					case 2:
121						otherCriteria = otherCriteria & " AND (Invoices.ApprovedBy=" & SalesPerson & ")"
122					case 3:
123						otherCriteria = otherCriteria & " AND (Invoices.IssuedBy=" & SalesPerson & ")"
124					end select
125				end if
126			end if
127
128			if Category = 0 then
129				GroupName= "(���)"
130'	S A M ------------------------------- THIS FILE HAS BEEN CHANGED BY SAM
131				mySQL_Sum="SELECT Count(*) AS CNT, SUM(A4Qtty * - (2 * CONVERT(tinyint, IsReverse) - 1)) AS A4Qtty, SUM(SumAppQtty * - (2 * CONVERT(tinyint, IsReverse) - 1)) AS SumAppQtty, SUM(SumPrice * - (2 * CONVERT(tinyint, IsReverse) - 1)) AS SumPrice, SUM(SumDiscount * - (2 * CONVERT(tinyint, IsReverse) - 1)) AS SumDiscount, SUM(SumReverse * - (2 * CONVERT(tinyint, IsReverse) - 1)) AS SumReverse, SUM(SumVat * - (2 * CONVERT(tinyint, IsReverse) -1)) AS SumVat FROM (SELECT InvoiceItems.ID, InvoiceItems.Name, SUM(InvoiceLines.Qtty * InvoiceLines.Sets * ROUND(InvoiceLines.Length * InvoiceLines.Width / 630 + .49, 0)) AS A4Qtty, SUM(InvoiceLines.AppQtty) AS SumAppQtty, SUM(CONVERT(bigint,InvoiceLines.Price)) AS SumPrice, SUM(InvoiceLines.Discount) AS SumDiscount, SUM(InvoiceLines.Reverse) AS SumReverse, SUM(InvoiceLines.Vat) AS SumVat, Invoices.IsReverse FROM InvoiceItems INNER JOIN InvoiceLines ON InvoiceItems.ID = InvoiceLines.Item INNER JOIN Invoices ON InvoiceLines.Invoice = Invoices.ID WHERE (Invoices.Voided = 0) AND (Invoices.Issued = 1) AND (Invoices.IssuedDate >= N'"& FromDate & "') AND (Invoices.IssuedDate <= N'"& ToDate & "') " & otherCriteria & " GROUP BY Invoices.IsReverse, InvoiceItems.ID, InvoiceItems.Name) DRV"
132				mySQL="SELECT InvoiceItems.ID, InvoiceItems.Name, SUM(InvoiceLines.Qtty * InvoiceLines.Sets * ROUND(InvoiceLines.Length * InvoiceLines.Width / 630 + .49, 0)) AS A4Qtty, SUM(InvoiceLines.AppQtty) AS SumAppQtty, SUM(CONVERT(bigint,InvoiceLines.Price)) AS SumPrice, SUM(InvoiceLines.Discount) AS SumDiscount, SUM(InvoiceLines.Reverse) AS SumReverse, SUM(InvoiceLines.Vat) AS SumVat, Invoices.IsReverse, MAX(InvoiceItemCategories.Name) as CategoryName FROM InvoiceItemCategories INNER JOIN InvoiceItemCategoryRelations ON InvoiceItemCategories.ID = InvoiceItemCategoryRelations.InvoiceItemCategory INNER JOIN InvoiceItems ON InvoiceItemCategoryRelations.InvoiceItem = InvoiceItems.ID INNER JOIN InvoiceLines ON InvoiceItems.ID = InvoiceLines.Item INNER JOIN Invoices ON InvoiceLines.Invoice = Invoices.ID WHERE (Invoices.Voided = 0) AND (Invoices.Issued = 1) AND (Invoices.IssuedDate >= N'"& FromDate & "') AND (Invoices.IssuedDate <= N'"& ToDate & "') " & otherCriteria & "  GROUP BY Invoices.IsReverse, InvoiceItems.ID, InvoiceItems.Name ORDER BY InvoiceItems.ID, Invoices.IsReverse"
133			else
134				mySQL_Sum="SELECT Count(*) AS CNT, SUM(A4Qtty * - (2 * CONVERT(tinyint, IsReverse) - 1)) AS A4Qtty, SUM(SumAppQtty * - (2 * CONVERT(tinyint, IsReverse) - 1)) AS SumAppQtty, SUM(SumPrice * - (2 * CONVERT(tinyint, IsReverse) - 1)) AS SumPrice, SUM(SumDiscount * - (2 * CONVERT(tinyint, IsReverse) - 1)) AS SumDiscount, SUM(SumReverse * - (2 * CONVERT(tinyint, IsReverse) - 1)) AS SumReverse, SUM(SumVat * -(2 * CONVERT(tinyint, IsReverse) - 1)) AS SumVat FROM (SELECT InvoiceItems.ID, InvoiceItems.Name, SUM(InvoiceLines.Qtty * InvoiceLines.Sets * ROUND(InvoiceLines.Length * InvoiceLines.Width / 630 + .49, 0)) AS A4Qtty, SUM(InvoiceLines.AppQtty) AS SumAppQtty, SUM(CONVERT(bigint,InvoiceLines.Price)) AS SumPrice, SUM(InvoiceLines.Discount) AS SumDiscount, SUM(InvoiceLines.Reverse) AS SumReverse, SUM(InvoiceLines.Vat) AS SumVat, Invoices.IsReverse FROM InvoiceItemCategories INNER JOIN InvoiceItemCategoryRelations ON InvoiceItemCategories.ID = InvoiceItemCategoryRelations.InvoiceItemCategory INNER JOIN InvoiceItems ON InvoiceItemCategoryRelations.InvoiceItem = InvoiceItems.ID INNER JOIN InvoiceLines ON InvoiceItems.ID = InvoiceLines.Item INNER JOIN Invoices ON InvoiceLines.Invoice = Invoices.ID WHERE (Invoices.Voided = 0) AND (Invoices.Issued = 1) AND (InvoiceItemCategories.ID = "& Category & ") AND (Invoices.IssuedDate >= N'"& FromDate & "') AND (Invoices.IssuedDate <= N'"& ToDate & "') " & otherCriteria & " GROUP BY Invoices.IsReverse, InvoiceItems.ID, InvoiceItems.Name) DRV"
135				mySQL="SELECT InvoiceItems.ID, InvoiceItems.Name, SUM(InvoiceLines.Qtty * InvoiceLines.Sets * ROUND(InvoiceLines.Length * InvoiceLines.Width / 630 + .49, 0)) AS A4Qtty, SUM(InvoiceLines.AppQtty) AS SumAppQtty, SUM(CONVERT(bigint,InvoiceLines.Price)) AS SumPrice, SUM(InvoiceLines.Discount) AS SumDiscount, SUM(InvoiceLines.Reverse) AS SumReverse, SUM(InvoiceLines.Vat) AS SumVat , Invoices.IsReverse, MAX(InvoiceItemCategories.Name) as CategoryName FROM InvoiceItemCategories INNER JOIN InvoiceItemCategoryRelations ON InvoiceItemCategories.ID = InvoiceItemCategoryRelations.InvoiceItemCategory INNER JOIN InvoiceItems ON InvoiceItemCategoryRelations.InvoiceItem = InvoiceItems.ID INNER JOIN InvoiceLines ON InvoiceItems.ID = InvoiceLines.Item INNER JOIN Invoices ON InvoiceLines.Invoice = Invoices.ID WHERE (Invoices.Voided = 0) AND (Invoices.Issued = 1) AND (InvoiceItemCategories.ID = "& Category & ") AND (Invoices.IssuedDate >= N'"& FromDate & "') AND (Invoices.IssuedDate <= N'"& ToDate & "') " & otherCriteria & " GROUP BY Invoices.IsReverse, InvoiceItems.ID, InvoiceItems.Name ORDER BY InvoiceItems.ID,Invoices.IsReverse"
136			end if
137'response.write mySQL
138'response.end
139%>
140			</SELECT>
141		</td>
142		<td align=left>�����</td>
143		<td><INPUT TYPE="text" NAME="ResultsInPage" style="width:75px;direction:LTR;text-align:right;" maxlength=5 value="<%=ResultsInPage%>"></td>
144	</tr>
145	<tr>
146		<td align=left>��������</td>
147		<td align=left>
148			<SELECT NAME="isA" style="width:150px;">
149				<option value="0" <%if isA=0 then response.write "selected " %>>��� </option>
150				<option value="1" <%if isA=1 then response.write "selected " %>>�� ��� ���</option>
151				<option value="2" <%if isA=2 then response.write "selected " %>>���� ��� ���</option>
152			</SELECT>
153		</td>
154	</tr>
155<%
156	if true Or Auth("C" , 6) then '����� ���� ��� ���� ����� �������
157%>
158	<tr>
159		<td align=left>CSR</td>
160		<td align=left>
161			<SELECT NAME="SalesAction" style="width:100px;">
162				<option value="1" <%if SalesAction=1 then response.write "selected " %>>��� �����</option>
163				<option value="2" <%if SalesAction=2 then response.write "selected " %>>����� �����</option>
164				<option value="3" <%if SalesAction=3 then response.write "selected " %>>���� �����</option>
165				<option value="0" <%if SalesAction=0 then response.write "selected " %>>������ �� �����</option>
166			</SELECT>
167		</td>
168		<td align=left>
169			<SELECT NAME="SalesPerson" style="width:100px;">
170				<option value="0" <%if SalesPerson=0 then response.write "selected " %>>��� </option>
171<%
172			set RS=Conn.Execute ("SELECT * FROM Users WHERE ID<>0 ORDER BY RealName") 
173
174			Do while not RS.eof
175%>
176				<option value="<%=RS("ID")%>" <%if SalesPerson=RS("ID") then response.write "selected " %>><%=RS("RealName")%></option>
177<%
178				RS.moveNext
179			Loop
180			RS.close
181%>
182			</SELECT>
183		</td>
184	</tr>
185<%
186	end if
187%>
188	<tr>
189		<td colspan=4 align=center><INPUT Class="GenButton" style="border:1 solid black;" TYPE="submit" value=" ����� "></td>
190	</tr>
191	</table>
192	</FORM>
193<br>
194<%
195
196	Set RS1=Conn.Execute(mySQL_Sum)
197	if NOT RS1.eof then
198
199		CNT =			cdbl(RS1("CNT"))
200		if CNT >0 then
201			A4Qtty =		cdbl(RS1("A4Qtty"))
202			SumAppQtty =	cdbl(RS1("SumAppQtty"))
203			SumPrice =		cdbl(RS1("SumPrice"))
204			SumDiscount =	cdbl(RS1("SumDiscount"))
205			SumReverse =	cdbl(RS1("SumReverse"))
206			SumVat =		cdbl(RS1("SumVat"))
207		else
208			A4Qtty =		0
209			SumAppQtty =	0
210			SumPrice =		0
211			SumDiscount =	0
212			SumReverse =	0
213			SumVat =		0
214		end if
215		SumSales =	SumPrice - SumDiscount - SumReverse + SumVat
216%>
217		<table class="CustTable" cellspacing='1' style='width:90%;' align='center'>
218			<tr>
219				<td colspan="8" class="CusTableHeader" style="text-align:right;height:35;">��� ���� ��� ���� <%=isAName %> &nbsp; <%=GroupName%>  (<%=pageTitle%>)</td>
220			</tr>
221			<tr>
222				<td class="CusTD3">#</td>
223				<td class="CusTD3" style="direction:RTL;">����� A4</td>
224				<td class="CusTD3">����� ����</td>
225				<td class="CusTD3">��� ����</td>
226				<td class="CusTD3">��� �����</td>
227				<td class="CusTD3">��� �ѐ��</td>
228				<td class""CusTD3">��� ������</td>
229				<td class="CusTD3">��� ����</td>
230			</tr>
231			<tr bgcolor="white">
232				<TD dir=LTR align=right><%=Separate(CNT)%></TD>
233				<TD dir=LTR align=right><%=Separate(A4Qtty)%></TD>
234				<TD dir=LTR align=right><%=Separate(SumAppQtty)%></TD>
235				<TD dir=LTR align=right><%=Separate(SumPrice)%></TD>
236				<TD dir=LTR align=right><%=Separate(SumDiscount)%></TD>
237				<TD dir=LTR align=right><%=Separate(SumReverse)%></TD>
238				<TD dir=LTR align=right><%=Separate(SumVat)%></TD>
239				<TD dir=LTR align=right><%=Separate(SumSales)%></TD>
240			</tr>
241		</table>
242		<br><br>
243<%
244	end if
245	RS1.close
246%>
247	<table class="CustTable" cellspacing='1' style='width:90%;' align='center'>
248		<tr>
249			<td colspan="8" class="CusTableHeader" style="text-align:right;height:35;">���� ��� ���� <%=isAName %>&nbsp;<%=GroupName%>  (<%=pageTitle%>)</td>
250		</tr>
251<%
252		Set RS1 = Server.CreateObject("ADODB.Recordset")
253
254		PageSize = ResultsInPage
255		RS1.PageSize = PageSize 
256
257		RS1.CursorLocation=3 'in ADOVBS_INC adUseClient=3
258		RS1.Open mySQL ,Conn,3
259		TotalPages = RS1.PageCount
260
261		CurrentPage=1
262
263		if isnumeric(Request.QueryString("p")) then
264			pp=clng(Request.QueryString("p"))
265			if pp <= TotalPages AND pp > 0 then
266				CurrentPage = pp
267			end if
268		end if
269
270		if not RS1.eof then
271			RS1.AbsolutePage=CurrentPage
272		end if
273
274
275		if RS1.eof then
276%>			<tr>
277				<td colspan="8" class="CusTD3" style='direction:RTL;'>��� ����� ���� ���.</td>
278			</tr>
279<%		else
280%>			<tr>
281				<td class="CusTD3">#</td>
282				<td class="CusTD3" style='direction:RTL;'>��� ����</td>
283				<td class="CusTD3" style="direction:RTL;">����� A4</td>
284				<td class="CusTD3">����� ����</td>
285				<td class="CusTD3">��� ����</td>
286				<td class="CusTD3">��� �����</td>
287				<td class="CusTD3">��� �ѐ��</td>
288				<td class="CusTD3">��� ������</td>
289				<td class="CusTD3">��� ����</td>
290				<td class="CusTD3">����</td>
291			</tr>
292			<SCRIPT LANGUAGE="JavaScript">
293			<!--
294			function drill(item) {
295				window.open("?act=showItemDetails&Item="+item+"&FromDate=<%=FromDate%>&ToDate=<%=ToDate%>&isA=<%=isA%>&SalesAction=<%=SalesAction%>&SalesPerson=<%=SalesPerson%>");
296			}
297			//-->
298			</SCRIPT>
299<%			tmpCounter=(CurrentPage - 1) * PageSize
300
301			Do while NOT RS1.eof AND (RS1.AbsolutePage = CurrentPage)
302				tmpCounter = tmpCounter + 1
303
304				if tmpCounter mod 2 = 1 then
305					tmpColor="#FFFFFF"
306					tmpColor2="#FFFFBB"
307				Else
308					tmpColor="#DDDDDD"
309					tmpColor2="#EEEEBB"
310				End if 
311
312				if RS1("IsReverse") then
313					
314					A4Qtty =		-cdbl(RS1("A4Qtty"))
315					SumAppQtty =	-cdbl(RS1("SumAppQtty"))
316					SumPrice =		-cdbl(RS1("SumPrice"))
317					SumDiscount =	-cdbl(RS1("SumDiscount"))
318					SumReverse =	-cdbl(RS1("SumReverse"))
319					SumVat =		-cdbl(RS1("SumVat"))
320
321					tmpColor="#FF9966"
322				else
323					A4Qtty =		cdbl(RS1("A4Qtty"))
324					SumAppQtty =	cdbl(RS1("SumAppQtty"))
325					SumPrice =		cdbl(RS1("SumPrice"))
326					SumDiscount =	cdbl(RS1("SumDiscount"))
327					SumReverse =	cdbl(RS1("SumReverse"))
328					SumVat =		cdbl(RS1("SumVat"))
329				end if
330
331				SumSales =	SumPrice - SumDiscount - SumReverse + SumVat
332
333%>
334				<TR bgcolor="<%=tmpColor%>" style="cursor: hand; height:30px;" onMouseOver="this.style.backgroundColor='<%=tmpColor2%>'" onMouseOut="this.style.backgroundColor='<%=tmpColor%>'" onclick="drill('<%=RS1("ID")%>');">
335					<TD><%=tmpCounter%></TD>
336					<TD><%=RS1("Name")%></TD>
337					<TD dir=LTR align=right><%=Separate(A4Qtty)%></TD>
338					<TD dir=LTR align=right><%=Separate(SumAppQtty)%></TD>
339					<TD dir=LTR align=right><%=Separate(SumPrice)%></TD>
340					<TD dir=LTR align=right><%=Separate(SumDiscount)%></TD>
341					<TD dir=LTR align=right><%=Separate(SumReverse)%></TD>
342					<TD dir=LTR align=right><%=Separate(SumVat)%></TD>
343					<TD dir=LTR align=right><%=Separate(SumSales)%></TD>
344					<td dir=LTR align=center><%=RS1("CategoryName")%></td>
345				</TR>
346<%				RS1.moveNext
347			Loop
348
349			if ToDate="9999/99/99" then ToDate="" 
350
351			if TotalPages > 1 then
352				pageCols=20
353%>			
354				<TR>
355					<TD bgcolor='#33AACC' height="30" colspan="8">
356					<table width=100% cellspacing=0 style="cursor:hand;color:#444444">
357					<tr>
358						<td style="height:25;border-bottom:1 solid black;" colspan=<%=pagecols%>>
359							<b>���� <%=CurrentPage%> �� <%=TotalPages%></b>
360							&nbsp;&nbsp;<a href="javascript:go2Page(<%=CurrentPage+1%>);">���� ��� &gt;</a>
361						</td>
362					</tr>
363					<tr>
364<%					for i=1 to TotalPages 
365						if i = CurrentPage then 
366%>							<td style="color:black;"><b>[<%=i%>]</b></td>
367<%						else
368%>							<td onclick="go2Page(<%=i%>);"><%=i%></td>
369<%						end if 
370						if i mod pageCols = 0 then response.write "</tr><tr>" 
371					next 
372
373%>					</tr>
374					</table>
375
376					<SCRIPT LANGUAGE="JavaScript">
377					<!--
378					function go2Page(p) {
379						window.location="?act=show&ResultsInPage=<%=ResultsInPage%>&p="+p+"&FromDate=<%=FromDate%>&ToDate=<%=ToDate%>&Category=<%=Category%>";
380					}
381					//-->
382					</SCRIPT>
383
384					</TD>
385				</TR>
386<%			end if
387		end if
388		RS1.close
389		Set RS1 = Nothing
390%>
391	</table>
392	<br>
393<%
394elseif request("act")="showItemDetails" then
395	ON ERROR RESUME NEXT
396
397		Item =			clng(request("Item"))
398
399		FromDate =		sqlSafe(request("FromDate"))
400		ToDate =		sqlSafe(request("ToDate"))
401
402		isA =			cint(request("isA"))
403
404		ResultsInPage =	50
405		
406		if ToDate = "" then ToDate = "9999/99/99"
407
408		if FromDate="" AND ToDate="9999/99/99" then
409			pageTitle="�� ���� ����"
410		elseif FromDate="" then
411			pageTitle="�� ����� �� ����� " & replace (ToDate,"/",".")
412		elseif ToDate="9999/99/99" then
413			pageTitle="�� ����� "& replace (FromDate,"/",".") & " �� ����� "
414		else
415			pageTitle="�� ����� "& replace (FromDate,"/",".") & " �� ����� " & replace (ToDate,"/",".")
416		end if
417	
418		SalesAction =	request("SalesAction")
419		SalesPerson =	request("SalesPerson")
420
421		if SalesAction="" then 
422			SalesAction = 2 '�����
423		else
424			SalesAction = cint(SalesAction)
425		end if
426		if SalesPerson="" then 
427			SalesPerson = 0 '���
428		else
429			SalesPerson = cint(SalesPerson)
430		end if
431
432		if Err.Number<>0 then
433			Err.clear
434
435			conn.close
436			response.redirect "OtherReports.asp?errMsg=" & Server.URLEncode("��� �� �����.")
437		end if
438	ON ERROR GOTO 0
439
440	mySQL= "SELECT Name FROM InvoiceItems WHERE (ID = "& Item & ")"
441	Set RS1 = Conn.Execute(mySQL)
442	if RS1.eof then
443		conn.close
444		response.redirect "OtherReports.asp?errMsg=" & Server.URLEncode("���� ���� ���� �����.")
445	else
446		ItemName=RS1("Name")
447	end if
448	RS1.close
449	Set RS1 = Nothing
450	otherCriteria = ""
451	if isA = 1 then
452		isAName = "�� ��� ���"
453		otherCriteria = " AND (Invoices.isA=1) "
454	elseif isA = 2 then
455		isAName = "���� ��� ���"
456		otherCriteria = " AND (Invoices.isA=0) "
457	end if
458
459	if Auth("C" , 6) then '����� ���� ��� ���� ����� �������
460		if SalesPerson <> 0 then
461			select case SalesAction
462			case 0:
463				otherCriteria = otherCriteria & " AND ((Invoices.CreatedBy=" & SalesPerson & ") OR (Invoices.ApprovedBy=" & SalesPerson & ") OR (Invoices.IssuedBy=" & SalesPerson & "))"
464			case 1:
465				otherCriteria = otherCriteria & " AND (Invoices.CreatedBy=" & SalesPerson & ")"
466			case 2:
467				otherCriteria = otherCriteria & " AND (Invoices.ApprovedBy=" & SalesPerson & ")"
468			case 3:
469				otherCriteria = otherCriteria & " AND (Invoices.IssuedBy=" & SalesPerson & ")"
470			end select
471		end if
472	end if
473
474
475%>
476<br>
477	<table class="CustTable" cellspacing='1' style='width:90%;' align='center'>
478		<tr>
479			<td colspan="10" class="CusTableHeader" style="text-align:right;height:35;">������   ��� <%=isAName%> ����  '<%=ItemName%>' (<%=pageTitle%>)</td>
480		</tr>
481<%
482		mySQL="SELECT Invoices.ID, Invoices.IssuedDate, Invoices.TotalReceivable, Invoices.IsReverse, Accounts.AccountTitle, SUM(InvoiceLines.Qtty * InvoiceLines.Sets * ROUND(InvoiceLines.Length * InvoiceLines.Width / 630 + .49, 0)) AS A4Qtty, SUM(InvoiceLines.AppQtty) AS SumAppQtty, SUM(InvoiceLines.Price - InvoiceLines.Discount - InvoiceLines.Reverse + InvoiceLines.Vat) AS SumReceivable, dbo.isInvoiceHasPaper(Invoices.ID) AS isPaper, dbo.isInvoiceHasHavale(Invoices.ID) AS isHavale FROM Invoices INNER JOIN InvoiceLines ON Invoices.ID = InvoiceLines.Invoice INNER JOIN Accounts ON Invoices.Customer = Accounts.ID WHERE (InvoiceLines.Item = "& Item & ") AND (Invoices.Voided = 0) AND (Invoices.Issued = 1) AND (Invoices.IssuedDate >= N'" & FromDate & "') AND (Invoices.IssuedDate <= N'"& ToDate & "') " & otherCriteria & " GROUP BY Accounts.AccountTitle, Invoices.ID, Invoices.TotalReceivable, Invoices.IsReverse, Invoices.IssuedDate, Invoices.IssuedDate ORDER BY Invoices.IssuedDate DESC"
483'response.write mySQL
484		Set RS1 = Server.CreateObject("ADODB.Recordset")
485
486		PageSize = ResultsInPage
487		RS1.PageSize = PageSize 
488
489		RS1.CursorLocation=3 'in ADOVBS_INC adUseClient=3
490		RS1.Open mySQL ,Conn,3
491		TotalPages = RS1.PageCount
492
493		CurrentPage=1
494
495		if isnumeric(Request.QueryString("p")) then
496			pp=clng(Request.QueryString("p"))
497			if pp <= TotalPages AND pp > 0 then
498				CurrentPage = pp
499			end if
500		end if
501
502		if not RS1.eof then
503			RS1.AbsolutePage=CurrentPage
504		end if
505
506
507		if RS1.eof then
508%>			<tr>
509				<td colspan="10" class="CusTD3" style='direction:RTL;'>��� ������� ���� ���.</td>
510			</tr>
511<%		else
512%>			<tr>
513				<td class="CusTD3">#</td>
514				<td class="CusTD3" style="direction:RTL;"># ������</td>
515				<td class="CusTD3">����� ����</td>
516				<td class="CusTD3">����� ����</td>
517				<td class="CusTD3" style="direction:RTL;">����� A4</td>
518				<td class="CusTD3">����� ����</td>
519				<td class="CusTD3">���� ����</td>
520				<td class="CusTD3">���� ������</td>
521				<td class="CusTD3" width="5px">I</td>
522				<td class="CusTD3" width="5px">II</td>
523			</tr>
524			<SCRIPT LANGUAGE="JavaScript">
525			<!--
526			function drill(inv) {
527				window.open('../AR/AccountReport.asp?act=showInvoice&invoice='+inv);
528			}
529			//-->
530			</SCRIPT>
531<%			tmpCounter=(CurrentPage - 1) * PageSize
532
533			Do while NOT RS1.eof AND (RS1.AbsolutePage = CurrentPage)
534				tmpCounter = tmpCounter + 1
535
536				if tmpCounter mod 2 = 1 then
537					tmpColor="#FFFFFF"
538					tmpColor2="#FFFFBB"
539				Else
540					tmpColor="#DDDDDD"
541					tmpColor2="#EEEEBB"
542				End if 
543
544				if RS1("IsReverse") then
545					A4Qtty =			-cdbl(RS1("A4Qtty"))
546					SumAppQtty =		-cdbl(RS1("SumAppQtty"))
547					SumReceivable =		-cdbl(RS1("SumReceivable"))
548					TotalReceivable =	-cdbl(RS1("TotalReceivable"))
549
550					tmpColor="#FF9966"
551				else
552					A4Qtty =			cdbl(RS1("A4Qtty"))
553					SumAppQtty =		cdbl(RS1("SumAppQtty"))
554					SumReceivable =		cdbl(RS1("SumReceivable"))
555					TotalReceivable =	cdbl(RS1("TotalReceivable"))
556				end if
557
558%>
559				<TR bgcolor="<%=tmpColor%>" style="cursor: hand; height:30px;" onMouseOver="this.style.backgroundColor='<%=tmpColor2%>'" onMouseOut="this.style.backgroundColor='<%=tmpColor%>'" onclick="drill('<%=RS1("ID")%>');">
560					<TD><%=tmpCounter%></TD>
561					<TD><%=RS1("ID")%></TD>
562					<TD dir=LTR align=right><%=RS1("IssuedDate")%></TD>
563					<TD><%=RS1("AccountTitle")%></TD>
564					<TD dir=LTR align=right><%=Separate(A4Qtty)%></TD>
565
566					<TD dir=LTR align=right><%=Separate(SumAppQtty)%></TD>
567					<TD dir=LTR align=right><%=Separate(SumReceivable)%></TD>
568					<TD dir=LTR align=right><%=Separate(TotalReceivable)%></TD>
569					<td dir="ltr" align="center"><%if cbool(RS1("isPaper")) then response.write("*")%></td>
570					<td dir="ltr" align="center"><%if cbool(RS1("isHavale")) then response.write("*")%></td>
571				</TR>
572<%				RS1.moveNext
573			Loop
574
575			if ToDate="9999/99/99" then ToDate="" 
576
577			if TotalPages > 1 then
578				pageCols=20
579%>			
580				<TR class="RepTableTitle">
581					<TD bgcolor='#33AACC' height="30" colspan="10">
582					<table width=100% cellspacing=0 style="cursor:hand;color:#444444">
583					<tr>
584						<td style="height:25;border-bottom:1 solid black;" colspan=<%=pagecols%>>
585							<b>���� <%=CurrentPage%> �� <%=TotalPages%></b>
586							&nbsp;&nbsp;<a href="javascript:go2Page(<%=CurrentPage+1%>);">���� ��� &gt;</a>
587						</td>
588					</tr>
589					<tr>
590<%					for i=1 to TotalPages 
591						if i = CurrentPage then 
592%>							<td style="color:black;"><b>[<%=i%>]</b></td>
593<%						else
594%>							<td onclick="go2Page(<%=i%>);"><%=i%></td>
595<%						end if 
596						if i mod pageCols = 0 then response.write "</tr><tr>" 
597					next 
598
599%>					</tr>
600					</table>
601<div>
602I: �ǘ��� ���� �&#1740;�� ����
603</div>
604<div>
605II: �ǘ��� ���� ����� ����
606</div>
607					<SCRIPT LANGUAGE="JavaScript">
608					<!--
609					function go2Page(p) {
610						window.location="?act=showItemDetails&Item=<%=Item%>&ResultsInPage=<%=ResultsInPage%>&p="+p+"&FromDate=<%=FromDate%>&ToDate=<%=ToDate%>&isA=<%=isA%>&SalesAction=<%=SalesAction%>&SalesPerson=<%=SalesPerson%>";
611					}
612					//-->
613					</SCRIPT>
614
615					</TD>
616				</TR>
617<%			end if
618		end if
619		RS1.close
620		Set RS1 = Nothing
621%>
622	</table>
623	<br>
624<%
625end if%>
626<!--#include file="tah.asp" -->