Lines 37-42
script to administer the budget periods table
Link Here
|
37 |
- we show the record having primkey=$primkey and ask for deletion validation form |
37 |
- we show the record having primkey=$primkey and ask for deletion validation form |
38 |
if $op=delete_confirmed |
38 |
if $op=delete_confirmed |
39 |
- we delete the record having primkey=$primkey |
39 |
- we delete the record having primkey=$primkey |
|
|
40 |
if $op=duplicate_form |
41 |
- displays the duplication of budget period form (allowing specification of dates) |
42 |
if $op=duplicate_budget |
43 |
- we perform the duplication of the budget period specified as budget_period_id |
40 |
|
44 |
|
41 |
=cut |
45 |
=cut |
42 |
|
46 |
|
Lines 54-59
use C4::Output;
Link Here
|
54 |
use C4::Acquisition; |
58 |
use C4::Acquisition; |
55 |
use C4::Budgets; |
59 |
use C4::Budgets; |
56 |
use C4::Debug; |
60 |
use C4::Debug; |
|
|
61 |
use C4::SQLHelper; |
57 |
|
62 |
|
58 |
my $dbh = C4::Context->dbh; |
63 |
my $dbh = C4::Context->dbh; |
59 |
|
64 |
|
Lines 169-174
elsif ( $op eq 'delete_confirmed' ) {
Link Here
|
169 |
$op='else'; |
174 |
$op='else'; |
170 |
} |
175 |
} |
171 |
|
176 |
|
|
|
177 |
# display the form for duplicating |
178 |
elsif ( $op eq 'duplicate_form'){ |
179 |
$template->param( |
180 |
DHTMLcalendar_dateformat => C4::Dates->DHTMLcalendar(), |
181 |
'duplicate_form' => '1', |
182 |
'budget_period_id' => $budget_period_id, |
183 |
); |
184 |
} |
185 |
|
186 |
# handle the actual duplication |
187 |
elsif ( $op eq 'duplicate_budget' ){ |
188 |
die "please specify a budget period id\n" if( !defined $budget_period_id || $budget_period_id eq '' ); |
189 |
my $startdate = $input->param('budget_period_startdate'); |
190 |
my $enddate = $input->param('budget_period_enddate'); |
191 |
|
192 |
my $data = GetBudgetPeriod( $budget_period_id); |
193 |
|
194 |
$data->{'budget_period_startdate'} = $startdate; |
195 |
$data->{'budget_period_enddate'} = $enddate; |
196 |
delete $data->{'budget_period_id'}; |
197 |
my $new_budget_period_id = C4::SQLHelper::InsertInTable('aqbudgetperiods', $data); |
198 |
|
199 |
my $tree = GetBudgetHierarchy( $budget_period_id ); |
200 |
|
201 |
# hash mapping old ids to new |
202 |
my %old_new; |
203 |
# hash mapping old parent ids to list of new children ids |
204 |
# only store a child here if the parents old id isnt in the old_new map |
205 |
# when the parent is found, this map will be used, and then the entry removed and their id placed in old_new |
206 |
my %parent_children; |
207 |
|
208 |
for my $entry( @$tree ){ |
209 |
die "serious errors, parent period $budget_period_id doesnt match child ", $entry->{'budget_period_id'}, "\n" if( $entry->{'budget_period_id'} != $budget_period_id ); |
210 |
my $orphan = 0; # set to 1 if we need to make an entry in parent_children |
211 |
my $old_id = delete $entry->{'budget_id'}; |
212 |
my $parent_id = delete $entry->{'budget_parent_id'}; |
213 |
$entry->{'budget_period_id'} = $new_budget_period_id; |
214 |
|
215 |
if( !defined $parent_id ){ |
216 |
} elsif( defined $parent_id && $parent_id eq '' ){ |
217 |
} elsif( defined $old_new{$parent_id} ){ |
218 |
# set parent id now |
219 |
$entry->{'budget_parent_id'} = $old_new{$parent_id}; |
220 |
} else { |
221 |
# make an entry in parent_children |
222 |
$parent_children{$parent_id} = [] unless defined $parent_children{$parent_id}; |
223 |
$orphan = 1; |
224 |
} |
225 |
|
226 |
# write it to db |
227 |
my $new_id = C4::SQLHelper::InsertInTable('aqbudgets', $entry); |
228 |
$old_new{$old_id} = $new_id; |
229 |
push @{$parent_children{$parent_id}}, $new_id if $orphan; |
230 |
|
231 |
# deal with any children |
232 |
if( defined $parent_children{$old_id} ){ |
233 |
# tell my children my new id |
234 |
for my $child ( @{$parent_children{$old_id}} ){ |
235 |
C4::SQLHelper::UpdateInTable('aqcudgets', [ 'budget_id' => $child, 'budget_parent_id' => $new_id ]); |
236 |
} |
237 |
delete $parent_children{$old_id}; |
238 |
} |
239 |
} |
240 |
|
241 |
# display the list of budgets |
242 |
$op = 'else'; |
243 |
} |
244 |
|
172 |
# DEFAULT - DISPLAY AQPERIODS TABLE |
245 |
# DEFAULT - DISPLAY AQPERIODS TABLE |
173 |
# ------------------------------------------------------------------- |
246 |
# ------------------------------------------------------------------- |
174 |
# display the list of budget periods |
247 |
# display the list of budget periods |