adding volume and volumeddesc field in the result list. Kados, pls check that it...
[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 use Data::Dumper;
108 warn "HERE : $default / $location".Dumper(@getoverdues);
109 # search for location authorised value
110 my ($tag,$subfield) = GetMarcFromKohaField('items.location','');
111 my $tagslib = &GetMarcStructure(1,'');
112 if ($tagslib->{$tag}->{$subfield}->{authorised_value}) {
113     my $values= GetAuthorisedValues($tagslib->{$tag}->{$subfield}->{authorised_value});
114     $template->param(locationsloop => $values);
115 }
116 # now display infos
117 foreach my $num (@getoverdues) {
118
119     my %overdueforbranch;
120     $overdueforbranch{'date_due'}          = format_date( $num->{'date_due'} );
121     $overdueforbranch{'title'}             = $num->{'title'};
122     $overdueforbranch{'description'}       = $num->{'description'};
123     $overdueforbranch{'barcode'}           = $num->{'barcode'};
124     $overdueforbranch{'biblionumber'}      = $num->{'biblionumber'};
125     $overdueforbranch{'borrowersurname'}   = $num->{'surname'};
126     $overdueforbranch{'borrowerfirstname'} = $num->{'firstname'};
127     $overdueforbranch{'borrowerphone'}     = $num->{'phone'};
128     $overdueforbranch{'borroweremail'}     = $num->{'email'};
129     $overdueforbranch{'itemcallnumber'}    = $num->{'itemcallnumber'};
130     $overdueforbranch{'borrowernumber'}    = $num->{'borrowernumber'};
131     $overdueforbranch{'itemnumber'}        = $num->{'itemnumber'};
132
133     # now we add on the template, the differents values of notify_level
134     if ( $num->{'notify_level'} eq '1' ) {
135         $overdueforbranch{'overdue1'}     = 1;
136         $overdueforbranch{'overdueLevel'} = 1;
137     }
138
139     if ( $num->{'notify_level'} eq '2' ) {
140         $overdueforbranch{'overdue2'}     = 1;
141         $overdueforbranch{'overdueLevel'} = 2;
142     }
143
144     if ( $num->{'notify_level'} eq '3' ) {
145         $overdueforbranch{'overdue3'}     = 1;
146         $overdueforbranch{'overdueLevel'} = 3;
147     }
148     $overdueforbranch{'notify_id'} = $num->{'notify_id'};
149
150     push( @overduesloop, \%overdueforbranch );
151 }
152
153 # initiate the templates for the overdueloop
154 $template->param(
155     overduesloop => \@overduesloop,
156     show_date    => format_date($todaysdate),
157     location     => $location,
158 );
159
160 output_html_with_http_headers $input, $cookie, $template->output;