@@ -, +, @@ --- admin/smart-rules.pl | 76 +--- .../prog/en/modules/admin/smart-rules.tt | 432 +++++++++++---------- 2 files changed, 229 insertions(+), 279 deletions(-) --- a/admin/smart-rules.pl +++ a/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'}; - } -} --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tt +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tt @@ -3,6 +3,8 @@ [% USE Koha %] [% USE Branches %] [% USE Categories %] +[% USE KohaDates %] +[% USE ItemTypes %] [% USE CirculationRules %] [% SET footerjs = 1 %] @@ -59,7 +61,7 @@ [% PROCESS options_for_libraries libraries => Branches.all( selected => current_branch, unfiltered => 1 ) %] - [% IF ( definedbranch ) %] + [% IF ( rules.count ) %]
@@ -799,8 +809,20 @@ [% MACRO jsinclude BLOCK %] [% Asset.js("js/admin-menu.js") | $raw %] + [% INCLUDE 'datatables.inc' %] [% INCLUDE 'calendar.inc' %]