From 4ec7a86abe22297103e1dfaf4314b0290828656b Mon Sep 17 00:00:00 2001 From: Paul Poulain Date: Tue, 28 Apr 2009 21:59:08 +0200 Subject: [PATCH] Budget management * budget period management * budget management (budgets lines are defined for a given budget period) budget_owner_search is the popup to select a librarian as budget owner --- admin/aqbudget_owner_search.pl | 121 +++++ admin/aqbudgetperiods.pl | 281 ++++++++++++ admin/aqbudgets.pl | 412 ++++++++++++++++++ admin/check_budget_parent.pl | 54 +++ admin/check_parent_total.pl | 103 +++++ .../prog/en/includes/admin-menu.inc | 6 +- .../prog/en/includes/budgetperiods-admin.inc | 37 ++ .../prog/en/includes/budgets-admin-search.inc | 119 +++++ .../prog/en/includes/budgets-admin.inc | 124 ++++++ .../modules/admin/aqbudget_owner_search.tmpl | 77 ++++ .../en/modules/admin/aqbudgetperiods.tmpl | 316 ++++++++++++++ .../prog/en/modules/admin/aqbudgets.tmpl | 360 +++++++++++++++ 12 files changed, 2007 insertions(+), 3 deletions(-) create mode 100755 admin/aqbudget_owner_search.pl create mode 100755 admin/aqbudgetperiods.pl create mode 100755 admin/aqbudgets.pl create mode 100755 admin/check_budget_parent.pl create mode 100755 admin/check_parent_total.pl create mode 100644 koha-tmpl/intranet-tmpl/prog/en/includes/budgetperiods-admin.inc create mode 100644 koha-tmpl/intranet-tmpl/prog/en/includes/budgets-admin-search.inc create mode 100644 koha-tmpl/intranet-tmpl/prog/en/includes/budgets-admin.inc create mode 100755 koha-tmpl/intranet-tmpl/prog/en/modules/admin/aqbudget_owner_search.tmpl create mode 100644 koha-tmpl/intranet-tmpl/prog/en/modules/admin/aqbudgetperiods.tmpl create mode 100644 koha-tmpl/intranet-tmpl/prog/en/modules/admin/aqbudgets.tmpl diff --git a/admin/aqbudget_owner_search.pl b/admin/aqbudget_owner_search.pl new file mode 100755 index 0000000000..cd8d46b1a1 --- /dev/null +++ b/admin/aqbudget_owner_search.pl @@ -0,0 +1,121 @@ +#!/usr/bin/perl + +# script to find a guarantor + +# Copyright 2008-2009 BibLibre SARL +# +# 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., 59 Temple Place, +# Suite 330, Boston, MA 02111-1307 USA + +use strict; +use C4::Auth ; +use C4::Output; +use CGI; +use C4::Dates qw/format_date/; +use C4::Members; + +my $input = new CGI; + +my $dbh = C4::Context->dbh; + +my ( $template, $loggedinuser, $cookie, $staff_flags ) = get_template_and_user( + { template_name => "admin/aqbudget_owner_search.tmpl", + query => $input, + type => "intranet", + authnotrequired => 0, + flagsrequired => { acquisition => 'budget_modify' }, + debug => 1, + } +); + +my $theme = $input->param('theme') || "default"; + +# only used if allowthemeoverride is set +my $member = $input->param('member'); +my $orderby = $input->param('orderby'); + +my $op = $input->param('op'); +$template->param( $op || else => 1, ); + +$orderby = "surname,firstname" unless $orderby; +$member =~ s/,//g; #remove any commas from search string +$member =~ s/\*/%/g; +if ( $member eq '' ) { + $template->param( results => 0 ); +} else { + $template->param( results => 1 ); +} + +my ( $count, $count2, $results ); +my @resultsdata; +my $toggle = 0; + +if ( $member ) { + my $dbh = C4::Context->dbh; + my $sth = $dbh->prepare( + qq| SELECT * from borrowers where surname like ? or firstname like ? or cardnumber like ? | + ); + + $sth->execute( "$member%", "$member%", "$member%", ); + my $results = $sth->fetchall_arrayref({}); + + foreach my $res (@$results) { + + my $perms = haspermission( $dbh, $res->{'userid'} ); + my $subperms = get_user_subpermissions ($res->{'userid'} ); + + + # if the member has 'acqui' permission set, then display to table. + if ( $perms->{superlibrarian} == 1 || + $perms->{acquisition} == 1 || + $subperms->{acquisition}->{'budget_manage'} || + $subperms->{acquisition}->{'budget_modify'} || + $subperms->{acquisition}->{'budget_add_del'} ) { + + $count2++; + #find out stats + my ( $od, $issue, $fines ) = GetMemberIssuesAndFines( $res->{'borrowerid'} ); + my $guarantorinfo = uc( $res->{'surname'} ) . " , " . ucfirst( $res->{'firstname'} ); + my $budget_owner_name = $res->{'firstname'} . ' ' . $res->{'surname'}, my $budget_owner_id = $res->{'borrowernumber'}; + + my %row = ( + toggle => $toggle, + count => 1, + borrowernumber => $res->{'borrowernumber'}, + cardnumber => $res->{'cardnumber'}, + surname => $res->{'surname'}, + firstname => $res->{'firstname'}, + categorycode => $res->{'categorycode'}, + branchcode => $res->{'branchcode'}, + guarantorinfo => $guarantorinfo, + budget_owner_id => $budget_owner_id, + budget_owner_name => $budget_owner_name, + odissue => "$od/$issue", + fines => $fines, +# borrowernotes => $res->{'borrowernotes'} + ); + $toggle = ( $toggle++ % 2 eq 0 ? 1 : 0 ); + push( @resultsdata, \%row ); + } + } +} + +$template->param( + member => $member, + numres => $count2, + resultsloop => \@resultsdata +); + +output_html_with_http_headers $input, $cookie, $template->output; diff --git a/admin/aqbudgetperiods.pl b/admin/aqbudgetperiods.pl new file mode 100755 index 0000000000..08d3a36445 --- /dev/null +++ b/admin/aqbudgetperiods.pl @@ -0,0 +1,281 @@ +#!/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., 59 Temple Place, +# Suite 330, Boston, MA 02111-1307 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 + +=cut + +## modules +use strict; +use Number::Format qw(format_price); +use CGI; +use List::Util qw/min/; +use C4::Dates qw/format_date format_date_in_iso/; +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 $budget_period_active = $input->param('budget_period_active'); +my $budget_period_locked = $input->param('budget_period_locked'); +my $op = $input->param('op'); + +#my $sort1_authcat = $input->param('sort1_authcat'); +#my $sort2_authcat = $input->param('sort2_authcat'); + +my $pagesize = 10; +$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 $script_name = "/cgi-bin/koha/admin/aqbudgetperiods.pl"; # ??? + +my ( $count, $results ) = GetBudgetPeriods(); +### $count +$template->param( period_button_only => 1 ) if ($count == 0) ; + +my $cur = GetCurrency(); +$template->param( cur => $cur->{symbol} ); +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' => ',' + ); +} + +if ($op) { $template->param( $op => 1 ); } +else { $template->param( 'else' => 1 ); } + +# 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 + +# my ( $default, $sort1_authcat_dropbox, $sort1_default, $sort2_default ); +# my ( $default, t ); + + if ($budget_period_id) { # MOD + my $data; + my $dbh = C4::Context->dbh; + my $sth = $dbh->prepare(qq| + SELECT * FROM aqbudgetperiods + WHERE budget_period_id=? | ); + $sth->execute($budget_period_id); + $data = $sth->fetchrow_hashref; + $sth->finish; + + # get dropboxes + $template->param( + budget_period_id => $budget_period_id, + budget_period_startdate => format_date( $data->{'budget_period_startdate'} ), + budget_period_enddate => format_date( $data->{'budget_period_enddate'} ), + budget_period_description => $data->{'budget_period_description'}, + budget_period_total => sprintf ("%.2f", $data->{'budget_period_total'} ), + budget_period_active => $data->{'budget_period_active'}, + budget_period_locked => $data->{'budget_period_locked'}, + ); + } # IF-MOD + $template->param( DHTMLcalendar_dateformat => C4::Dates->DHTMLcalendar(), ); +} + +elsif ( $op eq 'add_validate' ) { +## add or modify a budget period (confirmation) + + ## update budget period data + if ( $budget_period_id ne '' ) { + my $query = ' + UPDATE aqbudgetperiods + SET budget_period_startdate = ? + , budget_period_enddate = ? + , budget_period_description = ? + , budget_period_total = ? + , budget_period_locked = ? + WHERE budget_period_id = ? + '; + + my $sth = $dbh->prepare($query); + $sth->execute( + $input->param('budget_period_startdate') ? format_date_in_iso( $input->param('budget_period_startdate') ) : undef, + $input->param('budget_period_enddate') ? format_date_in_iso( $input->param('budget_period_enddate') ) : undef, + $input->param('budget_period_description') ? $input->param('budget_period_description') : undef, + $input->param('budget_period_total') ? $input->param('budget_period_total') : undef, + $input->param('budget_period_locked') ? $input->param('budget_period_locked') : undef, + $input->param('budget_period_id'), + ); + + # IF PASSED ACTIVE - THEN SET IT IN DB TOO. + set_active($budget_period_id) if ( $budget_period_active == 1 ); + + } else { # ELSE ITS AN ADD + my $query = " + INSERT INTO aqbudgetperiods ( + budget_period_id + , budget_period_startdate + , budget_period_enddate + , budget_period_total + , budget_period_description + , budget_period_locked ) + VALUES (?,?,?,?,?,? ); + "; + my $sth = $dbh->prepare($query); + $sth->execute( + $budget_period_id, + $input->param('budget_period_startdate') ? format_date_in_iso( $input->param('budget_period_startdate') ) : undef, + $input->param('budget_period_enddate') ? format_date_in_iso( $input->param('budget_period_enddate') ) : undef, + $input->param('budget_period_total') ? $input->param('budget_period_total') : undef, + $input->param('budget_period_description') ? $input->param('budget_period_description') : undef, + $input->param('budget_period_locked') ? $input->param('budget_period_locked') : undef, + ); + $budget_period_id = $dbh->last_insert_id( undef, undef, 'aqbudgetperiods', undef ); + set_active($budget_period_id) if ( $budget_period_active == 1 ); + } + + print "Content-Type: text/html\n\n"; #YUCK + # output_html_with_http_headers $input, $cookie, $template->output; # FIXME: THIS WOULD BE NICER THAN THE PREVIOUS PRINT + exit; +} + +#-------------------------------------------------- +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); + + $template->param( + budget_period_id => $budget_period_id, + budget_period_startdate => format_date($data->{'budget_period_startdate'}), + budget_period_enddate => format_date($data->{'budget_period_enddate'}), + budget_period_total => $num->format_price( $data->{'budget_period_total'} ) + +# budget_period_active => $data->{'budget_period_active'}, +# budget_period_description => $data->{'budget_period_description'}, +# template => C4::Context->preference('template'), ## ??!? + ); +} + +elsif ( $op eq 'delete_confirmed' ) { +## delete the budget period record + + my $dbh = C4::Context->dbh; + my $budget_period_id = uc( $input->param('budget_period_id') ); + my $sth = $dbh->prepare("DELETE FROM aqbudgetperiods WHERE budget_period_id=?"); + $sth->execute($budget_period_id); + $sth->finish; + print "Content-Type: text/html\n\n"; + exit; +} + +else { + +# DEFAULT - DISPLAY AQPERIODS TABLE +# ------------------------------------------------------------------- +# display the list of budget periods + my ( $count, $results ) = GetBudgetPeriods(); + my $page = $input->param('page') || 1; + my $first = ( $page - 1 ) * $pagesize; + + # if we are on the last page, the number of the last word to display + # must not exceed the length of the results array + my $last = min( $first + $pagesize - 1, scalar @{$results} - 1, ); + my $toggle = 0; + my @period_loop; + foreach my $result ( @{$results}[ $first .. $last ] ) { + my $budgetperiod = $result; + $budgetperiod->{'budget_period_startdate'} = format_date( $budgetperiod->{'budget_period_startdate'} ); + $budgetperiod->{'budget_period_enddate'} = format_date( $budgetperiod->{'budget_period_enddate'} ); + $budgetperiod->{'budget_period_total'} = $num->format_price( $budgetperiod->{'budget_period_total'} ); + $budgetperiod->{toggle} = ( $toggle++ % 2 eq 0 ? 1 : 0 ); + $budgetperiod->{budget_active} = 1; + push( @period_loop, $budgetperiod ); + } + my $budget_period_dropbox = GetBudgetPeriodsDropbox(); + + $template->param( + budget_period_dropbox => $budget_period_dropbox, + period_loop => \@period_loop, +# pagination_bar => pagination_bar( $script_name, +# getnbpages( scalar @{$results}, +# $pagesize ), $page, 'page' ) + ); +} + +output_html_with_http_headers $input, $cookie, $template->output; + +sub set_active { + my $sth = $dbh->do( + "UPDATE aqbudgetperiods + SET budget_period_active = 0 " + ); + my $sth = $dbh->do( + "UPDATE aqbudgetperiods + SET budget_period_active = 1 + WHERE budget_period_id = $budget_period_id" + ); +} diff --git a/admin/aqbudgets.pl b/admin/aqbudgets.pl new file mode 100755 index 0000000000..74a4178aee --- /dev/null +++ b/admin/aqbudgets.pl @@ -0,0 +1,412 @@ +#!/usr/bin/perl + +#script to administer the aqbudget table + +# Copyright 2008-2009 BibLibre SARL +# +# 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., 59 Temple Place, +# Suite 330, Boston, MA 02111-1307 USA + +use strict; +use CGI; +use List::Util qw/min/; +use Number::Format qw(format_price); + +use C4::Auth qw/get_user_subpermissions/; +use C4::Branch; # GetBranches +use C4::Dates qw/format_date format_date_in_iso/; +use C4::Auth; +use C4::Acquisition; +use C4::Budgets; # 1ST ADD +use C4::Members; # calls GetSortDetails() +use C4::Context; +use C4::Output; +use C4::Koha; +use C4::Debug; +#use POSIX qw(locale_h); + +my $input = new CGI; +my $dbh = C4::Context->dbh; + +my ($template, $borrowernumber, $cookie, $staffflags ) = get_template_and_user( + { template_name => "admin/aqbudgets.tmpl", + query => $input, + type => "intranet", + authnotrequired => 0, + flagsrequired => { acquisition => 'budget_manage' }, + debug => 0, + } +); + +my $op = $input->param('op'); + +# see if the user want to see all budgets or only owned ones +my $show_mine = 1; #SHOW BY DEFAULT +my $show = $input->param('show'); # SET TO 1, BY A FORM SUMBIT +$show_mine = $input->param('show_mine') if $show == 1; + + +# IF USER DOESNT HAVE PERM FOR AN 'ADD', THEN REDIRECT TO THE DEFAULT VIEW... +if ( not defined $template->{param_map}->{'CAN_user_acquisition_budget_add_del'} && $op == 'add_form' ) { + $op = ''; +} + +my $count = GetPeriodsCount(); +$template->param( period_button_only => 1 ) if $count == 0 ; +my $cur = GetCurrency; +my $cur_format = C4::Context->preference("CurrencyFormat"); +my $num; + +=c +# TODO: at some stage this currency handling should be done properly +with locales and POSIX.pm - and a proper 'locales' lookup and syspref + + setlocale( LC_MONETARY , "french"); + my $num = new Number::Format(); + my $formatted_number = $num->format_price('123456789.123'): + +=cut + +if ( $cur_format eq 'FR' ) { + $num = new Number::Format( + 'decimal_fill' => '2', + 'decimal_point' => ',', + 'int_curr_symbol' => '', + 'mon_thousands_sep' => ' ', + 'thousands_sep' => ' ', + 'mon_decimal_point' => ',' + ); +} else { # US by default.. + $num = new Number::Format( + 'int_curr_symbol' => '', + 'mon_thousands_sep' => ',', + 'mon_decimal_point' => '.' + ); +} + +# ' ------- get periods stuff ------------------' +# IF PERIODID IS DEFINED, GET THE PERIOD - ELSE JUST GET THE ACTIVE PERIOD BY DEFAULT +my $budget_period_id = $input->param('budget_period_id'); +my $period = GetBudgetPeriod($budget_period_id); + +# authcats_loop populates the YUI planning button +my @auth_cats_loop = GetBudgetAuthCats(); + +my $budget_period_id = $period->{'budget_period_id'}; +my $budget_period_locked = $period->{'budget_period_locked'}; +my $budget_period_description = $period->{'budget_period_description'}; +my $budget_period_total = $period->{'budget_period_total'}; + +$template->param( + budget_period_id => $budget_period_id, + budget_period_locked => $budget_period_locked, + budget_period_description => $budget_period_description, + auth_cats_loop => \@auth_cats_loop, +); +# ------- get periods stuff ------------------ + +my $script_name = "/cgi-bin/koha/admin/aqbudgets.pl"; +my $budget_id = $input->param('budget_id'); +my $budget_code = $input->param('budget_code'); +my $budget_name = $input->param('budget_name'); +my $budget_amount = $input->param('budget_amount'); +my $budget_amount_sublevel = $input->param('budget_amount_sublevel'); +my $budget_encumb = $input->param('budget_encumb'); +my $budget_expend = $input->param('budget_expend'); +my $budget_notes = $input->param('budget_notes'); +my $sort1_authcat = $input->param('sort1_authcat'); +my $sort2_authcat = $input->param('sort2_authcat'); +my $budget_description = $input->param('budget_description'); +my $budget_branchcode = $input->param('budget_branchcode'); +my $budget_owner_id = $input->param('budget_owner_id'); +my $budget_parent_id = $input->param('budget_parent_id'); +my $budget_permission = $input->param('budget_permission'); +my $budget_period_dropbox = $input->param('budget_period_dropbox'); +my $filter_budgetname = $input->param('filter_budgetname'); +my $filter_budgetbranch = $input->param('filter_budgetbranch'); + +my $pagesize = 20; # del + +# USED FOR PERMISSION COMPARSION LATER +my $borrower_id = $template->{param_map}->{'USER_INFO'}[0]->{'borrowernumber'}; +my $user = GetMemberDetails($borrower_id); +my $user_branchcode = $user->{'branchcode'}; + +$template->param( + action => $script_name, + script_name => $script_name, + show_mine => $show_mine, + $op || else => 1, +); + +my $sthtemp = $dbh->prepare("Select flags, branchcode from borrowers where borrowernumber = ?"); +$sthtemp->execute($borrowernumber); +my ( $flags, $homebranch ) = $sthtemp->fetchrow; + +my ( $budget, $period, $query, $sth ); + +my $branches = GetBranches; +my @branchloop2; +foreach my $thisbranch (keys %$branches) { + my %row = ( + value => $thisbranch, + branchname => $branches->{$thisbranch}->{'branchname'}, + ); + $row{selected} = 1 if $thisbranch eq $filter_budgetbranch; + push @branchloop2, \%row; +} + +#$template->param( +# budget_id => $budget->{'budget_id'} +#); + +# Used to create form to add or modify a record +if ($op eq 'add_form') { +#### ------------------- ADD_FORM ------------------------- + +#---- if primkey exists, it's a modify action, so read values to modify... +# pass the period_id to build the dropbox - because we only want to show budgets from this period + + my $dropbox_disabled; + if ( defined $budget_id ) { ### MOD + $budget = GetBudget($budget_id); + $dropbox_disabled = BudgetHasChildren($budget_id); + my $borrower = &GetMember( $budget->{budget_owner_id} ); + $budget->{budget_owner_name} = $borrower->{'firstname'} . ' ' . $borrower->{'surname'}; + } + + my $sort1_authcat_dropbox = GetAuthcatDropbox( 'sort1_authcat', $budget->{'sort1_authcat'} ); + my $sort2_authcat_dropbox = GetAuthcatDropbox( 'sort2_authcat', $budget->{'sort2_authcat'} ); + + my %labels; + my @values; + my $hier = GetBudgetHierarchy($budget_period_id); + foreach my $r (@$hier) { + $r->{budget_code_indent} =~ s/ /\~/g; # + $labels{"$r->{budget_id}"} = $r->{budget_code_indent}; + push @values, $r->{budget_id}; + } + push @values, ''; + # if no buget_id is passed then its an add + my $budget_dropbox; + my $budget_parent_id = $budget->{'budget_parent_id'} if $budget; + $budget_dropbox = CGI::scrolling_list( + -name => 'budget_parent_id', + -values => \@values, + -default => $budget_parent_id ? $budget_parent_id : undef, + -size => 10, + -style => "min-width:100px;", + -labels => \%labels, + ); + my $budget_parent_dropbox =~ s/\~/ /g; # + + my $branches = GetBranches; + my @branchloop_select; + foreach my $thisbranch ( keys %$branches ) { + my %row = ( + value => $thisbranch, + branchname => $branches->{$thisbranch}->{'branchname'}, + ); + $row{selected} = 1 if $thisbranch eq $budget->{'budget_branchcode'}; + push @branchloop_select, \%row; + } + +# $period = GetBudgetPeriod($budget->{'budget_period_id'}); +# $budget_period_description = $period->{'budget_period_description'}; + + my $budget_perm_dropbox = + GetBudgetPermDropbox($budget->{'budget_permission'}); + + # if no buget_id is passed then its an add + $template->param( + add_form => 1, + dateformat => C4::Dates->new()->visual(), + budget_id => $budget->{'budget_id'}, + budget_parent_id => $budget->{'budget_parent_id'}, + budget_parent_dropbox => $budget_parent_dropbox, + sort1_authcat_dropbox => $sort1_authcat_dropbox, + sort2_authcat_dropbox => $sort2_authcat_dropbox, + budget_perm_dropbox => $budget_perm_dropbox, + budget_code => $budget->{'budget_code'}, + budget_code_indent => $budget->{'budget_code_indent'}, + budget_name => $budget->{'budget_name'}, + budget_branchcode => $budget->{'budget_branchcode'}, + budget_amount => sprintf("%.2f", $budget->{'budget_amount'}), + budget_amount_sublevel => sprintf("%.2f", $budget->{'budget_amount_sublevel'}), + budget_encumb => $budget->{'budget_encumb'}, + budget_expend => $budget->{'budget_expend'}, + budget_notes => $budget->{'budget_notes'}, + budget_description => $budget->{'budget_description'}, + budget_owner_id => $budget->{'budget_owner_id'}, + budget_owner_name => $budget->{'budget_owner_name'}, + budget_permission => $budget->{'budget_permission'}, + budget_period_id => $budget_period_id, + budget_period_description => $budget_period_description, + branchloop_select => \@branchloop_select, + ); + # END $OP eq ADD_FORM +#---------------------- DEFAULT DISPLAPY BELOW --------------------- + +# called by default form, used to confirm deletion of data in DB +} elsif ($op eq 'delete_confirm') { + + my $budget = GetBudget($budget_id); + $template->param( + budget_id => $budget->{'budget_id'}, + budget_code => $budget->{'budget_code'}, + budget_name => $budget->{'budget_name'}, + budget_amount => $num->format_price( $budget->{'budget_amount'} ), + ); + # END $OP eq DELETE_CONFIRM +# called by delete_confirm, used to effectively confirm deletion of data in DB +} else { + if ( $op eq 'delete_confirmed' ) { + my $rc = DelBudget($budget_id); + } + if ( $op eq 'add_validate' ) { + my %budget_hash = ( + budget_id => $budget_id, + budget_parent_id => $budget_parent_id, + budget_period_id => $budget_period_id, + budget_code => $budget_code, + budget_name => $budget_name, + budget_branchcode => $budget_branchcode, + budget_amount => $budget_amount, + budget_amount_sublevel => $budget_amount_sublevel, + budget_encumb => $budget_encumb, + budget_expend => $budget_expend, + budget_notes => $budget_notes, + sort1_authcat => $sort1_authcat, + sort2_authcat => $sort2_authcat, + budget_description => $budget_description, + budget_owner_id => $budget_owner_id, + budget_permission => $budget_permission, + ); + if ( defined $budget_id ) { + ModBudget( \%budget_hash ); + } else { + AddBudget( \%budget_hash ); + } + } + my $branches = GetBranches(); + my $budget_period_dropbox = GetBudgetPeriodsDropbox($budget_period_id ); + $template->param( + budget_period_dropbox => $budget_period_dropbox, + budget_id => $budget_id, + budget_period_startdate => $period->{'budget_period_startdate'}, + budget_period_enddate => $period->{'budget_period_enddate'}, + ); + my $moo = GetBudgetHierarchy($budget_period_id, $template->{param_map}->{'USER_INFO'}[0]->{'branchcode'}, $show_mine?$borrower_id:''); + my @budgets = @$moo; #FIXME + + my $toggle = 0; + my @loop; + my $period_total = 0; + my ( $period_alloc_total, $base_alloc_total, $sub_alloc_total, $base_spent_total, $base_remaining_total ); + + foreach my $budget (@budgets) { + + # PERMISSIONS + unless($staffflags->{'superlibrarian'} == 1 ) { + #IF NO PERMS, THEN DISABLE EDIT/DELETE + unless ( $template->{param_map}->{'CAN_user_acquisition_budget_modify'} ) { + $budget->{'budget_lock'} = 1; + } + # check budget permission + if ( $budget_period_locked == 1 ) { + $budget->{'budget_lock'} = 1; + + } elsif ( $budget->{budget_permission} == 1 ) { + + if ( $borrower_id != $budget->{'budget_owner_id'} ) { + $budget->{'budget_lock'} = 1; + } + # check parent perms too + my $parents_perm = 0; + if ( $budget->{depth} > 0 ) { + $parents_perm = CheckBudgetParentPerm( $budget, $borrower_id ); + delete $budget->{'budget_lock'} if $parents_perm == '1'; + } + } elsif ( $budget->{budget_permission} == 2 ) { + + $budget->{'budget_lock'} = 1 if $user_branchcode ne $budget->{budget_branchcode}; + } + } # ...SUPER_LIB END + + # if a budget search doesnt match, next + if ($filter_budgetname ) { + next unless $budget->{budget_code} =~ m/$filter_budgetname/ || + $budget->{name} =~ m/$filter_budgetname/ ; + } + if ($filter_budgetbranch ) { + next unless $budget->{budget_branchcode} =~ m/$filter_budgetbranch/; + } + +## TOTALS + # adds to total - only if budget is a 'top-level' budget + $period_alloc_total += $budget->{'budget_amount_total'} if $budget->{'depth'} == 0; + $base_alloc_total += $budget->{'budget_amount'}; + $sub_alloc_total += $budget->{'budget_amount_sublevel'}; + $base_spent_total += $budget->{'budget_spent'}; + $budget->{'budget_remaining'} = $budget->{'budget_amount'} - $budget->{'budget_spent'}; + $base_remaining_total += $budget->{'budget_remaining'}; + +# if amount == 0 dont display... + delete $budget->{'budget_unalloc_sublevel'} if $budget->{'budget_unalloc_sublevel'} == 0 ; + delete $budget->{'budget_amount_sublevel'} if $budget->{'budget_amount_sublevel'} == 0 ; + + $budget->{'remaining_pos'} = 1 if $budget->{'budget_remaining'} > 0; + $budget->{'remaining_neg'} = 1 if $budget->{'budget_remaining'} < 0; + $budget->{'budget_amount'} = $num->format_price( $budget->{'budget_amount'} ); + $budget->{'budget_spent'} = $num->format_price( $budget->{'budget_spent'} ); + $budget->{'budget_remaining'} = $num->format_price( $budget->{'budget_remaining'} ); + $budget->{'budget_amount_total'} = $num->format_price( $budget->{'budget_amount_total'} ); + $budget->{'budget_amount_sublevel'} = $num->format_price( $budget->{'budget_amount_sublevel'} ) if defined $budget->{'budget_amount_sublevel'}; + $budget->{'budget_unalloc_sublevel'} = $num->format_price( $budget->{'budget_unalloc_sublevel'} ) if defined $budget->{'budget_unalloc_sublevel'}; + + my $borrower = &GetMember( $budget->{budget_owner_id} ); + $budget->{budget_owner_name} = $borrower->{'firstname'} . ' ' . $borrower->{'surname'}; + $budget->{budget_borrowernumber} = $borrower->{'borrowernumber'}; + + push( @loop, { %{$budget}, + toggle => $toggle++%2, + branchname => $branches->{ $budget->{branchcode} }->{branchname}, + startdate => format_date($budget->{startdate}), + enddate => format_date($budget->{enddate}), + } + ); + } + + $template->param( + else => 1, + budget => \@loop, + budget_period_total => $num->format_price($budget_period_total), + period_alloc_total => $num->format_price($period_alloc_total), + base_alloc_total => $num->format_price($base_alloc_total), + sub_alloc_total => $num->format_price($sub_alloc_total), + base_spent_total => $num->format_price($base_spent_total), + base_remaining_total => $num->format_price($base_remaining_total), + period_remaining_total => $num->format_price( $period_alloc_total - $base_alloc_total ), + branchloop => \@branchloop2, + cur => $cur->{symbol}, + cur_format => $cur_format, + # pagination_bar => pagination_bar( + # $script_name, getnbpages(scalar @results, $pagesize), + # $page, 'page' ), + ); + +} #---- END $OP eq DEFAULT + +output_html_with_http_headers $input, $cookie, $template->output; diff --git a/admin/check_budget_parent.pl b/admin/check_budget_parent.pl new file mode 100755 index 0000000000..991160ef6d --- /dev/null +++ b/admin/check_budget_parent.pl @@ -0,0 +1,54 @@ +#!/usr/bin/perl + +# Copyright 2000-2002 Katipo Communications +# +# 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., 59 Temple Place, +# Suite 330, Boston, MA 02111-1307 USA + +use strict; +use CGI; +use C4::Context; +use C4::Output; +use C4::Auth; +use C4::Budgets; + +=head1 + +fetches the budget amount fron the DB, +called by aqbudgets.pl and neworderempty.pl + +=cut + +my $input = new CGI; + +my $budget_id = $input->param('budget_id'); +my $new_parent_id = $input->param('new_parent'); + +my ( $template, $loggedinuser, $cookie ) = get_template_and_user( + { template_name => "acqui/ajax.tmpl", + query => $input, + type => "intranet", + authnotrequired => 0, + debug => 0, + } +); + +my $budget = GetBudget($budget_id); +my $new_parent_budget = GetBudget($new_parent_id); +my $result = CheckBudgetParent( $new_parent_budget, $budget ); +$template->param( return => $result ); + +output_html_with_http_headers $input, $cookie, $template->output; +1; diff --git a/admin/check_parent_total.pl b/admin/check_parent_total.pl new file mode 100755 index 0000000000..ac7534661f --- /dev/null +++ b/admin/check_parent_total.pl @@ -0,0 +1,103 @@ +#!/usr/bin/perl + +# Copyright 2000-2002 Katipo Communications +# +# 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., 59 Temple Place, +# Suite 330, Boston, MA 02111-1307 USA + +use strict; +use CGI; +use C4::Context; +use C4::Output; +use C4::Auth; +use C4::Budgets; + +=head1 + +This script checks the amount unallocated from the new parent budget , or the period - if no parent_id is given + +This script is called from aqbudgets.pl during an 'add' or 'mod' budget, from the JSscript Check() function, +to determine whether the new parent budget (or period) has enough unallocated funds for the save to complete. + +=cut + +my $dbh = C4::Context->dbh; +my $input = new CGI; + +my $total = $input->param('total'); +my $budget_id = $input->param('budget_id'); +my $parent_id = $input->param('parent_id'); +my $period_id = $input->param('period_id'); +my $returncode; + +my ( $template, $loggedinuser, $cookie ) = get_template_and_user( + { template_name => "acqui/ajax.tmpl", + query => $input, + type => "intranet", + authnotrequired => 0, + debug => 0, + } +); +my ($period, $parent , $budget); +$period = GetBudgetPeriod($period_id) if $period_id; +$parent = GetBudget($parent_id) if defined $parent_id; +$budget = GetBudget($budget_id) if defined $budget_id; + +# CHECK THE PARENT BUDGET FOR ENOUGHT AMOUNT UNALLOCATED, IF NOT THEN RETURN 1 +my ($sub_unalloc , $period_sum, $budget_period_unalloc); + +if ($parent) { + my $query = " SELECT SUM(budget_amount) as sum FROM aqbudgets where budget_parent_id = ? "; + my $sth = $dbh->prepare($query); + $sth->execute( $parent->{'budget_id'} ); + my $sum = $sth->fetchrow_hashref; + $sth->finish; + + $sub_unalloc = $parent->{'budget_amount_sublevel'} - $sum->{sum}; + +# TRICKY.. , IF THE PARENT IS THE CURRENT PARENT - THEN SUBSTRACT CURRENT BUDGET FROM TOTAL + if ( $budget->{'budget_parent_id'} == $parent_id ) { + $sub_unalloc += ( $budget->{'budget_amount'} + $budget->{'budget_amount_sublevel'} ); + $budget_period_unalloc += ( $budget->{'budget_amount'} + $budget->{'budget_amount_sublevel'} ); + } +} + +# ELSE , IF NO PARENT PASSED, THEN CHECK UNALLOCATED FOR PERIOD, IF NOT THEN RETURN 2 +else { + my $query = qq| SELECT (SUM(budget_amount_sublevel) + SUM(budget_amount)) as sum + FROM aqbudgets WHERE budget_period_id = ?|; + + my $sth = $dbh->prepare($query); + $sth->execute( $period->{'budget_period_total'} ); + $period_sum = $sth->fetchrow_hashref; + $sth->finish; + $budget_period_unalloc = $period->{'budget_period_total'} - $period_sum->{'sum'}; +} + +if ( $parent_id) { + if ( $total > $sub_unalloc ) { + $returncode = 1; + } +} elsif ( $total > $budget_period_unalloc ) { + $returncode = 2; + +} else { + $returncode = 0; +} + +$template->param( return => $returncode ); + +output_html_with_http_headers $input, $cookie, $template->output; +1; diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/admin-menu.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/admin-menu.inc index e14f3475db..c5919e66fd 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/admin-menu.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/admin-menu.inc @@ -5,10 +5,10 @@
Basic parameters
Patrons and circulation
diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/budgetperiods-admin.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/budgetperiods-admin.inc new file mode 100644 index 0000000000..77898f3b5f --- /dev/null +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/budgetperiods-admin.inc @@ -0,0 +1,37 @@ +
+ +
diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/budgets-admin-search.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/budgets-admin-search.inc new file mode 100644 index 0000000000..8fe4b69d25 --- /dev/null +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/budgets-admin-search.inc @@ -0,0 +1,119 @@ + +

+ + + diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/budgets-admin.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/budgets-admin.inc new file mode 100644 index 0000000000..79dc4516b3 --- /dev/null +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/budgets-admin.inc @@ -0,0 +1,124 @@ +
+ +
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/aqbudget_owner_search.tmpl b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/aqbudget_owner_search.tmpl new file mode 100755 index 0000000000..0445304a0f --- /dev/null +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/aqbudget_owner_search.tmpl @@ -0,0 +1,77 @@ + +Koha › Budget Owner Search + + + + + + + + +
+
+
+ + +

Search for Budget Owner

+
+
+ " class="focus" /> + + + + +
+
Only staff with superlibrarian or acquisistions permissions are returned from search results
+ +
+ + + +

Searched for , patron(s) found:

+ + + + + + + + + + + + + + + + + + +
CardnumberNameBranchCategorycodeSelect?
, + ', '');" /> +
+ + + +
+
+ diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/aqbudgetperiods.tmpl b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/aqbudgetperiods.tmpl new file mode 100644 index 0000000000..fb7b44c643 --- /dev/null +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/aqbudgetperiods.tmpl @@ -0,0 +1,316 @@ + + + + + + + + + Koha › Administration › Budget periods + + <!-- TMPL_IF name="add_form" -->› + <!-- TMPL_IF name="budget_period_id" --> + Modify budget period'<!-- TMPL_VAR name="budget_period_id" -->' + <!-- TMPL_ELSE --> + Add budget period + <!-- /TMPL_IF --> + <!-- /TMPL_IF --> + + <!-- TMPL_IF name="delete_confirm" -->› + Delete budget period '<!-- TMPL_VAR name="budget_period_description" -->'? + <!-- /TMPL_IF --> + <!-- TMPL_IF name="delete_confirmed" -->› + Data Deleted + <!-- /TMPL_IF --> + + + + + + + + + + + + + + + + +
+
+
+
+ + +  --> + + + + +

