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