From 141d29358f15eed2659de041ee5c4295c24e0fb5 Mon Sep 17 00:00:00 2001 From: "Meenakshi.R" Date: Wed, 6 Jun 2012 16:46:15 +0530 Subject: [PATCH] Bug 6782 - Move auto member cardnumber generation to occur when record is "Saved" (avoid collisions). MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Currently the card number is generated when the user enters the patron creation form. This creates a problem of concurrency - when two or more simulataneous users are registering members, the error "card no. in use" can occur. This change moves the card number generation to occur after the "Save" button is pressed. Changes: -C4/Members.pm: Added code to fixup_cardnumber,If the cardnumber is blank and "autoMemberNum" ON. -koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt: Added code to display "leave blank for auto calc during registration" in cardnumber label in patron registration form only if "autoMemberNum" ON. -members/memberentry.pl: Added code to get weather or not "autoMemberNum" is on or off and removed fixup_cardnumber generation. Test cases: -If "autoMemberNum" ON: ->In blank case, must generate auto card number in simulataneous users. ->If user entered, check for unique card number. -If "autoMemberNum" OFF: Must work normal. Followed test plan, works as expected. Note: Syspref PorrowerMandatoryField must not include cardnumber, otherwise you can not save. Maybe that should be mentioned in the comment for syspref autoMemberNum. Signed-off-by: Marc Véron Signed-off-by: Kyle M Hall Signed-off-by: Kyle M Hall --- C4/Members.pm | 6 ++++++ .../prog/en/modules/members/memberentrygen.tt | 16 ++++++++++------ members/memberentry.pl | 7 ++++++- 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/C4/Members.pm b/C4/Members.pm index dfe4cbd753..4195abe7bd 100644 --- a/C4/Members.pm +++ b/C4/Members.pm @@ -497,6 +497,12 @@ sub AddMember { $data{'dateenrolled'} = output_pref( { dt => dt_from_string, dateonly => 1, dateformat => 'iso' } ); } + if ( C4::Context->preference("autoMemberNum") ) { + if ( not exists $data{cardnumber} or not defined $data{cardnumber} or $data{cardnumber} eq '' ) { + $data{cardnumber} = fixup_cardnumber( $data{cardnumber}, C4::Context->userenv->{'branch'}, $data{categorycode} ); + } + } + my $patron_category = $schema->resultset('Category')->find( $data{'categorycode'} ); $data{'privacy'} = $patron_category->default_privacy() eq 'default' ? 1 diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt index a66826da92..54fd902c78 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt @@ -600,27 +600,31 @@ $(document).ready(function() { Library management
    [% UNLESS nocardnumber %]
  1. - [% IF ( mandatorycardnumber ) %] + [% IF mandatorycardnumber and not Koha.Preference('autoMemberNum') %] + [% ELSE %] + Card number: + [% END %] [% IF minlength_cardnumber == maxlength_cardnumber %] - [% IF ( mandatorycardnumber ) %]Required[% END %] + [% IF mandatorycardnumber and not Koha.Preference('autoMemberNum') %]Required[% END %]
    Card number must be exactly [% minlength_cardnumber %] characters.
    [% ELSIF minlength_cardnumber && maxlength_cardnumber %] - [% IF ( mandatorycardnumber ) %]Required[% END %] + [% IF mandatorycardnumber and not Koha.Preference('autoMemberNum') %]Required[% END %]
    Card number must be between [% minlength_cardnumber %] and [% maxlength_cardnumber %] characters.
    [% ELSIF maxlength_cardnumber %] - [% IF ( mandatorycardnumber ) %]Required[% END %] + [% IF mandatorycardnumber and not Koha.Preference('autoMemberNum') %]Required[% END %]
    Card number can be up to [% maxlength_cardnumber %] characters.
    [% ELSE %] - [% IF ( mandatorycardnumber ) %]Required[% END %] + [% IF mandatorycardnumber and not Koha.Preference('autoMemberNum') %]Required[% END %]
    There is no minimum or maximum character length.
    [% END %]
  2. diff --git a/members/memberentry.pl b/members/memberentry.pl index 2fcaa723ff..9213d59c64 100755 --- a/members/memberentry.pl +++ b/members/memberentry.pl @@ -561,7 +561,12 @@ if ( $op eq "duplicate" ) { $data{'cardnumber'} = ""; } -$data{'cardnumber'}=fixup_cardnumber($data{'cardnumber'}) if ( ( $op eq 'add' ) or ( $op eq 'duplicate' ) ); +if (C4::Context->preference("autoMemberNum")) { + $template->param( autoMemberNum => 1); +} else { + $template->param( autoMemberNum => 0); +} + if(!defined($data{'sex'})){ $template->param( none => 1); } elsif($data{'sex'} eq 'F'){ -- 2.39.5