&CountIssues
HasItems
&GetSubscriptionsFromBorrower
+ &subscriptionCurrentlyOnOrder
);
}
FROM subscription
LEFT JOIN serial ON serial.subscriptionid=subscription.subscriptionid
LEFT JOIN aqbooksellers ON subscription.aqbooksellerid = aqbooksellers.id
- WHERE id > 0 AND ((planneddate < now() AND serial.status=1) OR serial.STATUS = 3 OR serial.STATUS = 4) ORDER BY name|;
+ WHERE id > 0
+ AND (
+ (planneddate < now() AND serial.status=1)
+ OR serial.STATUS = 3 OR serial.STATUS = 4
+ )
+ AND subscription.closed = 0
+ ORDER BY name|;
return $dbh->selectall_arrayref($query, { Slice => {} });
}
LEFT JOIN aqbooksellers ON subscription.aqbooksellerid = aqbooksellers.id
WHERE ((planneddate < now() AND serial.STATUS =1) OR serial.STATUS = 3)
AND subscription.aqbooksellerid=?
+ AND subscription.closed = 0
ORDER BY title
|;
$sth = $dbh->prepare($query);
LEFT JOIN biblio ON biblio.biblionumber = subscription.biblionumber
LEFT JOIN aqbooksellers ON subscription.aqbooksellerid = aqbooksellers.id
WHERE ((planneddate < now() AND serial.STATUS =1) OR serial.STATUS = 3)
+ AND subscription.closed = 0
ORDER BY title
|;
$sth = $dbh->prepare($query);
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')
+ if ( C4::Context->preference('IndependentBranches')
&& C4::Context->userenv
&& C4::Context->userenv->{'flags'} != 1
&& C4::Context->userenv->{'branch'} ) {
this function returns the subscription which has $subscriptionid as id.
return :
a hashref. This hash containts
-subscription, subscriptionhistory, aqbudget.bookfundid, biblio.title
+subscription, subscriptionhistory, aqbooksellers.name, biblio.title
=cut
aqbooksellers.name AS aqbooksellername,
biblio.title AS bibliotitle,
subscription.biblionumber as bibnum);
- if ( C4::Context->preference('IndependantBranches')
+ if ( C4::Context->preference('IndependentBranches')
&& C4::Context->userenv
&& C4::Context->userenv->{'flags'} != 1
&& C4::Context->userenv->{'branch'} ) {
WHERE subscription.subscriptionid = ?
);
- # if (C4::Context->preference('IndependantBranches') &&
+ # if (C4::Context->preference('IndependentBranches') &&
# C4::Context->userenv &&
# C4::Context->userenv->{'flags'} != 1){
# # $debug and warn "flags: ".C4::Context->userenv->{'flags'};
biblio.title as bibliotitle,
subscription.branchcode AS branchcode,
subscription.subscriptionid AS subscriptionid |;
- if ( C4::Context->preference('IndependantBranches')
+ if ( C4::Context->preference('IndependentBranches')
&& C4::Context->userenv
&& C4::Context->userenv->{'flags'} != 1
&& C4::Context->userenv->{'branch'} ) {
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/;
$subs->{ "numberpattern" . $subs->{numberpattern} } = 1;
$subs->{ "status" . $subs->{'status'} } = 1;
$subs->{'cannotedit'} =
- ( C4::Context->preference('IndependantBranches')
+ ( C4::Context->preference('IndependentBranches')
&& C4::Context->userenv
&& C4::Context->userenv->{flags} % 2 != 1
&& C4::Context->userenv->{branch}
biblio.title as bibliotitle,
subscription.branchcode AS branchcode,
subscription.subscriptionid AS subscriptionid|;
- if ( C4::Context->preference('IndependantBranches')
+ if ( C4::Context->preference('IndependentBranches')
&& C4::Context->userenv
&& C4::Context->userenv->{'flags'} != 1
&& C4::Context->userenv->{'branch'} ) {
while ( my $line = $sth->fetchrow_hashref ) {
$line->{'cannotedit'} =
- ( C4::Context->preference('IndependantBranches')
+ ( C4::Context->preference('IndependentBranches')
&& C4::Context->userenv
&& C4::Context->userenv->{flags} % 2 != 1
&& C4::Context->userenv->{branch}
push @where_args, $args->{biblionumber};
}
if( $args->{title} ){
- push @where_strs, "biblio.title LIKE ?";
- push @where_args, "%$args->{title}%";
+ my @words = split / /, $args->{title};
+ my (@strs, @args);
+ foreach my $word (@words) {
+ push @strs, "biblio.title LIKE ?";
+ push @args, "%$word%";
+ }
+ if (@strs) {
+ push @where_strs, '(' . join (' AND ', @strs) . ')';
+ push @where_args, @args;
+ }
}
if( $args->{issn} ){
push @where_strs, "biblioitems.issn LIKE ?";
push @where_strs, "subscription.branchcode = ?";
push @where_args, "$args->{branch}";
}
-
+ if( defined $args->{closed} ){
+ push @where_strs, "subscription.closed = ?";
+ push @where_args, "$args->{closed}";
+ }
if(@where_strs){
$query .= " WHERE " . join(" AND ", @where_strs);
}
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)
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;
}
$sth->execute($subscriptionid);
my ( $missinglist, $recievedlist ) = $sth->fetchrow;
if ( $status == 2 ) {
-
$recievedlist .= "; $serialseq"
- unless ( index( "$recievedlist", "$serialseq" ) >= 0 );
+ if $recievedlist!~/(^|;)\s*$serialseq(?=;|$)/;
+ }
+ # in case serial has been previously marked as missing
+ if (grep /$status/, (1,2,3,7)) {
+ $missinglist=~ s/(^|;)\s*$serialseq(?=;|$)//g;
}
-
- # warn "missinglist : $missinglist serialseq :$serialseq, ".index("$missinglist","$serialseq");
$missinglist .= "; $serialseq"
- if ( $status == 4
- and not index( "$missinglist", "$serialseq" ) >= 0 );
+ if $status==4 && $missinglist!~/(^|;)\s*$serialseq(?=;|$)/;
$missinglist .= "; not issued $serialseq"
- if ( $status == 5
- and index( "$missinglist", "$serialseq" ) >= 0 );
+ if $status==5 && $missinglist!~/(^|;)\s*$serialseq(?=;|$)/;
+
$query = "UPDATE subscriptionhistory SET recievedlist=?, missinglist=? WHERE subscriptionid=?";
$sth = $dbh->prepare($query);
$recievedlist =~ s/^; //;
# renew subscription
$query = qq|
UPDATE subscription
- SET startdate=?,numberlength=?,weeklength=?,monthlength=?
+ SET startdate=?,numberlength=?,weeklength=?,monthlength=?,reneweddate=NOW()
WHERE subscriptionid=?
|;
$sth = $dbh->prepare($query);
return @{$occurences};
}
+=head2 CloseSubscription
+Close a subscription given a subscriptionid
+=cut
+sub CloseSubscription {
+ my ( $subscriptionid ) = @_;
+ return unless $subscriptionid;
+ my $dbh = C4::Context->dbh;
+ my $sth = $dbh->prepare( qq{
+ UPDATE subscription
+ SET closed = 1
+ WHERE subscriptionid = ?
+ } );
+ $sth->execute( $subscriptionid );
+
+ # Set status = missing when status = stopped
+ $sth = $dbh->prepare( qq{
+ UPDATE serial
+ SET status = 8
+ WHERE subscriptionid = ?
+ AND status = 1
+ } );
+ $sth->execute( $subscriptionid );
+}
+
+=head2 ReopenSubscription
+Reopen a subscription given a subscriptionid
+=cut
+sub ReopenSubscription {
+ my ( $subscriptionid ) = @_;
+ return unless $subscriptionid;
+ my $dbh = C4::Context->dbh;
+ my $sth = $dbh->prepare( qq{
+ UPDATE subscription
+ SET closed = 0
+ WHERE subscriptionid = ?
+ } );
+ $sth->execute( $subscriptionid );
+
+ # Set status = expected when status = stopped
+ $sth = $dbh->prepare( qq{
+ UPDATE serial
+ SET status = 1
+ WHERE subscriptionid = ?
+ AND status = 8
+ } );
+ $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;
+}
+
1;
__END__