63789fc095
This patch includes: - removing the use of subroutines InsertInTable, UpdateInTable, SearchInTable replaced by subroutines of DBIx::Class in the subroutines AddBudget, ModBudget, GetBudgets, AddBudgetPeriods, ModBudgetPeriod and GetBudgetPeriods and admin/aqbudgetperiods.pl - removing old database fields in OrderFromSubscription.t, Bookseller.t, Budgets.t, Serials.t, Serials_2.t - improvement of unit tests in t/db_dependent/Budgets.t - adaptation of calls to the subroutines AddBudget, ModBudget, GetBudgets, AddBudgetPeriods, ModBudgetPeriod and GetBudgetPeriods in order to match with the use of DBIx::Class Test plan: 1) Execute the UT of all of files wich uses AddBudget, ModBudget, GetBudgets, AddBudgetPeriods, ModBudgetPeriod or GetBudgetPeriods by launching the command : prove t/Budgets/ t/Budgets.t t/db_dependent/Budgets.t t/db_dependent/Acquisition.t t/db_dependent/Acquisition/ t/db_dependent/Bookseller.t t/db_dependent/Serials.t t/db_dependent/Serials_2.t 2) The result has to be a success : t/Budgets/CanUserModifyBudget.t ........................... ok t/Budgets/CanUserUseBudget.t .............................. ok t/Budgets.t ............................................... ok t/db_dependent/Budgets.t .................................. ok t/db_dependent/Acquisition.t .............................. ok t/db_dependent/Acquisition/GetBasketsInfosByBookseller.t .. ok t/db_dependent/Acquisition/GetOrdersByBiblionumber.t ...... ok t/db_dependent/Acquisition/Invoices.t ..................... ok t/db_dependent/Acquisition/OrderFromSubscription.t ........ ok t/db_dependent/Acquisition/TransferOrder.t ................ 1/11 # Transfering order to basket2 t/db_dependent/Acquisition/TransferOrder.t ................ ok t/db_dependent/Acquisition/close_reopen_basket.t .......... ok t/db_dependent/Bookseller.t ............................... 16/72 WARNING: GetBooksellerWithLateOrders is called with a negative value at /home/yohann/koha/C4/Bookseller.pm line 135. t/db_dependent/Bookseller.t ............................... ok t/db_dependent/Serials.t .................................. ok t/db_dependent/Serials_2.t ................................ ok All tests successful. Files=14, Tests=571, 22 wallclock secs ( 0.17 usr 0.03 sys + 20.26 cusr 1.10 csys = 21.56 CPU) Result: PASS 3) Go on the page admin/aqbudgetperiods.pl : Koha Administration > Budgets 4) Click on the button "New Budget" and record a new budget with a "nonzero amount" and "make budget active" 5) Click on the button "New Budget" and record another budget without "make budget active" 6) Verify there is the firt budget displayed in "Active budgets" and the second budget in "Inactive budgets" 7) Edit a budget and verify the new values are updated 8) Click on the budget active name in order to go on the page admin/aqbudgets.pl 9) Click on the button "New fund for ..." and record a new fund 10) Click on the button "Edit" then "Duplicate budget ..." in order to duplicate the budget 11) Verify there are two budgets in "Active Budgets" and one in "Inactive Budgets" 12) Click on "Funds" in the menu and verify there are two identical funds and each is associated to a different budget. Signed-off-by: Chris Cormack <chrisc@catalyst.net.nz> Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com> Signed-off-by: Tomas Cohen Arazi <tomascohen@gmail.com>
299 lines
10 KiB
Perl
Executable file
299 lines
10 KiB
Perl
Executable file
#!/usr/bin/perl
|
|
|
|
# Copyright 2008 BibLibre, BibLibre, Paul POULAIN
|
|
# SAN Ouest Provence
|
|
#
|
|
# This file is part of Koha.
|
|
#
|
|
# Koha is free software; you can redistribute it and/or modify it under the
|
|
# terms of the GNU General Public License as published by the Free Software
|
|
# Foundation; either version 2 of the License, or (at your option) any later
|
|
# version.
|
|
#
|
|
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
|
# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU General Public License along
|
|
# with Koha; if not, write to the Free Software Foundation, Inc.,
|
|
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
=head1 admin/aqbudgetperiods.pl
|
|
|
|
script to administer the budget periods table
|
|
This software is placed under the gnu General Public License, v2 (http://www.gnu.org/licenses/gpl.html)
|
|
|
|
ALGO :
|
|
this script use an $op to know what to do.
|
|
if $op is empty or none of the above values,
|
|
- the default screen is build (with all records, or filtered datas).
|
|
- the user can clic on add, modify or delete record.
|
|
if $op=add_form
|
|
- if primkey exists, this is a modification,so we read the $primkey record
|
|
- builds the add/modify form
|
|
if $op=add_validate
|
|
- the user has just send datas, so we create/modify the record
|
|
if $op=delete_confirm
|
|
- we show the record having primkey=$primkey and ask for deletion validation form
|
|
if $op=delete_confirmed
|
|
- we delete the record having primkey=$primkey
|
|
if $op=duplicate_form
|
|
- displays the duplication of budget period form (allowing specification of dates)
|
|
if $op=duplicate_budget
|
|
- we perform the duplication of the budget period specified as budget_period_id
|
|
|
|
=cut
|
|
|
|
## modules
|
|
use strict;
|
|
#use warnings; FIXME - Bug 2505
|
|
use Number::Format qw(format_price);
|
|
use CGI;
|
|
use List::Util qw/min/;
|
|
use Koha::DateUtils;
|
|
use Koha::Database;
|
|
use C4::Koha;
|
|
use C4::Context;
|
|
use C4::Auth;
|
|
use C4::Output;
|
|
use C4::Acquisition;
|
|
use C4::Budgets;
|
|
use C4::Debug;
|
|
|
|
my $dbh = C4::Context->dbh;
|
|
|
|
my $input = new CGI;
|
|
|
|
my $searchfield = $input->param('searchfield');
|
|
my $budget_period_id = $input->param('budget_period_id');
|
|
my $op = $input->param('op')||"else";
|
|
#my $sort1_authcat = $input->param('sort1_authcat');
|
|
#my $sort2_authcat = $input->param('sort2_authcat');
|
|
|
|
# get only the columns of aqbudgetperiods in budget_period_hashref
|
|
my @columns = Koha::Database->new()->schema->source('Aqbudgetperiod')->columns;
|
|
my $budget_period_hashref = { map { join(' ',@columns) =~ /$_/ ? ( $_ => $input->param($_) ) : () } keys($input->Vars) } ;
|
|
$budget_period_hashref->{budget_period_startdate} = dt_from_string( $input->param('budget_period_startdate') );
|
|
$budget_period_hashref->{budget_period_enddate} = dt_from_string( $input->param('budget_period_enddate') );
|
|
|
|
my $activepagesize = 20;
|
|
my $inactivepagesize = 20;
|
|
$searchfield =~ s/\,//g;
|
|
|
|
my ($template, $borrowernumber, $cookie, $staff_flags ) = get_template_and_user(
|
|
{ template_name => "admin/aqbudgetperiods.tmpl",
|
|
query => $input,
|
|
type => "intranet",
|
|
authnotrequired => 0,
|
|
flagsrequired => { acquisition => 'period_manage' },
|
|
debug => 1,
|
|
}
|
|
);
|
|
|
|
|
|
my $cur = GetCurrency();
|
|
$template->param( symbol => $cur->{symbol},
|
|
currency => $cur->{currency}
|
|
);
|
|
my $cur_format = C4::Context->preference("CurrencyFormat");
|
|
my $num;
|
|
|
|
if ( $cur_format eq 'US' ) {
|
|
$num = new Number::Format(
|
|
'int_curr_symbol' => '',
|
|
'mon_thousands_sep' => ',',
|
|
'mon_decimal_point' => '.'
|
|
);
|
|
} elsif ( $cur_format eq 'FR' ) {
|
|
$num = new Number::Format(
|
|
'decimal_fill' => '2',
|
|
'decimal_point' => ',',
|
|
'int_curr_symbol' => '',
|
|
'mon_thousands_sep' => ' ',
|
|
'thousands_sep' => ' ',
|
|
'mon_decimal_point' => ','
|
|
);
|
|
}
|
|
|
|
|
|
# ADD OR MODIFY A BUDGET PERIOD - BUILD SCREEN
|
|
if ( $op eq 'add_form' ) {
|
|
## add or modify a budget period (preparation)
|
|
## get information about the budget period that must be modified
|
|
|
|
if ($budget_period_id) { # MOD
|
|
my $budgetperiod_hash=GetBudgetPeriod($budget_period_id);
|
|
# get dropboxes
|
|
|
|
my $editnum = new Number::Format(
|
|
'int_curr_symbol' => '',
|
|
'thousands_sep' => '',
|
|
'mon_thousands_sep' => '',
|
|
'mon_decimal_point' => '.'
|
|
);
|
|
|
|
$$budgetperiod_hash{budget_period_total}= $editnum->format_price($$budgetperiod_hash{'budget_period_total'});
|
|
$template->param(
|
|
%$budgetperiod_hash
|
|
);
|
|
} # IF-MOD
|
|
}
|
|
|
|
elsif ( $op eq 'add_validate' ) {
|
|
## add or modify a budget period (confirimation)
|
|
|
|
## update budget period data
|
|
if ( $budget_period_id ne '' ) {
|
|
$$budget_period_hashref{$_}||=0 for qw(budget_period_active budget_period_locked);
|
|
my $status=ModBudgetPeriod($budget_period_hashref);
|
|
}
|
|
else { # ELSE ITS AN ADD
|
|
my $budget_period_id=AddBudgetPeriod($budget_period_hashref);
|
|
}
|
|
$op='else';
|
|
}
|
|
|
|
#--------------------------------------------------
|
|
elsif ( $op eq 'delete_confirm' ) {
|
|
## delete a budget period (preparation)
|
|
my $dbh = C4::Context->dbh;
|
|
## $total = number of records linked to the record that must be deleted
|
|
my $total = 0;
|
|
my $data = GetBudgetPeriod( $budget_period_id);
|
|
|
|
$$data{'budget_period_total'}=$num->format_price( $data->{'budget_period_total'});
|
|
$template->param(
|
|
%$data
|
|
);
|
|
}
|
|
|
|
elsif ( $op eq 'delete_confirmed' ) {
|
|
## delete the budget period record
|
|
|
|
my $data = GetBudgetPeriod( $budget_period_id);
|
|
DelBudgetPeriod($budget_period_id);
|
|
$op='else';
|
|
}
|
|
|
|
# display the form for duplicating
|
|
elsif ( $op eq 'duplicate_form'){
|
|
$template->param(
|
|
'duplicate_form' => '1',
|
|
'budget_period_id' => $budget_period_id,
|
|
);
|
|
}
|
|
|
|
# handle the actual duplication
|
|
elsif ( $op eq 'duplicate_budget' ){
|
|
die "please specify a budget period id\n" if( !defined $budget_period_id || $budget_period_id eq '' );
|
|
|
|
my $data = GetBudgetPeriod( $budget_period_id);
|
|
$data->{'budget_period_startdate'} = $budget_period_hashref->{budget_period_startdate};
|
|
$data->{'budget_period_enddate'} = $budget_period_hashref->{budget_period_enddate};
|
|
delete $data->{'budget_period_id'};
|
|
my $new_budget_period_id = AddBudgetPeriod($data);
|
|
|
|
my $tree = GetBudgetHierarchy( $budget_period_id );
|
|
|
|
# hash mapping old ids to new
|
|
my %old_new;
|
|
# hash mapping old parent ids to list of new children ids
|
|
# only store a child here if the parents old id isnt in the old_new map
|
|
# when the parent is found, this map will be used, and then the entry removed and their id placed in old_new
|
|
my %parent_children;
|
|
|
|
for my $entry( @$tree ){
|
|
die "serious errors, parent period $budget_period_id doesnt match child ", $entry->{'budget_period_id'}, "\n" if( $entry->{'budget_period_id'} != $budget_period_id );
|
|
my $orphan = 0; # set to 1 if we need to make an entry in parent_children
|
|
my $old_id = delete $entry->{'budget_id'};
|
|
my $parent_id = delete $entry->{'budget_parent_id'};
|
|
$entry->{'budget_period_id'} = $new_budget_period_id;
|
|
|
|
if( !defined $parent_id ){
|
|
} elsif( defined $parent_id && $parent_id eq '' ){
|
|
} elsif( defined $old_new{$parent_id} ){
|
|
# set parent id now
|
|
$entry->{'budget_parent_id'} = $old_new{$parent_id};
|
|
} else {
|
|
# make an entry in parent_children
|
|
$parent_children{$parent_id} = [] unless defined $parent_children{$parent_id};
|
|
$orphan = 1;
|
|
}
|
|
|
|
# get only the columns of aqbudgets
|
|
my @columns = Koha::Database->new()->schema->source('Aqbudget')->columns;
|
|
my $new_entry = { map { join(' ',@columns) =~ /$_/ ? ( $_ => $$entry{$_} ) : () } keys($entry) };
|
|
# write it to db
|
|
my $new_id = AddBudget($new_entry);
|
|
$old_new{$old_id} = $new_id;
|
|
push @{$parent_children{$parent_id}}, $new_id if $orphan;
|
|
|
|
# deal with any children
|
|
if( defined $parent_children{$old_id} ){
|
|
# tell my children my new id
|
|
for my $child ( @{$parent_children{$old_id}} ){
|
|
ModBudget( { 'budget_id' => $child, 'budget_parent_id' => $new_id } );
|
|
}
|
|
delete $parent_children{$old_id};
|
|
}
|
|
}
|
|
|
|
# display the list of budgets
|
|
$op = 'else';
|
|
}
|
|
|
|
# DEFAULT - DISPLAY AQPERIODS TABLE
|
|
# -------------------------------------------------------------------
|
|
# display the list of budget periods
|
|
|
|
my $activepage = $input->param('apage') || 1;
|
|
my $inactivepage = $input->param('ipage') || 1;
|
|
# Get active budget periods
|
|
my $results = GetBudgetPeriods(
|
|
{ budget_period_active => 1 },
|
|
{ -asc => 'budget_period_description' },
|
|
);
|
|
my $first = ( $activepage - 1 ) * $activepagesize;
|
|
my $last = min( $first + $activepagesize - 1, scalar @{$results} - 1, );
|
|
my @period_active_loop;
|
|
|
|
foreach my $result ( @{$results}[ $first .. $last ] ) {
|
|
my $budgetperiod = $result;
|
|
$budgetperiod->{'budget_period_total'} = $num->format_price( $budgetperiod->{'budget_period_total'} );
|
|
$budgetperiod->{budget_active} = 1;
|
|
push( @period_active_loop, $budgetperiod );
|
|
}
|
|
my $url = "aqbudgetperiods.pl";
|
|
$url .= "?ipage=$inactivepage" if($inactivepage != 1);
|
|
my $active_pagination_bar = pagination_bar ($url, getnbpages( scalar(@$results), $activepagesize), $activepage, "apage");
|
|
|
|
# Get inactive budget periods
|
|
$results = GetBudgetPeriods(
|
|
{ budget_period_active => 0 },
|
|
{ -desc => 'budget_period_enddate' },
|
|
);
|
|
|
|
$first = ( $inactivepage - 1 ) * $inactivepagesize;
|
|
$last = min( $first + $inactivepagesize - 1, scalar @{$results} - 1, );
|
|
my @period_inactive_loop;
|
|
foreach my $result ( @{$results}[ $first .. $last ] ) {
|
|
my $budgetperiod = $result;
|
|
$budgetperiod->{'budget_period_total'} = $num->format_price( $budgetperiod->{'budget_period_total'} );
|
|
$budgetperiod->{budget_active} = 1;
|
|
push( @period_inactive_loop, $budgetperiod );
|
|
}
|
|
$url = "aqbudgetperiods.pl?tab=2";
|
|
$url .= "&apage=$activepage" if($activepage != 1);
|
|
my $inactive_pagination_bar = pagination_bar ($url, getnbpages( scalar(@$results), $inactivepagesize), $inactivepage, "ipage");
|
|
|
|
my $tab = $input->param('tab') ? $input->param('tab') - 1 : 0;
|
|
$template->param(
|
|
period_active_loop => \@period_active_loop,
|
|
period_inactive_loop => \@period_inactive_loop,
|
|
active_pagination_bar => $active_pagination_bar,
|
|
inactive_pagination_bar => $inactive_pagination_bar,
|
|
tab => $tab,
|
|
);
|
|
|
|
$template->param($op=>1);
|
|
output_html_with_http_headers $input, $cookie, $template->output;
|