|
Lines 79-84
BEGIN {
Link Here
|
| 79 |
CloneBudgetPeriod |
79 |
CloneBudgetPeriod |
| 80 |
CloneBudgetHierarchy |
80 |
CloneBudgetHierarchy |
| 81 |
MoveOrders |
81 |
MoveOrders |
|
|
82 |
FieldsForCalculatingFundValues |
| 82 |
); |
83 |
); |
| 83 |
} |
84 |
} |
| 84 |
|
85 |
|
|
Lines 341-350
sub ModBudgetPlan {
Link Here
|
| 341 |
sub GetBudgetSpent { |
342 |
sub GetBudgetSpent { |
| 342 |
my ($budget_id) = @_; |
343 |
my ($budget_id) = @_; |
| 343 |
my $dbh = C4::Context->dbh; |
344 |
my $dbh = C4::Context->dbh; |
| 344 |
# unitprice_tax_included should always been set here |
345 |
|
| 345 |
# we should not need to retrieve ecost_tax_included |
346 |
# Choose correct unitprice and ecost fields |
|
|
347 |
my ( $unitprice_field, $ecost_field ) = FieldsForCalculatingFundValues(); |
| 348 |
|
| 346 |
my $sth = $dbh->prepare(qq| |
349 |
my $sth = $dbh->prepare(qq| |
| 347 |
SELECT SUM( | . C4::Acquisition::get_rounding_sql("COALESCE(unitprice_tax_included, ecost_tax_included)") . qq| * quantity ) AS sum FROM aqorders |
350 |
SELECT SUM( | . C4::Acquisition::get_rounding_sql("COALESCE($unitprice_field, $ecost_field)") . qq| * quantity ) AS sum FROM aqorders |
| 348 |
WHERE budget_id = ? AND |
351 |
WHERE budget_id = ? AND |
| 349 |
quantityreceived > 0 AND |
352 |
quantityreceived > 0 AND |
| 350 |
datecancellationprinted IS NULL |
353 |
datecancellationprinted IS NULL |
|
Lines 374-381
sub GetBudgetSpent {
Link Here
|
| 374 |
sub GetBudgetOrdered { |
377 |
sub GetBudgetOrdered { |
| 375 |
my ($budget_id) = @_; |
378 |
my ($budget_id) = @_; |
| 376 |
my $dbh = C4::Context->dbh; |
379 |
my $dbh = C4::Context->dbh; |
|
|
380 |
|
| 381 |
# Get correct unitprice and ecost prices as possible |
| 382 |
my ( $unitprice_field, $ecost_field ) = FieldsForCalculatingFundValues(); |
| 383 |
|
| 377 |
my $sth = $dbh->prepare(qq| |
384 |
my $sth = $dbh->prepare(qq| |
| 378 |
SELECT SUM(| . C4::Acquisition::get_rounding_sql(qq|ecost_tax_included|) . qq| * quantity) AS sum FROM aqorders |
385 |
SELECT SUM(| . C4::Acquisition::get_rounding_sql(qq|$ecost_field|) . qq| * quantity) AS sum FROM aqorders |
| 379 |
WHERE budget_id = ? AND |
386 |
WHERE budget_id = ? AND |
| 380 |
quantityreceived = 0 AND |
387 |
quantityreceived = 0 AND |
| 381 |
datecancellationprinted IS NULL |
388 |
datecancellationprinted IS NULL |
|
Lines 550-567
sub GetBudgetHierarchy {
Link Here
|
| 550 |
foreach my $first_parent (@first_parents) { |
557 |
foreach my $first_parent (@first_parents) { |
| 551 |
_add_budget_children(\@sort, $first_parent, 0); |
558 |
_add_budget_children(\@sort, $first_parent, 0); |
| 552 |
} |
559 |
} |
|
|
560 |
|
| 561 |
# Get correct unitprice and ecost prices as possible |
| 562 |
my ( $unitprice_field, $ecost_field ) = FieldsForCalculatingFundValues(); |
| 563 |
|
| 553 |
if (!$skiptotals) { |
564 |
if (!$skiptotals) { |
| 554 |
# Get all the budgets totals in as few queries as possible |
565 |
# Get all the budgets totals in as few queries as possible |
| 555 |
my $hr_budget_spent = $dbh->selectall_hashref(q| |
566 |
my $hr_budget_spent = $dbh->selectall_hashref(q| |
| 556 |
SELECT aqorders.budget_id, aqbudgets.budget_parent_id, |
567 |
SELECT aqorders.budget_id, aqbudgets.budget_parent_id, |
| 557 |
SUM( | . C4::Acquisition::get_rounding_sql(qq|COALESCE(unitprice_tax_included, ecost_tax_included)|) . q| * quantity ) AS budget_spent |
568 |
SUM( | . C4::Acquisition::get_rounding_sql(qq|COALESCE($unitprice_field, $ecost_field)|) . q| * quantity ) AS budget_spent |
| 558 |
FROM aqorders JOIN aqbudgets USING (budget_id) |
569 |
FROM aqorders JOIN aqbudgets USING (budget_id) |
| 559 |
WHERE quantityreceived > 0 AND datecancellationprinted IS NULL |
570 |
WHERE quantityreceived > 0 AND datecancellationprinted IS NULL |
| 560 |
GROUP BY budget_id, budget_parent_id |
571 |
GROUP BY budget_id, budget_parent_id |
| 561 |
|, 'budget_id'); |
572 |
|, 'budget_id'); |
| 562 |
my $hr_budget_ordered = $dbh->selectall_hashref(q| |
573 |
my $hr_budget_ordered = $dbh->selectall_hashref(q| |
| 563 |
SELECT aqorders.budget_id, aqbudgets.budget_parent_id, |
574 |
SELECT aqorders.budget_id, aqbudgets.budget_parent_id, |
| 564 |
SUM( | . C4::Acquisition::get_rounding_sql(qq|ecost_tax_included|) . q| * quantity) AS budget_ordered |
575 |
SUM( | . C4::Acquisition::get_rounding_sql(qq|$ecost_field|) . q| * quantity) AS budget_ordered |
| 565 |
FROM aqorders JOIN aqbudgets USING (budget_id) |
576 |
FROM aqorders JOIN aqbudgets USING (budget_id) |
| 566 |
WHERE quantityreceived = 0 AND datecancellationprinted IS NULL |
577 |
WHERE quantityreceived = 0 AND datecancellationprinted IS NULL |
| 567 |
GROUP BY budget_id, budget_parent_id |
578 |
GROUP BY budget_id, budget_parent_id |
|
Lines 1399-1404
sub MoveOrders {
Link Here
|
| 1399 |
return \@report; |
1410 |
return \@report; |
| 1400 |
} |
1411 |
} |
| 1401 |
|
1412 |
|
|
|
1413 |
=head2 FieldsForCalculatingFundValues |
| 1414 |
|
| 1415 |
my ( $unitprice_field, $ecost_field ) = FieldsForCalculatingFundValues(); |
| 1416 |
|
| 1417 |
Fetch the tax inclusive or tax exclusive database fields for caclulating fund values based |
| 1418 |
on the value of the CalculateFundValuesIncludingTax system preference. |
| 1419 |
|
| 1420 |
=cut |
| 1421 |
|
| 1422 |
sub FieldsForCalculatingFundValues { |
| 1423 |
|
| 1424 |
# Choose correct unitprice and ecost fields |
| 1425 |
my $unitprice_field = 'unitprice_tax_included'; |
| 1426 |
my $ecost_field = 'ecost_tax_included'; |
| 1427 |
|
| 1428 |
if ( !C4::Context->preference('CalculateFundValuesIncludingTax') ) { |
| 1429 |
$unitprice_field = 'unitprice_tax_excluded'; |
| 1430 |
$ecost_field = 'ecost_tax_excluded'; |
| 1431 |
} |
| 1432 |
|
| 1433 |
return ( $unitprice_field, $ecost_field); |
| 1434 |
} |
| 1435 |
|
| 1402 |
END { } # module clean-up code here (global destructor) |
1436 |
END { } # module clean-up code here (global destructor) |
| 1403 |
|
1437 |
|
| 1404 |
1; |
1438 |
1; |