use C4::Context;
use Koha::Database;
use Koha::Patrons;
+use Koha::Acquisition::Invoice::Adjustments;
use C4::Debug;
use vars qw(@ISA @EXPORT);
my ($budgetperiod) = @_;
return unless($budgetperiod->{budget_period_startdate} && $budgetperiod->{budget_period_enddate});
+ undef $budgetperiod->{budget_period_id};
my $resultset = Koha::Database->new()->schema->resultset('Aqbudgetperiod');
return $resultset->create($budgetperiod)->id;
}
datecancellationprinted IS NULL
|);
$sth->execute($budget_id);
- my $sum = $sth->fetchrow_array;
+ my $sum = 0 + $sth->fetchrow_array;
$sth = $dbh->prepare(qq|
SELECT SUM(shipmentcost) AS sum
my ($shipmentcost_sum) = $sth->fetchrow_array;
$sum += $shipmentcost_sum;
+ my $adjustments = Koha::Acquisition::Invoice::Adjustments->search({budget_id => $budget_id, closedate => { '!=' => undef } },{ join => 'invoiceid' });
+ while ( my $adj = $adjustments->next ){
+ $sum += $adj->adjustment;
+ }
+
return $sum;
}
datecancellationprinted IS NULL
|);
$sth->execute($budget_id);
- my $sum = $sth->fetchrow_array;
+ my $sum = 0 + $sth->fetchrow_array;
+
+ my $adjustments = Koha::Acquisition::Invoice::Adjustments->search({budget_id => $budget_id, encumber_open => 1, closedate => undef},{ join => 'invoiceid' });
+ while ( my $adj = $adjustments->next ){
+ $sum += $adj->adjustment;
+ }
return $sum;
}
}
# Get all the budgets totals in as few queries as possible
- my $hr_budget_spent = $dbh->selectall_hashref(qq|
+ my $hr_budget_spent = $dbh->selectall_hashref(q|
SELECT aqorders.budget_id, aqbudgets.budget_parent_id,
SUM( COALESCE(unitprice_tax_included, ecost_tax_included) * quantity ) AS budget_spent
FROM aqorders JOIN aqbudgets USING (budget_id)
WHERE quantityreceived > 0 AND datecancellationprinted IS NULL
- GROUP BY budget_id
+ GROUP BY budget_id, budget_parent_id
|, 'budget_id');
- my $hr_budget_ordered = $dbh->selectall_hashref(qq|
+ my $hr_budget_ordered = $dbh->selectall_hashref(q|
SELECT aqorders.budget_id, aqbudgets.budget_parent_id,
SUM(ecost_tax_included * quantity) AS budget_ordered
FROM aqorders JOIN aqbudgets USING (budget_id)
WHERE quantityreceived = 0 AND datecancellationprinted IS NULL
- GROUP BY budget_id
+ GROUP BY budget_id, budget_parent_id
|, 'budget_id');
- my $hr_budget_spent_shipment = $dbh->selectall_hashref(qq|
+ my $hr_budget_spent_shipment = $dbh->selectall_hashref(q|
SELECT shipmentcost_budgetid as budget_id,
SUM(shipmentcost) as shipmentcost
FROM aqinvoices
WHERE closedate IS NOT NULL
GROUP BY shipmentcost_budgetid
|, 'budget_id');
- my $hr_budget_ordered_shipment = $dbh->selectall_hashref(qq|
+ my $hr_budget_ordered_shipment = $dbh->selectall_hashref(q|
SELECT shipmentcost_budgetid as budget_id,
SUM(shipmentcost) as shipmentcost
FROM aqinvoices
foreach my $budget (@sort) {
- if ($budget->{budget_parent_id} == undef) {
+ if ( not defined $budget->{budget_parent_id} ) {
_recursiveAdd( $budget, undef, $hr_budget_spent, $hr_budget_spent_shipment, $hr_budget_ordered, $hr_budget_ordered_shipment );
}
}
my ($budget) = @_;
return unless ($budget);
+ undef $budget->{budget_encumb} if $budget->{budget_encumb} eq '';
+ undef $budget->{budget_owner_id} if $budget->{budget_owner_id} eq '';
my $resultset = Koha::Database->new()->schema->resultset('Aqbudget');
return $resultset->create($budget)->id;
}
my $result = Koha::Database->new()->schema->resultset('Aqbudget')->find($budget);
return unless($result);
+ undef $budget->{budget_encumb} if $budget->{budget_encumb} eq '';
+ undef $budget->{budget_owner_id} if $budget->{budget_owner_id} eq '';
$result = $result->update($budget);
return $result->in_storage;
}
my $tidy_budget =
{ map { join( ' ', @columns ) =~ /$_/ ? ( $_ => $budget->{$_} ) : () }
keys %$budget };
+ delete $tidy_budget->{timestamp};
my $new_budget_id = AddBudget(
{
%$tidy_budget,