|
Lines 44-56
BEGIN {
Link Here
|
| 44 |
&ReNewSubscription &GetLateIssues &GetLateOrMissingIssues |
44 |
&ReNewSubscription &GetLateIssues &GetLateOrMissingIssues |
| 45 |
&GetSerialInformation &AddItem2Serial |
45 |
&GetSerialInformation &AddItem2Serial |
| 46 |
&PrepareSerialsData &GetNextExpected &ModNextExpected |
46 |
&PrepareSerialsData &GetNextExpected &ModNextExpected |
|
|
47 |
&GetSerial &GetSerialItemnumber |
| 47 |
|
48 |
|
| 48 |
&UpdateClaimdateIssues |
49 |
&UpdateClaimdateIssues |
| 49 |
&GetSuppliersWithLateIssues &getsupplierbyserialid |
50 |
&GetSuppliersWithLateIssues &getsupplierbyserialid |
| 50 |
&GetDistributedTo &SetDistributedTo |
51 |
&GetDistributedTo &SetDistributedTo |
| 51 |
&getroutinglist &delroutingmember &addroutingmember |
52 |
&updateClaim &removeMissingIssue |
| 52 |
&reorder_members |
|
|
| 53 |
&check_routing &updateClaim &removeMissingIssue |
| 54 |
&CountIssues |
53 |
&CountIssues |
| 55 |
HasItems |
54 |
HasItems |
| 56 |
|
55 |
|
|
Lines 168-173
sub GetSubscriptionHistoryFromSubscriptionId() {
Link Here
|
| 168 |
return $dbh->prepare($query); |
167 |
return $dbh->prepare($query); |
| 169 |
} |
168 |
} |
| 170 |
|
169 |
|
|
|
170 |
=head2 GetSerial |
| 171 |
|
| 172 |
my $serial = &GetSerial($serialid); |
| 173 |
|
| 174 |
This sub returns serial informations (ie. in serial table) for given $serialid |
| 175 |
It returns a hashref where each key is a sql column. |
| 176 |
|
| 177 |
=cut |
| 178 |
|
| 179 |
sub GetSerial { |
| 180 |
my ($serialid) = @_; |
| 181 |
|
| 182 |
return unless $serialid; |
| 183 |
|
| 184 |
my $dbh = C4::Context->dbh; |
| 185 |
my $query = qq{ |
| 186 |
SELECT * |
| 187 |
FROM serial |
| 188 |
WHERE serialid = ? |
| 189 |
}; |
| 190 |
my $sth = $dbh->prepare($query); |
| 191 |
$sth->execute($serialid); |
| 192 |
return $sth->fetchrow_hashref; |
| 193 |
} |
| 194 |
|
| 195 |
=head2 GetSerialItemnumber |
| 196 |
|
| 197 |
my $itemnumber = GetSerialItemnumber($serialid); |
| 198 |
|
| 199 |
Returns the itemnumber associated to $serialid or undef if there is no item. |
| 200 |
|
| 201 |
=cut |
| 202 |
|
| 203 |
sub GetSerialItemnumber { |
| 204 |
my ($serialid) = @_; |
| 205 |
|
| 206 |
return unless $serialid; |
| 207 |
my $itemnumber; |
| 208 |
|
| 209 |
my $dbh = C4::Context->dbh; |
| 210 |
my $query = qq{ |
| 211 |
SELECT itemnumber |
| 212 |
FROM serialitems |
| 213 |
WHERE serialid = ? |
| 214 |
}; |
| 215 |
my $sth = $dbh->prepare($query); |
| 216 |
my $rv = $sth->execute($serialid); |
| 217 |
if ($rv) { |
| 218 |
my $result = $sth->fetchrow_hashref; |
| 219 |
$itemnumber = $result->{itemnumber}; |
| 220 |
} |
| 221 |
return $itemnumber; |
| 222 |
} |
| 223 |
|
| 171 |
=head2 GetSerialStatusFromSerialId |
224 |
=head2 GetSerialStatusFromSerialId |
| 172 |
|
225 |
|
| 173 |
$sth = GetSerialStatusFromSerialId(); |
226 |
$sth = GetSerialStatusFromSerialId(); |
|
Lines 1888-2042
sub getsupplierbyserialid {
Link Here
|
| 1888 |
return $result; |
1941 |
return $result; |
| 1889 |
} |
1942 |
} |
| 1890 |
|
1943 |
|
| 1891 |
=head2 check_routing |
|
|
| 1892 |
|
| 1893 |
$result = &check_routing($subscriptionid) |
| 1894 |
|
| 1895 |
this function checks to see if a serial has a routing list and returns the count of routingid |
| 1896 |
used to show either an 'add' or 'edit' link |
| 1897 |
|
| 1898 |
=cut |
| 1899 |
|
| 1900 |
sub check_routing { |
| 1901 |
my ($subscriptionid) = @_; |
| 1902 |
my $dbh = C4::Context->dbh; |
| 1903 |
my $sth = $dbh->prepare( |
| 1904 |
"SELECT count(routingid) routingids FROM subscription LEFT JOIN subscriptionroutinglist |
| 1905 |
ON subscription.subscriptionid = subscriptionroutinglist.subscriptionid |
| 1906 |
WHERE subscription.subscriptionid = ? ORDER BY ranking ASC |
| 1907 |
" |
| 1908 |
); |
| 1909 |
$sth->execute($subscriptionid); |
| 1910 |
my $line = $sth->fetchrow_hashref; |
| 1911 |
my $result = $line->{'routingids'}; |
| 1912 |
return $result; |
| 1913 |
} |
| 1914 |
|
| 1915 |
=head2 addroutingmember |
| 1916 |
|
| 1917 |
addroutingmember($borrowernumber,$subscriptionid) |
| 1918 |
|
| 1919 |
this function takes a borrowernumber and subscriptionid and adds the member to the |
| 1920 |
routing list for that serial subscription and gives them a rank on the list |
| 1921 |
of either 1 or highest current rank + 1 |
| 1922 |
|
| 1923 |
=cut |
| 1924 |
|
| 1925 |
sub addroutingmember { |
| 1926 |
my ( $borrowernumber, $subscriptionid ) = @_; |
| 1927 |
my $rank; |
| 1928 |
my $dbh = C4::Context->dbh; |
| 1929 |
my $sth = $dbh->prepare( "SELECT max(ranking) rank FROM subscriptionroutinglist WHERE subscriptionid = ?" ); |
| 1930 |
$sth->execute($subscriptionid); |
| 1931 |
while ( my $line = $sth->fetchrow_hashref ) { |
| 1932 |
if ( $line->{'rank'} > 0 ) { |
| 1933 |
$rank = $line->{'rank'} + 1; |
| 1934 |
} else { |
| 1935 |
$rank = 1; |
| 1936 |
} |
| 1937 |
} |
| 1938 |
$sth = $dbh->prepare( "INSERT INTO subscriptionroutinglist (subscriptionid,borrowernumber,ranking) VALUES (?,?,?)" ); |
| 1939 |
$sth->execute( $subscriptionid, $borrowernumber, $rank ); |
| 1940 |
} |
| 1941 |
|
| 1942 |
=head2 reorder_members |
| 1943 |
|
| 1944 |
reorder_members($subscriptionid,$routingid,$rank) |
| 1945 |
|
| 1946 |
this function is used to reorder the routing list |
| 1947 |
|
| 1948 |
it takes the routingid of the member one wants to re-rank and the rank it is to move to |
| 1949 |
- it gets all members on list puts their routingid's into an array |
| 1950 |
- removes the one in the array that is $routingid |
| 1951 |
- then reinjects $routingid at point indicated by $rank |
| 1952 |
- then update the database with the routingids in the new order |
| 1953 |
|
| 1954 |
=cut |
| 1955 |
|
| 1956 |
sub reorder_members { |
| 1957 |
my ( $subscriptionid, $routingid, $rank ) = @_; |
| 1958 |
my $dbh = C4::Context->dbh; |
| 1959 |
my $sth = $dbh->prepare( "SELECT * FROM subscriptionroutinglist WHERE subscriptionid = ? ORDER BY ranking ASC" ); |
| 1960 |
$sth->execute($subscriptionid); |
| 1961 |
my @result; |
| 1962 |
while ( my $line = $sth->fetchrow_hashref ) { |
| 1963 |
push( @result, $line->{'routingid'} ); |
| 1964 |
} |
| 1965 |
|
| 1966 |
# To find the matching index |
| 1967 |
my $i; |
| 1968 |
my $key = -1; # to allow for 0 being a valid response |
| 1969 |
for ( $i = 0 ; $i < @result ; $i++ ) { |
| 1970 |
if ( $routingid == $result[$i] ) { |
| 1971 |
$key = $i; # save the index |
| 1972 |
last; |
| 1973 |
} |
| 1974 |
} |
| 1975 |
|
| 1976 |
# if index exists in array then move it to new position |
| 1977 |
if ( $key > -1 && $rank > 0 ) { |
| 1978 |
my $new_rank = $rank - 1; # $new_rank is what you want the new index to be in the array |
| 1979 |
my $moving_item = splice( @result, $key, 1 ); |
| 1980 |
splice( @result, $new_rank, 0, $moving_item ); |
| 1981 |
} |
| 1982 |
for ( my $j = 0 ; $j < @result ; $j++ ) { |
| 1983 |
my $sth = $dbh->prepare( "UPDATE subscriptionroutinglist SET ranking = '" . ( $j + 1 ) . "' WHERE routingid = '" . $result[$j] . "'" ); |
| 1984 |
$sth->execute; |
| 1985 |
} |
| 1986 |
return; |
| 1987 |
} |
| 1988 |
|
| 1989 |
=head2 delroutingmember |
| 1990 |
|
| 1991 |
delroutingmember($routingid,$subscriptionid) |
| 1992 |
|
| 1993 |
this function either deletes one member from routing list if $routingid exists otherwise |
| 1994 |
deletes all members from the routing list |
| 1995 |
|
| 1996 |
=cut |
| 1997 |
|
| 1998 |
sub delroutingmember { |
| 1999 |
|
| 2000 |
# if $routingid exists then deletes that row otherwise deletes all with $subscriptionid |
| 2001 |
my ( $routingid, $subscriptionid ) = @_; |
| 2002 |
my $dbh = C4::Context->dbh; |
| 2003 |
if ($routingid) { |
| 2004 |
my $sth = $dbh->prepare("DELETE FROM subscriptionroutinglist WHERE routingid = ?"); |
| 2005 |
$sth->execute($routingid); |
| 2006 |
reorder_members( $subscriptionid, $routingid ); |
| 2007 |
} else { |
| 2008 |
my $sth = $dbh->prepare("DELETE FROM subscriptionroutinglist WHERE subscriptionid = ?"); |
| 2009 |
$sth->execute($subscriptionid); |
| 2010 |
} |
| 2011 |
return; |
| 2012 |
} |
| 2013 |
|
| 2014 |
=head2 getroutinglist |
| 2015 |
|
| 2016 |
@routinglist = getroutinglist($subscriptionid) |
| 2017 |
|
| 2018 |
this gets the info from the subscriptionroutinglist for $subscriptionid |
| 2019 |
|
| 2020 |
return : |
| 2021 |
the routinglist as an array. Each element of the array contains a hash_ref containing |
| 2022 |
routingid - a unique id, borrowernumber, ranking, and biblionumber of subscription |
| 2023 |
|
| 2024 |
=cut |
| 2025 |
|
| 2026 |
sub getroutinglist { |
| 2027 |
my ($subscriptionid) = @_; |
| 2028 |
my $dbh = C4::Context->dbh; |
| 2029 |
my $sth = $dbh->prepare( |
| 2030 |
'SELECT routingid, borrowernumber, ranking, biblionumber |
| 2031 |
FROM subscription |
| 2032 |
JOIN subscriptionroutinglist ON subscription.subscriptionid = subscriptionroutinglist.subscriptionid |
| 2033 |
WHERE subscription.subscriptionid = ? ORDER BY ranking ASC' |
| 2034 |
); |
| 2035 |
$sth->execute($subscriptionid); |
| 2036 |
my $routinglist = $sth->fetchall_arrayref({}); |
| 2037 |
return @{$routinglist}; |
| 2038 |
} |
| 2039 |
|
| 2040 |
=head2 countissuesfrom |
1944 |
=head2 countissuesfrom |
| 2041 |
|
1945 |
|
| 2042 |
$result = countissuesfrom($subscriptionid,$startdate) |
1946 |
$result = countissuesfrom($subscriptionid,$startdate) |