Lines 342-348
sub GetBudgetSpent {
Link Here
|
342 |
datecancellationprinted IS NULL |
342 |
datecancellationprinted IS NULL |
343 |
|); |
343 |
|); |
344 |
$sth->execute($budget_id); |
344 |
$sth->execute($budget_id); |
345 |
my $sum = 0 + $sth->fetchrow_array; |
345 |
my $sum = ( $sth->fetchrow_array || 0 ) + 0; |
346 |
|
346 |
|
347 |
$sth = $dbh->prepare(qq| |
347 |
$sth = $dbh->prepare(qq| |
348 |
SELECT SUM(shipmentcost) AS sum |
348 |
SELECT SUM(shipmentcost) AS sum |
Lines 352-358
sub GetBudgetSpent {
Link Here
|
352 |
|
352 |
|
353 |
$sth->execute($budget_id); |
353 |
$sth->execute($budget_id); |
354 |
my ($shipmentcost_sum) = $sth->fetchrow_array; |
354 |
my ($shipmentcost_sum) = $sth->fetchrow_array; |
355 |
$sum += $shipmentcost_sum; |
355 |
$sum += ( $shipmentcost_sum || 0 ) + 0; |
356 |
|
356 |
|
357 |
my $adjustments = Koha::Acquisition::Invoice::Adjustments->search({budget_id => $budget_id, closedate => { '!=' => undef } },{ join => 'invoiceid' }); |
357 |
my $adjustments = Koha::Acquisition::Invoice::Adjustments->search({budget_id => $budget_id, closedate => { '!=' => undef } },{ join => 'invoiceid' }); |
358 |
while ( my $adj = $adjustments->next ){ |
358 |
while ( my $adj = $adjustments->next ){ |
Lines 373-379
sub GetBudgetOrdered {
Link Here
|
373 |
datecancellationprinted IS NULL |
373 |
datecancellationprinted IS NULL |
374 |
|); |
374 |
|); |
375 |
$sth->execute($budget_id); |
375 |
$sth->execute($budget_id); |
376 |
my $sum = 0 + $sth->fetchrow_array; |
376 |
my $sum = ( $sth->fetchrow_array || 0 ) + 0; |
377 |
|
377 |
|
378 |
my $adjustments = Koha::Acquisition::Invoice::Adjustments->search({budget_id => $budget_id, encumber_open => 1, closedate => undef},{ join => 'invoiceid' }); |
378 |
my $adjustments = Koha::Acquisition::Invoice::Adjustments->search({budget_id => $budget_id, encumber_open => 1, closedate => undef},{ join => 'invoiceid' }); |
379 |
while ( my $adj = $adjustments->next ){ |
379 |
while ( my $adj = $adjustments->next ){ |
Lines 606-617
sub _recursiveAdd {
Link Here
|
606 |
_recursiveAdd($child, $budget, $hr_budget_spent, $hr_budget_spent_shipment, $hr_budget_ordered, $hr_budget_ordered_shipment, $hr_budget_spent_adjustment, $hr_budget_ordered_adjustment ); |
606 |
_recursiveAdd($child, $budget, $hr_budget_spent, $hr_budget_spent_shipment, $hr_budget_ordered, $hr_budget_ordered_shipment, $hr_budget_spent_adjustment, $hr_budget_ordered_adjustment ); |
607 |
} |
607 |
} |
608 |
|
608 |
|
609 |
$budget->{budget_spent} += $hr_budget_spent->{$budget->{budget_id}}->{budget_spent}; |
609 |
$budget->{budget_spent} += $hr_budget_spent->{$budget->{budget_id}}->{budget_spent} || 0; |
610 |
$budget->{budget_spent} += $hr_budget_spent_shipment->{$budget->{budget_id}}->{shipmentcost}; |
610 |
$budget->{budget_spent} += $hr_budget_spent_shipment->{$budget->{budget_id}}->{shipmentcost} || 0; |
611 |
$budget->{budget_spent} += $hr_budget_spent_adjustment->{$budget->{budget_id}}->{adjustments}; |
611 |
$budget->{budget_spent} += $hr_budget_spent_adjustment->{$budget->{budget_id}}->{adjustments} || 0; |
612 |
$budget->{budget_ordered} += $hr_budget_ordered->{$budget->{budget_id}}->{budget_ordered}; |
612 |
$budget->{budget_ordered} += $hr_budget_ordered->{$budget->{budget_id}}->{budget_ordered} || 0; |
613 |
$budget->{budget_ordered} += $hr_budget_ordered_shipment->{$budget->{budget_id}}->{shipmentcost}; |
613 |
$budget->{budget_ordered} += $hr_budget_ordered_shipment->{$budget->{budget_id}}->{shipmentcost} || 0; |
614 |
$budget->{budget_ordered} += $hr_budget_ordered_adjustment->{$budget->{budget_id}}->{adjustments}; |
614 |
$budget->{budget_ordered} += $hr_budget_ordered_adjustment->{$budget->{budget_id}}->{adjustments} || 0; |
615 |
|
615 |
|
616 |
$budget->{total_spent} += $budget->{budget_spent}; |
616 |
$budget->{total_spent} += $budget->{budget_spent}; |
617 |
$budget->{total_ordered} += $budget->{budget_ordered}; |
617 |
$budget->{total_ordered} += $budget->{budget_ordered}; |
Lines 636-665
sub _add_budget_children {
Link Here
|
636 |
} |
636 |
} |
637 |
|
637 |
|
638 |
# ------------------------------------------------------------------- |
638 |
# ------------------------------------------------------------------- |
639 |
|
639 |
# FIXME Must be replaced by Koha::Acquisition::Fund->store |
640 |
sub AddBudget { |
640 |
sub AddBudget { |
641 |
my ($budget) = @_; |
641 |
my ($budget) = @_; |
642 |
return unless ($budget); |
642 |
return unless ($budget); |
643 |
|
643 |
|
644 |
undef $budget->{budget_encumb} if $budget->{budget_encumb} eq ''; |
644 |
undef $budget->{budget_encumb} if defined $budget->{budget_encumb} && $budget->{budget_encumb} eq ''; |
645 |
undef $budget->{budget_owner_id} if $budget->{budget_owner_id} eq ''; |
645 |
undef $budget->{budget_owner_id} if defined $budget->{budget_owner_id} && $budget->{budget_owner_id} eq ''; |
646 |
my $resultset = Koha::Database->new()->schema->resultset('Aqbudget'); |
646 |
my $resultset = Koha::Database->new()->schema->resultset('Aqbudget'); |
647 |
return $resultset->create($budget)->id; |
647 |
return $resultset->create($budget)->id; |
648 |
} |
648 |
} |
649 |
|
649 |
|
650 |
# ------------------------------------------------------------------- |
650 |
# ------------------------------------------------------------------- |
|
|
651 |
# FIXME Must be replaced by Koha::Acquisition::Fund->store |
651 |
sub ModBudget { |
652 |
sub ModBudget { |
652 |
my ($budget) = @_; |
653 |
my ($budget) = @_; |
653 |
my $result = Koha::Database->new()->schema->resultset('Aqbudget')->find($budget); |
654 |
my $result = Koha::Database->new()->schema->resultset('Aqbudget')->find($budget); |
654 |
return unless($result); |
655 |
return unless($result); |
655 |
|
656 |
|
656 |
undef $budget->{budget_encumb} if $budget->{budget_encumb} eq ''; |
657 |
undef $budget->{budget_encumb} if defined $budget->{budget_encumb} && $budget->{budget_encumb} eq ''; |
657 |
undef $budget->{budget_owner_id} if $budget->{budget_owner_id} eq ''; |
658 |
undef $budget->{budget_owner_id} if defined $budget->{budget_owner_id} && $budget->{budget_owner_id} eq ''; |
658 |
$result = $result->update($budget); |
659 |
$result = $result->update($budget); |
659 |
return $result->in_storage; |
660 |
return $result->in_storage; |
660 |
} |
661 |
} |
661 |
|
662 |
|
662 |
# ------------------------------------------------------------------- |
663 |
# ------------------------------------------------------------------- |
|
|
664 |
# FIXME Must be replaced by Koha::Acquisition::Fund->delete |
663 |
sub DelBudget { |
665 |
sub DelBudget { |
664 |
my ($budget_id) = @_; |
666 |
my ($budget_id) = @_; |
665 |
my $dbh = C4::Context->dbh; |
667 |
my $dbh = C4::Context->dbh; |
Lines 809-822
sub GetBudgetsReport {
Link Here
|
809 |
ON bp.budget_period_id = b.budget_period_id |
811 |
ON bp.budget_period_id = b.budget_period_id |
810 |
INNER JOIN aqorders o |
812 |
INNER JOIN aqorders o |
811 |
ON b.budget_id = o.budget_id '; |
813 |
ON b.budget_id = o.budget_id '; |
812 |
if($activity ne ''){ |
814 |
if ( $activity && $activity ne '' ) { |
813 |
$query .= 'WHERE bp.budget_period_active=? '; |
815 |
$query .= 'WHERE bp.budget_period_active=? '; |
814 |
} |
816 |
} |
815 |
$query .= 'AND (o.orderstatus != "cancelled") |
817 |
$query .= 'AND (o.orderstatus != "cancelled") |
816 |
ORDER BY b.budget_name'; |
818 |
ORDER BY b.budget_name'; |
817 |
|
819 |
|
818 |
my $sth = $dbh->prepare($query); |
820 |
my $sth = $dbh->prepare($query); |
819 |
if($activity ne ''){ |
821 |
if ( $activity && $activity ne '' ) { |
820 |
$sth->execute($activity); |
822 |
$sth->execute($activity); |
821 |
} |
823 |
} |
822 |
else{ |
824 |
else{ |
Lines 1221-1227
sub CloneBudgetHierarchy {
Link Here
|
1221 |
my @first_level_budgets = |
1223 |
my @first_level_budgets = |
1222 |
( not defined $children_of ) |
1224 |
( not defined $children_of ) |
1223 |
? map { ( not $_->{budget_parent_id} ) ? $_ : () } @$budgets |
1225 |
? map { ( not $_->{budget_parent_id} ) ? $_ : () } @$budgets |
1224 |
: map { ( $_->{budget_parent_id} == $children_of ) ? $_ : () } @$budgets; |
1226 |
: map { ( defined $_->{budget_parent_id} && $_->{budget_parent_id} == $children_of ) ? $_ : () } @$budgets; |
1225 |
|
1227 |
|
1226 |
# get only the columns of aqbudgets |
1228 |
# get only the columns of aqbudgets |
1227 |
my @columns = Koha::Database->new()->schema->source('Aqbudget')->columns; |
1229 |
my @columns = Koha::Database->new()->schema->source('Aqbudget')->columns; |