|
Line 0
Link Here
|
|
|
1 |
package C4::Housebound; |
| 2 |
|
| 3 |
# Copyright 2011 Mark Gavillet |
| 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 |
| 17 |
# with Koha; if not, write to the Free Software Foundation, Inc., |
| 18 |
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 19 |
|
| 20 |
use strict; |
| 21 |
use warnings; |
| 22 |
use C4::Context; |
| 23 |
use parent qw(Exporter); |
| 24 |
|
| 25 |
our $VERSION = 3.02; |
| 26 |
our $debug = $ENV{DEBUG} || 0; |
| 27 |
our @EXPORT = qw( |
| 28 |
GetHouseboundDetails |
| 29 |
CreateHouseboundDetails |
| 30 |
UpdateHouseboundDetails |
| 31 |
GetCurrentHouseboundInstanceList |
| 32 |
GetHouseboundInstanceDetails |
| 33 |
UpdateHouseboundInstanceDetails |
| 34 |
CreateHouseboundInstanceDetails |
| 35 |
DeleteHouseboundInstanceDetails |
| 36 |
GetVolunteerNameAndID |
| 37 |
GetVolunteerList |
| 38 |
); |
| 39 |
|
| 40 |
=head1 NAME |
| 41 |
|
| 42 |
C4::Housebound - Perl Module containing functions for housebound patrons |
| 43 |
|
| 44 |
=head1 SYNOPSIS |
| 45 |
|
| 46 |
use C4::Housebound; |
| 47 |
|
| 48 |
=head1 DESCRIPTION |
| 49 |
|
| 50 |
This module contains routines for adding, modifying and deleting housebound details for patrons, and instances of item delivery by volunteers |
| 51 |
|
| 52 |
=head1 FUNCTIONS |
| 53 |
|
| 54 |
=over 2 |
| 55 |
|
| 56 |
=item GetHouseboundDetails |
| 57 |
|
| 58 |
($hbnumber, $day, $frequency, $borrowernumber, $Itype_quant, $Item_subject, $Item_authors, $referral, $notes) = &SearchMember($borrowernumber); |
| 59 |
|
| 60 |
=back |
| 61 |
|
| 62 |
Values returned |
| 63 |
$hbnumber - the id of the database record in table housebound |
| 64 |
$day - preferred day of the week for delivery |
| 65 |
$frequency - pattern of delivery (e.g. weeks 1/3, week 4, etc.) |
| 66 |
$borrowernumber - borrowernumber that is fed into the function, returned for convenience |
| 67 |
$Itype_quant - one or more values from the list of loanable Itypes (e.g. 2 BKS, 1 DVD, etc.) |
| 68 |
$Item_subject - one or more values defining subjects the borrower is interested in |
| 69 |
$Item_authors - one or more values defining authors the borrower is interested in |
| 70 |
$referral - person or organisation that referred this borrower |
| 71 |
$notes - freetext notes containing useful information about the patron (e.g. beware of the dog!) |
| 72 |
|
| 73 |
=cut |
| 74 |
|
| 75 |
sub GetHouseboundDetails { |
| 76 |
my ($borrowernumber) = @_; |
| 77 |
my $dbh = C4::Context->dbh; |
| 78 |
my $query; |
| 79 |
my $sth; |
| 80 |
if ($borrowernumber) { |
| 81 |
$sth = $dbh->prepare("select * from housebound where borrowernumber=?"); |
| 82 |
$sth->execute($borrowernumber); |
| 83 |
my $housebound = $sth->fetchrow_hashref; |
| 84 |
return $housebound; |
| 85 |
} |
| 86 |
return; |
| 87 |
} |
| 88 |
|
| 89 |
sub CreateHouseboundDetails { |
| 90 |
my ( $borrowernumber, $day, $frequency, $Itype_quant, $Item_subject, |
| 91 |
$Item_authors, $referral, $notes ) |
| 92 |
= @_; |
| 93 |
my $dbh = C4::Context->dbh; |
| 94 |
my $query; |
| 95 |
my $sth; |
| 96 |
if ($borrowernumber) { |
| 97 |
$sth = $dbh->prepare( |
| 98 |
"insert into housebound (day, frequency, borrowernumber, Itype_quant, Item_subject, Item_authors, referral, notes) values (?,?,?,?,?,?,?,?)" |
| 99 |
); |
| 100 |
$sth->execute( $day, $frequency, $borrowernumber, $Itype_quant, |
| 101 |
$Item_subject, $Item_authors, $referral, $notes ); |
| 102 |
} |
| 103 |
return; |
| 104 |
} |
| 105 |
|
| 106 |
sub UpdateHouseboundDetails { |
| 107 |
my ($hbnumber, $borrowernumber, $day, |
| 108 |
$frequency, $Itype_quant, $Item_subject, |
| 109 |
$Item_authors, $referral, $notes |
| 110 |
) = @_; |
| 111 |
my $dbh = C4::Context->dbh; |
| 112 |
my $query; |
| 113 |
my $sth; |
| 114 |
if ($hbnumber) { |
| 115 |
$sth = $dbh->prepare( |
| 116 |
"update housebound set day=?,frequency=?,borrowernumber=?,Itype_quant=?,Item_subject=?,Item_authors=?,referral=?,notes=? where hbnumber=?" |
| 117 |
); |
| 118 |
$sth->execute( |
| 119 |
$day, $frequency, $borrowernumber, |
| 120 |
$Itype_quant, $Item_subject, $Item_authors, |
| 121 |
$referral, $notes, $hbnumber |
| 122 |
); |
| 123 |
} |
| 124 |
return; |
| 125 |
} |
| 126 |
|
| 127 |
sub GetCurrentHouseboundInstanceList { |
| 128 |
my ($borrowernumber) = @_; |
| 129 |
my $dbh = C4::Context->dbh; |
| 130 |
my $query; |
| 131 |
my $sth; |
| 132 |
if ($borrowernumber) { |
| 133 |
|
| 134 |
#$sth = $dbh->prepare("select * from housebound_instance where borrowernumber=?"); |
| 135 |
$sth = $dbh->prepare( |
| 136 |
"SELECT housebound_instance . * , concat( volunteer.firstname, ' ', volunteer.surname ) AS vol, concat(chooser.firstname, ' ', chooser.surname) as cho, concat(deliverer.firstname, ' ', deliverer.surname) as del FROM housebound_instance left JOIN borrowers volunteer ON volunteer.borrowernumber = housebound_instance.volunteer left join borrowers chooser on chooser.borrowernumber = housebound_instance.chooser left join borrowers deliverer on deliverer.borrowernumber = housebound_instance.deliverer where housebound_instance.borrowernumber=? order by housebound_instance.dmy desc" |
| 137 |
); |
| 138 |
$sth->execute($borrowernumber); |
| 139 |
my $housebound_instances = $sth->fetchall_arrayref( {} ); |
| 140 |
return $housebound_instances; |
| 141 |
} |
| 142 |
return; |
| 143 |
} |
| 144 |
|
| 145 |
sub GetVolunteerNameAndID { |
| 146 |
my ($borrowernumber) = @_; |
| 147 |
my $dbh = C4::Context->dbh; |
| 148 |
my $query; |
| 149 |
my $sth; |
| 150 |
if ($borrowernumber) { |
| 151 |
$sth = $dbh->prepare( |
| 152 |
"select borrowernumber,title,firstname,surname from borrowers where borrowernumber=?" |
| 153 |
); |
| 154 |
$sth->execute($borrowernumber); |
| 155 |
my $volunteer = $sth->fetchrow_hashref; |
| 156 |
return $volunteer; |
| 157 |
} |
| 158 |
return; |
| 159 |
} |
| 160 |
|
| 161 |
sub GetVolunteerList { |
| 162 |
my $dbh = C4::Context->dbh; |
| 163 |
my $query; |
| 164 |
my $sth; |
| 165 |
$sth = $dbh->prepare( |
| 166 |
"SELECT borrowernumber as volbornumber, concat(title, ' ', firstname, ' ', surname) as fullname from borrowers where categorycode='VOL' order by surname, firstname asc" |
| 167 |
); |
| 168 |
$sth->execute(); |
| 169 |
my $volunteers = $sth->fetchall_arrayref( {} ); |
| 170 |
return $volunteers; |
| 171 |
} |
| 172 |
|
| 173 |
sub GetHouseboundInstanceDetails { |
| 174 |
my ($instanceid) = @_; |
| 175 |
my $dbh = C4::Context->dbh; |
| 176 |
my $query; |
| 177 |
my $sth; |
| 178 |
if ($instanceid) { |
| 179 |
$sth = |
| 180 |
$dbh->prepare("SELECT * from housebound_instance where instanceid=?"); |
| 181 |
$sth->execute($instanceid); |
| 182 |
my $instancedetails = $sth->fetchrow_hashref; |
| 183 |
return $instancedetails; |
| 184 |
} |
| 185 |
|
| 186 |
# return undef if no instanceid |
| 187 |
return; |
| 188 |
} |
| 189 |
|
| 190 |
sub UpdateHouseboundInstanceDetails { |
| 191 |
my ( $instanceid, $hbnumber, $dmy, $time, $borrowernumber, $volunteer, |
| 192 |
$chooser, $deliverer ) |
| 193 |
= @_; |
| 194 |
my $dbh = C4::Context->dbh; |
| 195 |
my $query; |
| 196 |
my $sth; |
| 197 |
if ($hbnumber) { |
| 198 |
$sth = $dbh->prepare( |
| 199 |
"update housebound_instance set hbnumber=?, dmy=?, time=?, borrowernumber=?, volunteer=?, chooser=?, deliverer=? where instanceid=?" |
| 200 |
); |
| 201 |
$sth->execute( $hbnumber, $dmy, $time, $borrowernumber, $volunteer, |
| 202 |
$chooser, $deliverer, $instanceid ); |
| 203 |
} |
| 204 |
return; |
| 205 |
} |
| 206 |
|
| 207 |
sub CreateHouseboundInstanceDetails { |
| 208 |
my ( $hbnumber, $dmy, $time, $borrowernumber, $volunteer, $chooser, |
| 209 |
$deliverer ) |
| 210 |
= @_; |
| 211 |
my $dbh = C4::Context->dbh; |
| 212 |
my $query; |
| 213 |
my $sth; |
| 214 |
if ($borrowernumber) { |
| 215 |
$sth = $dbh->prepare( |
| 216 |
"insert into housebound_instance (hbnumber, dmy, time, borrowernumber, volunteer, chooser, deliverer) values (?,?,?,?,?,?,?)" |
| 217 |
); |
| 218 |
$sth->execute( $hbnumber, $dmy, $time, $borrowernumber, $volunteer, |
| 219 |
$chooser, $deliverer ); |
| 220 |
} |
| 221 |
return; |
| 222 |
} |
| 223 |
|
| 224 |
sub DeleteHouseboundInstanceDetails { |
| 225 |
my ($instanceid) = @_; |
| 226 |
my $dbh = C4::Context->dbh; |
| 227 |
my $query; |
| 228 |
my $sth; |
| 229 |
if ($instanceid) { |
| 230 |
$sth = |
| 231 |
$dbh->prepare("delete from housebound_instance where instanceid=?"); |
| 232 |
$sth->execute($instanceid); |
| 233 |
} |
| 234 |
return; |
| 235 |
} |
| 236 |
|
| 237 |
1; |
| 238 |
|
| 239 |
__END__ |
| 240 |
|
| 241 |
=head1 AUTHOR |
| 242 |
|
| 243 |
Mark Gavillet |
| 244 |
|
| 245 |
=cut |