Lines 45-56
sub can_be_discharged {
Link Here
|
45 |
} |
45 |
} |
46 |
} |
46 |
} |
47 |
|
47 |
|
|
|
48 |
sub is_discharged { |
49 |
my ($params) = @_; |
50 |
return unless $params->{borrowernumber}; |
51 |
my $borrowernumber = $params->{borrowernumber}; |
52 |
|
53 |
|
54 |
my $restricted = Koha::Borrower::Debarments::IsDebarred($borrowernumber); |
55 |
my $validated = get_validated({borrowernumber => $borrowernumber}); |
56 |
|
57 |
if ($restricted && $validated) { |
58 |
return 1; |
59 |
} else { |
60 |
return 0; |
61 |
} |
62 |
} |
63 |
|
48 |
sub request { |
64 |
sub request { |
49 |
my ($params) = @_; |
65 |
my ($params) = @_; |
50 |
my $borrowernumber = $params->{borrowernumber}; |
66 |
my $borrowernumber = $params->{borrowernumber}; |
51 |
return unless $borrowernumber; |
67 |
return unless $borrowernumber; |
52 |
return unless can_be_discharged({ borrowernumber => $borrowernumber }); |
68 |
return unless can_be_discharged({ borrowernumber => $borrowernumber }); |
53 |
return if count($params); |
|
|
54 |
|
69 |
|
55 |
return $rs->create({ |
70 |
return $rs->create({ |
56 |
borrower => $borrowernumber, |
71 |
borrower => $borrowernumber, |
Lines 76-82
sub discharge {
Link Here
|
76 |
}); |
91 |
}); |
77 |
|
92 |
|
78 |
# Generate the discharge |
93 |
# Generate the discharge |
79 |
my $discharge = $rs->search({ borrower => $borrowernumber }); |
94 |
my $discharge = $rs->search({ borrower => $borrowernumber }, { order_by => { -desc => 'needed' }, rows => 1 }); |
80 |
if( $discharge->count > 0 ) { |
95 |
if( $discharge->count > 0 ) { |
81 |
$discharge->update({ validated => dt_from_string }); |
96 |
$discharge->update({ validated => dt_from_string }); |
82 |
} |
97 |
} |
Lines 149-152
sub get_pendings {
Link Here
|
149 |
return \@rs; |
164 |
return \@rs; |
150 |
} |
165 |
} |
151 |
|
166 |
|
|
|
167 |
sub get_validated { |
168 |
my ($params) = @_; |
169 |
my $branchcode = $params->{branchcode}; |
170 |
my $borrowernumber = $params->{borrowernumber}; |
171 |
|
172 |
my $cond = { |
173 |
'me.validated' => { '!=', undef }, |
174 |
( defined $borrowernumber ? ( 'me.borrower' => $borrowernumber ) : () ), |
175 |
( defined $branchcode ? ( 'borrower.branchcode' => $branchcode ) : () ), |
176 |
}; |
177 |
|
178 |
my @rs = $rs->search( $cond, { join => 'borrower' } ); |
179 |
return \@rs; |
180 |
} |
181 |
|
182 |
|
152 |
1; |
183 |
1; |