Bug 8821: make receive shipment page hide inactive funds like new order form
authorOwen Leonard <oleonard@myacpl.org>
Fri, 19 Jul 2013 13:07:52 +0000 (09:07 -0400)
committerGalen Charlton <gmc@esilibrary.com>
Mon, 16 Sep 2013 16:26:12 +0000 (16:26 +0000)
This patch adapts the fund-handling code from neworderempty.pl
in order to limit the display of funds by default to active ones,
with the option to check a box to display all funds.

This patch also adds "(inactive)" to the display of funds on this and
the neworderempty.tt template because it seemed like that was useful
information.

To test, make sure you have both active and inactive funds.
Start the process of receiving a shipment. The "fund" option
in the receive shipment form should show only active funds.
Checking the "show all" checkbox should allow you to choose
from both active and inactive funds.

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Jonathan Druart <jonathan.druart@biblibre.com>
Signed-off-by: Galen Charlton <gmc@esilibrary.com>
acqui/parcels.pl
koha-tmpl/intranet-tmpl/prog/en/modules/acqui/neworderempty.tt
koha-tmpl/intranet-tmpl/prog/en/modules/acqui/parcels.tt

index fbfa9fa..df02e21 100755 (executable)
@@ -179,13 +179,25 @@ if ($count_parcels) {
     $template->param( searchresults => $loopres, count => $count_parcels );
 }
 
-my $budgets = GetBudgets();
-my @budgets_loop;
-foreach my $budget (@$budgets) {
-    next unless CanUserUseBudget($loggedinuser, $budget, $flags);
-    push @budgets_loop, $budget;
+# build budget list
+my $budget_loop = [];
+my $budgets = GetBudgetHierarchy;
+foreach my $r (@{$budgets}) {
+    next unless (CanUserUseBudget($loggedinuser, $r, $flags));
+    if (!defined $r->{budget_amount} || $r->{budget_amount} == 0) {
+        next;
+    }
+    push @{$budget_loop}, {
+        b_id  => $r->{budget_id},
+        b_txt => $r->{budget_name},
+        b_active => $r->{budget_period_active},
+    };
 }
 
+@{$budget_loop} =
+  sort { uc( $a->{b_txt}) cmp uc( $b->{b_txt}) } @{$budget_loop};
+
+
 $template->param(
     orderby                  => $order,
     filter                   => $code,
@@ -196,7 +208,7 @@ $template->param(
     shipmentdate_today       => C4::Dates->new()->output(),
     booksellerid             => $booksellerid,
     GST                      => C4::Context->preference('gist'),
-    budgets                  => \@budgets_loop,
+    budgets                  => $budget_loop,
 );
 
 output_html_with_http_headers $input, $cookie, $template->output;
index c7f9be0..c261530 100644 (file)
@@ -421,7 +421,7 @@ $(document).ready(function()
                         <option value="[% budget_loo.b_id %]" selected="selected">[% budget_loo.b_txt %]</option>
                     [% ELSE %]
                         [% IF ( budget_loo.b_active ) %]<option value="[% budget_loo.b_id %]">[% budget_loo.b_txt %]</option>
-                        [% ELSE %]<option value="[% budget_loo.b_id %]" class="b_inactive">[% budget_loo.b_txt %]</option>
+                        [% ELSE %]<option value="[% budget_loo.b_id %]" class="b_inactive">[% budget_loo.b_txt %] (inactive)</option>
                         [% END %]
                     [% END %]
                 [% END %]
index cadd29c..59e3cdc 100644 (file)
     var parcelst = $("#parcelst").dataTable($.extend(true, {}, dataTablesDefaults, {
         "sPaginationType": "four_button"
     } ) );
+
+    //keep a copy of all budgets before removing the inactives
+    var budgetId = $("#shipmentcost_budgetid");
+    var disabledBudgetsCopy = budgetId.html();
+    $('.b_inactive').remove();
+
+    $('#showallfunds').click(function() {
+        if ($(this).is(":checked")) {
+            budgetId.html(disabledBudgetsCopy); //Puts back all the funds
+        }
+        else {
+            $('.b_inactive').remove();
+        }
+    });
  });
  //]]>
 </script>
             <select id="shipmentcost_budgetid" name="shipmentcost_budgetid">
                 <option value="">No fund</option>
                 [% FOREACH budget IN budgets %]
-                    <option value="[% budget.budget_id %]">[% budget.budget_name %]</option>
+                    [% IF ( budget.b_active ) %]
+                        <option value="[% budget.b_id %]">[% budget.b_txt %]</option>
+                    [% ELSE %]
+                        <option value="[% budget.b_id %]" class="b_inactive">[% budget.b_txt %] (inactive)</option>
+                    [% END %]
                 [% END %]
             </select>
+            <label for="showallfunds" style="float:none;width:auto;">&nbsp;Show all:</label>
+            <input type="checkbox" id="showallfunds" />
+
         </li>
                </ol>
     </fieldset>