Bug 15839: Koha::Reviews - Change default value for approved to 0
[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
7 # under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 3 of the License, or
9 # (at your option) any later version.
10 #
11 # Koha is distributed in the hope that it will be useful, but
12 # WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with Koha; if not, see <http://www.gnu.org/licenses>.
18
19 use strict;
20 #use warnings; FIXME - Bug 2505
21 use C4::Context;
22 use CGI qw ( -utf8 );
23 use C4::Output;
24 use C4::Auth;
25 use C4::Overdues;    # AddNotifyLine
26 use C4::Biblio;
27 use C4::Koha;
28 use C4::Debug;
29 use Koha::DateUtils;
30 use Data::Dumper;
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 (automatically), 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   FIXME: who is the author?
56   FIXME: No privisions (i.e. "actions") for handling notices are implemented.
57   FIXME: This is linked as "Overdue Fines" but the relationship to fines in GetOverduesForBranch is more complicated than that.
58
59 =cut
60
61 my $input       = new CGI;
62 my $dbh = C4::Context->dbh;
63
64 my ( $template, $loggedinuser, $cookie ) = get_template_and_user({
65         template_name   => "circ/branchoverdues.tt",
66         query           => $input,
67         type            => "intranet",
68         authnotrequired => 0,
69         flagsrequired   => { circulate => "circulate_remaining_permissions" },
70         debug           => 1,
71 });
72
73 my $default = C4::Context->userenv->{'branch'};
74
75 # Deal with the vars recept from the template
76 my $borrowernumber = $input->param('borrowernumber');
77 my $itemnumber     = $input->param('itemnumber');
78 my $method         = $input->param('method');
79 my $overduelevel   = $input->param('overduelevel');
80 my $notifyId       = $input->param('notifyId');
81 my $location       = $input->param('location');
82
83 # FIXME: better check that borrowernumber is defined and valid.
84 # FIXME: same for itemnumber and other variables passed in here.
85
86 # now create the line in bdd (notifys)
87 if ( $input->param('action') eq 'add' ) {
88     my $addnotify =
89       AddNotifyLine( $borrowernumber, $itemnumber, $overduelevel, $method,
90         $notifyId )    # FIXME: useless variable, no TMPL code for "action" exists.;
91 }
92 elsif ( $input->param('action') eq 'remove' ) {
93     my $notify_date  = $input->param('notify_date');
94     my $removenotify =
95       RemoveNotifyLine( $borrowernumber, $itemnumber, $notify_date );    # FIXME: useless variable, no TMPL code for "action" exists.
96 }
97
98 my @overduesloop;
99 my @getoverdues = GetOverduesForBranch( $default, $location );
100 $debug and warn "HERE : $default / $location" . Dumper(@getoverdues);
101 # search for location authorised value
102 my ($tag,$subfield) = GetMarcFromKohaField('items.location','');
103 my $tagslib = &GetMarcStructure(1,'');
104 if ($tagslib->{$tag}->{$subfield}->{authorised_value}) {
105     my $values= GetAuthorisedValues($tagslib->{$tag}->{$subfield}->{authorised_value});
106     for (@$values) { $_->{selected} = 1 if $location eq $_->{authorised_value} }
107     $template->param(locationsloop => $values);
108 }
109 # now display infos
110 foreach my $num (@getoverdues) {
111     my %overdueforbranch;
112     my $record = GetMarcBiblio($num->{biblionumber});
113     if ($record){
114         $overdueforbranch{'subtitle'} = GetRecordValue('subtitle',$record,'')->[0]->{subfield};
115     }
116     my $dt = dt_from_string($num->{date_due}, 'sql');
117     $overdueforbranch{'date_due'}          = output_pref($dt);
118     $overdueforbranch{'title'}             = $num->{'title'};
119     $overdueforbranch{'description'}       = $num->{'description'};
120     $overdueforbranch{'barcode'}           = $num->{'barcode'};
121     $overdueforbranch{'biblionumber'}      = $num->{'biblionumber'};
122     $overdueforbranch{'author'}            = $num->{'author'};
123     $overdueforbranch{'borrowersurname'}   = $num->{'surname'};
124     $overdueforbranch{'borrowerfirstname'} = $num->{'firstname'};
125     $overdueforbranch{'borrowerphone'}     = $num->{'phone'};
126     $overdueforbranch{'borroweremail'}     = $num->{'email'};
127     $overdueforbranch{'homebranch'}        = $num->{'homebranch'};
128     $overdueforbranch{'itemcallnumber'}    = $num->{'itemcallnumber'};
129     $overdueforbranch{'borrowernumber'}    = $num->{'borrowernumber'};
130     $overdueforbranch{'itemnumber'}        = $num->{'itemnumber'};
131     $overdueforbranch{'cardnumber'}        = $num->{'cardnumber'};
132
133     # now we add on the template, the differents values of notify_level
134     # FIXME: numerical comparison, not string eq.
135     if ( $num->{'notify_level'} eq '1' ) {
136         $overdueforbranch{'overdue1'}     = 1;
137         $overdueforbranch{'overdueLevel'} = 1;
138     }
139     elsif ( $num->{'notify_level'} eq '2' ) {
140         $overdueforbranch{'overdue2'}     = 1;
141         $overdueforbranch{'overdueLevel'} = 2;
142     }
143     elsif ( $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     location     => $location,
156 );
157
158 output_html_with_http_headers $input, $cookie, $template->output;