View | Details | Raw Unified | Return to bug 5670
Collapse All | Expand All

(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/members/housebound.tt (+24 lines)
Lines 48-53 $(document).ready(function() { Link Here
48
          <h3>Housebound details for [% patron.title %] [% patron.firstname %] [% patron.surname %] ([% patron.cardnumber %])</h3>
48
          <h3>Housebound details for [% patron.title %] [% patron.firstname %] [% patron.surname %] ([% patron.cardnumber %])</h3>
49
          <div class="yui-u first">
49
          <div class="yui-u first">
50
50
51
            [% FOR m IN messages %]
52
                <div class="dialog [% m.type %]">
53
                    [% SWITCH m.code %]
54
                    [% CASE 'error_on_patron_load' %]
55
                        An error occurred whilst loading the patron details.
56
                    [% CASE 'error_on_profile_store' %]
57
                        An error occurred whilst updating this housebound profile.
58
                    [% CASE 'error_on_profile_create' %]
59
                        An error occurred whilst creating this housebound profile.
60
                    [% CASE 'error_on_visit_load' %]
61
                        An error occurred whilst loading the housebound visit.
62
                    [% CASE 'error_on_visit_delete' %]
63
                        An error occurred whilst deleting a housebound visit.
64
                    [% CASE 'error_on_visit_store' %]
65
                        An error occurred whilst updating a housebound visit.
66
                    [% CASE 'error_on_visit_create' %]
67
                        An error occurred whilst creating a new housebound visit.
68
                    [% CASE %]
69
                        [% m.code %]
70
                    [% END %]
71
                    Please try again later.
72
                </div>
73
            [% END %]
74
51
            <!-- Create or edit housebound_profile -->
75
            <!-- Create or edit housebound_profile -->
52
            [% IF ( method == 'update_or_create' ) %]
76
            [% IF ( method == 'update_or_create' ) %]
53
              <h4>Manage housebound profile</h4>
77
              <h4>Manage housebound profile</h4>
(-)a/members/housebound.pl (-20 / +45 lines)
Lines 47-63 my ( $template, $loggedinuser, $cookie ) = get_template_and_user( Link Here
47
    }
47
    }
48
);
48
);
49
49
50
my $patron = Koha::Patrons->new->find($input->param('borrowernumber'));
50
my @messages;                   # For error messages.
51
my $method = $input->param('method') // q{};
51
my $method = $input->param('method') // q{};
52
my $visit_id = $input->param('visit_id') // q{};
52
my $visit_id = $input->param('visit_id') // q{};
53
my $branch = Koha::Libraries->new->find($patron->branchcode);
54
my $category = Koha::Patron::Categories->new->find($patron->categorycode);
55
my $houseboundprofile = $patron->housebound_profile;
56
53
54
# Get patron
55
my $patron = eval {
56
    return Koha::Patrons->new->find($input->param('borrowernumber'));
57
};
58
push @messages, { type => 'error', code => 'error_on_patron_load' }
59
    if ( $@ or !$patron );
60
61
# Get supporting cast
62
my ( $branch, $category, $houseboundprofile, $visit );
63
if ( $patron ) {
64
    $branch = Koha::Libraries->new->find($patron->branchcode);
65
    $category = Koha::Patron::Categories->new->find($patron->categorycode);
66
    $houseboundprofile = $patron->housebound_profile;
67
}
68
if ( $visit_id ) {
69
    $visit = eval {
70
        return Koha::Patron::HouseboundVisits->find($visit_id);
71
    };
72
    push @messages, { type => 'error', code => 'error_on_visit_load' }
73
        if ( $@ or !$visit );
74
}
75
76
# Main processing
57
my ( $houseboundvisits, $deliverers, $choosers );
77
my ( $houseboundvisits, $deliverers, $choosers );
58
my ( $houseboundvisit, $deliverer, $chooser );
78
my ( $houseboundvisit, $deliverer, $chooser );
59
79
60
if ( $method eq 'updateconfirm' ) {
80
if ( $method eq 'updateconfirm' and $houseboundprofile ) {
61
    # We have received the input from the profile edit form.  We must save the
81
    # We have received the input from the profile edit form.  We must save the
62
    # changes, and return to simple display.
82
    # changes, and return to simple display.
63
    $houseboundprofile->set({
83
    $houseboundprofile->set({
Lines 69-76 if ( $method eq 'updateconfirm' ) { Link Here
69
        referral      => $input->param('referral')      // q{},
89
        referral      => $input->param('referral')      // q{},
70
        notes         => $input->param('notes')         // q{},
90
        notes         => $input->param('notes')         // q{},
71
    });
91
    });
72
    die("Unable to store edited profile")
92
    my $success = eval { return $houseboundprofile->store };
73
        unless ( $houseboundprofile->store );
93
    push @messages, { type => 'error', code => 'error_on_profile_store' }
94
        if ( $@ or !$success );
74
    $method = undef;
95
    $method = undef;
75
} elsif ( $method eq 'createconfirm' ) {
96
} elsif ( $method eq 'createconfirm' ) {
76
    # We have received the input necessary to create a new profile.  We must
97
    # We have received the input necessary to create a new profile.  We must
Lines 85-108 if ( $method eq 'updateconfirm' ) { Link Here
85
        referral       => $input->param('referral')      // q{},
106
        referral       => $input->param('referral')      // q{},
86
        notes          => $input->param('notes')         // q{},
107
        notes          => $input->param('notes')         // q{},
87
    });
108
    });
