From 33d0f6daf5edad9d25d34963997a0f3e90af63c2 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Fri, 20 Apr 2012 14:44:01 +0200 Subject: [PATCH 1/1] Bug 7986: Export issues for patron In the circulation page, you can now export (as csv or iso2709) a list of items which are currently checked out by a borrower. 3 export types: - iso2709 with items: Export the items list in iso2709 format with item informations. - iso2709 without items: Export the items list in iso2709 format without item informations. - CSV: Export the items list based on a csv profil. 2 new system preferences: - DontExportFields: a list of fields not to be export - CsvProfileForExport: The Csv profil name used for the csv export Test plan: - Fill the CsvProfileForExport syspref - go on the borrower circulation page containing checkouts - Select one or more items and export them to the 3 different formats. - check if the result file is what you expected --- C4/Biblio.pm | 6 +- C4/Csv.pm | 13 + C4/Record.pm | 43 +++- circ/circulation.pl | 2 + installer/data/mysql/updatedatabase.pl | 22 ++ .../prog/en/includes/checkouts-table-footer.inc | 2 +- .../intranet-tmpl/prog/en/includes/prefs-menu.inc | 1 + .../en/modules/admin/preferences/circulation.pref | 6 + .../prog/en/modules/admin/preferences/tools.pref | 4 + .../prog/en/modules/circ/circulation.tt | 98 +++++++- .../intranet-tmpl/prog/en/modules/tools/export.tt | 2 +- tools/export.pl | 247 +++++++++++--------- 12 files changed, 318 insertions(+), 128 deletions(-) create mode 100644 koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/tools.pref diff --git a/C4/Biblio.pm b/C4/Biblio.pm index 56cd94e..cef937c 100644 --- a/C4/Biblio.pm +++ b/C4/Biblio.pm @@ -2743,16 +2743,17 @@ sub GetNoZebraIndexes { =head2 EmbedItemsInMarcBiblio - EmbedItemsInMarcBiblio($marc, $biblionumber); + EmbedItemsInMarcBiblio($marc, $biblionumber, $itemnumbers); Given a MARC::Record object containing a bib record, modify it to include the items attached to it as 9XX per the bib's MARC framework. +if $itemnumbers is defined, only specified itemnumbers are embedded =cut sub EmbedItemsInMarcBiblio { - my ($marc, $biblionumber) = @_; + my ($marc, $biblionumber, $itemnumbers) = @_; croak "No MARC record" unless $marc; my $frameworkcode = GetFrameworkCode($biblionumber); @@ -2765,6 +2766,7 @@ sub EmbedItemsInMarcBiblio { my @item_fields; my ( $itemtag, $itemsubfield ) = GetMarcFromKohaField( "items.itemnumber", $frameworkcode ); while (my ($itemnumber) = $sth->fetchrow_array) { + next if $itemnumbers and not grep { $_ == $itemnumber } @$itemnumbers; require C4::Items; my $item_marc = C4::Items::GetMarcItem($biblionumber, $itemnumber); push @item_fields, $item_marc->field($itemtag); diff --git a/C4/Csv.pm b/C4/Csv.pm index 07ce2eb..99619e5 100644 --- a/C4/Csv.pm +++ b/C4/Csv.pm @@ -35,6 +35,7 @@ $VERSION = 3.00; @EXPORT = qw( &GetCsvProfiles &GetCsvProfile + &GetCsvProfileId &GetCsvProfilesLoop &GetMarcFieldsForCsv ); @@ -64,6 +65,18 @@ sub GetCsvProfile { return ($sth->fetchrow_hashref); } +# Returns id of csv profile about a given csv profile name +sub GetCsvProfileId { + my ($name) = @_; + my $dbh = C4::Context->dbh; + my $query = "SELECT export_format_id FROM export_format WHERE profile=?"; + + $sth = $dbh->prepare($query); + $sth->execute($name); + + return ( $sth->fetchrow ); +} + # Returns fields to extract for the given csv profile sub GetMarcFieldsForCsv { diff --git a/C4/Record.pm b/C4/Record.pm index 89bde32..f6067a3 100644 --- a/C4/Record.pm +++ b/C4/Record.pm @@ -330,7 +330,7 @@ sub marc2endnote { =head2 marc2csv - Convert several records from UNIMARC to CSV - my ($csv) = marc2csv($biblios, $csvprofileid); + my ($csv) = marc2csv($biblios, $csvprofileid, $itemnumbers); Pre and postprocessing can be done through a YAML file @@ -340,10 +340,11 @@ C<$biblio> - a list of biblionumbers 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<$itemnumbers> - a list of itemnumbers to export =cut sub marc2csv { - my ($biblios, $id) = @_; + my ( $biblios, $id, $itemnumbers ) = @_; my $output; my $csv = Text::CSV::Encoded->new(); @@ -358,9 +359,18 @@ sub marc2csv { eval $preprocess if ($preprocess); my $firstpass = 1; - foreach my $biblio (@$biblios) { - $output .= marcrecord2csv($biblio, $id, $firstpass, $csv, $fieldprocessing) ; - $firstpass = 0; + + if ( $itemnumbers ) { + for my $itemnumber ( @$itemnumbers) { + my $biblionumber = GetBiblionumberFromItemnumber $itemnumber; + $output .= marcrecord2csv( $biblionumber, $id, $firstpass, $csv, $fieldprocessing, [$itemnumber] ); + $firstpass = 0; + } + } else { + foreach my $biblio (@$biblios) { + $output .= marcrecord2csv( $biblio, $id, $firstpass, $csv, $fieldprocessing ); + $firstpass = 0; + } } # Postprocessing @@ -383,16 +393,21 @@ C<$header> - true if the headers are to be printed (typically at first pass) C<$csv> - an already initialised Text::CSV object +C<$fieldprocessing> + +C<$itemnumbers> a list of itemnumbers to export + =cut sub marcrecord2csv { - my ($biblio, $id, $header, $csv, $fieldprocessing) = @_; + my ( $biblio, $id, $header, $csv, $fieldprocessing, $itemnumbers ) = @_; my $output; # Getting the record - my $record = GetMarcBiblio($biblio, 1); + my $record = GetMarcBiblio($biblio); next unless $record; + C4::Biblio::EmbedItemsInMarcBiblio( $record, $biblio, $itemnumbers ); # Getting the framework my $frameworkcode = GetFrameworkCode($biblio); @@ -503,8 +518,18 @@ sub marcrecord2csv { foreach (@fields) { my $value; - # Getting authorised value - $value = defined $authvalues->{$_->as_string} ? $authvalues->{$_->as_string} : $_->as_string; + # If it is a control field + if ($_->is_control_field) { + $value = defined $authvalues->{$_->as_string} ? $authvalues->{$_->as_string} : $_->as_string; + } else { + # If it is a field, we gather all subfields, joined by the subfield separator + my @subvaluesarray; + my @subfields = $_->subfields; + foreach my $subfield (@subfields) { + push (@subvaluesarray, defined $authvalues->{$subfield->[1]} ? $authvalues->{$subfield->[1]} : $subfield->[1]); + } + $value = join ($subfieldseparator, @subvaluesarray); + } # Field processing eval $fieldprocessing if ($fieldprocessing); diff --git a/circ/circulation.pl b/circ/circulation.pl index bcbcb6f..ad3026c 100755 --- a/circ/circulation.pl +++ b/circ/circulation.pl @@ -726,6 +726,8 @@ $template->param( AllowRenewalLimitOverride => C4::Context->preference("AllowRenewalLimitOverride"), dateformat => C4::Context->preference("dateformat"), DHTMLcalendar_dateformat => C4::Dates->DHTMLcalendar(), + dont_export_fields => C4::Context->preference("DontExportFields"), + csv_profil_for_export => C4::Context->preference("CsvProfilForExport"), canned_bor_notes_loop => $canned_notes, ); diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl index e140ff3..896799f 100755 --- a/installer/data/mysql/updatedatabase.pl +++ b/installer/data/mysql/updatedatabase.pl @@ -5199,6 +5199,28 @@ if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) { } + + + + +$DBversion = "3.07.00.XXX"; +if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) { + $dbh->do(qq{ + INSERT IGNORE INTO systempreferences (variable,value,explanation,options,type) VALUES('DontExportFields','','List of fields for non export in circulation.pl (separated by a space)','',''); + }); + print "Upgrade to $DBversion done (Add system preference DontExportFields)\n"; + SetVersion($DBversion); +} + +$DBversion = "3.07.00.XXX"; +if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) { + $dbh->do(qq{ + INSERT IGNORE INTO systempreferences (variable,value,explanation,options,type) VALUES('CsvProfileForExport','','Set a profile name for CSV export','',''); + }); + print "Upgrade to $DBversion done (Adds New System preference CsvProfileForExport)\n"; + SetVersion($DBversion) +} + =head1 FUNCTIONS =head2 TableExists($table) diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/checkouts-table-footer.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/checkouts-table-footer.inc index 5638710..c00e7db 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/checkouts-table-footer.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/checkouts-table-footer.inc @@ -3,7 +3,7 @@ Totals: [% totaldue %] [% totalprice %] - +

Renewal due date: Show Calendar