diff --git a/C4/Acquisition.pm b/C4/Acquisition.pm
index 0ad03e9819..2b60f39442 100644
--- a/C4/Acquisition.pm
+++ b/C4/Acquisition.pm
@@ -25,6 +25,7 @@ use C4::Debug;
use C4::Dates qw(format_date format_date_in_iso);
use MARC::Record;
use C4::Suggestions;
+use C4::Biblio;
use C4::Debug;
use C4::SQLHelper qw(InsertInTable);
@@ -40,6 +41,7 @@ BEGIN {
@ISA = qw(Exporter);
@EXPORT = qw(
&GetBasket &NewBasket &CloseBasket &DelBasket &ModBasket
+ &GetBasketAsCSV
&GetBasketsByBookseller &GetBasketsByBasketgroup
&ModBasketHeader
@@ -222,6 +224,66 @@ sub CloseBasket {
#------------------------------------------------------------#
+=head3 GetBasketAsCSV
+
+=over 4
+
+&GetBasketAsCSV($basketno);
+
+Export a basket as CSV
+
+=back
+
+=cut
+sub GetBasketAsCSV {
+ my ($basketno) = @_;
+ my $basket = GetBasket($basketno);
+ my @orders = GetOrders($basketno);
+ my $contract = GetContract($basket->{'contractnumber'});
+ my $csv = Text::CSV->new();
+ my $output;
+
+ # TODO: Translate headers
+ my @headers = qw(contractname ordernumber line entrydate isbn author title publishercode collectiontitle notes quantity rrp);
+
+ $csv->combine(@headers);
+ $output = $csv->string() . "\n";
+
+ my @rows;
+ foreach my $order (@orders) {
+ my @cols;
+ my $bd = GetBiblioData($order->{'biblionumber'});
+ push(@cols,
+ $contract->{'contractname'},
+ $order->{'ordernumber'},
+ $order->{'entrydate'},
+ $order->{'isbn'},
+ $bd->{'author'},
+ $bd->{'title'},
+ $bd->{'publishercode'},
+ $bd->{'collectiontitle'},
+ $order->{'notes'},
+ $order->{'quantity'},
+ $order->{'rrp'},
+ );
+ push (@rows, \@cols);
+ }
+
+ # Sort by publishercode
+ # TODO: Sort by publishercode then by title
+ @rows = sort { @$a[7] cmp @$b[7] } @rows;
+
+ foreach my $row (@rows) {
+ $csv->combine(@$row);
+ $output .= $csv->string() . "\n";
+
+ }
+
+ return $output;
+
+}
+
+
=head3 CloseBasketgroup
=over 4
@@ -1164,7 +1226,7 @@ sub ModReceiveOrder {
, unitprice=?
, freight=?
, rrp=?
- , quantityreceived=?
+ , quantity=?
WHERE biblionumber=? AND ordernumber=?");
$sth->execute($quantrec,$datereceived,$invoiceno,$cost,$freight,$rrp,$quantrec,$biblionumber,$ordernumber);
@@ -1174,6 +1236,8 @@ sub ModReceiveOrder {
foreach my $orderkey ( "linenumber", "allocation" ) {
delete($order->{'$orderkey'});
}
+ $order->{'quantity'} -= $quantrec;
+ $order->{'quantityreceived'} = 0;
my $newOrder = NewOrder($order);
} else {
$sth=$dbh->prepare("update aqorders
diff --git a/C4/Auth.pm b/C4/Auth.pm
index f0be27cb91..ea10d16816 100755
--- a/C4/Auth.pm
+++ b/C4/Auth.pm
@@ -165,7 +165,8 @@ sub get_template_and_user {
$template->param( bartotal => $total->{'bartotal'}, ) if ($total->{'bartotal'} > scalar (@$barshelves));
}
- $borrowernumber = getborrowernumber($user);
+ $borrowernumber = getborrowernumber($user) if defined($user);
+
my ( $borr ) = GetMemberDetails( $borrowernumber );
my @bordat;
$bordat[0] = $borr;
diff --git a/C4/AuthoritiesMarc.pm b/C4/AuthoritiesMarc.pm
index 12ba169d28..3d4564e2a0 100644
--- a/C4/AuthoritiesMarc.pm
+++ b/C4/AuthoritiesMarc.pm
@@ -1027,7 +1027,6 @@ sub BuildSummary{
$summary = $resultstring;
} else {
my $heading;
- my $authid;
my $altheading;
my $seealso;
my $broaderterms;
@@ -1040,7 +1039,7 @@ sub BuildSummary{
# construct UNIMARC summary, that is quite different from MARC21 one
# accepted form
foreach my $field ($record->field('2..')) {
- $heading.= $field->subfield('a');
+ $heading.= $field->as_string('abcdefghijlmnopqrstuvwxyz');
}
# rejected form(s)
foreach my $field ($record->field('3..')) {
@@ -1049,18 +1048,18 @@ sub BuildSummary{
foreach my $field ($record->field('4..')) {
if ($field->subfield('2')) {
my $thesaurus = "thes. : ".$thesaurus{"$field->subfield('2')"}." : ";
- $see.= ''.$thesaurus.$field->subfield('a')." -- \n";
+ $see.= ''.$thesaurus.$field->as_string('abcdefghijlmnopqrstuvwxyz')." -- \n";
}
}
# see :
foreach my $field ($record->field('5..')) {
if (($field->subfield('5')) && ($field->subfield('a')) && ($field->subfield('5') eq 'g')) {
- $broaderterms.= ''.$field->subfield('a')." -- \n";
- } elsif (($field->subfield('5')) && ($field->subfield('a')) && ($field->subfield('5') eq 'h')){
- $narrowerterms.= ''.$field->subfield('a')." -- \n";
+ $broaderterms.= ' '.$field->as_string('abcdefgjxyz')." -- \n";
+ } elsif (($field->subfield('5')) && ($field->as_string) && ($field->subfield('5') eq 'h')){
+ $narrowerterms.= ''.$field->as_string('abcdefgjxyz')." -- \n";
} elsif ($field->subfield('a')) {
- $seealso.= ''.$field->subfield('a')." -- \n";
+ $seealso.= ''.$field->as_string('abcdefgxyz')." -- \n";
}
}
# // form
diff --git a/C4/Biblio.pm b/C4/Biblio.pm
index 7b17981f22..ded50fc254 100755
--- a/C4/Biblio.pm
+++ b/C4/Biblio.pm
@@ -2294,14 +2294,15 @@ sub PrepareItemrecordDisplay {
$subfield_data{repeatable} = $tagslib->{$tag}->{$subfield}->{repeatable};
$subfield_data{hidden} = "display:none"
if $tagslib->{$tag}->{$subfield}->{hidden};
- my ( $x, $value );
+ my ( $x, $defaultvalue );
if ($itemrecord) {
- ( $x, $value ) = _find_value( $tag, $subfield, $itemrecord );
+ ( $x, $defaultvalue ) = _find_value( $tag, $subfield, $itemrecord );
}
- if ( !defined $value ) {
- $value = q||;
+ $defaultvalue = $tagslib->{$tag}->{$subfield}->{defaultvalue} unless $defaultvalue;
+ if ( !defined $defaultvalue ) {
+ $defaultvalue = q||;
}
- $value =~ s/"/"/g;
+ $defaultvalue =~ s/"/"/g;
# search for itemcallnumber if applicable
if ( $tagslib->{$tag}->{$subfield}->{kohafield} eq 'items.itemcallnumber'
@@ -2310,7 +2311,7 @@ sub PrepareItemrecordDisplay {
my $CNsubfield = substr( C4::Context->preference('itemcallnumber'), 3, 1 );
my $temp = $itemrecord->field($CNtag) if ($itemrecord);
if ($temp) {
- $value = $temp->subfield($CNsubfield);
+ $defaultvalue = $temp->subfield($CNsubfield);
}
}
if ( $tagslib->{$tag}->{$subfield}->{kohafield} eq 'items.itemcallnumber'
@@ -2318,7 +2319,7 @@ sub PrepareItemrecordDisplay {
&& $defaultvalues->{'callnumber'} ) {
my $temp = $itemrecord->field($subfield) if ($itemrecord);
unless ($temp) {
- $value = $defaultvalues->{'callnumber'} if $defaultvalues;
+ $defaultvalue = $defaultvalues->{'callnumber'} if $defaultvalues;
}
}
if ( ( $tagslib->{$tag}->{$subfield}->{kohafield} eq 'items.holdingbranch' || $tagslib->{$tag}->{$subfield}->{kohafield} eq 'items.homebranch' )
@@ -2326,7 +2327,7 @@ sub PrepareItemrecordDisplay {
&& $defaultvalues->{'branchcode'} ) {
my $temp = $itemrecord->field($subfield) if ($itemrecord);
unless ($temp) {
- $value = $defaultvalues->{branchcode} if $defaultvalues;
+ $defaultvalue = $defaultvalues->{branchcode} if $defaultvalues;
}
}
if ( $tagslib->{$tag}->{$subfield}->{authorised_value} ) {
@@ -2381,14 +2382,14 @@ sub PrepareItemrecordDisplay {
$subfield_data{marc_value} = CGI::scrolling_list(
-name => 'field_value',
-values => \@authorised_values,
- -default => "$value",
+ -default => "$defaultvalue",
-labels => \%authorised_lib,
-size => 1,
-tabindex => '',
-multiple => 0,
);
} else {
- $subfield_data{marc_value} = "";
+ $subfield_data{marc_value} = "";
}
push( @loop_data, \%subfield_data );
}
@@ -2970,8 +2971,10 @@ sub _koha_add_biblio {
my $error;
# set the series flag
- my $serial = 0;
- if ( $biblio->{'seriestitle'} ) { $serial = 1 }
+ unless (defined $biblio->{'serial'}){
+ $biblio->{'serial'} = 0;
+ if ( $biblio->{'seriestitle'} ) { $biblio->{'serial'} = 1 }
+ }
my $query = "INSERT INTO biblio
SET frameworkcode = ?,
@@ -2988,7 +2991,7 @@ sub _koha_add_biblio {
my $sth = $dbh->prepare($query);
$sth->execute(
$frameworkcode, $biblio->{'author'}, $biblio->{'title'}, $biblio->{'unititle'}, $biblio->{'notes'},
- $serial, $biblio->{'seriestitle'}, $biblio->{'copyrightdate'}, $biblio->{'abstract'}
+ $biblio->{'serial'}, $biblio->{'seriestitle'}, $biblio->{'copyrightdate'}, $biblio->{'abstract'}
);
my $biblionumber = $dbh->{'mysql_insertid'};
diff --git a/C4/Budgets.pm b/C4/Budgets.pm
index 8ef85edbf9..4a8b3b6487 100644
--- a/C4/Budgets.pm
+++ b/C4/Budgets.pm
@@ -39,6 +39,7 @@ BEGIN {
&ModBudget
&DelBudget
&GetBudgetSpent
+ &GetBudgetOrdered
&GetPeriodsCount
&GetBudgetPeriod
@@ -300,9 +301,26 @@ sub GetBudgetSpent {
my ($budget_id) = @_;
my $dbh = C4::Context->dbh;
my $sth = $dbh->prepare(qq|
- SELECT SUM(ecost * quantity ) AS sum FROM aqorders
+ SELECT SUM(ecost * quantity) AS sum FROM aqorders
WHERE budget_id = ? AND
- datecancellationprinted IS NULL
+ quantityreceived > 0 AND
+ datecancellationprinted IS NULL
+ |);
+
+ $sth->execute($budget_id);
+ my $sum = $sth->fetchrow_array;
+ return $sum;
+}
+
+# -------------------------------------------------------------------
+sub GetBudgetOrdered {
+ my ($budget_id) = @_;
+ my $dbh = C4::Context->dbh;
+ my $sth = $dbh->prepare(qq|
+ SELECT SUM(ecost * quantity) AS sum FROM aqorders
+ WHERE budget_id = ? AND
+ quantityreceived = 0 AND
+ datecancellationprinted IS NULL
|);
$sth->execute($budget_id);
diff --git a/C4/Charset.pm b/C4/Charset.pm
index e1b6c96efa..e39637acf3 100644
--- a/C4/Charset.pm
+++ b/C4/Charset.pm
@@ -23,6 +23,7 @@ use warnings;
use MARC::Charset qw/marc8_to_utf8/;
use Text::Iconv;
use C4::Debug;
+use Unicode::Normalize;
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
@@ -34,6 +35,7 @@ BEGIN {
@EXPORT = qw(
IsStringUTF8ish
MarcToUTF8Record
+ SetUTF8Flag
SetMarcUnicodeFlag
StripNonXmlChars
);
@@ -111,6 +113,86 @@ sub IsStringUTF8ish {
return utf8::decode($str);
}
+=head2 SetUTF8Flag
+
+=over 4
+
+my $marc_record = SetUTF8Flag($marc_record);
+
+=back
+
+This function sets the PERL UTF8 flag for data.
+It is required when using new_from_usmarc
+since MARC::File::USMARC does not handle PERL UTF8 setting.
+When editing unicode marc records fields and subfields, you
+would end up in double encoding without using this function.
+
+FIXME
+In my opinion, this function belongs to MARC::Record and not
+to this package.
+But since it handles charset, and MARC::Record, it finds its way in that package
+
+=cut
+
+sub SetUTF8Flag{
+ my ($record)=@_;
+ return unless ($record && $record->fields());
+ foreach my $field ($record->fields()){
+ if ($field->tag()>=10){
+ my @subfields;
+ foreach my $subfield ($field->subfields()){
+ push @subfields,($$subfield[0],NormalizeString($$subfield[1]));
+ }
+ my $newfield=MARC::Field->new(
+ $field->tag(),
+ $field->indicator(1),
+ $field->indicator(2),
+ @subfields
+ );
+ $field->replace_with($newfield);
+ }
+ }
+}
+
+=head2 NormalizeString
+
+=over 4
+
+ my $normalized_string=NormalizeString($string);
+
+=back
+ Given
+ a string
+ nfc : If you want to set NFC and not NFD
+ transform : If you expect all the signs to be removed
+ Sets the PERL UTF8 Flag on your initial data if need be
+ and applies cleaning if required
+
+ Returns a utf8 NFD normalized string
+
+ Sample code :
+ my $string=NormalizeString ("l'ornithoptère");
+ #results into ornithoptère in NFD form and sets UTF8 Flag
+=cut
+
+sub NormalizeString{
+ my ($string,$nfc,$transform)=@_;
+ utf8::decode($string) unless (utf8::is_utf8($string));
+ if ($nfc){
+ $string= NFD($string);
+ }
+ else {
+ $string=NFC($string);
+ }
+ if ($transform){
+ $string=~s/\<|\>|\^|\;|\.|\?|,|\-|\(|\)|\[|\]|\{|\}|\$|\%|\!|\*|\:|\\|\/|\&|\"|\'/ /g;
+ #removing one letter words "d'" "l'" was changed into "d " "l "
+ $string=~s/\b\S\b//g;
+ $string=~s/\s+$//g;
+ }
+ return $string;
+}
+
=head2 MarcToUTF8Record
=over 4
diff --git a/C4/Contract.pm b/C4/Contract.pm
new file mode 100644
index 0000000000..01dadd23de
--- /dev/null
+++ b/C4/Contract.pm
@@ -0,0 +1,73 @@
+package C4::Contract;
+
+# Copyright 2009-2010 BibLibre SARL
+#
+# This file is part of Koha.
+#
+# Koha is free software; you can redistribute it and/or modify it under the
+# terms of the GNU General Public License as published by the Free Software
+# Foundation; either version 2 of the License, or (at your option) any later
+# version.
+#
+# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along with
+# Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
+# Suite 330, Boston, MA 02111-1307 USA
+
+use strict;
+use C4::SQLHelper qw(:all);
+
+use vars qw($VERSION @ISA @EXPORT);
+
+BEGIN {
+ # set the version for version checking
+ $VERSION = 3.2;
+ require Exporter;
+ @ISA = qw(Exporter);
+ @EXPORT = qw(
+ &GetContract
+ &AddContract
+ &ModContract
+ &DelContract
+ );
+}
+
+=head1 NAME
+
+C4::Contract - Koha functions for dealing with bookseller contracts.
+
+=head1 SYNOPSIS
+
+use C4::Contract;
+
+=head1 DESCRIPTION
+
+The functions in this module deal with contracts. They allow to
+add a new contract, to modify it or to get some informations around
+a contract.
+
+This module is just a wrapper for C4::SQLHelper functions, so take a look at
+SQLHelper centralised documentation to know how to use the following subs.
+
+=cut
+
+sub GetContract { SearchInTable("aqcontract", shift); }
+
+sub AddContract { InsertInTable("aqcontract", shift); }
+
+sub ModContract { UpdateInTable("aqcontract", shift); }
+
+sub DelContract { DeleteInTable("aqcontract", shift); }
+
+1;
+
+__END__
+
+=head1 AUTHOR
+
+Koha Developement team
+
+=cut
diff --git a/C4/Csv.pm b/C4/Csv.pm
index 292cd4edad..a53fcb91df 100644
--- a/C4/Csv.pm
+++ b/C4/Csv.pm
@@ -31,6 +31,7 @@ $VERSION = 3.00;
@EXPORT = qw(
&GetCsvProfiles
+ &GetCsvProfile
&GetCsvProfilesLoop
&GetMarcFieldsForCsv
);
@@ -48,6 +49,18 @@ sub GetCsvProfiles {
}
+# Returns all informations about a given csv profile
+sub GetCsvProfile {
+ my ($id) = @_;
+ my $dbh = C4::Context->dbh;
+ my $query = "SELECT * FROM export_format WHERE export_format_id=?";
+
+ $sth = $dbh->prepare($query);
+ $sth->execute($id);
+
+ return ($sth->fetchrow_hashref);
+}
+
# Returns fields to extract for the given csv profile
sub GetMarcFieldsForCsv {
diff --git a/C4/Dates.pm b/C4/Dates.pm
index 7563b51714..451e2d34b7 100644
--- a/C4/Dates.pm
+++ b/C4/Dates.pm
@@ -70,10 +70,10 @@ sub regexp ($;$) {
# way of saying "does this string match *whatever* format that Dates object is?"
($format eq 'sql') and
- return qr/^(\d{4})(\d{2})(\d{2})(?:\s{4}(\d{2})(\d{2})(\d{2}))?/;
+ return qr/^(\d{4})(\d{1,2})(\d{1,2})(?:\s{4}(\d{2})(\d{2})(\d{2}))?/;
($format eq 'iso') and
- return qr/^(\d{4})$delim(\d{2})$delim(\d{2})(?:(?:\s{1}|T)(\d{2})\:?(\d{2})\:?(\d{2}))?Z?/;
- return qr/^(\d{2})$delim(\d{2})$delim(\d{4})(?:\s{1}(\d{2})\:?(\d{2})\:?(\d{2}))?/; # everything else
+ return qr/^(\d{4})$delim(\d{1,2})$delim(\d{1,2})(?:(?:\s{1}|T)(\d{2})\:?(\d{2})\:?(\d{2}))?Z?/;
+ return qr/^(\d{1,2})$delim(\d{1,2})$delim(\d{4})(?:\s{1}(\d{1,2})\:?(\d{1,2})\:?(\d{1,2}))?/; # everything else
}
sub dmy_map ($$) {
diff --git a/C4/Koha.pm b/C4/Koha.pm
index 31bd6784db..18af528a70 100644
--- a/C4/Koha.pm
+++ b/C4/Koha.pm
@@ -53,6 +53,7 @@ BEGIN {
&GetAuthorisedValues
&GetAuthorisedValueCategories
&GetKohaAuthorisedValues
+ &GetKohaAuthorisedValuesFromField
&GetAuthValCode
&GetNormalizedUPC
&GetNormalizedISBN
@@ -1064,6 +1065,30 @@ sub GetAuthValCode {
return $authvalcode;
}
+=head2 GetAuthValCodeFromField
+
+$authvalcode = GetAuthValCodeFromField($field,$subfield,$frameworkcode);
+
+C<$subfield> can be undefined
+
+=cut
+
+sub GetAuthValCodeFromField {
+ my ($field,$subfield,$fwcode) = @_;
+ my $dbh = C4::Context->dbh;
+ $fwcode='' unless $fwcode;
+ my $sth;
+ if (defined $subfield) {
+ $sth = $dbh->prepare('select authorised_value from marc_subfield_structure where tagfield=? and tagsubfield=? and frameworkcode=?');
+ $sth->execute($field,$subfield,$fwcode);
+ } else {
+ $sth = $dbh->prepare('select authorised_value from marc_tag_structure where tagfield=? and frameworkcode=?');
+ $sth->execute($field,$fwcode);
+ }
+ my ($authvalcode) = $sth->fetchrow_array;
+ return $authvalcode;
+}
+
=head2 GetAuthorisedValues
$authvalues = GetAuthorisedValues([$category], [$selected]);
@@ -1146,6 +1171,35 @@ sub GetKohaAuthorisedValues {
}
}
+=head2 GetKohaAuthorisedValuesFromField
+
+ Takes $field, $subfield $fwcode as parameters.
+ If $opac parameter is set to a true value, displays OPAC descriptions rather than normal ones when they exist.
+ $subfield can be undefined
+ Returns hashref of Code => description
+ Returns undef
+ if no authorised value category is defined for the given field and subfield
+
+=cut
+
+sub GetKohaAuthorisedValuesFromField {
+ my ($field, $subfield, $fwcode,$opac) = @_;
+ $fwcode='' unless $fwcode;
+ my %values;
+ my $dbh = C4::Context->dbh;
+ my $avcode = GetAuthValCodeFromField($field, $subfield, $fwcode);
+ if ($avcode) {
+ my $sth = $dbh->prepare("select authorised_value, lib, lib_opac from authorised_values where category=? ");
+ $sth->execute($avcode);
+ while ( my ($val, $lib, $lib_opac) = $sth->fetchrow_array ) {
+ $values{$val} = ($opac && $lib_opac) ? $lib_opac : $lib;
+ }
+ return \%values;
+ } else {
+ return undef;
+ }
+}
+
=head2 display_marc_indicators
=over 4
diff --git a/C4/Members.pm b/C4/Members.pm
index bed69abc4c..f9c2050d55 100644
--- a/C4/Members.pm
+++ b/C4/Members.pm
@@ -1269,16 +1269,20 @@ Return date is also in ISO format.
sub GetExpiryDate {
my ( $categorycode, $dateenrolled ) = @_;
- my $enrolmentperiod = 12; # reasonable default
+ my $enrolments;
if ($categorycode) {
my $dbh = C4::Context->dbh;
- my $sth = $dbh->prepare("select enrolmentperiod from categories where categorycode=?");
+ my $sth = $dbh->prepare("SELECT enrolmentperiod,enrolmentperioddate FROM categories WHERE categorycode=?");
$sth->execute($categorycode);
- $enrolmentperiod = $sth->fetchrow;
+ $enrolments = $sth->fetchrow_hashref;
}
# die "GetExpiryDate: for enrollmentperiod $enrolmentperiod (category '$categorycode') starting $dateenrolled.\n";
- my @date = split /-/,$dateenrolled;
- return sprintf("%04d-%02d-%02d", Add_Delta_YM(@date,0,$enrolmentperiod));
+ my @date = split (/-/,$dateenrolled);
+ if($enrolments->{enrolmentperiod}){
+ return sprintf("%04d-%02d-%02d", Add_Delta_YM(@date,0,$enrolments->{enrolmentperiod}));
+ }else{
+ return $enrolments->{enrolmentperioddate};
+ }
}
=head2 checkuserpassword (OUEST-PROVENCE)
@@ -1724,7 +1728,7 @@ Looks up the different title . Returns array with all borrowers title
=cut
sub GetTitles {
- my @borrowerTitle = split /,|\|/,C4::Context->preference('BorrowersTitles');
+ my @borrowerTitle = split (/,|\|/,C4::Context->preference('BorrowersTitles'));
unshift( @borrowerTitle, "" );
my $count=@borrowerTitle;
if ($count == 1){
@@ -1827,9 +1831,8 @@ this function get all borrowers who haven't borrowed since the date given on inp
=cut
sub GetBorrowersWhoHaveNotBorrowedSince {
-### TODO : It could be dangerous to delete Borrowers who have just been entered and who have not yet borrowed any book. May be good to add a dateexpiry or dateenrolled filter.
-
- my $filterdate = shift||POSIX::strftime("%Y-%m-%d",localtime());
+ my $filterdate = shift||POSIX::strftime("%Y-%m-%d",localtime());
+ my $filterexpiry = shift;
my $filterbranch = shift ||
((C4::Context->preference('IndependantBranches')
&& C4::Context->userenv
@@ -1839,20 +1842,29 @@ sub GetBorrowersWhoHaveNotBorrowedSince {
: "");
my $dbh = C4::Context->dbh;
my $query = "
- SELECT borrowers.borrowernumber,max(issues.timestamp) as latestissue
+ SELECT borrowers.borrowernumber,
+ max(old_issues.timestamp) as latestissue,
+ max(issues.timestamp) as currentissue
FROM borrowers
JOIN categories USING (categorycode)
- LEFT JOIN issues ON borrowers.borrowernumber = issues.borrowernumber
+ LEFT JOIN old_issues USING (borrowernumber)
+ LEFT JOIN issues USING (borrowernumber)
WHERE category_type <> 'S'
+ AND borrowernumber NOT IN (SELECT guarantorid FROM borrowers WHERE guarantorid IS NOT NULL AND guarantorid <> 0)
";
my @query_params;
if ($filterbranch && $filterbranch ne ""){
$query.=" AND borrowers.branchcode= ?";
push @query_params,$filterbranch;
- }
+ }
+ if($filterexpiry){
+ $query .= " AND dateexpiry < ? ";
+ push @query_params,$filterdate;
+ }
$query.=" GROUP BY borrowers.borrowernumber";
if ($filterdate){
- $query.=" HAVING latestissue OR latestissue IS NULL";
+ $query.=" HAVING (latestissue < ? OR latestissue IS NULL)
+ AND currentissue IS NULL";
push @query_params,$filterdate;
}
warn $query if $debug;
diff --git a/C4/Record.pm b/C4/Record.pm
index 127d5214bd..7c3fcc5ebb 100644
--- a/C4/Record.pm
+++ b/C4/Record.pm
@@ -31,7 +31,8 @@ use XML::LibXSLT;
use XML::LibXML;
use C4::Biblio; #marc2bibtex
use C4::Csv; #marc2csv
-use Text::CSV; #marc2csv
+use C4::Koha; #marc2csv
+use Text::CSV::Encoded; #marc2csv
use vars qw($VERSION @ISA @EXPORT);
@@ -331,16 +332,18 @@ sub marc2endnote {
=over 4
-my ($csv) = marc2csv($record, $csvprofileid);
+my ($csv) = marc2csv($record, $csvprofileid, $header);
Returns a CSV scalar
=over 2
-C<$record> - a MARC::Record object
+C<$biblio> - a biblionumber
C<$csvprofileid> - the id of the CSV profile to use for the export (see export_format.export_format_id and the GetCsvProfiles function in C4::Csv)
+C<$header> - true if the headers are to be printed (typically at first pass)
+
=back
=back
@@ -349,38 +352,81 @@ C<$csvprofileid> - the id of the CSV profile to use for the export (see export_f
sub marc2csv {
- my ($record, $id, $header) = @_;
+ my ($biblio, $id, $header) = @_;
my $output;
- my $csv = Text::CSV->new();
- # Get the information about the csv profile
- my $marcfieldslist = GetMarcFieldsForCsv($id);
+ # Getting the record
+ my $record = GetMarcBiblio($biblio);
+
+ # Getting the framework
+ my $frameworkcode = GetFrameworkCode($biblio);
+
+ # Getting information about the csv profile
+ my $profile = GetCsvProfile($id);
+
+ # Getting output encoding
+ my $encoding = $profile->{encoding} || 'utf8';
+
+ # Getting separators
+ my $csvseparator = $profile->{csv_separator} || ',';
+ my $fieldseparator = $profile->{field_separator} || '#';
+ my $subfieldseparator = $profile->{subfield_separator} || '|';
+
+ # TODO: Be more generic (in case we have to handle other protected chars or more separators)
+ if ($csvseparator eq '\t') { $csvseparator = "\t" }
+ if ($fieldseparator eq '\t') { $fieldseparator = "\t" }
+ if ($subfieldseparator eq '\t') { $subfieldseparator = "\t" }
+
+ # Init CSV
+ my $csv = Text::CSV::Encoded->new({ sep_char => $csvseparator });
+ $csv = $csv->encoding_out($encoding) if ($encoding ne 'utf8');
+
+ # Getting the marcfields
+ my $marcfieldslist = $profile->{marcfields};
# Getting the marcfields as an array
- my @marcfields = split('\|', $marcfieldslist);
+ my @marcfieldsarray = split('\|', $marcfieldslist);
+
+ # Separating the marcfields from the the user-supplied headers
+ my @marcfields;
+ foreach (@marcfieldsarray) {
+ my @result = split('=', $_);
+ if (scalar(@result) == 2) {
+ push @marcfields, { header => $result[0], field => $result[1] };
+ } else {
+ push @marcfields, { field => $result[0] }
+ }
+ }
# If we have to insert the headers
if ($header) {
my @marcfieldsheaders;
-
my $dbh = C4::Context->dbh;
# For each field or subfield
foreach (@marcfields) {
- # We get the matching tag name
- if (index($_, '$') > 0) {
- my ($fieldtag, $subfieldtag) = split('\$', $_);
- my $query = "SELECT liblibrarian FROM marc_subfield_structure WHERE tagfield=? AND tagsubfield=?";
- my $sth = $dbh->prepare($query);
- $sth->execute($fieldtag, $subfieldtag);
- my @results = $sth->fetchrow_array();
- push @marcfieldsheaders, $results[0];
+
+ my $field = $_->{field};
+
+ # If we have a user-supplied header, we use it
+ if (exists $_->{header}) {
+ push @marcfieldsheaders, $_->{header};
} else {
- my $query = "SELECT liblibrarian FROM marc_tag_structure WHERE tagfield=?";
- my $sth = $dbh->prepare($query);
- $sth->execute($_);
- my @results = $sth->fetchrow_array();
- push @marcfieldsheaders, $results[0];
+ # If not, we get the matching tag name from koha
+ if (index($field, '$') > 0) {
+ my ($fieldtag, $subfieldtag) = split('\$', $field);
+ my $query = "SELECT liblibrarian FROM marc_subfield_structure WHERE tagfield=? AND tagsubfield=?";
+ my $sth = $dbh->prepare($query);
+ $sth->execute($fieldtag, $subfieldtag);
+ my @results = $sth->fetchrow_array();
+ push @marcfieldsheaders, $results[0];
+ } else {
+ my $query = "SELECT liblibrarian FROM marc_tag_structure WHERE tagfield=?";
+ my $sth = $dbh->prepare($query);
+ $sth->execute($field);
+ my @results = $sth->fetchrow_array();
+ push @marcfieldsheaders, $results[0];
+ }
}
}
$csv->combine(@marcfieldsheaders);
@@ -389,7 +435,8 @@ sub marc2csv {
# For each marcfield to export
my @fieldstab;
- foreach my $marcfield (@marcfields) {
+ foreach (@marcfields) {
+ my $marcfield = $_->{field};
# If it is a subfield
if (index($marcfield, '$') > 0) {
my ($fieldtag, $subfieldtag) = split('\$', $marcfield);
@@ -402,14 +449,18 @@ sub marc2csv {
# We take every matching subfield
my @subfields = $field->subfield($subfieldtag);
foreach my $subfield (@subfields) {
- push @tmpfields, $subfield;
+
+ # Getting authorised value
+ my $authvalues = GetKohaAuthorisedValuesFromField($fieldtag, $subfieldtag, $frameworkcode, undef);
+ push @tmpfields, (defined $authvalues->{$subfield}) ? $authvalues->{$subfield} : $subfield;
}
}
- push (@fieldstab, join(',', @tmpfields));
+ push (@fieldstab, join($subfieldseparator, @tmpfields));
# Or a field
} else {
my @fields = ($record->field($marcfield));
- push (@fieldstab, join(',', map($_->as_string(), @fields)));
+ my $authvalues = GetKohaAuthorisedValuesFromField($marcfield, undef, $frameworkcode, undef);
+ push (@fieldstab, join($fieldseparator, map((defined $authvalues->{$_->as_string}) ? $authvalues->{$_->as_string} : $_->as_string, @fields)));
}
};
diff --git a/C4/Reports/Guided.pm b/C4/Reports/Guided.pm
index a7d6f48006..d8277b7e31 100644
--- a/C4/Reports/Guided.pm
+++ b/C4/Reports/Guided.pm
@@ -75,18 +75,29 @@ $keys{'5'} = ['borrowers.borrowernumber=accountlines.borrowernumber'];
# have to do someting here to know if its dropdown, free text, date etc
our %criteria;
+# reports on circulation
$criteria{'1'} = [
'statistics.type', 'borrowers.categorycode',
'statistics.branch',
'biblioitems.publicationyear|date',
'items.dateaccessioned|date'
];
+# reports on catalogue
$criteria{'2'} =
- [ 'items.itemnumber|textrange', 'items.biblionumber|textrange', 'items.barcode|textrange', 'biblio.frameworkcode', 'items.holdingbranch', 'items.homebranch', 'biblio.datecreated|daterange', 'biblio.timestamp|daterange', 'items.onloan|daterange', 'items.ccode', 'items.itemcallnumber|textrange', 'items.itype', 'items.itemlost', 'items.location' ];
-$criteria{'3'} = ['borrowers.branchcode'];
+ [ 'items.itemnumber|textrange', 'items.biblionumber|textrange', 'items.barcode|textrange',
+ 'biblio.frameworkcode', 'items.holdingbranch', 'items.homebranch',
+ 'biblio.datecreated|daterange', 'biblio.timestamp|daterange', 'items.onloan|daterange',
+ 'items.ccode', 'items.itemcallnumber|textrange', 'items.itype',
+ 'items.itemlost', 'items.location' ];
+# reports on borrowers
+$criteria{'3'} = ['borrowers.branchcode', 'borrowers.categorycode'];
+# reports on acquisition
$criteria{'4'} = ['aqorders.datereceived|date'];
-$criteria{'5'} = ['borrowers.branchcode'];
+# reports on accounting
+$criteria{'5'} = ['borrowers.branchcode', 'borrowers.categorycode'];
+
+# Adds itemtypes to criteria, according to the syspref
if (C4::Context->preference('item-level_itypes')) {
unshift @{ $criteria{'1'} }, 'items.itype';
unshift @{ $criteria{'2'} }, 'items.itype';
@@ -244,7 +255,6 @@ sub _build_query {
my $dbh = C4::Context->dbh();
my $joinedtables = join( ',', @$tables );
my $joinedcolumns = join( ',', @$columns );
- my $joinedkeys = join( ' AND ', @$keys );
my $query =
"SELECT $totals $joinedcolumns FROM $tables->[0] ";
for (my $i=1;$i<@$tables;$i++){
@@ -341,6 +351,14 @@ sub get_criteria {
my $sth = $dbh->prepare($query);
$sth->execute();
my @values;
+ # push the runtime choosing option
+ my $list;
+ $list='branches' if $column eq 'branchcode' or $column eq 'holdingbranch' or $column eq 'homebranch';
+ $list='categorycode' if $column eq 'categorycode';
+ $list='itemtype' if $column eq 'itype';
+ $list='ccode' if $column eq 'ccode';
+ # TODO : improve to let the librarian choose the description at runtime
+ push @values, { availablevalues => "<<$column".($list?"|$list":'').">>" };
while ( my $row = $sth->fetchrow_hashref() ) {
push @values, $row;
if ($row->{'availablevalues'} eq '') { $row->{'default'} = 1 };
diff --git a/C4/SIP/ILS/Item.pm b/C4/SIP/ILS/Item.pm
index 6f005b4a8c..fa88699ae1 100644
--- a/C4/SIP/ILS/Item.pm
+++ b/C4/SIP/ILS/Item.pm
@@ -9,6 +9,7 @@ package ILS::Item;
use strict;
use warnings;
+use DateTime;
use Sys::Syslog qw(syslog);
use Carp;
@@ -97,6 +98,14 @@ sub new {
# check if its on issue and if so get the borrower
my $issue = GetItemIssue($item->{'itemnumber'});
+ if ( $issue ) {
+ my $date = $issue->{ date_due };
+ my $dt = DateTime->new(
+ year => substr($date, 0, 4),
+ month => substr($date,5,2),
+ day => substr($date, 8, 2) );
+ $item->{ due_date } = $dt->epoch();
+ }
my $borrower = GetMember(borrowernumber=>$issue->{'borrowernumber'});
$item->{patron} = $borrower->{'cardnumber'};
my ($whatever, $arrayref) = GetReservesFromBiblionumber($item->{biblionumber});
diff --git a/C4/SIP/SIPServer.pm b/C4/SIP/SIPServer.pm
index 55b2380f73..c6de11e464 100644
--- a/C4/SIP/SIPServer.pm
+++ b/C4/SIP/SIPServer.pm
@@ -59,16 +59,8 @@ foreach my $svc (keys %{$config->{listeners}}) {
# Jun 16 21:21:31 server08 steve_sip[19305]: ILS::Transaction::Checkout performing checkout...
# [ TIMESTAMP ] [ HOST ] [ IDENT ] PID : Message...
#
-# The IDENT is determined by $ENV{KOHA_SIP_LOG_IDENT}, if present.
-# Otherwise it is "_sip" appended to $USER, if present, or "acs-server" as a fallback.
-#
+# The IDENT is determined by config file 'server-params' arguments
-my $syslog_ident = $ENV{KOHA_SIP_LOG_IDENT} || ($ENV{USER} ? $ENV{USER} . "_sip" : 'acs-server');
-
-push @parms,
- "log_file=Sys::Syslog",
- "syslog_ident=$syslog_ident",
- "syslog_facility=" . LOG_SIP;
#
# Server Management: set parameters for the Net::Server::PreFork
diff --git a/C4/SIP/SIPconfig.xml b/C4/SIP/SIPconfig.xml
index 0e5f05ed31..f229b9a51b 100644
--- a/C4/SIP/SIPconfig.xml
+++ b/C4/SIP/SIPconfig.xml
@@ -2,10 +2,18 @@
-
-
+
+
&op=add_form"},
@@ -26,11 +31,10 @@
{ text: _("Uncertain prices"), url: "/cgi-bin/koha/acqui/uncertainprice.pl?booksellerid=&owner=1"}
]
- new YAHOO.widget.Button("newbasket");
- new YAHOO.widget.Button("editsupplier");
- new YAHOO.widget.Button("receive");
- new YAHOO.widget.Button("editcontracts");
- new YAHOO.widget.Button({type: "menu", label: _("Manage orders"), name: "manageorders", menu: manageorders, container: "toolbar-list"});
+
+
+ new YAHOO.widget.Button({type: "menu", label: _("Manage orders"), name: "manageorders", menu: manageorders, container: "toolbar-list"});
+
}
@@ -39,7 +43,10 @@
-
\ No newline at end of file
+
+
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/acqui-home.tmpl b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/acqui-home.tmpl
index 5d793c07a6..697443317f 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/acqui-home.tmpl
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/acqui-home.tmpl
@@ -74,6 +74,7 @@