From e9ea9d2d558fee9894d3579a2c9a460bb7615235 Mon Sep 17 00:00:00 2001 From: Laura_Escamilla Date: Thu, 18 Sep 2025 16:22:59 +0000 Subject: [PATCH] Bug 35612: Added branch code logic --- Koha/Account.pm | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/Koha/Account.pm b/Koha/Account.pm index 0491325f5a..f8552cf2c2 100644 --- a/Koha/Account.pm +++ b/Koha/Account.pm @@ -28,6 +28,7 @@ use C4::Log qw( logaction ); use C4::Stats qw( UpdateStats ); use C4::Overdues qw(GetFine); use C4::Context; +use C4::Circulation; use Koha::Patrons; use Koha::Account::Credits; @@ -509,6 +510,30 @@ sub add_debit { $schema->txn_do( sub { + my $branch_source = C4::Context->preference('AccountLinesBranchSource'); + my $branchcode; + + if ( $branch_source eq 'patronhomebranch' ) { + my $patron = Koha::Patrons->find( $self->{patron_id} ); + $branchcode = $patron ? $patron->branchcode : undef; + + } elsif ( $branch_source eq 'itemhomebranch' && $item_id ) { + my $item = Koha::Items->find($item_id); + $branchcode = $item ? $item->homebranch : undef; + + } elsif ( $branch_source eq 'checkoutbranch' && $issue_id ) { + my $issue = Koha::Checkouts->find($issue_id); + $branchcode = $issue ? $issue->branchcode : undef; + + } elsif ( $branch_source eq 'circcontrolbranch' && $item_id ) { + my $item = Koha::Items->find($item_id); + my $patron = Koha::Patrons->find( $self->{patron_id} ); + $branchcode = + ( $item && $patron ) + ? C4::Circulation::_GetCircControlBranch( $item, $patron ) + : undef; + } + # Insert the account line $line = Koha::Account::Line->new( { @@ -533,7 +558,7 @@ sub add_debit { ? ( old_issue_id => $old_issue_id ) : () ), - branchcode => $library_id, + branchcode => $branchcode, register_id => $cash_register, ( $debit_type eq 'OVERDUE' -- 2.39.5