Advertisement
Guest User

Untitled

a guest
Sep 25th, 2017
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.65 KB | None | 0 0
  1. <cfset date1 = CREATEODBCDATETIME(form.StartDate & '00:00:00')>
  2. <cfset date2 = CREATEODBCDATETIME(form.EndDate & '23:59:59')>
  3.  
  4. <!--- WHITELIST OF VALID LOCATIONS --->
  5. <cfset validLocs = "OPERATIONS, CCC, QA, DS, PS, LWR, NR, SDL, FSC">
  6. <cfset locList = "">
  7. <cfif structKeyExists(FORM,"location") AND len(FORM.location) GT 0>
  8. <cfloop list="#FORM.location#" index="vLoc">
  9. <cfif listContainsNoCase(validLocs, vLoc) GT 0>
  10. <cfset locList = listAppend(locList,vloc)>
  11. </cfif>
  12. </cfloop>
  13. <cfelse>
  14. </cfif>
  15.  
  16. <cfquery datasource="#application.dsn#" name="GetEmployeeInfo">
  17. SELECT s4.associate /* Associate's ID */
  18. , s4.assoc_name /* Associate's Name */
  19. , s4.trans_location /* Associate's Location */
  20. , s4.checklistsByAssocLoc /* Gives you a count of Checklists by Associate for a specific Location. */
  21. , s4.assocChecklistsByLoc /* Gives you a count of Total Checklists by All Associates in a Location. */
  22. , s4.totalChecklistsByAssoc /** Gives you a count of Total Checklists by Specific Associate in All Locations. */
  23. , s4.totalAssocChecklistsByAllFilteredLoc /* Gives you a count of Total Checklists by Specific Associates in All Locations. */
  24. , CASE WHEN ( coalesce(s4.assocChecklistsByLoc,0) > 0 ) THEN (CAST(s4.checklistsByAssocLoc AS decimal(8,2))/s4.assocChecklistsByLoc) * 100 ELSE 0 END AS totalChecklistsByAssocLocPct /* This gives you a percent of associate location checklists over count of checklists by Associate in a Location. */
  25. , CASE WHEN ( coalesce(s4.totalAssocChecklistsByAllFilteredLoc,0) > 0 ) THEN (CAST(s4.totalChecklistsByAssoc AS decimal(8,2))/s4.totalAssocChecklistsByAllFilteredLoc) * 100 ELSE 0 END AS totalChecklistsByLocPct /* This gives you a percent of Total Associate Checklists in All Locations over count of Checklists by All Associate in All Locations. */
  26. , s4.rnA /* Placeholder for a record to display the Associate Name. */
  27. , s4.rnL /* Placeholder for a record to display the Location. */
  28. , s4.rnTotAssoc /* Placeholder for the last Associate Location row. The next row should be an Associate Total. */
  29. FROM (
  30. SELECT s3.*
  31. , SUM(s3.assocChecklistsByLoc) OVER (PARTITION BY s3.associate) AS totalAssocChecklistsByAllFilteredLoc /* Gives you a count of Total Checklists by Specific Associates in All Locations. */
  32. FROM (
  33.  
  34. SELECT s2.*
  35. FROM (
  36. SELECT a.assoc_name
  37. , s1.associate
  38. , s1.trans_location
  39. , s1.checklistsByAssocLoc
  40. , s1.assocChecklistsByLoc
  41. , s1.totalChecklistsByAssoc
  42. , ROW_NUMBER() OVER (PARTITION BY s1.associate ORDER BY s1.associate, s1.trans_location) AS rnA /* Placeholder for a record to display the Associate Name */
  43. , ROW_NUMBER() OVER (PARTITION BY s1.associate, s1.trans_location ORDER BY s1.associate, s1.trans_location) AS rnL /* Placeholder for a record to display the Location */
  44. , ROW_NUMBER() OVER (PARTITION BY s1.associate ORDER BY s1.trans_location DESC) AS rnTotAssoc /* Placeholder for the last Associate Location row. The next row should be an Associate Total. */
  45. FROM (
  46. SELECT c.associate
  47. , c.trans_location
  48. , COUNT(*) OVER (PARTITION BY c.associate, c.trans_location) AS checklistsByAssocLoc /* Gives you a count of Checklists by Associate for a specific Location. */
  49. , COUNT(*) OVER (PARTITION BY c.associate) AS totalChecklistsByAssoc /* Gives you a count of Total Checklists by Associate in All Locations. */
  50. , COUNT(*) OVER (PARTITION BY c.trans_location) AS assocChecklistsByLoc /* Gives you a count of Total Checklists by All Associates in a Location. */
  51. FROM cl_checklists c
  52. LEFT OUTER JOIN tco_associates a ON c.associate = a.assoc_id
  53. AND a.assoc_id IN ( <cfqueryparam value="#FORM.EmployeeName#" cfsqltype="cf_sql_varchar" list="true" /> ) /* SELECTED ASSOCIATE IDs */
  54. WHERE c.[DATE] >= <cfqueryparam value="#date1#" cfsqltype="cf_sql_timestamp" /> /* SELECTED DATES */
  55. AND c.[DATE] <= <cfqueryparam value="#date2#" cfsqltype="cf_sql_timestamp" />
  56. AND c.trans_location IN ( <cfqueryparam value="#locList#" cfsqltype="cf_sql_varchar" list="true" /> ) /* SELECTED LOCATIONS */
  57. ) s1
  58. INNER JOIN tco_associates a ON s1.associate = a.assoc_id
  59. AND a.assoc_id IN ( <cfqueryparam value="#FORM.EmployeeName#" cfsqltype="cf_sql_varchar" list="true" /> ) /* SELECTED ASSOCIATE IDs */
  60.  
  61. ) s2
  62. WHERE s2.rnA = 1 OR s2.rnL = 1 /* There will be a final Location (rnL=1 and rnTotAssoc=1). This is the final row. */
  63. ) s3
  64. ) s4
  65. ORDER BY s4.assoc_name, s4.trans_location
  66. </cfquery>
  67.  
  68. <table>
  69. <thead>
  70. <th><strong>Associate Name</strong></th>
  71. <th><strong>Location</strong></th>
  72. <th><strong>Checklists Generated by Associate</strong></th>
  73. <th><strong>Checklists Generated by Selected Location(s)</strong></th>
  74. <th><strong>Associate Percentage of Location Total</strong></th>
  75. <th></th>
  76. </thead>
  77. <cfoutput query="GetEmployeeInfo">
  78. <tr>
  79. <td><cfif rnA EQ 1><strong>#assoc_name#</strong></cfif></td>
  80. <td><cfif rnL EQ 1>#trans_location#</cfif></td>
  81. <td>#checklistsByAssocLoc#</td>
  82. <td>#assocChecklistsByLoc#</td>
  83. <td>#DecimalFormat(totalChecklistsByAssocLocPct)# %</td>
  84. <!---<td> rnA: #rnA# | rnL: #rnL# | rnTotAssoc: #rnTotAssoc# </td> --->
  85. </tr>
  86. <cfif rnTotAssoc EQ 1>
  87. <tr>
  88. <td>Associate Total</td>
  89. <td></td>
  90. <td>#totalChecklistsByAssoc#</td>
  91. <td>#totalAssocChecklistsByAllFilteredLoc#</td>
  92. <td>#DecimalFormat(totalChecklistsByLocPct)# %</td>
  93. <td></td>
  94. </tr>
  95. </cfif>
  96. </cfoutput>
  97. </table>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement