functions that were in C4::Interface::CGI::Output are now in C4::Output.
[koha.git] / circ / branchoverdues.pl
1 #!/usr/bin/perl
2
3 # $Id$
4 #
5 # This file is part of Koha.
6 #
7 # Koha is free software; you can redistribute it and/or modify it under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 2 of the License, or (at your option) any later
10 # version.
11 #
12 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License along with
17 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
18 # Suite 330, Boston, MA  02111-1307 USA
19
20 use strict;
21 use C4::Context;
22 use CGI;
23 use C4::Output;
24 use C4::Auth;
25 use C4::Date;
26 use C4::Overdues;    # AddNotifyLine
27 use C4::Biblio;
28 use C4::Koha;
29 use Mail::Sendmail;
30 use Getopt::Long;
31 use Date::Calc qw/Today Today_and_Now Now/;
32
33 =head1 branchoverdues.pl
34
35  this module is a new interface, allow to the librarian to check all items on overdues (based on the acountlines type 'FU' )
36  this interface is filtered by branches (automaticly), and by location (optional) ....
37  all informations are stocked in the notifys BDD
38
39  FIXME for this time, we have only four methods to notify :
40         - mail : work with a batch programm
41         - letter : for us, the letters are generated by an open-office program
42         - phone : Simple method, when the method 'phone' is selected, we consider, that the borrower as been notified, and the notify send date is implemented
43         - considered lost : for us if the document is on the third overduelevel,
44
45  FIXME the methods are actually hardcoded for the levels : (maybe can be improved by a new possibility in overduerule)
46
47         level 1 : three methods are possible : - mail, letter, phone
48         level 2 : only one method is possible : - letter
49         level 3 : only methode is possible  : - Considered Lost
50
51         the documents displayed on this interface, are checked on three points
52         - 1) the document must be on accountlines (Type 'FU')
53         - 2) item issues is not returned
54         - 3) this item as not been already notify
55
56 =cut
57
58 my $input       = new CGI;
59 my $dbh = C4::Context->dbh;
60
61 my $theme = $input->param('theme');    # only used if allowthemeoverride is set
62
63 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
64     {
65         template_name   => "circ/branchoverdues.tmpl",
66         query           => $input,
67         type            => "intranet",
68         authnotrequired => 0,
69         flagsrequired   => { circulate => 1 },
70         debug           => 1,
71     }
72 );
73
74 my $default = C4::Context->userenv->{'branch'};
75
76 # Initate localtime
77 my ( $year, $month, $day ) = &Today;
78 my $todaysdate = join "-", ( $year, $month, $day );
79
80 # Deal with the vars recept from the template
81 my $borrowernumber = $input->param('borrowernumber');
82 my $itemnumber     = $input->param('itemnumber');
83 my $method         = $input->param('method');
84 my $overduelevel   = $input->param('overduelevel');
85 my $notifyId       = $input->param('notifyId');
86 my $location = $input->param('location');
87
88 # now create the line in bdd (notifys)
89 if ( $input->param('action') eq 'add' ) {
90     my $addnotify =
91       AddNotifyLine( $borrowernumber, $itemnumber, $overduelevel, $method,
92         $notifyId );
93 }
94
95 #  possibility to remove notify line
96 if ( $input->param('action') eq 'remove' ) {
97     my $notify_date  = $input->param('notify_date');
98     my $removenotify =
99       RemoveNotifyLine( $borrowernumber, $itemnumber, $notify_date );
100 }
101
102 my @overduesloop;
103 my @todayoverduesloop;
104 my $counter = 0;
105
106 my @getoverdues = GetOverduesForBranch( $default, $location );
107
108 # search for location authorised value
109 my ($tag,$subfield) = GetMarcFromKohaField($dbh,'items.location','');
110 my $tagslib = &GetMarcStructure($dbh,1,'');
111 if ($tagslib->{$tag}->{$subfield}->{authorised_value}) {
112     my $values= GetAuthorisedValues($tagslib->{$tag}->{$subfield}->{authorised_value});
113     $template->param(locationsloop => $values);
114 }
115 # now display infos
116 foreach my $num (@getoverdues) {
117
118     my %overdueforbranch;
119     $overdueforbranch{'date_due'}          = format_date( $num->{'date_due'} );
120     $overdueforbranch{'title'}             = $num->{'title'};
121     $overdueforbranch{'description'}       = $num->{'description'};
122     $overdueforbranch{'barcode'}           = $num->{'barcode'};
123     $overdueforbranch{'biblionumber'}      = $num->{'biblionumber'};
124     $overdueforbranch{'borrowersurname'}   = $num->{'surname'};
125     $overdueforbranch{'borrowerfirstname'} = $num->{'firstname'};
126     $overdueforbranch{'borrowerphone'}     = $num->{'phone'};
127     $overdueforbranch{'borroweremail'}     = $num->{'email'};
128     $overdueforbranch{'itemcallnumber'}    = $num->{'itemcallnumber'};
129     $overdueforbranch{'borrowernumber'}    = $num->{'borrowernumber'};
130     $overdueforbranch{'itemnumber'}        = $num->{'itemnumber'};
131
132     # now we add on the template, the differents values of notify_level
133     if ( $num->{'notify_level'} eq '1' ) {
134         $overdueforbranch{'overdue1'}     = 1;
135         $overdueforbranch{'overdueLevel'} = 1;
136     }
137
138     if ( $num->{'notify_level'} eq '2' ) {
139         $overdueforbranch{'overdue2'}     = 1;
140         $overdueforbranch{'overdueLevel'} = 2;
141     }
142
143     if ( $num->{'notify_level'} eq '3' ) {
144         $overdueforbranch{'overdue3'}     = 1;
145         $overdueforbranch{'overdueLevel'} = 3;
146     }
147     $overdueforbranch{'notify_id'} = $num->{'notify_id'};
148
149     push( @overduesloop, \%overdueforbranch );
150 }
151
152 # initiate the templates for the overdueloop
153 $template->param(
154     overduesloop => \@overduesloop,
155     show_date    => format_date($todaysdate),
156     location     => $location,
157 );
158
159 output_html_with_http_headers $input, $cookie, $template->output;