|
Lines 51-63
BEGIN {
Link Here
|
| 51 |
&ReNewSubscription &GetLateOrMissingIssues |
51 |
&ReNewSubscription &GetLateOrMissingIssues |
| 52 |
&GetSerialInformation &AddItem2Serial |
52 |
&GetSerialInformation &AddItem2Serial |
| 53 |
&PrepareSerialsData &GetNextExpected &ModNextExpected |
53 |
&PrepareSerialsData &GetNextExpected &ModNextExpected |
|
|
54 |
&GetSerial &GetSerialItemnumber |
| 54 |
|
55 |
|
| 55 |
&UpdateClaimdateIssues |
56 |
&UpdateClaimdateIssues |
| 56 |
&GetSuppliersWithLateIssues &getsupplierbyserialid |
57 |
&GetSuppliersWithLateIssues &getsupplierbyserialid |
| 57 |
&GetDistributedTo &SetDistributedTo |
58 |
&GetDistributedTo &SetDistributedTo |
| 58 |
&getroutinglist &delroutingmember &addroutingmember |
59 |
&updateClaim &removeMissingIssue |
| 59 |
&reorder_members |
|
|
| 60 |
&check_routing &updateClaim &removeMissingIssue |
| 61 |
&CountIssues |
60 |
&CountIssues |
| 62 |
HasItems |
61 |
HasItems |
| 63 |
&GetSubscriptionsFromBorrower |
62 |
&GetSubscriptionsFromBorrower |
|
Lines 137-142
sub GetSubscriptionHistoryFromSubscriptionId {
Link Here
|
| 137 |
return $results; |
136 |
return $results; |
| 138 |
} |
137 |
} |
| 139 |
|
138 |
|
|
|
139 |
=head2 GetSerial |
| 140 |
|
| 141 |
my $serial = &GetSerial($serialid); |
| 142 |
|
| 143 |
This sub returns serial informations (ie. in serial table) for given $serialid |
| 144 |
It returns a hashref where each key is a sql column. |
| 145 |
|
| 146 |
=cut |
| 147 |
|
| 148 |
sub GetSerial { |
| 149 |
my ($serialid) = @_; |
| 150 |
|
| 151 |
return unless $serialid; |
| 152 |
|
| 153 |
my $dbh = C4::Context->dbh; |
| 154 |
my $query = qq{ |
| 155 |
SELECT * |
| 156 |
FROM serial |
| 157 |
WHERE serialid = ? |
| 158 |
}; |
| 159 |
my $sth = $dbh->prepare($query); |
| 160 |
$sth->execute($serialid); |
| 161 |
return $sth->fetchrow_hashref; |
| 162 |
} |
| 163 |
|
| 164 |
=head2 GetSerialItemnumber |
| 165 |
|
| 166 |
my $itemnumber = GetSerialItemnumber($serialid); |
| 167 |
|
| 168 |
Returns the itemnumber associated to $serialid or undef if there is no item. |
| 169 |
|
| 170 |
=cut |
| 171 |
|
| 172 |
sub GetSerialItemnumber { |
| 173 |
my ($serialid) = @_; |
| 174 |
|
| 175 |
return unless $serialid; |
| 176 |
my $itemnumber; |
| 177 |
|
| 178 |
my $dbh = C4::Context->dbh; |
| 179 |
my $query = qq{ |
| 180 |
SELECT itemnumber |
| 181 |
FROM serialitems |
| 182 |
WHERE serialid = ? |
| 183 |
}; |
| 184 |
my $sth = $dbh->prepare($query); |
| 185 |
my $rv = $sth->execute($serialid); |
| 186 |
if ($rv) { |
| 187 |
my $result = $sth->fetchrow_hashref; |
| 188 |
$itemnumber = $result->{itemnumber}; |
| 189 |
} |
| 190 |
return $itemnumber; |
| 191 |
} |
| 192 |
|
| 140 |
=head2 GetSerialStatusFromSerialId |
193 |
=head2 GetSerialStatusFromSerialId |
| 141 |
|
194 |
|
| 142 |
$sth = GetSerialStatusFromSerialId(); |
195 |
$sth = GetSerialStatusFromSerialId(); |
|
Lines 2077-2237
sub getsupplierbyserialid {
Link Here
|
| 2077 |
return $result; |
2130 |
return $result; |
| 2078 |
} |
2131 |
} |
| 2079 |
|
2132 |
|
| 2080 |
=head2 check_routing |
|
|
| 2081 |
|
| 2082 |
$result = &check_routing($subscriptionid) |
| 2083 |
|
| 2084 |
this function checks to see if a serial has a routing list and returns the count of routingid |
| 2085 |
used to show either an 'add' or 'edit' link |
| 2086 |
|
| 2087 |
=cut |
| 2088 |
|
| 2089 |
sub check_routing { |
| 2090 |
my ($subscriptionid) = @_; |
| 2091 |
|
| 2092 |
return unless ($subscriptionid); |
| 2093 |
|
| 2094 |
my $dbh = C4::Context->dbh; |
| 2095 |
my $sth = $dbh->prepare( |
| 2096 |
"SELECT count(routingid) routingids FROM subscription LEFT JOIN subscriptionroutinglist |
| 2097 |
ON subscription.subscriptionid = subscriptionroutinglist.subscriptionid |
| 2098 |
WHERE subscription.subscriptionid = ? ORDER BY ranking ASC |
| 2099 |
" |
| 2100 |
); |
| 2101 |
$sth->execute($subscriptionid); |
| 2102 |
my $line = $sth->fetchrow_hashref; |
| 2103 |
my $result = $line->{'routingids'}; |
| 2104 |
return $result; |
| 2105 |
} |
| 2106 |
|
| 2107 |
=head2 addroutingmember |
| 2108 |
|
| 2109 |
addroutingmember($borrowernumber,$subscriptionid) |
| 2110 |
|
| 2111 |
this function takes a borrowernumber and subscriptionid and adds the member to the |
| 2112 |
routing list for that serial subscription and gives them a rank on the list |
| 2113 |
of either 1 or highest current rank + 1 |
| 2114 |
|
| 2115 |
=cut |
| 2116 |
|
| 2117 |
sub addroutingmember { |
| 2118 |
my ( $borrowernumber, $subscriptionid ) = @_; |
| 2119 |
|
| 2120 |
return unless ($borrowernumber and $subscriptionid); |
| 2121 |
|
| 2122 |
my $rank; |
| 2123 |
my $dbh = C4::Context->dbh; |
| 2124 |
my $sth = $dbh->prepare( "SELECT max(ranking) rank FROM subscriptionroutinglist WHERE subscriptionid = ?" ); |
| 2125 |
$sth->execute($subscriptionid); |
| 2126 |
while ( my $line = $sth->fetchrow_hashref ) { |
| 2127 |
if ( $line->{'rank'} > 0 ) { |
| 2128 |
$rank = $line->{'rank'} + 1; |
| 2129 |
} else { |
| 2130 |
$rank = 1; |
| 2131 |
} |
| 2132 |
} |
| 2133 |
$sth = $dbh->prepare( "INSERT INTO subscriptionroutinglist (subscriptionid,borrowernumber,ranking) VALUES (?,?,?)" ); |
| 2134 |
$sth->execute( $subscriptionid, $borrowernumber, $rank ); |
| 2135 |
} |
| 2136 |
|
| 2137 |
=head2 reorder_members |
| 2138 |
|
| 2139 |
reorder_members($subscriptionid,$routingid,$rank) |
| 2140 |
|
| 2141 |
this function is used to reorder the routing list |
| 2142 |
|
| 2143 |
it takes the routingid of the member one wants to re-rank and the rank it is to move to |
| 2144 |
- it gets all members on list puts their routingid's into an array |
| 2145 |
- removes the one in the array that is $routingid |
| 2146 |
- then reinjects $routingid at point indicated by $rank |
| 2147 |
- then update the database with the routingids in the new order |
| 2148 |
|
| 2149 |
=cut |
| 2150 |
|
| 2151 |
sub reorder_members { |
| 2152 |
my ( $subscriptionid, $routingid, $rank ) = @_; |
| 2153 |
my $dbh = C4::Context->dbh; |
| 2154 |
my $sth = $dbh->prepare( "SELECT * FROM subscriptionroutinglist WHERE subscriptionid = ? ORDER BY ranking ASC" ); |
| 2155 |
$sth->execute($subscriptionid); |
| 2156 |
my @result; |
| 2157 |
while ( my $line = $sth->fetchrow_hashref ) { |
| 2158 |
push( @result, $line->{'routingid'} ); |
| 2159 |
} |
| 2160 |
|
| 2161 |
# To find the matching index |
| 2162 |
my $i; |
| 2163 |
my $key = -1; # to allow for 0 being a valid response |
| 2164 |
for ( $i = 0 ; $i < @result ; $i++ ) { |
| 2165 |
if ( $routingid == $result[$i] ) { |
| 2166 |
$key = $i; # save the index |
| 2167 |
last; |
| 2168 |
} |
| 2169 |
} |
| 2170 |
|
| 2171 |
# if index exists in array then move it to new position |
| 2172 |
if ( $key > -1 && $rank > 0 ) { |
| 2173 |
my $new_rank = $rank - 1; # $new_rank is what you want the new index to be in the array |
| 2174 |
my $moving_item = splice( @result, $key, 1 ); |
| 2175 |
splice( @result, $new_rank, 0, $moving_item ); |
| 2176 |
} |
| 2177 |
for ( my $j = 0 ; $j < @result ; $j++ ) { |
| 2178 |
my $sth = $dbh->prepare( "UPDATE subscriptionroutinglist SET ranking = '" . ( $j + 1 ) . "' WHERE routingid = '" . $result[$j] . "'" ); |
| 2179 |
$sth->execute; |
| 2180 |
} |
| 2181 |
return; |
| 2182 |
} |
| 2183 |
|
| 2184 |
=head2 delroutingmember |
| 2185 |
|
| 2186 |
delroutingmember($routingid,$subscriptionid) |
| 2187 |
|
| 2188 |
this function either deletes one member from routing list if $routingid exists otherwise |
| 2189 |
deletes all members from the routing list |
| 2190 |
|
| 2191 |
=cut |
| 2192 |
|
| 2193 |
sub delroutingmember { |
| 2194 |
|
| 2195 |
# if $routingid exists then deletes that row otherwise deletes all with $subscriptionid |
| 2196 |
my ( $routingid, $subscriptionid ) = @_; |
| 2197 |
my $dbh = C4::Context->dbh; |
| 2198 |
if ($routingid) { |
| 2199 |
my $sth = $dbh->prepare("DELETE FROM subscriptionroutinglist WHERE routingid = ?"); |
| 2200 |
$sth->execute($routingid); |
| 2201 |
reorder_members( $subscriptionid, $routingid ); |
| 2202 |
} else { |
| 2203 |
my $sth = $dbh->prepare("DELETE FROM subscriptionroutinglist WHERE subscriptionid = ?"); |
| 2204 |
$sth->execute($subscriptionid); |
| 2205 |
} |
| 2206 |
return; |
| 2207 |
} |
| 2208 |
|
| 2209 |
=head2 getroutinglist |
| 2210 |
|
| 2211 |
@routinglist = getroutinglist($subscriptionid) |
| 2212 |
|
| 2213 |
this gets the info from the subscriptionroutinglist for $subscriptionid |
| 2214 |
|
| 2215 |
return : |
| 2216 |
the routinglist as an array. Each element of the array contains a hash_ref containing |
| 2217 |
routingid - a unique id, borrowernumber, ranking, and biblionumber of subscription |
| 2218 |
|
| 2219 |
=cut |
| 2220 |
|
| 2221 |
sub getroutinglist { |
| 2222 |
my ($subscriptionid) = @_; |
| 2223 |
my $dbh = C4::Context->dbh; |
| 2224 |
my $sth = $dbh->prepare( |
| 2225 |
'SELECT routingid, borrowernumber, ranking, biblionumber |
| 2226 |
FROM subscription |
| 2227 |
JOIN subscriptionroutinglist ON subscription.subscriptionid = subscriptionroutinglist.subscriptionid |
| 2228 |
WHERE subscription.subscriptionid = ? ORDER BY ranking ASC' |
| 2229 |
); |
| 2230 |
$sth->execute($subscriptionid); |
| 2231 |
my $routinglist = $sth->fetchall_arrayref({}); |
| 2232 |
return @{$routinglist}; |
| 2233 |
} |
| 2234 |
|
| 2235 |
=head2 countissuesfrom |
2133 |
=head2 countissuesfrom |
| 2236 |
|
2134 |
|
| 2237 |
$result = countissuesfrom($subscriptionid,$startdate) |
2135 |
$result = countissuesfrom($subscriptionid,$startdate) |