use strict;
use C4::Context;
use C4::Dates qw(format_date format_date_in_iso);
+use C4::SQLHelper qw<:all>;
use C4::Debug;
use vars qw($VERSION @ISA @EXPORT);
&GetBudgetPeriod
&GetBudgetPeriods
&ModBudgetPeriod
+ &AddBudgetPeriod
&DelBudgetPeriod
&GetBudgetPeriodsDropbox
&GetBudgetPermDropbox
&ModBudgetPlan
+
&GetCurrency
&GetCurrencies
&ModCurrencies
&ConvertCurrency
- &GetBudgetsPlanCell
+
+ &GetBudgetsPlanCell
&AddBudgetPlanValue
&GetBudgetAuthCats
&BudgetHasChildren
my ( $authcat, @hide_cols ) = @_;
my $dbh = C4::Context->dbh;
-=c
- my $sth = $dbh->prepare(
- qq|
- UPDATE aqbudgets_planning
- SET display = 1 where authcat = ? |
- );
- $sth->execute( $authcat );
-=cut
-
my $sth1 = $dbh->prepare(
qq|
UPDATE aqbudgets_planning SET display = 0
return 0;
}
+sub AddBudgetPeriod {
+ my ($budgetperiod) = @_;
+ return InsertInTable("aqbudgetperiods",$budgetperiod);
+}
# -------------------------------------------------------------------
sub GetPeriodsCount {
my $dbh = C4::Context->dbh;
WHERE budget_parent_id = ? | );
$sth->execute( $budget_id );
my $sum = $sth->fetchrow_hashref;
- $sth->finish;
return $sum->{'sum'};
}
((aqbudgets.sort1_authcat = ? AND sort1 =?) OR
(aqbudgets.sort2_authcat = ? AND sort2 =?)) |
);
- $sth->{TraceLevel} = 2;
$sth->execute( $cell->{'budget_id'},
$budget->{'sort1_authcat'},
$cell->{'authvalue'},
$sth->execute($budget_id);
my $sum = $sth->fetchrow_array;
-# $sum = sprintf "%.2f", $sum;
return $sum;
}
# -------------------------------------------------------------------
sub GetBudgetPeriods {
- my $dbh = C4::Context->dbh;
- my $sth = $dbh->prepare(qq|
- SELECT *
- FROM aqbudgetperiods
- ORDER BY budget_period_startdate, budget_period_enddate |
- );
- $sth->execute();
- my @results;
- my $active;
- while (my $data = $sth->fetchrow_hashref) {
- if ($data->{'budget_period_active'} == 1) {
- $active = $data->{'budget_period_id'};
- }
- push(@results, $data);
- }
- $sth->finish;
- return ($active, \@results);
+ my ($filters,$orderby) = @_;
+ return SearchInTable("aqbudgetperiods",$filters, $orderby);
}
-
# -------------------------------------------------------------------
sub GetBudgetPeriod {
my ($budget_period_id) = @_;
my $total = 0;
## get information about the record that will be deleted
my $sth;
- if ($budget_period_id gt 0) {
+ if ($budget_period_id) {
$sth = $dbh->prepare( qq|
SELECT *
FROM aqbudgetperiods
$sth->execute();
}
my $data = $sth->fetchrow_hashref;
- $sth->finish;
return $data;
}
# -------------------------------------------------------------------
-sub DelBudgetPeriod() {
+sub DelBudgetPeriod{
my ($budget_period_id) = @_;
my $dbh = C4::Context->dbh;
; ## $total = number of records linked to the record that must be deleted
}
# -------------------------------------------------------------------
-sub ModBudgetPeriod() {
+sub ModBudgetPeriod {
my ($budget_period_information) = @_;
- my $dbh = C4::Context->dbh ; ## $total = number of records linked to the record that must be deleted my $total = 0;
-
- ## get information about the record that will be deleted
- my $budget_period_id=$$budget_period_information{'budget_period_id'};
- delete $$budget_period_information{'budget_period_id'};
- my @values;
- my @keys;
-
- while ( my ($k,$v) = each %$budget_period_information ) {
- next if (not $v and $k!~/sort1|note/);
- #next if any { $_ eq $k } qw( sort1 note);
- push @values, $v;
- push @keys, "$k=?";
- }
-
- my $query = do { local $"=',';
- qq{
- UPDATE aqbudgetperiods
- SET @keys
- WHERE budget_period_id=?
- }
- };
-
- my $sth=$dbh->prepare($query);
- my $data = $sth->execute(@values,$budget_period_id);
- return $data;
+ return UpdateInTable("aqbudgetperiods",$budget_period_information);
}
# -------------------------------------------------------------------
my $dbh = C4::Context->dbh;
my $query = qq|
SELECT aqbudgets.*
- FROM aqbudgets
- JOIN aqbudgetperiods USING (budget_period_id)
- WHERE budget_period_active=1 |;
+ FROM aqbudgets |;
# show only period X if requested
+ my @where_strings;
if ($budget_period_id) {
- $query .= "AND aqbudgets.budget_period_id = ?";
+ push @where_strings," aqbudgets.budget_period_id = ?";
push @bind_params, $budget_period_id;
}
# show only budgets owned by me, my branch or everyone
if ($owner) {
if ($branchcode) {
- $query .= " AND (budget_owner_id = ? OR budget_branchcode = ? OR (budget_branchcode IS NULL AND budget_owner_id IS NULL))";
- push @bind_params, $owner;
- push @bind_params, $branchcode;
+ push @where_strings,qq{ (budget_owner_id = ? OR budget_branchcode = ? OR (budget_branchcode IS NULL or budget_branchcode="" AND (budget_owner_id IS NULL OR budget_owner_id=""))};
+ push @bind_params, ($owner, $branchcode);
} else {
- $query .= ' AND budget_owner_id = ? OR budget_owner_id IS NULL';
+ push @where_strings, ' (budget_owner_id = ? OR budget_owner_id IS NULL or budget_owner_id ="") ';
push @bind_params, $owner;
}
} else {
if ($branchcode) {
- $query .= " AND (budget_branchcode =? or budget_branchcode is NULL)";
+ push @where_strings," (budget_branchcode =? or budget_branchcode is NULL)";
push @bind_params, $branchcode;
}
}
+ $query.=" WHERE ".join(' AND ', @where_strings);
+ $debug && warn $query,join(",",@bind_params);
my $sth = $dbh->prepare($query);
$sth->execute(@bind_params);
my $results = $sth->fetchall_arrayref({});
}
# -------------------------------------------------------------------
-sub AddBudget {
-my ($budget) = @_;
-my $dbh = C4::Context->dbh;
- my @keys; my @values;
-
- while ( my ($k,$v) = each %$budget ) {
- next unless $v;
- push @values, $v;
- push @keys , "$k = ?";
- }
- my $query = do {
- local $" = ',';
- qq{
- INSERT INTO aqbudgets
- SET @keys
- };
- };
-
- #warn $query;
- my $sth = $dbh->prepare($query);
- $sth->execute(@values);
- return $dbh->{'mysql_insertid'};
+sub AddBudget {
+ my ($budget) = @_;
+ return InsertInTable("aqbudgets",$budget);
}
# -------------------------------------------------------------------
sub ModBudget {
my ($budget) = @_;
- my $dbh = C4::Context->dbh;
- my $budgetid=$$budget{'budgetid'};
- delete $$budget{'budget_id'};
-
- my @values;
- my @keys;
-
- while ( my ($k,$v) = each %$budget ) {
- next if (not $v and $k!~/sort1|note/);
- #next if any { $_ eq $k } qw( sort1 note);
- push @values, $v;
- push @keys, "$k=?";
- }
-
- my $query = do { local $"=',';
- qq{
- UPDATE aqbudgets
- SET @keys
- WHERE budget_id=?
- };
- };
-
- my $sth = $dbh->prepare($query);
- $sth->execute( @values,$budgetid);
+ return UpdateInTable("aqbudgets",$budget);
}
# -------------------------------------------------------------------
my $dbh = C4::Context->dbh;
my $sth = $dbh->prepare("delete from aqbudgets where budget_id=?");
my $rc = $sth->execute($budget_id);
- $sth->finish;
return $rc;
}
=over 4
-&GetBudget($budget_id);
+&GetBudgets($filter, $order_by);
gets all budgets
# -------------------------------------------------------------------
sub GetBudgets {
- my ($active) = @_;
- my $dbh = C4::Context->dbh;
- my $q = "SELECT * from aqbudgets";
- my $row;
- my $sth;
- unless ($active) {
- $sth = $dbh->prepare($q);
- $sth->execute();
- } else {
- $q = "select budget_period_id from aqbudgetperiods where budget_period_active = 1 ";
- $sth = $dbh->prepare($q);
- $sth->execute();
- $row = $sth->fetchrow_hashref();
- $q = "select * from aqbudgets WHERE budget_period_id =? ";
- $sth = $dbh->prepare($q);
- $sth->execute( $row->{'budget_period_id'} );
- }
- my $results = $sth->fetchall_arrayref( {} );
- $sth->finish;
- return $results;
+ my ($filters,$orderby) = @_;
+ return SearchInTable("aqbudgets",$filters,$orderby);
}
# -------------------------------------------------------------------
while ( my $data = $sth->fetchrow_hashref ) {
push( @results, $data );
}
- $sth->finish;
return @results;
}
my $sth = $dbh->prepare($query);
$sth->execute;
my $r = $sth->fetchrow_hashref;
- $sth->finish;
return $r;
}
return ( $price / $cur );
}
+=item
+ returns an array containing fieldname followed by PRI as value if PRIMARY Key
+=cut
+sub _columns(;$) {
+ my $tablename=shift||"aqbudgets";
+ return @{C4::Context->dbh->selectcol_arrayref("SHOW columns from $tablename",{Columns=>[1,4]})};
+}
+
+sub _filter_fields{
+ my $budget=shift;
+ my $tablename=shift;
+ my @keys;
+ my @values;
+ my %columns= _columns($tablename);
+ #Filter Primary Keys of table
+ my $elements=join "|",grep {$columns{$_} ne "PRI"} keys %columns;
+ foreach my $field (grep {/\b($elements)\b/} keys %$budget){
+ $$budget{$field}=format_date_in_iso($$budget{$field}) if ($field=~/date/ && $$budget{$field} !~C4::Dates->regexp("iso"));
+ my $strkeys= " $field = ? ";
+ if ($field=~/branch/){
+ $strkeys="( $strkeys OR $field='' OR $field IS NULL) ";
+ }
+ push @values, $$budget{$field};
+ push @keys, $strkeys;
+ }
+ return (\@keys,\@values);
+}
+
END { } # module clean-up code here (global destructor)
1;
use C4::Context;
use C4::Languages qw(getTranslatedLanguages get_bidi regex_lang_subtags language_get_description accept_language );
+use C4::Dates qw(format_date);
+use C4::Budgets qw(GetCurrency);
use HTML::Template::Pro;
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
&themelanguage &gettemplate setlanguagecookie getlanguagecookie pagination_bar
);
push @EXPORT, qw(
- &output_html_with_http_headers &output_with_http_headers
+ &output_html_with_http_headers &output_with_http_headers FormatData FormatNumber
);
}
return $lang;
}
+=item FormatNumber
+=cut
+sub FormatNumber{
+my $cur = GetCurrency;
+my $cur_format = C4::Context->preference("CurrencyFormat");
+my $num;
+
+if ( $cur_format eq 'FR' ) {
+ $num = new Number::Format(
+ 'decimal_fill' => '2',
+ 'decimal_point' => ',',
+ 'int_curr_symbol' => $cur->{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' => '.'
+ );
+}
+return $num;
+}
+
+=item FormatData
+
+FormatData($data_hashref)
+C<$data_hashref> is a ref to data to format
+
+Format dates of data those dates are assumed to contain date in their noun
+Could be used in order to centralize all the formatting for HTML output
+=cut
+
+sub FormatData{
+ my $data_hashref=shift;
+ $$data_hashref{$_} = format_date( $$data_hashref{$_} ) for grep{/date/} keys (%$data_hashref);
+}
+
=item pagination_bar
pagination_bar($base_url, $nb_pages, $current_page, $startfrom_name)
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 $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');
#my $sort2_authcat = $input->param('sort2_authcat');
}
);
-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} );
);
}
-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;
-
+ 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'});
$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'},
+ %$budgetperiod_hash
);
} # IF-MOD
- $template->param( DHTMLcalendar_dateformat => C4::Dates->DHTMLcalendar(), );
+ $template->param( DHTMLcalendar_dateformat => C4::Dates->DHTMLcalendar(),);
+ $template->param( confirm_not_duplicate => $check_duplicate );
}
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 = ?
- , budget_period_active = ?
- 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_active') ? $input->param('budget_period_active') : undef,
- $input->param('budget_period_id'),
- );
-
- } 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
- , budget_period_active)
- 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,
- $input->param('budget_period_active') ? $input->param('budget_period_active') : undef,
- );
- $budget_period_id = $dbh->last_insert_id( undef, undef, 'aqbudgetperiods', undef );
- }
-
- print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=aqbudgetperiods.pl\"></html>"; #YUCK
- # output_html_with_http_headers $input, $cookie, $template->output; # FIXME: THIS WOULD BE NICER THAN THE PREVIOUS PRINT
- exit;
+ ## 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
+ 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';
}
#--------------------------------------------------
my $total = 0;
my $data = GetBudgetPeriod( $budget_period_id);
+ FormatData($data);
+ $$data{'budget_period_total'}=$num->format_price( $data->{'budget_period_total'});
$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'), ## ??!?
+ %$data
);
}
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<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=aqbudgetperiods.pl\"></html>";
- exit;
+ my $data = GetBudgetPeriod( $budget_period_id);
+ DelBudgetPeriod($budget_period_id);
+ $op='else';
}
-else {
-
# DEFAULT - DISPLAY AQPERIODS TABLE
# -------------------------------------------------------------------
# display the list of budget periods
- my ( $count, $results ) = GetBudgetPeriods();
+ my $results = GetBudgetPeriods();
+ $template->param( period_button_only => 1 ) unless (@$results) ;
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 @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'} );
+ FormatData($budgetperiod);
$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 );
}
$template->param(
budget_period_dropbox => $budget_period_dropbox,
period_loop => \@period_loop,
-# pagination_bar => pagination_bar( $script_name,
-# getnbpages( scalar @{$results},
-# $pagesize ), $page, 'page' )
+ pagination_bar => pagination_bar("aqbudgetperiods.pl",getnbpages(scalar(@$results),$pagesize),$page),
);
-}
+$template->param($op=>1);
output_html_with_http_headers $input, $cookie, $template->output;
$op = '';
}
-my $cur = GetCurrency;
-my $cur_format = C4::Context->preference("CurrencyFormat");
-my $num;
-
-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' => '.'
- );
-}
+my $num=FormatNumber;
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_hash=$input->Vars;
+my $budget_id = $$budget_hash{budget_id};
my $budget_permission = $input->param('budget_permission');
my $budget_period_dropbox = $input->param('budget_period_dropbox');
+#filtering non budget keys
+delete $$budget_hash{$_} foreach grep {/filter|^op$|show/} keys %$budget_hash;
my $filter_budgetname = $input->param('filter_budgetname');
my $filter_budgetbranch = $input->param('filter_budgetbranch');
# ' ------- 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);
-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'};
+my $period = GetBudgetPeriod($$budget_hash{budget_period_id});
$template->param(
- budget_period_id => $budget_period_id,
- budget_period_locked => $budget_period_locked,
- budget_period_description => $budget_period_description,
+ %$period
);
# ------- get periods stuff ------------------
# retrieve branches
-my ( $budget, $period, $query, $sth );
+my ( $budget, );
-my $branches = GetBranches;
+my $branches = GetBranches($show_mine);
my @branchloop2;
foreach my $thisbranch (keys %$branches) {
my %row = (
push @branchloop2, \%row;
}
-$template->param(auth_cats_loop => GetBudgetAuthCats($budget_period_id) );
+$template->param(auth_cats_loop => GetBudgetAuthCats($$period{budget_period_id}) );
# Used to create form to add or modify a record
if ($op eq 'add_form') {
# if no buget_id is passed then its an add
# 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
+ if (defined $budget_id ) { ### MOD
$budget = GetBudget($budget_id);
$dropbox_disabled = BudgetHasChildren($budget_id);
- my $borrower = &GetMember( $budget->{budget_owner_id} );
+ my $borrower = &GetMember( borrowernumber=>$budget->{budget_owner_id} );
$budget->{budget_owner_name} = $borrower->{'firstname'} . ' ' . $borrower->{'surname'};
+ $$budget{$_}= sprintf("%.2f", $budget->{$_}) for grep{/amount/} keys %$budget;
}
# build budget hierarchy
my %labels;
my @values;
- my $hier = GetBudgetHierarchy($budget_period_id);
+ my $hier = GetBudgetHierarchy($$period{budget_period_id});
foreach my $r (@$hier) {
$r->{budget_code_indent} =~ s/ /\~/g; #
$labels{"$r->{budget_id}"} = $r->{budget_code_indent};
# if no buget_id is passed then its an add
$template->param(
- add_form => 1,
+ add_validate => 1,
dateformat => C4::Dates->new()->visual(),
- budget_id => $budget->{'budget_id'},
- budget_parent_id => $budget->{'budget_parent_id'},
- budget_dropbox => $budget_period_dropbox,
+ budget_dropbox => $budget_period_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,
+ %$period,
+ %$budget,
);
# END $OP eq ADD_FORM
#---------------------- DEFAULT DISPLAY BELOW ---------------------
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 );
+ if ( defined $$budget_hash{budget_id} ) {
+ ModBudget( $budget_hash );
} else {
- AddBudget( \%budget_hash );
+ AddBudget( $budget_hash );
}
}
my $branches = GetBranches();
- my $budget_period_dropbox = GetBudgetPeriodsDropbox($budget_period_id );
+ my $budget_period_dropbox = GetBudgetPeriodsDropbox($$period{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'},
+ %$period,
);
- my $moo = GetBudgetHierarchy($budget_period_id, $template->{param_map}->{'USER_INFO'}[0]->{'branchcode'}, $show_mine?$borrower_id:'');
+ my $moo = GetBudgetHierarchy($$period{budget_period_id}, C4::Context->userenv->{branchcode}, $show_mine?$borrower_id:'');
my @budgets = @$moo; #FIXME
my $toggle = 0;
my $period_total = 0;
my ( $period_alloc_total, $base_alloc_total, $sub_alloc_total, $base_spent_total, $base_remaining_total );
+ use YAML;
+ $debug && warn Dump(@budgets);
+ #This Looks WEIRD to me : should budgets be filtered in such a way ppl who donot own it would not see the amount spent on the budget by others ?
+
foreach my $budget (@budgets) {
# PERMISSIONS
- unless($staffflags->{'superlibrarian'} == 1 ) {
+ unless($staffflags->{'superlibrarian'} % 2 == 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 ) {
+ if ( $$period{budget_period_locked} == 1 ) {
$budget->{'budget_lock'} = 1;
} elsif ( $budget->{budget_permission} == 1 ) {
$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'};
+ for (grep {/budget_spent|budget_amount|budget_remaining|budget_unalloc/} keys %$budget){
+ $$budget{$_} = $num->format_price( $$budget{$_} ) if defined($$budget{$_})
+ }
- my $borrower = &GetMember( $budget->{budget_owner_id} );
- $budget->{budget_owner_name} = $borrower->{'firstname'} . ' ' . $borrower->{'surname'};
- $budget->{budget_borrowernumber} = $borrower->{'borrowernumber'};
+ my $borrower = &GetMember( borrowernumber=>$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),
+ budget_period_total => $num->format_price($$period{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_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,
);
} #---- END $OP eq DEFAULT
--- /dev/null
+<div class="dialog alert">
+<script type="text/javascript">
+//<![CDATA[
+
+function confirmnotdup(){
+ $("#confirm_not_duplicate").attr("value","1");
+ // alert(_("Not a duplicate confirmed. Please click on Add biblio to save the record"));
+ var checkform = $("#f");
+ Check(checkform);
+}
+//]]>
+</script>
+
+
+<h4>Duplicate suspected</h4>
+<p>Is this a duplicate of
+ <ul><!--TMPL_LOOP Name="duplicates"-->
+ <li><a href="<!--TMPL_VAR Name="url"-->?<!--TMPL_VAR Name="field_name"-->=<!-- TMPL_VAR name="dupid" -->" onclick="openWindow('<!--TMPL_VAR Name="url"-->?<!--TMPL_VAR Name="field_name"-->=<!-- TMPL_VAR name="dupid" -->&popup=1', 'Duplicate '; return false;)"><!-- TMPL_VAR name="duplicateinformation" --></a>?
+ <form action="<!--TMPL_VAR Name="action_dup_yes_url"-->"" method="get">
+ <input type="hidden" name="<!--TMPL_VAR Name="field_name"-->" value="<!-- TMPL_VAR name="dupid" -->" />
+ <input type="submit" class="edit" value="Yes: Edit existing" />
+ </form>
+ </li>
+ <!--/TMPL_LOOP--></ul>
+</p>
+<form action="<TMPL_VAR Name="action_dup_no_url"-->" method="get">
+ <input type="submit" class="save" onclick="confirmnotdup(); return false;" value="No: Save as New" />
+</form>
+</div>
+
<div class="yui-b">
<!-- TMPL_INCLUDE NAME="budgets-admin.inc" -->
-<! -- FIXME <!-- TMPL_ELSE --> <!-- /TMPL_IF --> -->
<!-- TMPL_IF name="add_form" -->
<!-- add or modify a budget period -->
+<!--TMPL_IF Name="duplicates"--><!--TMPL_INCLUDE Name="duplicates.inc"--><!--/TMPL_IF-->
<!-- TMPL_IF name="budget_period_id" -->
<h3>Modify budget period</h3>
<!-- TMPL_ELSE -->
<h3>Add budget period</h3>
-<!-- /TMPL_IF -->
-
-<form action="/cgi-bin/koha/admin/aqbudgetperiods.pl" name="Aform" method="post">
+ <!-- /TMPL_IF -->
+<form action="/cgi-bin/koha/admin/aqbudgetperiods.pl" name="f" method="post">
<fieldset class="rows">
<!-- ################################################################################# -->
<!-- display information about the budget period that must be added or modified -->
<!-- ################################################################################# -->
<input type="hidden" name="op" value="add_validate" />
- <input type="hidden" name="checked" value="0" />
+ <input type="hidden" name="confirm_not_duplicate" value="<!--TMPL_VAR Name="confirm_not_duplicate"-->" />
<input type="hidden" name="budget_period_id" value="<!-- TMPL_VAR name="budget_period_id" -->" />
<ol>
<li>
<!-- ACTIVE -->
<!-- ############################## -->
<label for="budget_period_active">Make Period Active</label>
- <input type="checkbox" id="budget_period_active" name="budget_period_active" value="1"
- <!-- TMPL_IF NAME="budget_period_active" -->checked<!-- /TMPL_IF --> />
+ <!-- TMPL_IF NAME="budget_period_active" --><input type="checkbox" checked="checked" id="budget_period_active" name="budget_period_active" value="1" checked /><!--TMPL_ELSE--> <input type="checkbox" id="budget_period_active" name="budget_period_active" value="1"/> <!--/TMPL_IF-->
</li>
<li>
<!-- LOCK -->
<!-- ############################## -->
- <label for="budget_period_active">Lock Period</label>
- <input type="checkbox" id="budget_period_locked" name="budget_period_locked" value="1"
- <!-- TMPL_IF NAME="budget_period_locked" -->checked<!-- /TMPL_IF --> />
+ <label for="budget_period_locked">Lock Period</label>
+ <!-- TMPL_IF NAME="budget_period_locked" --><input type="checkbox" checked="checked" id="budget_period_locked" name="budget_period_locked" value="1" /><!--TMPL_ELSE--> <input type="checkbox" id="budget_period_locked" name="budget_period_locked" value="1"/> <!--/TMPL_IF-->
</li>
</ol>
</fieldset>
</tr>
<!-- TMPL_LOOP name="period_loop" -->
- <!-- TMPL_IF NAME="toggle" -->
+ <!-- TMPL_IF NAME="__odd__" -->
<tr>
<!-- TMPL_ELSE -->
<tr class="highlight">
</fieldset>
<fieldset class="action">
- <input type="button" value="Submit" /> <a class="cancel" href="/cgi-bin/koha/admin/aqbudgets.pl">Cancel</a>
+ <input type="submit" value="Submit" onclick="javascript:Check(this.form);" /> <a class="cancel" href="/cgi-bin/koha/admin/aqbudgets.pl">Cancel</a>
<input type="hidden" name="budget_period_id" value="<!-- TMPL_VAR name='budget_period_id' -->" />
</fieldset>
</form>
--- /dev/null
+use strict;
+use warnings;
+use Test::More tests=>18;
+
+BEGIN {use_ok('C4::Budgets') }
+use C4::Budgets;
+use C4::Dates;
+
+print "ok 1\n";
+use YAML;
+
+#
+# Budget Periods :
+#
+my $bpid;
+my $budgetperiod;
+my $active_period;
+my $mod_status;
+my $del_status;
+ok($bpid=AddBudgetPeriod(
+ { budget_period_startdate => '2008-01-01'
+ , budget_period_enddate => '2008-12-31'
+ , budget_description => "MAPERI"}),
+ "AddBudgetPeriod with iso dates OK");
+
+if (C4::Context->preference('dateformat') eq "metric"){
+ ok($bpid=AddBudgetPeriod(
+ { budget_period_startdate => '01-01-2008'
+ , budget_period_enddate => '31-12-2008'
+ , budget_description => "MAPERI"}),
+ "AddBudgetPeriod returned $bpid");
+}
+elsif (C4::Context->preference('dateformat') eq "us"){
+ ok($bpid=AddBudgetPeriod(
+ { budget_period_startdate => '01-01-2008'
+ , budget_period_enddate => '12-31-2008'
+ , budget_description => "MAPERI"}),
+ "AddBudgetPeriod returned $bpid");
+}
+
+ok($budgetperiod=GetBudgetPeriod($bpid),
+ "GetBudgetPeriod($bpid) returned ".Dump($budgetperiod));
+ok(!GetBudgetPeriod(0) ,"GetBudgetPeriod(0) returned undef : noactive BudgetPeriod");
+$$budgetperiod{budget_period_active}=1;
+ok($mod_status=ModBudgetPeriod($budgetperiod),"ModBudgetPeriod OK");
+ok($active_period=GetBudgetPeriod(0),"GetBudgetPeriod(0) returned".Dump($active_period));
+ok(scalar(GetBudgetPeriods())>0,"GetBudgetPeriods OK");#Should at least return the Budget inserted
+ok($del_status=DelBudgetPeriod($bpid),"DelBudgetPeriod returned $del_status");
+
+#
+# Budget :
+#
+
+# Add A budget Period
+if (C4::Context->preference('dateformat') eq "metric"){
+ok($bpid=AddBudgetPeriod(
+ { budget_period_startdate =>'01-01-2008'
+ , budget_period_enddate =>'31-12-2008'
+ , budget_description =>"MAPERI"}),
+ "AddBudgetPeriod returned $bpid");
+} elsif (C4::Context->preference('dateformat') eq "us"){
+ok($bpid=AddBudgetPeriod(
+ { budget_period_startdate =>'01-01-2008'
+ , budget_period_enddate =>'12-31-2008'
+ , budget_description =>"MAPERI"}),
+ "AddBudgetPeriod returned $bpid");
+}
+else{
+ok($bpid=AddBudgetPeriod(
+ {budget_period_startdate=>'2008-01-01'
+ ,budget_period_enddate =>'2008-12-31'
+ ,budget_description =>"MAPERI"
+ }),
+ "AddBudgetPeriod returned $bpid");
+
+}
+my $budget_id;
+ok($budget_id=AddBudget(
+ { budget_code => "ABCD"
+ , budget_amount => "123.132"
+ , budget_name => "Périodiques"
+ , budget_notes => "This is a note"
+ , budget_description=> "Serials"
+ , budget_active => 1
+ , budget_period_id => $bpid
+ }
+ ),
+ "AddBudget returned $budget_id");
+#budget_code | varchar(30) | YES | | NULL | |
+#| budget_amount | decimal(28,6) | NO | | 0.000000 | |
+#| budget_amount_sublevel | decimal(28,6) | YES | | NULL | |
+#| budget_id | int(11) | NO | PRI | NULL | |
+#| budget_branchcode | varchar(10) | YES | | NULL | |
+#| budget_parent_id | int(11) | YES | | NULL | |
+#| budget_name | varchar(80) | YES | | NULL | |
+#| budget_encumb | decimal(28,6) | YES | | 0.000000 | |
+#| budget_expend | decimal(28,6) | YES | | 0.000000 | |
+#| budget_notes | mediumtext | YES | | NULL | |
+#| budget_description | mediumtext | YES | | NULL | |
+#| timestamp | timestamp | NO | | CURRENT_TIMESTAMP | |
+#| budget_period_id | int(11) | YES | MUL | NULL | |
+#| sort1_authcat | varchar(80) | YES | | NULL | |
+#| sort2_authcat | varchar(80) | YES | | NULL | |
+#| budget_owner_id | int(11) | YES | | NULL | |
+#| budget_permission | int(1) | YES | | 0 | |
+
+my $budget;
+ok($budget=GetBudget($budget_id) ,"GetBudget OK");
+$$budget{budget_permission}=1;
+ok($mod_status=ModBudget($budget),"ModBudget OK");
+ok(GetBudgets()>0,
+ "GetBudgets OK");
+ok(GetBudgets({budget_period_id=>$bpid})>0,
+ "GetBudgets With Filter OK");
+ok(GetBudgets({budget_period_id=>$bpid},{"budget_description"=>0})>0,
+ "GetBudgets With Order OK");
+ok(GetBudgets({budget_period_id=>GetBudgetPeriod(0)->{budget_period_id}},{"budget_description"=>0})>0,
+ "GetBudgets With Order
+ Getting Active budgetPeriod OK");
+ok($del_status=DelBudget($budget_id),
+ "DelBudget returned $del_status");
+
+