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

(-)a/Koha/Borrower/Discharge.pm (-2 / +33 lines)
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;
(-)a/installer/data/mysql/atomicupdate/bug_14368_Add_discharges_history.sql (+1 lines)
Line 0 Link Here
1
ALTER TABLE discharges ADD COLUMN discharge_id int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY FIRST;
(-)a/installer/data/mysql/kohastructure.sql (+2 lines)
Lines 3529-3537 CREATE TABLE items_search_fields ( Link Here
3529
3529
3530
DROP TABLE IF EXISTS discharges;
3530
DROP TABLE IF EXISTS discharges;
3531
CREATE TABLE discharges (
3531
CREATE TABLE discharges (
3532
  discharge_id int(11) NOT NULL AUTO_INCREMENT,
3532
  borrower int(11) DEFAULT NULL,
3533
  borrower int(11) DEFAULT NULL,
3533
  needed timestamp NULL DEFAULT NULL,
3534
  needed timestamp NULL DEFAULT NULL,
3534
  validated timestamp NULL DEFAULT NULL,
3535
  validated timestamp NULL DEFAULT NULL,
3536
  PRIMARY KEY (discharge_id),
3535
  KEY borrower_discharges_ibfk1 (borrower),
3537
  KEY borrower_discharges_ibfk1 (borrower),
3536
  CONSTRAINT borrower_discharges_ibfk1 FOREIGN KEY (borrower) REFERENCES borrowers (borrowernumber) ON DELETE CASCADE ON UPDATE CASCADE
3538
  CONSTRAINT borrower_discharges_ibfk1 FOREIGN KEY (borrower) REFERENCES borrowers (borrowernumber) ON DELETE CASCADE ON UPDATE CASCADE
3537
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
3539
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/members/discharge.tt (+22 lines)
Lines 1-3 Link Here
1
[% USE KohaDates %]
1
[% INCLUDE 'doc-head-open.inc' %]
2
[% INCLUDE 'doc-head-open.inc' %]
2
<title>Koha &rsaquo; Patrons &rsaquo; [% IF (unknowuser) %]Patron does not exist[% ELSE %]Discharge for [% firstname %] [% surname %] ([% cardnumber %])[% END %]</title>
3
<title>Koha &rsaquo; Patrons &rsaquo; [% IF (unknowuser) %]Patron does not exist[% ELSE %]Discharge for [% firstname %] [% surname %] ([% cardnumber %])[% END %]</title>
3
[% INCLUDE 'doc-head-close.inc' %]
4
[% INCLUDE 'doc-head-close.inc' %]
Lines 37-42 Link Here
37
        <input type="hidden" value="[% borrowernumber %]" name="borrowernumber" />
38
        <input type="hidden" value="[% borrowernumber %]" name="borrowernumber" />
38
    </form>
39
    </form>
39
[% END %]
40
[% END %]
41
42
[% IF validated_discharges %]
43
    <h2>Already validated discharges</h2>
44
    <table>
45
        <thead>
46
            <tr>
47
                <th>Requested</th>
48
                <th>Validated</th>
49
            </tr>
50
        </thead>
51
        <tbody>
52
            [% FOR d IN validated_discharges %]
53
                <tr>
54
                    <td>[% d.needed | $KohaDates with_hours = 1 %]</td>
55
                    <td>[% d.validated | $KohaDates with_hours = 1 %]</td>
56
                </tr>
57
            [% END %]
58
        </tbody>
59
    </table>
60
[% END %]
61
40
</div>
62
</div>
41
63
42
64
(-)a/members/discharge.pl (+6 lines)
Lines 98-103 if ( $input->param('borrowernumber') ) { Link Here
98
        }
98
        }
99
    }
99
    }
100
100
101
    # Already generated discharges
102
    my $validated_discharges = Koha::Borrower::Discharge::get_validated({
103
        branchcode => $data->{'branchcode'},
104
    });
105
101
    $template->param(
106
    $template->param(
102
        borrowernumber    => $borrowernumber,
107
        borrowernumber    => $borrowernumber,
103
        biblionumber      => $data->{'biblionumber'},
108
        biblionumber      => $data->{'biblionumber'},
Lines 120-125 if ( $input->param('borrowernumber') ) { Link Here
120
        branchcode        => $data->{'branchcode'},
125
        branchcode        => $data->{'branchcode'},
121
        has_reserves      => $has_reserves,
126
        has_reserves      => $has_reserves,
122
        can_be_discharged => $can_be_discharged,
127
        can_be_discharged => $can_be_discharged,
128
        validated_discharges => $validated_discharges,
123
    );
129
    );
124
}
130
}
125
131
(-)a/opac/opac-discharge.pl (-1 / +1 lines)
Lines 92-98 else { Link Here
92
        validated      => 1,
92
        validated      => 1,
93
    });
93
    });
94
    $template->param(
94
    $template->param(
95
        available => $available,
95
        available => $available && Koha::Borrower::Discharge::is_discharged({borrowernumber => $loggedinuser}),
96
        pending   => $pending,
96
        pending   => $pending,
97
    );
97
    );
98
}
98
}
(-)a/t/db_dependent/Borrower_Discharge.t (-1 / +7 lines)
Lines 49-54 is( Koha::Borrower::Discharge::can_be_discharged({ borrowernumber => $borrowernu Link Here
49
49
50
is(Koha::Borrower::Discharge::generate_as_pdf,undef,"Confirm failure when lacking borrower number");
50
is(Koha::Borrower::Discharge::generate_as_pdf,undef,"Confirm failure when lacking borrower number");
51
51
52
# Verify that the user is not discharged anymore if the restriction has been lifted
53
Koha::Borrower::Discharge::discharge({ borrowernumber => $borrowernumber });
54
is( Koha::Borrower::Discharge::is_discharged({ borrowernumber => $borrowernumber }), 1, 'The patron has been discharged' );
55
is(Koha::Borrower::Debarments::IsDebarred($borrowernumber), '9999-12-31', 'The patron has been debarred after discharge');
56
Koha::Borrower::Debarments::DelDebarment($borrowernumber);
57
is( Koha::Borrower::Discharge::is_discharged({ borrowernumber => $borrowernumber }), 1, 'The patron is not discharged after the restriction has been lifted' );
58
52
# Check if PDF::FromHTML is installed.
59
# Check if PDF::FromHTML is installed.
53
my $check = eval { require PDF::FromHTML; };
60
my $check = eval { require PDF::FromHTML; };
54
61
55
- 

Return to bug 14368