Lines 55-61
use constant MISSING_STATUSES => (
Link Here
|
55 |
MISSING_LOST |
55 |
MISSING_LOST |
56 |
); |
56 |
); |
57 |
|
57 |
|
58 |
|
|
|
59 |
BEGIN { |
58 |
BEGIN { |
60 |
$VERSION = 3.07.00.049; # set version for version checking |
59 |
$VERSION = 3.07.00.049; # set version for version checking |
61 |
require Exporter; |
60 |
require Exporter; |
Lines 118-123
the array is in name order
Link Here
|
118 |
sub GetSuppliersWithLateIssues { |
117 |
sub GetSuppliersWithLateIssues { |
119 |
my $dbh = C4::Context->dbh; |
118 |
my $dbh = C4::Context->dbh; |
120 |
my $statuses = join(',', ( LATE, MISSING_STATUSES ) ); |
119 |
my $statuses = join(',', ( LATE, MISSING_STATUSES ) ); |
|
|
120 |
|
121 |
my $query = qq| |
121 |
my $query = qq| |
122 |
SELECT DISTINCT id, name |
122 |
SELECT DISTINCT id, name |
123 |
FROM subscription |
123 |
FROM subscription |
Lines 846-868
sub GetSerials {
Link Here
|
846 |
|
846 |
|
847 |
=head2 GetSerials2 |
847 |
=head2 GetSerials2 |
848 |
|
848 |
|
849 |
@serials = GetSerials2($subscriptionid,$status); |
849 |
@serials = GetSerials2($subscriptionid,$statuses); |
850 |
this function returns every serial waited for a given subscription |
850 |
this function returns every serial waited for a given subscription |
851 |
as well as the number of issues registered in the database (all types) |
851 |
as well as the number of issues registered in the database (all types) |
852 |
this number is used to see if a subscription can be deleted (=it must have only 1 issue) |
852 |
this number is used to see if a subscription can be deleted (=it must have only 1 issue) |
853 |
|
853 |
|
|
|
854 |
$statuses is an arrayref of statuses. |
855 |
|
854 |
=cut |
856 |
=cut |
855 |
|
857 |
|
856 |
sub GetSerials2 { |
858 |
sub GetSerials2 { |
857 |
my ( $subscription, $status ) = @_; |
859 |
my ( $subscription, $statuses ) = @_; |
|
|
860 |
|
861 |
return unless ($subscription and @$statuses); |
858 |
|
862 |
|
859 |
return unless ($subscription and $status); |
863 |
my $statuses_string = join ',', @$statuses; |
860 |
|
864 |
|
861 |
my $dbh = C4::Context->dbh; |
865 |
my $dbh = C4::Context->dbh; |
862 |
my $query = qq| |
866 |
my $query = qq| |
863 |
SELECT serialid,serialseq, status, planneddate, publisheddate,notes, routingnotes |
867 |
SELECT serialid,serialseq, status, planneddate, publisheddate,notes, routingnotes |
864 |
FROM serial |
868 |
FROM serial |
865 |
WHERE subscriptionid=$subscription AND status IN ($status) |
869 |
WHERE subscriptionid=$subscription AND status IN ($statuses_string) |
866 |
ORDER BY publisheddate,serialid DESC |
870 |
ORDER BY publisheddate,serialid DESC |
867 |
|; |
871 |
|; |
868 |
$debug and warn "GetSerials2 query: $query"; |
872 |
$debug and warn "GetSerials2 query: $query"; |
Lines 902-912
sub GetLatestSerials {
Link Here
|
902 |
|
906 |
|
903 |
my $dbh = C4::Context->dbh; |
907 |
my $dbh = C4::Context->dbh; |
904 |
|
908 |
|
|
|
909 |
my $statuses = join( ',', ( ARRIVED, MISSING_STATUSES ) ); |
905 |
# status = 2 is "arrived" |
910 |
# status = 2 is "arrived" |
906 |
my $strsth = "SELECT serialid,serialseq, status, planneddate, publisheddate, notes |
911 |
my $strsth = "SELECT serialid,serialseq, status, planneddate, publisheddate, notes |
907 |
FROM serial |
912 |
FROM serial |
908 |
WHERE subscriptionid = ? |
913 |
WHERE subscriptionid = ? |
909 |
AND status IN (2, 4, 41, 42, 43, 44) |
914 |
AND status IN ($statuses) |
910 |
ORDER BY publisheddate DESC LIMIT 0,$limit |
915 |
ORDER BY publisheddate DESC LIMIT 0,$limit |
911 |
"; |
916 |
"; |
912 |
my $sth = $dbh->prepare($strsth); |
917 |
my $sth = $dbh->prepare($strsth); |
Lines 1189-1200
sub _update_missinglist {
Link Here
|
1189 |
my $subscriptionid = shift; |
1194 |
my $subscriptionid = shift; |
1190 |
|
1195 |
|
1191 |
my $dbh = C4::Context->dbh; |
1196 |
my $dbh = C4::Context->dbh; |
1192 |
my @missingserials = GetSerials2($subscriptionid, "4,41,42,43,44,5"); |
1197 |
my @missingserials = GetSerials2($subscriptionid, [ MISSING_STATUSES, NOT_ISSUED ]); |
1193 |
my $missinglist; |
1198 |
my $missinglist; |
1194 |
foreach my $missingserial (@missingserials) { |
1199 |
foreach my $missingserial (@missingserials) { |
1195 |
if ( grep { $_ == $missingserial->{status} } qw( 4 41 42 43 44 ) ) { |
1200 |
if ( grep { $_ == $missingserial->{status} } MISSING_STATUSES ) { |
1196 |
$missinglist .= $missingserial->{'serialseq'} . "; "; |
1201 |
$missinglist .= $missingserial->{'serialseq'} . "; "; |
1197 |
} elsif($missingserial->{'status'} == 5) { |
1202 |
} elsif($missingserial->{'status'} == NOT_ISSUED) { |
1198 |
$missinglist .= "not issued " . $missingserial->{'serialseq'} . "; "; |
1203 |
$missinglist .= "not issued " . $missingserial->{'serialseq'} . "; "; |
1199 |
} |
1204 |
} |
1200 |
} |
1205 |
} |
Lines 1213-1219
sub _update_receivedlist {
Link Here
|
1213 |
my $subscriptionid = shift; |
1218 |
my $subscriptionid = shift; |
1214 |
|
1219 |
|
1215 |
my $dbh = C4::Context->dbh; |
1220 |
my $dbh = C4::Context->dbh; |
1216 |
my @receivedserials = GetSerials2($subscriptionid, "2"); |
1221 |
my @receivedserials = GetSerials2($subscriptionid, [ARRIVED]); |
1217 |
my $receivedlist; |
1222 |
my $receivedlist; |
1218 |
foreach (@receivedserials) { |
1223 |
foreach (@receivedserials) { |
1219 |
$receivedlist .= $_->{'serialseq'} . "; "; |
1224 |
$receivedlist .= $_->{'serialseq'} . "; "; |
Lines 1256-1262
sub ModSerialStatus {
Link Here
|
1256 |
|
1261 |
|
1257 |
# change status & update subscriptionhistory |
1262 |
# change status & update subscriptionhistory |
1258 |
my $val; |
1263 |
my $val; |
1259 |
if ( $status == 6 ) { |
1264 |
if ( $status == DELETED ) { |
1260 |
DelIssue( { 'serialid' => $serialid, 'subscriptionid' => $subscriptionid, 'serialseq' => $serialseq } ); |
1265 |
DelIssue( { 'serialid' => $serialid, 'subscriptionid' => $subscriptionid, 'serialseq' => $serialseq } ); |
1261 |
} else { |
1266 |
} else { |
1262 |
|
1267 |
|
Lines 1272-1293
sub ModSerialStatus {
Link Here
|
1272 |
$sth->execute($subscriptionid); |
1277 |
$sth->execute($subscriptionid); |
1273 |
my $val = $sth->fetchrow_hashref; |
1278 |
my $val = $sth->fetchrow_hashref; |
1274 |
unless ( $val->{manualhistory} ) { |
1279 |
unless ( $val->{manualhistory} ) { |
1275 |
if ( $status == 2 || ($oldstatus == 2 && $status != 2) ) { |
1280 |
if ( $status == ARRIVED || ($oldstatus == ARRIVED && $status != ARRIVED) ) { |
1276 |
_update_receivedlist($subscriptionid); |
1281 |
_update_receivedlist($subscriptionid); |
1277 |
} |
1282 |
} |
1278 |
my @missing_statuses = qw( 4 41 42 43 44 ); |
1283 |
if ( ( grep { $_ == $status } ( MISSING_STATUSES, NOT_ISSUED ) ) |
1279 |
if ( ( grep { $_ == $status } ( @missing_statuses, 5 ) ) |
|
|
1280 |
|| ( |
1284 |
|| ( |
1281 |
( grep { $_ == $oldstatus } @missing_statuses ) |
1285 |
( grep { $_ == $oldstatus } ( MISSING_STATUSES ) ) |
1282 |
&& ! ( grep { $_ == $status } @missing_statuses ) ) |
1286 |
&& ! ( grep { $_ == $status } ( MISSING_STATUSES ) ) ) |
1283 |
|| ($oldstatus == 5 && $status != 5)) { |
1287 |
|| ($oldstatus == NOT_ISSUED && $status != NOT_ISSUED)) { |
1284 |
_update_missinglist($subscriptionid); |
1288 |
_update_missinglist($subscriptionid); |
1285 |
} |
1289 |
} |
1286 |
} |
1290 |
} |
1287 |
} |
1291 |
} |
1288 |
|
1292 |
|
1289 |
# create new waited entry if needed (ie : was a "waited" and has changed) |
1293 |
# create new waited entry if needed (ie : was a "waited" and has changed) |
1290 |
if ( $oldstatus == 1 && $status != 1 ) { |
1294 |
if ( $oldstatus == EXPECTED && $status != EXPECTED ) { |
1291 |
my $subscription = GetSubscription($subscriptionid); |
1295 |
my $subscription = GetSubscription($subscriptionid); |
1292 |
my $pattern = C4::Serials::Numberpattern::GetSubscriptionNumberpattern($subscription->{numberpattern}); |
1296 |
my $pattern = C4::Serials::Numberpattern::GetSubscriptionNumberpattern($subscription->{numberpattern}); |
1293 |
|
1297 |
|
Lines 1308-1314
sub ModSerialStatus {
Link Here
|
1308 |
$sth->execute( $newlastvalue1, $newlastvalue2, $newlastvalue3, $newinnerloop1, $newinnerloop2, $newinnerloop3, $subscriptionid ); |
1312 |
$sth->execute( $newlastvalue1, $newlastvalue2, $newlastvalue3, $newinnerloop1, $newinnerloop2, $newinnerloop3, $subscriptionid ); |
1309 |
|
1313 |
|
1310 |
# check if an alert must be sent... (= a letter is defined & status became "arrived" |
1314 |
# check if an alert must be sent... (= a letter is defined & status became "arrived" |
1311 |
if ( $subscription->{letter} && $status == 2 && $oldstatus != 2 ) { |
1315 |
if ( $subscription->{letter} && $status == ARRIVED && $oldstatus != ARRIVED ) { |
1312 |
require C4::Letters; |
1316 |
require C4::Letters; |
1313 |
C4::Letters::SendAlerts( 'issue', $subscription->{subscriptionid}, $subscription->{letter} ); |
1317 |
C4::Letters::SendAlerts( 'issue', $subscription->{subscriptionid}, $subscription->{letter} ); |
1314 |
} |
1318 |
} |
Lines 1346-1352
sub GetNextExpected {
Link Here
|
1346 |
my $sth = $dbh->prepare($query); |
1350 |
my $sth = $dbh->prepare($query); |
1347 |
|
1351 |
|
1348 |
# Each subscription has only one 'expected' issue, with serial.status==1. |
1352 |
# Each subscription has only one 'expected' issue, with serial.status==1. |
1349 |
$sth->execute( $subscriptionid, 1 ); |
1353 |
$sth->execute( $subscriptionid, EXPECTED ); |
1350 |
my $nextissue = $sth->fetchrow_hashref; |
1354 |
my $nextissue = $sth->fetchrow_hashref; |
1351 |
if ( !$nextissue ) { |
1355 |
if ( !$nextissue ) { |
1352 |
$query = qq{ |
1356 |
$query = qq{ |
Lines 1394-1400
sub ModNextExpected {
Link Here
|
1394 |
my $sth = $dbh->prepare('UPDATE serial SET planneddate=?,publisheddate=? WHERE subscriptionid=? AND status=?'); |
1398 |
my $sth = $dbh->prepare('UPDATE serial SET planneddate=?,publisheddate=? WHERE subscriptionid=? AND status=?'); |
1395 |
|
1399 |
|
1396 |
# Each subscription has only one 'expected' issue, with serial.status==1. |
1400 |
# Each subscription has only one 'expected' issue, with serial.status==1. |
1397 |
$sth->execute( $date, $date, $subscriptionid, 1 ); |
1401 |
$sth->execute( $date, $date, $subscriptionid, EXPECTED ); |
1398 |
return 0; |
1402 |
return 0; |
1399 |
|
1403 |
|
1400 |
} |
1404 |
} |
Lines 1564-1570
sub NewSubscription {
Link Here
|
1564 |
VALUES (?,?,?,?,?,?) |
1568 |
VALUES (?,?,?,?,?,?) |
1565 |
|; |
1569 |
|; |
1566 |
$sth = $dbh->prepare($query); |
1570 |
$sth = $dbh->prepare($query); |
1567 |
$sth->execute( "$serialseq", $subscriptionid, $biblionumber, 1, $firstacquidate, $firstacquidate ); |
1571 |
$sth->execute( "$serialseq", $subscriptionid, $biblionumber, EXPECTED, $firstacquidate, $firstacquidate ); |
1568 |
|
1572 |
|
1569 |
logaction( "SERIAL", "ADD", $subscriptionid, "" ) if C4::Context->preference("SubscriptionLog"); |
1573 |
logaction( "SERIAL", "ADD", $subscriptionid, "" ) if C4::Context->preference("SubscriptionLog"); |
1570 |
|
1574 |
|
Lines 1679-1691
sub NewIssue {
Link Here
|
1679 |
$sth->execute($subscriptionid); |
1683 |
$sth->execute($subscriptionid); |
1680 |
my ( $missinglist, $recievedlist ) = $sth->fetchrow; |
1684 |
my ( $missinglist, $recievedlist ) = $sth->fetchrow; |
1681 |
|
1685 |
|
1682 |
if ( $status == 2 ) { |
1686 |
if ( $status == ARRIVED ) { |
1683 |
### TODO Add a feature that improves recognition and description. |
1687 |
### TODO Add a feature that improves recognition and description. |
1684 |
### As such count (serialseq) i.e. : N18,2(N19),N20 |
1688 |
### As such count (serialseq) i.e. : N18,2(N19),N20 |
1685 |
### Would use substr and index But be careful to previous presence of () |
1689 |
### Would use substr and index But be careful to previous presence of () |
1686 |
$recievedlist .= "; $serialseq" unless (index($recievedlist,$serialseq)>0); |
1690 |
$recievedlist .= "; $serialseq" unless (index($recievedlist,$serialseq)>0); |
1687 |
} |
1691 |
} |
1688 |
if ( $status == 4 ) { |
1692 |
if ( grep {/^$status$/} ( MISSING_STATUSES ) ) { |
1689 |
$missinglist .= "; $serialseq" unless (index($missinglist,$serialseq)>0); |
1693 |
$missinglist .= "; $serialseq" unless (index($missinglist,$serialseq)>0); |
1690 |
} |
1694 |
} |
1691 |
$query = qq| |
1695 |
$query = qq| |
Lines 2048-2053
sub GetLateOrMissingIssues {
Link Here
|
2048 |
} else { |
2052 |
} else { |
2049 |
$order = "title"; |
2053 |
$order = "title"; |
2050 |
} |
2054 |
} |
|
|
2055 |
my $missing_statuses_string = join ',', (MISSING_STATUSES); |
2051 |
if ($supplierid) { |
2056 |
if ($supplierid) { |
2052 |
$sth = $dbh->prepare( |
2057 |
$sth = $dbh->prepare( |
2053 |
"SELECT |
2058 |
"SELECT |
Lines 2060-2066
sub GetLateOrMissingIssues {
Link Here
|
2060 |
LEFT JOIN biblio ON subscription.biblionumber=biblio.biblionumber |
2065 |
LEFT JOIN biblio ON subscription.biblionumber=biblio.biblionumber |
2061 |
LEFT JOIN aqbooksellers ON subscription.aqbooksellerid = aqbooksellers.id |
2066 |
LEFT JOIN aqbooksellers ON subscription.aqbooksellerid = aqbooksellers.id |
2062 |
WHERE subscription.subscriptionid = serial.subscriptionid |
2067 |
WHERE subscription.subscriptionid = serial.subscriptionid |
2063 |
AND (serial.STATUS IN (4, 41, 42, 43, 44) OR ((planneddate < now() AND serial.STATUS =1) OR serial.STATUS = 3 OR serial.STATUS = 7)) |
2068 |
AND (serial.STATUS IN ($missing_statuses_string) OR ((planneddate < now() AND serial.STATUS =1) OR serial.STATUS = 3 OR serial.STATUS = 7)) |
2064 |
AND subscription.aqbooksellerid=$supplierid |
2069 |
AND subscription.aqbooksellerid=$supplierid |
2065 |
$byserial |
2070 |
$byserial |
2066 |
ORDER BY $order" |
2071 |
ORDER BY $order" |
Lines 2077-2083
sub GetLateOrMissingIssues {
Link Here
|
2077 |
LEFT JOIN biblio ON subscription.biblionumber=biblio.biblionumber |
2082 |
LEFT JOIN biblio ON subscription.biblionumber=biblio.biblionumber |
2078 |
LEFT JOIN aqbooksellers ON subscription.aqbooksellerid = aqbooksellers.id |
2083 |
LEFT JOIN aqbooksellers ON subscription.aqbooksellerid = aqbooksellers.id |
2079 |
WHERE subscription.subscriptionid = serial.subscriptionid |
2084 |
WHERE subscription.subscriptionid = serial.subscriptionid |
2080 |
AND (serial.STATUS IN (4, 41, 42, 43, 44) OR ((planneddate < now() AND serial.STATUS =1) OR serial.STATUS = 3 OR serial.STATUS = 7)) |
2085 |
AND (serial.STATUS IN ($missing_statuses_string) OR ((planneddate < now() AND serial.STATUS =1) OR serial.STATUS = 3 OR serial.STATUS = 7)) |
2081 |
$byserial |
2086 |
$byserial |
2082 |
ORDER BY $order" |
2087 |
ORDER BY $order" |
2083 |
); |
2088 |
); |