X-Git-Url: http://koha-dev.rot13.org:8081/gitweb/?a=blobdiff_plain;f=C4%2FSerials.pm;h=2fb639bb5299dec8b5b070ee11035d9f9c3f5bc8;hb=e27ea08887a0332692c37b05b15021b14b1bef78;hp=b37aa551db1708e4776762e61ed975dd6dcfa107;hpb=da5aca223fccdae6b0b64e4c1ba67e65c550242c;p=koha_fer diff --git a/C4/Serials.pm b/C4/Serials.pm index b37aa551db..2fb639bb52 100644 --- a/C4/Serials.pm +++ b/C4/Serials.pm @@ -20,6 +20,8 @@ package C4::Serials; use Modern::Perl; +use C4::Auth qw(haspermission); +use C4::Context; use C4::Dates qw(format_date format_date_in_iso); use Date::Calc qw(:all); use POSIX qw(strftime setlocale LC_TIME); @@ -58,6 +60,7 @@ BEGIN { &CountIssues HasItems &GetSubscriptionsFromBorrower + &subscriptionCurrentlyOnOrder ); } @@ -99,7 +102,7 @@ sub GetSuppliersWithLateIssues { WHERE id > 0 AND ( (planneddate < now() AND serial.status=1) - OR serial.STATUS = 3 OR serial.STATUS = 4 + OR serial.STATUS IN (3, 4, 41, 42, 43, 44) ) AND subscription.closed = 0 ORDER BY name|; @@ -120,6 +123,9 @@ name,title,planneddate,serialseq,serial.subscriptionid from tables : subscriptio sub GetLateIssues { my ($supplierid) = @_; + + return unless ($supplierid); + my $dbh = C4::Context->dbh; my $sth; if ($supplierid) { @@ -152,10 +158,8 @@ sub GetLateIssues { } my @issuelist; my $last_title; - my $odd = 0; while ( my $line = $sth->fetchrow_hashref ) { - $odd++ unless $line->{title} eq $last_title; - $line->{title} = "" if $line->{title} eq $last_title; + $line->{title} = "" if $last_title and $line->{title} eq $last_title; $last_title = $line->{title} if ( $line->{title} ); $line->{planneddate} = format_date( $line->{planneddate} ); push @issuelist, $line; @@ -226,15 +230,7 @@ sub GetSerialInformation { my ($serialid) = @_; my $dbh = C4::Context->dbh; my $query = qq| - SELECT serial.*, serial.notes as sernotes, serial.status as serstatus,subscription.*,subscription.subscriptionid as subsid |; - if ( C4::Context->preference('IndependantBranches') - && C4::Context->userenv - && C4::Context->userenv->{'flags'} != 1 - && C4::Context->userenv->{'branch'} ) { - $query .= " - , ((subscription.branchcode <>\"" . C4::Context->userenv->{'branch'} . "\") and subscription.branchcode <>\"\" and subscription.branchcode IS NOT NULL) as cannotedit "; - } - $query .= qq| + SELECT serial.*, serial.notes as sernotes, serial.status as serstatus,subscription.*,subscription.subscriptionid as subsid FROM serial LEFT JOIN subscription ON subscription.subscriptionid=serial.subscriptionid WHERE serialid = ? |; @@ -273,6 +269,7 @@ sub GetSerialInformation { $data->{ "status" . $data->{'serstatus'} } = 1; $data->{'subscriptionexpired'} = HasSubscriptionExpired( $data->{'subscriptionid'} ) && $data->{'status'} == 1; $data->{'abouttoexpire'} = abouttoexpire( $data->{'subscriptionid'} ); + $data->{cannotedit} = not can_edit_subscription( $data ); return $data; } @@ -286,6 +283,9 @@ returns the number of rows affected sub AddItem2Serial { my ( $serialid, $itemnumber ) = @_; + + return unless ($serialid and $itemnumber); + my $dbh = C4::Context->dbh; my $rq = $dbh->prepare("INSERT INTO `serialitems` SET serialid=? , itemnumber=?"); $rq->execute( $serialid, $itemnumber ); @@ -303,6 +303,9 @@ Update Claimdate for issues in @$serialids list with date $date sub UpdateClaimdateIssues { my ( $serialids, $date ) = @_; + + return unless ($serialids); + my $dbh = C4::Context->dbh; $date = strftime( "%Y-%m-%d", localtime ) unless ($date); my $query = " @@ -331,15 +334,7 @@ sub GetSubscription { subscriptionhistory.*, aqbooksellers.name AS aqbooksellername, biblio.title AS bibliotitle, - subscription.biblionumber as bibnum); - if ( C4::Context->preference('IndependantBranches') - && C4::Context->userenv - && C4::Context->userenv->{'flags'} != 1 - && C4::Context->userenv->{'branch'} ) { - $query .= " - , ((subscription.branchcode <>\"" . C4::Context->userenv->{'branch'} . "\") and subscription.branchcode <>\"\" and subscription.branchcode IS NOT NULL) as cannotedit "; - } - $query .= qq( + subscription.biblionumber as bibnum FROM subscription LEFT JOIN subscriptionhistory ON subscription.subscriptionid=subscriptionhistory.subscriptionid LEFT JOIN aqbooksellers ON subscription.aqbooksellerid=aqbooksellers.id @@ -347,16 +342,12 @@ sub GetSubscription { WHERE subscription.subscriptionid = ? ); - # if (C4::Context->preference('IndependantBranches') && - # C4::Context->userenv && - # C4::Context->userenv->{'flags'} != 1){ - # # $debug and warn "flags: ".C4::Context->userenv->{'flags'}; - # $query.=" AND subscription.branchcode IN ('".C4::Context->userenv->{'branch'}."',\"\")"; - # } $debug and warn "query : $query\nsubsid :$subscriptionid"; my $sth = $dbh->prepare($query); $sth->execute($subscriptionid); - return $sth->fetchrow_hashref; + my $subscription = $sth->fetchrow_hashref; + $subscription->{cannotedit} = not can_edit_subscription( $subscription ); + return $subscription; } =head2 GetFullSubscription @@ -368,6 +359,9 @@ sub GetSubscription { sub GetFullSubscription { my ($subscriptionid) = @_; + + return unless ($subscriptionid); + my $dbh = C4::Context->dbh; my $query = qq| SELECT serial.serialid, @@ -380,15 +374,7 @@ sub GetFullSubscription { aqbooksellers.name as aqbooksellername, biblio.title as bibliotitle, subscription.branchcode AS branchcode, - subscription.subscriptionid AS subscriptionid |; - if ( C4::Context->preference('IndependantBranches') - && C4::Context->userenv - && C4::Context->userenv->{'flags'} != 1 - && C4::Context->userenv->{'branch'} ) { - $query .= " - , ((subscription.branchcode <>\"" . C4::Context->userenv->{'branch'} . "\") and subscription.branchcode <>\"\" and subscription.branchcode IS NOT NULL) as cannotedit "; - } - $query .= qq| + subscription.subscriptionid AS subscriptionid FROM serial LEFT JOIN subscription ON (serial.subscriptionid=subscription.subscriptionid ) @@ -402,7 +388,11 @@ sub GetFullSubscription { $debug and warn "GetFullSubscription query: $query"; my $sth = $dbh->prepare($query); $sth->execute($subscriptionid); - return $sth->fetchall_arrayref( {} ); + my $subscriptions = $sth->fetchall_arrayref( {} ); + for my $subscription ( @$subscriptions ) { + $subscription->{cannotedit} = not can_edit_subscription( $subscription ); + } + return $subscriptions; } =head2 PrepareSerialsData @@ -414,6 +404,9 @@ sub GetFullSubscription { sub PrepareSerialsData { my ($lines) = @_; + + return unless ($lines); + my %tmpresults; my $year; my @res; @@ -430,12 +423,11 @@ sub PrepareSerialsData { if (!defined $subs->{$datefield} or $subs->{$datefield}=~m/^00/) { $subs->{$datefield} = 'XXX'; } - else { - $subs->{$datefield} = format_date( $subs->{$datefield} ); - } } $subs->{ "status" . $subs->{'status'} } = 1; - $subs->{"checked"} = $subs->{'status'} =~ /1|3|4|7/; + if ( grep { $_ == $subs->{status} } qw( 1 3 4 41 42 43 44 7 ) ) { + $subs->{"checked"} = 1; + } if ( $subs->{'year'} && $subs->{'year'} ne "" ) { $year = $subs->{'year'}; @@ -473,6 +465,9 @@ startdate, histstartdate,opacnote,missinglist,recievedlist,periodicity,status & sub GetSubscriptionsFromBiblionumber { my ($biblionumber) = @_; + + return unless ($biblionumber); + my $dbh = C4::Context->dbh; my $query = qq( SELECT subscription.*, @@ -500,13 +495,6 @@ sub GetSubscriptionsFromBiblionumber { $subs->{ "periodicity" . $subs->{periodicity} } = 1; $subs->{ "numberpattern" . $subs->{numberpattern} } = 1; $subs->{ "status" . $subs->{'status'} } = 1; - $subs->{'cannotedit'} = - ( C4::Context->preference('IndependantBranches') - && C4::Context->userenv - && C4::Context->userenv->{flags} % 2 != 1 - && C4::Context->userenv->{branch} - && $subs->{branchcode} - && ( C4::Context->userenv->{branch} ne $subs->{branchcode} ) ); if ( $subs->{enddate} eq '0000-00-00' ) { $subs->{enddate} = ''; @@ -515,6 +503,7 @@ sub GetSubscriptionsFromBiblionumber { } $subs->{'abouttoexpire'} = abouttoexpire( $subs->{'subscriptionid'} ); $subs->{'subscriptionexpired'} = HasSubscriptionExpired( $subs->{'subscriptionid'} ); + $subs->{cannotedit} = not can_edit_subscription( $subs ); push @res, $subs; } return \@res; @@ -540,16 +529,7 @@ sub GetFullSubscriptionsFromBiblionumber { year(IF(serial.publisheddate="00-00-0000",serial.planneddate,serial.publisheddate)) as year, biblio.title as bibliotitle, subscription.branchcode AS branchcode, - subscription.subscriptionid AS subscriptionid|; - if ( C4::Context->preference('IndependantBranches') - && C4::Context->userenv - && C4::Context->userenv->{'flags'} != 1 - && C4::Context->userenv->{'branch'} ) { - $query .= " - , ((subscription.branchcode <>\"" . C4::Context->userenv->{'branch'} . "\") and subscription.branchcode <>\"\" and subscription.branchcode IS NOT NULL) as cannotedit "; - } - - $query .= qq| + subscription.subscriptionid AS subscriptionid FROM serial LEFT JOIN subscription ON (serial.subscriptionid=subscription.subscriptionid) @@ -562,7 +542,11 @@ sub GetFullSubscriptionsFromBiblionumber { |; my $sth = $dbh->prepare($query); $sth->execute($biblionumber); - return $sth->fetchall_arrayref( {} ); + my $subscriptions = $sth->fetchall_arrayref( {} ); + for my $subscription ( @$subscriptions ) { + $subscription->{cannotedit} = not can_edit_subscription( $subscription ); + } + return $subscriptions; } =head2 GetSubscriptions @@ -637,30 +621,36 @@ sub GetSubscriptions { $debug and warn "GetSubscriptions query: $sql params : ", join( " ", @bind_params ); $sth = $dbh->prepare($sql); $sth->execute(@bind_params); - my @results; - - while ( my $line = $sth->fetchrow_hashref ) { - $line->{'cannotedit'} = - ( C4::Context->preference('IndependantBranches') - && C4::Context->userenv - && C4::Context->userenv->{flags} % 2 != 1 - && C4::Context->userenv->{branch} - && $line->{branchcode} - && ( C4::Context->userenv->{branch} ne $line->{branchcode} ) ); - push @results, $line; - } - return @results; + my $subscriptions = $sth->fetchall_arrayref( {} ); + for my $subscription ( @$subscriptions ) { + $subscription->{cannotedit} = not can_edit_subscription( $subscription ); + } + return @$subscriptions; } =head2 SearchSubscriptions -@results = SearchSubscriptions($args); -$args is a hashref. Its keys can be contained: title, issn, ean, publisher, bookseller and branchcode + @results = SearchSubscriptions($args); -this function gets all subscriptions which have title like $title, ISSN like $issn, EAN like $ean, publisher like $publisher, bookseller like $bookseller AND branchcode eq $branch. +This function returns a list of hashrefs, one for each subscription +that meets the conditions specified by the $args hashref. -return: -a table of hashref. Each hash containt the subscription. +The valid search fields are: + + biblionumber + title + issn + ean + callnumber + location + publisher + bookseller + branch + expiration_date + closed + +The expiration_date search field is special; it specifies the maximum +subscription expiration date. =cut @@ -668,7 +658,14 @@ sub SearchSubscriptions { my ( $args ) = @_; my $query = qq{ - SELECT subscription.*, subscriptionhistory.*, biblio.*, biblioitems.issn + SELECT + subscription.notes AS publicnotes, + subscription.*, + subscriptionhistory.*, + biblio.notes AS biblionotes, + biblio.title, + biblio.author, + biblioitems.issn FROM subscription LEFT JOIN subscriptionhistory USING(subscriptionid) LEFT JOIN biblio ON biblio.biblionumber = subscription.biblionumber @@ -701,6 +698,10 @@ sub SearchSubscriptions { push @where_strs, "biblioitems.ean LIKE ?"; push @where_args, "%$args->{ean}%"; } + if ( $args->{callnumber} ) { + push @where_strs, "subscription.callnumber LIKE ?"; + push @where_args, "%$args->{callnumber}%"; + } if( $args->{publisher} ){ push @where_strs, "biblioitems.publishercode LIKE ?"; push @where_args, "%$args->{publisher}%"; @@ -713,6 +714,14 @@ sub SearchSubscriptions { push @where_strs, "subscription.branchcode = ?"; push @where_args, "$args->{branch}"; } + if ( $args->{location} ) { + push @where_strs, "subscription.location = ?"; + push @where_args, "$args->{location}"; + } + if ( $args->{expiration_date} ) { + push @where_strs, "subscription.enddate <= ?"; + push @where_args, "$args->{expiration_date}"; + } if( defined $args->{closed} ){ push @where_strs, "subscription.closed = ?"; push @where_args, "$args->{closed}"; @@ -727,6 +736,14 @@ sub SearchSubscriptions { my $results = $sth->fetchall_arrayref( {} ); $sth->finish; + for my $subscription ( @$results ) { + $subscription->{cannotedit} = not can_edit_subscription( $subscription ); + $subscription->{cannotdisplay} = + ( C4::Context->preference("IndependentBranches") && + C4::Context->userenv && + $subscription->{branchcode} ne C4::Context->userenv->{'branch'} ) ? 1 : 0; + } + return @$results; } @@ -744,6 +761,9 @@ FIXME: We should return \@serials. sub GetSerials { my ( $subscriptionid, $count ) = @_; + + return unless $subscriptionid; + my $dbh = C4::Context->dbh; # status = 2 is "arrived" @@ -810,6 +830,9 @@ this number is used to see if a subscription can be deleted (=it must have only sub GetSerials2 { my ( $subscription, $status ) = @_; + + return unless ($subscription and $status); + my $dbh = C4::Context->dbh; my $query = qq| SELECT serialid,serialseq, status, planneddate, publisheddate,notes, routingnotes @@ -849,13 +872,16 @@ a ref to an array which contains all of the latest serials stored into a hash. sub GetLatestSerials { my ( $subscriptionid, $limit ) = @_; + + return unless ($subscriptionid and $limit); + my $dbh = C4::Context->dbh; # status = 2 is "arrived" - my $strsth = "SELECT serialid,serialseq, status, planneddate, notes + my $strsth = "SELECT serialid,serialseq, status, planneddate, publisheddate, notes FROM serial WHERE subscriptionid = ? - AND (status =2 or status=4) + AND status IN (2, 4, 41, 42, 43, 44) ORDER BY publisheddate DESC LIMIT 0,$limit "; my $sth = $dbh->prepare($strsth); @@ -864,6 +890,7 @@ sub GetLatestSerials { while ( my $line = $sth->fetchrow_hashref ) { $line->{ "status" . $line->{status} } = 1; # fills a "statusX" value, used for template status select list $line->{"planneddate"} = format_date( $line->{"planneddate"} ); + $line->{"publisheddate"} = format_date( $line->{"publisheddate"} ); push @serials, $line; } @@ -880,7 +907,10 @@ This function returns the field distributedto for the subscription matching subs sub GetDistributedTo { my $dbh = C4::Context->dbh; my $distributedto; - my $subscriptionid = @_; + my ($subscriptionid) = @_; + + return unless ($subscriptionid); + my $query = "SELECT distributedto FROM subscription WHERE subscriptionid=?"; my $sth = $dbh->prepare($query); $sth->execute($subscriptionid); @@ -905,7 +935,10 @@ This function get the next issue for the subscription given on input arg sub GetNextSeq { my ($subscription, $pattern, $planneddate) = @_; - my ( $calculated, $newlastvalue1, $newlastvalue2, $newlastvalue3, + + return unless ($subscription and $pattern); + + my ( $newlastvalue1, $newlastvalue2, $newlastvalue3, $newinnerloop1, $newinnerloop2, $newinnerloop3 ); my $count = 1; @@ -923,63 +956,66 @@ sub GetNextSeq { } my $numberingmethod = $pattern->{numberingmethod}; - $calculated = $numberingmethod; - my $locale = $subscription->{locale}; - $newlastvalue1 = $subscription->{lastvalue1} || 0; - $newlastvalue2 = $subscription->{lastvalue2} || 0; - $newlastvalue3 = $subscription->{lastvalue3} || 0; - $newinnerloop1 = $subscription->{innerloop1} || 0; - $newinnerloop2 = $subscription->{innerloop2} || 0; - $newinnerloop3 = $subscription->{innerloop3} || 0; - my %calc; - foreach(qw/X Y Z/) { - $calc{$_} = 1 if ($numberingmethod =~ /\{$_\}/); - } - - for(my $i = 0; $i < $count; $i++) { - if($calc{'X'}) { - # check if we have to increase the new value. - $newinnerloop1 += 1; - if ($newinnerloop1 >= $pattern->{every1}) { - $newinnerloop1 = 0; - $newlastvalue1 += $pattern->{add1}; + my $calculated = ""; + if ($numberingmethod) { + $calculated = $numberingmethod; + my $locale = $subscription->{locale}; + $newlastvalue1 = $subscription->{lastvalue1} || 0; + $newlastvalue2 = $subscription->{lastvalue2} || 0; + $newlastvalue3 = $subscription->{lastvalue3} || 0; + $newinnerloop1 = $subscription->{innerloop1} || 0; + $newinnerloop2 = $subscription->{innerloop2} || 0; + $newinnerloop3 = $subscription->{innerloop3} || 0; + my %calc; + foreach(qw/X Y Z/) { + $calc{$_} = 1 if ($numberingmethod =~ /\{$_\}/); + } + + for(my $i = 0; $i < $count; $i++) { + if($calc{'X'}) { + # check if we have to increase the new value. + $newinnerloop1 += 1; + if ($newinnerloop1 >= $pattern->{every1}) { + $newinnerloop1 = 0; + $newlastvalue1 += $pattern->{add1}; + } + # reset counter if needed. + $newlastvalue1 = $pattern->{setto1} if ($newlastvalue1 > $pattern->{whenmorethan1}); + } + if($calc{'Y'}) { + # check if we have to increase the new value. + $newinnerloop2 += 1; + if ($newinnerloop2 >= $pattern->{every2}) { + $newinnerloop2 = 0; + $newlastvalue2 += $pattern->{add2}; + } + # reset counter if needed. + $newlastvalue2 = $pattern->{setto2} if ($newlastvalue2 > $pattern->{whenmorethan2}); + } + if($calc{'Z'}) { + # check if we have to increase the new value. + $newinnerloop3 += 1; + if ($newinnerloop3 >= $pattern->{every3}) { + $newinnerloop3 = 0; + $newlastvalue3 += $pattern->{add3}; + } + # reset counter if needed. + $newlastvalue3 = $pattern->{setto3} if ($newlastvalue3 > $pattern->{whenmorethan3}); } - # reset counter if needed. - $newlastvalue1 = $pattern->{setto1} if ($newlastvalue1 > $pattern->{whenmorethan1}); + } + if($calc{'X'}) { + my $newlastvalue1string = _numeration( $newlastvalue1, $pattern->{numbering1}, $locale ); + $calculated =~ s/\{X\}/$newlastvalue1string/g; } if($calc{'Y'}) { - # check if we have to increase the new value. - $newinnerloop2 += 1; - if ($newinnerloop2 >= $pattern->{every2}) { - $newinnerloop2 = 0; - $newlastvalue2 += $pattern->{add2}; - } - # reset counter if needed. - $newlastvalue2 = $pattern->{setto2} if ($newlastvalue2 > $pattern->{whenmorethan2}); + my $newlastvalue2string = _numeration( $newlastvalue2, $pattern->{numbering2}, $locale ); + $calculated =~ s/\{Y\}/$newlastvalue2string/g; } if($calc{'Z'}) { - # check if we have to increase the new value. - $newinnerloop3 += 1; - if ($newinnerloop3 >= $pattern->{every3}) { - $newinnerloop3 = 0; - $newlastvalue3 += $pattern->{add3}; - } - # reset counter if needed. - $newlastvalue3 = $pattern->{setto3} if ($newlastvalue3 > $pattern->{whenmorethan3}); + my $newlastvalue3string = _numeration( $newlastvalue3, $pattern->{numbering3}, $locale ); + $calculated =~ s/\{Z\}/$newlastvalue3string/g; } } - if($calc{'X'}) { - my $newlastvalue1string = _numeration( $newlastvalue1, $pattern->{numbering1}, $locale ); - $calculated =~ s/\{X\}/$newlastvalue1string/g; - } - if($calc{'Y'}) { - my $newlastvalue2string = _numeration( $newlastvalue2, $pattern->{numbering2}, $locale ); - $calculated =~ s/\{Y\}/$newlastvalue2string/g; - } - if($calc{'Z'}) { - my $newlastvalue3string = _numeration( $newlastvalue3, $pattern->{numbering3}, $locale ); - $calculated =~ s/\{Z\}/$newlastvalue3string/g; - } return ($calculated, $newlastvalue1, $newlastvalue2, $newlastvalue3, @@ -999,6 +1035,9 @@ the sequence in string format sub GetSeq { my ($subscription, $pattern) = @_; + + return unless ($subscription and $pattern); + my $locale = $subscription->{locale}; my $calculated = $pattern->{numberingmethod}; @@ -1030,6 +1069,9 @@ the enddate or undef sub GetExpirationDate { my ( $subscriptionid, $startdate ) = @_; + + return unless ($subscriptionid); + my $dbh = C4::Context->dbh; my $subscription = GetSubscription($subscriptionid); my $enddate; @@ -1079,6 +1121,9 @@ the number of subscriptions sub CountSubscriptionFromBiblionumber { my ($biblionumber) = @_; + + return unless ($biblionumber); + my $dbh = C4::Context->dbh; my $query = "SELECT count(*) FROM subscription WHERE biblionumber=?"; my $sth = $dbh->prepare($query); @@ -1098,6 +1143,9 @@ returns the number of rows affected sub ModSubscriptionHistory { my ( $subscriptionid, $histstartdate, $enddate, $receivedlist, $missinglist, $opacnote, $librariannote ) = @_; + + return unless ($subscriptionid); + my $dbh = C4::Context->dbh; my $query = "UPDATE subscriptionhistory SET histstartdate=?,histenddate=?,recievedlist=?,missinglist=?,opacnote=?,librariannote=? @@ -1167,6 +1215,7 @@ Note : if we change from "waited" to something else,then we will have to create sub ModSerialStatus { my ( $serialid, $serialseq, $planneddate, $publisheddate, $status, $notes ) = @_; + return unless ($serialid); #It is a usual serial # 1st, get previous status : @@ -1201,8 +1250,11 @@ sub ModSerialStatus { if ( $status == 2 || ($oldstatus == 2 && $status != 2) ) { _update_receivedlist($subscriptionid); } - if($status == 4 || $status == 5 - || ($oldstatus == 4 && $status != 4) + my @missing_statuses = qw( 4 41 42 43 44 ); + if ( ( grep { $_ == $status } ( @missing_statuses, 5 ) ) + || ( + ( grep { $_ == $oldstatus } @missing_statuses ) + && ! ( grep { $_ == $status } @missing_statuses ) ) || ($oldstatus == 5 && $status != 5)) { _update_missinglist($subscriptionid); } @@ -1324,7 +1376,7 @@ sub ModNextExpected { =head2 GetSubscriptionIrregularities -=over4 +=over 4 =item @irreg = &GetSubscriptionIrregularities($subscriptionid); get the list of irregularities for a subscription @@ -1406,10 +1458,10 @@ sub ModSubscription { =head2 NewSubscription $subscriptionid = &NewSubscription($auser,branchcode,$aqbooksellerid,$cost,$aqbudgetid,$biblionumber, - $startdate,$periodicity,$dow,$numberlength,$weeklength,$monthlength, + $startdate,$periodicity,$numberlength,$weeklength,$monthlength, $lastvalue1,$innerloop1,$lastvalue2,$innerloop2,$lastvalue3,$innerloop3, $status, $notes, $letter, $firstacquidate, $irregularity, $numberpattern, - $callnumber, $hemisphere, $manualhistory, $internalnotes, $serialsadditems, + $locale, $callnumber, $manualhistory, $internalnotes, $serialsadditems, $staffdisplaycount, $opacdisplaycount, $graceperiod, $location, $enddate, $skip_serialseq); Create a new subscription with value given on input args. @@ -1542,7 +1594,7 @@ sub ReNewSubscription { # renew subscription $query = qq| UPDATE subscription - SET startdate=?,numberlength=?,weeklength=?,monthlength=? + SET startdate=?,numberlength=?,weeklength=?,monthlength=?,reneweddate=NOW() WHERE subscriptionid=? |; $sth = $dbh->prepare($query); @@ -1582,6 +1634,8 @@ sub NewIssue { my ( $serialseq, $subscriptionid, $biblionumber, $status, $planneddate, $publisheddate, $notes ) = @_; ### FIXME biblionumber CAN be provided by subscriptionid. So Do we STILL NEED IT ? + return unless ($subscriptionid); + my $dbh = C4::Context->dbh; my $query = qq| INSERT INTO serial @@ -1634,6 +1688,9 @@ return : sub ItemizeSerials { my ( $serialid, $info ) = @_; + + return unless ($serialid); + my $now = POSIX::strftime( "%Y-%m-%d", localtime ); my $dbh = C4::Context->dbh; @@ -1768,6 +1825,9 @@ sub HasSubscriptionStrictlyExpired { # Getting end of subscription date my ($subscriptionid) = @_; + + return unless ($subscriptionid); + my $dbh = C4::Context->dbh; my $subscription = GetSubscription($subscriptionid); my $expirationdate = $subscription->{enddate} || GetExpirationDate($subscriptionid); @@ -1809,6 +1869,9 @@ return : sub HasSubscriptionExpired { my ($subscriptionid) = @_; + + return unless ($subscriptionid); + my $dbh = C4::Context->dbh; my $subscription = GetSubscription($subscriptionid); my $frequency = C4::Serials::Frequency::GetSubscriptionFrequency($subscription->{periodicity}); @@ -1946,6 +2009,9 @@ name,title,planneddate,serialseq,serial.subscriptionid from tables : subscriptio sub GetLateOrMissingIssues { my ( $supplierid, $serialid, $order ) = @_; + + return unless ( $supplierid or $serialid ); + my $dbh = C4::Context->dbh; my $sth; my $byserial = ''; @@ -1969,7 +2035,7 @@ sub GetLateOrMissingIssues { LEFT JOIN biblio ON subscription.biblionumber=biblio.biblionumber LEFT JOIN aqbooksellers ON subscription.aqbooksellerid = aqbooksellers.id WHERE subscription.subscriptionid = serial.subscriptionid - AND (serial.STATUS = 4 OR ((planneddate < now() AND serial.STATUS =1) OR serial.STATUS = 3 OR serial.STATUS = 7)) + AND (serial.STATUS IN (4, 41, 42, 43, 44) OR ((planneddate < now() AND serial.STATUS =1) OR serial.STATUS = 3 OR serial.STATUS = 7)) AND subscription.aqbooksellerid=$supplierid $byserial ORDER BY $order" @@ -1986,7 +2052,7 @@ sub GetLateOrMissingIssues { LEFT JOIN biblio ON subscription.biblionumber=biblio.biblionumber LEFT JOIN aqbooksellers ON subscription.aqbooksellerid = aqbooksellers.id WHERE subscription.subscriptionid = serial.subscriptionid - AND (serial.STATUS = 4 OR ((planneddate < now() AND serial.STATUS =1) OR serial.STATUS = 3 OR serial.STATUS = 7)) + AND (serial.STATUS IN (4, 41, 42, 43, 44) OR ((planneddate < now() AND serial.STATUS =1) OR serial.STATUS = 3 OR serial.STATUS = 7)) $byserial ORDER BY $order" ); @@ -2020,6 +2086,9 @@ called when a missing issue is found from the serials-recieve.pl file sub removeMissingIssue { my ( $sequence, $subscriptionid ) = @_; + + return unless ($sequence and $subscriptionid); + my $dbh = C4::Context->dbh; my $sth = $dbh->prepare("SELECT * FROM subscriptionhistory WHERE subscriptionid = ?"); $sth->execute($subscriptionid); @@ -2105,6 +2174,9 @@ used to show either an 'add' or 'edit' link sub check_routing { my ($subscriptionid) = @_; + + return unless ($subscriptionid); + my $dbh = C4::Context->dbh; my $sth = $dbh->prepare( "SELECT count(routingid) routingids FROM subscription LEFT JOIN subscriptionroutinglist @@ -2130,6 +2202,9 @@ of either 1 or highest current rank + 1 sub addroutingmember { my ( $borrowernumber, $subscriptionid ) = @_; + + return unless ($borrowernumber and $subscriptionid); + my $rank; my $dbh = C4::Context->dbh; my $sth = $dbh->prepare( "SELECT max(ranking) rank FROM subscriptionroutinglist WHERE subscriptionid = ?" ); @@ -2730,6 +2805,55 @@ sub ReopenSubscription { $sth->execute( $subscriptionid ); } +=head2 subscriptionCurrentlyOnOrder + + $bool = subscriptionCurrentlyOnOrder( $subscriptionid ); + +Return 1 if subscription is currently on order else 0. + +=cut + +sub subscriptionCurrentlyOnOrder { + my ( $subscriptionid ) = @_; + my $dbh = C4::Context->dbh; + my $query = qq| + SELECT COUNT(*) FROM aqorders + WHERE subscriptionid = ? + AND datereceived IS NULL + AND datecancellationprinted IS NULL + |; + my $sth = $dbh->prepare( $query ); + $sth->execute($subscriptionid); + return $sth->fetchrow_array; +} + +=head2 can_edit_subscription + + $can = can_edit_subscription( $subscriptionid[, $userid] ); + +Return 1 if the subscription is editable by the current logged user (or a given $userid), else 0. + +=cut + +sub can_edit_subscription { + my ( $subscription, $userid ) = @_; + return 0 unless C4::Context->userenv; + my $flags = C4::Context->userenv->{flags}; + $userid ||= C4::Context->userenv->{'id'}; + my $independent_branches = C4::Context->preference('IndependentBranches'); + return 1 unless $independent_branches; + if( C4::Context->IsSuperLibrarian() + or C4::Auth::haspermission( $userid, {serials => 'superserials'}), + or C4::Auth::haspermission( $userid, {serials => 'edit_subscription'}), + or not defined $subscription->{branchcode} + or $subscription->{branchcode} eq '' + or $subscription->{branchcode} eq C4::Context->userenv->{'branch'} + ) { + return 1; + } + return 0; +} + 1; __END__