From e3ac6c30062a0b32d79defba80cfba01481a93cc Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Thu, 28 Mar 2019 10:00:22 +0000 Subject: [PATCH] Bug 22600: Add 'interface' to accountlines This patch adds the 'interface' field to the accountlines table and updates all Koha::Object routines and calls to use it. Signed-off-by: Martin Renvoize Signed-off-by: Josef Moravec --- C4/Accounts.pm | 2 + C4/Circulation.pm | 10 ++++- C4/Log.pm | 2 +- C4/Overdues.pm | 14 +++++-- C4/Reserves.pm | 1 + C4/SIP/ILS/Transaction/FeePayment.pm | 16 ++++---- C4/SIP/SIPServer.pm | 4 ++ Koha/Account.pm | 23 ++++++++--- Koha/Account/Line.pm | 7 +++- Koha/Hold.pm | 9 ++-- Koha/Patron.pm | 7 ++-- Koha/REST/V1/Patrons/Account.pm | 1 + installer/data/mysql/atomicupdate/bug_22600.perl | 52 ++++++++++++++++++++++++ installer/data/mysql/kohastructure.sql | 1 + 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 +- 19 files changed, 133 insertions(+), 29 deletions(-) create mode 100644 installer/data/mysql/atomicupdate/bug_22600.perl diff --git a/C4/Accounts.pm b/C4/Accounts.pm index 39b2bda305..174c825f8f 100644 --- a/C4/Accounts.pm +++ b/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, diff --git a/C4/Circulation.pm b/C4/Circulation.pm index 4ac38fe3a0..cf4077db11 100644 --- a/C4/Circulation.pm +++ b/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."; } diff --git a/C4/Log.pm b/C4/Log.pm index 3a1e93e081..34e2b609c2 100644 --- a/C4/Log.pm +++ b/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 diff --git a/C4/Overdues.pm b/C4/Overdues.pm index ae6b8ce4d0..b44aa583b2 100644 --- a/C4/Overdues.pm +++ b/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, diff --git a/C4/Reserves.pm b/C4/Reserves.pm index 09d36288e3..bbe0309795 100644 --- a/C4/Reserves.pm +++ b/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', diff --git a/C4/SIP/ILS/Transaction/FeePayment.pm b/C4/SIP/ILS/Transaction/FeePayment.pm index 41ed5c7ccb..de0c22b412 100644 --- a/C4/SIP/ILS/Transaction/FeePayment.pm +++ b/C4/SIP/ILS/Transaction/FeePayment.pm @@ -65,10 +65,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 +81,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; diff --git a/C4/SIP/SIPServer.pm b/C4/SIP/SIPServer.pm index 5e1e3a6ee3..63880c9eb7 100755 --- a/C4/SIP/SIPServer.pm +++ b/C4/SIP/SIPServer.pm @@ -11,6 +11,7 @@ use IO::Socket::INET; use Socket qw(:DEFAULT :crlf); require UNIVERSAL::require; +use C4::Context; use C4::SIP::Sip::Constants qw(:all); use C4::SIP::Sip::Configuration; use C4::SIP::Sip::Checksum qw(checksum verify_cksum); @@ -27,6 +28,9 @@ use constant LOG_SIP => "local6"; # Local alias for the logging facility # A script with no MAIN namespace? # A module that takes command line args? +# Set interface to 'sip' +C4::Context->interface('sip'); + my %transports = ( RAW => \&raw_transport, telnet => \&telnet_transport, diff --git a/Koha/Account.pm b/Koha/Account.pm index 120ab60730..61fdef2fdd 100644 --- a/Koha/Account.pm +++ b/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, } @@ -381,7 +389,8 @@ sub add_credit { manager_id => $user_id, branchcode => $library_id, } - ) + ), + $interface ); } } @@ -400,6 +409,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, @@ -436,6 +446,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}; @@ -467,6 +478,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, @@ -496,7 +508,8 @@ sub add_debit { itemnumber => $item_id, manager_id => $user_id, } - ) + ), + $interface ); } } diff --git a/Koha/Account/Line.pm b/Koha/Account/Line.pm index ef9f4f9063..6443b4d346 100644 --- a/Koha/Account/Line.pm +++ b/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 ) : ()), } ); diff --git a/Koha/Hold.pm b/Koha/Hold.pm index 37c7fa1c26..bfd3434026 100644 --- a/Koha/Hold.pm +++ b/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 } ); } diff --git a/Koha/Patron.pm b/Koha/Patron.pm index cc1892b855..d4544443f0 100644 --- a/Koha/Patron.pm +++ b/Koha/Patron.pm @@ -849,10 +849,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' } ); } diff --git a/Koha/REST/V1/Patrons/Account.pm b/Koha/REST/V1/Patrons/Account.pm index b0d623b719..d35e896c93 100644 --- a/Koha/REST/V1/Patrons/Account.pm +++ b/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 } ); diff --git a/installer/data/mysql/atomicupdate/bug_22600.perl b/installer/data/mysql/atomicupdate/bug_22600.perl new file mode 100644 index 0000000000..d33e0a7451 --- /dev/null +++ b/installer/data/mysql/atomicupdate/bug_22600.perl @@ -0,0 +1,52 @@ +$DBversion = 'XXX'; # will be replaced by the RM +if ( CheckVersion($DBversion) ) { + + if ( !column_exists( 'accountlines', 'interface' ) ) { + $dbh->do( + qq{ + ALTER TABLE `accountlines` + ADD + `interface` varchar(16) + AFTER + `manager_id`; + } + ); + } + + $dbh->do(qq{ + UPDATE + `accountlines` + SET + interface = 'opac' + WHERE + borrowernumber = manager_id; + }); + + $dbh->do(qq{ + UPDATE + `accountlines` + SET + interface = 'cron' + WHERE + manager_id IS NULL + AND + branchcode IS NULL; + }); + + $dbh->do(qq{ + UPDATE + `accountlines` + SET + interface = 'intranet' + WHERE + interface IS NULL; + }); + + $dbh->do(qq{ + ALTER TABLE `accountlines` + MODIFY COLUMN `interface` varchar(16) NOT NULL; + }); + + SetVersion($DBversion); + print "Upgrade to $DBversion done (Bug 22600 - Add interface to accountlines)\n"; +} diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql index 510e39eeeb..b1fe42355f 100644 --- a/installer/data/mysql/kohastructure.sql +++ b/installer/data/mysql/kohastructure.sql @@ -2683,6 +2683,7 @@ CREATE TABLE `accountlines` ( `timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP, `note` MEDIUMTEXT NULL default NULL, `manager_id` int(11) NULL DEFAULT NULL, + `interface` VARCHAR(16) NOT NULL, `branchcode` VARCHAR( 10 ) NULL DEFAULT NULL, -- the branchcode of the library where a payment was made, a manual invoice created, etc. PRIMARY KEY (`accountlines_id`), KEY `acctsborridx` (`borrowernumber`), diff --git a/members/mancredit.pl b/members/mancredit.pl index 8b349bdfdf..c37e39e448 100755 --- a/members/mancredit.pl +++ b/members/mancredit.pl @@ -89,7 +89,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') ) { diff --git a/members/pay.pl b/members/pay.pl index b128053fa1..dd7a1efb5f 100755 --- a/members/pay.pl +++ b/members/pay.pl @@ -113,6 +113,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, } ); @@ -216,6 +217,7 @@ sub writeoff_all { lines => [ scalar Koha::Account::Lines->find($accountlines_id) ], type => 'writeoff', note => $payment_note, + interface => C4::Context->interface, library_id => $branch, } ); diff --git a/members/paycollect.pl b/members/paycollect.pl index 5bd9c0e599..cecf2e3fb2 100755 --- a/members/paycollect.pl +++ b/members/paycollect.pl @@ -125,6 +125,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, } ); @@ -157,6 +158,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, } ); @@ -168,6 +170,7 @@ if ( $total_paid and $total_paid ne '0.00' ) { amount => $total_paid, note => $note, payment_type => $payment_type, + interface => C4::Context->interface } ); } diff --git a/offline_circ/process_koc.pl b/offline_circ/process_koc.pl index 174f00db67..aacfeda81e 100755 --- a/offline_circ/process_koc.pl +++ b/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, { diff --git a/opac/opac-account-pay-paypal-return.pl b/opac/opac-account-pay-paypal-return.pl index 76f6d21810..07ed4bc5e7 100755 --- a/opac/opac-account-pay-paypal-return.pl +++ b/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 } ); } -- 2.11.0