View | Details | Raw Unified | Return to bug 11814
Collapse All | Expand All

(-)a/C4/Serials.pm (-38 / +41 lines)
Lines 56-62 use constant MISSING_STATUSES => ( Link Here
56
    MISSING_LOST
56
    MISSING_LOST
57
);
57
);
58
58
59
60
BEGIN {
59
BEGIN {
61
    $VERSION = 3.07.00.049;    # set version for version checking
60
    $VERSION = 3.07.00.049;    # set version for version checking
62
    require Exporter;
61
    require Exporter;
Lines 336-347 sub UpdateClaimdateIssues { Link Here
336
    my $query = "
335
    my $query = "
337
        UPDATE serial
336
        UPDATE serial
338
        SET claimdate = ?,
337
        SET claimdate = ?,
339
            status = 7,
338
            status = ?,
340
            claims_count = claims_count + 1
339
            claims_count = claims_count + 1
341
        WHERE  serialid in (" . join( ",", map { '?' } @$serialids ) . ")
340
        WHERE  serialid in (" . join( ",", map { '?' } @$serialids ) . ")
342
    ";
341
    ";
343
    my $rq = $dbh->prepare($query);
342
    my $rq = $dbh->prepare($query);
344
    $rq->execute($date, @$serialids);
343
    $rq->execute($date, @$serialids, CLAIMED);
345
    return $rq->rows;
344
    return $rq->rows;
346
}
345
}
347
346
Lines 848-870 sub GetSerials { Link Here
848
847
849
=head2 GetSerials2
848
=head2 GetSerials2
850
849
851
@serials = GetSerials2($subscriptionid,$status);
850
@serials = GetSerials2($subscriptionid,$statuses);
852
this function returns every serial waited for a given subscription
851
this function returns every serial waited for a given subscription
853
as well as the number of issues registered in the database (all types)
852
as well as the number of issues registered in the database (all types)
854
this number is used to see if a subscription can be deleted (=it must have only 1 issue)
853
this number is used to see if a subscription can be deleted (=it must have only 1 issue)
855
854
855
$statuses is an arrayref of statuses.
856
856
=cut
857
=cut
857
858
858
sub GetSerials2 {
859
sub GetSerials2 {
859
    my ( $subscription, $status ) = @_;
860
    my ( $subscription, $statuses ) = @_;
860
861
861
    return unless ($subscription and $status);
862
    return unless ($subscription and @$statuses);
863
864
    my $statuses_string = join ',', @$statuses;
862
865
863
    my $dbh   = C4::Context->dbh;
866
    my $dbh   = C4::Context->dbh;
864
    my $query = qq|
867
    my $query = qq|
865
                 SELECT   serialid,serialseq, status, planneddate, publisheddate,notes, routingnotes
868
                 SELECT   serialid,serialseq, status, planneddate, publisheddate,notes, routingnotes
866
                 FROM     serial 
869
                 FROM     serial 
867
                 WHERE    subscriptionid=$subscription AND status IN ($status)
870
                 WHERE    subscriptionid=$subscription AND status IN ($statuses_string)
868
                 ORDER BY publisheddate,serialid DESC
871
                 ORDER BY publisheddate,serialid DESC
869
                    |;
872
                    |;
870
    $debug and warn "GetSerials2 query: $query";
873
    $debug and warn "GetSerials2 query: $query";
Lines 904-914 sub GetLatestSerials { Link Here
904
907
905
    my $dbh = C4::Context->dbh;
908
    my $dbh = C4::Context->dbh;
906
909
907
    # status = 2 is "arrived"
910
    my $statuses = join( ',', ( ARRIVED, MISSING_STATUSES ) );
908
    my $strsth = "SELECT   serialid,serialseq, status, planneddate, publisheddate, notes
911
    my $strsth = "SELECT   serialid,serialseq, status, planneddate, publisheddate, notes
909
                        FROM     serial
912
                        FROM     serial
910
                        WHERE    subscriptionid = ?
913
                        WHERE    subscriptionid = ?
911
                        AND      status IN (2, 4, 41, 42, 43, 44)
914
                        AND      status IN ($statuses)
912
                        ORDER BY publisheddate DESC LIMIT 0,$limit
915
                        ORDER BY publisheddate DESC LIMIT 0,$limit
913
                ";
916
                ";
914
    my $sth = $dbh->prepare($strsth);
917
    my $sth = $dbh->prepare($strsth);
Lines 1214-1220 sub ModSerialStatus { Link Here
1214
1217
1215
    # change status & update subscriptionhistory
1218
    # change status & update subscriptionhistory
1216
    my $val;
1219
    my $val;
1217
    if ( $status == 6 ) {
1220
    if ( $status == DELETED ) {
1218
        DelIssue( { 'serialid' => $serialid, 'subscriptionid' => $subscriptionid, 'serialseq' => $serialseq } );
1221
        DelIssue( { 'serialid' => $serialid, 'subscriptionid' => $subscriptionid, 'serialseq' => $serialseq } );
1219
    } else {
1222
    } else {
1220
1223
Lines 1231-1251 sub ModSerialStatus { Link Here
1231
            $sth->execute($subscriptionid);
1234
            $sth->execute($subscriptionid);
1232
            my ( $missinglist, $recievedlist ) = $sth->fetchrow;
1235
            my ( $missinglist, $recievedlist ) = $sth->fetchrow;
1233
1236
1234
            if ( $status == 2 || ($oldstatus == 2 && $status != 2) ) {
1237
            if ( $status == ARRIVED || ($oldstatus == ARRIVED && $status != ARRIVED) ) {
1235
                $recievedlist .= "; $serialseq"
1238
                $recievedlist .= "; $serialseq"
1236
                    if ($recievedlist !~ /(^|;)\s*$serialseq(?=;|$)/);
1239
                    if ($recievedlist !~ /(^|;)\s*$serialseq(?=;|$)/);
1237
            }
1240
            }
1238
1241
1239
            # in case serial has been previously marked as missing
1242
            # in case serial has been previously marked as missing
1240
            if (grep /$status/, (1,2,3,7)) {
1243
            if (grep /$status/, (EXPECTED, ARRIVED, LATE, CLAIMED)) {
1241
                $missinglist=~ s/(^|;)\s*$serialseq(?=;|$)//g;
1244
                $missinglist=~ s/(^|;)\s*$serialseq(?=;|$)//g;
1242
            }
1245
            }
1243
1246
1244
            my @missing_statuses = qw( 4 41 42 43 44 );
1245
            $missinglist .= "; $serialseq"
1247
            $missinglist .= "; $serialseq"
1246
                if ( ( grep { $_ == $status } @missing_statuses ) && ( $missinglist !~/(^|;)\s*$serialseq(?=;|$)/ ) );
1248
                if ( ( grep { $_ == $status } ( MISSING_STATUSES ) ) && ( $missinglist !~/(^|;)\s*$serialseq(?=;|$)/ ) );
1247
            $missinglist .= "; not issued $serialseq"
1249
            $missinglist .= "; not issued $serialseq"
1248
                if ( $status == 5 && $missinglist !~ /(^|;)\s*$serialseq(?=;|$)/ );
1250
                if ( $status == NOT_ISSUED && $missinglist !~ /(^|;)\s*$serialseq(?=;|$)/ );
1249
1251
1250
            $query = "UPDATE subscriptionhistory SET recievedlist=?, missinglist=? WHERE  subscriptionid=?";
1252
            $query = "UPDATE subscriptionhistory SET recievedlist=?, missinglist=? WHERE  subscriptionid=?";
1251
            $sth   = $dbh->prepare($query);
1253
            $sth   = $dbh->prepare($query);
Lines 1256-1262 sub ModSerialStatus { Link Here
1256
    }
1258
    }
1257
1259
1258
    # create new waited entry if needed (ie : was a "waited" and has changed)
1260
    # create new waited entry if needed (ie : was a "waited" and has changed)
1259
    if ( $oldstatus == 1 && $status != 1 ) {
1261
    if ( $oldstatus == EXPECTED && $status != EXPECTED ) {
1260
        my $subscription = GetSubscription($subscriptionid);
1262
        my $subscription = GetSubscription($subscriptionid);
1261
        my $pattern = C4::Serials::Numberpattern::GetSubscriptionNumberpattern($subscription->{numberpattern});
1263
        my $pattern = C4::Serials::Numberpattern::GetSubscriptionNumberpattern($subscription->{numberpattern});
1262
1264
Lines 1277-1283 sub ModSerialStatus { Link Here
1277
        $sth->execute( $newlastvalue1, $newlastvalue2, $newlastvalue3, $newinnerloop1, $newinnerloop2, $newinnerloop3, $subscriptionid );
1279
        $sth->execute( $newlastvalue1, $newlastvalue2, $newlastvalue3, $newinnerloop1, $newinnerloop2, $newinnerloop3, $subscriptionid );
1278
1280
1279
        # check if an alert must be sent... (= a letter is defined & status became "arrived"
1281
        # check if an alert must be sent... (= a letter is defined & status became "arrived"
1280
        if ( $subscription->{letter} && $status == 2 && $oldstatus != 2 ) {
1282
        if ( $subscription->{letter} && $status == ARRIVED && $oldstatus != ARRIVED ) {
1281
            require C4::Letters;
1283
            require C4::Letters;
1282
            C4::Letters::SendAlerts( 'issue', $subscription->{subscriptionid}, $subscription->{letter} );
1284
            C4::Letters::SendAlerts( 'issue', $subscription->{subscriptionid}, $subscription->{letter} );
1283
        }
1285
        }
Lines 1314-1321 sub GetNextExpected { Link Here
1314
    };
1316
    };
1315
    my $sth = $dbh->prepare($query);
1317
    my $sth = $dbh->prepare($query);
1316
1318
1317
    # Each subscription has only one 'expected' issue, with serial.status==1.
1319
    # Each subscription has only one 'expected' issue.
1318
    $sth->execute( $subscriptionid, 1 );
1320
    $sth->execute( $subscriptionid, EXPECTED );
1319
    my $nextissue = $sth->fetchrow_hashref;
1321
    my $nextissue = $sth->fetchrow_hashref;
1320
    if ( !$nextissue ) {
1322
    if ( !$nextissue ) {
1321
        $query = qq{
1323
        $query = qq{
Lines 1362-1369 sub ModNextExpected { Link Here
1362
    #FIXME: Would expect to only set planneddate, but we set both on new issue creation, so updating it here
1364
    #FIXME: Would expect to only set planneddate, but we set both on new issue creation, so updating it here
1363
    my $sth = $dbh->prepare('UPDATE serial SET planneddate=?,publisheddate=? WHERE subscriptionid=? AND status=?');
1365
    my $sth = $dbh->prepare('UPDATE serial SET planneddate=?,publisheddate=? WHERE subscriptionid=? AND status=?');
1364
1366
1365
    # Each subscription has only one 'expected' issue, with serial.status==1.
1367
    # Each subscription has only one 'expected' issue.
1366
    $sth->execute( $date, $date, $subscriptionid, 1 );
1368
    $sth->execute( $date, $date, $subscriptionid, EXPECTED );
1367
    return 0;
1369
    return 0;
1368
1370
1369
}
1371
}
Lines 1533-1539 sub NewSubscription { Link Here
1533
        VALUES (?,?,?,?,?,?)
1535
        VALUES (?,?,?,?,?,?)
1534
    |;
1536
    |;
1535
    $sth = $dbh->prepare($query);
1537
    $sth = $dbh->prepare($query);
1536
    $sth->execute( $serialseq, $subscriptionid, $biblionumber, 1, $firstacquidate, $firstacquidate );
1538
    $sth->execute( $serialseq, $subscriptionid, $biblionumber, EXPECTED, $firstacquidate, $firstacquidate );
1537
1539
1538
    logaction( "SERIAL", "ADD", $subscriptionid, "" ) if C4::Context->preference("SubscriptionLog");
1540
    logaction( "SERIAL", "ADD", $subscriptionid, "" ) if C4::Context->preference("SubscriptionLog");
1539
1541
Lines 1648-1660 sub NewIssue { Link Here
1648
    $sth->execute($subscriptionid);
1650
    $sth->execute($subscriptionid);
1649
    my ( $missinglist, $recievedlist ) = $sth->fetchrow;
1651
    my ( $missinglist, $recievedlist ) = $sth->fetchrow;
1650
1652
1651
    if ( $status == 2 ) {
1653
    if ( $status == ARRIVED ) {
1652
      ### TODO Add a feature that improves recognition and description.
1654
      ### TODO Add a feature that improves recognition and description.
1653
      ### As such count (serialseq) i.e. : N18,2(N19),N20
1655
      ### As such count (serialseq) i.e. : N18,2(N19),N20
1654
      ### Would use substr and index But be careful to previous presence of ()
1656
      ### Would use substr and index But be careful to previous presence of ()
1655
        $recievedlist .= "; $serialseq" unless (index($recievedlist,$serialseq)>0);
1657
        $recievedlist .= "; $serialseq" unless (index($recievedlist,$serialseq)>0);
1656
    }
1658
    }
1657
    if ( $status == 4 ) {
1659
    if ( grep {/^$status$/} ( MISSING_STATUSES ) ) {
1658
        $missinglist .= "; $serialseq" unless (index($missinglist,$serialseq)>0);
1660
        $missinglist .= "; $serialseq" unless (index($missinglist,$serialseq)>0);
1659
    }
1661
    }
1660
    $query = qq|
1662
    $query = qq|
Lines 1993-1999 sub DelIssue { Link Here
1993
1995
1994
@issuelist = GetLateMissingIssues($supplierid,$serialid)
1996
@issuelist = GetLateMissingIssues($supplierid,$serialid)
1995
1997
1996
this function selects missing issues on database - where serial.status = 4 or serial.status=3 or planneddate<now
1998
this function selects missing issues on database - where serial.status = MISSING* or serial.status = LATE or planneddate<now
1997
1999
1998
return :
2000
return :
1999
the issuelist as an array of hash refs. Each element of this array contains 
2001
the issuelist as an array of hash refs. Each element of this array contains 
Lines 2017-2022 sub GetLateOrMissingIssues { Link Here
2017
    } else {
2019
    } else {
2018
        $order = "title";
2020
        $order = "title";
2019
    }
2021
    }
2022
    my $missing_statuses_string = join ',', (MISSING_STATUSES);
2020
    if ($supplierid) {
2023
    if ($supplierid) {
2021
        $sth = $dbh->prepare(
2024
        $sth = $dbh->prepare(
2022
            "SELECT
2025
            "SELECT
Lines 2030-2036 sub GetLateOrMissingIssues { Link Here
2030
                LEFT JOIN biblioitems   ON subscription.biblionumber=biblioitems.biblionumber
2033
                LEFT JOIN biblioitems   ON subscription.biblionumber=biblioitems.biblionumber
2031
                LEFT JOIN aqbooksellers ON subscription.aqbooksellerid = aqbooksellers.id
2034
                LEFT JOIN aqbooksellers ON subscription.aqbooksellerid = aqbooksellers.id
2032
                WHERE subscription.subscriptionid = serial.subscriptionid
2035
                WHERE subscription.subscriptionid = serial.subscriptionid
2033
                AND (serial.STATUS IN (4, 41, 42, 43, 44) OR ((planneddate < now() AND serial.STATUS =1) OR serial.STATUS = 3 OR serial.STATUS = 7))
2036
                AND (serial.STATUS IN ($missing_statuses_string) OR ((planneddate < now() AND serial.STATUS = ?) OR serial.STATUS = ? OR serial.STATUS = ?))
2034
                AND subscription.aqbooksellerid=$supplierid
2037
                AND subscription.aqbooksellerid=$supplierid
2035
                $byserial
2038
                $byserial
2036
                ORDER BY $order"
2039
                ORDER BY $order"
Lines 2047-2058 sub GetLateOrMissingIssues { Link Here
2047
                LEFT JOIN biblio ON subscription.biblionumber=biblio.biblionumber
2050
                LEFT JOIN biblio ON subscription.biblionumber=biblio.biblionumber
2048
                LEFT JOIN aqbooksellers ON subscription.aqbooksellerid = aqbooksellers.id
2051
                LEFT JOIN aqbooksellers ON subscription.aqbooksellerid = aqbooksellers.id
2049
                WHERE subscription.subscriptionid = serial.subscriptionid
2052
                WHERE subscription.subscriptionid = serial.subscriptionid
2050
                        AND (serial.STATUS IN (4, 41, 42, 43, 44) OR ((planneddate < now() AND serial.STATUS =1) OR serial.STATUS = 3 OR serial.STATUS = 7))
2053
                        AND (serial.STATUS IN ($missing_statuses_string) OR ((planneddate < now() AND serial.STATUS = ?) OR serial.STATUS = ? OR serial.STATUS = ?))
2051
                $byserial
2054
                $byserial
2052
                ORDER BY $order"
2055
                ORDER BY $order"
2053
        );
2056
        );
2054
    }
2057
    }
2055
    $sth->execute;
2058
    $sth->execute( EXPECTED, LATE, CLAIMED );
2056
    my @issuelist;
2059
    my @issuelist;
2057
    while ( my $line = $sth->fetchrow_hashref ) {
2060
    while ( my $line = $sth->fetchrow_hashref ) {
2058
2061
Lines 2753-2759 sub CloseSubscription { Link Here
2753
    my ( $subscriptionid ) = @_;
2756
    my ( $subscriptionid ) = @_;
2754
    return unless $subscriptionid;
2757
    return unless $subscriptionid;
2755
    my $dbh = C4::Context->dbh;
2758
    my $dbh = C4::Context->dbh;
2756
    my $sth = $dbh->prepare( qq{
2759
    my $sth = $dbh->prepare( q{
2757
        UPDATE subscription
2760
        UPDATE subscription
2758
        SET closed = 1
2761
        SET closed = 1
2759
        WHERE subscriptionid = ?
2762
        WHERE subscriptionid = ?
Lines 2761-2773 sub CloseSubscription { Link Here
2761
    $sth->execute( $subscriptionid );
2764
    $sth->execute( $subscriptionid );
2762
2765
2763
    # Set status = missing when status = stopped
2766
    # Set status = missing when status = stopped
2764
    $sth = $dbh->prepare( qq{
2767
    $sth = $dbh->prepare( q{
2765
        UPDATE serial
2768
        UPDATE serial
2766
        SET status = 8
2769
        SET status = ?
2767
        WHERE subscriptionid = ?
2770
        WHERE subscriptionid = ?
2768
        AND status = 1
2771
        AND status = ?
2769
    } );
2772
    } );
2770
    $sth->execute( $subscriptionid );
2773
    $sth->execute( STOPPED, $subscriptionid, EXPECTED );
2771
}
2774
}
2772
2775
2773
=head2 ReopenSubscription
2776
=head2 ReopenSubscription
Lines 2777-2783 sub ReopenSubscription { Link Here
2777
    my ( $subscriptionid ) = @_;
2780
    my ( $subscriptionid ) = @_;
2778
    return unless $subscriptionid;
2781
    return unless $subscriptionid;
2779
    my $dbh = C4::Context->dbh;
2782
    my $dbh = C4::Context->dbh;
2780
    my $sth = $dbh->prepare( qq{
2783
    my $sth = $dbh->prepare( q{
2781
        UPDATE subscription
2784
        UPDATE subscription
2782
        SET closed = 0
2785
        SET closed = 0
2783
        WHERE subscriptionid = ?
2786
        WHERE subscriptionid = ?
Lines 2785-2797 sub ReopenSubscription { Link Here
2785
    $sth->execute( $subscriptionid );
2788
    $sth->execute( $subscriptionid );
2786
2789
2787
    # Set status = expected when status = stopped
2790
    # Set status = expected when status = stopped
2788
    $sth = $dbh->prepare( qq{
2791
    $sth = $dbh->prepare( q{
2789
        UPDATE serial
2792
        UPDATE serial
2790
        SET status = 1
2793
        SET status = ?
2791
        WHERE subscriptionid = ?
2794
        WHERE subscriptionid = ?
2792
        AND status = 8
2795
        AND status = ?
2793
    } );
2796
    } );
2794
    $sth->execute( $subscriptionid );
2797
    $sth->execute( EXPECTED, $subscriptionid, STOPPED );
2795
}
2798
}
2796
2799
2797
=head2 subscriptionCurrentlyOnOrder
2800
=head2 subscriptionCurrentlyOnOrder
(-)a/serials/serials-edit.pl (-2 / +2 lines)
Lines 94-102 my @errseq; Link Here
94
# If user comes from subscription details
94
# If user comes from subscription details
95
unless (@serialids) {
95
unless (@serialids) {
96
    my $serstatus = $query->param('serstatus');
96
    my $serstatus = $query->param('serstatus');
97
    my @statuses = split ',', $serstatus;
97
    if ($serstatus) {
98
    if ($serstatus) {
98
        foreach my $subscriptionid (@subscriptionids) {
99
        foreach my $subscriptionid (@subscriptionids) {
99
            my @tmpser = GetSerials2( $subscriptionid, $serstatus );
100
            my @tmpser = GetSerials2( $subscriptionid, \@statuses );
100
            push @serialids, map { $_->{serialid} } @tmpser;
101
            push @serialids, map { $_->{serialid} } @tmpser;
101
        }
102
        }
102
    }
103
    }
103
- 

Return to bug 11814