|
Lines 45-57
BEGIN {
Link Here
|
| 45 |
&ReNewSubscription &GetLateIssues &GetLateOrMissingIssues |
45 |
&ReNewSubscription &GetLateIssues &GetLateOrMissingIssues |
| 46 |
&GetSerialInformation &AddItem2Serial |
46 |
&GetSerialInformation &AddItem2Serial |
| 47 |
&PrepareSerialsData &GetNextExpected &ModNextExpected |
47 |
&PrepareSerialsData &GetNextExpected &ModNextExpected |
|
|
48 |
&GetSerial &GetSerialItemnumber |
| 48 |
|
49 |
|
| 49 |
&UpdateClaimdateIssues |
50 |
&UpdateClaimdateIssues |
| 50 |
&GetSuppliersWithLateIssues &getsupplierbyserialid |
51 |
&GetSuppliersWithLateIssues &getsupplierbyserialid |
| 51 |
&GetDistributedTo &SetDistributedTo |
52 |
&GetDistributedTo &SetDistributedTo |
| 52 |
&getroutinglist &delroutingmember &addroutingmember |
53 |
&updateClaim &removeMissingIssue |
| 53 |
&reorder_members |
|
|
| 54 |
&check_routing &updateClaim &removeMissingIssue |
| 55 |
&CountIssues |
54 |
&CountIssues |
| 56 |
HasItems |
55 |
HasItems |
| 57 |
&GetSubscriptionsFromBorrower |
56 |
&GetSubscriptionsFromBorrower |
|
Lines 178-183
sub GetSubscriptionHistoryFromSubscriptionId {
Link Here
|
| 178 |
return $dbh->prepare($query); |
177 |
return $dbh->prepare($query); |
| 179 |
} |
178 |
} |
| 180 |
|
179 |
|
|
|
180 |
=head2 GetSerial |
| 181 |
|
| 182 |
my $serial = &GetSerial($serialid); |
| 183 |
|
| 184 |
This sub returns serial informations (ie. in serial table) for given $serialid |
| 185 |
It returns a hashref where each key is a sql column. |
| 186 |
|
| 187 |
=cut |
| 188 |
|
| 189 |
sub GetSerial { |
| 190 |
my ($serialid) = @_; |
| 191 |
|
| 192 |
return unless $serialid; |
| 193 |
|
| 194 |
my $dbh = C4::Context->dbh; |
| 195 |
my $query = qq{ |
| 196 |
SELECT * |
| 197 |
FROM serial |
| 198 |
WHERE serialid = ? |
| 199 |
}; |
| 200 |
my $sth = $dbh->prepare($query); |
| 201 |
$sth->execute($serialid); |
| 202 |
return $sth->fetchrow_hashref; |
| 203 |
} |
| 204 |
|
| 205 |
=head2 GetSerialItemnumber |
| 206 |
|
| 207 |
my $itemnumber = GetSerialItemnumber($serialid); |
| 208 |
|
| 209 |
Returns the itemnumber associated to $serialid or undef if there is no item. |
| 210 |
|
| 211 |
=cut |
| 212 |
|
| 213 |
sub GetSerialItemnumber { |
| 214 |
my ($serialid) = @_; |
| 215 |
|
| 216 |
return unless $serialid; |
| 217 |
my $itemnumber; |
| 218 |
|
| 219 |
my $dbh = C4::Context->dbh; |
| 220 |
my $query = qq{ |
| 221 |
SELECT itemnumber |
| 222 |
FROM serialitems |
| 223 |
WHERE serialid = ? |
| 224 |
}; |
| 225 |
my $sth = $dbh->prepare($query); |
| 226 |
my $rv = $sth->execute($serialid); |
| 227 |
if ($rv) { |
| 228 |
my $result = $sth->fetchrow_hashref; |
| 229 |
$itemnumber = $result->{itemnumber}; |
| 230 |
} |
| 231 |
return $itemnumber; |
| 232 |
} |
| 233 |
|
| 181 |
=head2 GetSerialStatusFromSerialId |
234 |
=head2 GetSerialStatusFromSerialId |
| 182 |
|
235 |
|
| 183 |
$sth = GetSerialStatusFromSerialId(); |
236 |
$sth = GetSerialStatusFromSerialId(); |
|
Lines 1991-2145
sub getsupplierbyserialid {
Link Here
|
| 1991 |
return $result; |
2044 |
return $result; |
| 1992 |
} |
2045 |
} |
| 1993 |
|
2046 |
|
| 1994 |
=head2 check_routing |
|
|
| 1995 |
|
| 1996 |
$result = &check_routing($subscriptionid) |
| 1997 |
|
| 1998 |
this function checks to see if a serial has a routing list and returns the count of routingid |
| 1999 |
used to show either an 'add' or 'edit' link |
| 2000 |
|
| 2001 |
=cut |
| 2002 |
|
| 2003 |
sub check_routing { |
| 2004 |
my ($subscriptionid) = @_; |
| 2005 |
my $dbh = C4::Context->dbh; |
| 2006 |
my $sth = $dbh->prepare( |
| 2007 |
"SELECT count(routingid) routingids FROM subscription LEFT JOIN subscriptionroutinglist |
| 2008 |
ON subscription.subscriptionid = subscriptionroutinglist.subscriptionid |
| 2009 |
WHERE subscription.subscriptionid = ? ORDER BY ranking ASC |
| 2010 |
" |
| 2011 |
); |
| 2012 |
$sth->execute($subscriptionid); |
| 2013 |
my $line = $sth->fetchrow_hashref; |
| 2014 |
my $result = $line->{'routingids'}; |
| 2015 |
return $result; |
| 2016 |
} |
| 2017 |
|
| 2018 |
=head2 addroutingmember |
| 2019 |
|
| 2020 |
addroutingmember($borrowernumber,$subscriptionid) |
| 2021 |
|
| 2022 |
this function takes a borrowernumber and subscriptionid and adds the member to the |
| 2023 |
routing list for that serial subscription and gives them a rank on the list |
| 2024 |
of either 1 or highest current rank + 1 |
| 2025 |
|
| 2026 |
=cut |
| 2027 |
|
| 2028 |
sub addroutingmember { |
| 2029 |
my ( $borrowernumber, $subscriptionid ) = @_; |
| 2030 |
my $rank; |
| 2031 |
my $dbh = C4::Context->dbh; |
| 2032 |
my $sth = $dbh->prepare( "SELECT max(ranking) rank FROM subscriptionroutinglist WHERE subscriptionid = ?" ); |
| 2033 |
$sth->execute($subscriptionid); |
| 2034 |
while ( my $line = $sth->fetchrow_hashref ) { |
| 2035 |
if ( $line->{'rank'} > 0 ) { |
| 2036 |
$rank = $line->{'rank'} + 1; |
| 2037 |
} else { |
| 2038 |
$rank = 1; |
| 2039 |
} |
| 2040 |
} |
| 2041 |
$sth = $dbh->prepare( "INSERT INTO subscriptionroutinglist (subscriptionid,borrowernumber,ranking) VALUES (?,?,?)" ); |
| 2042 |
$sth->execute( $subscriptionid, $borrowernumber, $rank ); |
| 2043 |
} |
| 2044 |
|
| 2045 |
=head2 reorder_members |
| 2046 |
|
| 2047 |
reorder_members($subscriptionid,$routingid,$rank) |
| 2048 |
|
| 2049 |
this function is used to reorder the routing list |
| 2050 |
|
| 2051 |
it takes the routingid of the member one wants to re-rank and the rank it is to move to |
| 2052 |
- it gets all members on list puts their routingid's into an array |
| 2053 |
- removes the one in the array that is $routingid |
| 2054 |
- then reinjects $routingid at point indicated by $rank |
| 2055 |
- then update the database with the routingids in the new order |
| 2056 |
|
| 2057 |
=cut |
| 2058 |
|
| 2059 |
sub reorder_members { |
| 2060 |
my ( $subscriptionid, $routingid, $rank ) = @_; |
| 2061 |
my $dbh = C4::Context->dbh; |
| 2062 |
my $sth = $dbh->prepare( "SELECT * FROM subscriptionroutinglist WHERE subscriptionid = ? ORDER BY ranking ASC" ); |
| 2063 |
$sth->execute($subscriptionid); |
| 2064 |
my @result; |
| 2065 |
while ( my $line = $sth->fetchrow_hashref ) { |
| 2066 |
push( @result, $line->{'routingid'} ); |
| 2067 |
} |
| 2068 |
|
| 2069 |
# To find the matching index |
| 2070 |
my $i; |
| 2071 |
my $key = -1; # to allow for 0 being a valid response |
| 2072 |
for ( $i = 0 ; $i < @result ; $i++ ) { |
| 2073 |
if ( $routingid == $result[$i] ) { |
| 2074 |
$key = $i; # save the index |
| 2075 |
last; |
| 2076 |
} |
| 2077 |
} |
| 2078 |
|
| 2079 |
# if index exists in array then move it to new position |
| 2080 |
if ( $key > -1 && $rank > 0 ) { |
| 2081 |
my $new_rank = $rank - 1; # $new_rank is what you want the new index to be in the array |
| 2082 |
my $moving_item = splice( @result, $key, 1 ); |
| 2083 |
splice( @result, $new_rank, 0, $moving_item ); |
| 2084 |
} |
| 2085 |
for ( my $j = 0 ; $j < @result ; $j++ ) { |
| 2086 |
my $sth = $dbh->prepare( "UPDATE subscriptionroutinglist SET ranking = '" . ( $j + 1 ) . "' WHERE routingid = '" . $result[$j] . "'" ); |
| 2087 |
$sth->execute; |
| 2088 |
} |
| 2089 |
return; |
| 2090 |
} |
| 2091 |
|
| 2092 |
=head2 delroutingmember |
| 2093 |
|
| 2094 |
delroutingmember($routingid,$subscriptionid) |
| 2095 |
|
| 2096 |
this function either deletes one member from routing list if $routingid exists otherwise |
| 2097 |
deletes all members from the routing list |
| 2098 |
|
| 2099 |
=cut |
| 2100 |
|
| 2101 |
sub delroutingmember { |
| 2102 |
|
| 2103 |
# if $routingid exists then deletes that row otherwise deletes all with $subscriptionid |
| 2104 |
my ( $routingid, $subscriptionid ) = @_; |
| 2105 |
my $dbh = C4::Context->dbh; |
| 2106 |
if ($routingid) { |
| 2107 |
my $sth = $dbh->prepare("DELETE FROM subscriptionroutinglist WHERE routingid = ?"); |
| 2108 |
$sth->execute($routingid); |
| 2109 |
reorder_members( $subscriptionid, $routingid ); |
| 2110 |
} else { |
| 2111 |
my $sth = $dbh->prepare("DELETE FROM subscriptionroutinglist WHERE subscriptionid = ?"); |
| 2112 |
$sth->execute($subscriptionid); |
| 2113 |
} |
| 2114 |
return; |
| 2115 |
} |
| 2116 |
|
| 2117 |
=head2 getroutinglist |
| 2118 |
|
| 2119 |
@routinglist = getroutinglist($subscriptionid) |
| 2120 |
|
| 2121 |
this gets the info from the subscriptionroutinglist for $subscriptionid |
| 2122 |
|
| 2123 |
return : |
| 2124 |
the routinglist as an array. Each element of the array contains a hash_ref containing |
| 2125 |
routingid - a unique id, borrowernumber, ranking, and biblionumber of subscription |
| 2126 |
|
| 2127 |
=cut |
| 2128 |
|
| 2129 |
sub getroutinglist { |
| 2130 |
my ($subscriptionid) = @_; |
| 2131 |
my $dbh = C4::Context->dbh; |
| 2132 |
my $sth = $dbh->prepare( |
| 2133 |
'SELECT routingid, borrowernumber, ranking, biblionumber |
| 2134 |
FROM subscription |
| 2135 |
JOIN subscriptionroutinglist ON subscription.subscriptionid = subscriptionroutinglist.subscriptionid |
| 2136 |
WHERE subscription.subscriptionid = ? ORDER BY ranking ASC' |
| 2137 |
); |
| 2138 |
$sth->execute($subscriptionid); |
| 2139 |
my $routinglist = $sth->fetchall_arrayref({}); |
| 2140 |
return @{$routinglist}; |
| 2141 |
} |
| 2142 |
|
| 2143 |
=head2 countissuesfrom |
2047 |
=head2 countissuesfrom |
| 2144 |
|
2048 |
|
| 2145 |
$result = countissuesfrom($subscriptionid,$startdate) |
2049 |
$result = countissuesfrom($subscriptionid,$startdate) |