use C4::Dates qw(format_date format_date_in_iso);
use Date::Calc qw(:all);
use POSIX qw(strftime);
-use C4::Suggestions;
-use C4::Koha;
use C4::Biblio;
-use C4::Branch;
-use C4::Items;
-use C4::Search;
-use C4::Letters;
use C4::Log; # logaction
use C4::Debug;
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
BEGIN {
- $VERSION = 3.01; # set version for version checking
+ $VERSION = 3.07.00.049; # set version for version checking
require Exporter;
@ISA = qw(Exporter);
@EXPORT = qw(
&NewSubscription &ModSubscription &DelSubscription &GetSubscriptions
&GetSubscription &CountSubscriptionFromBiblionumber &GetSubscriptionsFromBiblionumber
+ &SearchSubscriptions
&GetFullSubscriptionsFromBiblionumber &GetFullSubscription &ModSubscriptionHistory
&HasSubscriptionStrictlyExpired &HasSubscriptionExpired &GetExpirationDate &abouttoexpire
&check_routing &updateClaim &removeMissingIssue
&CountIssues
HasItems
+ &GetSubscriptionsFromBorrower
);
}
my $queryitem = $dbh->prepare("SELECT itemnumber from serialitems where serialid=?");
$queryitem->execute($serialid);
my $itemnumbers = $queryitem->fetchall_arrayref( [0] );
+ require C4::Items;
if ( scalar(@$itemnumbers) > 0 ) {
foreach my $itemnum (@$itemnumbers) {
#It is ASSUMED that GetMarcItem ALWAYS WORK...
#Maybe GetMarcItem should return values on failure
$debug and warn "itemnumber :$itemnum->[0], bibnum :" . $data->{'biblionumber'};
- my $itemprocessed = PrepareItemrecordDisplay( $data->{'biblionumber'}, $itemnum->[0], $data );
+ my $itemprocessed = C4::Items::PrepareItemrecordDisplay( $data->{'biblionumber'}, $itemnum->[0], $data );
$itemprocessed->{'itemnumber'} = $itemnum->[0];
$itemprocessed->{'itemid'} = $itemnum->[0];
$itemprocessed->{'serialid'} = $serialid;
push @{ $data->{'items'} }, $itemprocessed;
}
} else {
- my $itemprocessed = PrepareItemrecordDisplay( $data->{'biblionumber'}, '', $data );
+ my $itemprocessed = C4::Items::PrepareItemrecordDisplay( $data->{'biblionumber'}, '', $data );
$itemprocessed->{'itemid'} = "N$serialid";
$itemprocessed->{'serialid'} = $serialid;
$itemprocessed->{'biblionumber'} = $data->{'biblionumber'};
$subs->{$datefield} = format_date( $subs->{$datefield} );
}
}
- $subs->{'branchname'} = GetBranchName( $subs->{'branchcode'} );
$subs->{ "status" . $subs->{'status'} } = 1;
$subs->{"checked"} = $subs->{'status'} =~ /1|3|4|7/;
foreach my $key ( sort { $b cmp $a } keys %tmpresults ) {
push @res, $tmpresults{$key};
}
- $res[0]->{'first'} = 1;
return \@res;
}
=head2 GetSubscriptions
-@results = GetSubscriptions($title,$ISSN,$biblionumber);
-this function gets all subscriptions which have title like $title,ISSN like $ISSN and biblionumber like $biblionumber.
+@results = GetSubscriptions($title,$ISSN,$ean,$biblionumber);
+this function gets all subscriptions which have title like $title,ISSN like $ISSN,EAN like $ean and biblionumber like $biblionumber.
return:
a table of hashref. Each hash containt the subscription.
=cut
sub GetSubscriptions {
- my ( $string, $issn, $biblionumber ) = @_;
+ my ( $string, $issn, $ean, $biblionumber ) = @_;
#return unless $title or $ISSN or $biblionumber;
my $dbh = C4::Context->dbh;
LEFT JOIN biblioitems ON biblio.biblionumber = biblioitems.biblionumber
);
my @bind_params;
- my $sqlwhere;
+ my $sqlwhere = q{};
if ($biblionumber) {
$sqlwhere = " WHERE biblio.biblionumber=?";
push @bind_params, $biblionumber;
my @sqlstrings;
my @strings_to_search;
@strings_to_search = map { "%$_%" } split( / /, $string );
- foreach my $index qw(biblio.title subscription.callnumber subscription.location subscription.notes subscription.internalnotes) {
+ foreach my $index (qw(biblio.title subscription.callnumber subscription.location subscription.notes subscription.internalnotes)) {
push @bind_params, @strings_to_search;
my $tmpstring = "AND $index LIKE ? " x scalar(@strings_to_search);
$debug && warn "$tmpstring";
$tmpstring =~ s/^AND //;
push @sqlstrings, $tmpstring;
}
- $sqlwhere .= ( $sqlwhere ? " AND " : " WHERE " ) . "(" . join( ") OR (", @sqlstrings ) . ")";
+ $sqlwhere .= ( $sqlwhere ? " AND " : " WHERE " ) . "((" . join( ") OR (", @sqlstrings ) . "))";
}
if ($issn) {
my @sqlstrings;
my @strings_to_search;
@strings_to_search = map { "%$_%" } split( / /, $issn );
- foreach my $index qw(biblioitems.issn subscription.callnumber) {
+ foreach my $index ( qw(biblioitems.issn subscription.callnumber)) {
push @bind_params, @strings_to_search;
my $tmpstring = "OR $index LIKE ? " x scalar(@strings_to_search);
$debug && warn "$tmpstring";
$tmpstring =~ s/^OR //;
push @sqlstrings, $tmpstring;
}
- $sqlwhere .= ( $sqlwhere ? " AND " : " WHERE " ) . "(" . join( ") OR (", @sqlstrings ) . ")";
+ $sqlwhere .= ( $sqlwhere ? " AND " : " WHERE " ) . "((" . join( ") OR (", @sqlstrings ) . "))";
}
+ if ($ean) {
+ my @sqlstrings;
+ my @strings_to_search;
+ @strings_to_search = map { "$_" } split( / /, $ean );
+ foreach my $index ( qw(biblioitems.ean) ) {
+ push @bind_params, @strings_to_search;
+ my $tmpstring = "OR $index = ? " x scalar(@strings_to_search);
+ $debug && warn "$tmpstring";
+ $tmpstring =~ s/^OR //;
+ push @sqlstrings, $tmpstring;
+ }
+ $sqlwhere .= ( $sqlwhere ? " AND " : " WHERE " ) . "((" . join( ") OR (", @sqlstrings ) . "))";
+ }
+
$sql .= "$sqlwhere ORDER BY title";
$debug and warn "GetSubscriptions query: $sql params : ", join( " ", @bind_params );
$sth = $dbh->prepare($sql);
$sth->execute(@bind_params);
my @results;
- my $previousbiblio = "";
- my $odd = 1;
while ( my $line = $sth->fetchrow_hashref ) {
- if ( $previousbiblio eq $line->{biblionumber} ) {
- $line->{title} = "";
- $line->{issn} = "";
- } else {
- $previousbiblio = $line->{biblionumber};
- $odd = -$odd;
- }
- $line->{toggle} = 1 if $odd == 1;
$line->{'cannotedit'} =
( C4::Context->preference('IndependantBranches')
&& C4::Context->userenv
return @results;
}
+=head2 SearchSubscriptions
+
+@results = SearchSubscriptions($args);
+$args is a hashref. Its keys can be contained: title, issn, ean, publisher, bookseller and branchcode
+
+this function gets all subscriptions which have title like $title, ISSN like $issn, EAN like $ean, publisher like $publisher, bookseller like $bookseller AND branchcode eq $branch.
+
+return:
+a table of hashref. Each hash containt the subscription.
+
+=cut
+
+sub SearchSubscriptions {
+ my ( $args ) = @_;
+
+ my $query = qq{
+ SELECT subscription.*, subscriptionhistory.*, biblio.*, biblioitems.issn
+ FROM subscription
+ LEFT JOIN subscriptionhistory USING(subscriptionid)
+ LEFT JOIN biblio ON biblio.biblionumber = subscription.biblionumber
+ LEFT JOIN biblioitems ON biblioitems.biblionumber = subscription.biblionumber
+ LEFT JOIN aqbooksellers ON subscription.aqbooksellerid = aqbooksellers.id
+ };
+ my @where_strs;
+ my @where_args;
+ if( $args->{biblionumber} ) {
+ push @where_strs, "biblio.biblionumber = ?";
+ push @where_args, $args->{biblionumber};
+ }
+ if( $args->{title} ){
+ push @where_strs, "biblio.title LIKE ?";
+ push @where_args, "%$args->{title}%";
+ }
+ if( $args->{issn} ){
+ push @where_strs, "biblioitems.issn LIKE ?";
+ push @where_args, "%$args->{issn}%";
+ }
+ if( $args->{ean} ){
+ push @where_strs, "biblioitems.ean LIKE ?";
+ push @where_args, "%$args->{ean}%";
+ }
+ if( $args->{publisher} ){
+ push @where_strs, "biblioitems.publishercode LIKE ?";
+ push @where_args, "%$args->{publisher}%";
+ }
+ if( $args->{bookseller} ){
+ push @where_strs, "aqbooksellers.name LIKE ?";
+ push @where_args, "%$args->{bookseller}%";
+ }
+ if( $args->{branch} ){
+ push @where_strs, "subscription.branchcode = ?";
+ push @where_args, "$args->{branch}";
+ }
+
+ if(@where_strs){
+ $query .= " WHERE " . join(" AND ", @where_strs);
+ }
+
+ my $dbh = C4::Context->dbh;
+ my $sth = $dbh->prepare($query);
+ $sth->execute(@where_args);
+ my $results = $sth->fetchall_arrayref( {} );
+ $sth->finish;
+
+ return @$results;
+}
+
+
=head2 GetSerials
($totalissues,@serials) = GetSerials($subscriptionid);
FROM serial
WHERE subscriptionid = ?
AND (status =2 or status=4)
- ORDER BY planneddate DESC LIMIT 0,$limit
+ ORDER BY publisheddate DESC LIMIT 0,$limit
";
my $sth = $dbh->prepare($strsth);
$sth->execute($subscriptionid);
# check if an alert must be sent... (= a letter is defined & status became "arrived"
if ( $val->{letter} && $status == 2 && $oldstatus != 2 ) {
- SendAlerts( 'issue', $val->{subscriptionid}, $val->{letter} );
+ require C4::Letters;
+ C4::Letters::SendAlerts( 'issue', $val->{subscriptionid}, $val->{letter} );
}
}
return;
logaction( "SERIAL", "ADD", $subscriptionid, "" ) if C4::Context->preference("SubscriptionLog");
#set serial flag on biblio if not already set.
- my ( $null, ($bib) ) = GetBiblio($biblionumber);
+ my $bib = GetBiblio($biblionumber);
if ( !$bib->{'serial'} ) {
my $record = GetMarcBiblio($biblionumber);
my ( $tag, $subf ) = GetMarcFromKohaField( 'biblio.serial', $bib->{'frameworkcode'} );
my $biblio = $sth->fetchrow_hashref;
if ( C4::Context->preference("RenewSerialAddsSuggestion") ) {
-
- NewSuggestion(
+ require C4::Suggestions;
+ C4::Suggestions::NewSuggestion(
{ 'suggestedby' => $user,
'title' => $subscription->{bibliotitle},
'author' => $biblio->{author},
my $fwk = GetFrameworkCode( $data->{'biblionumber'} );
if ( $info->{barcode} ) {
my @errors;
- my $exists = itemdata( $info->{'barcode'} );
- push @errors, "barcode_not_unique" if ($exists);
- unless ($exists) {
+ if ( is_barcode_in_use( $info->{barcode} ) ) {
+ push @errors, 'barcode_not_unique';
+ } else {
my $marcrecord = MARC::Record->new();
my ( $tag, $subfield ) = GetMarcFromKohaField( "items.barcode", $fwk );
my $newField = MARC::Field->new( "$tag", '', '', "$subfield" => $info->{barcode} );
$marcrecord->insert_fields_ordered($newField);
}
}
- AddItemFromMarc( $marcrecord, $data->{'biblionumber'} );
+ require C4::Items;
+ C4::Items::AddItemFromMarc( $marcrecord, $data->{'biblionumber'} );
return 1;
}
return ( 0, @errors );
my $sth = $dbh->prepare($query);
$sth->execute($subscriptionid);
my ($res) = $sth->fetchrow;
- return 0 unless $res;
+ if (!$res || $res=~m/^0000/) {
+ return 0;
+ }
my @res = split( /-/, $res );
my @endofsubscriptiondate = split( /-/, $expirationdate );
return 2 if ( scalar(@res) != 3 || scalar(@endofsubscriptiondate) != 3 || not check_date(@res) || not check_date(@endofsubscriptiondate) );
=head2 getroutinglist
-($count,@routinglist) = getroutinglist($subscriptionid)
+@routinglist = getroutinglist($subscriptionid)
this gets the info from the subscriptionroutinglist for $subscriptionid
return :
-a count of the number of members on routinglist
the routinglist as an array. Each element of the array contains a hash_ref containing
routingid - a unique id, borrowernumber, ranking, and biblionumber of subscription
my ($subscriptionid) = @_;
my $dbh = C4::Context->dbh;
my $sth = $dbh->prepare(
- "SELECT routingid, borrowernumber, ranking, biblionumber
+ 'SELECT routingid, borrowernumber, ranking, biblionumber
FROM subscription
JOIN subscriptionroutinglist ON subscription.subscriptionid = subscriptionroutinglist.subscriptionid
- WHERE subscription.subscriptionid = ? ORDER BY ranking ASC
- "
+ WHERE subscription.subscriptionid = ? ORDER BY ranking ASC'
);
$sth->execute($subscriptionid);
- my @routinglist;
- my $count = 0;
- while ( my $line = $sth->fetchrow_hashref ) {
- $count++;
- push( @routinglist, $line );
- }
- return ( $count, @routinglist );
+ my $routinglist = $sth->fetchall_arrayref({});
+ return @{$routinglist};
}
=head2 countissuesfrom
@res=Date::Calc::Today;
}
my @endofsubscriptiondate=split(/-/,$expirationdate);
- my @per_list = (0, 7, 7, 14, 21, 31, 62, 93, 93, 190, 365, 730, 0, 0, 0, 0);
+ my @per_list = (0, 7, 7, 14, 21, 31, 62, 93, 93, 190, 365, 730, 0, 124, 0, 0);
my @datebeforeend;
@datebeforeend = Add_Delta_Days( $endofsubscriptiondate[0],$endofsubscriptiondate[1],$endofsubscriptiondate[2],
- (3 * $per_list[$per])) if (@endofsubscriptiondate && $endofsubscriptiondate[0]*$endofsubscriptiondate[1]*$endofsubscriptiondate[2]);
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 GetNextDate
$resultdate = GetNextDate($planneddate,$subscription)
}
@resultdate = Add_Delta_YMD( $year, $month, $day, 0, 3, 0 );
}
+ if ( $subscription->{periodicity} == 13 ) {
+ for ( my $i = 0 ; $i < @irreg ; $i++ ) {
+ if ( $irreg[$i] == ( ( $tmpmonth != 8 ) ? ( $tmpmonth + 4 ) % 12 : 12 ) ) {
+ ( $year, $month, $day ) = Add_Delta_YMD( $year, $month, $day, 0, 4, 0 );
+ $tmpmonth = ( ( $tmpmonth != 8 ) ? ( $tmpmonth + 4 ) % 12 : 12 );
+ }
+ }
+ @resultdate = Add_Delta_YMD( $year, $month, $day, 0, 4, 0 );
+ }
if ( $subscription->{periodicity} == 9 ) {
for ( my $i = 0 ; $i < @irreg ; $i++ ) {
if ( $irreg[$i] == ( ( $tmpmonth != 9 ) ? ( $tmpmonth + 3 ) % 12 : 12 ) ) {
return "$resultdate";
}
-=head2 itemdata
-
- $item = itemdata($barcode);
+=head2 is_barcode_in_use
-Looks up the item with the given barcode, and returns a
-reference-to-hash containing information about that item. The keys of
-the hash are the fields from the C<items> and C<biblioitems> tables in
-the Koha database.
+Returns number of occurence 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 itemdata {
- my ($barcode) = @_;
+sub is_barcode_in_use {
+ my $barcode = shift;
my $dbh = C4::Context->dbh;
- my $sth = $dbh->prepare(
- "Select * from items LEFT JOIN biblioitems ON items.biblioitemnumber=biblioitems.biblioitemnumber
- WHERE barcode=?"
+ my $occurences = $dbh->selectall_arrayref(
+ 'SELECT itemnumber from items where barcode = ?',
+ {}, $barcode
+
);
- $sth->execute($barcode);
- my $data = $sth->fetchrow_hashref;
- $sth->finish;
- return ($data);
+
+ return @{$occurences};
}
1;