Fixed a few warnings.
[koha.git] / misc / fixborrower.pl
1 #!/usr/bin/perl
2
3 # This script will convert a database into the newer, proper
4 # form ... I think.
5
6
7 use C4::Database;
8 use strict;
9
10 my $dbh=C4Connect;
11
12 my $query = "Select * from categories where (categorycode like 'L%' or categorycode like 'F%'
13 or categorycode like 'S%' or categorycode like 'O%' or categorycode like 'H%') and (categorycode <>'HR' 
14 and categorycode <> 'ST')";
15
16 my $sth=$dbh->prepare($query);
17 $sth->execute;
18
19 while (my $data=$sth->fetchrow_hashref){
20   #update borrowers corresponding
21   #update categories
22
23     my $temp=substr($data->{'categorycode'},0,1);
24     $query="update borrowers set area='$temp' where categorycode='$data->{'categorycode'}'";
25     my $sth2=$dbh->prepare($query);
26     $sth2->execute;
27     $sth2->finish;
28  
29    $temp=substr($data->{'categorycode'},1,1);
30     $query="update borrowers set categorycode='$temp' where categorycode='$data->{'categorycode'}'"; 
31     $sth2=$dbh->prepare($query);
32     $sth2->execute;
33     $sth2->finish;
34
35     $query="delete from categories where categorycode='$data->{'categorycode'}'";
36     $sth2=$dbh->prepare($query);
37     $sth2->execute;
38     $sth2->finish;
39     
40 }
41
42 $query = "Select * from categories where (categorycode like 'V%') and (categorycode <>'HR' 
43 and categorycode <> 'ST')";
44
45 my $sth=$dbh->prepare($query);
46 $sth->execute;
47
48 while (my $data=$sth->fetchrow_hashref){
49   #update borrowers corresponding
50   #update categories
51 #    my $temp=substr($data->{'categorycode'},0,1);
52     $query="update borrowers set area='V' where categorycode='$data->{'categorycode'}'";
53     my $sth2=$dbh->prepare($query);
54     $sth2->execute;
55     $sth2->finish;
56
57     my $temp=substr($data->{'categorycode'},1,1);
58     $query="update borrowers set categorycode='$temp' where categorycode='$data->{'categorycode'}'"; 
59     $sth2=$dbh->prepare($query);
60     $sth2->execute;
61     $sth2->finish;
62
63     $query="delete from categories where categorycode='$data->{'categorycode'}'";
64     $sth2=$dbh->prepare($query);
65     $sth2->execute;
66     $sth2->finish;
67
68 }
69
70 my $query = "Select * from categories where categorycode = 'ST'";
71 my $sth=$dbh->prepare($query);
72 $sth->execute;
73
74 while (my $data=$sth->fetchrow_hashref){
75   #update borrowers corresponding
76   #update categories
77     $query="update borrowers set area='' where categorycode='$data->{'categorycode'}'";
78     my $sth2=$dbh->prepare($query);
79     $sth2->execute;
80     $sth2->finish;
81
82     $query="update borrowers set categorycode='W' where categorycode='$data->{'categorycode'}'"; 
83     $sth2=$dbh->prepare($query);
84     $sth2->execute;
85     $sth2->finish;
86
87     $query="delete from categories where categorycode='$data->{'categorycode'}'";
88     $sth2=$dbh->prepare($query);
89     $sth2->execute;
90     $sth2->finish;
91
92 }
93
94 my $query = "Select * from categories where categorycode = 'BR' or categorycode='CO' or categorycode='IS'";
95 my $sth=$dbh->prepare($query);
96 $sth->execute;
97
98 while (my $data=$sth->fetchrow_hashref){
99   #update borrowers corresponding
100   #update categories
101     $query="update borrowers set area='' where categorycode='$data->{'categorycode'}'";
102     my $sth2=$dbh->prepare($query);
103     $sth2->execute;
104     $sth2->finish;
105
106     $query="update borrowers set categorycode='I' where categorycode='$data->{'categorycode'}'"; 
107     $sth2=$dbh->prepare($query);
108     $sth2->execute;
109     $sth2->finish;
110
111     $query="delete from categories where categorycode='$data->{'categorycode'}'";
112     $sth2=$dbh->prepare($query);
113     $sth2->execute;
114     $sth2->finish;
115
116 }
117
118 my $query = "Select * from categories where categorycode = 'TD'  or categorycode='TR'";
119 my $sth=$dbh->prepare($query);
120 $sth->execute;
121
122 while (my $data=$sth->fetchrow_hashref){
123   #update borrowers corresponding
124   #update categories
125     $query="update borrowers set area='X' where categorycode='$data->{'categorycode'}'";
126     my $sth2=$dbh->prepare($query);
127     $sth2->execute;
128     $sth2->finish;
129
130     $query="update borrowers set categorycode='A' where categorycode='$data->{'categorycode'}'"; 
131     $sth2=$dbh->prepare($query);
132     $sth2->execute;
133     $sth2->finish;
134
135     $query="delete from categories where categorycode='$data->{'categorycode'}'";
136     $sth2=$dbh->prepare($query);
137     $sth2->execute;
138     $sth2->finish;
139
140 }
141
142 my $query = "Select * from categories where categorycode = 'HR'";
143 my $sth=$dbh->prepare($query);
144 $sth->execute;
145
146 while (my $data=$sth->fetchrow_hashref){
147   #update borrowers corresponding
148   #update categories
149     $query="update borrowers set area='K' where categorycode='$data->{'categorycode'}'";
150     my $sth2=$dbh->prepare($query);
151     $sth2->execute;
152     $sth2->finish;
153
154     $query="update borrowers set categorycode='A' where categorycode='$data->{'categorycode'}'"; 
155     $sth2=$dbh->prepare($query);
156     $sth2->execute;
157     $sth2->finish;
158
159     $query="delete from categories where categorycode='$data->{'categorycode'}'";
160     $sth2=$dbh->prepare($query);
161     $sth2->execute;
162     $sth2->finish;
163
164 }
165
166 my $query = "Select * from categories where categorycode = 'IL'";
167 my $sth=$dbh->prepare($query);
168 $sth->execute;
169
170 while (my $data=$sth->fetchrow_hashref){
171   #update borrowers corresponding
172   #update categories
173     $query="update borrowers set area='Z' where categorycode='$data->{'categorycode'}'";
174     my $sth2=$dbh->prepare($query);
175     $sth2->execute;
176     $sth2->finish;
177
178     $query="update borrowers set categorycode='L' where categorycode='$data->{'categorycode'}'"; 
179     $sth2=$dbh->prepare($query);
180     $sth2->execute;
181     $sth2->finish;
182
183     $query="delete from categories where categorycode='$data->{'categorycode'}'";
184     $sth2=$dbh->prepare($query);
185     $sth2->execute;
186     $sth2->finish;
187
188 }
189
190 my $query = "Select * from categories where categorycode = 'TB'";
191 my $sth=$dbh->prepare($query);
192 $sth->execute;
193 while (my $data=$sth->fetchrow_hashref){
194   #update borrowers corresponding
195   #update categories
196
197     $query="update borrowers set area='' where categorycode='$data->{'categorycode'}'";
198     my $sth2=$dbh->prepare($query);
199     $sth2->execute;
200     $sth2->finish;
201     
202     $query="update borrowers set categorycode='P' where categorycode='$data->{'categorycode'}'"; 
203     $sth2=$dbh->prepare($query);
204     $sth2->execute;
205     $sth2->finish;
206
207     $query="delete from categories where categorycode='$data->{'categorycode'}'";
208     $sth2=$dbh->prepare($query);
209     $sth2->execute;
210     $sth2->finish;
211
212 }
213
214 $sth->finish;
215
216 my @queryValues = 
217     ("insert into categories values ('E','Senior Citizen',5,99,0,'A',0,0,0,99,1)",
218      "insert into categories values ('A','Adult',5,99,0,'A',0,0,0,99,1)",
219      "insert into categories values ('C','Child',5,16,0,'A',0,0,0,99,0)",
220      "insert into categories values ('B','Housebound',5,99,0,'E',0,0,0,99,0)",
221      "insert into categories values ('F','Family',5,99,0,'A',0,0,0,99,1)",
222      "insert into categories values ('W','Workers',5,99,0,'A',0,0,0,99,0)",
223      "insert into categories values ('I','Institution',5,99,0,'A',0,0,0,99,0)",
224      "insert into categories values ('P','Privileged',5,99,0,'A',0,0,0,99,0)",
225      "insert into categories values ('L','Library',5,99,0,'A',0,0,0,99,0)"
226      );   
227
228 foreach $query (@queryValues) {
229     $sth=$dbh->prepare($query);
230     $sth->execute;
231     $sth->finish;
232 }
233
234 $dbh->disconnect;