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