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 333-342
sub UpdateClaimdateIssues {
Link Here
|
333 |
my $dbh = C4::Context->dbh; |
333 |
my $dbh = C4::Context->dbh; |
334 |
$date = strftime( "%Y-%m-%d", localtime ) unless ($date); |
334 |
$date = strftime( "%Y-%m-%d", localtime ) unless ($date); |
335 |
my $query = " |
335 |
my $query = " |
336 |
UPDATE serial SET claimdate = ?, status = 7 |
336 |
UPDATE serial SET claimdate = ?, status = ? |
337 |
WHERE serialid in (" . join( ",", map { '?' } @$serialids ) . ")"; |
337 |
WHERE serialid in (" . join( ",", map { '?' } @$serialids ) . ")"; |
338 |
my $rq = $dbh->prepare($query); |
338 |
my $rq = $dbh->prepare($query); |
339 |
$rq->execute($date, @$serialids); |
339 |
$rq->execute($date, @$serialids, CLAIMED); |
340 |
return $rq->rows; |
340 |
return $rq->rows; |
341 |
} |
341 |
} |
342 |
|
342 |
|
Lines 843-865
sub GetSerials {
Link Here
|
843 |
|
843 |
|
844 |
=head2 GetSerials2 |
844 |
=head2 GetSerials2 |
845 |
|
845 |
|
846 |
@serials = GetSerials2($subscriptionid,$status); |
846 |
@serials = GetSerials2($subscriptionid,$statuses); |
847 |
this function returns every serial waited for a given subscription |
847 |
this function returns every serial waited for a given subscription |
848 |
as well as the number of issues registered in the database (all types) |
848 |
as well as the number of issues registered in the database (all types) |
849 |
this number is used to see if a subscription can be deleted (=it must have only 1 issue) |
849 |
this number is used to see if a subscription can be deleted (=it must have only 1 issue) |
850 |
|
850 |
|
|
|
851 |
$statuses is an arrayref of statuses. |
852 |
|
851 |
=cut |
853 |
=cut |
852 |
|
854 |
|
853 |
sub GetSerials2 { |
855 |
sub GetSerials2 { |
854 |
my ( $subscription, $status ) = @_; |
856 |
my ( $subscription, $statuses ) = @_; |
|
|
857 |
|
858 |
return unless ($subscription and @$statuses); |
855 |
|
859 |
|
856 |
return unless ($subscription and $status); |
860 |
my $statuses_string = join ',', @$statuses; |
857 |
|
861 |
|
858 |
my $dbh = C4::Context->dbh; |
862 |
my $dbh = C4::Context->dbh; |
859 |
my $query = qq| |
863 |
my $query = qq| |
860 |
SELECT serialid,serialseq, status, planneddate, publisheddate,notes, routingnotes |
864 |
SELECT serialid,serialseq, status, planneddate, publisheddate,notes, routingnotes |
861 |
FROM serial |
865 |
FROM serial |
862 |
WHERE subscriptionid=$subscription AND status IN ($status) |
866 |
WHERE subscriptionid=$subscription AND status IN ($statuses_string) |
863 |
ORDER BY publisheddate,serialid DESC |
867 |
ORDER BY publisheddate,serialid DESC |
864 |
|; |
868 |
|; |
865 |
$debug and warn "GetSerials2 query: $query"; |
869 |
$debug and warn "GetSerials2 query: $query"; |
Lines 899-909
sub GetLatestSerials {
Link Here
|
899 |
|
903 |
|
900 |
my $dbh = C4::Context->dbh; |
904 |
my $dbh = C4::Context->dbh; |
901 |
|
905 |
|
|
|
906 |
my $statuses = join( ',', ( ARRIVED, MISSING_STATUSES ) ); |
902 |
# status = 2 is "arrived" |
907 |
# status = 2 is "arrived" |
903 |
my $strsth = "SELECT serialid,serialseq, status, planneddate, publisheddate, notes |
908 |
my $strsth = "SELECT serialid,serialseq, status, planneddate, publisheddate, notes |
904 |
FROM serial |
909 |
FROM serial |
905 |
WHERE subscriptionid = ? |
910 |
WHERE subscriptionid = ? |
906 |
AND status IN (2, 4, 41, 42, 43, 44) |
911 |
AND status IN ($statuses) |
907 |
ORDER BY publisheddate DESC LIMIT 0,$limit |
912 |
ORDER BY publisheddate DESC LIMIT 0,$limit |
908 |
"; |
913 |
"; |
909 |
my $sth = $dbh->prepare($strsth); |
914 |
my $sth = $dbh->prepare($strsth); |
Lines 1186-1197
sub _update_missinglist {
Link Here
|
1186 |
my $subscriptionid = shift; |
1191 |
my $subscriptionid = shift; |
1187 |
|
1192 |
|
1188 |
my $dbh = C4::Context->dbh; |
1193 |
my $dbh = C4::Context->dbh; |
1189 |
my @missingserials = GetSerials2($subscriptionid, "4,41,42,43,44,5"); |
1194 |
my @missingserials = GetSerials2($subscriptionid, [ MISSING_STATUSES, NOT_ISSUED ]); |
1190 |
my $missinglist; |
1195 |
my $missinglist; |
1191 |
foreach my $missingserial (@missingserials) { |
1196 |
foreach my $missingserial (@missingserials) { |
1192 |
if ( grep { $_ == $missingserial->{status} } qw( 4 41 42 43 44 ) ) { |
1197 |
if ( grep { $_ == $missingserial->{status} } MISSING_STATUSES ) { |
1193 |
$missinglist .= $missingserial->{'serialseq'} . "; "; |
1198 |
$missinglist .= $missingserial->{'serialseq'} . "; "; |
1194 |
} elsif($missingserial->{'status'} == 5) { |
1199 |
} elsif($missingserial->{'status'} == NOT_ISSUED) { |
1195 |
$missinglist .= "not issued " . $missingserial->{'serialseq'} . "; "; |
1200 |
$missinglist .= "not issued " . $missingserial->{'serialseq'} . "; "; |
1196 |
} |
1201 |
} |
1197 |
} |
1202 |
} |
Lines 1210-1216
sub _update_receivedlist {
Link Here
|
1210 |
my $subscriptionid = shift; |
1215 |
my $subscriptionid = shift; |
1211 |
|
1216 |
|
1212 |
my $dbh = C4::Context->dbh; |
1217 |
my $dbh = C4::Context->dbh; |
1213 |
my @receivedserials = GetSerials2($subscriptionid, "2"); |
1218 |
my @receivedserials = GetSerials2($subscriptionid, [ARRIVED]); |
1214 |
my $receivedlist; |
1219 |
my $receivedlist; |
1215 |
foreach (@receivedserials) { |
1220 |
foreach (@receivedserials) { |
1216 |
$receivedlist .= $_->{'serialseq'} . "; "; |
1221 |
$receivedlist .= $_->{'serialseq'} . "; "; |
Lines 1253-1259
sub ModSerialStatus {
Link Here
|
1253 |
|
1258 |
|
1254 |
# change status & update subscriptionhistory |
1259 |
# change status & update subscriptionhistory |
1255 |
my $val; |
1260 |
my $val; |
1256 |
if ( $status == 6 ) { |
1261 |
if ( $status == DELETED ) { |
1257 |
DelIssue( { 'serialid' => $serialid, 'subscriptionid' => $subscriptionid, 'serialseq' => $serialseq } ); |
1262 |
DelIssue( { 'serialid' => $serialid, 'subscriptionid' => $subscriptionid, 'serialseq' => $serialseq } ); |
1258 |
} else { |
1263 |
} else { |
1259 |
|
1264 |
|
Lines 1265-1286
sub ModSerialStatus {
Link Here
|
1265 |
$sth->execute($subscriptionid); |
1270 |
$sth->execute($subscriptionid); |
1266 |
my $val = $sth->fetchrow_hashref; |
1271 |
my $val = $sth->fetchrow_hashref; |
1267 |
unless ( $val->{manualhistory} ) { |
1272 |
unless ( $val->{manualhistory} ) { |
1268 |
if ( $status == 2 || ($oldstatus == 2 && $status != 2) ) { |
1273 |
if ( $status == ARRIVED || ($oldstatus == ARRIVED && $status != ARRIVED) ) { |
1269 |
_update_receivedlist($subscriptionid); |
1274 |
_update_receivedlist($subscriptionid); |
1270 |
} |
1275 |
} |
1271 |
my @missing_statuses = qw( 4 41 42 43 44 ); |
1276 |
if ( ( grep { $_ == $status } ( MISSING_STATUSES, NOT_ISSUED ) ) |
1272 |
if ( ( grep { $_ == $status } ( @missing_statuses, 5 ) ) |
|
|
1273 |
|| ( |
1277 |
|| ( |
1274 |
( grep { $_ == $oldstatus } @missing_statuses ) |
1278 |
( grep { $_ == $oldstatus } ( MISSING_STATUSES ) ) |
1275 |
&& ! ( grep { $_ == $status } @missing_statuses ) ) |
1279 |
&& ! ( grep { $_ == $status } ( MISSING_STATUSES ) ) ) |
1276 |
|| ($oldstatus == 5 && $status != 5)) { |
1280 |
|| ($oldstatus == NOT_ISSUED && $status != NOT_ISSUED)) { |
1277 |
_update_missinglist($subscriptionid); |
1281 |
_update_missinglist($subscriptionid); |
1278 |
} |
1282 |
} |
1279 |
} |
1283 |
} |
1280 |
} |
1284 |
} |
1281 |
|
1285 |
|
1282 |
# create new waited entry if needed (ie : was a "waited" and has changed) |
1286 |
# create new waited entry if needed (ie : was a "waited" and has changed) |
1283 |
if ( $oldstatus == 1 && $status != 1 ) { |
1287 |
if ( $oldstatus == EXPECTED && $status != EXPECTED ) { |
1284 |
my $subscription = GetSubscription($subscriptionid); |
1288 |
my $subscription = GetSubscription($subscriptionid); |
1285 |
my $pattern = C4::Serials::Numberpattern::GetSubscriptionNumberpattern($subscription->{numberpattern}); |
1289 |
my $pattern = C4::Serials::Numberpattern::GetSubscriptionNumberpattern($subscription->{numberpattern}); |
1286 |
|
1290 |
|
Lines 1301-1307
sub ModSerialStatus {
Link Here
|
1301 |
$sth->execute( $newlastvalue1, $newlastvalue2, $newlastvalue3, $newinnerloop1, $newinnerloop2, $newinnerloop3, $subscriptionid ); |
1305 |
$sth->execute( $newlastvalue1, $newlastvalue2, $newlastvalue3, $newinnerloop1, $newinnerloop2, $newinnerloop3, $subscriptionid ); |
1302 |
|
1306 |
|
1303 |
# check if an alert must be sent... (= a letter is defined & status became "arrived" |
1307 |
# check if an alert must be sent... (= a letter is defined & status became "arrived" |
1304 |
if ( $subscription->{letter} && $status == 2 && $oldstatus != 2 ) { |
1308 |
if ( $subscription->{letter} && $status == ARRIVED && $oldstatus != ARRIVED ) { |
1305 |
require C4::Letters; |
1309 |
require C4::Letters; |
1306 |
C4::Letters::SendAlerts( 'issue', $subscription->{subscriptionid}, $subscription->{letter} ); |
1310 |
C4::Letters::SendAlerts( 'issue', $subscription->{subscriptionid}, $subscription->{letter} ); |
1307 |
} |
1311 |
} |
Lines 1339-1345
sub GetNextExpected {
Link Here
|
1339 |
my $sth = $dbh->prepare($query); |
1343 |
my $sth = $dbh->prepare($query); |
1340 |
|
1344 |
|
1341 |
# Each subscription has only one 'expected' issue, with serial.status==1. |
1345 |
# Each subscription has only one 'expected' issue, with serial.status==1. |
1342 |
$sth->execute( $subscriptionid, 1 ); |
1346 |
$sth->execute( $subscriptionid, EXPECTED ); |
1343 |
my $nextissue = $sth->fetchrow_hashref; |
1347 |
my $nextissue = $sth->fetchrow_hashref; |
1344 |
if ( !$nextissue ) { |
1348 |
if ( !$nextissue ) { |
1345 |
$query = qq{ |
1349 |
$query = qq{ |
Lines 1387-1393
sub ModNextExpected {
Link Here
|
1387 |
my $sth = $dbh->prepare('UPDATE serial SET planneddate=?,publisheddate=? WHERE subscriptionid=? AND status=?'); |
1391 |
my $sth = $dbh->prepare('UPDATE serial SET planneddate=?,publisheddate=? WHERE subscriptionid=? AND status=?'); |
1388 |
|
1392 |
|
1389 |
# Each subscription has only one 'expected' issue, with serial.status==1. |
1393 |
# Each subscription has only one 'expected' issue, with serial.status==1. |
1390 |
$sth->execute( $date, $date, $subscriptionid, 1 ); |
1394 |
$sth->execute( $date, $date, $subscriptionid, EXPECTED ); |
1391 |
return 0; |
1395 |
return 0; |
1392 |
|
1396 |
|
1393 |
} |
1397 |
} |
Lines 1557-1563
sub NewSubscription {
Link Here
|
1557 |
VALUES (?,?,?,?,?,?) |
1561 |
VALUES (?,?,?,?,?,?) |
1558 |
|; |
1562 |
|; |
1559 |
$sth = $dbh->prepare($query); |
1563 |
$sth = $dbh->prepare($query); |
1560 |
$sth->execute( $serialseq, $subscriptionid, $biblionumber, 1, $firstacquidate, $firstacquidate ); |
1564 |
$sth->execute( $serialseq, $subscriptionid, $biblionumber, EXPECTED, $firstacquidate, $firstacquidate ); |
1561 |
|
1565 |
|
1562 |
logaction( "SERIAL", "ADD", $subscriptionid, "" ) if C4::Context->preference("SubscriptionLog"); |
1566 |
logaction( "SERIAL", "ADD", $subscriptionid, "" ) if C4::Context->preference("SubscriptionLog"); |
1563 |
|
1567 |
|
Lines 1672-1684
sub NewIssue {
Link Here
|
1672 |
$sth->execute($subscriptionid); |
1676 |
$sth->execute($subscriptionid); |
1673 |
my ( $missinglist, $recievedlist ) = $sth->fetchrow; |
1677 |
my ( $missinglist, $recievedlist ) = $sth->fetchrow; |
1674 |
|
1678 |
|
1675 |
if ( $status == 2 ) { |
1679 |
if ( $status == ARRIVED ) { |
1676 |
### TODO Add a feature that improves recognition and description. |
1680 |
### TODO Add a feature that improves recognition and description. |
1677 |
### As such count (serialseq) i.e. : N18,2(N19),N20 |
1681 |
### As such count (serialseq) i.e. : N18,2(N19),N20 |
1678 |
### Would use substr and index But be careful to previous presence of () |
1682 |
### Would use substr and index But be careful to previous presence of () |
1679 |
$recievedlist .= "; $serialseq" unless (index($recievedlist,$serialseq)>0); |
1683 |
$recievedlist .= "; $serialseq" unless (index($recievedlist,$serialseq)>0); |
1680 |
} |
1684 |
} |
1681 |
if ( $status == 4 ) { |
1685 |
if ( grep {/^$status$/} ( MISSING_STATUSES ) ) { |
1682 |
$missinglist .= "; $serialseq" unless (index($missinglist,$serialseq)>0); |
1686 |
$missinglist .= "; $serialseq" unless (index($missinglist,$serialseq)>0); |
1683 |
} |
1687 |
} |
1684 |
$query = qq| |
1688 |
$query = qq| |
Lines 2041-2046
sub GetLateOrMissingIssues {
Link Here
|
2041 |
} else { |
2045 |
} else { |
2042 |
$order = "title"; |
2046 |
$order = "title"; |
2043 |
} |
2047 |
} |
|
|
2048 |
my $missing_statuses_string = join ',', (MISSING_STATUSES); |
2044 |
if ($supplierid) { |
2049 |
if ($supplierid) { |
2045 |
$sth = $dbh->prepare( |
2050 |
$sth = $dbh->prepare( |
2046 |
"SELECT |
2051 |
"SELECT |
Lines 2054-2060
sub GetLateOrMissingIssues {
Link Here
|
2054 |
LEFT JOIN biblioitems ON subscription.biblionumber=biblioitems.biblionumber |
2059 |
LEFT JOIN biblioitems ON subscription.biblionumber=biblioitems.biblionumber |
2055 |
LEFT JOIN aqbooksellers ON subscription.aqbooksellerid = aqbooksellers.id |
2060 |
LEFT JOIN aqbooksellers ON subscription.aqbooksellerid = aqbooksellers.id |
2056 |
WHERE subscription.subscriptionid = serial.subscriptionid |
2061 |
WHERE subscription.subscriptionid = serial.subscriptionid |
2057 |
AND (serial.STATUS IN (4, 41, 42, 43, 44) OR ((planneddate < now() AND serial.STATUS =1) OR serial.STATUS = 3 OR serial.STATUS = 7)) |
2062 |
AND (serial.STATUS IN ($missing_statuses_string) OR ((planneddate < now() AND serial.STATUS = ?) OR serial.STATUS = ? OR serial.STATUS = ?)) |
2058 |
AND subscription.aqbooksellerid=$supplierid |
2063 |
AND subscription.aqbooksellerid=$supplierid |
2059 |
$byserial |
2064 |
$byserial |
2060 |
ORDER BY $order" |
2065 |
ORDER BY $order" |
Lines 2071-2082
sub GetLateOrMissingIssues {
Link Here
|
2071 |
LEFT JOIN biblio ON subscription.biblionumber=biblio.biblionumber |
2076 |
LEFT JOIN biblio ON subscription.biblionumber=biblio.biblionumber |
2072 |
LEFT JOIN aqbooksellers ON subscription.aqbooksellerid = aqbooksellers.id |
2077 |
LEFT JOIN aqbooksellers ON subscription.aqbooksellerid = aqbooksellers.id |
2073 |
WHERE subscription.subscriptionid = serial.subscriptionid |
2078 |
WHERE subscription.subscriptionid = serial.subscriptionid |
2074 |
AND (serial.STATUS IN (4, 41, 42, 43, 44) OR ((planneddate < now() AND serial.STATUS =1) OR serial.STATUS = 3 OR serial.STATUS = 7)) |
2079 |
AND (serial.STATUS IN ($missing_statuses_string) OR ((planneddate < now() AND serial.STATUS =?) OR serial.STATUS = ? OR serial.STATUS = ?)) |
2075 |
$byserial |
2080 |
$byserial |
2076 |
ORDER BY $order" |
2081 |
ORDER BY $order" |
2077 |
); |
2082 |
); |
2078 |
} |
2083 |
} |
2079 |
$sth->execute; |
2084 |
$sth->execute( EXPECTED, LATE, CLAIMED ); |
2080 |
my @issuelist; |
2085 |
my @issuelist; |
2081 |
while ( my $line = $sth->fetchrow_hashref ) { |
2086 |
while ( my $line = $sth->fetchrow_hashref ) { |
2082 |
|
2087 |
|
Lines 2784-2790
sub CloseSubscription {
Link Here
|
2784 |
my ( $subscriptionid ) = @_; |
2789 |
my ( $subscriptionid ) = @_; |
2785 |
return unless $subscriptionid; |
2790 |
return unless $subscriptionid; |
2786 |
my $dbh = C4::Context->dbh; |
2791 |
my $dbh = C4::Context->dbh; |
2787 |
my $sth = $dbh->prepare( qq{ |
2792 |
my $sth = $dbh->prepare( q{ |
2788 |
UPDATE subscription |
2793 |
UPDATE subscription |
2789 |
SET closed = 1 |
2794 |
SET closed = 1 |
2790 |
WHERE subscriptionid = ? |
2795 |
WHERE subscriptionid = ? |
Lines 2792-2804
sub CloseSubscription {
Link Here
|
2792 |
$sth->execute( $subscriptionid ); |
2797 |
$sth->execute( $subscriptionid ); |
2793 |
|
2798 |
|
2794 |
# Set status = missing when status = stopped |
2799 |
# Set status = missing when status = stopped |
2795 |
$sth = $dbh->prepare( qq{ |
2800 |
$sth = $dbh->prepare( q{ |
2796 |
UPDATE serial |
2801 |
UPDATE serial |
2797 |
SET status = 8 |
2802 |
SET status = ? |
2798 |
WHERE subscriptionid = ? |
2803 |
WHERE subscriptionid = ? |
2799 |
AND status = 1 |
2804 |
AND status = 1 |
2800 |
} ); |
2805 |
} ); |
2801 |
$sth->execute( $subscriptionid ); |
2806 |
$sth->execute( STOPPED, $subscriptionid ); |
2802 |
} |
2807 |
} |
2803 |
|
2808 |
|
2804 |
=head2 ReopenSubscription |
2809 |
=head2 ReopenSubscription |
Lines 2808-2814
sub ReopenSubscription {
Link Here
|
2808 |
my ( $subscriptionid ) = @_; |
2813 |
my ( $subscriptionid ) = @_; |
2809 |
return unless $subscriptionid; |
2814 |
return unless $subscriptionid; |
2810 |
my $dbh = C4::Context->dbh; |
2815 |
my $dbh = C4::Context->dbh; |
2811 |
my $sth = $dbh->prepare( qq{ |
2816 |
my $sth = $dbh->prepare( q{ |
2812 |
UPDATE subscription |
2817 |
UPDATE subscription |
2813 |
SET closed = 0 |
2818 |
SET closed = 0 |
2814 |
WHERE subscriptionid = ? |
2819 |
WHERE subscriptionid = ? |
Lines 2816-2828
sub ReopenSubscription {
Link Here
|
2816 |
$sth->execute( $subscriptionid ); |
2821 |
$sth->execute( $subscriptionid ); |
2817 |
|
2822 |
|
2818 |
# Set status = expected when status = stopped |
2823 |
# Set status = expected when status = stopped |
2819 |
$sth = $dbh->prepare( qq{ |
2824 |
$sth = $dbh->prepare( q{ |
2820 |
UPDATE serial |
2825 |
UPDATE serial |
2821 |
SET status = 1 |
2826 |
SET status = 1 |
2822 |
WHERE subscriptionid = ? |
2827 |
WHERE subscriptionid = ? |
2823 |
AND status = 8 |
2828 |
AND status = ? |
2824 |
} ); |
2829 |
} ); |
2825 |
$sth->execute( $subscriptionid ); |
2830 |
$sth->execute( $subscriptionid, STOPPED ); |
2826 |
} |
2831 |
} |
2827 |
|
2832 |
|
2828 |
=head2 subscriptionCurrentlyOnOrder |
2833 |
=head2 subscriptionCurrentlyOnOrder |