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