From 6569179efb360ce108d0e5d35bd754234b21cf84 Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Tue, 9 Apr 2019 16:39:22 +0000 Subject: [PATCH] Bug 21946: Use objects for displaying circulation rules --- admin/smart-rules.pl | 76 +--- .../prog/en/modules/admin/smart-rules.tt | 432 +++++++++++---------- 2 files changed, 229 insertions(+), 279 deletions(-) diff --git a/admin/smart-rules.pl b/admin/smart-rules.pl index 927533d..d283bae 100755 --- a/admin/smart-rules.pl +++ b/admin/smart-rules.pl @@ -508,51 +508,9 @@ $template->param( my $patron_categories = Koha::Patron::Categories->search({}, { order_by => ['description'] }); -my @row_loop; my $itemtypes = Koha::ItemTypes->search_with_localization; -my $sth2 = $dbh->prepare(" - SELECT issuingrules.*, - itemtypes.description AS humanitemtype, - categories.description AS humancategorycode, - COALESCE( localization.translation, itemtypes.description ) AS translated_description - FROM issuingrules - LEFT JOIN itemtypes - ON (itemtypes.itemtype = issuingrules.itemtype) - LEFT JOIN categories - ON (categories.categorycode = issuingrules.categorycode) - LEFT JOIN localization ON issuingrules.itemtype = localization.code - AND localization.entity = 'itemtypes' - AND localization.lang = ? - WHERE issuingrules.branchcode = ? -"); -$sth2->execute($language, $branch); - -while (my $row = $sth2->fetchrow_hashref) { - $row->{'current_branch'} ||= $row->{'branchcode'}; - $row->{humanitemtype} ||= $row->{itemtype}; - $row->{default_translated_description} = 1 if $row->{humanitemtype} eq '*'; - $row->{'humancategorycode'} ||= $row->{'categorycode'}; - $row->{'default_humancategorycode'} = 1 if $row->{'humancategorycode'} eq '*'; - $row->{'fine'} = sprintf('%.2f', $row->{'fine'}); - if ($row->{'hardduedate'} && $row->{'hardduedate'} ne '0000-00-00') { - my $harddue_dt = eval { dt_from_string( $row->{'hardduedate'} ) }; - $row->{'hardduedate'} = eval { output_pref( { dt => $harddue_dt, dateonly => 1 } ) } if ( $harddue_dt ); - $row->{'hardduedatebefore'} = 1 if ($row->{'hardduedatecompare'} == -1); - $row->{'hardduedateexact'} = 1 if ($row->{'hardduedatecompare'} == 0); - $row->{'hardduedateafter'} = 1 if ($row->{'hardduedatecompare'} == 1); - } else { - $row->{'hardduedate'} = 0; - } - if ($row->{no_auto_renewal_after_hard_limit}) { - my $dt = eval { dt_from_string( $row->{no_auto_renewal_after_hard_limit} ) }; - $row->{no_auto_renewal_after_hard_limit} = eval { output_pref( { dt => $dt, dateonly => 1 } ) } if $dt; - } - - push @row_loop, $row; -} - -my @sorted_row_loop = sort by_category_and_itemtype @row_loop; +my $issuing_rules = Koha::IssuingRules->search({ branchcode => $branch }); my $sth_branch_item; if ($branch eq "*") { @@ -628,41 +586,11 @@ $template->param(default_rules => ($defaults ? 1 : 0)); $template->param( patron_categories => $patron_categories, itemtypeloop => $itemtypes, - rules => \@sorted_row_loop, + rules => $issuing_rules, humanbranch => ($branch ne '*' ? $branch : ''), current_branch => $branch, - definedbranch => scalar(@sorted_row_loop)>0 ); output_html_with_http_headers $input, $cookie, $template->output; exit 0; -# sort by patron category, then item type, putting -# default entries at the bottom -sub by_category_and_itemtype { - unless (by_category($a, $b)) { - return by_itemtype($a, $b); - } -} - -sub by_category { - my ($a, $b) = @_; - if ($a->{'default_humancategorycode'}) { - return ($b->{'default_humancategorycode'} ? 0 : 1); - } elsif ($b->{'default_humancategorycode'}) { - return -1; - } else { - return $a->{'humancategorycode'} cmp $b->{'humancategorycode'}; - } -} - -sub by_itemtype { - my ($a, $b) = @_; - if ($a->{default_translated_description}) { - return ($b->{'default_translated_description'} ? 0 : 1); - } elsif ($b->{'default_translated_description'}) { - return -1; - } else { - return lc $a->{'translated_description'} cmp lc $b->{'translated_description'}; - } -} diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tt index e41d59b..c78c4d3 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tt @@ -2,6 +2,8 @@ [% USE Asset %] [% USE Branches %] [% USE Categories %] +[% USE KohaDates %] +[% USE ItemTypes %] [% USE CirculationRules %] [% SET footerjs = 1 %] @@ -58,7 +60,7 @@ [% PROCESS options_for_libraries libraries => Branches.all( selected => current_branch, unfiltered => 1 ) %] - [% IF ( definedbranch ) %] + [% IF ( rules.count ) %]
@@ -75,181 +77,224 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + [% FOREACH rule IN rules %] - - - + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - [% END %] + + [% END %] + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Patron categoryItem typeActionsNoteCurrent checkouts allowedCurrent on-site checkouts allowedLoan periodUnitHard due dateFine amountFine charging intervalWhen to chargeFine grace periodOverdue fines cap (amount)Cap fine at replacement priceSuspension in days (day)Max. suspension duration (day)Suspension charging intervalRenewals allowed (count)Renewal periodNo renewal beforeAutomatic renewalNo automatic renewal afterNo automatic renewal after (hard limit)Holds allowed (total)Holds allowed (daily)Holds per record (count)On shelf holds allowedItem level holdsArticle requestsRental discount (%)Actions
 Patron category Item typeActionsNoteCurrent checkouts allowedCurrent on-site checkouts allowedLoan periodUnitHard due dateFine amountFine charging intervalWhen to chargeFine grace periodOverdue fines cap (amount)Cap fine at replacement priceSuspension in days (day)Max. suspension duration (day)Suspension charging intervalRenewals allowed (count)Renewal periodNo renewal beforeAutomatic renewalNo automatic renewal afterNo automatic renewal after (hard limit)Holds allowed (total)Holds allowed (daily)Holds per record (count)On shelf holds allowedItem level holdsArticle requestsRental discount (%)Actions
 Patron category Item type NoteCurrent checkouts allowedCurrent on-site checkouts allowedLoan periodUnitHard due dateFine amountFine charging intervalCharge when?Fine grace periodOverdue fines cap (amount)Cap fine at replacement priceSuspension in days (day)Max. suspension duration (day)Suspension charging intervalRenewals allowed (count)Renewal periodNo renewal beforeAutomatic renewalNo automatic renewal afterNo automatic renewal after (hard limit)Holds allowed (total)Holds allowed (daily)Holds per record (count)On shelf holds allowedItem level holdsArticle requestsRental discount (%) 
[% IF ( rule.default_humancategorycode ) %] - All - [% ELSE %] - [% rule.humancategorycode | html %] - [% END %] - [% IF rule.default_translated_description %] - All - [% ELSE %] - [% rule.translated_description | html %] - [% END %] - - Edit - Delete - [% IF ( rule.categorycode == '*' ) %]1[% ELSE %]0[% END %][% IF ( rule.categorycode == '*' ) %] + All + [% ELSE %] + [% Categories.GetName(rule.categorycode) | html %] + [% END %] + [% IF ( rule.itemtype == '*' ) %]1[% ELSE %]0[% END %][% IF rule.itemtype == '*' %] + All + [% ELSE %] + [% ItemTypes.GetDescription(rule.itemtype) | html %] + [% END %] + + Edit + Delete + - [% IF rule.note %] - View note - [% ELSE %] [% END %] - - [% SET rule_value = CirculationRules.Get( rule.branchcode, rule.categorycode, rule.itemtype, 'maxissueqty' ) %] - [% IF rule_value %] - [% rule_value | html %] - [% ELSE %] - Unlimited - [% END %] - - [% SET rule_value = CirculationRules.Get( rule.branchcode, rule.categorycode, rule.itemtype, 'maxonsiteissueqty' ) %] - [% IF rule_value %] - [% rule_value | html %] - [% ELSE %] - Unlimited - [% END %] - [% rule.issuelength | html %] - [% rule.lengthunit | html %] - - [% IF ( rule.hardduedate ) %] - [% IF ( rule.hardduedatebefore ) %] - before [% rule.hardduedate | html %] - - [% ELSIF ( rule.hardduedateexact ) %] - on [% rule.hardduedate | html %] - - [% ELSIF ( rule.hardduedateafter ) %] - after [% rule.hardduedate | html %] - - [% END %] - [% ELSE %] - None defined - [% END %] - [% rule.fine | html %][% rule.chargeperiod | html %] - [% IF rule.chargeperiod_charge_at %] - Start of interval - [% ELSE %] - End of interval - [% END %] - [% rule.firstremind | html %][% rule.overduefinescap FILTER format("%.2f") %] - [% IF rule.cap_fine_to_replacement_price %] - - [% ELSE %] - - [% END %] - [% rule.finedays | html %][% rule.maxsuspensiondays | html %][% rule.suspension_chargeperiod | html %][% rule.renewalsallowed | html %][% rule.renewalperiod | html %][% rule.norenewalbefore | html %] - [% IF ( rule.auto_renew ) %] - Yes - [% ELSE %] - No - [% END %] - [% rule.no_auto_renewal_after | html %][% rule.no_auto_renewal_after_hard_limit | html %][% rule.reservesallowed | html %][% IF rule.unlimited_holds_per_day %] - Unlimited - [% ELSE %] - [% rule.holds_per_day | html %] - [% END %] - [% rule.holds_per_record | html %] - [% IF rule.onshelfholds == 1 %] - Yes - [% ELSIF rule.onshelfholds == 2 %] - If all unavailable - [% ELSE %] - If any unavailable - [% END %] - - [% IF rule.opacitemholds == 'F'%] - Force - [% ELSIF rule.opacitemholds == 'Y'%] - Allow - [% ELSE %] - Don't allow - [% END %] - - [% IF rule.article_requests == 'no' %] - No - [% ELSIF rule.article_requests == 'yes' %] - Yes - [% ELSIF rule.article_requests == 'bib_only' %] - Record only - [% ELSIF rule.article_requests == 'item_only' %] - Item only - [% END %] - [% rule.rentaldiscount | html %] - Edit - Delete - + [% IF rule.note %] + View note + [% ELSE %] [% END %] + + [% SET rule_value = CirculationRules.Get( rule.branchcode, rule.categorycode, rule.itemtype, 'maxissueqty' ) %] + [% IF rule_value %] + [% rule_value | html %] + [% ELSE %] + Unlimited + [% END %] + + [% SET rule_value = CirculationRules.Get( rule.branchcode, rule.categorycode, rule.itemtype, 'maxonsiteissueqty' ) %] + [% IF rule_value %] + [% rule_value | html %] + [% ELSE %] + Unlimited + [% END %] + [% rule.issuelength | html %] + [% rule.lengthunit | html %] + + [% IF ( rule.hardduedate ) %] + [% IF ( rule.hardduedatecompare < 0 ) %] + before [% rule.hardduedate | $KohaDates %] + + [% ELSIF ( rule.hardduedatecompare == 0 ) %] + on [% rule.hardduedate | $KohaDates %] + + [% ELSIF ( rule.hardduedatecompare > 1 ) %] + after [% rule.hardduedate | $KohaDates %] + + [% END %] + [% ELSE %] + None defined + [% END %] + [% rule.fine FILTER format("%.2f") %][% rule.chargeperiod | html %] + [% IF rule.chargeperiod_charge_at %] + Start of interval + [% ELSE %] + End of interval + [% END %] + [% rule.firstremind | html %][% rule.overduefinescap FILTER format("%.2f") %] + [% IF rule.cap_fine_to_replacement_price %] + + [% ELSE %] + + [% END %] + [% rule.finedays | html %][% rule.maxsuspensiondays | html %][% rule.suspension_chargeperiod | html %][% rule.renewalsallowed | html %][% rule.renewalperiod | html %][% rule.norenewalbefore | html %] + [% IF ( rule.auto_renew ) %] + Yes + [% ELSE %] + No + [% END %] + [% rule.no_auto_renewal_after | html %][% rule.no_auto_renewal_after_hard_limit | $KohaDates %][% rule.reservesallowed | html %][% IF NOT rule.holds_per_day.defined %] + Unlimited + [% ELSE %] + [% rule.holds_per_day | html %] + [% END %] + [% rule.holds_per_record | html %] + [% IF rule.onshelfholds == 1 %] + Yes + [% ELSIF rule.onshelfholds == 2 %] + If all unavailable + [% ELSE %] + If any unavailable + [% END %] + + [% IF rule.opacitemholds == 'F'%] + Force + [% ELSIF rule.opacitemholds == 'Y'%] + Allow + [% ELSE %] + Don't allow + [% END %] + + [% IF rule.article_requests == 'no' %] + No + [% ELSIF rule.article_requests == 'yes' %] + Yes + [% ELSIF rule.article_requests == 'bib_only' %] + Record only + [% ELSIF rule.article_requests == 'item_only' %] + Item only + [% END %] + [% rule.rentaldiscount | html %] + Edit + Delete +
2 0
Patron categoryItem type NoteCurrent checkouts allowedCurrent on-site checkouts allowedLoan periodUnitHard due dateFine amountFine charging intervalCharge when?Fine grace periodOverdue fines cap (amount)Cap fine at replacement priceSuspension in days (day)Max. suspension duration (day)Suspension charging intervalRenewals allowed (count)Renewal periodNo renewal beforeAutomatic renewalNo automatic renewal afterNo automatic renewal after (hard limit)Holds allowed (total)Holds allowed (daily)Holds per record (count)On shelf holds allowedItem level holdsArticle requestsRental discount (%) 
@@ -798,8 +808,20 @@ [% MACRO jsinclude BLOCK %] [% Asset.js("js/admin-menu.js") | $raw %] + [% INCLUDE 'datatables.inc' %] [% INCLUDE 'calendar.inc' %]