Lines 588-593
sub DelBudget {
Link Here
|
588 |
} |
588 |
} |
589 |
|
589 |
|
590 |
|
590 |
|
|
|
591 |
sub CopyBudget { |
592 |
my ($budgetperiod, $budget_period_id) = @_; |
593 |
my $prev_budget_period_id = $budgetperiod->{'copy_previous_budget'}; |
594 |
my $copy_data_budget = $budgetperiod->{'copy_data_budget'}; |
595 |
#Creates a copy of a selected budget |
596 |
if ($prev_budget_period_id != 0) { |
597 |
#Get all the funds of that budget |
598 |
my $dbh = C4::Context->dbh; |
599 |
my $query = " |
600 |
SELECT * |
601 |
FROM aqbudgets |
602 |
WHERE budget_period_id=?"; |
603 |
my $sth = $dbh->prepare($query); |
604 |
$sth->execute( $prev_budget_period_id ); |
605 |
my $result = $sth->fetchall_arrayref({}); |
606 |
my @budget_is_copy_of; |
607 |
#Copy all the funds to the new budget |
608 |
foreach my $budget (@$result){ |
609 |
$budget->{'budget_period_id'} = $budget_period_id; |
610 |
#Update the parent_id to be the id of the copy of that parent |
611 |
$budget->{'budget_parent_id'} = $budget_is_copy_of[$budget->{'budget_parent_id'}]; |
612 |
my $new_budget_id = C4::Budgets::AddBudget($budget); |
613 |
|
614 |
#Remember this budget is a copy of which |
615 |
$budget_is_copy_of[$budget->{'budget_id'}] = $new_budget_id; |
616 |
|
617 |
if ($copy_data_budget) { |
618 |
#Transfers the orders from the previous fund to the new |
619 |
my $query = " |
620 |
UPDATE aqorders SET budget_id = ? |
621 |
WHERE budget_id=? AND |
622 |
quantityreceived = 0 AND |
623 |
datecancellationprinted IS NULL"; |
624 |
my $sth = $dbh->prepare($query); |
625 |
$sth->execute($new_budget_id, $budget->{'budget_id'} ); |
626 |
} |
627 |
} |
628 |
#Disable the previous budget |
629 |
my $query = " |
630 |
UPDATE aqbudgetperiods SET budget_period_active = 0 |
631 |
WHERE budget_period_id=?"; |
632 |
my $sth = $dbh->prepare($query); |
633 |
$sth->execute( $prev_budget_period_id ); |
634 |
} |
635 |
} |
636 |
|
591 |
=head2 GetBudget |
637 |
=head2 GetBudget |
592 |
|
638 |
|
593 |
&GetBudget($budget_id); |
639 |
&GetBudget($budget_id); |