4 # This file is part of Koha.
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
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.
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
24 use C4::Dates qw/format_date/;
25 use C4::Overdues; # AddNotifyLine
29 use Date::Calc qw/Today Today_and_Now Now/;
31 =head1 branchoverdues.pl
33 this module is a new interface, allow to the librarian to check all items on overdues (based on the acountlines type 'FU' )
34 this interface is filtered by branches (automatically), and by location (optional) ....
35 all informations are stocked in the notifys BDD
37 FIXME for this time, we have only four methods to notify :
38 - mail : work with a batch programm
39 - letter : for us, the letters are generated by an open-office program
40 - phone : Simple method, when the method 'phone' is selected, we consider, that the borrower as been notified, and the notify send date is implemented
41 - considered lost : for us if the document is on the third overduelevel,
43 FIXME the methods are actually hardcoded for the levels : (maybe can be improved by a new possibility in overduerule)
45 level 1 : three methods are possible : - mail, letter, phone
46 level 2 : only one method is possible : - letter
47 level 3 : only methode is possible : - Considered Lost
49 the documents displayed on this interface, are checked on three points
50 - 1) the document must be on accountlines (Type 'FU')
51 - 2) item issues is not returned
52 - 3) this item as not been already notify
57 my $dbh = C4::Context->dbh;
59 my $theme = $input->param('theme'); # only used if allowthemeoverride is set
61 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
63 template_name => "circ/branchoverdues.tmpl",
67 flagsrequired => { circulate => 1 },
72 my $default = C4::Context->userenv->{'branch'};
75 my ( $year, $month, $day ) = &Today;
76 my $todaysdate = join "-", ( $year, $month, $day );
78 # Deal with the vars recept from the template
79 my $borrowernumber = $input->param('borrowernumber');
80 my $itemnumber = $input->param('itemnumber');
81 my $method = $input->param('method');
82 my $overduelevel = $input->param('overduelevel');
83 my $notifyId = $input->param('notifyId');
84 my $location = $input->param('location');
86 # now create the line in bdd (notifys)
87 if ( $input->param('action') eq 'add' ) {
89 AddNotifyLine( $borrowernumber, $itemnumber, $overduelevel, $method,
92 elsif ( $input->param('action') eq 'remove' ) {
93 my $notify_date = $input->param('notify_date');
95 RemoveNotifyLine( $borrowernumber, $itemnumber, $notify_date );
99 my @todayoverduesloop;
102 my @getoverdues = GetOverduesForBranch( $default, $location );
104 $debug and warn "HERE : $default / $location" . Dumper(@getoverdues);
105 # search for location authorised value
106 my ($tag,$subfield) = GetMarcFromKohaField('items.location','');
107 my $tagslib = &GetMarcStructure(1,'');
108 if ($tagslib->{$tag}->{$subfield}->{authorised_value}) {
109 my $values= GetAuthorisedValues($tagslib->{$tag}->{$subfield}->{authorised_value});
110 $template->param(locationsloop => $values);
113 foreach my $num (@getoverdues) {
115 my %overdueforbranch;
116 $overdueforbranch{'date_due'} = format_date( $num->{'date_due'} );
117 $overdueforbranch{'title'} = $num->{'title'};
118 $overdueforbranch{'description'} = $num->{'description'};
119 $overdueforbranch{'barcode'} = $num->{'barcode'};
120 $overdueforbranch{'biblionumber'} = $num->{'biblionumber'};
121 $overdueforbranch{'borrowersurname'} = $num->{'surname'};
122 $overdueforbranch{'borrowerfirstname'} = $num->{'firstname'};
123 $overdueforbranch{'borrowerphone'} = $num->{'phone'};
124 $overdueforbranch{'borroweremail'} = $num->{'email'};
125 $overdueforbranch{'itemcallnumber'} = $num->{'itemcallnumber'};
126 $overdueforbranch{'borrowernumber'} = $num->{'borrowernumber'};
127 $overdueforbranch{'itemnumber'} = $num->{'itemnumber'};
129 # now we add on the template, the differents values of notify_level
130 if ( $num->{'notify_level'} eq '1' ) {
131 $overdueforbranch{'overdue1'} = 1;
132 $overdueforbranch{'overdueLevel'} = 1;
135 if ( $num->{'notify_level'} eq '2' ) {
136 $overdueforbranch{'overdue2'} = 1;
137 $overdueforbranch{'overdueLevel'} = 2;
140 if ( $num->{'notify_level'} eq '3' ) {
141 $overdueforbranch{'overdue3'} = 1;
142 $overdueforbranch{'overdueLevel'} = 3;
144 $overdueforbranch{'notify_id'} = $num->{'notify_id'};
146 push( @overduesloop, \%overdueforbranch );
149 # initiate the templates for the overdueloop
151 overduesloop => \@overduesloop,
152 show_date => format_date($todaysdate),
153 location => $location,
156 output_html_with_http_headers $input, $cookie, $template->output;