From 8ef116a9221ff1365fab54e1eeeef8f31dd25f79 Mon Sep 17 00:00:00 2001 From: Alex Sassmannshausen Date: Wed, 12 Oct 2016 17:26:02 +0200 Subject: [PATCH] Bug 5670: [QA Followup] HouseboundRole CRUD from UI. * koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt: Add HouseboundRole form. * members/memberentry.pl: Handle HouseboundRole CRUD. Signed-off-by: Claire Gravely Signed-off-by: Kyle M Hall --- .../prog/en/modules/members/memberentrygen.tt | 49 +++++++++++++++ members/memberentry.pl | 60 +++++++++++++++++-- 2 files changed, 104 insertions(+), 5 deletions(-) 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 c5a3696448..8d7e2c76aa 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt @@ -917,6 +917,55 @@ $(document).ready(function() { [% END # hide fieldset %][% END %] + [% IF ( HouseboundModule ) %] +
+ Housebound roles +
    +
  1. + + [% IF ( housebound_role.housebound_chooser == 1 ) %] + + + + + [% ELSE %] + + + + + [% END %] +
  2. +
  3. + + [% IF ( housebound_role.housebound_deliverer == 1 ) %] + + + + + [% ELSE %] + + + + + [% END %] +
  4. +
+
+ [% END # hide fieldset %] [% UNLESS ( opadd || opduplicate ) %]
diff --git a/members/memberentry.pl b/members/memberentry.pl index 36c8a9442f..f1fd8e3ebf 100755 --- a/members/memberentry.pl +++ b/members/memberentry.pl @@ -44,6 +44,8 @@ use Koha::Cities; use Koha::DateUtils; use Koha::Libraries; use Koha::Patron::Categories; +use Koha::Patron::HouseboundRole; +use Koha::Patron::HouseboundRoles; use Koha::Token; use Email::Valid; use Module::Load; @@ -436,11 +438,53 @@ if ((!$nok) and $nodouble and ($op eq 'insert' or $op eq 'save')){ if ( exists $data{'borrowernumber'} && C4::Context->preference('NorwegianPatronDBEnable') && C4::Context->preference('NorwegianPatronDBEnable') == 1 ) { NLSync({ 'borrowernumber' => $borrowernumber }); } - } elsif ($op eq 'save'){ - if ($NoUpdateLogin) { - delete $newdata{'password'}; - delete $newdata{'userid'}; - } + + # Create HouseboundRole if necessary. + # Borrower did not exist, so HouseboundRole *cannot* yet exist. + my ( $hsbnd_chooser, $hsbnd_deliverer ) = ( 0, 0 ); + $hsbnd_chooser = 1 if $input->param('housebound_chooser'); + $hsbnd_deliverer = 1 if $input->param('housebound_deliverer'); + # Only create a HouseboundRole if patron has a role. + if ( $hsbnd_chooser || $hsbnd_deliverer ) { + Koha::Patron::HouseboundRole->new({ + borrowernumber_id => $borrowernumber, + housebound_chooser => $hsbnd_chooser, + housebound_deliverer => $hsbnd_deliverer, + })->store; + } + + } elsif ($op eq 'save') { + + # Update or create our HouseboundRole if necessary. + my $housebound_role = Koha::Patron::HouseboundRoles->find($borrowernumber); + my ( $hsbnd_chooser, $hsbnd_deliverer ) = ( 0, 0 ); + $hsbnd_chooser = 1 if $input->param('housebound_chooser'); + $hsbnd_deliverer = 1 if $input->param('housebound_deliverer'); + if ( $housebound_role ) { + if ( $hsbnd_chooser || $hsbnd_deliverer ) { + # Update our HouseboundRole. + $housebound_role + ->housebound_chooser($hsbnd_chooser) + ->housebound_deliverer($hsbnd_deliverer) + ->store; + } else { + $housebound_role->delete; # No longer needed. + } + } else { + # Only create a HouseboundRole if patron has a role. + if ( $hsbnd_chooser || $hsbnd_deliverer ) { + $housebound_role = Koha::Patron::HouseboundRole->new({ + borrowernumber_id => $borrowernumber, + housebound_chooser => $hsbnd_chooser, + housebound_deliverer => $hsbnd_deliverer, + })->store; + } + } + + if ($NoUpdateLogin) { + delete $newdata{'password'}; + delete $newdata{'userid'}; + } &ModMember(%newdata) unless scalar(keys %newdata) <= 1; # bug 4508 - avoid crash if we're not # updating any columns in the borrowers table, # which can happen if we're only editing the @@ -704,6 +748,12 @@ $template->param( ), ); +# HouseboundModule data +$template->param( + HouseboundModule => C4::Context->preference("HouseboundModule"), + housebound_role => Koha::Patron::HouseboundRoles->find($borrowernumber), +); + if(defined($data{'flags'})){ $template->param(flags=>$data{'flags'}); } -- 2.39.5