From f414d72415391c6027ba79e8a8b4e26a55bd61a4 Mon Sep 17 00:00:00 2001 From: Bouzid Fergani Date: Wed, 13 Apr 2016 17:03:57 -0400 Subject: [PATCH] Bug 11371 - Add option show or no inactive budget and more options Use subroutine GetBudgetHierarchy fir return all budgets Delete subroutine GetBudgetPeriodDescription and theire tests Use Price TT plugin Correct name of column and capitalization the first letter Add checkbox for show inactive budgets, default the drop down list containt a active budget Not use [i] for inactive budgets, i add (inactive) at the end of inactive budget Add vendor note in the list of show attribute Test case: Go to Home > Reports > Orders by budget Select one or all budgets You can show the inactive budget, default the drop down list containt a active budget Choose output to screen ou csv file --- C4/Budgets.pm | 34 -------------- .../csv_headers/reports/orders_by_budget.tt | 2 +- .../prog/en/modules/reports/orders_by_budget.tt | 50 ++++++++++++++------- reports/orders_by_fund.pl | 52 +++++++--------------- t/db_dependent/Budgets.t | 21 +-------- 5 files changed, 51 insertions(+), 108 deletions(-) diff --git a/C4/Budgets.pm b/C4/Budgets.pm index b60ecb1..809f63e 100644 --- a/C4/Budgets.pm +++ b/C4/Budgets.pm @@ -454,40 +454,6 @@ sub GetBudgetPeriod { return $data; } -# ------------------------------------------------------------------- - -=head2 GetBudgetPeriodDescription - - $description = GetBudgetPeriodDescription($budget_id); - - Return value: hashref - - Returns the budget period description for a given budget id. - - Description is fetched from aqbudgetperiods, id is compared aqbudgets. (INNER JOIN on budget_period_id) - -=cut - -sub GetBudgetPeriodDescription { - my ($budget_id) = @_; - my $dbh = C4::Context->dbh; - my $sth; - if ($budget_id) { - $sth = $dbh->prepare( - "SELECT budget_period_description - FROM aqbudgetperiods bp - INNER JOIN aqbudgets b - ON bp.budget_period_id = b.budget_period_id - WHERE b.budget_id=? - " - ); - $sth->execute($budget_id); - } - my $data = $sth->fetchrow_hashref; - return $data; -} - -# ------------------------------------------------------------------- sub DelBudgetPeriod{ my ($budget_period_id) = @_; my $dbh = C4::Context->dbh; diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/csv_headers/reports/orders_by_budget.tt b/koha-tmpl/intranet-tmpl/prog/en/includes/csv_headers/reports/orders_by_budget.tt index 49dfc9d..2acc795 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/csv_headers/reports/orders_by_budget.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/csv_headers/reports/orders_by_budget.tt @@ -1 +1 @@ -Fund[% sep %]"Basket Num"[% sep %]"Basket Name"[% sep %]"authorised By"[% sep %]"Biblio Number"[% sep %]Title[% sep %]Currency[% sep %]"Vendor Price"[% sep %]RRP[% sep %]"Budgeted Cost"[% sep %]Quantity[% sep %]"Total RRP"[% sep %]"Total Cost"[% sep %]"Entry Date"[% sep %]"Date Received"[% sep %]Notes +Fund[% sep %]"Basket num"[% sep %]"Basket name"[% sep %]"Authorised by"[% sep %]"Biblio number"[% sep %]Title[% sep %]Currency[% sep %]"Vendor price"[% sep %]RRP[% sep %]"Budgeted cost"[% sep %]Quantity[% sep %]"Total RRP"[% sep %]"Total cost"[% sep %]"Entry date"[% sep %]"Date received"[% sep %]"Internal note"[% sep %]"Vendor note" diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/reports/orders_by_budget.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/reports/orders_by_budget.tt index 8b9a025..2921d85 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/reports/orders_by_budget.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/reports/orders_by_budget.tt @@ -1,3 +1,4 @@ +[% USE Price %] [% INCLUDE 'doc-head-open.inc' %] Koha › Reports › Orders by fund [% INCLUDE 'doc-head-close.inc' %] @@ -11,6 +12,16 @@ @@ -39,19 +50,20 @@ Fund Basket - Basket Name - Basket By + Basket name + Basket by Title Currency - Vendor Price + List price RRP - Budgeted Cost + Budgeted cost Quantity Total RRP - Total Cost - Entry Date - Date Received - Notes + Total cost + Entry date + Date deceived + Internal note + Vendor note @@ -65,19 +77,20 @@ [% ordersloo.authorisedbyname %] [% ordersloo.title |html %] [% ordersloo.currency %] - [% ordersloo.listprice %] - [% ordersloo.rrp %] - [% ordersloo.ecost %] + [% ordersloo.listprice | $Price %] + [% ordersloo.rrp | $Price %] + [% ordersloo.ecost | $Price %] [% ordersloo.quantity %] - [% ordersloo.total_rrp %] - [% ordersloo.total_ecost %] + [% ordersloo.total_rrp | $Price %] + [% ordersloo.total_ecost | $Price %] [% ordersloo.entrydate %] [% ordersloo.datereceived %] [% ordersloo.order_internalnote |html %] + [% ordersloo.order_vendornote |html %] [% END %] - TOTAL[% total_quantity %][% total_rrp %][% total_ecost %] + TOTAL[% total_quantity %][% total_rrp | $Price %][% total_ecost | $Price %] [% END %] [% ELSE %] @@ -90,12 +103,17 @@ [% FOREACH budgetsloo IN budgetsloop %] [% IF ( budgetsloo.selected ) %] - + + [% bdgclass=budgetsloo.active? "": "b_inactive" %] + [% END %] + + diff --git a/reports/orders_by_fund.pl b/reports/orders_by_fund.pl index 2a8a7cb..ce00d72 100755 --- a/reports/orders_by_fund.pl +++ b/reports/orders_by_fund.pl @@ -27,6 +27,7 @@ This script displays all orders associated to a selected budget. use strict; use warnings; +use Modern::Perl; use CGI; use C4::Auth; @@ -36,7 +37,6 @@ use C4::Biblio; use C4::Reports; use C4::Acquisition; #GetBasket() - my $query = new CGI; my ( $template, $loggedinuser, $cookie ) = get_template_and_user( { @@ -112,12 +112,6 @@ if ( $get_orders ) { # Format the dates and currencies correctly $order->{'datereceived'} = Koha::DateUtils::output_pref(Koha::DateUtils::dt_from_string($order->{'datereceived'})); $order->{'entrydate'} = Koha::DateUtils::output_pref(Koha::DateUtils::dt_from_string($order->{'entrydate'})); - $order->{'listprice'} = sprintf( "%.2f", $order->{'listprice'} ); - $order->{'rrp'} = sprintf( "%.2f", $order->{'rrp'} ); - $order->{'ecost'} = sprintf( "%.2f", $order->{'ecost'}); - $order->{'total_rrp'} = sprintf( "%.2f", $order->{'total_rrp'}); - $order->{'total_ecost'} = sprintf( "%.2f", $order->{'total_ecost'}); - $total_quantity += $order->{'quantity'}; $total_rrp += $order->{'total_rrp'}; $total_ecost += $order->{'total_ecost'}; @@ -133,8 +127,8 @@ if ( $get_orders ) { ordersloop => \@orders, get_orders => $get_orders, total_quantity => $total_quantity, - total_rrp => sprintf( "%.2f", $total_rrp ), - total_ecost => sprintf( "%.2f", $total_ecost ), + total_rrp => $total_rrp, + total_ecost => $total_ecost, ); } # If we are outputting to a file, create it and exit. @@ -161,11 +155,6 @@ if ( $get_orders ) { my @rows; foreach my $order (@orders) { my @row; - my $sep=''; - if ($order->{'order_vendornote'}){ - $sep='. Note2:' - } - $order->{'order_internalnote'} .= $sep .$order->{'order_vendornote'}; push(@row, _surround($order->{'budget_name'})); push(@row, _surround($order->{'basketno'})); push(@row, _surround($order->{'basketname'})); @@ -182,6 +171,7 @@ if ( $get_orders ) { push(@row, _surround($order->{'entrydate'})); push(@row, _surround($order->{'datereceived'})); push(@row, _surround($order->{'order_internalnote'})); + push(@row, _surround($order->{'order_vendornote'})); push(@rows, \@row); } @@ -204,30 +194,18 @@ else { my @CSVdelimiters =(',','#',qw(; tabulation \\ /)); # getting all budgets - # active budgets - my @active_budgets = C4::Budgets::GetBudgetsByActivity(1); - # non active budgets - my @non_active_budgets = C4::Budgets::GetBudgetsByActivity(0); - my @budgetsloop; - foreach my $thisbudget ( sort {$a->{budget_name} cmp $b->{budget_name}} @active_budgets ) { - my $budget_period_desc = C4::Budgets::GetBudgetPeriodDescription($thisbudget->{budget_id}); - my %row = ( - value => $thisbudget->{budget_id}, - description => $thisbudget->{budget_name}, - period => "(" . $budget_period_desc->{budget_period_description} . ")", - ); - push @budgetsloop, \%row; - } - foreach my $thisbudget ( sort {$a->{budget_name} cmp $b->{budget_name}} @non_active_budgets ) { - my $budget_period_desc = C4::Budgets::GetBudgetPeriodDescription($thisbudget->{budget_id}); - my %row = ( - value => $thisbudget->{budget_id}, - description => "[i] ". $thisbudget->{budget_name}, - period => "(" . $budget_period_desc->{budget_period_description} . ")", - ); - push @budgetsloop, \%row; + my $budgets = GetBudgetHierarchy; + my $budgetloop = []; + foreach my $budget (@{$budgets}) { + push @{$budgetloop},{ + value => $budget->{budget_id}, + description => $budget->{budget_name}, + period => $budget->{budget_period_description}, + active => $budget->{budget_period_active}, + }; } - $template->param( budgetsloop => \@budgetsloop, + @{$budgetloop} =sort { uc( $a->{description}) cmp uc( $b->{description}) } @{$budgetloop}; + $template->param( budgetsloop => \@{$budgetloop}, outputFormatloop => \@outputFormats, delimiterloop => \@CSVdelimiters, delimiterPreference => C4::Context->preference('delimiter') diff --git a/t/db_dependent/Budgets.t b/t/db_dependent/Budgets.t index 3f13f60..e0ed6e9 100755 --- a/t/db_dependent/Budgets.t +++ b/t/db_dependent/Budgets.t @@ -1,6 +1,6 @@ #!/usr/bin/perl use Modern::Perl; -use Test::More tests => 130; +use Test::More tests => 129; BEGIN { use_ok('C4::Budgets') } @@ -468,25 +468,6 @@ for my $budget (@$budget_hierarchy_cloned) { is( $number_of_budgets_not_reset, 0, 'CloneBudgetPeriod has reset all budgets (funds)' ); -#GetBudgetPeriodDescription -$my_budgetperiod = { - budget_period_startdate => '2008-01-01', - budget_period_enddate => '2008-12-31', - budget_period_description => 'MAPERI', - budget_period_active => 0, -}; -$bpid = AddBudgetPeriod($my_budgetperiod); -$my_budget = { - budget_code => 'ABCD', - budget_amount => '123.132000', - budget_name => 'Periodiques', - budget_notes => 'This is a note', - budget_period_id => $bpid, -}; -$budget_id = AddBudget($my_budget); -my $data=GetBudgetPeriodDescription($budget_id); -is( $data->{budget_period_description}, 'MAPERI' ,'GetBudgetPeriodDescription return right value'); - #GetBudgetsByActivity my $result=C4::Budgets::GetBudgetsByActivity(1); isnt( $result, undef ,'GetBudgetsByActivity return correct value with parameter 1'); -- 1.9.1