- ## 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<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';