Ticket #39615 Fix versions for upgrades
[freeside.git] / bin / cch_tax_tool
1 #!/usr/bin/perl -w
2
3 use strict;
4
5 # this tool manipulates fixed length cch tax files by comparing the
6 # update files in the $update_dir to the initial install files 
7 # in the $init_dir
8 #
9 # it produces .DOIT files in $update_dir which are suitable for
10 # syncing a database initialzed with the files in $init_dir to
11 # the state represented by the files in $update_dir
12 #
13 # how one acquires update files from cch that overlap with initial
14 # full install remains a mystery
15
16 my $init_dir = "cchinit/";
17 my $update_dir = "cchupdate/";
18
19 foreach my $file (qw (CODE DETAIL PLUS4 GEOCODE TXMATRIX ZIP)) {
20    my $tfile = $update_dir. $file. "T";
21    $tfile = $update_dir. "TXMATRIT" if $tfile =~ /TXMATRIXT$/;
22    open FILE, "$tfile.TXT" or die "Can't open $tfile.TXT\n";
23    open INSERT, ">$tfile.INS" or die "Can't open $tfile.INS\n";
24    open DELETE, ">$tfile.DEL" or die "Can't open $tfile.DEL\n";
25    while(<FILE>){
26      chomp;
27      print INSERT "$_\n" if s/I$//;
28      print DELETE "$_\n" if s/D$//;
29    }
30    close FILE;
31    close INSERT;
32    close DELETE;
33    system "sort $tfile.INS > $tfile.INSSORT";
34    system "sort $tfile.DEL > $tfile.DELSORT";
35    system "sort $init_dir$file.txt > $tfile.ORGINSSORT";
36    system "comm -12 $tfile.INSSORT $tfile.ORGINSSORT > $tfile.PREINS";
37    system "comm -23 $tfile.INSSORT $tfile.ORGINSSORT > $tfile.2BEINS";
38    system "comm -23 $tfile.DELSORT $tfile.ORGINSSORT > $tfile.PREDEL";
39    system "comm -12 $tfile.DELSORT $tfile.ORGINSSORT > $tfile.2BEDEL";
40 }
41
42 foreach my $file (qw (CODET DETAILT PLUS4T GEOCODET TXMATRIT ZIPT)) {
43    my $tfile = $update_dir. $file;
44    $tfile = "TXMATRIT" if $tfile eq "TXMATRIXT";
45    open INSERT, "$tfile.2BEINS" or die "Can't open $tfile.2BEINS\n";
46    open DELETE, "$tfile.2BEDEL" or die "Can't open $tfile.2BEDEL\n";
47    open FILE, ">$tfile.DOIT" or die "Can't open $tfile.DOIT\n";
48    while(<INSERT>){
49      chomp;
50      print FILE $_, "I\n";
51    }
52    while(<DELETE>){
53      chomp;
54      print FILE $_, "D\n";
55    }
56    close FILE;
57    close INSERT;
58    close DELETE;
59 }