&PrepareSerialsData &GetNextExpected &ModNextExpected
&GetPreviousSerialid
- &GetSuppliersWithLateIssues &getsupplierbyserialid
- &GetDistributedTo &SetDistributedTo
+ &GetSuppliersWithLateIssues
&getroutinglist &delroutingmember &addroutingmember
&reorder_members
&check_routing &updateClaim
&CountIssues
HasItems
- &GetSubscriptionsFromBorrower
&subscriptionCurrentlyOnOrder
);
return $results;
}
-=head2 GetSerialStatusFromSerialId
-
-$sth = GetSerialStatusFromSerialId();
-this function returns a statement handle
-After this function, don't forget to execute it by using $sth->execute($serialid)
-return :
-$sth = $dbh->prepare($query).
-
-=cut
-
-sub GetSerialStatusFromSerialId {
- my $dbh = C4::Context->dbh;
- my $query = qq|
- SELECT status
- FROM serial
- WHERE serialid = ?
- |;
- return $dbh->prepare($query);
-}
-
=head2 GetSerialInformation
$data = GetSerialInformation($serialid);
$subs = GetSubscription($subscriptionid)
this function returns the subscription which has $subscriptionid as id.
return :
-a hashref. This hash containts
+a hashref. This hash contains
subscription, subscriptionhistory, aqbooksellers.name, biblio.title
=cut
return $return;
}
-
-
-=head2 GetDistributedTo
-
-$distributedto=GetDistributedTo($subscriptionid)
-This function returns the field distributedto for the subscription matching subscriptionid
-
-=cut
-
-sub GetDistributedTo {
- my $dbh = C4::Context->dbh;
- my $distributedto;
- my ($subscriptionid) = @_;
-
- return unless ($subscriptionid);
-
- my $query = "SELECT distributedto FROM subscription WHERE subscriptionid=?";
- my $sth = $dbh->prepare($query);
- $sth->execute($subscriptionid);
- return ($distributedto) = $sth->fetchrow;
-}
-
=head2 GetNextSeq
my (
# then create the 1st expected number
$query = qq(
INSERT INTO subscriptionhistory
- (biblionumber, subscriptionid, histstartdate)
- VALUES (?,?,?)
+ (biblionumber, subscriptionid, histstartdate, missinglist, recievedlist)
+ VALUES (?,?,?, '', '')
);
$sth = $dbh->prepare($query);
$sth->execute( $biblionumber, $subscriptionid, $startdate);
logaction( "SERIAL", "ADD", $subscriptionid, "" ) if C4::Context->preference("SubscriptionLog");
#set serial flag on biblio if not already set.
- my $bib = GetBiblio($biblionumber);
- if ( $bib and !$bib->{'serial'} ) {
- my $record = GetMarcBiblio($biblionumber);
- my ( $tag, $subf ) = GetMarcFromKohaField( 'biblio.serial', $bib->{'frameworkcode'} );
+ my $biblio = Koha::Biblios->find( $biblionumber );
+ if ( $biblio and !$biblio->serial ) {
+ my $record = GetMarcBiblio({ biblionumber => $biblionumber });
+ my ( $tag, $subf ) = GetMarcFromKohaField( 'biblio.serial', $biblio->frameworkcode );
if ($tag) {
eval { $record->field($tag)->update( $subf => 1 ); };
}
- ModBiblio( $record, $biblionumber, $bib->{'frameworkcode'} );
+ ModBiblio( $record, $biblionumber, $biblio->frameworkcode );
}
return $subscriptionid;
}
);
}
+ $numberlength ||= 0; # Should not we raise an exception instead?
+ $weeklength ||= 0;
+
# renew subscription
$query = qq|
UPDATE subscription
return 0; # Notice that you'll never get here.
}
-=head2 SetDistributedto
-
-SetDistributedto($distributedto,$subscriptionid);
-This function update the value of distributedto for a subscription given on input arg.
-
-=cut
-
-sub SetDistributedto {
- my ( $distributedto, $subscriptionid ) = @_;
- my $dbh = C4::Context->dbh;
- my $query = qq|
- UPDATE subscription
- SET distributedto=?
- WHERE subscriptionid=?
- |;
- my $sth = $dbh->prepare($query);
- $sth->execute( $distributedto, $subscriptionid );
- return;
-}
-
=head2 DelSubscription
DelSubscription($subscriptionid)
{}, CLAIMED, @$serialids );
}
-=head2 getsupplierbyserialid
-
-$result = getsupplierbyserialid($serialid)
-
-this function is used to find the supplier id given a serial id
-
-return :
-hashref containing serialid, subscriptionid, and aqbooksellerid
-
-=cut
-
-sub getsupplierbyserialid {
- my ($serialid) = @_;
- my $dbh = C4::Context->dbh;
- my $sth = $dbh->prepare(
- "SELECT serialid, serial.subscriptionid, aqbooksellerid
- FROM serial
- LEFT JOIN subscription ON serial.subscriptionid = subscription.subscriptionid
- WHERE serialid = ?
- "
- );
- $sth->execute($serialid);
- my $line = $sth->fetchrow_hashref;
- my $result = $line->{'aqbooksellerid'};
- return $result;
-}
-
=head2 check_routing
$result = &check_routing($subscriptionid)
return 0;
}
-sub in_array { # used in next sub down
- my ( $val, @elements ) = @_;
- foreach my $elem (@elements) {
- if ( $val == $elem ) {
- return 1;
- }
- }
- return 0;
-}
-
-=head2 GetSubscriptionsFromBorrower
-
-($count,@routinglist) = GetSubscriptionsFromBorrower($borrowernumber)
-
-this gets the info from subscriptionroutinglist for each $subscriptionid
-
-return :
-a count of the serial subscription routing lists to which a patron belongs,
-with the titles of those serial subscriptions as an array. Each element of the array
-contains a hash_ref with subscriptionID and title of subscription.
-
-=cut
-
-sub GetSubscriptionsFromBorrower {
- my ($borrowernumber) = @_;
- my $dbh = C4::Context->dbh;
- my $sth = $dbh->prepare(
- "SELECT subscription.subscriptionid, biblio.title
- FROM subscription
- JOIN biblio ON biblio.biblionumber = subscription.biblionumber
- JOIN subscriptionroutinglist USING (subscriptionid)
- WHERE subscriptionroutinglist.borrowernumber = ? ORDER BY title ASC
- "
- );
- $sth->execute($borrowernumber);
- my @routinglist;
- my $count = 0;
- while ( my $line = $sth->fetchrow_hashref ) {
- $count++;
- push( @routinglist, $line );
- }
- return ( $count, @routinglist );
-}
-
-
=head2 GetFictiveIssueNumber
$issueno = GetFictiveIssueNumber($subscription, $publishedate);
The issue number calculation is based on subscription frequency, first acquisition
date, and $publisheddate.
+Returns undef when called for irregular frequencies.
+
The routine is used to skip irregularities when calculating the next issue
date (in GetNextDate) or the next issue number (in GetNextSeq).
my $frequency = GetSubscriptionFrequency($subscription->{'periodicity'});
my $unit = $frequency->{unit} ? lc $frequency->{'unit'} : undef;
- my $issueno = 0;
+ return if !$unit;
+ my $issueno;
- if($unit) {
- my ($year, $month, $day) = split /-/, $publisheddate;
- my ($fa_year, $fa_month, $fa_day) = split /-/, $subscription->{'firstacquidate'};
- my $wkno;
- my $delta = _delta_units( [$fa_year, $fa_month, $fa_day], [$year, $month, $day], $unit );
+ my ( $year, $month, $day ) = split /-/, $publisheddate;
+ my ( $fa_year, $fa_month, $fa_day ) = split /-/, $subscription->{'firstacquidate'};
+ my $delta = _delta_units( [$fa_year, $fa_month, $fa_day], [$year, $month, $day], $unit );
- if($frequency->{'unitsperissue'} == 1) {
- $issueno = $delta * $frequency->{'issuesperunit'} + $subscription->{'countissuesperunit'};
- } else {
- # Assuming issuesperunit == 1
- $issueno = int( ($delta + $frequency->{'unitsperissue'}) / $frequency->{'unitsperissue'} );
- }
+ if( $frequency->{'unitsperissue'} == 1 ) {
+ $issueno = $delta * $frequency->{'issuesperunit'} + $subscription->{'countissuesperunit'};
+ } else { # issuesperunit == 1
+ $issueno = 1 + int( $delta / $frequency->{'unitsperissue'} );
}
return $issueno;
}
sub _delta_units {
my ( $date1, $date2, $unit ) = @_;
+ # date1 and date2 are array refs in the form [ yy, mm, dd ]
if( $unit eq 'day' ) {
return Delta_Days( @$date1, @$date2 );
return $string;
}
-=head2 is_barcode_in_use
-
-Returns number of occurrences of the barcode in the items table
-Can be used as a boolean test of whether the barcode has
-been deployed as yet
-
-=cut
-
-sub is_barcode_in_use {
- my $barcode = shift;
- my $dbh = C4::Context->dbh;
- my $occurrences = $dbh->selectall_arrayref(
- 'SELECT itemnumber from items where barcode = ?',
- {}, $barcode
-
- );
-
- return @{$occurrences};
-}
-
=head2 CloseSubscription
Close a subscription given a subscriptionid