@@ -, +, @@ --- C4/Accounts.pm | 2 + C4/Circulation.pm | 10 ++++- C4/Log.pm | 2 +- C4/Overdues.pm | 14 +++++-- C4/Reserves.pm | 1 + C4/SIP/ILS.pm | 1 + C4/SIP/ILS/Transaction/FeePayment.pm | 17 ++++---- Koha/Account.pm | 23 ++++++++--- Koha/Account/Line.pm | 7 +++- Koha/Hold.pm | 9 +++-- Koha/Patron.pm | 7 ++-- Koha/REST/V1/Patrons/Account.pm | 1 + .../data/mysql/atomicupdate/bug_22600.perl | 40 +++++++++++++++++++ members/mancredit.pl | 3 +- members/pay.pl | 2 + members/paycollect.pl | 3 ++ offline_circ/process_koc.pl | 2 +- opac/opac-account-pay-paypal-return.pl | 3 +- 18 files changed, 118 insertions(+), 29 deletions(-) create mode 100644 installer/data/mysql/atomicupdate/bug_22600.perl --- a/C4/Accounts.pm +++ a/C4/Accounts.pm @@ -107,6 +107,7 @@ sub chargelostitem{ description => $description, note => $processingfeenote, user_id => C4::Context->userenv ? C4::Context->userenv->{'number'} : undef, + interface => C4::Context->interface, library_id => C4::Context->userenv ? C4::Context->userenv->{'branch'} : undef, type => 'processing', item_id => $itemnumber, @@ -122,6 +123,7 @@ sub chargelostitem{ description => $description, note => undef, user_id => C4::Context->userenv ? C4::Context->userenv->{'number'} : undef, + interface => C4::Context->interface, library_id => C4::Context->userenv ? C4::Context->userenv->{'branch'} : undef, type => 'lost_item', item_id => $itemnumber, --- a/C4/Circulation.pm +++ a/C4/Circulation.pm @@ -2416,6 +2416,7 @@ sub _FixAccountForLostAndReturned { { amount => $credit_total, description => 'Item Returned ' . $item_id, type => 'lost_item_return', + interface => C4::Context->interface, library_id => $branchcode } ); @@ -3220,6 +3221,7 @@ sub AddIssuingCharge { note => undef, user_id => C4::Context->userenv ? C4::Context->userenv->{'number'} : undef, library_id => C4::Context->userenv ? C4::Context->userenv->{'branch'} : undef, + interface => C4::Context->interface, type => 'rent', item_id => $checkout->itemnumber, issue_id => $checkout->issue_id, @@ -3810,7 +3812,13 @@ sub ProcessOfflinePayment { my $patron = Koha::Patrons->find({ cardnumber => $operation->{cardnumber} }); - $patron->account->pay({ amount => $operation->{amount}, library_id => $operation->{branchcode} }); + $patron->account->pay( + { + amount => $operation->{amount}, + library_id => $operation->{branchcode}, + interface => 'koc' + } + ); return "Success."; } --- a/C4/Log.pm +++ a/C4/Log.pm @@ -56,7 +56,7 @@ The functions in this module perform various functions in order to log all the o =item logaction - &logaction($modulename, $actionname, $objectnumber, $infos); + &logaction($modulename, $actionname, $objectnumber, $infos, $interface); Adds a record into action_logs table to report the different changes upon the database. Each log entry includes the number of the user currently logged in. For batch --- a/C4/Overdues.pm +++ a/C4/Overdues.pm @@ -573,8 +573,15 @@ sub UpdateFine { if ( $data ) { if ( $data->{'amount'} != $amount ) { - my $accountline = Koha::Account::Lines->find( $data->{accountlines_id} ); - $accountline->adjust({ amount => $amount, type => 'fine_update' }); + my $accountline = + Koha::Account::Lines->find( $data->{accountlines_id} ); + $accountline->adjust( + { + amount => $amount, + type => 'fine_update', + interface => C4::Context->interface + } + ); } } else { if ( $amount ) { # Don't add new fines with an amount of 0 @@ -592,7 +599,8 @@ sub UpdateFine { description => $desc, note => undef, user_id => undef, - library_id => undef, + interface => C4::Context->interface, + library_id => undef, #FIXME: Should we grab the checkout or circ-control branch here perhaps? type => 'fine', item_id => $itemnum, issue_id => $issue_id, --- a/C4/Reserves.pm +++ a/C4/Reserves.pm @@ -575,6 +575,7 @@ sub ChargeReserveFee { note => undef, user_id => C4::Context->userenv ? C4::Context->userenv->{'number'} : undef, library_id => C4::Context->userenv ? C4::Context->userenv->{'branch'} : undef, + interface => C4::Context->interface, sip => undef, invoice_type => undef, type => 'reserve', --- a/C4/SIP/ILS.pm +++ a/C4/SIP/ILS.pm @@ -21,6 +21,7 @@ use C4::SIP::ILS::Transaction::RenewAll; my $debug = 0; +C4::Context->interface('SIP'); my %supports = ( 'magnetic media' => 1, 'security inhibit' => 0, --- a/C4/SIP/ILS/Transaction/FeePayment.pm +++ a/C4/SIP/ILS/Transaction/FeePayment.pm @@ -28,6 +28,7 @@ use parent qw(C4::SIP::ILS::Transaction); our $debug = 0; my %fields = (); +C4::Context->interface('opac'); sub new { my $class = shift; @@ -65,10 +66,11 @@ sub pay { if ( $fee ) { $account->pay( { - amount => $amt, - sip => $sip_type, - type => $type, - lines => [$fee], + amount => $amt, + sip => $sip_type, + type => $type, + lines => [$fee], + interface => C4::Context->interface } ); return 1; @@ -80,9 +82,10 @@ sub pay { else { $account->pay( { - amount => $amt, - sip => $sip_type, - type => $type, + amount => $amt, + sip => $sip_type, + type => $type, + interface => C4::Context->interface } ); return 1; --- a/Koha/Account.pm +++ a/Koha/Account.pm @@ -86,6 +86,7 @@ sub pay { my $patron = Koha::Patrons->find( $self->{patron_id} ); my $manager_id = $userenv ? $userenv->{number} : 0; + my $interface = $params ? ( $params->{interface} || C4::Context->interface ) : C4::Context->interface; my @fines_paid; # List of account lines paid on with this payment @@ -135,7 +136,8 @@ sub pay { manager_id => $manager_id, note => $note, } - ) + ), + $interface ); push( @fines_paid, $fine->id ); } @@ -185,7 +187,8 @@ sub pay { manager_id => $manager_id, note => $note, } - ) + ), + $interface ); push( @fines_paid, $fine->id ); } @@ -211,6 +214,7 @@ sub pay { payment_type => $payment_type, amountoutstanding => 0 - $balance_remaining, manager_id => $manager_id, + interface => $interface, branchcode => $library_id, note => $note, } @@ -244,7 +248,8 @@ sub pay { accountlines_paid => \@fines_paid, manager_id => $manager_id, } - ) + ), + $interface ); } @@ -289,6 +294,7 @@ my $credit_line = Koha::Account->new({ patron_id => $patron_id })->add_credit( description => $description, note => $note, user_id => $user_id, + interface => $interface, library_id => $library_id, sip => $sip, payment_type => $payment_type, @@ -315,6 +321,7 @@ sub add_credit { my $description = $params->{description} // q{}; my $note = $params->{note} // q{}; my $user_id = $params->{user_id}; + my $interface = $params->{interface}; my $library_id = $params->{library_id}; my $sip = $params->{sip}; my $payment_type = $params->{payment_type}; @@ -344,6 +351,7 @@ sub add_credit { payment_type => $payment_type, note => $note, manager_id => $user_id, + interface => $interface, branchcode => $library_id, itemnumber => $item_id, lastincrement => undef, @@ -382,7 +390,8 @@ sub add_credit { manager_id => $user_id, branchcode => $library_id, } - ) + ), + $interface ); } } @@ -401,6 +410,7 @@ my $debit_line = Koha::Account->new({ patron_id => $patron_id })->add_debit( description => $description, note => $note, user_id => $user_id, + interface => $interface, library_id => $library_id, type => $debit_type, item_id => $item_id, @@ -437,6 +447,7 @@ sub add_debit { my $description = $params->{description} // q{}; my $note = $params->{note} // q{}; my $user_id = $params->{user_id}; + my $interface = $params->{interface}; my $library_id = $params->{library_id}; my $type = $params->{type}; my $item_id = $params->{item_id}; @@ -468,6 +479,7 @@ sub add_debit { payment_type => undef, note => $note, manager_id => $user_id, + interface => $interface, itemnumber => $item_id, issue_id => $issue_id, branchcode => $library_id, @@ -498,7 +510,8 @@ sub add_debit { itemnumber => $item_id, manager_id => $user_id, } - ) + ), + $interface ); } } --- a/Koha/Account/Line.pm +++ a/Koha/Account/Line.pm @@ -229,8 +229,9 @@ This method allows updating a debit or credit on a patron's account $account_line->adjust( { - amount => $amount, - type => $update_type, + amount => $amount, + type => $update_type, + interface => $interface } ); @@ -250,6 +251,7 @@ sub adjust { my $amount = $params->{amount}; my $update_type = $params->{type}; + my $interface = $params->{interface}; unless ( exists($Koha::Account::Line::allowed_update->{$update_type}) ) { Koha::Exceptions::Account::UnrecognisedType->throw( @@ -286,6 +288,7 @@ sub adjust { amount => $new_outstanding * -1, description => 'Overpayment refund', type => 'credit', + interface => $interface, ( $update_type eq 'fine_update' ? ( item_id => $self->itemnumber ) : ()), } ); --- a/Koha/Hold.pm +++ a/Koha/Hold.pm @@ -369,11 +369,12 @@ sub cancel { Koha::Account->new( { patron_id => $self->borrowernumber } ); $account->add_debit( { - amount => $charge, - user_id => C4::Context->userenv ? C4::Context->userenv->{'number'} : undef, + amount => $charge, + user_id => C4::Context->userenv ? C4::Context->userenv->{'number'} : undef, + interface => C4::Context->interface, library_id => C4::Context->userenv ? C4::Context->userenv->{'branch'} : undef, - type => 'hold_expired', - item_id => $self->itemnumber + type => 'hold_expired', + item_id => $self->itemnumber } ); } --- a/Koha/Patron.pm +++ a/Koha/Patron.pm @@ -848,10 +848,11 @@ sub add_enrolment_fee_if_needed { if ( $enrolment_fee && $enrolment_fee > 0 ) { $self->account->add_debit( { - amount => $enrolment_fee, - user_id => C4::Context->userenv ? C4::Context->userenv->{'number'} : undef, + amount => $enrolment_fee, + user_id => C4::Context->userenv ? C4::Context->userenv->{'number'} : undef, + interface => C4::Context->interface, library_id => C4::Context->userenv ? C4::Context->userenv->{'branch'} : undef, - type => 'account' + type => 'account' } ); } --- a/Koha/REST/V1/Patrons/Account.pm +++ a/Koha/REST/V1/Patrons/Account.pm @@ -114,6 +114,7 @@ sub add_credit { description => $description, note => $note, user_id => $user->id, + interface => 'api', library_id => $library_id } ); --- a/installer/data/mysql/atomicupdate/bug_22600.perl +++ a/installer/data/mysql/atomicupdate/bug_22600.perl @@ -0,0 +1,40 @@ +# DO NOT PUSH - UPDATE IS INLINED WITHIN UPDATEDATABASE + +$DBversion = 'XXX'; # will be replaced by the RM +if ( CheckVersion($DBversion) ) { + + if ( !column_exists( 'accountlines', 'status' ) ) { + $dbh->do( + qq{ + ALTER TABLE `accountlines` + ADD + `interface` varchar(16) DEFAULT 'script' + AFTER + `manager_id` + } + ); + } + + $dbh->do(qq{ + UPDATE + `accountlines` + SET + interface = 'opac' + WHERE + borrowernumber = manager_id; + }); + + $dbh->do(qq{ + UPDATE + `accountlines` + SET + interface = 'intranet' + WHERE + manager_id IS NOT NULL + AND + manager_id != borrowernumber; + }); + + SetVersion($DBversion); + print "Upgrade to $DBversion done (Bug 22518 - Fix accounttype 'O' to 'FU')\n"; +} --- a/members/mancredit.pl +++ a/members/mancredit.pl @@ -90,7 +90,8 @@ if ($add){ library_id => $library_id, note => $note, type => $type, - user_id => $logged_in_user->id + user_id => $logged_in_user->id, + interface => C4::Context->interface }); if ( C4::Context->preference('AccountAutoReconcile') ) { --- a/members/pay.pl +++ a/members/pay.pl @@ -114,6 +114,7 @@ elsif ( $input->param('confirm_writeoff') ) { lines => [ scalar Koha::Account::Lines->find($accountlines_id) ], type => 'writeoff', note => $payment_note, + interface => C4::Context->interface, library_id => $branch, } ); @@ -218,6 +219,7 @@ sub writeoff_all { lines => [ scalar Koha::Account::Lines->find($accountlines_id) ], type => 'writeoff', note => $payment_note, + interface => C4::Context->interface, library_id => $branch, } ); --- a/members/paycollect.pl +++ a/members/paycollect.pl @@ -126,6 +126,7 @@ if ( $total_paid and $total_paid ne '0.00' ) { amount => $total_paid, library_id => $branch, note => $payment_note, + interface => C4::Context->interface, payment_type => $payment_type, } ); @@ -158,6 +159,7 @@ if ( $total_paid and $total_paid ne '0.00' ) { amount => $total_paid, lines => \@lines, note => $note, + interface => C4::Context->interface, payment_type => $payment_type, } ); @@ -169,6 +171,7 @@ if ( $total_paid and $total_paid ne '0.00' ) { amount => $total_paid, note => $note, payment_type => $payment_type, + interface => C4::Context->interface } ); } --- a/offline_circ/process_koc.pl +++ a/offline_circ/process_koc.pl @@ -371,7 +371,7 @@ sub kocMakePayment { my $patron = Koha::Patrons->find( { cardnumber => $cardnumber } ); Koha::Account->new( { patron_id => $patron->id } ) - ->pay( { amount => $amount } ); + ->pay( { amount => $amount, interface => C4::Context->interface } ); push @output, { --- a/opac/opac-account-pay-paypal-return.pl +++ a/opac/opac-account-pay-paypal-return.pl @@ -103,7 +103,8 @@ if ( $response->is_success ) { { amount => $amount, lines => \@lines, - note => 'PayPal' + note => 'PayPal', + interface => C4::Context->interface } ); } --