PageRenderTime 24ms CodeModel.GetById 15ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/beta/AR/Rep_COGS.asp

http://github.com/khaneh/Orders
ASP | 292 lines | 248 code | 39 blank | 5 comment | 28 complexity | 6624b2bb76e594a182c935614af2d39e MD5 | raw file
  1<%@LANGUAGE="VBSCRIPT" CODEPAGE="1256"%><%
  2'Accounting (8)
  3PageTitle="����� ���� ���� ���"
  4SubmenuItem=11
  5if not Auth("C" , 7) 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	.RepTable {font-family:tahoma; font-size:9pt; direction: RTL; }
 13	.RepTable td {border:1pt solid white;vertical-align:top;}
 14	.RepTable a {text-decoration:none; color:#222288;}
 15	.RepTable a:hover {text-decoration:underline;}
 16	.RepTable2 th {font-size:9pt; background-color:#666699;height:25px;}
 17	.RepTable2 input {font-family:tahoma; font-size:9pt; border:1 solid black;}
 18</STYLE>
 19<BR>
 20<%
 21'-----------------------------------------------------------------------------------------------------
 22'----------------------------------------------------------------------------------------- Search Form
 23'-----------------------------------------------------------------------------------------------------
 24if request("act")="MoeenRep" OR request("act")="show" then
 25
 26	ON ERROR RESUME NEXT
 27
 28		ResultsInPage =	cint(request("ResultsInPage"))
 29
 30		FromDate =		sqlSafe(request("FromDate"))
 31		ToDate =		sqlSafe(request("ToDate"))
 32		
 33		if FromDate="" AND ToDate="" then
 34			pageTitle="�� ���� ����"
 35		elseif FromDate="" then
 36			pageTitle="�� ����� �� ����� " & replace (ToDate,"/",".")
 37		elseif ToDate="" then
 38			pageTitle="�� ����� "& replace (FromDate,"/",".") & " �� ����� "
 39		else
 40			pageTitle="�� ����� "& replace (FromDate,"/",".") & " �� ����� " & replace (ToDate,"/",".")
 41		end if
 42	
 43		if ToDate = "" then ToDate = "9999/99/99"
 44		
 45		if Err.Number<>0 then
 46			Err.clear
 47			conn.close
 48			response.redirect "OtherReports.asp?errMsg=" & Server.URLEncode("��� �� �����.")
 49		end if
 50	ON ERROR GOTO 0
 51
 52	Ord=request("Ord")
 53
 54	select case Ord
 55	case "1":
 56		order="Invoices.ID"
 57	case "-1":
 58		order="Invoices.ID DESC"
 59	case "2":
 60		order="AccountTitle"
 61	case "-2":
 62		order="AccountTitle DESC"
 63	case "3":
 64		order="InventoryCost"
 65	case "-3":
 66		order="InventoryCost DESC"
 67	case "4":
 68		order="OutServiceCost"
 69	case "-4":
 70		order="OutServiceCost DESC"
 71	case "5":
 72		order="TotalReceivable"
 73	case "-5":
 74		order="TotalReceivable DESC"
 75	case "6":
 76		order="Margin"
 77	case "-6":
 78		order="Margin DESC"
 79	case else:
 80		order="Invoices.ID"
 81		Ord=1
 82	end select
 83
 84%>
 85	<SCRIPT LANGUAGE="JavaScript">
 86	<!--
 87	if (window.XMLHttpRequest) {
 88				var objHTTP=new XMLHttpRequest();
 89			} else if (window.ActiveXObject) {
 90				var objHTTP = new ActiveXObject("Microsoft.XMLHTTP");
 91			}
 92	var detailPosition=0;
 93	function showDetails(index){
 94		if (detailPosition==0){
 95			index=index+1;
 96		}
 97		else{
 98			COGStbl.removeChild(COGStbl.getElementsByTagName("tr")[detailPosition])
 99		}
100		if (detailPosition < index)
101			index=index-1;
102		
103
104		detailPosition=index+1;
105
106		COGStbl=document.getElementById('COGS').getElementsByTagName("TBODY")[0];
107		inv = COGStbl.getElementsByTagName("tr")[index].getElementsByTagName("td")[0].innerText;
108
109		objHTTP.open('GET','Rep_COGS_mini.asp?id='+inv,false);
110		objHTTP.send()
111
112		newRow=document.createElement("tr");
113		newRow.setAttribute("bgColor", '#f0f0f0');
114
115		tempTD=document.createElement("td");
116		tempTD.colSpan=6;
117		tempTD.setAttribute("align", 'center');
118		tempTD.innerHTML=objHTTP.responseText;
119		newRow.appendChild(tempTD);
120
121		COGStbl.insertBefore(newRow,COGStbl.getElementsByTagName("tr")[detailPosition]);
122
123		return;
124	}
125	//-->
126	</SCRIPT>
127	<TABLE id="COGS" dir=rtl align=center width=640 cellspacing=2 cellpadding=2 style="border:2 solid #330066;">
128<%
129	if ord<0 then
130		style="background-color: #33CC99;"
131		arrow="<br><span style='font-family:webdings'>6 6 6</span>"
132	else
133		style="background-color: #33CC99;"
134		arrow="<br><span style='font-family:webdings'>5 5 5</span>"
135	end if
136%>
137	<TR bgcolor="eeeeee" style="cursor:hand;" title="����� �����">
138		<TD width=50 onclick='go2Page(1,1);' style="<%if abs(ord)=1 then response.write style%>">������			<%if abs(ord)=1 then response.write arrow%></TD>
139		<TD width='*' onclick='go2Page(1,2);' style="<%if abs(ord)=2 then response.write style%>">����� ����		<%if abs(ord)=2 then response.write arrow%></TD>
140		<TD width=70 onclick='go2Page(1,-3);' style="<%if abs(ord)=3 then response.write style%>">����� �����		<%if abs(ord)=3 then response.write arrow%></TD>
141		<TD width=70 onclick='go2Page(1,-4);' style="<%if abs(ord)=4 then response.write style%>">����� ������	<%if abs(ord)=4 then response.write arrow%></TD>
142		<TD width=70 onclick='go2Page(1,-5);' style="<%if abs(ord)=5 then response.write style%>">���� ������	<%if abs(ord)=5 then response.write arrow%></TD>
143		<TD width=70 onclick='go2Page(1,-6);' style="<%if abs(ord)=6 then response.write style%>">���	<%if abs(ord)=6 then response.write arrow%></TD>
144	</TR>
145	<TR bgcolor="eeeeee" >
146		<TD colspan=6 height=2 bgcolor=0></TD>
147	</TR>
148<%		
149	SumCredit=0
150	SumDebit=0
151	SumCreditRemained=0
152	SumDebitRemained=0
153	tmpCounter=0
154
155	mySQL="SELECT Invoices.ID, InventoryCost.SumPrice AS InventoryCost, OutServiceCost.SumPrice AS OutServiceCost, Invoices.TotalReceivable, Invoices.TotalReceivable - ISNULL(NULLIF (OutServiceCost.SumPrice, - 1), 0) - ISNULL(NULLIF (InventoryCost.SumPrice, - 1), 0) AS Margin, Accounts.AccountTitle FROM Invoices INNER JOIN Accounts ON Invoices.Customer = Accounts.ID LEFT OUTER JOIN (SELECT InvoiceOrderRelations.Invoice, CASE WHEN COUNT(*) = COUNT(VoucherLines.price) THEN SUM(VoucherLines.price) ELSE - 1 END AS SumPrice FROM Vouchers INNER JOIN VoucherLines ON Vouchers.id = VoucherLines.Voucher_ID RIGHT OUTER JOIN InvoiceOrderRelations INNER JOIN PurchaseOrders INNER JOIN PurchaseRequestOrderRelations INNER JOIN PurchaseRequests ON PurchaseRequestOrderRelations.Req_ID = PurchaseRequests.ID ON PurchaseOrders.ID = PurchaseRequestOrderRelations.Ord_ID ON InvoiceOrderRelations.[Order] = PurchaseRequests.Order_ID ON Vouchers.Voided = 0 AND VoucherLines.RelatedPurchaseOrderID = PurchaseOrders.ID WHERE (PurchaseRequests.Status <> N'del') AND (PurchaseOrders.Status <> N'CANCEL') GROUP BY InvoiceOrderRelations.Invoice) OutServiceCost ON Invoices.ID = OutServiceCost.Invoice LEFT OUTER JOIN (SELECT InvoiceOrderRelations.Invoice, CASE WHEN COUNT(*) = COUNT(InventoryItemsUnitPrice.UnitPrice) THEN SUM(InventoryPickuplistItems.Qtty * InventoryItemsUnitPrice.UnitPrice) ELSE - 1 END AS SumPrice FROM InventoryPickuplistItems INNER JOIN InventoryPickuplists ON InventoryPickuplistItems.pickupListID = InventoryPickuplists.id INNER JOIN InvoiceOrderRelations ON InventoryPickuplistItems.Order_ID = InvoiceOrderRelations.[Order] LEFT OUTER JOIN InventoryItemsUnitPrice ON InventoryPickuplists.CreationDate >= InventoryItemsUnitPrice.StartDate AND InventoryPickuplists.CreationDate <= InventoryItemsUnitPrice.EndDate AND InventoryPickuplistItems.ItemID = InventoryItemsUnitPrice.InventoryItem WHERE (InventoryPickuplistItems.CustomerHaveInvItem = 0) AND (NOT (InventoryPickuplists.Status = N'del')) GROUP BY InvoiceOrderRelations.Invoice) InventoryCost ON Invoices.ID = InventoryCost.Invoice WHERE (Invoices.Voided = 0) AND (Invoices.Issued = 1) AND (Invoices.IssuedDate >= N'"& FromDate & "' AND Invoices.IssuedDate <= N'"& ToDate & "') ORDER BY "& order
156'response.write "<div dir=LTR>" & mySQL & "</div><br>"
157
158	Set rs=Server.CreateObject("ADODB.Recordset")'Conn.Execute(mySQL)
159
160	PageSize = 50
161	rs.PageSize = PageSize
162
163	rs.CursorLocation=3 'in ADOVBS_INC adUseClient=3
164	rs.Open mySQL ,Conn,3
165	TotalPages = rs.PageCount
166
167	CurrentPage=1
168
169	if isnumeric(Request.QueryString("p")) then
170		pp=clng(Request.QueryString("p"))
171		if pp <= TotalPages AND pp > 0 then
172			CurrentPage = pp
173		end if
174	end if
175
176	if not rs.eof then
177		rs.AbsolutePage=CurrentPage
178	end if
179
180	if rs.eof then
181%>		<tr>
182			<td bgcolor="#BBBBBB" height="30" colspan="7" align=center><b>��� .</b></td>
183		</tr>
184<%	else
185		Do While NOT rs.eof AND (rs.AbsolutePage = CurrentPage)
186			tmpCounter = tmpCounter + 1
187			if tmpCounter mod 2 = 1 then
188				tmpColor="#FFFFFF"
189				tmpColor2="#FFFFBB"
190			Else
191				tmpColor="#DDDDDD"
192				tmpColor2="#EEEEBB"
193			End if 
194
195			marginInvalid=false
196
197			if isnull(rs("InventoryCost"))  then 
198				InventoryCost	=	""
199			elseif rs("InventoryCost")="-1" then
200				InventoryCost	=	"<font color='red'> ���� </font>"
201				marginInvalid=true
202			else
203				InventoryCost	=	cdbl(rs("InventoryCost"))
204			end if
205
206			if isnull(rs("OutServiceCost"))  then 
207				OutServiceCost	=	""
208			elseif rs("OutServiceCost")="-1" then
209				OutServiceCost	=	"<font color='red'> ���� </font>"
210				marginInvalid=true
211			else
212				OutServiceCost	=	cdbl(rs("OutServiceCost"))
213			end if
214			TotalReceivable	=	cdbl(rs("TotalReceivable"))
215			Margin			=	cdbl(rs("Margin"))
216
217			if marginInvalid then
218				MarginColor = "red"
219			else
220				MarginColor = ""
221			end if
222
223			
224
225	%>
226			<TR bgcolor="<%=tmpColor%>" onclick="showDetails(this.rowIndex);" style="cursor:pointer;">
227				<TD dir=ltr align=right><A target="_blank" onclick="event.cancelBubble=true;" HREF="AccountReport.asp?act=showInvoice&invoice=<%=rs("ID")%>"><%=rs("ID")%></A></TD>
228				<TD><%=rs("AccountTitle")%></TD>
229				<TD dir=ltr align=right><span dir=ltr><%=Separate(InventoryCost)%></span></TD>
230				<TD dir=ltr align=right><span dir=ltr><%=Separate(OutServiceCost)%></span></TD>
231				<TD dir=ltr align=right><span dir=ltr><%=Separate(TotalReceivable)%></span></TD>
232				<TD dir=ltr align=right><span dir=ltr style="color:<%=MarginColor%>"><%=Separate(Margin)%></span></TD>
233			</TR>
234			 
235	<% 
236		rs.moveNext
237		Loop
238
239		if TotalPages > 1 then
240			pageCols=20
241%>			
242			<TR bgcolor="eeeeee" >
243				<TD colspan=6 height=2 bgcolor=0></TD>
244			</TR>
245			<TR class="RepTableTitle">
246				<TD bgcolor="#CCCCEE" height="30" colspan="6">
247				<table width=100% cellspacing=0 style="cursor:hand;color:gray;">
248				<tr>
249					<td style="height:25;border-bottom:1 solid black;" colspan=<%=pagecols%>>
250						<b>���� <%=CurrentPage%> �� <%=TotalPages%></b>
251						&nbsp;&nbsp;<a href="javascript:go2Page(<%=CurrentPage+1%>,0);">���� ��� &gt;</a>
252					</td>
253				</tr>
254				<tr>
255<%				for i=1 to TotalPages 
256					if i = CurrentPage then 
257%>						<td style="color:black;"><b>[<%=i%>]</b></td>
258<%					else
259%>						<td onclick="go2Page(<%=i%>,0);"><%=i%></td>
260<%					end if 
261					if i mod pageCols = 0 then response.write "</tr><tr>" 
262				next 
263
264%>				</tr>
265				</table>
266				</TD>
267			</TR>
268<%		end if
269%>
270		</TABLE><br>
271		<SCRIPT LANGUAGE="JavaScript">
272		<!--
273		function go2Page(p,ord) {
274			if(ord==0){
275				ord=<%=Ord%>;
276			}
277			else if(ord==<%=Ord%>){
278				ord= 0-ord;
279			}
280			str='?act=MoeenRep&GLAccount='+escape('<%=GLAccount%>')+'&FromDate='+escape('<%=FromDate%>')+'&ToDate='+escape('<%=ToDate%>')+'&FromTafsil='+escape('<%=FromTafsil%>')+'&ToTafsil='+escape('<%=ToTafsil%>')+'&Ord='+escape(ord)+'&p='+escape(p) //+'& ='+escape(' ')+'& ='+escape(' ')+'& ='+escape(' ')
281			window.location=str;
282		}
283		//-->
284		</SCRIPT>
285<%
286	end if
287end if
288
289
290%>
291
292<!--#include file="tah.asp" -->