3 # Copyright 2000-2002 Katipo Communications
4 # Parts Copyright 2010 Biblibre
6 # This file is part of Koha.
8 # Koha is free software; you can redistribute it and/or modify it under the
9 # terms of the GNU General Public License as published by the Free Software
10 # Foundation; either version 2 of the License, or (at your option) any later
13 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
14 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
15 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License along
18 # with Koha; if not, write to the Free Software Foundation, Inc.,
19 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 use C4
::Auth
qw(haspermission);
25 use C4
::Dates
qw(format_date format_date_in_iso);
26 use Date
::Calc
qw(:all);
27 use POSIX
qw(strftime setlocale LC_TIME);
29 use C4
::Log
; # logaction
31 use C4
::Serials
::Frequency
;
32 use C4
::Serials
::Numberpattern
;
34 use vars
qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
37 $VERSION = 3.07.00.049; # set version for version checking
41 &NewSubscription &ModSubscription &DelSubscription &GetSubscriptions
42 &GetSubscription &CountSubscriptionFromBiblionumber &GetSubscriptionsFromBiblionumber
44 &GetFullSubscriptionsFromBiblionumber &GetFullSubscription &ModSubscriptionHistory
45 &HasSubscriptionStrictlyExpired &HasSubscriptionExpired &GetExpirationDate &abouttoexpire
46 &GetSubscriptionHistoryFromSubscriptionId
48 &GetNextSeq &GetSeq &NewIssue &ItemizeSerials &GetSerials
49 &GetLatestSerials &ModSerialStatus &GetNextDate &GetSerials2
50 &ReNewSubscription &GetLateIssues &GetLateOrMissingIssues
51 &GetSerialInformation &AddItem2Serial
52 &PrepareSerialsData &GetNextExpected &ModNextExpected
54 &UpdateClaimdateIssues
55 &GetSuppliersWithLateIssues &getsupplierbyserialid
56 &GetDistributedTo &SetDistributedTo
57 &getroutinglist &delroutingmember &addroutingmember
59 &check_routing &updateClaim &removeMissingIssue
62 &GetSubscriptionsFromBorrower
63 &subscriptionCurrentlyOnOrder
70 C4::Serials - Serials Module Functions
78 Functions for handling subscriptions, claims routing etc.
83 =head2 GetSuppliersWithLateIssues
85 $supplierlist = GetSuppliersWithLateIssues()
87 this function get all suppliers with late issues.
90 an array_ref of suppliers each entry is a hash_ref containing id and name
91 the array is in name order
95 sub GetSuppliersWithLateIssues
{
96 my $dbh = C4
::Context
->dbh;
98 SELECT DISTINCT id
, name
100 LEFT JOIN serial ON serial
.subscriptionid
=subscription
.subscriptionid
101 LEFT JOIN aqbooksellers ON subscription
.aqbooksellerid
= aqbooksellers
.id
104 (planneddate
< now
() AND serial
.status
=1)
105 OR serial
.STATUS IN
(3, 4, 41, 42, 43, 44)
107 AND subscription
.closed
= 0
109 return $dbh->selectall_arrayref($query, { Slice
=> {} });
114 @issuelist = GetLateIssues($supplierid)
116 this function selects late issues from the database
119 the issuelist as an array. Each element of this array contains a hashi_ref containing
120 name,title,planneddate,serialseq,serial.subscriptionid from tables : subscription, serial & biblio
125 my ($supplierid) = @_;
127 return unless ($supplierid);
129 my $dbh = C4
::Context
->dbh;
133 SELECT name
,title
,planneddate
,serialseq
,serial
.subscriptionid
135 LEFT JOIN serial ON subscription
.subscriptionid
= serial
.subscriptionid
136 LEFT JOIN biblio ON biblio
.biblionumber
= subscription
.biblionumber
137 LEFT JOIN aqbooksellers ON subscription
.aqbooksellerid
= aqbooksellers
.id
138 WHERE
((planneddate
< now
() AND serial
.STATUS
=1) OR serial
.STATUS
= 3)
139 AND subscription
.aqbooksellerid
=?
140 AND subscription
.closed
= 0
143 $sth = $dbh->prepare($query);
144 $sth->execute($supplierid);
147 SELECT name
,title
,planneddate
,serialseq
,serial
.subscriptionid
149 LEFT JOIN serial ON subscription
.subscriptionid
= serial
.subscriptionid
150 LEFT JOIN biblio ON biblio
.biblionumber
= subscription
.biblionumber
151 LEFT JOIN aqbooksellers ON subscription
.aqbooksellerid
= aqbooksellers
.id
152 WHERE
((planneddate
< now
() AND serial
.STATUS
=1) OR serial
.STATUS
= 3)
153 AND subscription
.closed
= 0
156 $sth = $dbh->prepare($query);
161 while ( my $line = $sth->fetchrow_hashref ) {
162 $line->{title
} = "" if $last_title and $line->{title
} eq $last_title;
163 $last_title = $line->{title
} if ( $line->{title
} );
164 $line->{planneddate
} = format_date
( $line->{planneddate
} );
165 push @issuelist, $line;
170 =head2 GetSubscriptionHistoryFromSubscriptionId
172 $history = GetSubscriptionHistoryFromSubscriptionId($subscriptionid);
174 This function returns the subscription history as a hashref
178 sub GetSubscriptionHistoryFromSubscriptionId
{
179 my ($subscriptionid) = @_;
181 return unless $subscriptionid;
183 my $dbh = C4
::Context
->dbh;
186 FROM subscriptionhistory
187 WHERE subscriptionid
= ?
189 my $sth = $dbh->prepare($query);
190 $sth->execute($subscriptionid);
191 my $results = $sth->fetchrow_hashref;
197 =head2 GetSerialStatusFromSerialId
199 $sth = GetSerialStatusFromSerialId();
200 this function returns a statement handle
201 After this function, don't forget to execute it by using $sth->execute($serialid)
203 $sth = $dbh->prepare($query).
207 sub GetSerialStatusFromSerialId
{
208 my $dbh = C4
::Context
->dbh;
214 return $dbh->prepare($query);
217 =head2 GetSerialInformation
220 $data = GetSerialInformation($serialid);
221 returns a hash_ref containing :
222 items : items marcrecord (can be an array)
224 subscription table field
225 + information about subscription expiration
229 sub GetSerialInformation
{
231 my $dbh = C4
::Context
->dbh;
233 SELECT serial
.*, serial
.notes as sernotes
, serial
.status as serstatus
,subscription
.*,subscription
.subscriptionid as subsid
234 FROM serial LEFT JOIN subscription ON subscription
.subscriptionid
=serial
.subscriptionid
237 my $rq = $dbh->prepare($query);
238 $rq->execute($serialid);
239 my $data = $rq->fetchrow_hashref;
241 # create item information if we have serialsadditems for this subscription
242 if ( $data->{'serialsadditems'} ) {
243 my $queryitem = $dbh->prepare("SELECT itemnumber from serialitems where serialid=?");
244 $queryitem->execute($serialid);
245 my $itemnumbers = $queryitem->fetchall_arrayref( [0] );
247 if ( scalar(@
$itemnumbers) > 0 ) {
248 foreach my $itemnum (@
$itemnumbers) {
250 #It is ASSUMED that GetMarcItem ALWAYS WORK...
251 #Maybe GetMarcItem should return values on failure
252 $debug and warn "itemnumber :$itemnum->[0], bibnum :" . $data->{'biblionumber'};
253 my $itemprocessed = C4
::Items
::PrepareItemrecordDisplay
( $data->{'biblionumber'}, $itemnum->[0], $data );
254 $itemprocessed->{'itemnumber'} = $itemnum->[0];
255 $itemprocessed->{'itemid'} = $itemnum->[0];
256 $itemprocessed->{'serialid'} = $serialid;
257 $itemprocessed->{'biblionumber'} = $data->{'biblionumber'};
258 push @
{ $data->{'items'} }, $itemprocessed;
261 my $itemprocessed = C4
::Items
::PrepareItemrecordDisplay
( $data->{'biblionumber'}, '', $data );
262 $itemprocessed->{'itemid'} = "N$serialid";
263 $itemprocessed->{'serialid'} = $serialid;
264 $itemprocessed->{'biblionumber'} = $data->{'biblionumber'};
265 $itemprocessed->{'countitems'} = 0;
266 push @
{ $data->{'items'} }, $itemprocessed;
269 $data->{ "status" . $data->{'serstatus'} } = 1;
270 $data->{'subscriptionexpired'} = HasSubscriptionExpired
( $data->{'subscriptionid'} ) && $data->{'status'} == 1;
271 $data->{'abouttoexpire'} = abouttoexpire
( $data->{'subscriptionid'} );
272 $data->{cannotedit
} = not can_edit_subscription
( $data );
276 =head2 AddItem2Serial
278 $rows = AddItem2Serial($serialid,$itemnumber);
279 Adds an itemnumber to Serial record
280 returns the number of rows affected
285 my ( $serialid, $itemnumber ) = @_;
287 return unless ($serialid and $itemnumber);
289 my $dbh = C4
::Context
->dbh;
290 my $rq = $dbh->prepare("INSERT INTO `serialitems` SET serialid=? , itemnumber=?");
291 $rq->execute( $serialid, $itemnumber );
295 =head2 UpdateClaimdateIssues
297 UpdateClaimdateIssues($serialids,[$date]);
299 Update Claimdate for issues in @$serialids list with date $date
304 sub UpdateClaimdateIssues
{
305 my ( $serialids, $date ) = @_;
307 return unless ($serialids);
309 my $dbh = C4
::Context
->dbh;
310 $date = strftime
( "%Y-%m-%d", localtime ) unless ($date);
312 UPDATE serial SET claimdate = ?, status = 7
313 WHERE serialid in (" . join( ",", map { '?' } @
$serialids ) . ")";
314 my $rq = $dbh->prepare($query);
315 $rq->execute($date, @
$serialids);
319 =head2 GetSubscription
321 $subs = GetSubscription($subscriptionid)
322 this function returns the subscription which has $subscriptionid as id.
324 a hashref. This hash containts
325 subscription, subscriptionhistory, aqbooksellers.name, biblio.title
329 sub GetSubscription
{
330 my ($subscriptionid) = @_;
331 my $dbh = C4
::Context
->dbh;
333 SELECT subscription
.*,
334 subscriptionhistory
.*,
335 aqbooksellers
.name AS aqbooksellername
,
336 biblio
.title AS bibliotitle
,
337 subscription
.biblionumber as bibnum
339 LEFT JOIN subscriptionhistory ON subscription
.subscriptionid
=subscriptionhistory
.subscriptionid
340 LEFT JOIN aqbooksellers ON subscription
.aqbooksellerid
=aqbooksellers
.id
341 LEFT JOIN biblio ON biblio
.biblionumber
=subscription
.biblionumber
342 WHERE subscription
.subscriptionid
= ?
345 $debug and warn "query : $query\nsubsid :$subscriptionid";
346 my $sth = $dbh->prepare($query);
347 $sth->execute($subscriptionid);
348 my $subscription = $sth->fetchrow_hashref;
349 $subscription->{cannotedit
} = not can_edit_subscription
( $subscription );
350 return $subscription;
353 =head2 GetFullSubscription
355 $array_ref = GetFullSubscription($subscriptionid)
356 this function reads the serial table.
360 sub GetFullSubscription
{
361 my ($subscriptionid) = @_;
363 return unless ($subscriptionid);
365 my $dbh = C4
::Context
->dbh;
367 SELECT serial
.serialid
,
370 serial
.publisheddate
,
372 serial
.notes as notes
,
373 year
(IF
(serial
.publisheddate
="00-00-0000",serial
.planneddate
,serial
.publisheddate
)) as year
,
374 aqbooksellers
.name as aqbooksellername
,
375 biblio
.title as bibliotitle
,
376 subscription
.branchcode AS branchcode
,
377 subscription
.subscriptionid AS subscriptionid
379 LEFT JOIN subscription ON
380 (serial
.subscriptionid
=subscription
.subscriptionid
)
381 LEFT JOIN aqbooksellers on subscription
.aqbooksellerid
=aqbooksellers
.id
382 LEFT JOIN biblio on biblio
.biblionumber
=subscription
.biblionumber
383 WHERE serial
.subscriptionid
= ?
385 IF
(serial
.publisheddate
="00-00-0000",serial
.planneddate
,serial
.publisheddate
) DESC
,
386 serial
.subscriptionid
388 $debug and warn "GetFullSubscription query: $query";
389 my $sth = $dbh->prepare($query);
390 $sth->execute($subscriptionid);
391 my $subscriptions = $sth->fetchall_arrayref( {} );
392 for my $subscription ( @
$subscriptions ) {
393 $subscription->{cannotedit
} = not can_edit_subscription
( $subscription );
395 return $subscriptions;
398 =head2 PrepareSerialsData
400 $array_ref = PrepareSerialsData($serialinfomation)
401 where serialinformation is a hashref array
405 sub PrepareSerialsData
{
408 return unless ($lines);
414 my $aqbooksellername;
418 my $previousnote = "";
420 foreach my $subs (@
{$lines}) {
421 for my $datefield ( qw(publisheddate planneddate) ) {
422 # handle 0000-00-00 dates
423 if (defined $subs->{$datefield} and $subs->{$datefield} =~ m/^00/) {
424 $subs->{$datefield} = undef;
427 $subs->{ "status" . $subs->{'status'} } = 1;
428 if ( grep { $_ == $subs->{status
} } qw( 1 3 4 41 42 43 44 7 ) ) {
429 $subs->{"checked"} = 1;
432 if ( $subs->{'year'} && $subs->{'year'} ne "" ) {
433 $year = $subs->{'year'};
437 if ( $tmpresults{$year} ) {
438 push @
{ $tmpresults{$year}->{'serials'} }, $subs;
440 $tmpresults{$year} = {
442 'aqbooksellername' => $subs->{'aqbooksellername'},
443 'bibliotitle' => $subs->{'bibliotitle'},
444 'serials' => [$subs],
449 foreach my $key ( sort { $b cmp $a } keys %tmpresults ) {
450 push @res, $tmpresults{$key};
455 =head2 GetSubscriptionsFromBiblionumber
457 $array_ref = GetSubscriptionsFromBiblionumber($biblionumber)
458 this function get the subscription list. it reads the subscription table.
460 reference to an array of subscriptions which have the biblionumber given on input arg.
461 each element of this array is a hashref containing
462 startdate, histstartdate,opacnote,missinglist,recievedlist,periodicity,status & enddate
466 sub GetSubscriptionsFromBiblionumber
{
467 my ($biblionumber) = @_;
469 return unless ($biblionumber);
471 my $dbh = C4
::Context
->dbh;
473 SELECT subscription
.*,
475 subscriptionhistory
.*,
476 aqbooksellers
.name AS aqbooksellername
,
477 biblio
.title AS bibliotitle
479 LEFT JOIN subscriptionhistory ON subscription
.subscriptionid
=subscriptionhistory
.subscriptionid
480 LEFT JOIN aqbooksellers ON subscription
.aqbooksellerid
=aqbooksellers
.id
481 LEFT JOIN biblio ON biblio
.biblionumber
=subscription
.biblionumber
482 LEFT JOIN branches ON branches
.branchcode
=subscription
.branchcode
483 WHERE subscription
.biblionumber
= ?
485 my $sth = $dbh->prepare($query);
486 $sth->execute($biblionumber);
488 while ( my $subs = $sth->fetchrow_hashref ) {
489 $subs->{startdate
} = format_date
( $subs->{startdate
} );
490 $subs->{histstartdate
} = format_date
( $subs->{histstartdate
} );
491 $subs->{histenddate
} = format_date
( $subs->{histenddate
} );
492 $subs->{opacnote
} =~ s/\n/\<br\/\
>/g
;
493 $subs->{missinglist
} =~ s/\n/\<br\/\
>/g
;
494 $subs->{recievedlist
} =~ s/\n/\<br\/\
>/g
;
495 $subs->{ "periodicity" . $subs->{periodicity
} } = 1;
496 $subs->{ "numberpattern" . $subs->{numberpattern
} } = 1;
497 $subs->{ "status" . $subs->{'status'} } = 1;
499 if ( $subs->{enddate
} eq '0000-00-00' ) {
500 $subs->{enddate
} = '';
502 $subs->{enddate
} = format_date
( $subs->{enddate
} );
504 $subs->{'abouttoexpire'} = abouttoexpire
( $subs->{'subscriptionid'} );
505 $subs->{'subscriptionexpired'} = HasSubscriptionExpired
( $subs->{'subscriptionid'} );
506 $subs->{cannotedit
} = not can_edit_subscription
( $subs );
512 =head2 GetFullSubscriptionsFromBiblionumber
514 $array_ref = GetFullSubscriptionsFromBiblionumber($biblionumber)
515 this function reads the serial table.
519 sub GetFullSubscriptionsFromBiblionumber
{
520 my ($biblionumber) = @_;
521 my $dbh = C4
::Context
->dbh;
523 SELECT serial
.serialid
,
526 serial
.publisheddate
,
528 serial
.notes as notes
,
529 year
(IF
(serial
.publisheddate
="00-00-0000",serial
.planneddate
,serial
.publisheddate
)) as year
,
530 biblio
.title as bibliotitle
,
531 subscription
.branchcode AS branchcode
,
532 subscription
.subscriptionid AS subscriptionid
534 LEFT JOIN subscription ON
535 (serial
.subscriptionid
=subscription
.subscriptionid
)
536 LEFT JOIN aqbooksellers on subscription
.aqbooksellerid
=aqbooksellers
.id
537 LEFT JOIN biblio on biblio
.biblionumber
=subscription
.biblionumber
538 WHERE subscription
.biblionumber
= ?
540 IF
(serial
.publisheddate
="00-00-0000",serial
.planneddate
,serial
.publisheddate
) DESC
,
541 serial
.subscriptionid
543 my $sth = $dbh->prepare($query);
544 $sth->execute($biblionumber);
545 my $subscriptions = $sth->fetchall_arrayref( {} );
546 for my $subscription ( @
$subscriptions ) {
547 $subscription->{cannotedit
} = not can_edit_subscription
( $subscription );
549 return $subscriptions;
552 =head2 GetSubscriptions
554 @results = GetSubscriptions($title,$ISSN,$ean,$biblionumber);
555 this function gets all subscriptions which have title like $title,ISSN like $ISSN,EAN like $ean and biblionumber like $biblionumber.
557 a table of hashref. Each hash containt the subscription.
561 sub GetSubscriptions
{
562 my ( $string, $issn, $ean, $biblionumber ) = @_;
564 #return unless $title or $ISSN or $biblionumber;
565 my $dbh = C4
::Context
->dbh;
568 SELECT subscriptionhistory
.*, subscription
.*, biblio
.title
,biblioitems
.issn
,biblio
.biblionumber
570 LEFT JOIN subscriptionhistory USING
(subscriptionid
)
571 LEFT JOIN biblio ON biblio
.biblionumber
= subscription
.biblionumber
572 LEFT JOIN biblioitems ON biblio
.biblionumber
= biblioitems
.biblionumber
577 $sqlwhere = " WHERE biblio.biblionumber=?";
578 push @bind_params, $biblionumber;
582 my @strings_to_search;
583 @strings_to_search = map { "%$_%" } split( / /, $string );
584 foreach my $index (qw(biblio.title subscription.callnumber subscription.location subscription.notes subscription.internalnotes)) {
585 push @bind_params, @strings_to_search;
586 my $tmpstring = "AND $index LIKE ? " x
scalar(@strings_to_search);
587 $debug && warn "$tmpstring";
588 $tmpstring =~ s/^AND //;
589 push @sqlstrings, $tmpstring;
591 $sqlwhere .= ( $sqlwhere ?
" AND " : " WHERE " ) . "((" . join( ") OR (", @sqlstrings ) . "))";
595 my @strings_to_search;
596 @strings_to_search = map { "%$_%" } split( / /, $issn );
597 foreach my $index ( qw(biblioitems.issn subscription.callnumber)) {
598 push @bind_params, @strings_to_search;
599 my $tmpstring = "OR $index LIKE ? " x
scalar(@strings_to_search);
600 $debug && warn "$tmpstring";
601 $tmpstring =~ s/^OR //;
602 push @sqlstrings, $tmpstring;
604 $sqlwhere .= ( $sqlwhere ?
" AND " : " WHERE " ) . "((" . join( ") OR (", @sqlstrings ) . "))";
608 my @strings_to_search;
609 @strings_to_search = map { "$_" } split( / /, $ean );
610 foreach my $index ( qw(biblioitems.ean) ) {
611 push @bind_params, @strings_to_search;
612 my $tmpstring = "OR $index = ? " x
scalar(@strings_to_search);
613 $debug && warn "$tmpstring";
614 $tmpstring =~ s/^OR //;
615 push @sqlstrings, $tmpstring;
617 $sqlwhere .= ( $sqlwhere ?
" AND " : " WHERE " ) . "((" . join( ") OR (", @sqlstrings ) . "))";
620 $sql .= "$sqlwhere ORDER BY title";
621 $debug and warn "GetSubscriptions query: $sql params : ", join( " ", @bind_params );
622 $sth = $dbh->prepare($sql);
623 $sth->execute(@bind_params);
624 my $subscriptions = $sth->fetchall_arrayref( {} );
625 for my $subscription ( @
$subscriptions ) {
626 $subscription->{cannotedit
} = not can_edit_subscription
( $subscription );
628 return @
$subscriptions;
631 =head2 SearchSubscriptions
633 @results = SearchSubscriptions($args);
635 This function returns a list of hashrefs, one for each subscription
636 that meets the conditions specified by the $args hashref.
638 The valid search fields are:
652 The expiration_date search field is special; it specifies the maximum
653 subscription expiration date.
657 sub SearchSubscriptions
{
662 subscription
.notes AS publicnotes
,
664 subscriptionhistory
.*,
665 biblio
.notes AS biblionotes
,
670 LEFT JOIN subscriptionhistory USING
(subscriptionid
)
671 LEFT JOIN biblio ON biblio
.biblionumber
= subscription
.biblionumber
672 LEFT JOIN biblioitems ON biblioitems
.biblionumber
= subscription
.biblionumber
673 LEFT JOIN aqbooksellers ON subscription
.aqbooksellerid
= aqbooksellers
.id
677 if( $args->{biblionumber
} ) {
678 push @where_strs, "biblio.biblionumber = ?";
679 push @where_args, $args->{biblionumber
};
681 if( $args->{title
} ){
682 my @words = split / /, $args->{title
};
684 foreach my $word (@words) {
685 push @strs, "biblio.title LIKE ?";
686 push @args, "%$word%";
689 push @where_strs, '(' . join (' AND ', @strs) . ')';
690 push @where_args, @args;
694 push @where_strs, "biblioitems.issn LIKE ?";
695 push @where_args, "%$args->{issn}%";
698 push @where_strs, "biblioitems.ean LIKE ?";
699 push @where_args, "%$args->{ean}%";
701 if ( $args->{callnumber
} ) {
702 push @where_strs, "subscription.callnumber LIKE ?";
703 push @where_args, "%$args->{callnumber}%";
705 if( $args->{publisher
} ){
706 push @where_strs, "biblioitems.publishercode LIKE ?";
707 push @where_args, "%$args->{publisher}%";
709 if( $args->{bookseller
} ){
710 push @where_strs, "aqbooksellers.name LIKE ?";
711 push @where_args, "%$args->{bookseller}%";
713 if( $args->{branch
} ){
714 push @where_strs, "subscription.branchcode = ?";
715 push @where_args, "$args->{branch}";
717 if ( $args->{location
} ) {
718 push @where_strs, "subscription.location = ?";
719 push @where_args, "$args->{location}";
721 if ( $args->{expiration_date
} ) {
722 push @where_strs, "subscription.enddate <= ?";
723 push @where_args, "$args->{expiration_date}";
725 if( defined $args->{closed
} ){
726 push @where_strs, "subscription.closed = ?";
727 push @where_args, "$args->{closed}";
730 $query .= " WHERE " . join(" AND ", @where_strs);
733 my $dbh = C4
::Context
->dbh;
734 my $sth = $dbh->prepare($query);
735 $sth->execute(@where_args);
736 my $results = $sth->fetchall_arrayref( {} );
739 for my $subscription ( @
$results ) {
740 $subscription->{cannotedit
} = not can_edit_subscription
( $subscription );
741 $subscription->{cannotdisplay
} = not can_show_subscription
( $subscription );
750 ($totalissues,@serials) = GetSerials($subscriptionid);
751 this function gets every serial not arrived for a given subscription
752 as well as the number of issues registered in the database (all types)
753 this number is used to see if a subscription can be deleted (=it must have only 1 issue)
755 FIXME: We should return \@serials.
760 my ( $subscriptionid, $count ) = @_;
762 return unless $subscriptionid;
764 my $dbh = C4
::Context
->dbh;
766 # status = 2 is "arrived"
768 $count = 5 unless ($count);
770 my $query = "SELECT serialid,serialseq, status, publisheddate, planneddate,notes, routingnotes
772 WHERE subscriptionid = ? AND status NOT IN (2, 4, 41, 42, 43, 44, 5)
773 ORDER BY IF(publisheddate<>'0000-00-00',publisheddate,planneddate) DESC";
774 my $sth = $dbh->prepare($query);
775 $sth->execute($subscriptionid);
777 while ( my $line = $sth->fetchrow_hashref ) {
778 $line->{ "status" . $line->{status
} } = 1; # fills a "statusX" value, used for template status select list
779 for my $datefield ( qw( planneddate publisheddate) ) {
780 if ($line->{$datefield} && $line->{$datefield}!~m/^00/) {
781 $line->{$datefield} = format_date
( $line->{$datefield});
783 $line->{$datefield} = q{};
786 push @serials, $line;
789 # OK, now add the last 5 issues arrives/missing
790 $query = "SELECT serialid,serialseq, status, planneddate, publisheddate,notes, routingnotes
792 WHERE subscriptionid = ?
793 AND (status in (2, 4, 41, 42, 43, 44, 5))
794 ORDER BY IF(publisheddate<>'0000-00-00',publisheddate,planneddate) DESC
796 $sth = $dbh->prepare($query);
797 $sth->execute($subscriptionid);
798 while ( ( my $line = $sth->fetchrow_hashref ) && $counter < $count ) {
800 $line->{ "status" . $line->{status
} } = 1; # fills a "statusX" value, used for template status select list
801 for my $datefield ( qw( planneddate publisheddate) ) {
802 if ($line->{$datefield} && $line->{$datefield}!~m/^00/) {
803 $line->{$datefield} = format_date
( $line->{$datefield});
805 $line->{$datefield} = q{};
809 push @serials, $line;
812 $query = "SELECT count(*) FROM serial WHERE subscriptionid=?";
813 $sth = $dbh->prepare($query);
814 $sth->execute($subscriptionid);
815 my ($totalissues) = $sth->fetchrow;
816 return ( $totalissues, @serials );
821 @serials = GetSerials2($subscriptionid,$status);
822 this function returns every serial waited for a given subscription
823 as well as the number of issues registered in the database (all types)
824 this number is used to see if a subscription can be deleted (=it must have only 1 issue)
829 my ( $subscription, $status ) = @_;
831 return unless ($subscription and $status);
833 my $dbh = C4
::Context
->dbh;
835 SELECT serialid
,serialseq
, status
, planneddate
, publisheddate
,notes
, routingnotes
837 WHERE subscriptionid
=$subscription AND status IN
($status)
838 ORDER BY publisheddate
,serialid DESC
840 $debug and warn "GetSerials2 query: $query";
841 my $sth = $dbh->prepare($query);
845 while ( my $line = $sth->fetchrow_hashref ) {
846 $line->{ "status" . $line->{status
} } = 1; # fills a "statusX" value, used for template status select list
847 # Format dates for display
848 for my $datefield ( qw( planneddate publisheddate ) ) {
849 if (!defined($line->{$datefield}) || $line->{$datefield} =~m/^00/) {
850 $line->{$datefield} = q{};
853 $line->{$datefield} = format_date
( $line->{$datefield} );
856 push @serials, $line;
861 =head2 GetLatestSerials
863 \@serials = GetLatestSerials($subscriptionid,$limit)
864 get the $limit's latest serials arrived or missing for a given subscription
866 a ref to an array which contains all of the latest serials stored into a hash.
870 sub GetLatestSerials
{
871 my ( $subscriptionid, $limit ) = @_;
873 return unless ($subscriptionid and $limit);
875 my $dbh = C4
::Context
->dbh;
877 # status = 2 is "arrived"
878 my $strsth = "SELECT serialid,serialseq, status, planneddate, publisheddate, notes
880 WHERE subscriptionid = ?
881 AND status IN (2, 4, 41, 42, 43, 44)
882 ORDER BY publisheddate DESC LIMIT 0,$limit
884 my $sth = $dbh->prepare($strsth);
885 $sth->execute($subscriptionid);
887 while ( my $line = $sth->fetchrow_hashref ) {
888 $line->{ "status" . $line->{status
} } = 1; # fills a "statusX" value, used for template status select list
889 $line->{"planneddate"} = format_date
( $line->{"planneddate"} );
890 $line->{"publisheddate"} = format_date
( $line->{"publisheddate"} );
891 push @serials, $line;
897 =head2 GetDistributedTo
899 $distributedto=GetDistributedTo($subscriptionid)
900 This function returns the field distributedto for the subscription matching subscriptionid
904 sub GetDistributedTo
{
905 my $dbh = C4
::Context
->dbh;
907 my ($subscriptionid) = @_;
909 return unless ($subscriptionid);
911 my $query = "SELECT distributedto FROM subscription WHERE subscriptionid=?";
912 my $sth = $dbh->prepare($query);
913 $sth->execute($subscriptionid);
914 return ($distributedto) = $sth->fetchrow;
920 $nextseq, $newlastvalue1, $newlastvalue2, $newlastvalue3,
921 $newinnerloop1, $newinnerloop2, $newinnerloop3
922 ) = GetNextSeq( $subscription, $pattern, $planneddate );
924 $subscription is a hashref containing all the attributes of the table
926 $pattern is a hashref containing all the attributes of the table
927 'subscription_numberpatterns'.
928 $planneddate is a C4::Dates object.
929 This function get the next issue for the subscription given on input arg
934 my ($subscription, $pattern, $planneddate) = @_;
936 return unless ($subscription and $pattern);
938 my ( $newlastvalue1, $newlastvalue2, $newlastvalue3,
939 $newinnerloop1, $newinnerloop2, $newinnerloop3 );
942 if ($subscription->{'skip_serialseq'}) {
943 my @irreg = split /;/, $subscription->{'irregularity'};
945 my $irregularities = {};
946 $irregularities->{$_} = 1 foreach(@irreg);
947 my $issueno = GetFictiveIssueNumber
($subscription, $planneddate) + 1;
948 while($irregularities->{$issueno}) {
955 my $numberingmethod = $pattern->{numberingmethod
};
957 if ($numberingmethod) {
958 $calculated = $numberingmethod;
959 my $locale = $subscription->{locale
};
960 $newlastvalue1 = $subscription->{lastvalue1
} || 0;
961 $newlastvalue2 = $subscription->{lastvalue2
} || 0;
962 $newlastvalue3 = $subscription->{lastvalue3
} || 0;
963 $newinnerloop1 = $subscription->{innerloop1
} || 0;
964 $newinnerloop2 = $subscription->{innerloop2
} || 0;
965 $newinnerloop3 = $subscription->{innerloop3
} || 0;
968 $calc{$_} = 1 if ($numberingmethod =~ /\{$_\}/);
971 for(my $i = 0; $i < $count; $i++) {
973 # check if we have to increase the new value.
975 if ($newinnerloop1 >= $pattern->{every1
}) {
977 $newlastvalue1 += $pattern->{add1
};
979 # reset counter if needed.
980 $newlastvalue1 = $pattern->{setto1
} if ($newlastvalue1 > $pattern->{whenmorethan1
});
983 # check if we have to increase the new value.
985 if ($newinnerloop2 >= $pattern->{every2
}) {
987 $newlastvalue2 += $pattern->{add2
};
989 # reset counter if needed.
990 $newlastvalue2 = $pattern->{setto2
} if ($newlastvalue2 > $pattern->{whenmorethan2
});
993 # check if we have to increase the new value.
995 if ($newinnerloop3 >= $pattern->{every3
}) {
997 $newlastvalue3 += $pattern->{add3
};
999 # reset counter if needed.
1000 $newlastvalue3 = $pattern->{setto3
} if ($newlastvalue3 > $pattern->{whenmorethan3
});
1004 my $newlastvalue1string = _numeration
( $newlastvalue1, $pattern->{numbering1
}, $locale );
1005 $calculated =~ s/\{X\}/$newlastvalue1string/g;
1008 my $newlastvalue2string = _numeration
( $newlastvalue2, $pattern->{numbering2
}, $locale );
1009 $calculated =~ s/\{Y\}/$newlastvalue2string/g;
1012 my $newlastvalue3string = _numeration
( $newlastvalue3, $pattern->{numbering3
}, $locale );
1013 $calculated =~ s/\{Z\}/$newlastvalue3string/g;
1017 return ($calculated,
1018 $newlastvalue1, $newlastvalue2, $newlastvalue3,
1019 $newinnerloop1, $newinnerloop2, $newinnerloop3);
1024 $calculated = GetSeq($subscription, $pattern)
1025 $subscription is a hashref containing all the attributes of the table 'subscription'
1026 $pattern is a hashref containing all the attributes of the table 'subscription_numberpatterns'
1027 this function transforms {X},{Y},{Z} to 150,0,0 for example.
1029 the sequence in string format
1034 my ($subscription, $pattern) = @_;
1036 return unless ($subscription and $pattern);
1038 my $locale = $subscription->{locale
};
1040 my $calculated = $pattern->{numberingmethod
};
1042 my $newlastvalue1 = $subscription->{'lastvalue1'} || 0;
1043 $newlastvalue1 = _numeration
($newlastvalue1, $pattern->{numbering1
}, $locale) if ($pattern->{numbering1
}); # reset counter if needed.
1044 $calculated =~ s/\{X\}/$newlastvalue1/g;
1046 my $newlastvalue2 = $subscription->{'lastvalue2'} || 0;
1047 $newlastvalue2 = _numeration
($newlastvalue2, $pattern->{numbering2
}, $locale) if ($pattern->{numbering2
}); # reset counter if needed.
1048 $calculated =~ s/\{Y\}/$newlastvalue2/g;
1050 my $newlastvalue3 = $subscription->{'lastvalue3'} || 0;
1051 $newlastvalue3 = _numeration
($newlastvalue3, $pattern->{numbering3
}, $locale) if ($pattern->{numbering3
}); # reset counter if needed.
1052 $calculated =~ s/\{Z\}/$newlastvalue3/g;
1056 =head2 GetExpirationDate
1058 $enddate = GetExpirationDate($subscriptionid, [$startdate])
1060 this function return the next expiration date for a subscription given on input args.
1063 the enddate or undef
1067 sub GetExpirationDate
{
1068 my ( $subscriptionid, $startdate ) = @_;
1070 return unless ($subscriptionid);
1072 my $dbh = C4
::Context
->dbh;
1073 my $subscription = GetSubscription
($subscriptionid);
1076 # we don't do the same test if the subscription is based on X numbers or on X weeks/months
1077 $enddate = $startdate || $subscription->{startdate
};
1078 my @date = split( /-/, $enddate );
1079 return if ( scalar(@date) != 3 || not check_date
(@date) );
1080 my $frequency = C4
::Serials
::Frequency
::GetSubscriptionFrequency
($subscription->{periodicity
});
1081 if ( $frequency and $frequency->{unit
} ) {
1084 if ( my $length = $subscription->{numberlength
} ) {
1086 #calculate the date of the last issue.
1087 for ( my $i = 1 ; $i <= $length ; $i++ ) {
1088 $enddate = GetNextDate
( $subscription, $enddate );
1090 } elsif ( $subscription->{monthlength
} ) {
1091 if ( $$subscription{startdate
} ) {
1092 my @enddate = Add_Delta_YM
( $date[0], $date[1], $date[2], 0, $subscription->{monthlength
} );
1093 $enddate = sprintf( "%04d-%02d-%02d", $enddate[0], $enddate[1], $enddate[2] );
1095 } elsif ( $subscription->{weeklength
} ) {
1096 if ( $$subscription{startdate
} ) {
1097 my @date = split( /-/, $subscription->{startdate
} );
1098 my @enddate = Add_Delta_Days
( $date[0], $date[1], $date[2], $subscription->{weeklength
} * 7 );
1099 $enddate = sprintf( "%04d-%02d-%02d", $enddate[0], $enddate[1], $enddate[2] );
1102 $enddate = $subscription->{enddate
};
1106 return $subscription->{enddate
};
1110 =head2 CountSubscriptionFromBiblionumber
1112 $subscriptionsnumber = CountSubscriptionFromBiblionumber($biblionumber)
1113 this returns a count of the subscriptions for a given biblionumber
1115 the number of subscriptions
1119 sub CountSubscriptionFromBiblionumber
{
1120 my ($biblionumber) = @_;
1122 return unless ($biblionumber);
1124 my $dbh = C4
::Context
->dbh;
1125 my $query = "SELECT count(*) FROM subscription WHERE biblionumber=?";
1126 my $sth = $dbh->prepare($query);
1127 $sth->execute($biblionumber);
1128 my $subscriptionsnumber = $sth->fetchrow;
1129 return $subscriptionsnumber;
1132 =head2 ModSubscriptionHistory
1134 ModSubscriptionHistory($subscriptionid,$histstartdate,$enddate,$recievedlist,$missinglist,$opacnote,$librariannote);
1136 this function modifies the history of a subscription. Put your new values on input arg.
1137 returns the number of rows affected
1141 sub ModSubscriptionHistory
{
1142 my ( $subscriptionid, $histstartdate, $enddate, $receivedlist, $missinglist, $opacnote, $librariannote ) = @_;
1144 return unless ($subscriptionid);
1146 my $dbh = C4
::Context
->dbh;
1147 my $query = "UPDATE subscriptionhistory
1148 SET histstartdate=?,histenddate=?,recievedlist=?,missinglist=?,opacnote=?,librariannote=?
1149 WHERE subscriptionid=?
1151 my $sth = $dbh->prepare($query);
1152 $receivedlist =~ s/^; // if $receivedlist;
1153 $missinglist =~ s/^; // if $missinglist;
1154 $opacnote =~ s/^; // if $opacnote;
1155 $sth->execute( $histstartdate, $enddate, $receivedlist, $missinglist, $opacnote, $librariannote, $subscriptionid );
1159 # Update missinglist field, used by ModSerialStatus
1160 sub _update_missinglist
{
1161 my $subscriptionid = shift;
1163 my $dbh = C4
::Context
->dbh;
1164 my @missingserials = GetSerials2
($subscriptionid, "4,41,42,43,44,5");
1166 foreach my $missingserial (@missingserials) {
1167 if ( grep { $_ == $missingserial->{status
} } qw( 4 41 42 43 44 ) ) {
1168 $missinglist .= $missingserial->{'serialseq'} . "; ";
1169 } elsif($missingserial->{'status'} == 5) {
1170 $missinglist .= "not issued " . $missingserial->{'serialseq'} . "; ";
1173 $missinglist =~ s/; $//;
1175 UPDATE subscriptionhistory
1177 WHERE subscriptionid
= ?
1179 my $sth = $dbh->prepare($query);
1180 $sth->execute($missinglist, $subscriptionid);
1183 # Update recievedlist field, used by ModSerialStatus
1184 sub _update_receivedlist
{
1185 my $subscriptionid = shift;
1187 my $dbh = C4
::Context
->dbh;
1188 my @receivedserials = GetSerials2
($subscriptionid, "2");
1190 foreach (@receivedserials) {
1191 $receivedlist .= $_->{'serialseq'} . "; ";
1193 $receivedlist =~ s/; $//;
1195 UPDATE subscriptionhistory
1196 SET recievedlist
= ?
1197 WHERE subscriptionid
= ?
1199 my $sth = $dbh->prepare($query);
1200 $sth->execute($receivedlist, $subscriptionid);
1203 =head2 ModSerialStatus
1205 ModSerialStatus($serialid,$serialseq, $planneddate,$publisheddate,$status,$notes)
1207 This function modify the serial status. Serial status is a number.(eg 2 is "arrived")
1208 Note : if we change from "waited" to something else,then we will have to create a new "waited" entry
1212 sub ModSerialStatus
{
1213 my ( $serialid, $serialseq, $planneddate, $publisheddate, $status, $notes ) = @_;
1215 return unless ($serialid);
1217 #It is a usual serial
1218 # 1st, get previous status :
1219 my $dbh = C4
::Context
->dbh;
1220 my $query = "SELECT serial.subscriptionid,serial.status,subscription.periodicity
1221 FROM serial, subscription
1222 WHERE serial.subscriptionid=subscription.subscriptionid
1224 my $sth = $dbh->prepare($query);
1225 $sth->execute($serialid);
1226 my ( $subscriptionid, $oldstatus, $periodicity ) = $sth->fetchrow;
1227 my $frequency = GetSubscriptionFrequency
($periodicity);
1229 # change status & update subscriptionhistory
1231 if ( $status == 6 ) {
1232 DelIssue
( { 'serialid' => $serialid, 'subscriptionid' => $subscriptionid, 'serialseq' => $serialseq } );
1235 my $query = 'UPDATE serial SET serialseq=?,publisheddate=?,planneddate=?,status=?,notes=? WHERE serialid = ?';
1236 $sth = $dbh->prepare($query);
1237 $sth->execute( $serialseq, $publisheddate, $planneddate, $status, $notes, $serialid );
1238 $query = "SELECT * FROM subscription WHERE subscriptionid = ?";
1239 $sth = $dbh->prepare($query);
1240 $sth->execute($subscriptionid);
1241 my $val = $sth->fetchrow_hashref;
1242 unless ( $val->{manualhistory
} ) {
1243 if ( $status == 2 || ($oldstatus == 2 && $status != 2) ) {
1244 _update_receivedlist
($subscriptionid);
1246 my @missing_statuses = qw( 4 41 42 43 44 );
1247 if ( ( grep { $_ == $status } ( @missing_statuses, 5 ) )
1249 ( grep { $_ == $oldstatus } @missing_statuses )
1250 && ! ( grep { $_ == $status } @missing_statuses ) )
1251 || ($oldstatus == 5 && $status != 5)) {
1252 _update_missinglist
($subscriptionid);
1257 # create new waited entry if needed (ie : was a "waited" and has changed)
1258 if ( $oldstatus == 1 && $status != 1 ) {
1259 my $subscription = GetSubscription
($subscriptionid);
1260 my $pattern = C4
::Serials
::Numberpattern
::GetSubscriptionNumberpattern
($subscription->{numberpattern
});
1264 $newserialseq, $newlastvalue1, $newlastvalue2, $newlastvalue3,
1265 $newinnerloop1, $newinnerloop2, $newinnerloop3
1267 = GetNextSeq
( $subscription, $pattern, $publisheddate );
1269 # next date (calculated from actual date & frequency parameters)
1270 my $nextpublisheddate = GetNextDate
($subscription, $publisheddate, 1);
1271 my $nextpubdate = $nextpublisheddate;
1272 NewIssue
( $newserialseq, $subscriptionid, $subscription->{'biblionumber'}, 1, $nextpubdate, $nextpubdate );
1273 $query = "UPDATE subscription SET lastvalue1=?, lastvalue2=?, lastvalue3=?, innerloop1=?, innerloop2=?, innerloop3=?
1274 WHERE subscriptionid = ?";
1275 $sth = $dbh->prepare($query);
1276 $sth->execute( $newlastvalue1, $newlastvalue2, $newlastvalue3, $newinnerloop1, $newinnerloop2, $newinnerloop3, $subscriptionid );
1278 # check if an alert must be sent... (= a letter is defined & status became "arrived"
1279 if ( $subscription->{letter
} && $status == 2 && $oldstatus != 2 ) {
1280 require C4
::Letters
;
1281 C4
::Letters
::SendAlerts
( 'issue', $subscription->{subscriptionid
}, $subscription->{letter
} );
1288 =head2 GetNextExpected
1290 $nextexpected = GetNextExpected($subscriptionid)
1292 Get the planneddate for the current expected issue of the subscription.
1298 planneddate => ISO date
1303 sub GetNextExpected
{
1304 my ($subscriptionid) = @_;
1306 my $dbh = C4
::Context
->dbh;
1310 WHERE subscriptionid
= ?
1314 my $sth = $dbh->prepare($query);
1316 # Each subscription has only one 'expected' issue, with serial.status==1.
1317 $sth->execute( $subscriptionid, 1 );
1318 my $nextissue = $sth->fetchrow_hashref;
1319 if ( !$nextissue ) {
1323 WHERE subscriptionid
= ?
1324 ORDER BY publisheddate DESC
1327 $sth = $dbh->prepare($query);
1328 $sth->execute($subscriptionid);
1329 $nextissue = $sth->fetchrow_hashref;
1331 foreach(qw
/planneddate publisheddate/) {
1332 if ( !defined $nextissue->{$_} ) {
1333 # or should this default to 1st Jan ???
1334 $nextissue->{$_} = strftime
( '%Y-%m-%d', localtime );
1336 $nextissue->{$_} = ($nextissue->{$_} ne '0000-00-00')
1344 =head2 ModNextExpected
1346 ModNextExpected($subscriptionid,$date)
1348 Update the planneddate for the current expected issue of the subscription.
1349 This will modify all future prediction results.
1351 C<$date> is an ISO date.
1357 sub ModNextExpected
{
1358 my ( $subscriptionid, $date ) = @_;
1359 my $dbh = C4
::Context
->dbh;
1361 #FIXME: Would expect to only set planneddate, but we set both on new issue creation, so updating it here
1362 my $sth = $dbh->prepare('UPDATE serial SET planneddate=?,publisheddate=? WHERE subscriptionid=? AND status=?');
1364 # Each subscription has only one 'expected' issue, with serial.status==1.
1365 $sth->execute( $date, $date, $subscriptionid, 1 );
1370 =head2 GetSubscriptionIrregularities
1374 =item @irreg = &GetSubscriptionIrregularities($subscriptionid);
1375 get the list of irregularities for a subscription
1381 sub GetSubscriptionIrregularities
{
1382 my $subscriptionid = shift;
1384 return unless $subscriptionid;
1386 my $dbh = C4
::Context
->dbh;
1390 WHERE subscriptionid
= ?
1392 my $sth = $dbh->prepare($query);
1393 $sth->execute($subscriptionid);
1395 my ($result) = $sth->fetchrow_array;
1396 my @irreg = split /;/, $result;
1401 =head2 ModSubscription
1403 this function modifies a subscription. Put all new values on input args.
1404 returns the number of rows affected
1408 sub ModSubscription
{
1410 $auser, $branchcode, $aqbooksellerid, $cost, $aqbudgetid, $startdate,
1411 $periodicity, $firstacquidate, $irregularity, $numberpattern, $locale,
1412 $numberlength, $weeklength, $monthlength, $lastvalue1, $innerloop1,
1413 $lastvalue2, $innerloop2, $lastvalue3, $innerloop3, $status,
1414 $biblionumber, $callnumber, $notes, $letter, $manualhistory,
1415 $internalnotes, $serialsadditems, $staffdisplaycount, $opacdisplaycount,
1416 $graceperiod, $location, $enddate, $subscriptionid, $skip_serialseq
1419 my $dbh = C4
::Context
->dbh;
1420 my $query = "UPDATE subscription
1421 SET librarian=?, branchcode=?, aqbooksellerid=?, cost=?, aqbudgetid=?,
1422 startdate=?, periodicity=?, firstacquidate=?, irregularity=?,
1423 numberpattern=?, locale=?, numberlength=?, weeklength=?, monthlength=?,
1424 lastvalue1=?, innerloop1=?, lastvalue2=?, innerloop2=?,
1425 lastvalue3=?, innerloop3=?, status=?, biblionumber=?,
1426 callnumber=?, notes=?, letter=?, manualhistory=?,
1427 internalnotes=?, serialsadditems=?, staffdisplaycount=?,
1428 opacdisplaycount=?, graceperiod=?, location = ?, enddate=?,
1430 WHERE subscriptionid = ?";
1432 my $sth = $dbh->prepare($query);
1434 $auser, $branchcode, $aqbooksellerid, $cost,
1435 $aqbudgetid, $startdate, $periodicity, $firstacquidate,
1436 $irregularity, $numberpattern, $locale, $numberlength,
1437 $weeklength, $monthlength, $lastvalue1, $innerloop1,
1438 $lastvalue2, $innerloop2, $lastvalue3, $innerloop3,
1439 $status, $biblionumber, $callnumber, $notes,
1440 $letter, ($manualhistory ?
$manualhistory : 0),
1441 $internalnotes, $serialsadditems, $staffdisplaycount, $opacdisplaycount,
1442 $graceperiod, $location, $enddate, $skip_serialseq,
1445 my $rows = $sth->rows;
1447 logaction
( "SERIAL", "MODIFY", $subscriptionid, "" ) if C4
::Context
->preference("SubscriptionLog");
1451 =head2 NewSubscription
1453 $subscriptionid = &NewSubscription($auser,branchcode,$aqbooksellerid,$cost,$aqbudgetid,$biblionumber,
1454 $startdate,$periodicity,$numberlength,$weeklength,$monthlength,
1455 $lastvalue1,$innerloop1,$lastvalue2,$innerloop2,$lastvalue3,$innerloop3,
1456 $status, $notes, $letter, $firstacquidate, $irregularity, $numberpattern,
1457 $locale, $callnumber, $manualhistory, $internalnotes, $serialsadditems,
1458 $staffdisplaycount, $opacdisplaycount, $graceperiod, $location, $enddate, $skip_serialseq);
1460 Create a new subscription with value given on input args.
1463 the id of this new subscription
1467 sub NewSubscription
{
1469 $auser, $branchcode, $aqbooksellerid, $cost, $aqbudgetid, $biblionumber,
1470 $startdate, $periodicity, $numberlength, $weeklength, $monthlength,
1471 $lastvalue1, $innerloop1, $lastvalue2, $innerloop2, $lastvalue3,
1472 $innerloop3, $status, $notes, $letter, $firstacquidate, $irregularity,
1473 $numberpattern, $locale, $callnumber, $manualhistory, $internalnotes,
1474 $serialsadditems, $staffdisplaycount, $opacdisplaycount, $graceperiod,
1475 $location, $enddate, $skip_serialseq
1477 my $dbh = C4
::Context
->dbh;
1479 #save subscription (insert into database)
1481 INSERT INTO subscription
1482 (librarian
, branchcode
, aqbooksellerid
, cost
, aqbudgetid
,
1483 biblionumber
, startdate
, periodicity
, numberlength
, weeklength
,
1484 monthlength
, lastvalue1
, innerloop1
, lastvalue2
, innerloop2
,
1485 lastvalue3
, innerloop3
, status
, notes
, letter
, firstacquidate
,
1486 irregularity
, numberpattern
, locale
, callnumber
,
1487 manualhistory
, internalnotes
, serialsadditems
, staffdisplaycount
,
1488 opacdisplaycount
, graceperiod
, location
, enddate
, skip_serialseq
)
1489 VALUES
(?
,?
,?
,?
,?
,?
,?
,?
,?
,?
,?
,?
,?
,?
,?
,?
,?
,?
,?
,?
,?
,?
,?
,?
,?
,?
,?
,?
,?
,?
,?
,?
,?
,?
)
1491 my $sth = $dbh->prepare($query);
1493 $auser, $branchcode, $aqbooksellerid, $cost, $aqbudgetid, $biblionumber,
1494 $startdate, $periodicity, $numberlength, $weeklength,
1495 $monthlength, $lastvalue1, $innerloop1, $lastvalue2, $innerloop2,
1496 $lastvalue3, $innerloop3, $status, $notes, $letter,
1497 $firstacquidate, $irregularity, $numberpattern, $locale, $callnumber,
1498 $manualhistory, $internalnotes, $serialsadditems, $staffdisplaycount,
1499 $opacdisplaycount, $graceperiod, $location, $enddate, $skip_serialseq
1502 my $subscriptionid = $dbh->{'mysql_insertid'};
1504 $enddate = GetExpirationDate
( $subscriptionid, $startdate );
1508 WHERE subscriptionid
=?
1510 $sth = $dbh->prepare($query);
1511 $sth->execute( $enddate, $subscriptionid );
1514 # then create the 1st expected number
1516 INSERT INTO subscriptionhistory
1517 (biblionumber
, subscriptionid
, histstartdate
, opacnote
, librariannote
)
1520 $sth = $dbh->prepare($query);
1521 $sth->execute( $biblionumber, $subscriptionid, $startdate, $notes, $internalnotes );
1523 # reread subscription to get a hash (for calculation of the 1st issue number)
1524 my $subscription = GetSubscription
($subscriptionid);
1525 my $pattern = C4
::Serials
::Numberpattern
::GetSubscriptionNumberpattern
($subscription->{numberpattern
});
1527 # calculate issue number
1528 my $serialseq = GetSeq
($subscription, $pattern) || q{};
1531 (serialseq
,subscriptionid
,biblionumber
,status
, planneddate
, publisheddate
)
1532 VALUES
(?
,?
,?
,?
,?
,?
)
1534 $sth = $dbh->prepare($query);
1535 $sth->execute( $serialseq, $subscriptionid, $biblionumber, 1, $firstacquidate, $firstacquidate );
1537 logaction
( "SERIAL", "ADD", $subscriptionid, "" ) if C4
::Context
->preference("SubscriptionLog");
1539 #set serial flag on biblio if not already set.
1540 my $bib = GetBiblio
($biblionumber);
1541 if ( $bib and !$bib->{'serial'} ) {
1542 my $record = GetMarcBiblio
($biblionumber);
1543 my ( $tag, $subf ) = GetMarcFromKohaField
( 'biblio.serial', $bib->{'frameworkcode'} );
1545 eval { $record->field($tag)->update( $subf => 1 ); };
1547 ModBiblio
( $record, $biblionumber, $bib->{'frameworkcode'} );
1549 return $subscriptionid;
1552 =head2 ReNewSubscription
1554 ReNewSubscription($subscriptionid,$user,$startdate,$numberlength,$weeklength,$monthlength,$note)
1556 this function renew a subscription with values given on input args.
1560 sub ReNewSubscription
{
1561 my ( $subscriptionid, $user, $startdate, $numberlength, $weeklength, $monthlength, $note ) = @_;
1562 my $dbh = C4
::Context
->dbh;
1563 my $subscription = GetSubscription
($subscriptionid);
1567 LEFT JOIN biblioitems ON biblio
.biblionumber
=biblioitems
.biblionumber
1568 WHERE biblio
.biblionumber
=?
1570 my $sth = $dbh->prepare($query);
1571 $sth->execute( $subscription->{biblionumber
} );
1572 my $biblio = $sth->fetchrow_hashref;
1574 if ( C4
::Context
->preference("RenewSerialAddsSuggestion") ) {
1575 require C4
::Suggestions
;
1576 C4
::Suggestions
::NewSuggestion
(
1577 { 'suggestedby' => $user,
1578 'title' => $subscription->{bibliotitle
},
1579 'author' => $biblio->{author
},
1580 'publishercode' => $biblio->{publishercode
},
1581 'note' => $biblio->{note
},
1582 'biblionumber' => $subscription->{biblionumber
}
1587 # renew subscription
1590 SET startdate
=?
,numberlength
=?
,weeklength
=?
,monthlength
=?
,reneweddate
=NOW
()
1591 WHERE subscriptionid
=?
1593 $sth = $dbh->prepare($query);
1594 $sth->execute( $startdate, $numberlength, $weeklength, $monthlength, $subscriptionid );
1595 my $enddate = GetExpirationDate
($subscriptionid);
1596 $debug && warn "enddate :$enddate";
1600 WHERE subscriptionid
=?
1602 $sth = $dbh->prepare($query);
1603 $sth->execute( $enddate, $subscriptionid );
1605 UPDATE subscriptionhistory
1607 WHERE subscriptionid
=?
1609 $sth = $dbh->prepare($query);
1610 $sth->execute( $enddate, $subscriptionid );
1612 logaction
( "SERIAL", "RENEW", $subscriptionid, "" ) if C4
::Context
->preference("SubscriptionLog");
1618 NewIssue($serialseq,$subscriptionid,$biblionumber,$status, $planneddate, $publisheddate, $notes)
1620 Create a new issue stored on the database.
1621 Note : we have to update the recievedlist and missinglist on subscriptionhistory for this subscription.
1622 returns the serial id
1627 my ( $serialseq, $subscriptionid, $biblionumber, $status, $planneddate, $publisheddate, $notes ) = @_;
1628 ### FIXME biblionumber CAN be provided by subscriptionid. So Do we STILL NEED IT ?
1630 return unless ($subscriptionid);
1632 my $dbh = C4
::Context
->dbh;
1635 (serialseq
,subscriptionid
,biblionumber
,status
,publisheddate
,planneddate
,notes
)
1636 VALUES
(?
,?
,?
,?
,?
,?
,?
)
1638 my $sth = $dbh->prepare($query);
1639 $sth->execute( $serialseq, $subscriptionid, $biblionumber, $status, $publisheddate, $planneddate, $notes );
1640 my $serialid = $dbh->{'mysql_insertid'};
1642 SELECT missinglist
,recievedlist
1643 FROM subscriptionhistory
1644 WHERE subscriptionid
=?
1646 $sth = $dbh->prepare($query);
1647 $sth->execute($subscriptionid);
1648 my ( $missinglist, $recievedlist ) = $sth->fetchrow;
1650 if ( $status == 2 ) {
1651 ### TODO Add a feature that improves recognition and description.
1652 ### As such count (serialseq) i.e. : N18,2(N19),N20
1653 ### Would use substr and index But be careful to previous presence of ()
1654 $recievedlist .= "; $serialseq" unless (index($recievedlist,$serialseq)>0);
1656 if ( $status == 4 ) {
1657 $missinglist .= "; $serialseq" unless (index($missinglist,$serialseq)>0);
1660 UPDATE subscriptionhistory
1661 SET recievedlist
=?
, missinglist
=?
1662 WHERE subscriptionid
=?
1664 $sth = $dbh->prepare($query);
1665 $recievedlist =~ s/^; //;
1666 $missinglist =~ s/^; //;
1667 $sth->execute( $recievedlist, $missinglist, $subscriptionid );
1671 =head2 ItemizeSerials
1673 ItemizeSerials($serialid, $info);
1674 $info is a hashref containing barcode branch, itemcallnumber, status, location
1675 $serialid the serialid
1677 1 if the itemize is a succes.
1678 0 and @error otherwise. @error containts the list of errors found.
1682 sub ItemizeSerials
{
1683 my ( $serialid, $info ) = @_;
1685 return unless ($serialid);
1687 my $now = POSIX
::strftime
( "%Y-%m-%d", localtime );
1689 my $dbh = C4
::Context
->dbh;
1695 my $sth = $dbh->prepare($query);
1696 $sth->execute($serialid);
1697 my $data = $sth->fetchrow_hashref;
1698 if ( C4
::Context
->preference("RoutingSerials") ) {
1700 # check for existing biblioitem relating to serial issue
1701 my ( $count, @results ) = GetBiblioItemByBiblioNumber
( $data->{'biblionumber'} );
1703 for ( my $i = 0 ; $i < $count ; $i++ ) {
1704 if ( $results[$i]->{'volumeddesc'} eq $data->{'serialseq'} . ' (' . $data->{'planneddate'} . ')' ) {
1705 $bibitemno = $results[$i]->{'biblioitemnumber'};
1709 if ( $bibitemno == 0 ) {
1710 my $sth = $dbh->prepare( "SELECT * FROM biblioitems WHERE biblionumber = ? ORDER BY biblioitemnumber DESC" );
1711 $sth->execute( $data->{'biblionumber'} );
1712 my $biblioitem = $sth->fetchrow_hashref;
1713 $biblioitem->{'volumedate'} = $data->{planneddate
};
1714 $biblioitem->{'volumeddesc'} = $data->{serialseq
} . ' (' . format_date
( $data->{'planneddate'} ) . ')';
1715 $biblioitem->{'dewey'} = $info->{itemcallnumber
};
1719 my $fwk = GetFrameworkCode
( $data->{'biblionumber'} );
1720 if ( $info->{barcode
} ) {
1722 if ( is_barcode_in_use
( $info->{barcode
} ) ) {
1723 push @errors, 'barcode_not_unique';
1725 my $marcrecord = MARC
::Record
->new();
1726 my ( $tag, $subfield ) = GetMarcFromKohaField
( "items.barcode", $fwk );
1727 my $newField = MARC
::Field
->new( "$tag", '', '', "$subfield" => $info->{barcode
} );
1728 $marcrecord->insert_fields_ordered($newField);
1729 if ( $info->{branch
} ) {
1730 my ( $tag, $subfield ) = GetMarcFromKohaField
( "items.homebranch", $fwk );
1732 #warn "items.homebranch : $tag , $subfield";
1733 if ( $marcrecord->field($tag) ) {
1734 $marcrecord->field($tag)->add_subfields( "$subfield" => $info->{branch
} );
1736 my $newField = MARC
::Field
->new( "$tag", '', '', "$subfield" => $info->{branch
} );
1737 $marcrecord->insert_fields_ordered($newField);
1739 ( $tag, $subfield ) = GetMarcFromKohaField
( "items.holdingbranch", $fwk );
1741 #warn "items.holdingbranch : $tag , $subfield";
1742 if ( $marcrecord->field($tag) ) {
1743 $marcrecord->field($tag)->add_subfields( "$subfield" => $info->{branch
} );
1745 my $newField = MARC
::Field
->new( "$tag", '', '', "$subfield" => $info->{branch
} );
1746 $marcrecord->insert_fields_ordered($newField);
1749 if ( $info->{itemcallnumber
} ) {
1750 my ( $tag, $subfield ) = GetMarcFromKohaField
( "items.itemcallnumber", $fwk );
1752 if ( $marcrecord->field($tag) ) {
1753 $marcrecord->field($tag)->add_subfields( "$subfield" => $info->{itemcallnumber
} );
1755 my $newField = MARC
::Field
->new( "$tag", '', '', "$subfield" => $info->{itemcallnumber
} );
1756 $marcrecord->insert_fields_ordered($newField);
1759 if ( $info->{notes
} ) {
1760 my ( $tag, $subfield ) = GetMarcFromKohaField
( "items.itemnotes", $fwk );
1762 if ( $marcrecord->field($tag) ) {
1763 $marcrecord->field($tag)->add_subfields( "$subfield" => $info->{notes
} );
1765 my $newField = MARC
::Field
->new( "$tag", '', '', "$subfield" => $info->{notes
} );
1766 $marcrecord->insert_fields_ordered($newField);
1769 if ( $info->{location
} ) {
1770 my ( $tag, $subfield ) = GetMarcFromKohaField
( "items.location", $fwk );
1772 if ( $marcrecord->field($tag) ) {
1773 $marcrecord->field($tag)->add_subfields( "$subfield" => $info->{location
} );
1775 my $newField = MARC
::Field
->new( "$tag", '', '', "$subfield" => $info->{location
} );
1776 $marcrecord->insert_fields_ordered($newField);
1779 if ( $info->{status
} ) {
1780 my ( $tag, $subfield ) = GetMarcFromKohaField
( "items.notforloan", $fwk );
1782 if ( $marcrecord->field($tag) ) {
1783 $marcrecord->field($tag)->add_subfields( "$subfield" => $info->{status
} );
1785 my $newField = MARC
::Field
->new( "$tag", '', '', "$subfield" => $info->{status
} );
1786 $marcrecord->insert_fields_ordered($newField);
1789 if ( C4
::Context
->preference("RoutingSerials") ) {
1790 my ( $tag, $subfield ) = GetMarcFromKohaField
( "items.dateaccessioned", $fwk );
1791 if ( $marcrecord->field($tag) ) {
1792 $marcrecord->field($tag)->add_subfields( "$subfield" => $now );
1794 my $newField = MARC
::Field
->new( "$tag", '', '', "$subfield" => $now );
1795 $marcrecord->insert_fields_ordered($newField);
1799 C4
::Items
::AddItemFromMarc
( $marcrecord, $data->{'biblionumber'} );
1802 return ( 0, @errors );
1806 =head2 HasSubscriptionStrictlyExpired
1808 1 or 0 = HasSubscriptionStrictlyExpired($subscriptionid)
1810 the subscription has stricly expired when today > the end subscription date
1813 1 if true, 0 if false, -1 if the expiration date is not set.
1817 sub HasSubscriptionStrictlyExpired
{
1819 # Getting end of subscription date
1820 my ($subscriptionid) = @_;
1822 return unless ($subscriptionid);
1824 my $dbh = C4
::Context
->dbh;
1825 my $subscription = GetSubscription
($subscriptionid);
1826 my $expirationdate = $subscription->{enddate
} || GetExpirationDate
($subscriptionid);
1828 # If the expiration date is set
1829 if ( $expirationdate != 0 ) {
1830 my ( $endyear, $endmonth, $endday ) = split( '-', $expirationdate );
1832 # Getting today's date
1833 my ( $nowyear, $nowmonth, $nowday ) = Today
();
1835 # if today's date > expiration date, then the subscription has stricly expired
1836 if ( Delta_Days
( $nowyear, $nowmonth, $nowday, $endyear, $endmonth, $endday ) < 0 ) {
1843 # There are some cases where the expiration date is not set
1844 # As we can't determine if the subscription has expired on a date-basis,
1850 =head2 HasSubscriptionExpired
1852 $has_expired = HasSubscriptionExpired($subscriptionid)
1854 the subscription has expired when the next issue to arrive is out of subscription limit.
1857 0 if the subscription has not expired
1858 1 if the subscription has expired
1859 2 if has subscription does not have a valid expiration date set
1863 sub HasSubscriptionExpired
{
1864 my ($subscriptionid) = @_;
1866 return unless ($subscriptionid);
1868 my $dbh = C4
::Context
->dbh;
1869 my $subscription = GetSubscription
($subscriptionid);
1870 my $frequency = C4
::Serials
::Frequency
::GetSubscriptionFrequency
($subscription->{periodicity
});
1871 if ( $frequency and $frequency->{unit
} ) {
1872 my $expirationdate = $subscription->{enddate
} || GetExpirationDate
($subscriptionid);
1873 if (!defined $expirationdate) {
1874 $expirationdate = q{};
1877 SELECT max
(planneddate
)
1879 WHERE subscriptionid
=?
1881 my $sth = $dbh->prepare($query);
1882 $sth->execute($subscriptionid);
1883 my ($res) = $sth->fetchrow;
1884 if (!$res || $res=~m/^0000/) {
1887 my @res = split( /-/, $res );
1888 my @endofsubscriptiondate = split( /-/, $expirationdate );
1889 return 2 if ( scalar(@res) != 3 || scalar(@endofsubscriptiondate) != 3 || not check_date
(@res) || not check_date
(@endofsubscriptiondate) );
1891 if ( ( @endofsubscriptiondate && Delta_Days
( $res[0], $res[1], $res[2], $endofsubscriptiondate[0], $endofsubscriptiondate[1], $endofsubscriptiondate[2] ) <= 0 )
1896 if ( $subscription->{'numberlength'} ) {
1897 my $countreceived = countissuesfrom
( $subscriptionid, $subscription->{'startdate'} );
1898 return 1 if ( $countreceived > $subscription->{'numberlength'} );
1904 return 0; # Notice that you'll never get here.
1907 =head2 SetDistributedto
1909 SetDistributedto($distributedto,$subscriptionid);
1910 This function update the value of distributedto for a subscription given on input arg.
1914 sub SetDistributedto
{
1915 my ( $distributedto, $subscriptionid ) = @_;
1916 my $dbh = C4
::Context
->dbh;
1920 WHERE subscriptionid
=?
1922 my $sth = $dbh->prepare($query);
1923 $sth->execute( $distributedto, $subscriptionid );
1927 =head2 DelSubscription
1929 DelSubscription($subscriptionid)
1930 this function deletes subscription which has $subscriptionid as id.
1934 sub DelSubscription
{
1935 my ($subscriptionid) = @_;
1936 my $dbh = C4
::Context
->dbh;
1937 $subscriptionid = $dbh->quote($subscriptionid);
1938 $dbh->do("DELETE FROM subscription WHERE subscriptionid=$subscriptionid");
1939 $dbh->do("DELETE FROM subscriptionhistory WHERE subscriptionid=$subscriptionid");
1940 $dbh->do("DELETE FROM serial WHERE subscriptionid=$subscriptionid");
1942 logaction
( "SERIAL", "DELETE", $subscriptionid, "" ) if C4
::Context
->preference("SubscriptionLog");
1947 DelIssue($serialseq,$subscriptionid)
1948 this function deletes an issue which has $serialseq and $subscriptionid given on input arg.
1950 returns the number of rows affected
1955 my ($dataissue) = @_;
1956 my $dbh = C4
::Context
->dbh;
1957 ### TODO Add itemdeletion. Would need to get itemnumbers. Should be in a pref ?
1962 AND subscriptionid
= ?
1964 my $mainsth = $dbh->prepare($query);
1965 $mainsth->execute( $dataissue->{'serialid'}, $dataissue->{'subscriptionid'} );
1967 #Delete element from subscription history
1968 $query = "SELECT * FROM subscription WHERE subscriptionid = ?";
1969 my $sth = $dbh->prepare($query);
1970 $sth->execute( $dataissue->{'subscriptionid'} );
1971 my $val = $sth->fetchrow_hashref;
1972 unless ( $val->{manualhistory
} ) {
1974 SELECT
* FROM subscriptionhistory
1975 WHERE subscriptionid
= ?
1977 my $sth = $dbh->prepare($query);
1978 $sth->execute( $dataissue->{'subscriptionid'} );
1979 my $data = $sth->fetchrow_hashref;
1980 my $serialseq = $dataissue->{'serialseq'};
1981 $data->{'missinglist'} =~ s/\b$serialseq\b//;
1982 $data->{'recievedlist'} =~ s/\b$serialseq\b//;
1983 my $strsth = "UPDATE subscriptionhistory SET " . join( ",", map { join( "=", $_, $dbh->quote( $data->{$_} ) ) } keys %$data ) . " WHERE subscriptionid=?";
1984 $sth = $dbh->prepare($strsth);
1985 $sth->execute( $dataissue->{'subscriptionid'} );
1988 return $mainsth->rows;
1991 =head2 GetLateOrMissingIssues
1993 @issuelist = GetLateMissingIssues($supplierid,$serialid)
1995 this function selects missing issues on database - where serial.status = 4 or serial.status=3 or planneddate<now
1998 the issuelist as an array of hash refs. Each element of this array contains
1999 name,title,planneddate,serialseq,serial.subscriptionid from tables : subscription, serial & biblio
2003 sub GetLateOrMissingIssues
{
2004 my ( $supplierid, $serialid, $order ) = @_;
2006 return unless ( $supplierid or $serialid );
2008 my $dbh = C4
::Context
->dbh;
2012 $byserial = "and serialid = " . $serialid;
2015 $order .= ", title";
2020 $sth = $dbh->prepare(
2022 serialid, aqbooksellerid, name,
2023 biblio.title, biblioitems.issn, planneddate, serialseq,
2024 serial.status, serial.subscriptionid, claimdate,
2025 subscription.branchcode
2027 LEFT JOIN subscription ON serial.subscriptionid=subscription.subscriptionid
2028 LEFT JOIN biblio ON subscription.biblionumber=biblio.biblionumber
2029 LEFT JOIN biblioitems ON subscription.biblionumber=biblioitems.biblionumber
2030 LEFT JOIN aqbooksellers ON subscription.aqbooksellerid = aqbooksellers.id
2031 WHERE subscription.subscriptionid = serial.subscriptionid
2032 AND (serial.STATUS IN (4, 41, 42, 43, 44) OR ((planneddate < now() AND serial.STATUS =1) OR serial.STATUS = 3 OR serial.STATUS = 7))
2033 AND subscription.aqbooksellerid=$supplierid
2038 $sth = $dbh->prepare(
2040 serialid, aqbooksellerid, name,
2041 biblio.title, planneddate, serialseq,
2042 serial.status, serial.subscriptionid, claimdate,
2043 subscription.branchcode
2045 LEFT JOIN subscription ON serial.subscriptionid=subscription.subscriptionid
2046 LEFT JOIN biblio ON subscription.biblionumber=biblio.biblionumber
2047 LEFT JOIN aqbooksellers ON subscription.aqbooksellerid = aqbooksellers.id
2048 WHERE subscription.subscriptionid = serial.subscriptionid
2049 AND (serial.STATUS IN (4, 41, 42, 43, 44) OR ((planneddate < now() AND serial.STATUS =1) OR serial.STATUS = 3 OR serial.STATUS = 7))
2056 while ( my $line = $sth->fetchrow_hashref ) {
2058 if ($line->{planneddate
} && $line->{planneddate
} !~/^0+\-/) {
2059 $line->{planneddate
} = format_date
( $line->{planneddate
} );
2061 if ($line->{claimdate
} && $line->{claimdate
} !~/^0+\-/) {
2062 $line->{claimdate
} = format_date
( $line->{claimdate
} );
2064 $line->{"status".$line->{status
}} = 1;
2065 push @issuelist, $line;
2070 =head2 removeMissingIssue
2072 removeMissingIssue($subscriptionid)
2074 this function removes an issue from being part of the missing string in
2075 subscriptionlist.missinglist column
2077 called when a missing issue is found from the serials-recieve.pl file
2081 sub removeMissingIssue
{
2082 my ( $sequence, $subscriptionid ) = @_;
2084 return unless ($sequence and $subscriptionid);
2086 my $dbh = C4
::Context
->dbh;
2087 my $sth = $dbh->prepare("SELECT * FROM subscriptionhistory WHERE subscriptionid = ?");
2088 $sth->execute($subscriptionid);
2089 my $data = $sth->fetchrow_hashref;
2090 my $missinglist = $data->{'missinglist'};
2091 my $missinglistbefore = $missinglist;
2093 # warn $missinglist." before";
2094 $missinglist =~ s/($sequence)//;
2096 # warn $missinglist." after";
2097 if ( $missinglist ne $missinglistbefore ) {
2098 $missinglist =~ s/\|\s\|/\|/g;
2099 $missinglist =~ s/^\| //g;
2100 $missinglist =~ s/\|$//g;
2101 my $sth2 = $dbh->prepare(
2102 "UPDATE subscriptionhistory
2104 WHERE subscriptionid = ?"
2106 $sth2->execute( $missinglist, $subscriptionid );
2113 &updateClaim($serialid)
2115 this function updates the time when a claim is issued for late/missing items
2117 called from claims.pl file
2122 my ($serialid) = @_;
2123 my $dbh = C4
::Context
->dbh;
2124 my $sth = $dbh->prepare(
2125 "UPDATE serial SET claimdate = now()
2129 $sth->execute($serialid);
2133 =head2 getsupplierbyserialid
2135 $result = getsupplierbyserialid($serialid)
2137 this function is used to find the supplier id given a serial id
2140 hashref containing serialid, subscriptionid, and aqbooksellerid
2144 sub getsupplierbyserialid
{
2145 my ($serialid) = @_;
2146 my $dbh = C4
::Context
->dbh;
2147 my $sth = $dbh->prepare(
2148 "SELECT serialid, serial.subscriptionid, aqbooksellerid
2150 LEFT JOIN subscription ON serial.subscriptionid = subscription.subscriptionid
2154 $sth->execute($serialid);
2155 my $line = $sth->fetchrow_hashref;
2156 my $result = $line->{'aqbooksellerid'};
2160 =head2 check_routing
2162 $result = &check_routing($subscriptionid)
2164 this function checks to see if a serial has a routing list and returns the count of routingid
2165 used to show either an 'add' or 'edit' link
2170 my ($subscriptionid) = @_;
2172 return unless ($subscriptionid);
2174 my $dbh = C4
::Context
->dbh;
2175 my $sth = $dbh->prepare(
2176 "SELECT count(routingid) routingids FROM subscription LEFT JOIN subscriptionroutinglist
2177 ON subscription.subscriptionid = subscriptionroutinglist.subscriptionid
2178 WHERE subscription.subscriptionid = ? ORDER BY ranking ASC
2181 $sth->execute($subscriptionid);
2182 my $line = $sth->fetchrow_hashref;
2183 my $result = $line->{'routingids'};
2187 =head2 addroutingmember
2189 addroutingmember($borrowernumber,$subscriptionid)
2191 this function takes a borrowernumber and subscriptionid and adds the member to the
2192 routing list for that serial subscription and gives them a rank on the list
2193 of either 1 or highest current rank + 1
2197 sub addroutingmember
{
2198 my ( $borrowernumber, $subscriptionid ) = @_;
2200 return unless ($borrowernumber and $subscriptionid);
2203 my $dbh = C4
::Context
->dbh;
2204 my $sth = $dbh->prepare( "SELECT max(ranking) rank FROM subscriptionroutinglist WHERE subscriptionid = ?" );
2205 $sth->execute($subscriptionid);
2206 while ( my $line = $sth->fetchrow_hashref ) {
2207 if ( $line->{'rank'} > 0 ) {
2208 $rank = $line->{'rank'} + 1;
2213 $sth = $dbh->prepare( "INSERT INTO subscriptionroutinglist (subscriptionid,borrowernumber,ranking) VALUES (?,?,?)" );
2214 $sth->execute( $subscriptionid, $borrowernumber, $rank );
2217 =head2 reorder_members
2219 reorder_members($subscriptionid,$routingid,$rank)
2221 this function is used to reorder the routing list
2223 it takes the routingid of the member one wants to re-rank and the rank it is to move to
2224 - it gets all members on list puts their routingid's into an array
2225 - removes the one in the array that is $routingid
2226 - then reinjects $routingid at point indicated by $rank
2227 - then update the database with the routingids in the new order
2231 sub reorder_members
{
2232 my ( $subscriptionid, $routingid, $rank ) = @_;
2233 my $dbh = C4
::Context
->dbh;
2234 my $sth = $dbh->prepare( "SELECT * FROM subscriptionroutinglist WHERE subscriptionid = ? ORDER BY ranking ASC" );
2235 $sth->execute($subscriptionid);
2237 while ( my $line = $sth->fetchrow_hashref ) {
2238 push( @result, $line->{'routingid'} );
2241 # To find the matching index
2243 my $key = -1; # to allow for 0 being a valid response
2244 for ( $i = 0 ; $i < @result ; $i++ ) {
2245 if ( $routingid == $result[$i] ) {
2246 $key = $i; # save the index
2251 # if index exists in array then move it to new position
2252 if ( $key > -1 && $rank > 0 ) {
2253 my $new_rank = $rank - 1; # $new_rank is what you want the new index to be in the array
2254 my $moving_item = splice( @result, $key, 1 );
2255 splice( @result, $new_rank, 0, $moving_item );
2257 for ( my $j = 0 ; $j < @result ; $j++ ) {
2258 my $sth = $dbh->prepare( "UPDATE subscriptionroutinglist SET ranking = '" . ( $j + 1 ) . "' WHERE routingid = '" . $result[$j] . "'" );
2264 =head2 delroutingmember
2266 delroutingmember($routingid,$subscriptionid)
2268 this function either deletes one member from routing list if $routingid exists otherwise
2269 deletes all members from the routing list
2273 sub delroutingmember
{
2275 # if $routingid exists then deletes that row otherwise deletes all with $subscriptionid
2276 my ( $routingid, $subscriptionid ) = @_;
2277 my $dbh = C4
::Context
->dbh;
2279 my $sth = $dbh->prepare("DELETE FROM subscriptionroutinglist WHERE routingid = ?");
2280 $sth->execute($routingid);
2281 reorder_members
( $subscriptionid, $routingid );
2283 my $sth = $dbh->prepare("DELETE FROM subscriptionroutinglist WHERE subscriptionid = ?");
2284 $sth->execute($subscriptionid);
2289 =head2 getroutinglist
2291 @routinglist = getroutinglist($subscriptionid)
2293 this gets the info from the subscriptionroutinglist for $subscriptionid
2296 the routinglist as an array. Each element of the array contains a hash_ref containing
2297 routingid - a unique id, borrowernumber, ranking, and biblionumber of subscription
2301 sub getroutinglist
{
2302 my ($subscriptionid) = @_;
2303 my $dbh = C4
::Context
->dbh;
2304 my $sth = $dbh->prepare(
2305 'SELECT routingid, borrowernumber, ranking, biblionumber
2307 JOIN subscriptionroutinglist ON subscription.subscriptionid = subscriptionroutinglist.subscriptionid
2308 WHERE subscription.subscriptionid = ? ORDER BY ranking ASC'
2310 $sth->execute($subscriptionid);
2311 my $routinglist = $sth->fetchall_arrayref({});
2312 return @
{$routinglist};
2315 =head2 countissuesfrom
2317 $result = countissuesfrom($subscriptionid,$startdate)
2319 Returns a count of serial rows matching the given subsctiptionid
2320 with published date greater than startdate
2324 sub countissuesfrom
{
2325 my ( $subscriptionid, $startdate ) = @_;
2326 my $dbh = C4
::Context
->dbh;
2330 WHERE subscriptionid
=?
2331 AND serial
.publisheddate
>?
2333 my $sth = $dbh->prepare($query);
2334 $sth->execute( $subscriptionid, $startdate );
2335 my ($countreceived) = $sth->fetchrow;
2336 return $countreceived;
2341 $result = CountIssues($subscriptionid)
2343 Returns a count of serial rows matching the given subsctiptionid
2348 my ($subscriptionid) = @_;
2349 my $dbh = C4
::Context
->dbh;
2353 WHERE subscriptionid
=?
2355 my $sth = $dbh->prepare($query);
2356 $sth->execute($subscriptionid);
2357 my ($countreceived) = $sth->fetchrow;
2358 return $countreceived;
2363 $result = HasItems($subscriptionid)
2365 returns a count of items from serial matching the subscriptionid
2370 my ($subscriptionid) = @_;
2371 my $dbh = C4
::Context
->dbh;
2373 SELECT COUNT
(serialitems
.itemnumber
)
2375 LEFT JOIN serialitems USING
(serialid
)
2376 WHERE subscriptionid
=? AND serialitems
.serialid IS NOT NULL
2378 my $sth=$dbh->prepare($query);
2379 $sth->execute($subscriptionid);
2380 my ($countitems)=$sth->fetchrow_array();
2384 =head2 abouttoexpire
2386 $result = abouttoexpire($subscriptionid)
2388 this function alerts you to the penultimate issue for a serial subscription
2390 returns 1 - if this is the penultimate issue
2396 my ($subscriptionid) = @_;
2397 my $dbh = C4
::Context
->dbh;
2398 my $subscription = GetSubscription
($subscriptionid);
2399 my $per = $subscription->{'periodicity'};
2400 my $frequency = C4
::Serials
::Frequency
::GetSubscriptionFrequency
($per);
2401 if ($frequency and $frequency->{unit
}){
2402 my $expirationdate = GetExpirationDate
($subscriptionid);
2403 my ($res) = $dbh->selectrow_array('select max(planneddate) from serial where subscriptionid = ?', undef, $subscriptionid);
2404 my $nextdate = GetNextDate
($subscription, $res);
2405 if(Date
::Calc
::Delta_Days
(
2406 split( /-/, $nextdate ),
2407 split( /-/, $expirationdate )
2411 } elsif ($subscription->{numberlength
}>0) {
2412 return (countissuesfrom
($subscriptionid,$subscription->{'startdate'}) >=$subscription->{numberlength
}-1);
2417 sub in_array
{ # used in next sub down
2418 my ( $val, @elements ) = @_;
2419 foreach my $elem (@elements) {
2420 if ( $val == $elem ) {
2427 =head2 GetSubscriptionsFromBorrower
2429 ($count,@routinglist) = GetSubscriptionsFromBorrower($borrowernumber)
2431 this gets the info from subscriptionroutinglist for each $subscriptionid
2434 a count of the serial subscription routing lists to which a patron belongs,
2435 with the titles of those serial subscriptions as an array. Each element of the array
2436 contains a hash_ref with subscriptionID and title of subscription.
2440 sub GetSubscriptionsFromBorrower
{
2441 my ($borrowernumber) = @_;
2442 my $dbh = C4
::Context
->dbh;
2443 my $sth = $dbh->prepare(
2444 "SELECT subscription.subscriptionid, biblio.title
2446 JOIN biblio ON biblio.biblionumber = subscription.biblionumber
2447 JOIN subscriptionroutinglist USING (subscriptionid)
2448 WHERE subscriptionroutinglist.borrowernumber = ? ORDER BY title ASC
2451 $sth->execute($borrowernumber);
2454 while ( my $line = $sth->fetchrow_hashref ) {
2456 push( @routinglist, $line );
2458 return ( $count, @routinglist );
2462 =head2 GetFictiveIssueNumber
2464 $issueno = GetFictiveIssueNumber($subscription, $publishedate);
2466 Get the position of the issue published at $publisheddate, considering the
2467 first issue (at firstacquidate) is at position 1, the next is at position 2, etc...
2468 This issuenumber doesn't take into account irregularities, so, for instance, if the 3rd
2469 issue is declared as 'irregular' (will be skipped at receipt), the next issue number
2470 will be 4, not 3. It's why it is called 'fictive'. It is NOT a serial seq, and is not
2471 depending on how many rows are in serial table.
2472 The issue number calculation is based on subscription frequency, first acquisition
2473 date, and $publisheddate.
2477 sub GetFictiveIssueNumber
{
2478 my ($subscription, $publisheddate) = @_;
2480 my $frequency = GetSubscriptionFrequency
($subscription->{'periodicity'});
2481 my $unit = $frequency->{unit
} ?
lc $frequency->{'unit'} : undef;
2485 my ($year, $month, $day) = split /-/, $publisheddate;
2486 my ($fa_year, $fa_month, $fa_day) = split /-/, $subscription->{'firstacquidate'};
2490 if($unit eq 'day') {
2491 $delta = Delta_Days
($fa_year, $fa_month, $fa_day, $year, $month, $day);
2492 } elsif($unit eq 'week') {
2493 ($wkno, $year) = Week_of_Year
($year, $month, $day);
2494 my ($fa_wkno, $fa_yr) = Week_of_Year
($fa_year, $fa_month, $fa_day);
2495 $delta = ($fa_yr == $year) ?
($wkno - $fa_wkno) : ( ($year-$fa_yr-1)*52 + (52-$fa_wkno+$wkno) );
2496 } elsif($unit eq 'month') {
2497 $delta = ($fa_year == $year)
2498 ?
($month - $fa_month)
2499 : ( ($year-$fa_year-1)*12 + (12-$fa_month+$month) );
2500 } elsif($unit eq 'year') {
2501 $delta = $year - $fa_year;
2503 if($frequency->{'unitsperissue'} == 1) {
2504 $issueno = $delta * $frequency->{'issuesperunit'} + $subscription->{'countissuesperunit'};
2506 # Assuming issuesperunit == 1
2507 $issueno = int( ($delta + $frequency->{'unitsperissue'}) / $frequency->{'unitsperissue'} );
2515 $resultdate = GetNextDate($publisheddate,$subscription)
2517 this function it takes the publisheddate and will return the next issue's date
2518 and will skip dates if there exists an irregularity.
2519 $publisheddate has to be an ISO date
2520 $subscription is a hashref containing at least 'periodicity', 'firstacquidate', 'irregularity', and 'countissuesperunit'
2521 $updatecount is a boolean value which, when set to true, update the 'countissuesperunit' in database
2522 - eg if periodicity is monthly and $publisheddate is 2007-02-10 but if March and April is to be
2523 skipped then the returned date will be 2007-05-10
2526 $resultdate - then next date in the sequence (ISO date)
2528 Return undef if subscription is irregular
2533 my ( $subscription, $publisheddate, $updatecount ) = @_;
2535 return unless $subscription and $publisheddate;
2537 my $freqdata = GetSubscriptionFrequency
($subscription->{'periodicity'});
2539 if ($freqdata->{'unit'}) {
2540 my ( $year, $month, $day ) = split /-/, $publisheddate;
2542 # Process an irregularity Hash
2543 # Suppose that irregularities are stored in a string with this structure
2544 # irreg1;irreg2;irreg3
2545 # where irregX is the number of issue which will not be received
2546 # (the first issue takes the number 1, the 2nd the number 2 and so on)
2548 if ( $subscription->{irregularity
} ) {
2549 my @irreg = split /;/, $subscription->{'irregularity'} ;
2550 foreach my $irregularity (@irreg) {
2551 $irregularities{$irregularity} = 1;
2555 # Get the 'fictive' next issue number
2556 # It is used to check if next issue is an irregular issue.
2557 my $issueno = GetFictiveIssueNumber
($subscription, $publisheddate) + 1;
2559 # Then get the next date
2560 my $unit = lc $freqdata->{'unit'};
2561 if ($unit eq 'day') {
2562 while ($irregularities{$issueno}) {
2563 if ($subscription->{'countissuesperunit'} + 1 > $freqdata->{'issuesperunit'}){
2564 ($year,$month,$day) = Add_Delta_Days
($year,$month, $day , $freqdata->{'unitsperissue'} );
2565 $subscription->{'countissuesperunit'} = 1;
2567 $subscription->{'countissuesperunit'}++;
2571 if ($subscription->{'countissuesperunit'} + 1 > $freqdata->{'issuesperunit'}){
2572 ($year,$month,$day) = Add_Delta_Days
($year,$month, $day , $freqdata->{"unitsperissue"} );
2573 $subscription->{'countissuesperunit'} = 1;
2575 $subscription->{'countissuesperunit'}++;
2578 elsif ($unit eq 'week') {
2579 my ($wkno, $yr) = Week_of_Year
($year, $month, $day);
2580 while ($irregularities{$issueno}) {
2581 if ($subscription->{'countissuesperunit'} + 1 > $freqdata->{'issuesperunit'}){
2582 $subscription->{'countissuesperunit'} = 1;
2583 $wkno += $freqdata->{"unitsperissue"};
2588 my $dow = Day_of_Week
($year, $month, $day);
2589 ($year,$month,$day) = Monday_of_Week
($wkno, $yr);
2590 if($freqdata->{'issuesperunit'} == 1) {
2591 ($year, $month, $day) = Add_Delta_Days
($year, $month, $day, $dow - 1);
2594 $subscription->{'countissuesperunit'}++;
2598 if ($subscription->{'countissuesperunit'} + 1 > $freqdata->{'issuesperunit'}){
2599 $subscription->{'countissuesperunit'} = 1;
2600 $wkno += $freqdata->{"unitsperissue"};
2602 $wkno = $wkno % 52 ;
2605 my $dow = Day_of_Week
($year, $month, $day);
2606 ($year,$month,$day) = Monday_of_Week
($wkno, $yr);
2607 if($freqdata->{'issuesperunit'} == 1) {
2608 ($year, $month, $day) = Add_Delta_Days
($year, $month, $day, $dow - 1);
2611 $subscription->{'countissuesperunit'}++;
2614 elsif ($unit eq 'month') {
2615 while ($irregularities{$issueno}) {
2616 if ($subscription->{'countissuesperunit'} + 1 > $freqdata->{'issuesperunit'}){
2617 $subscription->{'countissuesperunit'} = 1;
2618 ($year,$month,$day) = Add_Delta_YM
($year,$month,$day, 0,$freqdata->{"unitsperissue"});
2619 unless($freqdata->{'issuesperunit'} == 1) {
2620 $day = 1; # Jumping to the first day of month, because we don't know what day is expected
2623 $subscription->{'countissuesperunit'}++;
2627 if ($subscription->{'countissuesperunit'} + 1 > $freqdata->{'issuesperunit'}){
2628 $subscription->{'countissuesperunit'} = 1;
2629 ($year,$month,$day) = Add_Delta_YM
($year,$month,$day, 0,$freqdata->{"unitsperissue"});
2630 unless($freqdata->{'issuesperunit'} == 1) {
2631 $day = 1; # Jumping to the first day of month, because we don't know what day is expected
2634 $subscription->{'countissuesperunit'}++;
2637 elsif ($unit eq 'year') {
2638 while ($irregularities{$issueno}) {
2639 if ($subscription->{'countissuesperunit'} + 1 > $freqdata->{'issuesperunit'}){
2640 $subscription->{'countissuesperunit'} = 1;
2641 ($year,$month,$day) = Add_Delta_YM
($year,$month,$day, $freqdata->{"unitsperissue"},0);
2642 unless($freqdata->{'issuesperunit'} == 1) {
2643 # Jumping to the first day of year, because we don't know what day is expected
2648 $subscription->{'countissuesperunit'}++;
2652 if ($subscription->{'countissuesperunit'} + 1 > $freqdata->{'issuesperunit'}){
2653 $subscription->{'countissuesperunit'} = 1;
2654 ($year,$month,$day) = Add_Delta_YM
($year,$month,$day, $freqdata->{"unitsperissue"},0);
2655 unless($freqdata->{'issuesperunit'} == 1) {
2656 # Jumping to the first day of year, because we don't know what day is expected
2661 $subscription->{'countissuesperunit'}++;
2665 my $dbh = C4
::Context
->dbh;
2668 SET countissuesperunit
= ?
2669 WHERE subscriptionid
= ?
2671 my $sth = $dbh->prepare($query);
2672 $sth->execute($subscription->{'countissuesperunit'}, $subscription->{'subscriptionid'});
2674 return sprintf("%04d-%02d-%02d", $year, $month, $day);
2680 $string = &_numeration($value,$num_type,$locale);
2682 _numeration returns the string corresponding to $value in the num_type
2692 my ($value, $num_type, $locale) = @_;
2694 my $initlocale = setlocale
(LC_TIME
);
2695 if($locale and $locale ne $initlocale) {
2696 $locale = setlocale
(LC_TIME
, $locale);
2698 $locale ||= $initlocale;
2702 when (/^dayname$/) {
2703 $value = $value % 7;
2704 $string = POSIX
::strftime
("%A",0,0,0,0,0,0,$value);
2706 when (/^monthname$/) {
2707 $value = $value % 12;
2708 $string = POSIX
::strftime
("%B",0,0,0,1,$value,0,0,0,0);
2711 my $seasonlocale = ($locale)
2712 ?
(substr $locale,0,2)
2716 [qw(Spring Summer Fall Winter)],
2718 [qw(Printemps Été Automne Hiver)],
2720 $value = $value % 4;
2721 $string = ($seasons{$seasonlocale})
2722 ?
$seasons{$seasonlocale}->[$value]
2723 : $seasons{'en'}->[$value];
2729 if($locale ne $initlocale) {
2730 setlocale
(LC_TIME
, $initlocale);
2735 =head2 is_barcode_in_use
2737 Returns number of occurence of the barcode in the items table
2738 Can be used as a boolean test of whether the barcode has
2739 been deployed as yet
2743 sub is_barcode_in_use
{
2744 my $barcode = shift;
2745 my $dbh = C4
::Context
->dbh;
2746 my $occurences = $dbh->selectall_arrayref(
2747 'SELECT itemnumber from items where barcode = ?',
2752 return @
{$occurences};
2755 =head2 CloseSubscription
2756 Close a subscription given a subscriptionid
2758 sub CloseSubscription
{
2759 my ( $subscriptionid ) = @_;
2760 return unless $subscriptionid;
2761 my $dbh = C4
::Context
->dbh;
2762 my $sth = $dbh->prepare( qq{
2765 WHERE subscriptionid
= ?
2767 $sth->execute( $subscriptionid );
2769 # Set status = missing when status = stopped
2770 $sth = $dbh->prepare( qq{
2773 WHERE subscriptionid
= ?
2776 $sth->execute( $subscriptionid );
2779 =head2 ReopenSubscription
2780 Reopen a subscription given a subscriptionid
2782 sub ReopenSubscription
{
2783 my ( $subscriptionid ) = @_;
2784 return unless $subscriptionid;
2785 my $dbh = C4
::Context
->dbh;
2786 my $sth = $dbh->prepare( qq{
2789 WHERE subscriptionid
= ?
2791 $sth->execute( $subscriptionid );
2793 # Set status = expected when status = stopped
2794 $sth = $dbh->prepare( qq{
2797 WHERE subscriptionid
= ?
2800 $sth->execute( $subscriptionid );
2803 =head2 subscriptionCurrentlyOnOrder
2805 $bool = subscriptionCurrentlyOnOrder( $subscriptionid );
2807 Return 1 if subscription is currently on order else 0.
2811 sub subscriptionCurrentlyOnOrder
{
2812 my ( $subscriptionid ) = @_;
2813 my $dbh = C4
::Context
->dbh;
2815 SELECT COUNT
(*) FROM aqorders
2816 WHERE subscriptionid
= ?
2817 AND datereceived IS NULL
2818 AND datecancellationprinted IS NULL
2820 my $sth = $dbh->prepare( $query );
2821 $sth->execute($subscriptionid);
2822 return $sth->fetchrow_array;
2825 =head2 can_edit_subscription
2827 $can = can_edit_subscription( $subscriptionid[, $userid] );
2829 Return 1 if the subscription can be edited by the current logged user (or a given $userid), else 0.
2833 sub can_edit_subscription
{
2834 my ( $subscription, $userid ) = @_;
2835 return _can_do_on_subscription
( $subscription, $userid, 'edit_subscription' );
2838 =head2 can_show_subscription
2840 $can = can_show_subscription( $subscriptionid[, $userid] );
2842 Return 1 if the subscription can be shown by the current logged user (or a given $userid), else 0.
2846 sub can_show_subscription
{
2847 my ( $subscription, $userid ) = @_;
2848 return _can_do_on_subscription
( $subscription, $userid, '*' );
2851 sub _can_do_on_subscription
{
2852 my ( $subscription, $userid, $permission ) = @_;
2853 return 0 unless C4
::Context
->userenv;
2854 my $flags = C4
::Context
->userenv->{flags
};
2855 $userid ||= C4
::Context
->userenv->{'id'};
2857 if ( C4
::Context
->preference('IndependentBranches') ) {
2859 if C4
::Context
->IsSuperLibrarian()
2861 C4
::Auth
::haspermission
( $userid, { serials
=> 'superserials' } )
2863 C4
::Auth
::haspermission
( $userid,
2864 { serials
=> $permission } )
2865 and ( not defined $subscription->{branchcode
}
2866 or $subscription->{branchcode
} eq ''
2867 or $subscription->{branchcode
} eq
2868 C4
::Context
->userenv->{'branch'} )
2873 if C4
::Context
->IsSuperLibrarian()
2875 C4
::Auth
::haspermission
( $userid, { serials
=> 'superserials' } )
2876 or C4
::Auth
::haspermission
(
2877 $userid, { serials
=> $permission }
2889 Koha Development Team <http://koha-community.org/>