|
Lines 78-88
BEGIN {
Link Here
|
| 78 |
&GetSerialInformation &AddItem2Serial |
78 |
&GetSerialInformation &AddItem2Serial |
| 79 |
&PrepareSerialsData &GetNextExpected &ModNextExpected |
79 |
&PrepareSerialsData &GetNextExpected &ModNextExpected |
| 80 |
&GetPreviousSerialid |
80 |
&GetPreviousSerialid |
|
|
81 |
GetSerial GetSerialItemnumber |
| 81 |
|
82 |
|
| 82 |
&GetSuppliersWithLateIssues |
83 |
&GetSuppliersWithLateIssues |
| 83 |
&getroutinglist &delroutingmember &addroutingmember |
84 |
&updateClaim |
| 84 |
&reorder_members |
|
|
| 85 |
&check_routing &updateClaim |
| 86 |
&CountIssues |
85 |
&CountIssues |
| 87 |
HasItems |
86 |
HasItems |
| 88 |
&subscriptionCurrentlyOnOrder |
87 |
&subscriptionCurrentlyOnOrder |
|
Lines 162-167
sub GetSubscriptionHistoryFromSubscriptionId {
Link Here
|
| 162 |
return $results; |
161 |
return $results; |
| 163 |
} |
162 |
} |
| 164 |
|
163 |
|
|
|
164 |
=head2 GetSerial |
| 165 |
|
| 166 |
my $serial = &GetSerial($serialid); |
| 167 |
|
| 168 |
This sub returns serial informations (ie. in serial table) for given $serialid |
| 169 |
It returns a hashref where each key is a sql column. |
| 170 |
|
| 171 |
=cut |
| 172 |
|
| 173 |
sub GetSerial { |
| 174 |
my ($serialid) = @_; |
| 175 |
|
| 176 |
return unless $serialid; |
| 177 |
|
| 178 |
my $dbh = C4::Context->dbh; |
| 179 |
my $query = qq{ |
| 180 |
SELECT * |
| 181 |
FROM serial |
| 182 |
WHERE serialid = ? |
| 183 |
}; |
| 184 |
my $sth = $dbh->prepare($query); |
| 185 |
$sth->execute($serialid); |
| 186 |
return $sth->fetchrow_hashref; |
| 187 |
} |
| 188 |
|
| 189 |
=head2 GetSerialItemnumber |
| 190 |
|
| 191 |
my $itemnumber = GetSerialItemnumber($serialid); |
| 192 |
|
| 193 |
Returns the itemnumber associated to $serialid or undef if there is no item. |
| 194 |
|
| 195 |
=cut |
| 196 |
|
| 197 |
sub GetSerialItemnumber { |
| 198 |
my ($serialid) = @_; |
| 199 |
|
| 200 |
return unless $serialid; |
| 201 |
my $itemnumber; |
| 202 |
|
| 203 |
my $dbh = C4::Context->dbh; |
| 204 |
my $query = qq{ |
| 205 |
SELECT itemnumber |
| 206 |
FROM serialitems |
| 207 |
WHERE serialid = ? |
| 208 |
}; |
| 209 |
my $sth = $dbh->prepare($query); |
| 210 |
my $rv = $sth->execute($serialid); |
| 211 |
if ($rv) { |
| 212 |
my $result = $sth->fetchrow_hashref; |
| 213 |
$itemnumber = $result->{itemnumber}; |
| 214 |
} |
| 215 |
return $itemnumber; |
| 216 |
} |
| 217 |
|
| 165 |
=head2 GetSerialInformation |
218 |
=head2 GetSerialInformation |
| 166 |
|
219 |
|
| 167 |
$data = GetSerialInformation($serialid); |
220 |
$data = GetSerialInformation($serialid); |
|
Lines 657-663
sub GetSerials {
Link Here
|
| 657 |
my @serials; |
710 |
my @serials; |
| 658 |
my $statuses = join( ',', ( ARRIVED, MISSING_STATUSES, NOT_ISSUED ) ); |
711 |
my $statuses = join( ',', ( ARRIVED, MISSING_STATUSES, NOT_ISSUED ) ); |
| 659 |
my $query = "SELECT serialid,serialseq, status, publisheddate, |
712 |
my $query = "SELECT serialid,serialseq, status, publisheddate, |
| 660 |
publisheddatetext, planneddate,notes, routingnotes |
713 |
publisheddatetext, planneddate, notes |
| 661 |
FROM serial |
714 |
FROM serial |
| 662 |
WHERE subscriptionid = ? AND status NOT IN ( $statuses ) |
715 |
WHERE subscriptionid = ? AND status NOT IN ( $statuses ) |
| 663 |
ORDER BY IF(publisheddate IS NULL,planneddate,publisheddate) DESC"; |
716 |
ORDER BY IF(publisheddate IS NULL,planneddate,publisheddate) DESC"; |
|
Lines 678-684
sub GetSerials {
Link Here
|
| 678 |
|
731 |
|
| 679 |
# OK, now add the last 5 issues arrives/missing |
732 |
# OK, now add the last 5 issues arrives/missing |
| 680 |
$query = "SELECT serialid,serialseq, status, planneddate, publisheddate, |
733 |
$query = "SELECT serialid,serialseq, status, planneddate, publisheddate, |
| 681 |
publisheddatetext, notes, routingnotes |
734 |
publisheddatetext, notes |
| 682 |
FROM serial |
735 |
FROM serial |
| 683 |
WHERE subscriptionid = ? |
736 |
WHERE subscriptionid = ? |
| 684 |
AND status IN ( $statuses ) |
737 |
AND status IN ( $statuses ) |
|
Lines 726-732
sub GetSerials2 {
Link Here
|
| 726 |
my $dbh = C4::Context->dbh; |
779 |
my $dbh = C4::Context->dbh; |
| 727 |
my $query = q| |
780 |
my $query = q| |
| 728 |
SELECT serialid,serialseq, status, planneddate, publisheddate, |
781 |
SELECT serialid,serialseq, status, planneddate, publisheddate, |
| 729 |
publisheddatetext, notes, routingnotes |
782 |
publisheddatetext, notes |
| 730 |
FROM serial |
783 |
FROM serial |
| 731 |
WHERE subscriptionid=? |
784 |
WHERE subscriptionid=? |
| 732 |
| |
785 |
| |
|
Lines 1084-1096
sub ModSerialStatus {
Link Here
|
| 1084 |
#It is a usual serial |
1137 |
#It is a usual serial |
| 1085 |
# 1st, get previous status : |
1138 |
# 1st, get previous status : |
| 1086 |
my $dbh = C4::Context->dbh; |
1139 |
my $dbh = C4::Context->dbh; |
| 1087 |
my $query = "SELECT serial.subscriptionid,serial.status,subscription.periodicity,serial.routingnotes |
1140 |
my $query = "SELECT serial.subscriptionid,serial.status,subscription.periodicity |
| 1088 |
FROM serial, subscription |
1141 |
FROM serial, subscription |
| 1089 |
WHERE serial.subscriptionid=subscription.subscriptionid |
1142 |
WHERE serial.subscriptionid=subscription.subscriptionid |
| 1090 |
AND serialid=?"; |
1143 |
AND serialid=?"; |
| 1091 |
my $sth = $dbh->prepare($query); |
1144 |
my $sth = $dbh->prepare($query); |
| 1092 |
$sth->execute($serialid); |
1145 |
$sth->execute($serialid); |
| 1093 |
my ( $subscriptionid, $oldstatus, $periodicity, $routingnotes ) = $sth->fetchrow; |
1146 |
my ( $subscriptionid, $oldstatus, $periodicity ) = $sth->fetchrow; |
| 1094 |
my $frequency = GetSubscriptionFrequency($periodicity); |
1147 |
my $frequency = GetSubscriptionFrequency($periodicity); |
| 1095 |
|
1148 |
|
| 1096 |
# change status & update subscriptionhistory |
1149 |
# change status & update subscriptionhistory |
|
Lines 1101-1112
sub ModSerialStatus {
Link Here
|
| 1101 |
my $query = ' |
1154 |
my $query = ' |
| 1102 |
UPDATE serial |
1155 |
UPDATE serial |
| 1103 |
SET serialseq = ?, publisheddate = ?, publisheddatetext = ?, |
1156 |
SET serialseq = ?, publisheddate = ?, publisheddatetext = ?, |
| 1104 |
planneddate = ?, status = ?, notes = ?, routingnotes = ? |
1157 |
planneddate = ?, status = ?, notes = ? |
| 1105 |
WHERE serialid = ? |
1158 |
WHERE serialid = ? |
| 1106 |
'; |
1159 |
'; |
| 1107 |
$sth = $dbh->prepare($query); |
1160 |
$sth = $dbh->prepare($query); |
| 1108 |
$sth->execute( $serialseq, $publisheddate, $publisheddatetext, |
1161 |
$sth->execute( $serialseq, $publisheddate, $publisheddatetext, |
| 1109 |
$planneddate, $status, $notes, $routingnotes, $serialid ); |
1162 |
$planneddate, $status, $notes, $serialid ); |
| 1110 |
$query = "SELECT * FROM subscription WHERE subscriptionid = ?"; |
1163 |
$query = "SELECT * FROM subscription WHERE subscriptionid = ?"; |
| 1111 |
$sth = $dbh->prepare($query); |
1164 |
$sth = $dbh->prepare($query); |
| 1112 |
$sth->execute($subscriptionid); |
1165 |
$sth->execute($subscriptionid); |
|
Lines 1162-1168
sub ModSerialStatus {
Link Here
|
| 1162 |
$sth = $dbh->prepare($query); |
1215 |
$sth = $dbh->prepare($query); |
| 1163 |
$sth->execute( $newlastvalue1, $newlastvalue2, $newlastvalue3, $newinnerloop1, $newinnerloop2, $newinnerloop3, $subscriptionid ); |
1216 |
$sth->execute( $newlastvalue1, $newlastvalue2, $newlastvalue3, $newinnerloop1, $newinnerloop2, $newinnerloop3, $subscriptionid ); |
| 1164 |
my $newnote = C4::Context->preference('PreserveSerialNotes') ? $notes : ""; |
1217 |
my $newnote = C4::Context->preference('PreserveSerialNotes') ? $notes : ""; |
| 1165 |
NewIssue( $newserialseq, $subscriptionid, $subscription->{'biblionumber'}, 1, $nextpubdate, $nextpubdate, undef, $newnote, $routingnotes ); |
1218 |
NewIssue( $newserialseq, $subscriptionid, $subscription->{'biblionumber'}, 1, $nextpubdate, $nextpubdate, undef, $newnote ); |
| 1166 |
# check if an alert must be sent... (= a letter is defined & status became "arrived" |
1219 |
# check if an alert must be sent... (= a letter is defined & status became "arrived" |
| 1167 |
if ( $subscription->{letter} && $status == ARRIVED && $oldstatus != ARRIVED ) { |
1220 |
if ( $subscription->{letter} && $status == ARRIVED && $oldstatus != ARRIVED ) { |
| 1168 |
require C4::Letters; |
1221 |
require C4::Letters; |
|
Lines 1541-1547
sub ReNewSubscription {
Link Here
|
| 1541 |
|
1594 |
|
| 1542 |
=head2 NewIssue |
1595 |
=head2 NewIssue |
| 1543 |
|
1596 |
|
| 1544 |
NewIssue($serialseq,$subscriptionid,$biblionumber,$status, $planneddate, $publisheddate, $notes, $routingnotes) |
1597 |
NewIssue($serialseq,$subscriptionid,$biblionumber,$status, $planneddate, $publisheddate, $notes) |
| 1545 |
|
1598 |
|
| 1546 |
Create a new issue stored on the database. |
1599 |
Create a new issue stored on the database. |
| 1547 |
Note : we have to update the recievedlist and missinglist on subscriptionhistory for this subscription. |
1600 |
Note : we have to update the recievedlist and missinglist on subscriptionhistory for this subscription. |
|
Lines 1551-1557
returns the serial id
Link Here
|
| 1551 |
|
1604 |
|
| 1552 |
sub NewIssue { |
1605 |
sub NewIssue { |
| 1553 |
my ( $serialseq, $subscriptionid, $biblionumber, $status, $planneddate, |
1606 |
my ( $serialseq, $subscriptionid, $biblionumber, $status, $planneddate, |
| 1554 |
$publisheddate, $publisheddatetext, $notes, $routingnotes ) = @_; |
1607 |
$publisheddate, $publisheddatetext, $notes ) = @_; |
| 1555 |
### FIXME biblionumber CAN be provided by subscriptionid. So Do we STILL NEED IT ? |
1608 |
### FIXME biblionumber CAN be provided by subscriptionid. So Do we STILL NEED IT ? |
| 1556 |
|
1609 |
|
| 1557 |
return unless ($subscriptionid); |
1610 |
return unless ($subscriptionid); |
|
Lines 1573-1579
sub NewIssue {
Link Here
|
| 1573 |
publisheddate => $publisheddate, |
1626 |
publisheddate => $publisheddate, |
| 1574 |
publisheddatetext => $publisheddatetext, |
1627 |
publisheddatetext => $publisheddatetext, |
| 1575 |
notes => $notes, |
1628 |
notes => $notes, |
| 1576 |
routingnotes => $routingnotes |
|
|
| 1577 |
} |
1629 |
} |
| 1578 |
)->store(); |
1630 |
)->store(); |
| 1579 |
|
1631 |
|
|
Lines 1886-2046
sub updateClaim {
Link Here
|
| 1886 |
{}, CLAIMED, @$serialids ); |
1938 |
{}, CLAIMED, @$serialids ); |
| 1887 |
} |
1939 |
} |
| 1888 |
|
1940 |
|
| 1889 |
=head2 check_routing |
|
|
| 1890 |
|
| 1891 |
$result = &check_routing($subscriptionid) |
| 1892 |
|
| 1893 |
this function checks to see if a serial has a routing list and returns the count of routingid |
| 1894 |
used to show either an 'add' or 'edit' link |
| 1895 |
|
| 1896 |
=cut |
| 1897 |
|
| 1898 |
sub check_routing { |
| 1899 |
my ($subscriptionid) = @_; |
| 1900 |
|
| 1901 |
return unless ($subscriptionid); |
| 1902 |
|
| 1903 |
my $dbh = C4::Context->dbh; |
| 1904 |
my $sth = $dbh->prepare( |
| 1905 |
"SELECT count(routingid) routingids FROM subscription LEFT JOIN subscriptionroutinglist |
| 1906 |
ON subscription.subscriptionid = subscriptionroutinglist.subscriptionid |
| 1907 |
WHERE subscription.subscriptionid = ? GROUP BY routingid ORDER BY ranking ASC |
| 1908 |
" |
| 1909 |
); |
| 1910 |
$sth->execute($subscriptionid); |
| 1911 |
my $line = $sth->fetchrow_hashref; |
| 1912 |
my $result = $line->{'routingids'}; |
| 1913 |
return $result; |
| 1914 |
} |
| 1915 |
|
| 1916 |
=head2 addroutingmember |
| 1917 |
|
| 1918 |
addroutingmember($borrowernumber,$subscriptionid) |
| 1919 |
|
| 1920 |
this function takes a borrowernumber and subscriptionid and adds the member to the |
| 1921 |
routing list for that serial subscription and gives them a rank on the list |
| 1922 |
of either 1 or highest current rank + 1 |
| 1923 |
|
| 1924 |
=cut |
| 1925 |
|
| 1926 |
sub addroutingmember { |
| 1927 |
my ( $borrowernumber, $subscriptionid ) = @_; |
| 1928 |
|
| 1929 |
return unless ($borrowernumber and $subscriptionid); |
| 1930 |
|
| 1931 |
my $rank; |
| 1932 |
my $dbh = C4::Context->dbh; |
| 1933 |
my $sth = $dbh->prepare( "SELECT max(ranking) rank FROM subscriptionroutinglist WHERE subscriptionid = ?" ); |
| 1934 |
$sth->execute($subscriptionid); |
| 1935 |
while ( my $line = $sth->fetchrow_hashref ) { |
| 1936 |
if ( $line->{'rank'} > 0 ) { |
| 1937 |
$rank = $line->{'rank'} + 1; |
| 1938 |
} else { |
| 1939 |
$rank = 1; |
| 1940 |
} |
| 1941 |
} |
| 1942 |
$sth = $dbh->prepare( "INSERT INTO subscriptionroutinglist (subscriptionid,borrowernumber,ranking) VALUES (?,?,?)" ); |
| 1943 |
$sth->execute( $subscriptionid, $borrowernumber, $rank ); |
| 1944 |
} |
| 1945 |
|
| 1946 |
=head2 reorder_members |
| 1947 |
|
| 1948 |
reorder_members($subscriptionid,$routingid,$rank) |
| 1949 |
|
| 1950 |
this function is used to reorder the routing list |
| 1951 |
|
| 1952 |
it takes the routingid of the member one wants to re-rank and the rank it is to move to |
| 1953 |
- it gets all members on list puts their routingid's into an array |
| 1954 |
- removes the one in the array that is $routingid |
| 1955 |
- then reinjects $routingid at point indicated by $rank |
| 1956 |
- then update the database with the routingids in the new order |
| 1957 |
|
| 1958 |
=cut |
| 1959 |
|
| 1960 |
sub reorder_members { |
| 1961 |
my ( $subscriptionid, $routingid, $rank ) = @_; |
| 1962 |
my $dbh = C4::Context->dbh; |
| 1963 |
my $sth = $dbh->prepare( "SELECT * FROM subscriptionroutinglist WHERE subscriptionid = ? ORDER BY ranking ASC" ); |
| 1964 |
$sth->execute($subscriptionid); |
| 1965 |
my @result; |
| 1966 |
while ( my $line = $sth->fetchrow_hashref ) { |
| 1967 |
push( @result, $line->{'routingid'} ); |
| 1968 |
} |
| 1969 |
|
| 1970 |
# To find the matching index |
| 1971 |
my $i; |
| 1972 |
my $key = -1; # to allow for 0 being a valid response |
| 1973 |
for ( $i = 0 ; $i < @result ; $i++ ) { |
| 1974 |
if ( $routingid == $result[$i] ) { |
| 1975 |
$key = $i; # save the index |
| 1976 |
last; |
| 1977 |
} |
| 1978 |
} |
| 1979 |
|
| 1980 |
# if index exists in array then move it to new position |
| 1981 |
if ( $key > -1 && $rank > 0 ) { |
| 1982 |
my $new_rank = $rank - 1; # $new_rank is what you want the new index to be in the array |
| 1983 |
my $moving_item = splice( @result, $key, 1 ); |
| 1984 |
splice( @result, $new_rank, 0, $moving_item ); |
| 1985 |
} |
| 1986 |
for ( my $j = 0 ; $j < @result ; $j++ ) { |
| 1987 |
my $sth = $dbh->prepare( "UPDATE subscriptionroutinglist SET ranking = '" . ( $j + 1 ) . "' WHERE routingid = '" . $result[$j] . "'" ); |
| 1988 |
$sth->execute; |
| 1989 |
} |
| 1990 |
return; |
| 1991 |
} |
| 1992 |
|
| 1993 |
=head2 delroutingmember |
| 1994 |
|
| 1995 |
delroutingmember($routingid,$subscriptionid) |
| 1996 |
|
| 1997 |
this function either deletes one member from routing list if $routingid exists otherwise |
| 1998 |
deletes all members from the routing list |
| 1999 |
|
| 2000 |
=cut |
| 2001 |
|
| 2002 |
sub delroutingmember { |
| 2003 |
|
| 2004 |
# if $routingid exists then deletes that row otherwise deletes all with $subscriptionid |
| 2005 |
my ( $routingid, $subscriptionid ) = @_; |
| 2006 |
my $dbh = C4::Context->dbh; |
| 2007 |
if ($routingid) { |
| 2008 |
my $sth = $dbh->prepare("DELETE FROM subscriptionroutinglist WHERE routingid = ?"); |
| 2009 |
$sth->execute($routingid); |
| 2010 |
reorder_members( $subscriptionid, $routingid ); |
| 2011 |
} else { |
| 2012 |
my $sth = $dbh->prepare("DELETE FROM subscriptionroutinglist WHERE subscriptionid = ?"); |
| 2013 |
$sth->execute($subscriptionid); |
| 2014 |
} |
| 2015 |
return; |
| 2016 |
} |
| 2017 |
|
| 2018 |
=head2 getroutinglist |
| 2019 |
|
| 2020 |
@routinglist = getroutinglist($subscriptionid) |
| 2021 |
|
| 2022 |
this gets the info from the subscriptionroutinglist for $subscriptionid |
| 2023 |
|
| 2024 |
return : |
| 2025 |
the routinglist as an array. Each element of the array contains a hash_ref containing |
| 2026 |
routingid - a unique id, borrowernumber, ranking, and biblionumber of subscription |
| 2027 |
|
| 2028 |
=cut |
| 2029 |
|
| 2030 |
sub getroutinglist { |
| 2031 |
my ($subscriptionid) = @_; |
| 2032 |
my $dbh = C4::Context->dbh; |
| 2033 |
my $sth = $dbh->prepare( |
| 2034 |
'SELECT routingid, borrowernumber, ranking, biblionumber |
| 2035 |
FROM subscription |
| 2036 |
JOIN subscriptionroutinglist ON subscription.subscriptionid = subscriptionroutinglist.subscriptionid |
| 2037 |
WHERE subscription.subscriptionid = ? ORDER BY ranking ASC' |
| 2038 |
); |
| 2039 |
$sth->execute($subscriptionid); |
| 2040 |
my $routinglist = $sth->fetchall_arrayref({}); |
| 2041 |
return @{$routinglist}; |
| 2042 |
} |
| 2043 |
|
| 2044 |
=head2 countissuesfrom |
1941 |
=head2 countissuesfrom |
| 2045 |
|
1942 |
|
| 2046 |
$result = countissuesfrom($subscriptionid,$startdate) |
1943 |
$result = countissuesfrom($subscriptionid,$startdate) |