Lines 50-62
BEGIN {
Link Here
|
50 |
&ReNewSubscription &GetLateIssues &GetLateOrMissingIssues |
50 |
&ReNewSubscription &GetLateIssues &GetLateOrMissingIssues |
51 |
&GetSerialInformation &AddItem2Serial |
51 |
&GetSerialInformation &AddItem2Serial |
52 |
&PrepareSerialsData &GetNextExpected &ModNextExpected |
52 |
&PrepareSerialsData &GetNextExpected &ModNextExpected |
|
|
53 |
&GetSerial &GetSerialItemnumber |
53 |
|
54 |
|
54 |
&UpdateClaimdateIssues |
55 |
&UpdateClaimdateIssues |
55 |
&GetSuppliersWithLateIssues &getsupplierbyserialid |
56 |
&GetSuppliersWithLateIssues &getsupplierbyserialid |
56 |
&GetDistributedTo &SetDistributedTo |
57 |
&GetDistributedTo &SetDistributedTo |
57 |
&getroutinglist &delroutingmember &addroutingmember |
58 |
&updateClaim &removeMissingIssue |
58 |
&reorder_members |
|
|
59 |
&check_routing &updateClaim &removeMissingIssue |
60 |
&CountIssues |
59 |
&CountIssues |
61 |
HasItems |
60 |
HasItems |
62 |
&GetSubscriptionsFromBorrower |
61 |
&GetSubscriptionsFromBorrower |
Lines 194-199
sub GetSubscriptionHistoryFromSubscriptionId {
Link Here
|
194 |
return $results; |
193 |
return $results; |
195 |
} |
194 |
} |
196 |
|
195 |
|
|
|
196 |
=head2 GetSerial |
197 |
|
198 |
my $serial = &GetSerial($serialid); |
199 |
|
200 |
This sub returns serial informations (ie. in serial table) for given $serialid |
201 |
It returns a hashref where each key is a sql column. |
202 |
|
203 |
=cut |
204 |
|
205 |
sub GetSerial { |
206 |
my ($serialid) = @_; |
207 |
|
208 |
return unless $serialid; |
209 |
|
210 |
my $dbh = C4::Context->dbh; |
211 |
my $query = qq{ |
212 |
SELECT * |
213 |
FROM serial |
214 |
WHERE serialid = ? |
215 |
}; |
216 |
my $sth = $dbh->prepare($query); |
217 |
$sth->execute($serialid); |
218 |
return $sth->fetchrow_hashref; |
219 |
} |
220 |
|
221 |
=head2 GetSerialItemnumber |
222 |
|
223 |
my $itemnumber = GetSerialItemnumber($serialid); |
224 |
|
225 |
Returns the itemnumber associated to $serialid or undef if there is no item. |
226 |
|
227 |
=cut |
228 |
|
229 |
sub GetSerialItemnumber { |
230 |
my ($serialid) = @_; |
231 |
|
232 |
return unless $serialid; |
233 |
my $itemnumber; |
234 |
|
235 |
my $dbh = C4::Context->dbh; |
236 |
my $query = qq{ |
237 |
SELECT itemnumber |
238 |
FROM serialitems |
239 |
WHERE serialid = ? |
240 |
}; |
241 |
my $sth = $dbh->prepare($query); |
242 |
my $rv = $sth->execute($serialid); |
243 |
if ($rv) { |
244 |
my $result = $sth->fetchrow_hashref; |
245 |
$itemnumber = $result->{itemnumber}; |
246 |
} |
247 |
return $itemnumber; |
248 |
} |
249 |
|
197 |
=head2 GetSerialStatusFromSerialId |
250 |
=head2 GetSerialStatusFromSerialId |
198 |
|
251 |
|
199 |
$sth = GetSerialStatusFromSerialId(); |
252 |
$sth = GetSerialStatusFromSerialId(); |
Lines 2132-2292
sub getsupplierbyserialid {
Link Here
|
2132 |
return $result; |
2185 |
return $result; |
2133 |
} |
2186 |
} |
2134 |
|
2187 |
|
2135 |
=head2 check_routing |
|
|
2136 |
|
2137 |
$result = &check_routing($subscriptionid) |
2138 |
|
2139 |
this function checks to see if a serial has a routing list and returns the count of routingid |
2140 |
used to show either an 'add' or 'edit' link |
2141 |
|
2142 |
=cut |
2143 |
|
2144 |
sub check_routing { |
2145 |
my ($subscriptionid) = @_; |
2146 |
|
2147 |
return unless ($subscriptionid); |
2148 |
|
2149 |
my $dbh = C4::Context->dbh; |
2150 |
my $sth = $dbh->prepare( |
2151 |
"SELECT count(routingid) routingids FROM subscription LEFT JOIN subscriptionroutinglist |
2152 |
ON subscription.subscriptionid = subscriptionroutinglist.subscriptionid |
2153 |
WHERE subscription.subscriptionid = ? ORDER BY ranking ASC |
2154 |
" |
2155 |
); |
2156 |
$sth->execute($subscriptionid); |
2157 |
my $line = $sth->fetchrow_hashref; |
2158 |
my $result = $line->{'routingids'}; |
2159 |
return $result; |
2160 |
} |
2161 |
|
2162 |
=head2 addroutingmember |
2163 |
|
2164 |
addroutingmember($borrowernumber,$subscriptionid) |
2165 |
|
2166 |
this function takes a borrowernumber and subscriptionid and adds the member to the |
2167 |
routing list for that serial subscription and gives them a rank on the list |
2168 |
of either 1 or highest current rank + 1 |
2169 |
|
2170 |
=cut |
2171 |
|
2172 |
sub addroutingmember { |
2173 |
my ( $borrowernumber, $subscriptionid ) = @_; |
2174 |
|
2175 |
return unless ($borrowernumber and $subscriptionid); |
2176 |
|
2177 |
my $rank; |
2178 |
my $dbh = C4::Context->dbh; |
2179 |
my $sth = $dbh->prepare( "SELECT max(ranking) rank FROM subscriptionroutinglist WHERE subscriptionid = ?" ); |
2180 |
$sth->execute($subscriptionid); |
2181 |
while ( my $line = $sth->fetchrow_hashref ) { |
2182 |
if ( $line->{'rank'} > 0 ) { |
2183 |
$rank = $line->{'rank'} + 1; |
2184 |
} else { |
2185 |
$rank = 1; |
2186 |
} |
2187 |
} |
2188 |
$sth = $dbh->prepare( "INSERT INTO subscriptionroutinglist (subscriptionid,borrowernumber,ranking) VALUES (?,?,?)" ); |
2189 |
$sth->execute( $subscriptionid, $borrowernumber, $rank ); |
2190 |
} |
2191 |
|
2192 |
=head2 reorder_members |
2193 |
|
2194 |
reorder_members($subscriptionid,$routingid,$rank) |
2195 |
|
2196 |
this function is used to reorder the routing list |
2197 |
|
2198 |
it takes the routingid of the member one wants to re-rank and the rank it is to move to |
2199 |
- it gets all members on list puts their routingid's into an array |
2200 |
- removes the one in the array that is $routingid |
2201 |
- then reinjects $routingid at point indicated by $rank |
2202 |
- then update the database with the routingids in the new order |
2203 |
|
2204 |
=cut |
2205 |
|
2206 |
sub reorder_members { |
2207 |
my ( $subscriptionid, $routingid, $rank ) = @_; |
2208 |
my $dbh = C4::Context->dbh; |
2209 |
my $sth = $dbh->prepare( "SELECT * FROM subscriptionroutinglist WHERE subscriptionid = ? ORDER BY ranking ASC" ); |
2210 |
$sth->execute($subscriptionid); |
2211 |
my @result; |
2212 |
while ( my $line = $sth->fetchrow_hashref ) { |
2213 |
push( @result, $line->{'routingid'} ); |
2214 |
} |
2215 |
|
2216 |
# To find the matching index |
2217 |
my $i; |
2218 |
my $key = -1; # to allow for 0 being a valid response |
2219 |
for ( $i = 0 ; $i < @result ; $i++ ) { |
2220 |
if ( $routingid == $result[$i] ) { |
2221 |
$key = $i; # save the index |
2222 |
last; |
2223 |
} |
2224 |
} |
2225 |
|
2226 |
# if index exists in array then move it to new position |
2227 |
if ( $key > -1 && $rank > 0 ) { |
2228 |
my $new_rank = $rank - 1; # $new_rank is what you want the new index to be in the array |
2229 |
my $moving_item = splice( @result, $key, 1 ); |
2230 |
splice( @result, $new_rank, 0, $moving_item ); |
2231 |
} |
2232 |
for ( my $j = 0 ; $j < @result ; $j++ ) { |
2233 |
my $sth = $dbh->prepare( "UPDATE subscriptionroutinglist SET ranking = '" . ( $j + 1 ) . "' WHERE routingid = '" . $result[$j] . "'" ); |
2234 |
$sth->execute; |
2235 |
} |
2236 |
return; |
2237 |
} |
2238 |
|
2239 |
=head2 delroutingmember |
2240 |
|
2241 |
delroutingmember($routingid,$subscriptionid) |
2242 |
|
2243 |
this function either deletes one member from routing list if $routingid exists otherwise |
2244 |
deletes all members from the routing list |
2245 |
|
2246 |
=cut |
2247 |
|
2248 |
sub delroutingmember { |
2249 |
|
2250 |
# if $routingid exists then deletes that row otherwise deletes all with $subscriptionid |
2251 |
my ( $routingid, $subscriptionid ) = @_; |
2252 |
my $dbh = C4::Context->dbh; |
2253 |
if ($routingid) { |
2254 |
my $sth = $dbh->prepare("DELETE FROM subscriptionroutinglist WHERE routingid = ?"); |
2255 |
$sth->execute($routingid); |
2256 |
reorder_members( $subscriptionid, $routingid ); |
2257 |
} else { |
2258 |
my $sth = $dbh->prepare("DELETE FROM subscriptionroutinglist WHERE subscriptionid = ?"); |
2259 |
$sth->execute($subscriptionid); |
2260 |
} |
2261 |
return; |
2262 |
} |
2263 |
|
2264 |
=head2 getroutinglist |
2265 |
|
2266 |
@routinglist = getroutinglist($subscriptionid) |
2267 |
|
2268 |
this gets the info from the subscriptionroutinglist for $subscriptionid |
2269 |
|
2270 |
return : |
2271 |
the routinglist as an array. Each element of the array contains a hash_ref containing |
2272 |
routingid - a unique id, borrowernumber, ranking, and biblionumber of subscription |
2273 |
|
2274 |
=cut |
2275 |
|
2276 |
sub getroutinglist { |
2277 |
my ($subscriptionid) = @_; |
2278 |
my $dbh = C4::Context->dbh; |
2279 |
my $sth = $dbh->prepare( |
2280 |
'SELECT routingid, borrowernumber, ranking, biblionumber |
2281 |
FROM subscription |
2282 |
JOIN subscriptionroutinglist ON subscription.subscriptionid = subscriptionroutinglist.subscriptionid |
2283 |
WHERE subscription.subscriptionid = ? ORDER BY ranking ASC' |
2284 |
); |
2285 |
$sth->execute($subscriptionid); |
2286 |
my $routinglist = $sth->fetchall_arrayref({}); |
2287 |
return @{$routinglist}; |
2288 |
} |
2289 |
|
2290 |
=head2 countissuesfrom |
2188 |
=head2 countissuesfrom |
2291 |
|
2189 |
|
2292 |
$result = countissuesfrom($subscriptionid,$startdate) |
2190 |
$result = countissuesfrom($subscriptionid,$startdate) |