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

(-)a/admin/smart-rules.pl (-64 / +156 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, 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=?, 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
            reservesallowed,
112
            issuelength,
113
            lengthunit,
114
            hardduedate,
115
            hardduedatecompare,
116
            fine,
117
            finedays,
118
            firstremind,
119
            chargeperiod,
120
            rentaldiscount,
121
            overduefinescap
122
        ) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)
123
    ');
124
    my $sth_update=$dbh->prepare("
125
        UPDATE issuingrules
126
        SET fine = ?,
127
            finedays = ?,
128
            firstremind = ?,
129
            chargeperiod = ?,
130
            maxissueqty = ?,
131
            renewalsallowed = ?,
132
            reservesallowed = ?,
133
            issuelength = ?,
134
            lengthunit = ?,
135
            hardduedate = ?,
136
            hardduedatecompare = ?,
137
            rentaldiscount = ?,
138
            overduefinescap = ?
139
        WHERE branchcode = ?
140
            AND categorycode = ?
141
            AND itemtype = ?
142
    ");
143
86
    my $br = $branch; # branch
144
    my $br = $branch; # branch
87
    my $bor  = $input->param('categorycode'); # borrower category
145
    my $bor  = $input->param('categorycode'); # borrower category
88
    my $cat  = $input->param('itemtype');     # item type
146
    my $cat  = $input->param('itemtype');     # item type
Lines 121-135 elsif ($op eq "set-branch-defaults") { Link Here
121
    $maxissueqty = undef if $maxissueqty !~ /^\d+/;
179
    $maxissueqty = undef if $maxissueqty !~ /^\d+/;
122
    $holdallowed =~ s/\s//g;
180
    $holdallowed =~ s/\s//g;
123
    $holdallowed = undef if $holdallowed !~ /^\d+/;
181
    $holdallowed = undef if $holdallowed !~ /^\d+/;
124
    my $sth_search = $dbh->prepare("SELECT count(*) AS total
182
    my $sth_search = $dbh->prepare("
125
                                    FROM circ_rules
183
        SELECT count(*) AS total
126
                                    WHERE branchcode = ?");
184
        FROM circ_rules
127
    my $sth_insert = $dbh->prepare("INSERT INTO circ_rules
185
        WHERE branchcode = ?
128
                                    (branchcode, maxissueqty, holdallowed, returnbranch)
186
    ");
129
                                    VALUES (?, ?, ?, ?)");
187
    my $sth_insert = $dbh->prepare("
130
    my $sth_update = $dbh->prepare("UPDATE circ_rules
188
        INSERT INTO circ_rules (branchcode, maxissueqty, holdallowed, returnbranch)
131
                                    SET maxissueqty = ?, holdallowed = ?, returnbranch = ?
189
        VALUES (?, ?, ?, ?)
132
                                    WHERE branchcode = ?");
190
    ");
191
    my $sth_update = $dbh->prepare("
192
        UPDATE circ_rules
193
        SET maxissueqty = ?, holdallowed = ?, returnbranch = ?
194
        WHERE branchcode = ?
195
    ");
133
196
134
    $sth_search->execute( $branch );
197
    $sth_search->execute( $branch );
135
    my $res = $sth_search->fetchrow_hashref();
198
    my $res = $sth_search->fetchrow_hashref();
Lines 146-160 elsif ($op eq "add-branch-cat") { Link Here
146
    $maxissueqty = undef if $maxissueqty !~ /^\d+/;
209
    $maxissueqty = undef if $maxissueqty !~ /^\d+/;
147
210
148
    if ($categorycode eq "*") {
211
    if ($categorycode eq "*") {
149
        my $sth_search = $dbh->prepare("SELECT count(*) AS total
212
        my $sth_search = $dbh->prepare("
150
                                        FROM circ_rules
213
            SELECT count(*) AS total
151
                                        WHERE branchcode = ?");
214
            FROM circ_rules
152
        my $sth_insert = $dbh->prepare("INSERT INTO circ_rules
215
            WHERE branchcode = ?
153
                                        (branchcode, maxissueqty)
216
        ");
154
                                        VALUES (?, ?)");
217
        my $sth_insert = $dbh->prepare("
155
        my $sth_update = $dbh->prepare("UPDATE circ_rules
218
            INSERT INTO circ_rules (branchcode, maxissueqty)
156
                                        SET maxissueqty = ?
219
            VALUES (?, ?)
157
                                        WHERE branchcode = ?");
220
        ");
221
        my $sth_update = $dbh->prepare("
222
            UPDATE circ_rules
223
            SET maxissueqty = ?
224
            WHERE branchcode = ?
225
        ");
158
226
159
        $sth_search->execute( $branch );
227
        $sth_search->execute( $branch );
160
        my $res = $sth_search->fetchrow_hashref();
228
        my $res = $sth_search->fetchrow_hashref();
Lines 164-180 elsif ($op eq "add-branch-cat") { Link Here
164
            $sth_insert->execute( $maxissueqty, $branch );
232
            $sth_insert->execute( $maxissueqty, $branch );
165
        }
233
        }
166
    } else {
234
    } else {
167
        my $sth_search = $dbh->prepare("SELECT count(*) AS total
235
        my $sth_search = $dbh->prepare("
168
                                        FROM borrower_circ_rules
236
            SELECT count(*) AS total
169
                                        WHERE branchcode = ?
237
            FROM borrower_circ_rules
170
                                        AND categorycode = ?");
238
            WHERE branchcode = ?
171
        my $sth_insert = $dbh->prepare("INSERT INTO borrower_circ_rules
239
                AND categorycode = ?
172
                                        (branchcode, categorycode, maxissueqty)
240
        ");
173
                                        VALUES (?, ?, ?)");
241
        my $sth_insert = $dbh->prepare("
174
        my $sth_update = $dbh->prepare("UPDATE borrower_circ_rules
242
            INSERT INTO borrower_circ_rules
175
                                        SET maxissueqty = ?
243
                (branchcode, categorycode, maxissueqty)
176
                                        WHERE branchcode = ?
244
            VALUES (?, ?, ?)");
177
                                        AND categorycode = ?");
245
        my $sth_update = $dbh->prepare("
246
            UPDATE borrower_circ_rules
247
            SET maxissueqty = ?
248
            WHERE branchcode = ?
249
                AND categorycode = ?
250
        ");
178
        $sth_search->execute( $branch, $categorycode );
251
        $sth_search->execute( $branch, $categorycode );
179
        my $res = $sth_search->fetchrow_hashref();
252
        my $res = $sth_search->fetchrow_hashref();
180
        if ($res->{total}) {
253
        if ($res->{total}) {
Lines 192-206 elsif ($op eq "add-branch-item") { Link Here
192
    $holdallowed = undef if $holdallowed !~ /^\d+/;
265
    $holdallowed = undef if $holdallowed !~ /^\d+/;
193
266
194
    if ($itemtype eq "*") {
267
    if ($itemtype eq "*") {
195
        my $sth_search = $dbh->prepare("SELECT count(*) AS total
268
        my $sth_search = $dbh->prepare("
196
                                        FROM circ_rules
269
            SELECT count(*) AS total
197
                                        WHERE branchcode = ?");
270
            FROM circ_rules
198
        my $sth_insert = $dbh->prepare("INSERT INTO circ_rules
271
            WHERE branchcode = ?
199
                                        (branchcode, holdallowed, returnbranch)
272
        ");
200
                                        VALUES (?, ?, ?)");
273
        my $sth_insert = $dbh->prepare("
201
        my $sth_update = $dbh->prepare("UPDATE circ_rules
274
            INSERT INTO circ_rules
202
                                        SET holdallowed = ?, returnbranch = ?
275
                (branchcode, holdallowed, returnbranch)
203
                                        WHERE branchcode = ?");
276
            VALUES (?, ?, ?)
277
        ");
278
        my $sth_update = $dbh->prepare("
279
            UPDATE circ_rules
280
            SET holdallowed = ?, returnbranch = ?
281
            WHERE branchcode = ?
282
        ");
204
283
205
        $sth_search->execute( $branch );
284
        $sth_search->execute( $branch );
206
        my $res = $sth_search->fetchrow_hashref();
285
        my $res = $sth_search->fetchrow_hashref();
Lines 210-225 elsif ($op eq "add-branch-item") { Link Here
210
            $sth_insert->execute($branch, $holdallowed, $returnbranch);
289
            $sth_insert->execute($branch, $holdallowed, $returnbranch);
211
        }
290
        }
212
    } else {
291
    } else {
213
        my $sth_search = $dbh->prepare("SELECT count(*) AS total
292
        my $sth_search = $dbh->prepare("
214
                                        FROM item_circ_rules
293
            SELECT count(*) AS total
215
                                        WHERE itemtype = ?");
294
            FROM item_circ_rules
216
        my $sth_insert = $dbh->prepare("INSERT INTO item_circ_rules
295
            WHERE itemtype = ?
217
                                        (branchcode, itemtype, holdallowed, returnbranch)
296
        ");
218
                                        VALUES (?, ?, ?, ?)");
297
        my $sth_insert = $dbh->prepare("
219
        my $sth_update = $dbh->prepare("UPDATE item_circ_rules
298
            INSERT INTO item_circ_rules
220
                                        SET holdallowed = ?, returnbranch = ?
299
                (branchcode, itemtype, holdallowed, returnbranch)
221
                                        WHERE branchcode = ?
300
            VALUES (?, ?, ?, ?)
222
                                        AND itemtype = ?");
301
        ");
302
        my $sth_update = $dbh->prepare("
303
            UPDATE item_circ_rules
304
            SET holdallowed = ?, returnbranch = ?
305
            WHERE branchcode = ?
306
                AND itemtype = ?
307
        ");
223
        $sth_search->execute($itemtype);
308
        $sth_search->execute($itemtype);
224
        my $res = $sth_search->fetchrow_hashref();
309
        my $res = $sth_search->fetchrow_hashref();
225
        if ($res->{total}) {
310
        if ($res->{total}) {
Lines 240-246 for my $thisbranch (sort { $branches->{$a}->{branchname} cmp $branches->{$b}->{b Link Here
240
    };
325
    };
241
}
326
}
242
327
243
my $sth=$dbh->prepare("SELECT description,categorycode FROM categories ORDER BY description");
328
my $sth=$dbh->prepare("
329
    SELECT description,categorycode
330
    FROM categories
331
    ORDER BY description
332
");
244
$sth->execute;
333
$sth->execute;
245
my @category_loop;
334
my @category_loop;
246
while (my $data=$sth->fetchrow_hashref){
335
while (my $data=$sth->fetchrow_hashref){
Lines 248-254 while (my $data=$sth->fetchrow_hashref){ Link Here
248
}
337
}
249
338
250
$sth->finish;
339
$sth->finish;
251
$sth=$dbh->prepare("SELECT description,itemtype FROM itemtypes ORDER BY description");
340
$sth=$dbh->prepare("
341
    SELECT description,itemtype
342
    FROM itemtypes
343
    ORDER BY description
344
");
252
$sth->execute;
345
$sth->execute;
253
# $i=0;
346
# $i=0;
254
my @row_loop;
347
my @row_loop;
255
- 

Return to bug 8369