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

(-)a/Koha/Borrower/Discharge.pm (+135 lines)
Line 0 Link Here
1
package Koha::Borrower::Discharge;
2
3
use Modern::Perl;
4
use CGI;
5
use File::Temp qw( :POSIX );
6
use HTML::HTMLDoc;
7
8
use C4::Members qw( GetPendingIssues );
9
use C4::Reserves qw( GetReservesFromBorrowernumber CancelReserve );
10
11
use Koha::Database;
12
use Koha::DateUtils qw( dt_from_string output_pref );
13
14
my $rs = Koha::Database->new->schema->resultset('Discharge');
15
16
sub count {
17
    my ($params) = @_;
18
    my $values = {};
19
20
    if( $params->{borrowernumber} ) {
21
        $values->{borrower} = $params->{borrowernumber};
22
    }
23
    if( $params->{pending} ) {
24
        $values->{needed} = { '!=', undef };
25
        $values->{validated} = undef;
26
    }
27
    elsif( $params->{validated} ) {
28
        $values->{validated} = { '!=', undef };
29
    }
30
31
    return $rs->search( $values )->count;
32
}
33
34
sub can_be_discharged {
35
    my ($params) = @_;
36
    return unless $params->{borrowernumber};
37
38
    my $issues = GetPendingIssues( $params->{borrowernumber} );
39
    if( @$issues ) {
40
        return 0;
41
    }
42
    else {
43
        return 1;
44
    }
45
}
46
47
sub request {
48
    my ($params) = @_;
49
    my $borrowernumber = $params->{borrowernumber};
50
    return unless $borrowernumber;
51
    return unless can_be_discharged({ borrowernumber => $borrowernumber });
52
    return if count($params);
53
54
    return $rs->create({
55
        borrower => $borrowernumber,
56
        needed   => dt_from_string,
57
    });
58
}
59
60
sub discharge {
61
    my ($params) = @_;
62
    my $borrowernumber = $params->{borrowernumber};
63
    return unless $borrowernumber and can_be_discharged( { borrowernumber => $borrowernumber } );
64
65
    # Cancel reserves
66
    my @reserves = GetReservesFromBorrowernumber($borrowernumber);
67
    for my $reserve (@reserves) {
68
        CancelReserve( { reserve_id => $reserve->{reserve_id} } );
69
    }
70
71
    # Debar the member
72
    Koha::Borrower::Debarments::AddDebarment({
73
        borrowernumber => $borrowernumber,
74
        type           => 'DISCHARGE',
75
    });
76
77
    # Generate the discharge
78
    my $discharge = $rs->search({ borrower => $borrowernumber });
79
    if( $discharge->count > 0 ) {
80
        $discharge->update({ validated => dt_from_string });
81
    }
82
    else {
83
        $rs->create({
84
            borrower  => $borrowernumber,
85
            validated => dt_from_string,
86
        });
87
    }
88
}
89
90
sub generate_as_pdf {
91
    my ($params) = @_;
92
    return unless $params->{borrowernumber};
93
94
    my $letter = C4::Letters::GetPreparedLetter(
95
        module      => 'members',
96
        letter_code => 'DISCHARGE',
97
        tables      => { borrowers => $params->{borrowernumber}, },
98
    );
99
100
    my $today = output_pref( dt_from_string() );
101
    $letter->{'title'}   =~ s/<<today>>/$today/g;
102
    $letter->{'content'} =~ s/<<today>>/$today/g;
103
104
    my $tmpl = C4::Templates::gettemplate('batch/print-notices.tt', 'intranet', new CGI);
105
    $tmpl->param(
106
        stylesheet => C4::Context->preference("NoticeCSS"),
107
        today      => $today,
108
        messages   => [$letter],
109
    );
110
111
    my $pdf_path = tmpnam();
112
    my $htmldoc  = new HTML::HTMLDoc();
113
    $htmldoc->set_html_content($tmpl->output);
114
    $htmldoc->generate_pdf()->to_file($pdf_path);
115
116
    return $pdf_path;
117
}
118
119
sub get_pendings {
120
    my ($params)       = @_;
121
    my $branchcode     = $params->{branchcode};
122
    my $borrowernumber = $params->{borrowernumber};
123
124
    my $cond = {
125
        'me.needed'    => { '!=', undef },
126
        'me.validated' => undef,
127
        ( defined $borrowernumber ? ( 'me.borrower' => $borrowernumber ) : () ),
128
        ( defined $branchcode ? ( 'borrower.branchcode' => $branchcode ) : () ),
129
    };
130
131
    my @rs = $rs->search( $cond, { join => 'borrower' } );
132
    return \@rs;
133
}
134
135
1;
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/members/discharge.tt (+41 lines)
Line 0 Link Here
1
[% 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
[% INCLUDE 'doc-head-close.inc' %]
4
</head>
5
<body>
6
[% INCLUDE 'header.inc' %]
7
[% INCLUDE 'patron-search.inc' %]
8
9
<div id="breadcrumbs">
10
         <a href="/cgi-bin/koha/mainpage.pl">Home</a>
11
&rsaquo; <a href="/cgi-bin/koha/members/members-home.pl">Patrons</a>
12
&rsaquo; [% IF (unknowuser) %]Patron does not exist[% ELSE %]Discharge for [% firstname %] [% surname %] ([% cardnumber %])[% END %]
13
</div>
14
15
<div id="doc3" class="yui-t1">
16
   <div id="bd">
17
    <div id="yui-main">
18
    <div class="yui-b">
19
<div class="yui-g">
20
<h3>Discharge</h3>
21
[% UNLESS can_be_discharged %]
22
    <p>Cannot edit discharge: borrower has issues.</p>
23
[% ELSE %]
24
    [% IF has_reserves %]
25
        <p>Borrower has reserves: they will be canceled if the discharge is generated.</p>
26
    [% END %]
27
    <form method="post">
28
        <input type="submit" value="Generate discharge" name="discharge" />
29
        <input type="hidden" value="[% borrowernumber %]" name="borrowernumber" />
30
    </form>
31
[% END %]
32
</div>
33
34
35
</div>
36
</div>
37
<div class="yui-b">
38
[% INCLUDE 'circ-menu.inc' %]
39
</div>
40
</div>
41
[% INCLUDE 'intranet-bottom.inc' %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/members/discharges.tt (+41 lines)
Line 0 Link Here
1
[% INCLUDE 'doc-head-open.inc' %]
2
<title>Koha &rsaquo; Patrons &rsaquo; Pending discharge requests</title>
3
[% INCLUDE 'doc-head-close.inc' %]
4
</head>
5
<body id="pat_discharges" class="pat">
6
[% INCLUDE 'header.inc' %]
7
[% INCLUDE 'patron-search.inc' %]
8
9
<div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo; <a href="/cgi-bin/koha/members/members-home.pl">Patrons</a> &rsaquo; Pending discharge requests</div>
10
11
<div id="doc2" class="yui-t7">
12
<div id="bd">
13
  <div id="yui-main">
14
    [% IF pending_discharges %]
15
      <h2>Pending discharge requests</h2>
16
      <div id="pending_updates">
17
        <table>
18
          <thead>
19
            <tr>
20
              <th>Patron</th>
21
              <th>Allow</th>
22
            </tr>
23
          </thead>
24
          <tbody>
25
            [% FOR d IN pending_discharges %]
26
              <tr>
27
                <td><a href="/cgi-bin/koha/members/discharge.pl?borrowernumber=[% d.borrower.borrowernumber %]">[% d.borrower.surname %], [% d.borrower.firstname %]</a></td>
28
                <td><a href="/cgi-bin/koha/members/discharges.pl?op=allow&borrowernumber=[% d.borrower.borrowernumber %]">Allow</a></td>
29
              </tr>
30
            [% END %]
31
          </tbody>
32
        </table>
33
      </div>
34
    [% ELSE %]
35
      <div class="dialog message">
36
        <p>There are no pending discharge requests.</p>
37
      </div>
38
    [% END %]
39
  </div>
40
</div>
41
[% INCLUDE 'intranet-bottom.inc' %]
(-)a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-discharge.tt (+47 lines)
Line 0 Link Here
1
[% USE Koha %]
2
[% INCLUDE 'doc-head-open.inc' %]
3
[% IF ( LibraryNameTitle ) %][% LibraryNameTitle %][% ELSE %]Koha online[% END %] catalog &rsaquo; Discharge
4
[% INCLUDE 'doc-head-close.inc' %]
5
[% BLOCK cssinclude %][% END %]
6
</head>
7
<body id="opac-discharge" class="scrollto">
8
[% INCLUDE 'masthead.inc' %]
9
10
<div class="main">
11
    <ul class="breadcrumb">
12
        <li><a href="/cgi-bin/koha/opac-main.pl">Home</a> <span class="divider">&rsaquo;</span></li>
13
        <li><a href="#">Discharge</a></li>
14
    </ul>
15
16
    <div class="container-fluid">
17
        <div class="row-fluid">
18
            <div class="span2">
19
                <div id="navigation">
20
                    [% INCLUDE 'navigation.inc' IsPatronPage=1 %]
21
                </div>
22
            </div>
23
            <div class="span10">
24
                <div id="discharge" class="maincontainer">
25
                    <h1>Discharge</h1>
26
                    [% IF success %]
27
                        <p>Your discharge request has been sent. Your discharge will be available on this page within a few days.</p>
28
                    [% ELSIF available %]
29
                        <a href="/cgi-bin/koha/opac-discharge.pl?op=get">Get your discharge</a></li>
30
                    [% ELSIF pending %]
31
                        <p>Your discharge will be available on this page within a few days.</p>
32
                    [% ELSIF has_issues %]
33
                        <p>You cannot be discharged, you have issues. Please return items before asking for a discharge.</p>
34
                    [% ELSE %]
35
                        <h2>What is a discharge?</h2>
36
                        <p>This document certifies that you have returned all borrowed items. It is sometimes asked during a file transfer from a school to another. The discharge is sent by us to your school. You will also find it available on your reader account.</p>
37
                        <p><strong>Warning</strong>: This request is only valid if you are in good standing with the library. Once the application is made, you can not borrow library materials.</p>
38
                        <a href="/cgi-bin/koha/opac-discharge.pl?op=request">Ask for a discharge</a>
39
                    [% END %]
40
                </div> <!-- / #discharge -->
41
            </div> <!-- / .span10 -->
42
        </div> <!-- / .row-fluid -->
43
    </div>  <!-- / .container-fluid -->
44
</div> <!-- / .main -->
45
46
[% INCLUDE 'opac-bottom.inc' %]
47
[% BLOCK jsinclude %][% END %]
(-)a/members/discharge.pl (+120 lines)
Line 0 Link Here
1
#!/usr/bin/perl
2
3
# This file is part of Koha.
4
#
5
# Copyright 2013 BibLibre
6
#
7
# Koha is free software; you can redistribute it and/or modify it
8
# under the terms of the GNU General Public License as published by
9
# the Free Software Foundation; either version 3 of the License, or
10
# (at your option) any later version.
11
#
12
# Koha is distributed in the hope that it will be useful, but
13
# WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
16
#
17
# You should have received a copy of the GNU General Public License
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
19
20
=head1 NAME
21
22
discharges.pl
23
24
=head1 DESCRIPTION
25
26
Allows librarian to edit and/or manage borrowers' discharges
27
28
=cut
29
30
use Modern::Perl;
31
32
use CGI;
33
use C4::Auth;
34
use C4::Output;
35
use C4::Members;
36
use C4::Reserves;
37
use C4::Letters;
38
use Koha::Borrower::Discharge;
39
40
use Koha::DateUtils;
41
42
my $input = new CGI;
43
my ( $template, $loggedinuser, $cookie, $flags ) = get_template_and_user({
44
    template_name   => 'members/discharge.tt',
45
    query           => $input,
46
    type            => 'intranet',
47
    authnotrequired => 0,
48
    flagsrequired   => { 'borrowers' => '*' },
49
});
50
51
my $borrowernumber;
52
my $data;
53
if ( $input->param('borrowernumber') ) {
54
    $borrowernumber = $input->param('borrowernumber');
55
56
    # Getting member data
57
    $data = GetMember( borrowernumber => $borrowernumber );
58
59
    my $can_be_discharged = Koha::Borrower::Discharge::can_be_discharged({
60
        borrowernumber => $borrowernumber
61
    });
62
63
    # Getting reserves
64
    my @reserves    = GetReservesFromBorrowernumber($borrowernumber);
65
    my $has_reserves = scalar(@reserves);
66
67
    # Generating discharge if needed
68
    if ( $input->param('discharge') and $can_be_discharged ) {
69
        my $is_discharged = Koha::Borrower::Discharge::count({
70
            borrowernumber => $borrowernumber,
71
            validated      => 1,
72
        });
73
        unless ($is_discharged) {
74
            Koha::Borrower::Discharge::discharge({
75
                borrowernumber => $borrowernumber
76
            });
77
        }
78
        my $pdf_path = Koha::Borrower::Discharge::generate_as_pdf(
79
            { borrowernumber => $borrowernumber, } );
80
81
        print $input->header(
82
            -type       => 'application/pdf',
83
            -charset    => 'utf-8',
84
            -attachment => "discharge_$borrowernumber.pdf",
85
        );
86
        open my $fh, '<', $pdf_path;
87
        my @lines = <$fh>;
88
        close $fh;
89
        print @lines;
90
        exit;
91
    }
92
93
    $template->param(
94
        borrowernumber    => $borrowernumber,
95
        biblionumber      => $data->{'biblionumber'},
96
        title             => $data->{'title'},
97
        initials          => $data->{'initials'},
98
        surname           => $data->{'surname'},
99
        borrowernumber    => $borrowernumber,
100
        firstname         => $data->{'firstname'},
101
        cardnumber        => $data->{'cardnumber'},
102
        categorycode      => $data->{'categorycode'},
103
        category_type     => $data->{'category_type'},
104
        categoryname      => $data->{'description'},
105
        address           => $data->{'address'},
106
        address2          => $data->{'address2'},
107
        city              => $data->{'city'},
108
        zipcode           => $data->{'zipcode'},
109
        country           => $data->{'country'},
110
        phone             => $data->{'phone'},
111
        email             => $data->{'email'},
112
        branchcode        => $data->{'branchcode'},
113
        has_reserves      => $has_reserves,
114
        can_be_discharged => $can_be_discharged,
115
    );
116
}
117
118
$template->param( dischargeview => 1, );
119
120
output_html_with_http_headers $input, $cookie, $template->output;
(-)a/members/discharges.pl (+58 lines)
Line 0 Link Here
1
#!/usr/bin/perl
2
3
# This file is part of Koha.
4
#
5
# Copyright 2013 BibLibre
6
#
7
# Koha is free software; you can redistribute it and/or modify it
8
# under the terms of the GNU General Public License as published by
9
# the Free Software Foundation; either version 3 of the License, or
10
# (at your option) any later version.
11
#
12
# Koha is distributed in the hope that it will be useful, but
13
# WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
16
#
17
# You should have received a copy of the GNU General Public License
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
19
20
use Modern::Perl;
21
22
use CGI;
23
use C4::Auth;
24
use C4::Output;
25
use C4::Context;
26
use Koha::Borrower::Discharge;
27
28
my $input = new CGI;
29
my $op = $input->param('op') // 'list';
30
31
my ( $template, $loggedinuser, $cookie, $flags ) = get_template_and_user({
32
    template_name   => "members/discharges.tt",
33
    query           => $input,
34
    type            => "intranet",
35
    authnotrequired => 0,
36
    flagsrequired   => { borrowers => 1 },
37
});
38
39
my $branchcode =
40
  ( C4::Context->preference("IndependentBranches")
41
      and not C4::Context->IsSuperLibrarian() )
42
  ? C4::Context->userenv()->{'branch'}
43
  : undef;
44
45
if( $op eq 'allow' ) {
46
    my $borrowernumber = $input->param('borrowernumber');
47
    Koha::Borrower::Discharge::discharge({
48
        borrowernumber => $borrowernumber
49
    }) if $borrowernumber;
50
}
51
52
my $pending_discharges = Koha::Borrower::Discharge::get_pendings({
53
    branchcode => $branchcode
54
});
55
56
$template->param( pending_discharges => $pending_discharges );
57
58
output_html_with_http_headers $input, $cookie, $template->output;
(-)a/opac/opac-discharge.pl (-1 / +90 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
3
# This file is part of Koha.
4
#
5
# Copyright 2013 BibLibre
6
#
7
# Koha is free software; you can redistribute it and/or modify it
8
# under the terms of the GNU General Public License as published by
9
# the Free Software Foundation; either version 3 of the License, or
10
# (at your option) any later version.
11
#
12
# Koha is distributed in the hope that it will be useful, but
13
# WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
16
#
17
# You should have received a copy of the GNU General Public License
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
19
20
use Modern::Perl;
21
22
use C4::Auth qw(:DEFAULT get_session);
23
use CGI;
24
use C4::Context;
25
use C4::Output;
26
use C4::Log;
27
use C4::Debug;
28
use C4::Branch;
29
use C4::Members;
30
use Koha::Borrower::Discharge;
31
use Koha::DateUtils;
32
33
my $input = new CGI;
34
35
my $op = $input->param("op");
36
37
# Getting the template and auth
38
my ( $template, $loggedinuser, $cookie ) = get_template_and_user({
39
    template_name => "opac-discharge.tt",
40
    query         => $input,
41
    type          => "opac",
42
    debug         => 1,
43
});
44
45
if ( $op eq 'request' ) {
46
    my $success = Koha::Borrower::Discharge::request({
47
        borrowernumber => $loggedinuser,
48
    });
49
50
    if ($success) {
51
        $template->param( success => 1 );
52
    }
53
    else {
54
        $template->param( has_issues => 1 );
55
    }
56
}
57
elsif ( $op eq 'get' ) {
58
    my $pdf_path = Koha::Borrower::Discharge::generate_as_pdf({
59
        borrowernumber => $loggedinuser
60
    });
61
62
    print $input->header(
63
        -type       => 'application/pdf',
64
        -charset    => 'utf-8',
65
        -attachment => "discharge_$loggedinuser.pdf",
66
    );
67
    open my $fh, '<', $pdf_path;
68
    my @lines = <$fh>;
69
    close $fh;
70
    print @lines;
71
    exit;
72
}
73
else {
74
    my $pending = Koha::Borrower::Discharge::count({
75
        borrowernumber => $loggedinuser,
76
        pending        => 1,
77
    });
78
    my $available = Koha::Borrower::Discharge::count({
79
        borrowernumber => $loggedinuser,
80
        validated      => 1,
81
    });
82
    $template->param(
83
        available => $available,
84
        pending   => $pending,
85
    );
86
}
87
88
$template->param( dischargeview => 1 );
89
90
output_html_with_http_headers $input, $cookie, $template->output;

Return to bug 8007