View | Details | Raw Unified | Return to bug 8369
Collapse All | Expand All

(-)a/admin/smart-rules.pl (-64 / +158 lines)
Lines 50-88 if ($op eq 'delete') { Link Here
50
    my $categorycode = $input->param('categorycode');
50
    my $categorycode = $input->param('categorycode');
51
    $debug and warn "deleting $1 $2 $branch";
51
    $debug and warn "deleting $1 $2 $branch";
52
52
53
    my $sth_Idelete = $dbh->prepare("delete from issuingrules where branchcode=? and categorycode=? and itemtype=?");
53
    my $sth_Idelete = $dbh->prepare("
54
        DELETE FROM issuingrules
55
        WHERE branchcode = ?
56
            AND categorycode = ?
57
            AND itemtype = ?
58
    ");
54
    $sth_Idelete->execute($branch, $categorycode, $itemtype);
59
    $sth_Idelete->execute($branch, $categorycode, $itemtype);
55
}
60
}
56
elsif ($op eq 'delete-branch-cat') {
61
elsif ($op eq 'delete-branch-cat') {
57
    my $categorycode  = $input->param('categorycode');
62
    my $categorycode  = $input->param('categorycode');
58
    if ($categorycode eq "*") {
63
    if ($categorycode eq "*") {
59
        my $sth_delete = $dbh->prepare("DELETE FROM circ_rules WHERE branchcode = ?");
64
        my $sth_delete = $dbh->prepare("
65
            DELETE FROM circ_rules
66
            WHERE branchcode = ?
67
        ");
60
        $sth_delete->execute( $branch );
68
        $sth_delete->execute( $branch );
61
    } else {
69
    } else {
62
        my $sth_delete = $dbh->prepare("DELETE FROM borrower_circ_rules
70
        my $sth_delete = $dbh->prepare("
63
                                        WHERE branchcode = ?
71
            DELETE FROM borrower_circ_rules
64
                                        AND categorycode = ?");
72
            WHERE branchcode = ?
73
            AND categorycode = ?
74
        ");
65
        $sth_delete->execute( $branch, $categorycode );
75
        $sth_delete->execute( $branch, $categorycode );
66
    }
76
    }
67
}
77
}
68
elsif ($op eq 'delete-branch-item') {
78
elsif ($op eq 'delete-branch-item') {
69
    my $itemtype  = $input->param('itemtype');
79
    my $itemtype  = $input->param('itemtype');
70
    if ($itemtype eq "*") {
80
    if ($itemtype eq "*") {
71
        my $sth_delete = $dbh->prepare("DELETE FROM circ_rules WHERE branchcode = ?");
81
        my $sth_delete = $dbh->prepare("
82
            DELETE FROM circ_rules
83
            WHERE branchcode = ?
84
        ");
72
        $sth_delete->execute( $branch);
85
        $sth_delete->execute( $branch);
73
    } else {
86
    } else {
74
        my $sth_delete = $dbh->prepare("DELETE FROM item_circ_rules
87
        my $sth_delete = $dbh->prepare("
75
                                        WHERE branchcode = ?
88
            DELETE FROM item_circ_rules
76
                                        AND itemtype = ?");
89
            WHERE branchcode = ?
90
            AND itemtype = ?
91
        ");
77
        $sth_delete->execute( $branch, $itemtype );
92
        $sth_delete->execute( $branch, $itemtype );
78
    }
93
    }
79
}
94
}
80
# save the values entered
95
# save the values entered
81
elsif ($op eq 'add') {
96
elsif ($op eq 'add') {
82
    my $sth_search = $dbh->prepare('SELECT COUNT(*) AS total FROM issuingrules WHERE branchcode=? AND categorycode=? AND itemtype=?');
97
    my $sth_search = $dbh->prepare('
83
    my $sth_insert = $dbh->prepare('INSERT INTO issuingrules (branchcode, categorycode, itemtype, maxissueqty, renewalsallowed, renewalperiod, reservesallowed, issuelength, lengthunit, hardduedate, hardduedatecompare, fine, finedays, firstremind, chargeperiod,rentaldiscount, overduefinescap) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)');
98
        SELECT COUNT(*) AS total
84
    my $sth_update=$dbh->prepare("UPDATE issuingrules SET fine=?, finedays=?, firstremind=?, chargeperiod=?, maxissueqty=?, renewalsallowed=?, renewalperiod=?, reservesallowed=?, issuelength=?, lengthunit = ?, hardduedate=?, hardduedatecompare=?, rentaldiscount=?, overduefinescap=?  WHERE branchcode=? AND categorycode=? AND itemtype=?");
99
        FROM issuingrules
85
    
100
        WHERE branchcode=?
101
            AND categorycode=?
102
            AND itemtype=?
103
    ');
104
    my $sth_insert = $dbh->prepare('
105
        INSERT INTO issuingrules (
106
            branchcode,
107
            categorycode,
108
            itemtype,
109
            maxissueqty,
110
            renewalsallowed,
111
            renewalperiod,
112
            reservesallowed,
113
            issuelength,
114
            lengthunit,
115
            hardduedate,
116
            hardduedatecompare,
117
            fine,
118
            finedays,
119
            firstremind,
120
            chargeperiod,
121
            rentaldiscount,
122
            overduefinescap
123
        ) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)
124
    ');
125
    my $sth_update=$dbh->prepare("
126
        UPDATE issuingrules
127
        SET fine = ?,
128
            finedays = ?,
129
            firstremind = ?,
130
            chargeperiod = ?,
131
            maxissueqty = ?,
132
            renewalsallowed = ?,
133
            renewalperiod = ?,
134
            reservesallowed = ?,
135
            issuelength = ?,
136
            lengthunit = ?,
137
            hardduedate = ?,
138
            hardduedatecompare = ?,
139
            rentaldiscount = ?,
140
            overduefinescap = ?
141
        WHERE branchcode = ?
142
            AND categorycode = ?
143
            AND itemtype = ?
144
    ");
145
86
    my $br = $branch; # branch
146
    my $br = $branch; # branch
87
    my $bor  = $input->param('categorycode'); # borrower category
147
    my $bor  = $input->param('categorycode'); # borrower category
88
    my $cat  = $input->param('itemtype');     # item type
148
    my $cat  = $input->param('itemtype');     # item type
Lines 122-136 elsif ($op eq "set-branch-defaults") { Link Here
122
    $maxissueqty = undef if $maxissueqty !~ /^\d+/;
182
    $maxissueqty = undef if $maxissueqty !~ /^\d+/;
123
    $holdallowed =~ s/\s//g;
183
    $holdallowed =~ s/\s//g;
124
    $holdallowed = undef if $holdallowed !~ /^\d+/;
184
    $holdallowed = undef if $holdallowed !~ /^\d+/;
125
    my $sth_search = $dbh->prepare("SELECT count(*) AS total
185
    my $sth_search = $dbh->prepare("
126
                                    FROM circ_rules
186
        SELECT count(*) AS total
127
                                    WHERE branchcode = ?");
187
        FROM circ_rules
128
    my $sth_insert = $dbh->prepare("INSERT INTO circ_rules
188
        WHERE branchcode = ?
129
                                    (branchcode, maxissueqty, holdallowed, returnbranch)
189
    ");
130
                                    VALUES (?, ?, ?, ?)");
190
    my $sth_insert = $dbh->prepare("
131
    my $sth_update = $dbh->prepare("UPDATE circ_rules
191
        INSERT INTO circ_rules (branchcode, maxissueqty, holdallowed, returnbranch)
132
                                    SET maxissueqty = ?, holdallowed = ?, returnbranch = ?
192
        VALUES (?, ?, ?, ?)
133
                                    WHERE branchcode = ?");
193
    ");
194
    my $sth_update = $dbh->prepare("
195
        UPDATE circ_rules
196
        SET maxissueqty = ?, holdallowed = ?, returnbranch = ?
197
        WHERE branchcode = ?
198
    ");
134
199
135
    $sth_search->execute( $branch );
200
    $sth_search->execute( $branch );
136
    my $res = $sth_search->fetchrow_hashref();
201
    my $res = $sth_search->fetchrow_hashref();
Lines 147-161 elsif ($op eq "add-branch-cat") { Link Here
147
    $maxissueqty = undef if $maxissueqty !~ /^\d+/;
212
    $maxissueqty = undef if $maxissueqty !~ /^\d+/;
148
213
149
    if ($categorycode eq "*") {
214
    if ($categorycode eq "*") {
150
        my $sth_search = $dbh->prepare("SELECT count(*) AS total
215
        my $sth_search = $dbh->prepare("
151
                                        FROM circ_rules
216
            SELECT count(*) AS total
152
                                        WHERE branchcode = ?");
217
            FROM circ_rules
153
        my $sth_insert = $dbh->prepare("INSERT INTO circ_rules
218
            WHERE branchcode = ?
154
                                        (branchcode, maxissueqty)
219
        ");
155
                                        VALUES (?, ?)");
220
        my $sth_insert = $dbh->prepare("
156
        my $sth_update = $dbh->prepare("UPDATE circ_rules
221
            INSERT INTO circ_rules (branchcode, maxissueqty)
157
                                        SET maxissueqty = ?
222
            VALUES (?, ?)
158
                                        WHERE branchcode = ?");
223
        ");
224
        my $sth_update = $dbh->prepare("
225
            UPDATE circ_rules
226
            SET maxissueqty = ?
227
            WHERE branchcode = ?
228
        ");
159
229
160
        $sth_search->execute( $branch );
230
        $sth_search->execute( $branch );
161
        my $res = $sth_search->fetchrow_hashref();
231
        my $res = $sth_search->fetchrow_hashref();
Lines 165-181 elsif ($op eq "add-branch-cat") { Link Here
165
            $sth_insert->execute( $maxissueqty, $branch );
235
            $sth_insert->execute( $maxissueqty, $branch );
166
        }
236
        }
167
    } else {
237
    } else {
168
        my $sth_search = $dbh->prepare("SELECT count(*) AS total
238
        my $sth_search = $dbh->prepare("
169
                                        FROM borrower_circ_rules
239
            SELECT count(*) AS total
170
                                        WHERE branchcode = ?
240
            FROM borrower_circ_rules
171
                                        AND categorycode = ?");
241
            WHERE branchcode = ?
172
        my $sth_insert = $dbh->prepare("INSERT INTO borrower_circ_rules
242
                AND categorycode = ?
173
                                        (branchcode, categorycode, maxissueqty)
243
        ");
174
                                        VALUES (?, ?, ?)");
244
        my $sth_insert = $dbh->prepare("
175
        my $sth_update = $dbh->prepare("UPDATE borrower_circ_rules
245
            INSERT INTO borrower_circ_rules
176
                                        SET maxissueqty = ?
246
                (branchcode, categorycode, maxissueqty)
177
                                        WHERE branchcode = ?
247
            VALUES (?, ?, ?)");
178
                                        AND categorycode = ?");
248
        my $sth_update = $dbh->prepare("
249
            UPDATE borrower_circ_rules
250
            SET maxissueqty = ?
251
            WHERE branchcode = ?
252
                AND categorycode = ?
253
        ");
179
        $sth_search->execute( $branch, $categorycode );
254
        $sth_search->execute( $branch, $categorycode );
180
        my $res = $sth_search->fetchrow_hashref();
255
        my $res = $sth_search->fetchrow_hashref();
181
        if ($res->{total}) {
256
        if ($res->{total}) {
Lines 193-207 elsif ($op eq "add-branch-item") { Link Here
193
    $holdallowed = undef if $holdallowed !~ /^\d+/;
268
    $holdallowed = undef if $holdallowed !~ /^\d+/;
194
269
195
    if ($itemtype eq "*") {
270
    if ($itemtype eq "*") {
196
        my $sth_search = $dbh->prepare("SELECT count(*) AS total
271
        my $sth_search = $dbh->prepare("
197
                                        FROM circ_rules
272
            SELECT count(*) AS total
198
                                        WHERE branchcode = ?");
273
            FROM circ_rules
199
        my $sth_insert = $dbh->prepare("INSERT INTO circ_rules
274
            WHERE branchcode = ?
200
                                        (branchcode, holdallowed, returnbranch)
275
        ");
201
                                        VALUES (?, ?, ?)");
276
        my $sth_insert = $dbh->prepare("
202
        my $sth_update = $dbh->prepare("UPDATE circ_rules
277
            INSERT INTO circ_rules
203
                                        SET holdallowed = ?, returnbranch = ?
278
                (branchcode, holdallowed, returnbranch)
204
                                        WHERE branchcode = ?");
279
            VALUES (?, ?, ?)
280
        ");
281
        my $sth_update = $dbh->prepare("
282
            UPDATE circ_rules
283
            SET holdallowed = ?, returnbranch = ?
284
            WHERE branchcode = ?
285
        ");
205
286
206
        $sth_search->execute( $branch );
287
        $sth_search->execute( $branch );
207
        my $res = $sth_search->fetchrow_hashref();
288
        my $res = $sth_search->fetchrow_hashref();
Lines 211-226 elsif ($op eq "add-branch-item") { Link Here
211
            $sth_insert->execute($branch, $holdallowed, $returnbranch);
292
            $sth_insert->execute($branch, $holdallowed, $returnbranch);
212
        }
293
        }
213
    } else {
294
    } else {
214
        my $sth_search = $dbh->prepare("SELECT count(*) AS total
295
        my $sth_search = $dbh->prepare("
215
                                        FROM item_circ_rules
296
            SELECT count(*) AS total
216
                                        WHERE itemtype = ?");
297
            FROM item_circ_rules
217
        my $sth_insert = $dbh->prepare("INSERT INTO item_circ_rules
298
            WHERE itemtype = ?
218
                                        (branchcode, itemtype, holdallowed, returnbranch)
299
        ");
219
                                        VALUES (?, ?, ?, ?)");
300
        my $sth_insert = $dbh->prepare("
220
        my $sth_update = $dbh->prepare("UPDATE item_circ_rules
301
            INSERT INTO item_circ_rules
221
                                        SET holdallowed = ?, returnbranch = ?
302
                (branchcode, itemtype, holdallowed, returnbranch)
222
                                        WHERE branchcode = ?
303
            VALUES (?, ?, ?, ?)
223
                                        AND itemtype = ?");
304
        ");
305
        my $sth_update = $dbh->prepare("
306
            UPDATE item_circ_rules
307
            SET holdallowed = ?, returnbranch = ?
308
            WHERE branchcode = ?
309
                AND itemtype = ?
310
        ");
224
        $sth_search->execute($itemtype);
311
        $sth_search->execute($itemtype);
225
        my $res = $sth_search->fetchrow_hashref();
312
        my $res = $sth_search->fetchrow_hashref();
226
        if ($res->{total}) {
313
        if ($res->{total}) {
Lines 241-247 for my $thisbranch (sort { $branches->{$a}->{branchname} cmp $branches->{$b}->{b Link Here
241
    };
328
    };
242
}
329
}
243
330
244
my $sth=$dbh->prepare("SELECT description,categorycode FROM categories ORDER BY description");
331
my $sth=$dbh->prepare("
332
    SELECT description,categorycode
333
    FROM categories
334
    ORDER BY description
335
");
245
$sth->execute;
336
$sth->execute;
246
my @category_loop;
337
my @category_loop;
247
while (my $data=$sth->fetchrow_hashref){
338
while (my $data=$sth->fetchrow_hashref){
Lines 249-255 while (my $data=$sth->fetchrow_hashref){ Link Here
249
}
340
}
250
341
251
$sth->finish;
342
$sth->finish;
252
$sth=$dbh->prepare("SELECT description,itemtype FROM itemtypes ORDER BY description");
343
$sth=$dbh->prepare("
344
    SELECT description,itemtype
345
    FROM itemtypes
346
    ORDER BY description
347
");
253
$sth->execute;
348
$sth->execute;
254
# $i=0;
349
# $i=0;
255
my @row_loop;
350
my @row_loop;
256
- 

Return to bug 8369