moving stuff, again
[migration-tools.git] / ils-specific / parse-tlc-items-out.pl
1 #!/usr/bin/perl
2
3 # This parses TCL items-out reports converted from excel to csv, turning them
4 # into a tab separated file.  arg!
5
6 my $state;
7 my $patron;
8 my $item;
9 my $out;
10 my $due;
11 my $price;
12
13 my ($a,$b,$c,$d,$e,$f,$g) = (0,1,2,3,4,5,6,7);
14
15 print "patron\titem\tout\tdue\tprice\n";
16
17 while (<>) {
18     chomp;
19     my @fields = split /\t/;
20
21     if ( (!$state || $state eq 'item' || $state eq 'none') && $fields[$f] eq 'Borrower ID') {
22         $state = 'borrower';
23         next;
24     }
25
26     if ($state eq 'borrower') {
27         $patron = $fields[$f];
28         $state = 'none';
29         next;
30     }
31
32     if ($state eq 'none' && $fields[$b] eq 'Item ID') {
33         $state = 'item';
34         next;
35     }
36
37     if ($state eq 'item' && $fields[$b] =~ /^\d+$/o) {
38         $item = $fields[$b];
39         if ($fields[$f] =~ /^(\d+)\/(\d+)\/(\d+)$/) {
40             $out = sprintf('%04d-%02d-%02d', 2000 + $3, $1, $2);
41         }
42         if ($fields[$e] =~ /^(\d+)\/(\d+)\/(\d+)$/) {
43             $due = sprintf('%04d-%02d-%02d', 2000 + $3, $1, $2);
44         }
45         ($price = $fields[$g]) =~ s/\*//go;
46         print join("\t", $patron, $item, $out, $due, $price) . "\n";
47     }
48 }