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);
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|;
sub GetLateIssues {
my ($supplierid) = @_;
+
+ return unless ($supplierid);
+
my $dbh = C4::Context->dbh;
my $sth;
if ($supplierid) {
}
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;
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 = ?
|;
$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;
}
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 );
sub UpdateClaimdateIssues {
my ( $serialids, $date ) = @_;
+
+ return unless ($serialids);
+
my $dbh = C4::Context->dbh;
$date = strftime( "%Y-%m-%d", localtime ) unless ($date);
my $query = "
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
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
sub GetFullSubscription {
my ($subscriptionid) = @_;
+
+ return unless ($subscriptionid);
+
my $dbh = C4::Context->dbh;
my $query = qq|
SELECT serial.serialid,
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 )
$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
sub PrepareSerialsData {
my ($lines) = @_;
+
+ return unless ($lines);
+
my %tmpresults;
my $year;
my @res;
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'};
sub GetSubscriptionsFromBiblionumber {
my ($biblionumber) = @_;
+
+ return unless ($biblionumber);
+
my $dbh = C4::Context->dbh;
my $query = qq(
SELECT subscription.*,
$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} = '';
}
$subs->{'abouttoexpire'} = abouttoexpire( $subs->{'subscriptionid'} );
$subs->{'subscriptionexpired'} = HasSubscriptionExpired( $subs->{'subscriptionid'} );
+ $subs->{cannotedit} = not can_edit_subscription( $subs );
push @res, $subs;
}
return \@res;
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)
|;
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
$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
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
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}%";
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}";
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->IsSuperLibrarian()) &&
+ $subscription->{branchcode} ne C4::Context->userenv->{'branch'} ) ? 1 : 0;
+ }
+
return @$results;
}
sub GetSerials {
my ( $subscriptionid, $count ) = @_;
+
+ return unless $subscriptionid;
+
my $dbh = C4::Context->dbh;
# status = 2 is "arrived"
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
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);
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;
}
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);
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;
}
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});
}
- # 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});
+ }
+ }
+ 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,
sub GetSeq {
my ($subscription, $pattern) = @_;
+
+ return unless ($subscription and $pattern);
+
my $locale = $subscription->{locale};
my $calculated = $pattern->{numberingmethod};
sub GetExpirationDate {
my ( $subscriptionid, $startdate ) = @_;
+
+ return unless ($subscriptionid);
+
my $dbh = C4::Context->dbh;
my $subscription = GetSubscription($subscriptionid);
my $enddate;
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);
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=?
sub ModSerialStatus {
my ( $serialid, $serialseq, $planneddate, $publisheddate, $status, $notes ) = @_;
+ return unless ($serialid);
#It is a usual serial
# 1st, get previous status :
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);
}
=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.
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
sub ItemizeSerials {
my ( $serialid, $info ) = @_;
+
+ return unless ($serialid);
+
my $now = POSIX::strftime( "%Y-%m-%d", localtime );
my $dbh = C4::Context->dbh;
# 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);
sub HasSubscriptionExpired {
my ($subscriptionid) = @_;
+
+ return unless ($subscriptionid);
+
my $dbh = C4::Context->dbh;
my $subscription = GetSubscription($subscriptionid);
my $frequency = C4::Serials::Frequency::GetSubscriptionFrequency($subscription->{periodicity});
sub GetLateOrMissingIssues {
my ( $supplierid, $serialid, $order ) = @_;
+
+ return unless ( $supplierid or $serialid );
+
my $dbh = C4::Context->dbh;
my $sth;
my $byserial = '';
$sth = $dbh->prepare(
"SELECT
serialid, aqbooksellerid, name,
- biblio.title, planneddate, serialseq,
+ biblio.title, biblioitems.issn, planneddate, serialseq,
serial.status, serial.subscriptionid, claimdate,
subscription.branchcode
FROM serial
LEFT JOIN subscription ON serial.subscriptionid=subscription.subscriptionid
LEFT JOIN biblio ON subscription.biblionumber=biblio.biblionumber
+ LEFT JOIN biblioitems ON subscription.biblionumber=biblioitems.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"
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"
);
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);
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
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 = ?" );
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__