-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcirc-type-totals.js
46 lines (45 loc) · 1.34 KB
/
circ-type-totals.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// Koha report: https://library-staff.cca.edu/cgi-bin/koha/reports/guided_reports.pl?phase=Run+this+report&reports=231
const map = {
'': 'Other materials',
'ARCHIVE': 'Other materials',
'2DAYRES': 'Books',
'2HOURRES': 'Books',
'3HOURRES': 'Books',
'BK': 'Books',
'BOOK': 'Books',
'BOUNDPER': 'Periodicals',
'DVD': 'Videos',
'EQUIPMENT': 'Equipment',
'LIBUSEBK': 'Books',
'LIBUSEBOOK ': 'Books',
'LIBUSEDVD': 'Videos',
'LIBUSESUPP': 'Other materials',
'LIBUSEVIDE': 'Videos',
'MATSAMP': 'Materials Samples',
'MIXEDMEDIA': 'Other materials',
'NEWPER': 'Periodicals',
'REALIA': 'Other materials',
'SUPPL': 'Other materials',
'VIDEOTAPE': 'Videos'
}
let sum = {}
// build the categories from the map
for (let key in map) {
if (!sum[map[key]]) sum[map[key]] = 0
}
// loop over table & add each row to its matching sum entry
$('table tr').each((index, row) => {
if (index != 0) {
let type = $(row).find('td').eq(0).text().trim()
let quantity = parseInt($(row).find('td').eq(1).text().trim())
if (sum.hasOwnProperty(map[type])) {
sum[map[type]] += quantity
}
}
})
// printy/copy to clipboad in a nicer format
let out = 'Type\tTotal\n'
for (let key of Object.keys(sum).sort()) {
out += `${key}\t${sum[key]}\n`
}
console.log(out + '\n')