@@ -, +, @@ https://github.com/bywatersolutions/koha-plugin-barcode-transformer/releases/download/v1.0.1/koha-plugin-barcode-transformer-v1.0.1.kpz cardnumber, type in some cardnumbers but prefix them with A and postfix them with A or B, e.g. A12345A, A12345B --- C4/SIP/Sip/MsgType.pm | 16 ++++++++++++++++ Koha/Patron.pm | 8 +++++++- circ/circulation.pl | 4 +++- members/memberentry.pl | 4 ++++ opac/sco/sco-main.pl | 1 + 5 files changed, 31 insertions(+), 2 deletions(-) --- a/C4/SIP/Sip/MsgType.pm +++ a/C4/SIP/Sip/MsgType.pm @@ -19,6 +19,7 @@ use CGI qw ( -utf8 ); use C4::Auth qw(&check_api_auth); use Koha::Patron::Attributes; +use Koha::Plugins; use Koha::Items; use UNIVERSAL::can; @@ -519,6 +520,7 @@ sub handle_checkout { $fields = $self->{fields}; $patron_id = $fields->{ (FID_PATRON_ID) }; + ($patron_id) = Koha::Plugins->call('patron_barcode_transform', $patron_id ) || $patron_id; $item_id = $fields->{ (FID_ITEM_ID) }; my $fee_ack = $fields->{ (FID_FEE_ACK) }; @@ -740,6 +742,8 @@ sub handle_block_patron { $patron_id = $fields->{ (FID_PATRON_ID) }; $terminal_pwd = $fields->{ (FID_TERMINAL_PWD) }; + ($patron_id) = Koha::Plugins->call('patron_barcode_transform', $patron_id ) || $patron_id; + # Terminal passwords are different from account login # passwords, but I have no idea what to do with them. So, # I'll just ignore them for now. @@ -964,6 +968,8 @@ sub handle_patron_info { $start = $fields->{ (FID_START_ITEM) }; $end = $fields->{ (FID_END_ITEM) }; + ($patron_id) = Koha::Plugins->call('patron_barcode_transform', $patron_id ) || $patron_id; + $patron = $ils->find_patron($patron_id); $resp = (PATRON_INFO_RESP); @@ -1121,6 +1127,8 @@ sub handle_fee_paid { $fee_id = $fields->{ (FID_FEE_ID) }; $trans_id = $fields->{ (FID_TRANSACTION_ID) }; + ($patron_id) = Koha::Plugins->call('patron_barcode_transform', $patron_id ) || $patron_id; + $ils->check_inst_id( $inst_id, "handle_fee_paid" ); my $pay_result = $ils->pay_fee( $patron_id, $patron_pwd, $fee_amt, $fee_type, $pay_type, $fee_id, $trans_id, $currency, $is_writeoff, $disallow_overpayment, $register_id ); @@ -1317,6 +1325,8 @@ sub handle_patron_enable { $patron_id = $fields->{ (FID_PATRON_ID) }; $patron_pwd = $fields->{ (FID_PATRON_PWD) }; + ($patron_id) = Koha::Plugins->call('patron_barcode_transform', $patron_id ) || $patron_id; + siplog( "LOG_DEBUG", "handle_patron_enable: patron_id: '%s', patron_pwd: '%s'", $patron_id, $patron_pwd ); $patron = $ils->find_patron($patron_id); @@ -1380,6 +1390,8 @@ sub handle_hold { $title_id = $fields->{ (FID_TITLE_ID) } || ''; $fee_ack = $fields->{ (FID_FEE_ACK) } || 'N'; + ($patron_id) = Koha::Plugins->call('patron_barcode_transform', $patron_id ) || $patron_id; + if ( $hold_mode eq '+' ) { $status = $ils->add_hold( $patron_id, $patron_pwd, $item_id, $title_id, $expiry_date, $pickup_locn, $hold_type, $fee_ack ); } elsif ( $hold_mode eq '-' ) { @@ -1445,6 +1457,8 @@ sub handle_renew { $item_props = $fields->{ (FID_ITEM_PROPS) }; $fee_ack = $fields->{ (FID_FEE_ACK) }; + ($patron_id) = Koha::Plugins->call('patron_barcode_transform', $patron_id ) || $patron_id; + $status = $ils->renew( $patron_id, $patron_pwd, $item_id, $title_id, $no_block, $nb_due_date, $third_party, $item_props, $fee_ack ); $patron = $status->patron; @@ -1526,6 +1540,8 @@ sub handle_renew_all { $terminal_pwd = $fields->{ (FID_TERMINAL_PWD) }; $fee_ack = $fields->{ (FID_FEE_ACK) }; + ($patron_id) = Koha::Plugins->call('patron_barcode_transform', $patron_id ) || $patron_id; + $status = $ils->renew_all( $patron_id, $patron_pwd, $fee_ack ); $resp .= $status->ok ? '1' : '0'; --- a/Koha/Patron.pm +++ a/Koha/Patron.pm @@ -111,7 +111,10 @@ Autogenerate next cardnumber from highest value found in database sub fixup_cardnumber { my ( $self ) = @_; - my $max = Koha::Patrons->search({ + + my ( $max ) = Koha::Plugins->call( 'barcode_generate', 'patron', $self ); + + $max ||= Koha::Patrons->search({ cardnumber => {-regexp => '^-?[0-9]+$'} }, { select => \'CAST(cardnumber AS SIGNED)', @@ -198,6 +201,9 @@ sub store { $self->trim_whitespaces; + my ( $new_cardnumber ) = Koha::Plugins->call( 'patron_barcode_transform', $self->cardnumber ) || $self->cardnumber; + $self->cardnumber( $new_cardnumber ); + # Set surname to uppercase if uppercasesurname is true $self->surname( uc($self->surname) ) if C4::Context->preference("uppercasesurnames"); --- a/circ/circulation.pl +++ a/circ/circulation.pl @@ -81,7 +81,8 @@ my $autoswitched; my $borrowernumber = $query->param('borrowernumber'); if (C4::Context->preference("AutoSwitchPatron") && $barcode) { - if (Koha::Patrons->search( { cardnumber => $barcode} )->count() > 0) { + my ( $new_barcode ) = Koha::Plugins->call( 'patron_barcode_transform', $findborrower ) || $findborrower; + if (Koha::Patrons->search( { cardnumber => $new_barcode} )->count() > 0) { $findborrower = $barcode; undef $barcode; undef $borrowernumber; @@ -226,6 +227,7 @@ if ( @$barcodes == 0 && $charges eq 'yes' ) { # my $message; if ($findborrower) { + ( $findborrower ) = Koha::Plugins->call( 'patron_barcode_transform', $findborrower ) || $findborrower; my $patron = Koha::Patrons->find( { cardnumber => $findborrower } ); if ( $patron ) { $borrowernumber = $patron->borrowernumber; --- a/members/memberentry.pl +++ a/members/memberentry.pl @@ -45,6 +45,7 @@ use Koha::Patron::Attribute::Types; use Koha::Patron::Categories; use Koha::Patron::HouseboundRole; use Koha::Patron::HouseboundRoles; +use Koha::Plugins; use Koha::Token; use Email::Valid; use Koha::SMS::Providers; @@ -333,6 +334,9 @@ if ($op eq 'save' || $op eq 'insert'){ # If the cardnumber is blank, treat it as null. $newdata{'cardnumber'} = undef if $newdata{'cardnumber'} =~ /^\s*$/; + my ( $new_barcode ) = Koha::Plugins->call( 'patron_barcode_transform', $newdata{'cardnumber'} ) || $newdata{'cardnumber'}; + $newdata{'cardnumber'} = $new_barcode; + if (my $error_code = checkcardnumber($newdata{cardnumber},$newdata{borrowernumber})){ push @errors, $error_code == 1 ? 'ERROR_cardnumber_already_exists' --- a/opac/sco/sco-main.pl +++ a/opac/sco/sco-main.pl @@ -124,6 +124,7 @@ if (C4::Context->preference('SelfCheckoutByLogin') && !$patronid) { my ( $borrower, $patron ); if ( $patronid ) { + ( $patronid ) = Koha::Plugins->call( 'patron_barcode_transform', $patronid ) || $patronid; $patron = Koha::Patrons->find( { cardnumber => $patronid } ); $borrower = $patron->unblessed if $patron; } --