Modify budget period

+ +

Add budget period

+ + +
+
+ + + + + + " /> +
    +
  1. + + " /> + + +
  2. +
  3. + + + + + " /> + + + +
  4. + +
  5. + + + + " /> +
  6. + +
  7. + + + + " /> +
  8. + +
  9. + + + + checked /> +
  10. + +
  11. + + + + checked /> +
  12. +
+
+ +
+ + + + + +
+ +
+ + + + + + + + + +
+

Cannot delete budget period

+

This record is used times + . Deletion is not possible.

+ +
+

Delete budget period ''?

+ + + + + + + + + + + + + + + + + + + + + +
Start date
End date
Total amount
+ + + + + + +
" method="post"> + + " /> + +
+ +
" method="post"> + +
+ +
+ + + +

Budget periods administration

+ Currency = + + + + + + + + + + + + + + + + + + + + + + + + + + +
Period NameStart DateEnd DateActiveLockedTotalActions
✓ X + ?op=add_form&budget_period_id=">Edit + ?op=delete_confirm&budget_period_id=">Delete + ">Budgets +
+
+ + +
+
+
+ +
+
+ diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/aqbudgets.tmpl b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/aqbudgets.tmpl new file mode 100644 index 0000000000..db599e04c7 --- /dev/null +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/aqbudgets.tmpl @@ -0,0 +1,360 @@ + + + + + + + + + + + + + + + +
+
+
+
+ + + + +