88
    die("Unable to store new profile")
109
    my $success = eval { return $houseboundprofile->store };
89
        unless ( $houseboundprofile->store );
110
    push @messages, { type => 'error', code => 'error_on_profile_create' }
111
        if ( $@ or !$success );
90
    $method = undef;
112
    $method = undef;
91
} elsif ( $method eq 'visit_update_or_create' ) {
113
} elsif ( $method eq 'visit_update_or_create' ) {
92
    # We want to edit, edit a visit, so we must pass its details.
114
    # We want to edit, edit a visit, so we must pass its details.
93
    $deliverers = Koha::Patrons->new->housebound_deliverers;
115
    $deliverers = Koha::Patrons->new->housebound_deliverers;
94
    $choosers = Koha::Patrons->new->housebound_choosers;
116
    $choosers = Koha::Patrons->new->housebound_choosers;
95
    $houseboundvisit = Koha::Patron::HouseboundVisits->find($visit_id)
117
    $houseboundvisit = $visit;
96
        if ( $visit_id );
118
} elsif ( $method eq 'visit_delete' and $visit ) {
97
} elsif ( $method eq 'visit_delete' ) {
98
    # We want ot delete a specific visit.
119
    # We want ot delete a specific visit.
99
    my $visit = Koha::Patron::HouseboundVisits->find($visit_id);
120
    my $success = eval { return $visit->delete };
100
    die("Unable to delete visit") unless ( $visit->delete );
121
    push @messages, { type => 'error', code => 'error_on_visit_delete' }
122
        if ( $@ or !$success );
101
    $method = undef;
123
    $method = undef;
102
} elsif ( $method eq 'editvisitconfirm' ) {
124
} elsif ( $method eq 'editvisitconfirm' and $visit ) {
103
    # We have received input for editing a visit.  We must store and return to
125
    # We have received input for editing a visit.  We must store and return to
104
    # simple display.
126
    # simple display.
105
    my $visit = Koha::Patron::HouseboundVisits->find($visit_id);
106
    $visit->set({
127
    $visit->set({
107
        borrowernumber      => $input->param('borrowernumber') // q{},
128
        borrowernumber      => $input->param('borrowernumber') // q{},
108
        appointment_date    => $input->param('date')           // q{},
129
        appointment_date    => $input->param('date')           // q{},
Lines 110-118 if ( $method eq 'updateconfirm' ) { Link Here
110
        chooser_brwnumber   => $input->param('chooser')        // q{},
131
        chooser_brwnumber   => $input->param('chooser')        // q{},
111
        deliverer_brwnumber => $input->param('deliverer')      // q{},
132
        deliverer_brwnumber => $input->param('deliverer')      // q{},
112
    });
133
    });
113
    die("Unable to store edited visit") unless ( $visit->store );
134
    my $success = eval { return $visit->store };
135
    push @messages, { type => 'error', code => 'error_on_visit_store' }
136
        if ( $@ or !$success );
114
    $method = undef;
137
    $method = undef;
115
} elsif ( $method eq 'addvisitconfirm' ) {
138
} elsif ( $method eq 'addvisitconfirm' and !$visit ) {
116
    # We have received input for creating a visit.  We must store and return
139
    # We have received input for creating a visit.  We must store and return
117
    # to simple display.
140
    # to simple display.
118
    my $visit = Koha::Patron::HouseboundVisit->new({
141
    my $visit = Koha::Patron::HouseboundVisit->new({
Lines 122-128 if ( $method eq 'updateconfirm' ) { Link Here
122
        chooser_brwnumber   => $input->param('chooser')        // q{},
145
        chooser_brwnumber   => $input->param('chooser')        // q{},
123
        deliverer_brwnumber => $input->param('deliverer')      // q{},
146
        deliverer_brwnumber => $input->param('deliverer')      // q{},
124
    });
147
    });
125
    die("Unable to store new visit") unless ( $visit->store );
148
    my $success = eval { return $visit->store };
149
    push @messages, { type => 'error', code => 'error_on_visit_create' }
150
        if ( $@ or !$success );
126
    $method = undef;
151
    $method = undef;
127
}
152
}
128
153
Lines 135-140 $template->param( Link Here
135
    visit              => $houseboundvisit,
160
    visit              => $houseboundvisit,
136
    branch             => $branch,
161
    branch             => $branch,
137
    category           => $category,
162
    category           => $category,
163
    messages           => \@messages,
138
    method             => $method,
164
    method             => $method,
139
    choosers           => $choosers,
165
    choosers           => $choosers,
140
    deliverers         => $deliverers,
166
    deliverers         => $deliverers,
141
- 

Return to bug 5670