From 480841965e08a6cf5ddf7086cc9a210223cffecb Mon Sep 17 00:00:00 2001 From: Jared Camins-Esakov Date: Sat, 8 Jun 2013 13:27:36 -0400 Subject: [PATCH] Bug 10403: add ability to change fund on receipt Right now there is no way to change the budget or fund when receiving an item, which is annoying, particularly at the end of the fiscal year when every item not already received has to be switched to the following year's budget. This patch adds the ability to change the budget and fund when receiving. To test: 1) Apply patch. 2) Create an order for a vendor, choosing a fund to use for that order. 3) Receive the order, leaving the fund unchanged. Make sure the fund did not change. 4) Create another order for a vendor, choosing a fund to use for that order. 5) Receive the order, this time changing the fund. Make sure the fund is changed. 6) Run the unit test: > prove t/db_dependent/Acquisition.t 7) Sign off. (Notes: this patch depends on the Acquisitions.t unit test improvements in bug 10274; the seemingly-unrelated change in SQLHelper quiets an irritating warning caused by the NewOrder call in ModReceiveOrder) Signed-off-by: Mathieu Saby Signed-off-by: Jonathan Druart Signed-off-by: Galen Charlton --- C4/Acquisition.pm | 5 +- C4/SQLHelper.pm | 2 +- acqui/finishreceive.pl | 3 +- acqui/orderreceive.pl | 35 +++++++++- .../prog/en/modules/acqui/orderreceive.tt | 14 +++- t/db_dependent/Acquisition.t | 70 ++++++++++++++++++- 6 files changed, 121 insertions(+), 8 deletions(-) diff --git a/C4/Acquisition.pm b/C4/Acquisition.pm index e470b24e07..c93b0a71b0 100644 --- a/C4/Acquisition.pm +++ b/C4/Acquisition.pm @@ -1268,6 +1268,7 @@ sub ModReceiveOrder { $sth->finish; delete $order->{'ordernumber'}; + $order->{'budget_id'} = ( $budget_id || $order->{'budget_id'} ); $order->{'quantity'} = $quantrec; $order->{'quantityreceived'} = $quantrec; $order->{'datereceived'} = $datereceived; @@ -1287,9 +1288,9 @@ sub ModReceiveOrder { } else { $sth=$dbh->prepare("update aqorders set quantityreceived=?,datereceived=?,invoiceid=?, - unitprice=?,rrp=?,ecost=? + unitprice=?,rrp=?,ecost=?,budget_id=? where biblionumber=? and ordernumber=?"); - $sth->execute($quantrec,$datereceived,$invoiceid,$cost,$rrp,$ecost,$biblionumber,$ordernumber); + $sth->execute($quantrec,$datereceived,$invoiceid,$cost,$rrp,$ecost,$budget_id,$biblionumber,$ordernumber); $sth->finish; } return ($datereceived, $new_ordernumber); diff --git a/C4/SQLHelper.pm b/C4/SQLHelper.pm index 21f5fa179b..f1fa7b5276 100644 --- a/C4/SQLHelper.pm +++ b/C4/SQLHelper.pm @@ -406,7 +406,7 @@ sub _filter_hash{ ## supposed to be a hash of simple values, hashes of arrays could be implemented $filter_input->{$field}=format_date_in_iso($filter_input->{$field}) if $columns->{$field}{Type}=~/date/ && - $filter_input->{$field} !~C4::Dates->regexp("iso"); + ($filter_input->{$field} && $filter_input->{$field} !~C4::Dates->regexp("iso")); my ($tmpkeys, $localvalues)=_Process_Operands($filter_input->{$field},"$tablename.$field",$searchtype,$columns); if (@$tmpkeys){ push @values, @$localvalues; diff --git a/acqui/finishreceive.pl b/acqui/finishreceive.pl index f9c85320e6..4196b52815 100755 --- a/acqui/finishreceive.pl +++ b/acqui/finishreceive.pl @@ -54,6 +54,7 @@ my $cnt = 0; my $ecost = $input->param('ecost'); my $rrp = $input->param('rrp'); my $note = $input->param("note"); +my $bookfund = $input->param("bookfund"); my $order = GetOrder($ordernumber); #need old recievedate if we update the order, parcel.pl only shows the right parcel this way FIXME @@ -93,7 +94,7 @@ if ($quantityrec > $origquantityrec ) { $order->{ecost}, $invoiceid, $order->{rrp}, - undef, + $bookfund, $datereceived, \@received_items, ); diff --git a/acqui/orderreceive.pl b/acqui/orderreceive.pl index ab7b34123d..fa400a1020 100755 --- a/acqui/orderreceive.pl +++ b/acqui/orderreceive.pl @@ -69,7 +69,7 @@ use C4::Auth; use C4::Output; use C4::Dates qw/format_date/; use C4::Bookseller qw/ GetBookSellerFromId /; -use C4::Budgets qw/ GetBudget /; +use C4::Budgets qw/ GetBudget GetBudgetHierarchy CanUserUseBudget GetBudgetPeriods /; use C4::Members; use C4::Branch; # GetBranches use C4::Items; @@ -95,7 +95,7 @@ $results = SearchOrders({ ordernumber => $ordernumber }) if $ordernumber; -my ( $template, $loggedinuser, $cookie ) = get_template_and_user( +my ( $template, $loggedinuser, $cookie, $userflags ) = get_template_and_user( { template_name => "acqui/orderreceive.tmpl", query => $input, @@ -228,6 +228,37 @@ $template->param( firstnamesuggestedby => $suggestion->{firstnamesuggestedby}, ); +my $borrower = GetMember( 'borrowernumber' => $loggedinuser ); +my @budget_loop; +my $periods = GetBudgetPeriods( { 'budget_period_active' => 1 } ); +foreach my $period (@$periods) { + my $budget_hierarchy = GetBudgetHierarchy( $period->{'budget_period_id'} ); + my @funds; + foreach my $r ( @{$budget_hierarchy} ) { + next unless ( CanUserUseBudget( $borrower, $r, $userflags ) ); + if ( !defined $r->{budget_amount} || $r->{budget_amount} == 0 ) { + next; + } + push @funds, + { + b_id => $r->{budget_id}, + b_txt => $r->{budget_name}, + b_sel => ( $r->{budget_id} == $order->{budget_id} ) ? 1 : 0, + }; + } + + @funds = sort { uc( $a->{b_txt} ) cmp uc( $b->{b_txt} ) } @funds; + + push @budget_loop, + { + 'id' => $period->{'budget_period_id'}, + 'description' => $period->{'budget_period_description'}, + 'funds' => \@funds + }; +} + +$template->{'VARS'}->{'budget_loop'} = \@budget_loop; + # regardless of the content of $unitprice e.g 0 or '' or any string will return in these cases 0.00 # and the 'IF' in the .tt will show 0.00 and not 'ecost' (see BZ 7129) # So if $unitprice == 0 we don't create unitprice diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/orderreceive.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/orderreceive.tt index 67999e4104..0ffce9978b 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/orderreceive.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/orderreceive.tt @@ -265,7 +265,19 @@ Accounting details
  1. [% datereceived %]
  2. -
  3. [% bookfund %]
  4. +
  5. (Current: [% bookfund %])
  6. [% IF ( memberfirstname and membersurname ) %][% IF ( memberfirstname ) %][% memberfirstname %][% END %] [% membersurname %][% ELSE %]No name[% END %]
  7. [% IF ( edit and not subscriptionid) %] diff --git a/t/db_dependent/Acquisition.t b/t/db_dependent/Acquisition.t index 202641fc2f..2b36068cb7 100755 --- a/t/db_dependent/Acquisition.t +++ b/t/db_dependent/Acquisition.t @@ -8,7 +8,7 @@ use POSIX qw(strftime); use C4::Bookseller qw( GetBookSellerFromId ); -use Test::More tests => 44; +use Test::More tests => 59; BEGIN { use_ok('C4::Acquisition'); @@ -146,4 +146,72 @@ my $allorders = SearchOrders({ }); is(scalar(@$allorders), 3, 'retrieved all 3 orders even after after receiving on one (bug 10723)'); +my $invoiceid = AddInvoice(invoicenumber => 'invoice', booksellerid => 1, unknown => "unknown"); + +my ($datereceived, $new_ordernumber) = ModReceiveOrder( + $biblionumber2, + $ordernumber2, + 2, + undef, + 12, + 12, + $invoiceid, + 42, + ); +my $order2 = GetOrder( $ordernumber2 ); +is($order2->{'quantityreceived'}, 0, 'Splitting up order did not receive any on original order'); +is($order2->{'quantity'}, 40, '40 items on original order'); +is($order2->{'budget_id'}, $budgetid, 'Budget on original order is unchanged'); + +$neworder = GetOrder( $new_ordernumber ); +is($neworder->{'quantity'}, 2, '2 items on new order'); +is($neworder->{'quantityreceived'}, 2, 'Splitting up order received items on new order'); +is($neworder->{'budget_id'}, $budgetid, 'Budget on new order is unchanged'); + +my $budgetid2 = C4::Budgets::AddBudget( + { + budget_code => "budget_code_test_modrecv", + budget_name => "budget_name_test_modrecv", + } +); + +($datereceived, $new_ordernumber) = ModReceiveOrder( + $biblionumber2, + $ordernumber3, + 2, + undef, + 12, + 12, + $invoiceid, + 42, + $budgetid2 + ); + +my $order3 = GetOrder( $ordernumber3 ); +is($order3->{'quantityreceived'}, 0, 'Splitting up order did not receive any on original order'); +is($order3->{'quantity'}, 2, '2 items on original order'); +is($order3->{'budget_id'}, $budgetid, 'Budget on original order is unchanged'); + +$neworder = GetOrder( $new_ordernumber ); +is($neworder->{'quantity'}, 2, '2 items on new order'); +is($neworder->{'quantityreceived'}, 2, 'Splitting up order received items on new order'); +is($neworder->{'budget_id'}, $budgetid2, 'Budget on new order is changed'); + +($datereceived, $new_ordernumber) = ModReceiveOrder( + $biblionumber2, + $ordernumber3, + 2, + undef, + 12, + 12, + $invoiceid, + 42, + $budgetid2 + ); + +$order3 = GetOrder( $ordernumber3 ); +is($order3->{'quantityreceived'}, 2, 'Order not split up'); +is($order3->{'quantity'}, 2, '2 items on order'); +is($order3->{'budget_id'}, $budgetid2, 'Budget has changed'); + $dbh->rollback; -- 2.39.5