Bug 14045: Introduce the maxonsiteissueqty field as a copy of maxissueqty

This patch adds the new fields maxonsiteissueqty as a copy of the
existing maxissueqty field.

There is no brainy code here, it only adds the ability to fill the new
field from the admin interface (admin/smart-rules.pl).

Signed-off-by: Nicolas Legrand <nicolas.legrand@bulac.fr>

Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
This commit is contained in:
Jonathan Druart 2015-05-13 17:07:28 +02:00 committed by Tomas Cohen Arazi
parent c91b0d49a6
commit eda4070f2b
2 changed files with 97 additions and 46 deletions

View File

@ -111,6 +111,7 @@ elsif ($op eq 'add') {
my $firstremind = $input->param('firstremind');
my $chargeperiod = $input->param('chargeperiod');
my $maxissueqty = $input->param('maxissueqty');
my $maxonsiteissueqty = $input->param('maxonsiteissueqty');
my $renewalsallowed = $input->param('renewalsallowed');
my $renewalperiod = $input->param('renewalperiod');
my $norenewalbefore = $input->param('norenewalbefore');
@ -120,6 +121,8 @@ elsif ($op eq 'add') {
my $onshelfholds = $input->param('onshelfholds') || 0;
$maxissueqty =~ s/\s//g;
$maxissueqty = undef if $maxissueqty !~ /^\d+/;
$maxonsiteissueqty =~ s/\s//g;
$maxonsiteissueqty = undef if $maxonsiteissueqty !~ /^\d+/;
my $issuelength = $input->param('issuelength');
my $lengthunit = $input->param('lengthunit');
my $hardduedate = $input->param('hardduedate');
@ -128,7 +131,7 @@ elsif ($op eq 'add') {
my $rentaldiscount = $input->param('rentaldiscount');
my $opacitemholds = $input->param('opacitemholds') || 0;
my $overduefinescap = $input->param('overduefinescap') || undef;
$debug and warn "Adding $br, $bor, $itemtype, $fine, $maxissueqty";
$debug and warn "Adding $br, $bor, $itemtype, $fine, $maxissueqty, $maxonsiteissueqty";
my $schema = Koha::Database->new()->schema();
my $rs = $schema->resultset('Issuingrule');
@ -143,6 +146,7 @@ elsif ($op eq 'add') {
firstremind => $firstremind,
chargeperiod => $chargeperiod,
maxissueqty => $maxissueqty,
maxonsiteissueqty => $maxonsiteissueqty,
renewalsallowed => $renewalsallowed,
renewalperiod => $renewalperiod,
norenewalbefore => $norenewalbefore,
@ -164,10 +168,13 @@ elsif ($op eq 'add') {
elsif ($op eq "set-branch-defaults") {
my $categorycode = $input->param('categorycode');
my $maxissueqty = $input->param('maxissueqty');
my $maxonsiteissueqty = $input->param('maxonsiteissueqty');
my $holdallowed = $input->param('holdallowed');
my $returnbranch = $input->param('returnbranch');
$maxissueqty =~ s/\s//g;
$maxissueqty = undef if $maxissueqty !~ /^\d+/;
$maxonsiteissueqty =~ s/\s//g;
$maxonsiteissueqty = undef if $maxonsiteissueqty !~ /^\d+/;
$holdallowed =~ s/\s//g;
$holdallowed = undef if $holdallowed !~ /^\d+/;
@ -175,114 +182,137 @@ elsif ($op eq "set-branch-defaults") {
my $sth_search = $dbh->prepare("SELECT count(*) AS total
FROM default_circ_rules");
my $sth_insert = $dbh->prepare("INSERT INTO default_circ_rules
(maxissueqty, holdallowed, returnbranch)
VALUES (?, ?, ?)");
(maxissueqty, maxonsiteissueqty, holdallowed, returnbranch)
VALUES (?, ?, ?, ?)");
my $sth_update = $dbh->prepare("UPDATE default_circ_rules
SET maxissueqty = ?, holdallowed = ?, returnbranch = ?");
SET maxissueqty = ?, maxonsiteissueqty = ?, holdallowed = ?, returnbranch = ?");
$sth_search->execute();
my $res = $sth_search->fetchrow_hashref();
if ($res->{total}) {
$sth_update->execute($maxissueqty, $holdallowed, $returnbranch);
$sth_update->execute($maxissueqty, $maxonsiteissueqty, $holdallowed, $returnbranch);
} else {
$sth_insert->execute($maxissueqty, $holdallowed, $returnbranch);
$sth_insert->execute($maxissueqty, $maxonsiteissueqty, $holdallowed, $returnbranch);
}
} else {
my $sth_search = $dbh->prepare("SELECT count(*) AS total
FROM default_branch_circ_rules
WHERE branchcode = ?");
my $sth_insert = $dbh->prepare("INSERT INTO default_branch_circ_rules
(branchcode, maxissueqty, holdallowed, returnbranch)
VALUES (?, ?, ?, ?)");
(branchcode, maxissueqty, maxonsiteissueqty, holdallowed, returnbranch)
VALUES (?, ?, ?, ?, ?)");
my $sth_update = $dbh->prepare("UPDATE default_branch_circ_rules
SET maxissueqty = ?, holdallowed = ?, returnbranch = ?
SET maxissueqty = ?, maxonsiteissueqty = ?, holdallowed = ?, returnbranch = ?
WHERE branchcode = ?");
$sth_search->execute($branch);
my $res = $sth_search->fetchrow_hashref();
if ($res->{total}) {
$sth_update->execute($maxissueqty, $holdallowed, $returnbranch, $branch);
$sth_update->execute($maxissueqty, $maxonsiteissueqty, $holdallowed, $returnbranch, $branch);
} else {
$sth_insert->execute($branch, $maxissueqty, $holdallowed, $returnbranch);
$sth_insert->execute($branch, $maxissueqty, $maxonsiteissueqty, $holdallowed, $returnbranch);
}
}
}
elsif ($op eq "add-branch-cat") {
my $categorycode = $input->param('categorycode');
my $maxissueqty = $input->param('maxissueqty');
my $maxonsiteissueqty = $input->param('maxonsiteissueqty');
$maxissueqty =~ s/\s//g;
$maxissueqty = undef if $maxissueqty !~ /^\d+/;
$maxonsiteissueqty =~ s/\s//g;
$maxonsiteissueqty = undef if $maxonsiteissueqty !~ /^\d+/;
if ($branch eq "*") {
if ($categorycode eq "*") {
my $sth_search = $dbh->prepare("SELECT count(*) AS total
FROM default_circ_rules");
my $sth_insert = $dbh->prepare("INSERT INTO default_circ_rules
(maxissueqty)
VALUES (?)");
my $sth_update = $dbh->prepare("UPDATE default_circ_rules
SET maxissueqty = ?");
my $sth_insert = $dbh->prepare(q|
INSERT INTO default_circ_rules
(maxissueqty, maxonsiteissueqty)
VALUES (?, ?)
|);
my $sth_update = $dbh->prepare(q|
UPDATE default_circ_rules
SET maxissueqty = ?,
maxonsiteissueqty = ?
|);
$sth_search->execute();
my $res = $sth_search->fetchrow_hashref();
if ($res->{total}) {
$sth_update->execute($maxissueqty);
$sth_update->execute($maxissueqty, $maxonsiteissueqty);
} else {
$sth_insert->execute($maxissueqty);
$sth_insert->execute($maxissueqty, $maxonsiteissueqty);
}
} else {
my $sth_search = $dbh->prepare("SELECT count(*) AS total
FROM default_borrower_circ_rules
WHERE categorycode = ?");
my $sth_insert = $dbh->prepare("INSERT INTO default_borrower_circ_rules
(categorycode, maxissueqty)
VALUES (?, ?)");
my $sth_update = $dbh->prepare("UPDATE default_borrower_circ_rules
SET maxissueqty = ?
WHERE categorycode = ?");
my $sth_insert = $dbh->prepare(q|
INSERT INTO default_borrower_circ_rules
(categorycode, maxissueqty, maxonsiteissueqty)
VALUES (?, ?, ?)
|);
my $sth_update = $dbh->prepare(q|
UPDATE default_borrower_circ_rules
SET maxissueqty = ?,
maxonsiteissueqty = ?
WHERE categorycode = ?
|);
$sth_search->execute($branch);
my $res = $sth_search->fetchrow_hashref();
if ($res->{total}) {
$sth_update->execute($maxissueqty, $categorycode);
$sth_update->execute($maxissueqty, $maxonsiteissueqty, $categorycode);
} else {
$sth_insert->execute($categorycode, $maxissueqty);
$sth_insert->execute($categorycode, $maxissueqty, $maxonsiteissueqty);
}
}
} elsif ($categorycode eq "*") {
my $sth_search = $dbh->prepare("SELECT count(*) AS total
FROM default_branch_circ_rules
WHERE branchcode = ?");
my $sth_insert = $dbh->prepare("INSERT INTO default_branch_circ_rules
(branchcode, maxissueqty)
VALUES (?, ?)");
my $sth_update = $dbh->prepare("UPDATE default_branch_circ_rules
SET maxissueqty = ?
WHERE branchcode = ?");
my $sth_insert = $dbh->prepare(q|
INSERT INTO default_branch_circ_rules
(branchcode, maxissueqty, maxonsiteissueqty)
VALUES (?, ?, ?)
|);
my $sth_update = $dbh->prepare(q|
UPDATE default_branch_circ_rules
SET maxissueqty = ?,
maxonsiteissueqty = ?
WHERE branchcode = ?
|);
$sth_search->execute($branch);
my $res = $sth_search->fetchrow_hashref();
if ($res->{total}) {
$sth_update->execute($maxissueqty, $branch);
$sth_update->execute($maxissueqty, $maxonsiteissueqty, $branch);
} else {
$sth_insert->execute($branch, $maxissueqty);
$sth_insert->execute($branch, $maxissueqty, $maxonsiteissueqty);
}
} else {
my $sth_search = $dbh->prepare("SELECT count(*) AS total
FROM branch_borrower_circ_rules
WHERE branchcode = ?
AND categorycode = ?");
my $sth_insert = $dbh->prepare("INSERT INTO branch_borrower_circ_rules
(branchcode, categorycode, maxissueqty)
VALUES (?, ?, ?)");
my $sth_update = $dbh->prepare("UPDATE branch_borrower_circ_rules
SET maxissueqty = ?
WHERE branchcode = ?
AND categorycode = ?");
my $sth_insert = $dbh->prepare(q|
INSERT INTO branch_borrower_circ_rules
(branchcode, categorycode, maxissueqty, maxonsiteissueqty)
VALUES (?, ?, ?, ?)
|);
my $sth_update = $dbh->prepare(q|
UPDATE branch_borrower_circ_rules
SET maxissueqty = ?,
maxonsiteissueqty = ?
WHERE branchcode = ?
AND categorycode = ?
|);
$sth_search->execute($branch, $categorycode);
my $res = $sth_search->fetchrow_hashref();
if ($res->{total}) {
$sth_update->execute($maxissueqty, $branch, $categorycode);
$sth_update->execute($maxissueqty, $maxonsiteissueqty, $branch, $categorycode);
} else {
$sth_insert->execute($branch, $categorycode, $maxissueqty);
$sth_insert->execute($branch, $categorycode, $maxissueqty, $maxonsiteissueqty);
}
}
}
@ -455,6 +485,7 @@ my @sorted_branch_cat_rules = sort { $a->{'humancategorycode'} cmp $b->{'humanca
# note undef maxissueqty so that template can deal with them
foreach my $entry (@sorted_branch_cat_rules, @sorted_row_loop) {
$entry->{unlimited_maxissueqty} = 1 unless defined($entry->{maxissueqty});
$entry->{unlimited_maxonsiteissueqty} = 1 unless defined($entry->{maxonsiteissueqty});
}
@sorted_row_loop = sort by_category_and_itemtype @row_loop;
@ -516,6 +547,7 @@ if ($defaults) {
$template->param(default_holdallowed_same => 1) if($defaults->{holdallowed} == 1);
$template->param(default_holdallowed_any => 1) if($defaults->{holdallowed} == 2);
$template->param(default_maxissueqty => $defaults->{maxissueqty});
$template->param(default_maxonsiteissueqty => $defaults->{maxonsiteissueqty});
$template->param(default_returnbranch => $defaults->{returnbranch});
}

View File

@ -38,7 +38,7 @@ $(document).ready(function() {
itm = $(this).text();
itm = itm.replace(/^\s*|\s*$/g,'');
var current_column = $("#edit_row td:eq("+i+")");
if ( i != 5 ) {
if ( i != 6 ) {
$(current_column).find("input[type='text']").val(itm);
// select the corresponding option
$(current_column).find("select option").each(function(){
@ -58,8 +58,8 @@ $(document).ready(function() {
// Remove potential previous input added
$(current_column).find("input").remove();
$(current_column).append("<input type='hidden' name='"+name+"' value='"+val+"' />");
} else if ( i == 2 ) {
// If the value is not an integer for "Current checkouts allowed"
} else if ( i == 2 || i == 3 ) {
// If the value is not an integer for "Current checkouts allowed" or "Current on-site checkouts allowed"
// The value is "Unlimited" (or an equivalent translated string)
// an it should be set to an empty string
if( !((parseFloat(itm) == parseInt(itm)) && !isNaN(itm)) ) {
@ -142,6 +142,7 @@ for="tobranch"><strong>Clone these rules to:</strong></label> <input type="hidde
<th>Patron category</th>
<th>Item type</th>
<th>Current checkouts allowed</th>
<th>Current on-site checkouts allowed</th>
<th>Loan period</th>
<th>Unit</th>
<th>Hard due date</th>
@ -183,6 +184,12 @@ for="tobranch"><strong>Clone these rules to:</strong></label> <input type="hidde
[% rule.maxissueqty %]
[% END %]
</td>
<td>[% IF rule.unlimited_maxonsiteissueqty %]
Unlimited
[% ELSE %]
[% rule.maxonsiteissueqty %]
[% END %]
</td>
<td>[% rule.issuelength %]</td>
<td>
[% rule.lengthunit %]
@ -247,6 +254,7 @@ for="tobranch"><strong>Clone these rules to:</strong></label> <input type="hidde
</select>
</td>
<td><input type="text" name="maxissueqty" id="maxissueqty" size="3" /></td>
<td><input type="text" name="maxonsiteissueqty" id="maxonsiteissueqty" size="3" /></td>
<td><input type="text" name="issuelength" id="issuelength" size="3" /> </td>
<td>
<select name="lengthunit" id="lengthunit">
@ -338,6 +346,7 @@ for="tobranch"><strong>Clone these rules to:</strong></label> <input type="hidde
<tr>
<th>&nbsp;</th>
<th>Total current checkouts allowed</th>
<th>Total current on-site checkouts allowed</th>
<th>Hold policy</th>
<th>Return policy</th>
<th>&nbsp;</th>
@ -346,6 +355,7 @@ for="tobranch"><strong>Clone these rules to:</strong></label> <input type="hidde
<tr>
<td><em>Defaults[% UNLESS ( default_rules ) %] (not set)[% END %]</em></td>
<td><input type="text" name="maxissueqty" size="3" value="[% default_maxissueqty %]"/></td>
<td><input type="text" name="maxonsiteissueqty" size="3" value="[% default_onsitemaxissueqty %]"/></td>
<td>
<select name="holdallowed">
[% IF ( default_holdallowed_any ) %]
@ -420,6 +430,7 @@ for="tobranch"><strong>Clone these rules to:</strong></label> <input type="hidde
<tr>
<th>Patron category</th>
<th>Total current checkouts allowed</th>
<th>Total current on-site checkouts allowed</th>
<th>&nbsp;</th>
</tr>
[% FOREACH branch_cat_rule_loo IN branch_cat_rule_loop %]
@ -440,6 +451,13 @@ for="tobranch"><strong>Clone these rules to:</strong></label> <input type="hidde
[% branch_cat_rule_loo.maxissueqty %]
[% END %]
</td>
<td>[% IF ( branch_cat_rule_loo.unlimited_maxonsiteissueqty ) %]
Unlimited
[% ELSE %]
[% branch_cat_rule_loo.maxonsiteissueqty %]
[% END %]
</td>
<td>
<a class="button" href="/cgi-bin/koha/admin/smart-rules.pl?op=delete-branch-cat&amp;categorycode=[% branch_cat_rule_loo.categorycode %]&amp;branch=[% current_branch %]">Delete</a>
</td>
@ -454,6 +472,7 @@ for="tobranch"><strong>Clone these rules to:</strong></label> <input type="hidde
</select>
</td>
<td><input name="maxissueqty" size="3" /></td>
<td><input name="maxonsiteissueqty" size="3" /></td>
<td><input type="submit" value="Add" class="submit" /></td>
</tr>
</table>