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 3526-3534 CREATE TABLE items_search_fields ( Link Here
3526
3526
3527
DROP TABLE IF EXISTS discharges;
3527
DROP TABLE IF EXISTS discharges;
3528
CREATE TABLE discharges (
3528
CREATE TABLE discharges (
3529
  discharge_id int(11) NOT NULL AUTO_INCREMENT,
3529
  borrower int(11) DEFAULT NULL,
3530
  borrower int(11) DEFAULT NULL,
3530
  needed timestamp NULL DEFAULT NULL,
3531
  needed timestamp NULL DEFAULT NULL,
3531
  validated timestamp NULL DEFAULT NULL,
3532
  validated timestamp NULL DEFAULT NULL,
3533
  PRIMARY KEY (discharge_id),
3532
  KEY borrower_discharges_ibfk1 (borrower),
3534
  KEY borrower_discharges_ibfk1 (borrower),
3533
  CONSTRAINT borrower_discharges_ibfk1 FOREIGN KEY (borrower) REFERENCES borrowers (borrowernumber) ON DELETE CASCADE ON UPDATE CASCADE
3535
  CONSTRAINT borrower_discharges_ibfk1 FOREIGN KEY (borrower) REFERENCES borrowers (borrowernumber) ON DELETE CASCADE ON UPDATE CASCADE
3534
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
3536
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/members/discharge.tt (+21 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
    [% IF validated_discharges %]
42
    <h2>Already validated discharges</h2>
43
        <table>
44
            <thead>
45
                <tr>
46
                    <th>Requested</th>
47
                    <th>Validated</th>
48
                </tr>
49
            </thead>
50
            <tbody>
51
                [% FOR d IN validated_discharges %]
52
                    <tr>
53
                        <td>[% d.needed | $KohaDates with_hours = 1 %]</td>
54
                        <td>[% d.validated | $KohaDates with_hours = 1 %]</td>
55
                    </tr>
56
                [% END %]
57
            </tbody>
58
        </table>
59
    [% END %]
60
40
</div>
61
</div>
41
62
42
63
(-)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