@@ -13,6 +13,52 @@ FROM ach_files
1313WHERE created_at >= datetime('now', '-7 days')
1414ORDER BY created_at DESC
1515LIMIT 5;
16+ ` } ,
17+ { name : "Largest Amounts in Files" , query : `
18+ WITH RankedEntries AS (
19+ SELECT e.entry_id, e.file_id,
20+ e.individual_name, e.dfi_account_number, e.amount,
21+ e.transaction_code, e.trace_number, f.filename, f.file_creation_date,
22+ (
23+ SELECT COUNT(*) + 1
24+ FROM ach_entries e2
25+ WHERE e2.file_id = e.file_id
26+ AND e2.amount > e.amount
27+ ) AS rank_num
28+ FROM ach_entries e
29+ JOIN ach_files f ON e.file_id = f.file_id
30+ WHERE f.created_at >= datetime('now', '-7 days')
31+ )
32+ SELECT
33+ -- entry_id, file_id,
34+ individual_name, dfi_account_number, amount, transaction_code,
35+ trace_number, filename, file_creation_date
36+ FROM RankedEntries
37+ WHERE rank_num <= 3
38+ ORDER BY file_id, amount DESC
39+ LIMIT 10;
40+ ` } ,
41+ ] ,
42+ } ,
43+ {
44+ category : "Batches" ,
45+ queries : [
46+ { name : "Originator Activity Summary" , query : `
47+ SELECT
48+ b.company_name, b.company_identification, COUNT(DISTINCT b.batch_id) AS batch_count,
49+ SUM(e.amount) AS total_amount, COUNT(e.entry_id) AS entry_count, f.filename
50+
51+ FROM ach_batches b
52+ JOIN ach_entries e ON b.batch_id = e.batch_id AND b.file_id = e.file_id
53+ JOIN ach_files f ON b.file_id = f.file_id
54+
55+ WHERE
56+ -- b.company_identification = :company_id AND
57+ f.created_at >= datetime('now', '-30 days')
58+
59+ GROUP BY b.company_name, b.company_identification, f.filename
60+ ORDER BY total_amount DESC
61+ LIMIT 10;
1662` } ,
1763 ] ,
1864 } ,
@@ -37,12 +83,47 @@ WHERE
3783ORDER BY f.created_at DESC
3884LIMIT 10;
3985` } ,
86+ { name : "Possible Duplicate Entries" , query : `
87+ SELECT
88+ e.dfi_account_number, e.amount, e.individual_name, e.trace_number, COUNT(*) AS entry_count,
89+ -- GROUP_CONCAT(e.entry_id) AS entry_ids,
90+ f.filename
91+
92+ FROM ach_entries e
93+ JOIN ach_files f ON e.file_id = f.file_id
94+
95+ WHERE
96+ f.created_at >= datetime('now', '-30 days')
97+
98+ GROUP BY e.dfi_account_number, e.amount, e.trace_number
99+ HAVING entry_count > 1
100+ ORDER BY f.created_at DESC
101+ LIMIT 10;
102+
103+ ` } ,
40104 ] ,
41105 } ,
42106 {
43107 category : "Exceptions" ,
44108 queries : [
45- { name : "Recent Returns and Corrections" , query : `
109+ { name : "Recent Corrections" , query : `
110+ SELECT
111+ -- e.entry_id,
112+ e.individual_name, e.dfi_account_number, e.amount,
113+ e.trace_number, a.change_code,
114+ -- a.payment_related_information,
115+ f.filename, f.file_creation_date
116+
117+ FROM ach_entries e
118+ JOIN ach_addendas a ON e.entry_id = a.entry_id AND e.file_id = a.file_id
119+ JOIN ach_files f ON e.file_id = f.file_id
120+
121+ WHERE a.change_code IS NOT NULL
122+
123+ ORDER BY f.created_at DESC
124+ LIMIT 10;
125+ ` } ,
126+ { name : "Recent Returns" , query : `
46127SELECT
47128 -- e.entry_id,
48129 e.individual_name, e.dfi_account_number, e.amount,
@@ -54,7 +135,7 @@ FROM ach_entries e
54135JOIN ach_addendas a ON e.entry_id = a.entry_id AND e.file_id = a.file_id
55136JOIN ach_files f ON e.file_id = f.file_id
56137
57- WHERE a.return_code IS NOT NULL OR a.change_code IS NOT NULL
138+ WHERE a.return_code IS NOT NULL
58139
59140ORDER BY f.created_at DESC
60141LIMIT 10;
@@ -141,9 +222,9 @@ function populateAccordion() {
141222 const option = document . createElement ( "button" ) ;
142223 option . classList . add ( "query-option" ) ;
143224 option . textContent = query . name ;
144- option . setAttribute ( "data-query" , query . query ) ;
225+ option . setAttribute ( "data-query" , query . query . trim ( ) ) ;
145226 option . addEventListener ( "click" , ( ) => {
146- document . querySelector ( "#query" ) . value = query . query ;
227+ document . querySelector ( "#query" ) . value = query . query . trim ( ) ;
147228 } ) ;
148229 content . appendChild ( option ) ;
149230 } ) ;
0 commit comments