PageRenderTime 67ms CodeModel.GetById 36ms app.highlight 13ms RepoModel.GetById 2ms app.codeStats 1ms

/beta/AR/Rep_InvoiceItems.asp

http://github.com/khaneh/Orders
ASP | 646 lines | 572 code | 66 blank | 8 comment | 55 complexity | 880d41bfdb246d02c72eef1e7b7e711d 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		if auth("C","B") then Category = 8
 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				'mySQL="SELECT InvoiceItemCategories.ID, InvoiceItemCategories.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, 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 BETWEEN N'"& FromDate & "' AND  N'"& ToDate & "') " & otherCriteria & " GROUP BY InvoiceItemCategories.ID, InvoiceItemCategories.Name ORDER BY InvoiceItemCategories.ID "
134				mySQL="SELECT InvoiceItemCategories.ID, InvoiceItemCategories.Name, ISNULL(drv.A4Qtty,0) as A4Qtty, ISNULL(drv.SumAppQtty,0) as SumAppQtty, ISNULL(drv.SumPrice,0) as SumPrice, ISNULL(drv.SumDiscount,0) as SumDiscount, ISNULL(drv.SumReverse,0) as SumReverse, ISNULL(drv.SumVat,0) as SumVat, ISNULL(drv.CategoryName,'-') as CategoryName FROM InvoiceItemCategories LEFT OUTER JOIN (SELECT InvoiceItemCategories.ID, 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, 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 BETWEEN N'"& FromDate & "' AND  N'"& ToDate & "') " & otherCriteria & " GROUP BY InvoiceItemCategories.ID) drv ON InvoiceItemCategories.ID = drv.ID ORDER BY InvoiceItemCategories.ID"
135			else
136				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"
137				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"
138			end if
139
140%>
141			</SELECT>
142		</td>
143		<td align=left>�����</td>
144		<td><INPUT TYPE="text" NAME="ResultsInPage" style="width:75px;direction:LTR;text-align:right;" maxlength=5 value="<%=ResultsInPage%>"></td>
145	</tr>
146	<tr>
147		<td align=left>��������</td>
148		<td align=left>
149			<SELECT NAME="isA" style="width:150px;">
150				<option value="0" <%if isA=0 then response.write "selected " %>>��� </option>
151				<option value="1" <%if isA=1 then response.write "selected " %>>�� ��� ���</option>
152				<option value="2" <%if isA=2 then response.write "selected " %>>���� ��� ���</option>
153			</SELECT>
154		</td>
155	</tr>
156<%
157'response.write mySQL
158'response.end
159	if true Or Auth("C" , 6) then '����� ���� ��� ���� ����� �������
160%>
161	<tr>
162		<td align=left>CSR</td>
163		<td align=left>
164			<SELECT NAME="SalesAction" style="width:100px;">
165				<option value="1" <%if SalesAction=1 then response.write "selected " %>>��� �����</option>
166				<option value="2" <%if SalesAction=2 then response.write "selected " %>>����� �����</option>
167				<option value="3" <%if SalesAction=3 then response.write "selected " %>>���� �����</option>
168				<option value="0" <%if SalesAction=0 then response.write "selected " %>>������ �� �����</option>
169			</SELECT>
170		</td>
171		<td align=left>
172			<SELECT NAME="SalesPerson" style="width:100px;">
173				<option value="0" <%if SalesPerson=0 then response.write "selected " %>>��� </option>
174<%
175			set RS=Conn.Execute ("SELECT * FROM Users WHERE ID<>0 ORDER BY RealName") 
176
177			Do while not RS.eof
178%>
179				<option value="<%=RS("ID")%>" <%if SalesPerson=RS("ID") then response.write "selected " %>><%=RS("RealName")%></option>
180<%
181				RS.moveNext
182			Loop
183			RS.close
184%>
185			</SELECT>
186		</td>
187	</tr>
188<%
189	end if
190%>
191	<tr>
192		<td colspan=4 align=center><INPUT Class="GenButton" style="border:1 solid black;" TYPE="submit" value=" ����� "></td>
193	</tr>
194	</table>
195	</FORM>
196<br>
197<%
198'response.write mySQL_Sum
199	Set RS1=Conn.Execute(mySQL_Sum)
200	if NOT RS1.eof then
201
202		CNT =			cdbl(RS1("CNT"))
203		if CNT >0 then
204			A4Qtty =		cdbl(RS1("A4Qtty"))
205			SumAppQtty =	cdbl(RS1("SumAppQtty"))
206			SumPrice =		cdbl(RS1("SumPrice"))
207			SumDiscount =	cdbl(RS1("SumDiscount"))
208			SumReverse =	cdbl(RS1("SumReverse"))
209			SumVat =		cdbl(RS1("SumVat"))
210		else
211			A4Qtty =		0
212			SumAppQtty =	0
213			SumPrice =		0
214			SumDiscount =	0
215			SumReverse =	0
216			SumVat =		0
217		end if
218		SumSales =	SumPrice - SumDiscount - SumReverse '+ SumVat
219%>
220		<table class="CustTable" cellspacing='1' style='width:90%;' align='center'>
221			<tr>
222				<td colspan="8" class="CusTableHeader" style="text-align:right;height:35;">��� ���� ��� ���� <%=isAName %> &nbsp; <%=GroupName%>  (<%=pageTitle%>)</td>
223			</tr>
224			<tr>
225				<td class="CusTD3">#</td>
226				<td class="CusTD3" style="direction:RTL;">����� A4</td>
227				<td class="CusTD3">����� ����</td>
228				<td class="CusTD3">��� ����</td>
229				<td class="CusTD3">��� �����</td>
230				<td class="CusTD3">��� �ѐ��</td>
231				<td class="CusTD3">��� ������</td>
232				<td class="CusTD3">��� ���� ����</td>
233			</tr>
234			<tr bgcolor="white">
235				<TD dir=LTR align=right><%=Separate(CNT)%></TD>
236				<TD dir=LTR align=right><%=Separate(A4Qtty)%></TD>
237				<TD dir=LTR align=right><%=Separate(SumAppQtty)%></TD>
238				<TD dir=LTR align=right><%=Separate(SumPrice)%></TD>
239				<TD dir=LTR align=right><%=Separate(SumDiscount)%></TD>
240				<TD dir=LTR align=right><%=Separate(SumReverse)%></TD>
241				<TD dir=LTR align=right><%=Separate(SumVat)%></TD>
242				<TD dir=LTR align=right><%=Separate(SumSales)%></TD>
243			</tr>
244		</table>
245		<br><br>
246<%
247	end if
248	RS1.close
249%>
250	<table class="CustTable" cellspacing='1' style='width:90%;' align='center'>
251		<tr>
252			<td colspan="10" class="CusTableHeader" style="text-align:right;height:35;">���� ��� ���� <%=isAName %>&nbsp;<%=GroupName%>  (<%=pageTitle%>)</td>
253		</tr>
254<%
255		Set RS1 = Server.CreateObject("ADODB.Recordset")
256
257		PageSize = ResultsInPage
258		RS1.PageSize = PageSize 
259
260		RS1.CursorLocation=3 'in ADOVBS_INC adUseClient=3
261		RS1.Open mySQL ,Conn,3
262		TotalPages = RS1.PageCount
263
264		CurrentPage=1
265
266		if isnumeric(Request.QueryString("p")) then
267			pp=clng(Request.QueryString("p"))
268			if pp <= TotalPages AND pp > 0 then
269				CurrentPage = pp
270			end if
271		end if
272
273		if not RS1.eof then
274			RS1.AbsolutePage=CurrentPage
275		end if
276
277
278		if RS1.eof then
279%>			<tr>
280				<td colspan="10" class="CusTD3" style='direction:RTL;'>��� ����� ���� ���.</td>
281			</tr>
282<%		else
283%>			<tr>
284				<td class="CusTD3">#</td>
285				<td class="CusTD3" style='direction:RTL;'>��� ����</td>
286				<td class="CusTD3" style="direction:RTL;">����� A4</td>
287				<td class="CusTD3">����� ����</td>
288				<td class="CusTD3">��� ����</td>
289				<td class="CusTD3">��� �����</td>
290				<td class="CusTD3">��� �ѐ��</td>
291				<td class="CusTD3">��� ������</td>
292				<td class="CusTD3">��� ���� ����</td>
293				<td class="CusTD3">����</td>
294			</tr>
295			<SCRIPT LANGUAGE="JavaScript">
296			<!--
297			function drill(item) {
298				<%if Category=0 then 
299					response.write "window.open('?act=show&category='+item+'&FromDate="& FromDate & "&ToDate=" & ToDate & "&isA=" & isA & "&SalesAction=" & SalesAction & "&SalesPerson=" & SalesPerson & "&ResultsInPage="&ResultsInPage&"');"
300				else
301					response.write "window.open('?act=showItemDetails&Item='+item+'&FromDate="& FromDate & "&ToDate=" & ToDate & "&isA=" & isA & "&SalesAction=" & SalesAction & "&SalesPerson=" & SalesPerson & "');"
302				end if
303				%>
304				
305			}
306			function drillGroup(cat) {
307				window.location('../AR/Rep_InvoiceItems.asp?act=show&category='+cat+"&FromDate=<%=FromDate%>&ToDate=<%=ToDate%>&isA=<%=isA%>&SalesAction=<%=SalesAction%>&SalesPerson=<%=SalesPerson%>");
308			}
309			//-->
310			</SCRIPT>
311<%			tmpCounter=(CurrentPage - 1) * PageSize
312
313			Do while NOT RS1.eof AND (RS1.AbsolutePage = CurrentPage)
314				tmpCounter = tmpCounter + 1
315
316				if tmpCounter mod 2 = 1 then
317					tmpColor="#FFFFFF"
318					tmpColor2="#FFFFBB"
319				Else
320					tmpColor="#DDDDDD"
321					tmpColor2="#EEEEBB"
322				End if 
323				if Category=0 then 
324					A4Qtty =		cdbl(RS1("A4Qtty"))
325					SumAppQtty =	cdbl(RS1("SumAppQtty"))
326					SumPrice =		cdbl(RS1("SumPrice"))
327					SumDiscount =	cdbl(RS1("SumDiscount"))
328					SumReverse =	cdbl(RS1("SumReverse"))
329					SumVat =		cdbl(RS1("SumVat"))
330				else
331					if RS1("IsReverse") then
332					
333						A4Qtty =		-cdbl(RS1("A4Qtty"))
334						SumAppQtty =	-cdbl(RS1("SumAppQtty"))
335						SumPrice =		-cdbl(RS1("SumPrice"))
336						SumDiscount =	-cdbl(RS1("SumDiscount"))
337						SumReverse =	-cdbl(RS1("SumReverse"))
338						SumVat =		-cdbl(RS1("SumVat"))
339
340						tmpColor="#FF9966"
341					else
342						A4Qtty =		cdbl(RS1("A4Qtty"))
343						SumAppQtty =	cdbl(RS1("SumAppQtty"))
344						SumPrice =		cdbl(RS1("SumPrice"))
345						SumDiscount =	cdbl(RS1("SumDiscount"))
346						SumReverse =	cdbl(RS1("SumReverse"))
347						SumVat =		cdbl(RS1("SumVat"))
348					end if
349				end if
350				SumSales =	SumPrice - SumDiscount - SumReverse '+ SumVat
351
352%>
353				<TR bgcolor="<%=tmpColor%>">
354					<TD><%=tmpCounter%></TD>
355					<TD style="cursor: hand; height:30px;" onMouseOver="this.style.backgroundColor='<%=tmpColor2%>'" onMouseOut="this.style.backgroundColor='<%=tmpColor%>'" onclick="drill('<%=RS1("ID")%>');"><%=RS1("Name")%></TD>
356					<TD dir=LTR align=right><%=Separate(A4Qtty)%></TD>
357					<TD dir=LTR align=right><%=Separate(SumAppQtty)%></TD>
358					<TD dir=LTR align=right><%=Separate(SumPrice)%></TD>
359					<TD dir=LTR align=right><%=Separate(SumDiscount)%></TD>
360					<TD dir=LTR align=right><a href="rep_reversSales.asp?act=show&fromDate=<%=escape(fromDate)%>&toDate=<%=escape(toDate)%>&<%if Category=0 then response.write "cat" else response.write "item"%>=<%=rs1("id")%>"><%=Separate(SumReverse)%></a></TD>
361					<TD dir=LTR align=right><%=Separate(SumVat)%></TD>
362					<TD dir=LTR align=right><%=Separate(SumSales)%></TD>
363					<td dir=LTR align=center><%=RS1("CategoryName")%></td>
364				</TR>
365<%				RS1.moveNext
366			Loop
367
368			if ToDate="9999/99/99" then ToDate="" 
369
370			if TotalPages > 1 then
371				pageCols=20
372%>			
373				<TR>
374					<TD bgcolor='#33AACC' height="30" colspan="8">
375					<table width=100% cellspacing=0 style="cursor:hand;color:#444444">
376					<tr>
377						<td style="height:25;border-bottom:1 solid black;" colspan=<%=pagecols%>>
378							<b>���� <%=CurrentPage%> �� <%=TotalPages%></b>
379							&nbsp;&nbsp;<a href="javascript:go2Page(<%=CurrentPage+1%>);">���� ��� &gt;</a>
380						</td>
381					</tr>
382					<tr>
383<%					for i=1 to TotalPages 
384						if i = CurrentPage then 
385%>							<td style="color:black;"><b>[<%=i%>]</b></td>
386<%						else
387%>							<td onclick="go2Page(<%=i%>);"><%=i%></td>
388<%						end if 
389						if i mod pageCols = 0 then response.write "</tr><tr>" 
390					next 
391
392%>					</tr>
393					</table>
394
395					<SCRIPT LANGUAGE="JavaScript">
396					<!--
397					function go2Page(p) {
398						window.location="?act=show&ResultsInPage=<%=ResultsInPage%>&p="+p+"&FromDate=<%=FromDate%>&ToDate=<%=ToDate%>&Category=<%=Category%>";
399					}
400					//-->
401					</SCRIPT>
402
403					</TD>
404				</TR>
405<%			end if
406		end if
407		RS1.close
408		Set RS1 = Nothing
409%>
410	</table>
411	<br>
412<%
413elseif request("act")="showItemDetails" then
414	ON ERROR RESUME NEXT
415
416		Item =			clng(request("Item"))
417
418		FromDate =		sqlSafe(request("FromDate"))
419		ToDate =		sqlSafe(request("ToDate"))
420
421		isA =			cint(request("isA"))
422
423		ResultsInPage =	50
424		
425		if ToDate = "" then ToDate = "9999/99/99"
426
427		if FromDate="" AND ToDate="9999/99/99" then
428			pageTitle="�� ���� ����"
429		elseif FromDate="" then
430			pageTitle="�� ����� �� ����� " & replace (ToDate,"/",".")
431		elseif ToDate="9999/99/99" then
432			pageTitle="�� ����� "& replace (FromDate,"/",".") & " �� ����� "
433		else
434			pageTitle="�� ����� "& replace (FromDate,"/",".") & " �� ����� " & replace (ToDate,"/",".")
435		end if
436	
437		SalesAction =	request("SalesAction")
438		SalesPerson =	request("SalesPerson")
439
440		if SalesAction="" then 
441			SalesAction = 2 '�����
442		else
443			SalesAction = cint(SalesAction)
444		end if
445		if SalesPerson="" then 
446			SalesPerson = 0 '���
447		else
448			SalesPerson = cint(SalesPerson)
449		end if
450
451		if Err.Number<>0 then
452			Err.clear
453
454			conn.close
455			response.redirect "OtherReports.asp?errMsg=" & Server.URLEncode("��� �� �����.")
456		end if
457	ON ERROR GOTO 0
458
459	mySQL= "SELECT Name FROM InvoiceItems WHERE (ID = "& Item & ")"
460	Set RS1 = Conn.Execute(mySQL)
461	if RS1.eof then
462		conn.close
463		response.redirect "OtherReports.asp?errMsg=" & Server.URLEncode("���� ���� ���� �����.")
464	else
465		ItemName=RS1("Name")
466	end if
467	RS1.close
468	Set RS1 = Nothing
469	otherCriteria = ""
470	if isA = 1 then
471		isAName = "�� ��� ���"
472		otherCriteria = " AND (Invoices.isA=1) "
473	elseif isA = 2 then
474		isAName = "���� ��� ���"
475		otherCriteria = " AND (Invoices.isA=0) "
476	end if
477
478	if Auth("C" , 6) then '����� ���� ��� ���� ����� �������
479		if SalesPerson <> 0 then
480			select case SalesAction
481			case 0:
482				otherCriteria = otherCriteria & " AND ((Invoices.CreatedBy=" & SalesPerson & ") OR (Invoices.ApprovedBy=" & SalesPerson & ") OR (Invoices.IssuedBy=" & SalesPerson & "))"
483			case 1:
484				otherCriteria = otherCriteria & " AND (Invoices.CreatedBy=" & SalesPerson & ")"
485			case 2:
486				otherCriteria = otherCriteria & " AND (Invoices.ApprovedBy=" & SalesPerson & ")"
487			case 3:
488				otherCriteria = otherCriteria & " AND (Invoices.IssuedBy=" & SalesPerson & ")"
489			end select
490		end if
491	end if
492
493
494%>
495<br>
496	<table class="CustTable" cellspacing='1' style='width:90%;' align='center'>
497		<tr>
498			<td colspan="10" class="CusTableHeader" style="text-align:right;height:35;">������   ��� <%=isAName%> ����  '<%=ItemName%>' (<%=pageTitle%>)</td>
499		</tr>
500<%
501		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) 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"
502'response.write mySQL
503		Set RS1 = Server.CreateObject("ADODB.Recordset")
504
505		PageSize = ResultsInPage
506		RS1.PageSize = PageSize 
507
508		RS1.CursorLocation=3 'in ADOVBS_INC adUseClient=3
509		RS1.Open mySQL ,Conn,3
510		TotalPages = RS1.PageCount
511
512		CurrentPage=1
513
514		if isnumeric(Request.QueryString("p")) then
515			pp=clng(Request.QueryString("p"))
516			if pp <= TotalPages AND pp > 0 then
517				CurrentPage = pp
518			end if
519		end if
520
521		if not RS1.eof then
522			RS1.AbsolutePage=CurrentPage
523		end if
524
525
526		if RS1.eof then
527%>			<tr>
528				<td colspan="10" class="CusTD3" style='direction:RTL;'>��� ������� ���� ���.</td>
529			</tr>
530<%		else
531%>			<tr>
532				<td class="CusTD3">#</td>
533				<td class="CusTD3" style="direction:RTL;"># ������</td>
534				<td class="CusTD3">����� ����</td>
535				<td class="CusTD3">����� ����</td>
536				<td class="CusTD3" style="direction:RTL;">����� A4</td>
537				<td class="CusTD3">����� ����</td>
538				<td class="CusTD3">���� ���� ����</td>
539				<td class="CusTD3">���� ������</td>
540				<td class="CusTD3" width="5px">I</td>
541				<td class="CusTD3" width="5px">II</td>
542			</tr>
543			<SCRIPT LANGUAGE="JavaScript">
544			<!--
545			function drill(inv) {
546				window.open('../AR/AccountReport.asp?act=showInvoice&invoice='+inv);
547			}
548			
549			//-->
550			</SCRIPT>
551<%			tmpCounter=(CurrentPage - 1) * PageSize
552
553			Do while NOT RS1.eof AND (RS1.AbsolutePage = CurrentPage)
554				tmpCounter = tmpCounter + 1
555
556				if tmpCounter mod 2 = 1 then
557					tmpColor="#FFFFFF"
558					tmpColor2="#FFFFBB"
559				Else
560					tmpColor="#DDDDDD"
561					tmpColor2="#EEEEBB"
562				End if 
563
564				if RS1("IsReverse") then
565					A4Qtty =			-cdbl(RS1("A4Qtty"))
566					SumAppQtty =		-cdbl(RS1("SumAppQtty"))
567					SumReceivable =		-cdbl(RS1("SumReceivable"))
568					TotalReceivable =	-cdbl(RS1("TotalReceivable"))
569
570					tmpColor="#FF9966"
571				else
572					A4Qtty =			cdbl(RS1("A4Qtty"))
573					SumAppQtty =		cdbl(RS1("SumAppQtty"))
574					SumReceivable =		cdbl(RS1("SumReceivable"))
575					TotalReceivable =	cdbl(RS1("TotalReceivable"))
576				end if
577
578%>
579				<TR bgcolor="<%=tmpColor%>" style="cursor: hand; height:30px;" onMouseOver="this.style.backgroundColor='<%=tmpColor2%>'" onMouseOut="this.style.backgroundColor='<%=tmpColor%>'" onclick="drill('<%=RS1("ID")%>');">
580					<TD><%=tmpCounter%></TD>
581					<TD><%=RS1("ID")%></TD>
582					<TD dir=LTR align=right><%=RS1("IssuedDate")%></TD>
583					<TD><%=RS1("AccountTitle")%></TD>
584					<TD dir=LTR align=right><%=Separate(A4Qtty)%></TD>
585
586					<TD dir=LTR align=right><%=Separate(SumAppQtty)%></TD>
587					<TD dir=LTR align=right><%=Separate(SumReceivable)%></TD>
588					<TD dir=LTR align=right><%=Separate(TotalReceivable)%></TD>
589					<td dir="ltr" align="center"><%if cbool(RS1("isPaper")) then response.write("*")%></td>
590					<td dir="ltr" align="center"><%if cbool(RS1("isHavale")) then response.write("*")%></td>
591				</TR>
592<%				RS1.moveNext
593			Loop
594
595			if ToDate="9999/99/99" then ToDate="" 
596
597			if TotalPages > 1 then
598				pageCols=20
599%>			
600				<TR class="RepTableTitle">
601					<TD bgcolor='#33AACC' height="30" colspan="10">
602					<table width=100% cellspacing=0 style="cursor:hand;color:#444444">
603					<tr>
604						<td style="height:25;border-bottom:1 solid black;" colspan=<%=pagecols%>>
605							<b>���� <%=CurrentPage%> �� <%=TotalPages%></b>
606							&nbsp;&nbsp;<a href="javascript:go2Page(<%=CurrentPage+1%>);">���� ��� &gt;</a>
607						</td>
608					</tr>
609					<tr>
610<%					for i=1 to TotalPages 
611						if i = CurrentPage then 
612%>							<td style="color:black;"><b>[<%=i%>]</b></td>
613<%						else
614%>							<td onclick="go2Page(<%=i%>);"><%=i%></td>
615<%						end if 
616						if i mod pageCols = 0 then response.write "</tr><tr>" 
617					next 
618
619%>					</tr>
620					</table>
621<div>
622I: ������ ���� ���� ����
623</div>
624<div>
625II: ������ ���� ����� ����
626</div>
627					<SCRIPT LANGUAGE="JavaScript">
628					<!--
629					function go2Page(p) {
630						window.location="?act=showItemDetails&Item=<%=Item%>&ResultsInPage=<%=ResultsInPage%>&p="+p+"&FromDate=<%=FromDate%>&ToDate=<%=ToDate%>&isA=<%=isA%>&SalesAction=<%=SalesAction%>&SalesPerson=<%=SalesPerson%>";
631					}
632					//-->
633					</SCRIPT>
634
635					</TD>
636				</TR>
637<%			end if
638		end if
639		RS1.close
640		Set RS1 = Nothing
641%>
642	</table>
643	<br>
644<%
645end if%>
646<!--#include file="tah.asp" -->