5 # This file is part of Koha.
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
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.
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
26 use C4::Overdues; # AddNotifyLine
31 use Date::Calc qw/Today Today_and_Now Now/;
33 =head1 branchoverdues.pl
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
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,
45 FIXME the methods are actually hardcoded for the levels : (maybe can be improved by a new possibility in overduerule)
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
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
59 my $dbh = C4::Context->dbh;
61 my $theme = $input->param('theme'); # only used if allowthemeoverride is set
63 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
65 template_name => "circ/branchoverdues.tmpl",
69 flagsrequired => { circulate => 1 },
74 my $default = C4::Context->userenv->{'branch'};
77 my ( $year, $month, $day ) = &Today;
78 my $todaysdate = join "-", ( $year, $month, $day );
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');
88 # now create the line in bdd (notifys)
89 if ( $input->param('action') eq 'add' ) {
91 AddNotifyLine( $borrowernumber, $itemnumber, $overduelevel, $method,
95 # possibility to remove notify line
96 if ( $input->param('action') eq 'remove' ) {
97 my $notify_date = $input->param('notify_date');
99 RemoveNotifyLine( $borrowernumber, $itemnumber, $notify_date );
103 my @todayoverduesloop;
106 my @getoverdues = GetOverduesForBranch( $default, $location );
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);
117 foreach my $num (@getoverdues) {
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'};
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;
139 if ( $num->{'notify_level'} eq '2' ) {
140 $overdueforbranch{'overdue2'} = 1;
141 $overdueforbranch{'overdueLevel'} = 2;
144 if ( $num->{'notify_level'} eq '3' ) {
145 $overdueforbranch{'overdue3'} = 1;
146 $overdueforbranch{'overdueLevel'} = 3;
148 $overdueforbranch{'notify_id'} = $num->{'notify_id'};
150 push( @overduesloop, \%overdueforbranch );
153 # initiate the templates for the overdueloop
155 overduesloop => \@overduesloop,
156 show_date => format_date($todaysdate),
157 location => $location,
160 output_html_with_http_headers $input, $cookie, $template->output;