Lines 77-89
BEGIN {
Link Here
|
77 |
&ReNewSubscription &GetLateOrMissingIssues |
77 |
&ReNewSubscription &GetLateOrMissingIssues |
78 |
&GetSerialInformation &AddItem2Serial |
78 |
&GetSerialInformation &AddItem2Serial |
79 |
&PrepareSerialsData &GetNextExpected &ModNextExpected |
79 |
&PrepareSerialsData &GetNextExpected &ModNextExpected |
|
|
80 |
&GetSerial &GetSerialItemnumber |
80 |
|
81 |
|
81 |
&UpdateClaimdateIssues |
82 |
&UpdateClaimdateIssues |
82 |
&GetSuppliersWithLateIssues &getsupplierbyserialid |
83 |
&GetSuppliersWithLateIssues &getsupplierbyserialid |
83 |
&GetDistributedTo &SetDistributedTo |
84 |
&GetDistributedTo &SetDistributedTo |
84 |
&getroutinglist &delroutingmember &addroutingmember |
85 |
&updateClaim |
85 |
&reorder_members |
|
|
86 |
&check_routing &updateClaim |
87 |
&CountIssues |
86 |
&CountIssues |
88 |
HasItems |
87 |
HasItems |
89 |
&GetSubscriptionsFromBorrower |
88 |
&GetSubscriptionsFromBorrower |
Lines 164-169
sub GetSubscriptionHistoryFromSubscriptionId {
Link Here
|
164 |
return $results; |
163 |
return $results; |
165 |
} |
164 |
} |
166 |
|
165 |
|
|
|
166 |
=head2 GetSerial |
167 |
|
168 |
my $serial = &GetSerial($serialid); |
169 |
|
170 |
This sub returns serial informations (ie. in serial table) for given $serialid |
171 |
It returns a hashref where each key is a sql column. |
172 |
|
173 |
=cut |
174 |
|
175 |
sub GetSerial { |
176 |
my ($serialid) = @_; |
177 |
|
178 |
return unless $serialid; |
179 |
|
180 |
my $dbh = C4::Context->dbh; |
181 |
my $query = qq{ |
182 |
SELECT * |
183 |
FROM serial |
184 |
WHERE serialid = ? |
185 |
}; |
186 |
my $sth = $dbh->prepare($query); |
187 |
$sth->execute($serialid); |
188 |
return $sth->fetchrow_hashref; |
189 |
} |
190 |
|
191 |
=head2 GetSerialItemnumber |
192 |
|
193 |
my $itemnumber = GetSerialItemnumber($serialid); |
194 |
|
195 |
Returns the itemnumber associated to $serialid or undef if there is no item. |
196 |
|
197 |
=cut |
198 |
|
199 |
sub GetSerialItemnumber { |
200 |
my ($serialid) = @_; |
201 |
|
202 |
return unless $serialid; |
203 |
my $itemnumber; |
204 |
|
205 |
my $dbh = C4::Context->dbh; |
206 |
my $query = qq{ |
207 |
SELECT itemnumber |
208 |
FROM serialitems |
209 |
WHERE serialid = ? |
210 |
}; |
211 |
my $sth = $dbh->prepare($query); |
212 |
my $rv = $sth->execute($serialid); |
213 |
if ($rv) { |
214 |
my $result = $sth->fetchrow_hashref; |
215 |
$itemnumber = $result->{itemnumber}; |
216 |
} |
217 |
return $itemnumber; |
218 |
} |
219 |
|
167 |
=head2 GetSerialStatusFromSerialId |
220 |
=head2 GetSerialStatusFromSerialId |
168 |
|
221 |
|
169 |
$sth = GetSerialStatusFromSerialId(); |
222 |
$sth = GetSerialStatusFromSerialId(); |
Lines 702-708
sub GetSerials {
Link Here
|
702 |
my @serials; |
755 |
my @serials; |
703 |
my $statuses = join( ',', ( ARRIVED, MISSING_STATUSES, NOT_ISSUED ) ); |
756 |
my $statuses = join( ',', ( ARRIVED, MISSING_STATUSES, NOT_ISSUED ) ); |
704 |
my $query = "SELECT serialid,serialseq, status, publisheddate, |
757 |
my $query = "SELECT serialid,serialseq, status, publisheddate, |
705 |
publisheddatetext, planneddate,notes, routingnotes |
758 |
publisheddatetext, planneddate, notes |
706 |
FROM serial |
759 |
FROM serial |
707 |
WHERE subscriptionid = ? AND status NOT IN ( $statuses ) |
760 |
WHERE subscriptionid = ? AND status NOT IN ( $statuses ) |
708 |
ORDER BY IF(publisheddate<>'0000-00-00',publisheddate,planneddate) DESC"; |
761 |
ORDER BY IF(publisheddate<>'0000-00-00',publisheddate,planneddate) DESC"; |
Lines 723-729
sub GetSerials {
Link Here
|
723 |
|
776 |
|
724 |
# OK, now add the last 5 issues arrives/missing |
777 |
# OK, now add the last 5 issues arrives/missing |
725 |
$query = "SELECT serialid,serialseq, status, planneddate, publisheddate, |
778 |
$query = "SELECT serialid,serialseq, status, planneddate, publisheddate, |
726 |
publisheddatetext, notes, routingnotes |
779 |
publisheddatetext, notes |
727 |
FROM serial |
780 |
FROM serial |
728 |
WHERE subscriptionid = ? |
781 |
WHERE subscriptionid = ? |
729 |
AND status IN ( $statuses ) |
782 |
AND status IN ( $statuses ) |
Lines 773-779
sub GetSerials2 {
Link Here
|
773 |
my $dbh = C4::Context->dbh; |
826 |
my $dbh = C4::Context->dbh; |
774 |
my $query = qq| |
827 |
my $query = qq| |
775 |
SELECT serialid,serialseq, status, planneddate, publisheddate, |
828 |
SELECT serialid,serialseq, status, planneddate, publisheddate, |
776 |
publisheddatetext, notes, routingnotes |
829 |
publisheddatetext, notes |
777 |
FROM serial |
830 |
FROM serial |
778 |
WHERE subscriptionid=$subscription AND status IN ($statuses_string) |
831 |
WHERE subscriptionid=$subscription AND status IN ($statuses_string) |
779 |
ORDER BY publisheddate,serialid DESC |
832 |
ORDER BY publisheddate,serialid DESC |
Lines 1933-2093
sub getsupplierbyserialid {
Link Here
|
1933 |
return $result; |
1986 |
return $result; |
1934 |
} |
1987 |
} |
1935 |
|
1988 |
|
1936 |
=head2 check_routing |
|
|
1937 |
|
1938 |
$result = &check_routing($subscriptionid) |
1939 |
|
1940 |
this function checks to see if a serial has a routing list and returns the count of routingid |
1941 |
used to show either an 'add' or 'edit' link |
1942 |
|
1943 |
=cut |
1944 |
|
1945 |
sub check_routing { |
1946 |
my ($subscriptionid) = @_; |
1947 |
|
1948 |
return unless ($subscriptionid); |
1949 |
|
1950 |
my $dbh = C4::Context->dbh; |
1951 |
my $sth = $dbh->prepare( |
1952 |
"SELECT count(routingid) routingids FROM subscription LEFT JOIN subscriptionroutinglist |
1953 |
ON subscription.subscriptionid = subscriptionroutinglist.subscriptionid |
1954 |
WHERE subscription.subscriptionid = ? ORDER BY ranking ASC |
1955 |
" |
1956 |
); |
1957 |
$sth->execute($subscriptionid); |
1958 |
my $line = $sth->fetchrow_hashref; |
1959 |
my $result = $line->{'routingids'}; |
1960 |
return $result; |
1961 |
} |
1962 |
|
1963 |
=head2 addroutingmember |
1964 |
|
1965 |
addroutingmember($borrowernumber,$subscriptionid) |
1966 |
|
1967 |
this function takes a borrowernumber and subscriptionid and adds the member to the |
1968 |
routing list for that serial subscription and gives them a rank on the list |
1969 |
of either 1 or highest current rank + 1 |
1970 |
|
1971 |
=cut |
1972 |
|
1973 |
sub addroutingmember { |
1974 |
my ( $borrowernumber, $subscriptionid ) = @_; |
1975 |
|
1976 |
return unless ($borrowernumber and $subscriptionid); |
1977 |
|
1978 |
my $rank; |
1979 |
my $dbh = C4::Context->dbh; |
1980 |
my $sth = $dbh->prepare( "SELECT max(ranking) rank FROM subscriptionroutinglist WHERE subscriptionid = ?" ); |
1981 |
$sth->execute($subscriptionid); |
1982 |
while ( my $line = $sth->fetchrow_hashref ) { |
1983 |
if ( $line->{'rank'} > 0 ) { |
1984 |
$rank = $line->{'rank'} + 1; |
1985 |
} else { |
1986 |
$rank = 1; |
1987 |
} |
1988 |
} |
1989 |
$sth = $dbh->prepare( "INSERT INTO subscriptionroutinglist (subscriptionid,borrowernumber,ranking) VALUES (?,?,?)" ); |
1990 |
$sth->execute( $subscriptionid, $borrowernumber, $rank ); |
1991 |
} |
1992 |
|
1993 |
=head2 reorder_members |
1994 |
|
1995 |
reorder_members($subscriptionid,$routingid,$rank) |
1996 |
|
1997 |
this function is used to reorder the routing list |
1998 |
|
1999 |
it takes the routingid of the member one wants to re-rank and the rank it is to move to |
2000 |
- it gets all members on list puts their routingid's into an array |
2001 |
- removes the one in the array that is $routingid |
2002 |
- then reinjects $routingid at point indicated by $rank |
2003 |
- then update the database with the routingids in the new order |
2004 |
|
2005 |
=cut |
2006 |
|
2007 |
sub reorder_members { |
2008 |
my ( $subscriptionid, $routingid, $rank ) = @_; |
2009 |
my $dbh = C4::Context->dbh; |
2010 |
my $sth = $dbh->prepare( "SELECT * FROM subscriptionroutinglist WHERE subscriptionid = ? ORDER BY ranking ASC" ); |
2011 |
$sth->execute($subscriptionid); |
2012 |
my @result; |
2013 |
while ( my $line = $sth->fetchrow_hashref ) { |
2014 |
push( @result, $line->{'routingid'} ); |
2015 |
} |
2016 |
|
2017 |
# To find the matching index |
2018 |
my $i; |
2019 |
my $key = -1; # to allow for 0 being a valid response |
2020 |
for ( $i = 0 ; $i < @result ; $i++ ) { |
2021 |
if ( $routingid == $result[$i] ) { |
2022 |
$key = $i; # save the index |
2023 |
last; |
2024 |
} |
2025 |
} |
2026 |
|
2027 |
# if index exists in array then move it to new position |
2028 |
if ( $key > -1 && $rank > 0 ) { |
2029 |
my $new_rank = $rank - 1; # $new_rank is what you want the new index to be in the array |
2030 |
my $moving_item = splice( @result, $key, 1 ); |
2031 |
splice( @result, $new_rank, 0, $moving_item ); |
2032 |
} |
2033 |
for ( my $j = 0 ; $j < @result ; $j++ ) { |
2034 |
my $sth = $dbh->prepare( "UPDATE subscriptionroutinglist SET ranking = '" . ( $j + 1 ) . "' WHERE routingid = '" . $result[$j] . "'" ); |
2035 |
$sth->execute; |
2036 |
} |
2037 |
return; |
2038 |
} |
2039 |
|
2040 |
=head2 delroutingmember |
2041 |
|
2042 |
delroutingmember($routingid,$subscriptionid) |
2043 |
|
2044 |
this function either deletes one member from routing list if $routingid exists otherwise |
2045 |
deletes all members from the routing list |
2046 |
|
2047 |
=cut |
2048 |
|
2049 |
sub delroutingmember { |
2050 |
|
2051 |
# if $routingid exists then deletes that row otherwise deletes all with $subscriptionid |
2052 |
my ( $routingid, $subscriptionid ) = @_; |
2053 |
my $dbh = C4::Context->dbh; |
2054 |
if ($routingid) { |
2055 |
my $sth = $dbh->prepare("DELETE FROM subscriptionroutinglist WHERE routingid = ?"); |
2056 |
$sth->execute($routingid); |
2057 |
reorder_members( $subscriptionid, $routingid ); |
2058 |
} else { |
2059 |
my $sth = $dbh->prepare("DELETE FROM subscriptionroutinglist WHERE subscriptionid = ?"); |
2060 |
$sth->execute($subscriptionid); |
2061 |
} |
2062 |
return; |
2063 |
} |
2064 |
|
2065 |
=head2 getroutinglist |
2066 |
|
2067 |
@routinglist = getroutinglist($subscriptionid) |
2068 |
|
2069 |
this gets the info from the subscriptionroutinglist for $subscriptionid |
2070 |
|
2071 |
return : |
2072 |
the routinglist as an array. Each element of the array contains a hash_ref containing |
2073 |
routingid - a unique id, borrowernumber, ranking, and biblionumber of subscription |
2074 |
|
2075 |
=cut |
2076 |
|
2077 |
sub getroutinglist { |
2078 |
my ($subscriptionid) = @_; |
2079 |
my $dbh = C4::Context->dbh; |
2080 |
my $sth = $dbh->prepare( |
2081 |
'SELECT routingid, borrowernumber, ranking, biblionumber |
2082 |
FROM subscription |
2083 |
JOIN subscriptionroutinglist ON subscription.subscriptionid = subscriptionroutinglist.subscriptionid |
2084 |
WHERE subscription.subscriptionid = ? ORDER BY ranking ASC' |
2085 |
); |
2086 |
$sth->execute($subscriptionid); |
2087 |
my $routinglist = $sth->fetchall_arrayref({}); |
2088 |
return @{$routinglist}; |
2089 |
} |
2090 |
|
2091 |
=head2 countissuesfrom |
1989 |
=head2 countissuesfrom |
2092 |
|
1990 |
|
2093 |
$result = countissuesfrom($subscriptionid,$startdate) |
1991 |
$result = countissuesfrom($subscriptionid,$startdate) |
Lines 2225-2245
sub GetSubscriptionsFromBorrower {
Link Here
|
2225 |
my ($borrowernumber) = @_; |
2123 |
my ($borrowernumber) = @_; |
2226 |
my $dbh = C4::Context->dbh; |
2124 |
my $dbh = C4::Context->dbh; |
2227 |
my $sth = $dbh->prepare( |
2125 |
my $sth = $dbh->prepare( |
2228 |
"SELECT subscription.subscriptionid, biblio.title |
2126 |
"SELECT subscriptionroutinglist.*, biblio.title AS bibliotitle |
2229 |
FROM subscription |
2127 |
FROM subscriptionroutinglist |
|
|
2128 |
JOIN subscriptionrouting ON (subscriptionroutinglist.routinglistid = subscriptionrouting.routinglistid) |
2129 |
JOIN subscription ON (subscriptionroutinglist.subscriptionid = subscription.subscriptionid) |
2230 |
JOIN biblio ON biblio.biblionumber = subscription.biblionumber |
2130 |
JOIN biblio ON biblio.biblionumber = subscription.biblionumber |
2231 |
JOIN subscriptionroutinglist USING (subscriptionid) |
2131 |
WHERE subscriptionrouting.borrowernumber = ? ORDER BY title ASC |
2232 |
WHERE subscriptionroutinglist.borrowernumber = ? ORDER BY title ASC |
|
|
2233 |
" |
2132 |
" |
2234 |
); |
2133 |
); |
2235 |
$sth->execute($borrowernumber); |
2134 |
$sth->execute($borrowernumber); |
2236 |
my @routinglist; |
2135 |
my $routinglists = $sth->fetchall_arrayref({}); |
2237 |
my $count = 0; |
2136 |
return $routinglists ? @$routinglists : (); |
2238 |
while ( my $line = $sth->fetchrow_hashref ) { |
|
|
2239 |
$count++; |
2240 |
push( @routinglist, $line ); |
2241 |
} |
2242 |
return ( $count, @routinglist ); |
2243 |
} |
2137 |
} |
2244 |
|
2138 |
|
2245 |
|
2139 |
|