opac.css - button background fix for input.icon
[koha.git] / circ / branchoverdues.pl
1 #!/usr/bin/perl
2
3 #
4 # This file is part of Koha.
5 #
6 # Koha is free software; you can redistribute it and/or modify it under the
7 # terms of the GNU General Public License as published by the Free Software
8 # Foundation; either version 2 of the License, or (at your option) any later
9 # version.
10 #
11 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
12 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
13 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License along with
16 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
17 # Suite 330, Boston, MA  02111-1307 USA
18
19 use strict;
20 use C4::Context;
21 use CGI;
22 use C4::Output;
23 use C4::Auth;
24 use C4::Dates qw/format_date/;
25 use C4::Overdues;    # AddNotifyLine
26 use C4::Biblio;
27 use C4::Koha;
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 location (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 $dbh = C4::Context->dbh;
59
60 my $theme = $input->param('theme');    # only used if allowthemeoverride is set
61
62 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
63     {
64         template_name   => "circ/branchoverdues.tmpl",
65         query           => $input,
66         type            => "intranet",
67         authnotrequired => 0,
68         flagsrequired   => { circulate => 1 },
69         debug           => 1,
70     }
71 );
72
73 my $default = C4::Context->userenv->{'branch'};
74
75 # Initate localtime
76 my ( $year, $month, $day ) = &Today;
77 my $todaysdate = join "-", ( $year, $month, $day );
78
79 # Deal with the vars recept from the template
80 my $borrowernumber = $input->param('borrowernumber');
81 my $itemnumber     = $input->param('itemnumber');
82 my $method         = $input->param('method');
83 my $overduelevel   = $input->param('overduelevel');
84 my $notifyId       = $input->param('notifyId');
85 my $location = $input->param('location');
86
87 # now create the line in bdd (notifys)
88 if ( $input->param('action') eq 'add' ) {
89     my $addnotify =
90       AddNotifyLine( $borrowernumber, $itemnumber, $overduelevel, $method,
91         $notifyId );
92 }
93
94 #  possibility to remove notify line
95 if ( $input->param('action') eq 'remove' ) {
96     my $notify_date  = $input->param('notify_date');
97     my $removenotify =
98       RemoveNotifyLine( $borrowernumber, $itemnumber, $notify_date );
99 }
100
101 my @overduesloop;
102 my @todayoverduesloop;
103 my $counter = 0;
104
105 my @getoverdues = GetOverduesForBranch( $default, $location );
106 use Data::Dumper;
107 warn "HERE : $default / $location".Dumper(@getoverdues);
108 # search for location authorised value
109 my ($tag,$subfield) = GetMarcFromKohaField('items.location','');
110 my $tagslib = &GetMarcStructure(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;