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

(-)a/Koha/Patron/Discharge.pm (-23 / +53 lines)
Lines 95-104 sub is_discharged { Link Here
95
    return unless $params->{borrowernumber};
95
    return unless $params->{borrowernumber};
96
    my $borrowernumber = $params->{borrowernumber};
96
    my $borrowernumber = $params->{borrowernumber};
97
97
98
    my $restricted = Koha::Patrons->find( $borrowernumber )->is_debarred;
98
    my $restricted = Koha::Patrons->find($borrowernumber)->is_debarred;
99
    my @validated = get_validated({borrowernumber => $borrowernumber});
99
    my @validated  = get_validated( { borrowernumber => $borrowernumber } );
100
100
101
    if ($restricted && @validated) {
101
    if ( $restricted && @validated ) {
102
        return 1;
102
        return 1;
103
    } else {
103
    } else {
104
        return 0;
104
        return 0;
Lines 113-130 Place a discharge request on a given borrower after checking the borrower has th Link Here
113
113
114
=cut
114
=cut
115
115
116
sub is_discharged {
117
    my ($params) = @_;
118
    my $discharge = Koha::Database->new->schema->resultset('Discharge')->search(
119
        {
120
            borrower  => $params->{borrowernumber},
121
            validated => { "not" => undef },
122
            cancelled => undef,
123
        }
124
    );
125
    return $discharge->count > 0;
126
}
127
128
sub request {
116
sub request {
129
    my ($params) = @_;
117
    my ($params) = @_;
130
    my $borrowernumber = $params->{borrowernumber};
118
    my $borrowernumber = $params->{borrowernumber};
Lines 141-172 sub request { Link Here
141
    );
129
    );
142
}
130
}
143
131
144
=head3 discharge
132
=head3 is_cancelled
145
133
146
    my $request = Koha::Patron:Discharge->discharge({borrowernumber => $borrowernumber});
134
    my $is_cancelled = Koha::Patron:Discharge->is_cancelled({discharge_id => $discharge_id});
147
135
148
Place a discharge request on a given borrower, if a discharge was requested, update the status to discharged and place a suspension on the user.
136
Returns true if there is a discharge that has been cancelled and has the given discharge_id, false else.
149
137
150
=cut
138
=cut
151
139
152
sub is_cancelled {
140
sub is_cancelled {
153
    my ($params) = @_;
141
    my ($params) = @_;
142
    unless ( $params->{discharge_id} ) {
143
        Koha::Exceptions::BadParameter->throw("is_cancelled must be called with a discharge_id");
144
    }
154
    my $discharge = Koha::Database->new->schema->resultset('Discharge')->search(
145
    my $discharge = Koha::Database->new->schema->resultset('Discharge')->search(
155
        {
146
        {
156
            discharge_id => $params->{discharge_id},
147
            discharge_id => $params->{discharge_id},
157
            cancelled    => { "not" => undef },
158
        }
148
        }
159
    );
149
    );
160
    return $discharge->count > 0;
150
    if ( $discharge->count == 0 ) {
151
        Koha::Exceptions::BadParameter->throw("is_cancelled must be called with a valid discharge_id");
152
    }
153
    return defined $discharge->single->cancelled;
161
}
154
}
162
155
156
=head3 cancel
157
158
    Koha::Patron:Discharge->cancel(
159
        discharge_id          => $discharge_id,
160
        cancellation_reason   => $cancellation_reason,
161
        borrowernumber        => $borrowernumber,
162
    });
163
164
Cancel the discharge given as argument through discharge_id. This will remove suspension associated with the borrowernumber, and update cancellation date and reason.
165
166
=cut
167
163
sub cancel {
168
sub cancel {
164
    my ($params) = @_;
169
    my ($params) = @_;
165
    my $discharge = Koha::Database->new->schema->resultset('Discharge')->search(
170
    my $discharge = Koha::Database->new->schema->resultset('Discharge')->find(
166
        {
171
        {
167
            discharge_id => $params->{discharge_id},
172
            discharge_id => $params->{discharge_id},
168
        }
173
        }
169
    );
174
    );
175
    my $patron = Koha::Patrons->find( { borrowernumber => $params->{borrowernumber} } );
176
    unless ( $patron || $discharge ) {
177
        Koha::Exceptions::BadParameter->throw("cancel() must be called either with a borrowernumber or a discharge id");
178
    }
179
    if ( $patron && $discharge && ( $discharge->borrower->borrowernumber != $patron->borrowernumber ) ) {
180
        Koha::Exceptions::BadParameter->throw(
181
            "If passing patron and discharge, the patron and the discharge must correspond");
182
    }
183
    if ($discharge) {
184
        $patron = Koha::Patrons->find( { borrowernumber => $discharge->borrower->borrowernumber } );
185
    } else {
186
        $discharge = Koha::Database->new->schema->resultset('Discharge')->search(
187
            {
188
                borrower  => $patron->borrowernumber,
189
                validated => { -not => undef }
190
            }
191
        )->single;
192
    }
170
    $discharge->update(
193
    $discharge->update(
171
        {
194
        {
172
            cancelled           => dt_from_string,
195
            cancelled           => dt_from_string,
Lines 175-186 sub cancel { Link Here
175
    );
198
    );
176
    Koha::Patron::Debarments::DelUniqueDebarment(
199
    Koha::Patron::Debarments::DelUniqueDebarment(
177
        {
200
        {
178
            borrowernumber => $params->{borrowernumber},
201
            borrowernumber => $patron->borrowernumber,
179
            type           => "DISCHARGE",
202
            type           => "DISCHARGE",
180
        }
203
        }
181
    );
204
    );
182
}
205
}
183
206
207
=head3 discharge
208
209
    my $request = Koha::Patron:Discharge->discharge({borrowernumber => $borrowernumber});
210
211
Place a discharge request on a given borrower, if a discharge was requested, update the status to discharged and place a suspension on the user.
212
213
=cut
214
184
sub discharge {
215
sub discharge {
185
    my ($params) = @_;
216
    my ($params) = @_;
186
    my $borrowernumber = $params->{borrowernumber};
217
    my $borrowernumber = $params->{borrowernumber};
187
- 

Return to bug 37344