fixing permissions on mainpage
[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::Interface::CGI::Output;
24 use C4::Auth;
25 use C4::Date;
26 use C4::Circulation::Circ2;    # AddNotifyLine
27 use C4::Koha;                  # GetDepartment...
28 use Mail::Sendmail;
29 use Getopt::Long;
30 use Date::Calc qw/Today Today_and_Now Now/;
31
32 =head1 branchoverdues.pl
33
34  this module is a new interface, allow to the librarian to check all items on overdues (based on the acountlines type 'FU' )
35  this interface is filtered by branches (automaticly), and by department (optional) ....
36  all informations are stocked in the notifys BDD
37
38  FIXME for this time, we have only four methods to notify :
39         - mail : work with a batch programm
40         - letter : for us, the letters are generated by an open-office program
41         - phone : Simple method, when the method 'phone' is selected, we consider, that the borrower as been notified, and the notify send date is implemented
42         - considered lost : for us if the document is on the third overduelevel,
43
44  FIXME the methods are actually hardcoded for the levels : (maybe can be improved by a new possibility in overduerule)
45
46         level 1 : three methods are possible : - mail, letter, phone
47         level 2 : only one method is possible : - letter
48         level 3 : only methode is possible  : - Considered Lost
49
50         the documents displayed on this interface, are checked on three points
51         - 1) the document must be on accountlines (Type 'FU')
52         - 2) item issues is not returned
53         - 3) this item as not been already notify
54
55 =cut
56
57 my $input       = new CGI;
58 my $theme = $input->param('theme');    # only used if allowthemeoverride is set
59
60 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
61     {
62         template_name   => "circ/branchoverdues.tmpl",
63         query           => $input,
64         type            => "intranet",
65         authnotrequired => 0,
66         flagsrequired   => { circulate => 1 },
67         debug           => 1,
68     }
69 );
70
71 my $default = C4::Context->userenv->{'branch'};
72
73 # Initate localtime
74 my ( $year, $month, $day ) = &Today;
75 my $todaysdate = join "-", ( $year, $month, $day );
76
77 # Deal with the vars recept from the template
78 my $borrowernumber = $input->param('borrowernumber');
79 my $itemnumber     = $input->param('itemnumber');
80 my $method         = $input->param('method');
81 my $overduelevel   = $input->param('overduelevel');
82 my $notifyId       = $input->param('notifyId');
83 my $department = $input->param('department');
84
85 # now create the line in bdd (notifys)
86 if ( $input->param('action') eq 'add' ) {
87     my $addnotify =
88       AddNotifyLine( $borrowernumber, $itemnumber, $overduelevel, $method,
89         $notifyId );
90 }
91
92 #  possibility to remove notify line
93 if ( $input->param('action') eq 'remove' ) {
94     my $notify_date  = $input->param('notify_date');
95     my $removenotify =
96       RemoveNotifyLine( $borrowernumber, $itemnumber, $notify_date );
97 }
98
99 my @overduesloop;
100 my @todayoverduesloop;
101 my $counter = 0;
102
103 my @getoverdues = GetOverduesForBranch( $default, $department );
104
105 # filter by department
106 if ($department) {
107     my ( $departmentlib, $departmentValue ) = GetDepartmentLib($department);
108     $template->param(
109         department      => $departmentlib,
110         departmentValue => $departmentValue,
111     );
112 }
113 else {
114
115     # initiate the selector of departments .....
116     my @getdepartments = GetDepartments();
117     my @departmentsloop;
118     foreach my $dpt (@getdepartments) {
119         my %department;
120         $department{'authorised_value'} = $dpt->{'authorised_value'};
121         $department{'lib'}              = $dpt->{'lib'};
122         push( @departmentsloop, \%department );
123     }
124     $template->param( departmentsloop => \@departmentsloop, );
125 }
126
127 # now display infos
128 foreach my $num (@getoverdues) {
129
130     my %overdueforbranch;
131     $overdueforbranch{'date_due'}          = format_date( $num->{'date_due'} );
132     $overdueforbranch{'title'}             = $num->{'title'};
133     $overdueforbranch{'description'}       = $num->{'description'};
134     $overdueforbranch{'barcode'}           = $num->{'barcode'};
135     $overdueforbranch{'biblionumber'}      = $num->{'biblionumber'};
136     $overdueforbranch{'borrowersurname'}   = $num->{'surname'};
137     $overdueforbranch{'borrowerfirstname'} = $num->{'firstname'};
138     $overdueforbranch{'borrowerphone'}     = $num->{'phone'};
139     $overdueforbranch{'borroweremail'}     = $num->{'email'};
140     $overdueforbranch{'itemcallnumber'}    = $num->{'itemcallnumber'};
141     $overdueforbranch{'borrowernumber'}    = $num->{'borrowernumber'};
142     $overdueforbranch{'itemnumber'}        = $num->{'itemnumber'};
143
144     # now we add on the template, the differents values of notify_level
145     if ( $num->{'notify_level'} eq '1' ) {
146         $overdueforbranch{'overdue1'}     = 1;
147         $overdueforbranch{'overdueLevel'} = 1;
148     }
149
150     if ( $num->{'notify_level'} eq '2' ) {
151         $overdueforbranch{'overdue2'}     = 1;
152         $overdueforbranch{'overdueLevel'} = 2;
153     }
154
155     if ( $num->{'notify_level'} eq '3' ) {
156         $overdueforbranch{'overdue3'}     = 1;
157         $overdueforbranch{'overdueLevel'} = 3;
158     }
159     $overdueforbranch{'notify_id'} = $num->{'notify_id'};
160
161     push( @overduesloop, \%overdueforbranch );
162 }
163
164 # initiate the templates for the overdueloop
165 $template->param(
166     overduesloop => \@overduesloop,
167     show_date    => format_date($todaysdate),
168 );
169
170 output_html_with_http_headers $input, $cookie, $template->output;