Markup corrections and standardizations.
[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 C4::Debug;
29
30 =head1 branchoverdues.pl
31
32  this module is a new interface, allow to the librarian to check all items on overdues (based on the acountlines type 'FU' )
33  this interface is filtered by branches (automatically), and by location (optional) ....
34  all informations are stocked in the notifys BDD
35
36  FIXME for this time, we have only four methods to notify :
37         - mail : work with a batch programm
38         - letter : for us, the letters are generated by an open-office program
39         - phone : Simple method, when the method 'phone' is selected, we consider, that the borrower as been notified, and the notify send date is implemented
40         - considered lost : for us if the document is on the third overduelevel,
41
42  FIXME the methods are actually hardcoded for the levels : (maybe can be improved by a new possibility in overduerule)
43
44         level 1 : three methods are possible : - mail, letter, phone
45         level 2 : only one method is possible : - letter
46         level 3 : only methode is possible  : - Considered Lost
47
48         the documents displayed on this interface, are checked on three points
49         - 1) the document must be on accountlines (Type 'FU')
50         - 2) item issues is not returned
51         - 3) this item as not been already notify
52
53 =cut
54
55 my $input       = new CGI;
56 my $dbh = C4::Context->dbh;
57
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 # Deal with the vars recept from the template
74 my $borrowernumber = $input->param('borrowernumber');
75 my $itemnumber     = $input->param('itemnumber');
76 my $method         = $input->param('method');
77 my $overduelevel   = $input->param('overduelevel');
78 my $notifyId       = $input->param('notifyId');
79 my $location       = $input->param('location');
80
81 # now create the line in bdd (notifys)
82 if ( $input->param('action') eq 'add' ) {
83     my $addnotify =
84       AddNotifyLine( $borrowernumber, $itemnumber, $overduelevel, $method,
85         $notifyId );
86 }
87 elsif ( $input->param('action') eq 'remove' ) {
88     my $notify_date  = $input->param('notify_date');
89     my $removenotify =
90       RemoveNotifyLine( $borrowernumber, $itemnumber, $notify_date );
91 }
92
93 my @overduesloop;
94 my @todayoverduesloop;
95 my $counter = 0;
96
97 my @getoverdues = GetOverduesForBranch( $default, $location );
98 use Data::Dumper;
99 $debug and warn "HERE : $default / $location" . Dumper(@getoverdues);
100 # search for location authorised value
101 my ($tag,$subfield) = GetMarcFromKohaField('items.location','');
102 my $tagslib = &GetMarcStructure(1,'');
103 if ($tagslib->{$tag}->{$subfield}->{authorised_value}) {
104     my $values= GetAuthorisedValues($tagslib->{$tag}->{$subfield}->{authorised_value});
105     $template->param(locationsloop => $values);
106 }
107 # now display infos
108 foreach my $num (@getoverdues) {
109
110     my %overdueforbranch;
111     $overdueforbranch{'date_due'}          = format_date( $num->{'date_due'} );
112     $overdueforbranch{'title'}             = $num->{'title'};
113     $overdueforbranch{'description'}       = $num->{'description'};
114     $overdueforbranch{'barcode'}           = $num->{'barcode'};
115     $overdueforbranch{'biblionumber'}      = $num->{'biblionumber'};
116     $overdueforbranch{'borrowersurname'}   = $num->{'surname'};
117     $overdueforbranch{'borrowerfirstname'} = $num->{'firstname'};
118     $overdueforbranch{'borrowerphone'}     = $num->{'phone'};
119     $overdueforbranch{'borroweremail'}     = $num->{'email'};
120     $overdueforbranch{'itemcallnumber'}    = $num->{'itemcallnumber'};
121     $overdueforbranch{'borrowernumber'}    = $num->{'borrowernumber'};
122     $overdueforbranch{'itemnumber'}        = $num->{'itemnumber'};
123
124     # now we add on the template, the differents values of notify_level
125     if ( $num->{'notify_level'} eq '1' ) {
126         $overdueforbranch{'overdue1'}     = 1;
127         $overdueforbranch{'overdueLevel'} = 1;
128     }
129
130     if ( $num->{'notify_level'} eq '2' ) {
131         $overdueforbranch{'overdue2'}     = 1;
132         $overdueforbranch{'overdueLevel'} = 2;
133     }
134
135     if ( $num->{'notify_level'} eq '3' ) {
136         $overdueforbranch{'overdue3'}     = 1;
137         $overdueforbranch{'overdueLevel'} = 3;
138     }
139     $overdueforbranch{'notify_id'} = $num->{'notify_id'};
140
141     push( @overduesloop, \%overdueforbranch );
142 }
143
144 # initiate the templates for the overdueloop
145 $template->param(
146     overduesloop => \@overduesloop,
147     show_date    => format_date(C4::Dates->today('iso')),
148     location     => $location,
149 );
150
151 output_html_with_http_headers $input, $cookie, $template->output;