Issuing rules are now explicitly sorted by patron category,
then item type.  The default patron category sorts last; within
a list of item types for a given patron category, the default
item type sorts last.  This follows the order in which
the issuing rules are applied.

Since the primary sort is patron category, also moved that
to be the first column in the issuing rules table.
---
 admin/smart-rules.pl                               |   37 +++++++++++++++++++-
 .../prog/en/modules/admin/smart-rules.tmpl         |   32 ++++++++++-------
 2 files changed, 55 insertions(+), 14 deletions(-)

diff --git a/admin/smart-rules.pl b/admin/smart-rules.pl
index bc9f9a7..2b6a1be 100755
--- a/admin/smart-rules.pl
+++ b/admin/smart-rules.pl
@@ -125,11 +125,46 @@ while (my $row = $sth2->fetchrow_hashref) {
     push @row_loop, $row;
 }
 $sth->finish;
+
+my @sorted_row_loop = sort by_category_and_itemtype @row_loop;
+
 $template->param(categoryloop => [EMAIL PROTECTED],
                         itemtypeloop => [EMAIL PROTECTED],
-                        rules => [EMAIL PROTECTED],
+                        rules => [EMAIL PROTECTED],
                         branchloop => [EMAIL PROTECTED],
                         humanbranch => ($branch ne '*' ? 
$branches->{$branch}->{branchname} : ''),
                         branch => $branch
                         );
 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_humanitemtype'}) {
+        return ($b->{'default_humanitemtype'} ? 0 : 1);
+    } elsif ($b->{'default_humanitemtype'}) {
+        return -1;
+    } else {
+        return $a->{'humanitemtype'} cmp $b->{'humanitemtype'};
+    }
+}
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tmpl 
b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tmpl
index a00c16e..4bc47cb 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tmpl
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tmpl
@@ -59,20 +59,26 @@ $(document).ready(function() {
             <input type="hidden" name="op" value="add" />
             <table>
             <tr>
-                <th>Item Type</th><th>Patron 
Category</th><th>Amount</th><th>Grace<br />Period</th><th>Charging<br 
/>Interval</th><th>Amount<br />Loanable</th><th>Loan time</th><th>&nbsp;</th>
+                <th>Patron Category</th>
+                <th>Item Type</th>
+                <th>Amount</th>
+                <th>Grace Period</th>
+                <th>Charging Interval</th>
+                <th>Amoun Loanable</th>
+                <th>Loan time</th><th>&nbsp;</th>
             </tr>
             <!-- TMPL_LOOP NAME="rules" -->
                 <tr>
-                    <td><!-- TMPL_IF NAME="default_humanitemtype" -->
+                    <td><!-- TMPL_IF NAME="default_humancategorycode" -->
                             Any
                         <!-- TMPL_ELSE -->
-                            <!-- TMPL_VAR NAME="humanitemtype" -->
+                            <!-- TMPL_VAR NAME="humancategorycode" -->
                         <!-- /TMPL_IF -->
                     </td>
-                    <td><!-- TMPL_IF NAME="default_humancategorycode" -->
+                    <td><!-- TMPL_IF NAME="default_humanitemtype" -->
                             Any
                         <!-- TMPL_ELSE -->
-                            <!-- TMPL_VAR NAME="humancategorycode" -->
+                            <!-- TMPL_VAR NAME="humanitemtype" -->
                         <!-- /TMPL_IF -->
                     </td>
                     <td>$<!-- TMPL_VAR NAME="fine" --></td>
@@ -87,18 +93,18 @@ $(document).ready(function() {
             <!-- /TMPL_LOOP -->
                 <tr>
                     <td>
-                        <select name="itemtype" style="width:13em;">
-                            <option value="*">Any</option>
-                        <!-- TMPL_LOOP NAME="itemtypeloop" -->
-                            <option value="<!-- TMPL_VAR NAME="itemtype" 
-->"><!-- TMPL_VAR NAME="description" --></option>
+                        <select name="categorycode">
+                            <option value="*">Default</option>
+                        <!-- TMPL_LOOP NAME="categoryloop" -->
+                            <option value="<!-- TMPL_VAR NAME="categorycode" 
-->"><!-- TMPL_VAR NAME="description" --></option>
                         <!-- /TMPL_LOOP -->
                         </select>
                     </td>
                     <td>
-                        <select name="categorycode">
-                            <option value="*">Any</option>
-                        <!-- TMPL_LOOP NAME="categoryloop" -->
-                            <option value="<!-- TMPL_VAR NAME="categorycode" 
-->"><!-- TMPL_VAR NAME="description" --></option>
+                        <select name="itemtype" style="width:13em;">
+                            <option value="*">Default</option>
+                        <!-- TMPL_LOOP NAME="itemtypeloop" -->
+                            <option value="<!-- TMPL_VAR NAME="itemtype" 
-->"><!-- TMPL_VAR NAME="description" --></option>
                         <!-- /TMPL_LOOP -->
                         </select>
                     </td>
-- 
1.5.5.GIT

_______________________________________________
Koha-patches mailing list
[email protected]
http://lists.koha.org/mailman/listinfo/koha-patches

Reply via email to