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