Bugzilla – Attachment 68403 Details for
Bug 9573
Ability to download items lost report
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 9573: Lost items report - Add the CSV export ability
Bug-9573-Lost-items-report---Add-the-CSV-export-ab.patch (text/plain), 8.79 KB, created by
Biblibre Sandboxes
on 2017-10-23 14:09:59 UTC
(
hide
)
Description:
Bug 9573: Lost items report - Add the CSV export ability
Filename:
MIME Type:
Creator:
Biblibre Sandboxes
Created:
2017-10-23 14:09:59 UTC
Size:
8.79 KB
patch
obsolete
>From 8b4f94c4ef7b4e4de1c947a1a3cdf7b359ffcdc3 Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Thu, 5 Oct 2017 17:38:34 -0300 >Subject: [PATCH] Bug 9573: Lost items report - Add the CSV export ability >MIME-Version: 1.0 >Content-Type: text/plain; charset=UTF-8 >Content-Transfer-Encoding: 8bit > >Finally we add the ability to export the list of lost items. >The items will be export in CSV format using a CSV profile defined. > >Test plan: >0/ Apply all the patches from this patch set >1/ Define a CSV profile (type=SQL, Usage=Export lost items in report) >Try something like that to get the same columns as the default table: >Title=biblio.title >|Author=biblio.author >|Lost status=items.itemlost >|Lost on=items.itemlost_on >|Barcode=items.barcode >|Call number=items.itemcallnumber >|Date last seen=items.datelastseen >|Price=items.price >|Rep. price=items.replacementprice >|Library=items.homebranch >|item type=items.itype >|Current location=items.holdingbranch >|Location=items.location >|Not for loan status=items.notforloan >|Notes=items.itemnotes >2/ Use the filters and select items to export >3/ Export the list of items you want and make sure the CSV is correctly >formatted and contains the items you selected > >QA Notes: >- I think we should add default CSV profiles for the different "usage", >but I would consider it as a separate enhancement since none of them is >defined yet >- Most of the code to export CSV is no reusable. We should make >Koha::Exporter::Record support CSV export for type=SQL (it only >supports MARC type so far). > >Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de> > >Signed-off-by: Séverine QUEUNE <severine.queune@bulac.fr> >--- > .../prog/en/modules/reports/itemslost.tt | 18 ++++++- > .../prog/en/modules/tools/csv-profiles.tt | 3 +- > reports/itemslost.pl | 62 +++++++++++++++++++++- > 3 files changed, 78 insertions(+), 5 deletions(-) > >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/reports/itemslost.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/reports/itemslost.tt >index 1d24dda..cc33a2d 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/reports/itemslost.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/reports/itemslost.tt >@@ -33,7 +33,8 @@ > itemnumbers.push($(this).val()); > }); > if (itemnumbers.length > 0) { >- var url = '/cgi-bin/koha/tools/batchMod.pl?op=show'; >+ var csv_profile_id = $("#csv_profile_id option:selected").val(); >+ var url = '/cgi-bin/koha/reports/itemslost.pl?op=export&csv_profile_id='+csv_profile_id; > url += '&itemnumber=' + itemnumbers.join('&itemnumber='); > $('a.itemselection_action_export').attr('href', url); > } else { >@@ -56,6 +57,9 @@ > $("input[name='itemnumber'][type='checkbox']").change(function() { > itemSelectionBuildActionLinks(); > }); >+ $("#csv_profile_id").change(function() { >+ itemSelectionBuildActionLinks(); >+ }); > > $(".SelectAll").on("click",function(e){ > e.preventDefault(); >@@ -104,7 +108,17 @@ > <a href="#" class="ClearAll"><i class="fa fa-remove"></i> Clear all</a> > <span class="itemselection_actions"> > | Actions: >- <a class="itemselection_action_export"><i class="fa fa-trash"></i> Export selected items</a> >+ [% IF csv_profiles.count %] >+ <a class="itemselection_action_export"><i class="fa fa-download"></i> Export selected items</a> >+ Using the following CSV profile: >+ <select name="csv_profile_id" id="csv_profile_id"> >+ [% FOREACH csv_profile IN csv_profiles %] >+ <option value="[% csv_profile.export_format_id %]">[% csv_profile.profile %]</<option> >+ [% END %] >+ </select> >+ [% ELSE %] >+ <span class="itemselection_action_export" title="You should create a CSV profile for export_lost_items"><i class="fa fa-download"></i> Export selected items</a> >+ [% END %] > </span> > </div> > >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/csv-profiles.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/csv-profiles.tt >index cdbaab9..8b36112 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/csv-profiles.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/csv-profiles.tt >@@ -112,6 +112,7 @@ function reloadPage(p) { > [% IF used_for_code == 'export_records' %] Export records > [% ELSIF used_for_code == 'late_issues' %] Late serial issues claims > [% ELSIF used_for_code == 'export_basket' %] Basket export in acquisition >+ [% ELSIF used_for_code == 'export_lost_items' %] Export lost items in report > [% ELSE %] Unknown usage > [% END %] > [% END %] >@@ -152,7 +153,7 @@ function reloadPage(p) { > <li class="sql_specific"> > <label for="used_for_sql">Usage: </label> > <select id="used_for_sql" name="used_for_sql"> >- [% FOREACH used_for IN [ 'late_issues' 'export_basket' ] %] >+ [% FOREACH used_for IN [ 'late_issues' 'export_basket' 'export_lost_items' ] %] > [% IF csv_profile.used_for == used_for %] > <option value="[% used_for %]" selected="selected">[% PROCESS used_for_description used_for_code = used_for %]</option> > [% ELSE %] >diff --git a/reports/itemslost.pl b/reports/itemslost.pl >index 41de7dd..cf5394b 100755 >--- a/reports/itemslost.pl >+++ b/reports/itemslost.pl >@@ -35,6 +35,7 @@ use C4::Biblio; > use C4::Items; > > use Koha::AuthorisedValues; >+use Koha::CsvProfiles; > use Koha::DateUtils; > > my $query = new CGI; >@@ -51,8 +52,62 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user( > > my $params = $query->Vars; > my $get_items = $params->{'get_items'}; >- >-if ($get_items) { >+my $op = $query->param('op') || ''; >+ >+if ( $op eq 'export' ) { >+ my @itemnumbers = $query->multi_param('itemnumber'); >+ my $csv_profile_id = $query->param('csv_profile_id'); >+ my @rows; >+ if ($csv_profile_id) { >+ # FIXME This following code has the same logic as GetBasketAsCSV >+ # We should refactor all the CSV export code >+ # Note: For MARC it is already done in Koha::Exporter::Record but not for SQL CSV profiles type >+ my $csv_profile = Koha::CsvProfiles->find( $csv_profile_id ); >+ die "There is no valid csv profile given" unless $csv_profile; >+ >+ my $csv = Text::CSV_XS->new({'quote_char'=>'"','escape_char'=>'"','sep_char'=>$csv_profile->csv_separator,'binary'=>1}); >+ my $csv_profile_content = $csv_profile->content; >+ my ( @headers, @fields ); >+ while ( $csv_profile_content =~ / >+ ([^=\|]+) # header >+ =? >+ ([^\|]*) # fieldname (table.row or row) >+ \|? /gxms >+ ) { >+ my $header = $1; >+ my $field = ($2 eq '') ? $1 : $2; >+ >+ $header =~ s/^\s+|\s+$//g; # Trim whitespaces >+ push @headers, $header; >+ >+ $field =~ s/[^\.]*\.{1}//; # Remove the table name if exists. >+ $field =~ s/^\s+|\s+$//g; # Trim whitespaces >+ push @fields, $field; >+ } >+ my $items = Koha::Items->search({ itemnumber => { -in => \@itemnumbers } }); >+ while ( my $item = $items->next ) { >+ my @row; >+ my $all_fields = $item->unblessed; >+ $all_fields = { %$all_fields, %{$item->biblio->unblessed}, %{$item->biblioitem->unblessed} }; >+ for my $field (@fields) { >+ push @row, $all_fields->{$field}; >+ } >+ push @rows, \@row; >+ } >+ my $content = join( $csv_profile->csv_separator, @headers ) . "\n"; >+ for my $row ( @rows ) { >+ $csv->combine(@$row); >+ my $string = $csv->string; >+ $content .= $string . "\n"; >+ } >+ print $query->header( >+ -type => 'text/csv', >+ -attachment => 'lost_items.csv', >+ ); >+ print $content; >+ exit; >+ } >+} elsif ( $get_items ) { > my $branchfilter = $params->{'branchfilter'} || undef; > my $barcodefilter = $params->{'barcodefilter'} || undef; > my $itemtypesfilter = $params->{'itemtypesfilter'} || undef; >@@ -97,8 +152,11 @@ if ($get_items) { > # getting all itemtypes > my $itemtypes = Koha::ItemTypes->search_with_localization; > >+my $csv_profiles = Koha::CsvProfiles->search({ type => 'sql', used_for => 'export_lost_items' }); >+ > $template->param( > itemtypes => $itemtypes, >+ csv_profiles => $csv_profiles, > ); > > # writing the template >-- >2.7.4
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 9573
:
68085
|
68086
|
68087
|
68088
|
68089
|
68090
|
68184
|
68283
|
68351
|
68352
|
68353
|
68354
|
68355
|
68356
|
68357
|
68358
|
68398
|
68399
|
68400
|
68401
|
68402
|
68403
|
68404
|
68405
|
71275
|
71276
|
71277
|
71278
|
71279
|
71280
|
71281
|
71282
|
71872
|
71873
|
71874
|
71875
|
71876
|
71877
|
71878
|
71879
|
71880
|
71887
|
71888
|
71889
|
71890
|
71891
|
71892
|
71893
|
71894
|
71895