|
Lines 24-35
use Koha::Patrons;
Link Here
|
| 24 |
use Koha::Acquisition::Invoice::Adjustments; |
24 |
use Koha::Acquisition::Invoice::Adjustments; |
| 25 |
use C4::Debug; |
25 |
use C4::Debug; |
| 26 |
use C4::Acquisition; |
26 |
use C4::Acquisition; |
|
|
27 |
use C4::Log qw(logaction); |
| 27 |
use vars qw(@ISA @EXPORT); |
28 |
use vars qw(@ISA @EXPORT); |
| 28 |
|
29 |
|
| 29 |
BEGIN { |
30 |
BEGIN { |
| 30 |
require Exporter; |
31 |
require Exporter; |
| 31 |
@ISA = qw(Exporter); |
32 |
@ISA = qw(Exporter); |
| 32 |
@EXPORT = qw( |
33 |
@EXPORT = qw( |
| 33 |
|
34 |
|
| 34 |
&GetBudget |
35 |
&GetBudget |
| 35 |
&GetBudgetByOrderNumber |
36 |
&GetBudgetByOrderNumber |
|
Lines 39-45
BEGIN {
Link Here
|
| 39 |
&GetBudgetsReport |
40 |
&GetBudgetsReport |
| 40 |
&GetBudgetReport |
41 |
&GetBudgetReport |
| 41 |
&GetBudgetHierarchy |
42 |
&GetBudgetHierarchy |
| 42 |
&AddBudget |
43 |
&AddBudget |
| 43 |
&ModBudget |
44 |
&ModBudget |
| 44 |
&DelBudget |
45 |
&DelBudget |
| 45 |
&GetBudgetSpent |
46 |
&GetBudgetSpent |
|
Lines 54-68
BEGIN {
Link Here
|
| 54 |
&CanUserUseBudget |
55 |
&CanUserUseBudget |
| 55 |
&CanUserModifyBudget |
56 |
&CanUserModifyBudget |
| 56 |
|
57 |
|
| 57 |
&GetBudgetPeriod |
58 |
&GetBudgetPeriod |
| 58 |
&GetBudgetPeriods |
59 |
&GetBudgetPeriods |
| 59 |
&ModBudgetPeriod |
60 |
&ModBudgetPeriod |
| 60 |
&AddBudgetPeriod |
61 |
&AddBudgetPeriod |
| 61 |
&DelBudgetPeriod |
62 |
&DelBudgetPeriod |
| 62 |
|
63 |
|
| 63 |
&ModBudgetPlan |
64 |
&ModBudgetPlan |
| 64 |
|
65 |
|
| 65 |
&GetBudgetsPlanCell |
66 |
&GetBudgetsPlanCell |
| 66 |
&AddBudgetPlanValue |
67 |
&AddBudgetPlanValue |
| 67 |
&GetBudgetAuthCats |
68 |
&GetBudgetAuthCats |
| 68 |
&BudgetHasChildren |
69 |
&BudgetHasChildren |
|
Lines 71-77
BEGIN {
Link Here
|
| 71 |
|
72 |
|
| 72 |
&HideCols |
73 |
&HideCols |
| 73 |
&GetCols |
74 |
&GetCols |
| 74 |
); |
75 |
); |
| 75 |
} |
76 |
} |
| 76 |
|
77 |
|
| 77 |
# ----------------------------BUDGETS.PM-----------------------------"; |
78 |
# ----------------------------BUDGETS.PM-----------------------------"; |
|
Lines 341-347
sub GetBudgetSpent {
Link Here
|
| 341 |
quantityreceived > 0 AND |
342 |
quantityreceived > 0 AND |
| 342 |
datecancellationprinted IS NULL |
343 |
datecancellationprinted IS NULL |
| 343 |
|); |
344 |
|); |
| 344 |
$sth->execute($budget_id); |
345 |
$sth->execute($budget_id); |
| 345 |
my $sum = ( $sth->fetchrow_array || 0 ) + 0; |
346 |
my $sum = ( $sth->fetchrow_array || 0 ) + 0; |
| 346 |
|
347 |
|
| 347 |
$sth = $dbh->prepare(qq| |
348 |
$sth = $dbh->prepare(qq| |
|
Lines 359-378
sub GetBudgetSpent {
Link Here
|
| 359 |
$sum += $adj->adjustment; |
360 |
$sum += $adj->adjustment; |
| 360 |
} |
361 |
} |
| 361 |
|
362 |
|
| 362 |
return $sum; |
363 |
return $sum; |
| 363 |
} |
364 |
} |
| 364 |
|
365 |
|
| 365 |
# ------------------------------------------------------------------- |
366 |
# ------------------------------------------------------------------- |
| 366 |
sub GetBudgetOrdered { |
367 |
sub GetBudgetOrdered { |
| 367 |
my ($budget_id) = @_; |
368 |
my ($budget_id) = @_; |
| 368 |
my $dbh = C4::Context->dbh; |
369 |
my $dbh = C4::Context->dbh; |
| 369 |
my $sth = $dbh->prepare(qq| |
370 |
my $sth = $dbh->prepare(qq| |
| 370 |
SELECT SUM(| . C4::Acquisition::get_rounding_sql(qq|ecost_tax_included|) . qq| * quantity) AS sum FROM aqorders |
371 |
SELECT SUM(| . C4::Acquisition::get_rounding_sql(qq|ecost_tax_included|) . qq| * quantity) AS sum FROM aqorders |
| 371 |
WHERE budget_id = ? AND |
372 |
WHERE budget_id = ? AND |
| 372 |
quantityreceived = 0 AND |
373 |
quantityreceived = 0 AND |
| 373 |
datecancellationprinted IS NULL |
374 |
datecancellationprinted IS NULL |
| 374 |
|); |
375 |
|); |
| 375 |
$sth->execute($budget_id); |
376 |
$sth->execute($budget_id); |
| 376 |
my $sum = ( $sth->fetchrow_array || 0 ) + 0; |
377 |
my $sum = ( $sth->fetchrow_array || 0 ) + 0; |
| 377 |
|
378 |
|
| 378 |
my $adjustments = Koha::Acquisition::Invoice::Adjustments->search({budget_id => $budget_id, encumber_open => 1, closedate => undef},{ join => 'invoiceid' }); |
379 |
my $adjustments = Koha::Acquisition::Invoice::Adjustments->search({budget_id => $budget_id, encumber_open => 1, closedate => undef},{ join => 'invoiceid' }); |
|
Lines 380-386
sub GetBudgetOrdered {
Link Here
|
| 380 |
$sum += $adj->adjustment; |
381 |
$sum += $adj->adjustment; |
| 381 |
} |
382 |
} |
| 382 |
|
383 |
|
| 383 |
return $sum; |
384 |
return $sum; |
| 384 |
} |
385 |
} |
| 385 |
|
386 |
|
| 386 |
=head2 GetBudgetName |
387 |
=head2 GetBudgetName |
|
Lines 430-436
sub GetBudgetAuthCats {
Link Here
|
| 430 |
|
431 |
|
| 431 |
# ------------------------------------------------------------------- |
432 |
# ------------------------------------------------------------------- |
| 432 |
sub GetBudgetPeriods { |
433 |
sub GetBudgetPeriods { |
| 433 |
my ($filters,$orderby) = @_; |
434 |
my ($filters,$orderby) = @_; |
| 434 |
|
435 |
|
| 435 |
my $rs = Koha::Database->new()->schema->resultset('Aqbudgetperiod'); |
436 |
my $rs = Koha::Database->new()->schema->resultset('Aqbudgetperiod'); |
| 436 |
$rs = $rs->search( $filters, { order_by => $orderby } ); |
437 |
$rs = $rs->search( $filters, { order_by => $orderby } ); |
|
Lines 451-468
sub GetBudgetPeriod {
Link Here
|
| 451 |
} |
452 |
} |
| 452 |
|
453 |
|
| 453 |
sub DelBudgetPeriod{ |
454 |
sub DelBudgetPeriod{ |
| 454 |
my ($budget_period_id) = @_; |
455 |
my ($budget_period_id) = @_; |
| 455 |
my $dbh = C4::Context->dbh; |
456 |
my $dbh = C4::Context->dbh; |
| 456 |
; ## $total = number of records linked to the record that must be deleted |
457 |
; ## $total = number of records linked to the record that must be deleted |
| 457 |
my $total = 0; |
458 |
my $total = 0; |
| 458 |
|
459 |
|
| 459 |
## get information about the record that will be deleted |
460 |
## get information about the record that will be deleted |
| 460 |
my $sth = $dbh->prepare(qq| |
461 |
my $sth = $dbh->prepare(qq| |
| 461 |
DELETE |
462 |
DELETE |
| 462 |
FROM aqbudgetperiods |
463 |
FROM aqbudgetperiods |
| 463 |
WHERE budget_period_id=? | |
464 |
WHERE budget_period_id=? | |
| 464 |
); |
465 |
); |
| 465 |
return $sth->execute($budget_period_id); |
466 |
return $sth->execute($budget_period_id); |
| 466 |
} |
467 |
} |
| 467 |
|
468 |
|
| 468 |
# ------------------------------------------------------------------- |
469 |
# ------------------------------------------------------------------- |
|
Lines 487-499
sub GetBudgetHierarchy {
Link Here
|
| 487 |
LEFT JOIN borrowers b on b.borrowernumber = aqbudgets.budget_owner_id |
488 |
LEFT JOIN borrowers b on b.borrowernumber = aqbudgets.budget_owner_id |
| 488 |
JOIN aqbudgetperiods USING (budget_period_id)|; |
489 |
JOIN aqbudgetperiods USING (budget_period_id)|; |
| 489 |
|
490 |
|
| 490 |
my @where_strings; |
491 |
my @where_strings; |
| 491 |
# show only period X if requested |
492 |
# show only period X if requested |
| 492 |
if ($budget_period_id) { |
493 |
if ($budget_period_id) { |
| 493 |
push @where_strings," aqbudgets.budget_period_id = ?"; |
494 |
push @where_strings," aqbudgets.budget_period_id = ?"; |
| 494 |
push @bind_params, $budget_period_id; |
495 |
push @bind_params, $budget_period_id; |
| 495 |
} |
496 |
} |
| 496 |
# show only budgets owned by me, my branch or everyone |
497 |
# show only budgets owned by me, my branch or everyone |
| 497 |
if ($owner) { |
498 |
if ($owner) { |
| 498 |
if ($branchcode) { |
499 |
if ($branchcode) { |
| 499 |
push @where_strings, |
500 |
push @where_strings, |
|
Lines 509-518
sub GetBudgetHierarchy {
Link Here
|
| 509 |
push @bind_params, $branchcode; |
510 |
push @bind_params, $branchcode; |
| 510 |
} |
511 |
} |
| 511 |
} |
512 |
} |
| 512 |
$query.=" WHERE ".join(' AND ', @where_strings) if @where_strings; |
513 |
$query.=" WHERE ".join(' AND ', @where_strings) if @where_strings; |
| 513 |
$debug && warn $query,join(",",@bind_params); |
514 |
$debug && warn $query,join(",",@bind_params); |
| 514 |
my $sth = $dbh->prepare($query); |
515 |
my $sth = $dbh->prepare($query); |
| 515 |
$sth->execute(@bind_params); |
516 |
$sth->execute(@bind_params); |
| 516 |
|
517 |
|
| 517 |
my %links; |
518 |
my %links; |
| 518 |
# create hash with budget_id has key |
519 |
# create hash with budget_id has key |
|
Lines 644-650
sub AddBudget {
Link Here
|
| 644 |
undef $budget->{budget_encumb} if defined $budget->{budget_encumb} && $budget->{budget_encumb} eq ''; |
645 |
undef $budget->{budget_encumb} if defined $budget->{budget_encumb} && $budget->{budget_encumb} eq ''; |
| 645 |
undef $budget->{budget_owner_id} if defined $budget->{budget_owner_id} && $budget->{budget_owner_id} eq ''; |
646 |
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'); |
647 |
my $resultset = Koha::Database->new()->schema->resultset('Aqbudget'); |
| 647 |
return $resultset->create($budget)->id; |
648 |
my $id = $resultset->create($budget)->id; |
|
|
649 |
|
| 650 |
# Log the addition |
| 651 |
if (C4::Context->preference("AcqLog")) { |
| 652 |
my $infos = |
| 653 |
sprintf("%010d", $budget->{budget_amount}) . |
| 654 |
sprintf("%010d", $budget->{budget_encumb}) . |
| 655 |
sprintf("%010d", $budget->{budget_expend}); |
| 656 |
logaction( |
| 657 |
'ACQUISITIONS', |
| 658 |
'CREATE_FUND', |
| 659 |
$id, |
| 660 |
$infos |
| 661 |
); |
| 662 |
} |
| 663 |
return $id; |
| 648 |
} |
664 |
} |
| 649 |
|
665 |
|
| 650 |
# ------------------------------------------------------------------- |
666 |
# ------------------------------------------------------------------- |
|
Lines 654-659
sub ModBudget {
Link Here
|
| 654 |
my $result = Koha::Database->new()->schema->resultset('Aqbudget')->find($budget); |
670 |
my $result = Koha::Database->new()->schema->resultset('Aqbudget')->find($budget); |
| 655 |
return unless($result); |
671 |
return unless($result); |
| 656 |
|
672 |
|
|
|
673 |
# Log this modification |
| 674 |
if (C4::Context->preference("AcqLog")) { |
| 675 |
my $infos = |
| 676 |
sprintf("%010d", $budget->{budget_amount}) . |
| 677 |
sprintf("%010d", $budget->{budget_encumb}) . |
| 678 |
sprintf("%010d", $budget->{budget_expend}) . |
| 679 |
sprintf("%010d", $result->budget_amount) . |
| 680 |
sprintf("%010d", $result->budget_encumb) . |
| 681 |
sprintf("%010d", $result->budget_expend) . |
| 682 |
sprintf("%010d", 0 - ($result->budget_amount - $budget->{budget_amount})); |
| 683 |
logaction( |
| 684 |
'ACQUISITIONS', |
| 685 |
'MODIFY_FUND', |
| 686 |
$budget->{budget_id}, |
| 687 |
$infos |
| 688 |
); |
| 689 |
} |
| 690 |
|
| 657 |
undef $budget->{budget_encumb} if defined $budget->{budget_encumb} && $budget->{budget_encumb} eq ''; |
691 |
undef $budget->{budget_encumb} if defined $budget->{budget_encumb} && $budget->{budget_encumb} eq ''; |
| 658 |
undef $budget->{budget_owner_id} if defined $budget->{budget_owner_id} && $budget->{budget_owner_id} eq ''; |
692 |
undef $budget->{budget_owner_id} if defined $budget->{budget_owner_id} && $budget->{budget_owner_id} eq ''; |
| 659 |
$result = $result->update($budget); |
693 |
$result = $result->update($budget); |
|
Lines 663-673
sub ModBudget {
Link Here
|
| 663 |
# ------------------------------------------------------------------- |
697 |
# ------------------------------------------------------------------- |
| 664 |
# FIXME Must be replaced by Koha::Acquisition::Fund->delete |
698 |
# FIXME Must be replaced by Koha::Acquisition::Fund->delete |
| 665 |
sub DelBudget { |
699 |
sub DelBudget { |
| 666 |
my ($budget_id) = @_; |
700 |
my ($budget_id) = @_; |
| 667 |
my $dbh = C4::Context->dbh; |
701 |
my $dbh = C4::Context->dbh; |
| 668 |
my $sth = $dbh->prepare("delete from aqbudgets where budget_id=?"); |
702 |
my $sth = $dbh->prepare("delete from aqbudgets where budget_id=?"); |
| 669 |
my $rc = $sth->execute($budget_id); |
703 |
my $rc = $sth->execute($budget_id); |
| 670 |
return $rc; |
704 |
# Log the deletion |
|
|
705 |
if (C4::Context->preference("AcqLog")) { |
| 706 |
logaction( |
| 707 |
'ACQUISITIONS', |
| 708 |
'DELETE_FUND', |
| 709 |
$budget_id |
| 710 |
); |
| 711 |
} |
| 712 |
return $rc; |
| 671 |
} |
713 |
} |
| 672 |
|
714 |
|
| 673 |
|
715 |
|