Budgets for ''

+ +
+
+ Budget options +
  • + + +
  • +
  • + + + + +
  • + + + + + + +
  • + + +
    +
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + --> + + + + + + + + + + + + + + + + + + + + + + + + + + +
    Budget hierarchyBudget nameTotal
    allocated
    Base-level
    allocated
    Sub-level
    allocated (unallocated)
    Base-level
    spent
    Base-level
    remaining
    OwnerBranchNoteActions
    + + ( ) + + -- STYLE="color: green;" + STYLE="color: red;" > + "> Edit Delete &budget_period_id=" >Edit + ">Delete
    Period allocated
    + +Currency =
    +
    + + + + + + +
    +
    + ModifyAdd Budget + + for period + + + + + +
      +
    1. + + + + + " /> + +
    2. + +
    3. + + " size="30" /> +
    4. + +
    5. + + " size="60" /> +
    6. + +
      base-level and sub-level amount fields cannot both be empty
      +
    7. + + " size="8" /> +
    8. + +
    9. + + " size="8" /> +
    10. + +
    11. + + " size="8" /> +
    12. + +
    13. + + " size="8" /> +
    14. + + +
    15. + + + "> + + + + + +
    16. + + + + +
    17. + + +
    18. + +
    19. + + +
    20. + +
    21. + + +
    22. + +
    23. + + +
    24. +
    25. + + +
    26. +
    + + + + +
    + +
    + Cancel + +
    +
    + + + + +

    Delete Budget ?

    + + < + + +
    Budget Amount: +
    + +
    " method="post"> + + " /> + +
    + +
    " method="get"> + +
    +
    + + +
    +
    +
    + +
    +
    + -- 2.20.1