X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=admin%2Faqbudgetperiods.pl;h=64b333a4850c4bf99417b8c36b0638a770dcc61b;hb=25eeaf0f8e67b065559218c78a15bcb3700a0f0f;hp=b12f85ebda9c36082727d0ae499250b58c82e378;hpb=4747ea7462c04770484386538b1594c1760bc75b;p=koha.git diff --git a/admin/aqbudgetperiods.pl b/admin/aqbudgetperiods.pl index b12f85ebda..64b333a485 100755 --- a/admin/aqbudgetperiods.pl +++ b/admin/aqbudgetperiods.pl @@ -14,9 +14,9 @@ # 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 +# 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 @@ -37,11 +37,16 @@ script to administer the budget periods table - 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/; @@ -53,6 +58,7 @@ use C4::Output; use C4::Acquisition; use C4::Budgets; use C4::Debug; +use C4::SQLHelper; my $dbh = C4::Context->dbh; @@ -61,7 +67,6 @@ 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 $check_duplicate = $input->param('confirm_not_duplicate')||0; my $budget_period_hashref= $input->Vars; #my $sort1_authcat = $input->param('sort1_authcat'); @@ -82,7 +87,9 @@ my ($template, $borrowernumber, $cookie, $staff_flags ) = get_template_and_user( my $cur = GetCurrency(); -$template->param( cur => $cur->{symbol} ); +$template->param( symbol => $cur->{symbol}, + currency => $cur->{currency} + ); my $cur_format = C4::Context->preference("CurrencyFormat"); my $num; @@ -114,13 +121,20 @@ if ( $op eq 'add_form' ) { my $budgetperiod_hash=GetBudgetPeriod($budget_period_id); # get dropboxes FormatData($budgetperiod_hash); - $$budgetperiod_hash{budget_period_total}= $num->format_price($$budgetperiod_hash{'budget_period_total'}); + + 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 $template->param( DHTMLcalendar_dateformat => C4::Dates->DHTMLcalendar(),); - $template->param( confirm_not_duplicate => $check_duplicate ); } elsif ( $op eq 'add_validate' ) { @@ -132,31 +146,6 @@ elsif ( $op eq 'add_validate' ) { my $status=ModBudgetPeriod($budget_period_hashref); } else { # ELSE ITS AN ADD - unless ($check_duplicate){ - my $candidates=GetBudgetPeriods({ - budget_period_startdate => $$budget_period_hashref{budget_period_startdate} - , budget_period_enddate => $$budget_period_hashref{budget_period_enddate} - }); - if (@$candidates){ - my @duplicates=map{ - { dupid => $$_{budget_period_id} - , duplicateinformation => - $$_{budget_period_description}." ".$$_{budget_period_startdate}." ".$$_{budget_period_enddate} - } - } @$candidates; - $template->param(url => "aqbudgetperiods.pl", - field_name => "budget_period_id", - action_dup_yes_url=> "aqbudgets.pl", - action_dup_no_url => "aqbudgetperiods.pl?op=add_validate", - confirm_not_duplicate => 0 - ); - delete $$budget_period_hashref{budget_period_id}; - $template->param(duplicates=>\@duplicates,%$budget_period_hashref); - $template->param("add_form"=>1); - output_html_with_http_headers $input, $cookie, $template->output; - exit; - } - } my $budget_period_id=AddBudgetPeriod($budget_period_hashref); } $op='else'; @@ -185,6 +174,74 @@ elsif ( $op eq 'delete_confirmed' ) { $op='else'; } +# display the form for duplicating +elsif ( $op eq 'duplicate_form'){ + $template->param( + DHTMLcalendar_dateformat => C4::Dates->DHTMLcalendar(), + '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 $startdate = $input->param('budget_period_startdate'); + my $enddate = $input->param('budget_period_enddate'); + + my $data = GetBudgetPeriod( $budget_period_id); + + $data->{'budget_period_startdate'} = $startdate; + $data->{'budget_period_enddate'} = $enddate; + delete $data->{'budget_period_id'}; + my $new_budget_period_id = C4::SQLHelper::InsertInTable('aqbudgetperiods', $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; + } + + # write it to db + my $new_id = C4::SQLHelper::InsertInTable('aqbudgets', $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}} ){ + C4::SQLHelper::UpdateInTable('aqcudgets', [ '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 @@ -204,10 +261,8 @@ elsif ( $op eq 'delete_confirmed' ) { $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("aqbudgetperiods.pl",getnbpages(scalar(@$results),$pagesize),$page), );