Bugzilla – Attachment 56222 Details for
Bug 8612
CSV export profile to have custom fields in export csv basket
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 8612 - System preference to have custom fields in export csv basket
Bug-8612---System-preference-to-have-custom-fields.patch (text/plain), 9.93 KB, created by
Josef Moravec
on 2016-10-12 07:08:31 UTC
(
hide
)
Description:
Bug 8612 - System preference to have custom fields in export csv basket
Filename:
MIME Type:
Creator:
Josef Moravec
Created:
2016-10-12 07:08:31 UTC
Size:
9.93 KB
patch
obsolete
>From dbf8874dfadd722cd89dafba9826abf1755d8c7a Mon Sep 17 00:00:00 2001 >From: Blou <philippe.blouin@inlibro.com> >Date: Thu, 26 Mar 2015 16:07:44 -0400 >Subject: [PATCH] Bug 8612 - System preference to have custom fields in export > csv basket >MIME-Version: 1.0 >Content-Type: text/plain; charset=UTF-8 >Content-Transfer-Encoding: 8bit > >This patch allows the user use a CSV export profile to create the fields to export the basket as CSV in a basket page. > >To test: > >1) Apply the patch; >2) Create a CSV export profile - type sql - Home ⺠Tools ⺠CSV export profiles > ex: biblionumber=biblio.biblionumber|auteur=biblio.author|titre=biblio.title|date=biblioitems.copyrightdate|editeur=biblioitems.publishercode|isbn=biblioitems.isbn|quantite=aqorders.quantity|prix=aqorders.rrp|panier=aqorders.basketno >3) Create a new basket and add an order to the basket >4) Validate: the text "Select CSV profile:" and a dropdown in the basket view >5) In the new dropdown, select the CSV export profile created >6) Validate the CSV file. >7) Do the same validation with a closed basket. > a) close the basket > b) View the basket > c) validate that there is a dropdown > d) test it with an export > >Signed-off-by: Josef Moravec <josef.moravec@gmail.com> > >Works as expected for me > >Signed-off-by: Josef Moravec <josef.moravec@gmail.com> >--- > acqui/basket.pl | 79 +++++++++++++++++++++- > .../intranet-tmpl/prog/en/modules/acqui/basket.tt | 45 +++++++++++- > 2 files changed, 120 insertions(+), 4 deletions(-) > >diff --git a/acqui/basket.pl b/acqui/basket.pl >index f3bf36a..5aaa2b4 100755 >--- a/acqui/basket.pl >+++ b/acqui/basket.pl >@@ -34,6 +34,7 @@ use C4::Biblio; > use C4::Members qw/GetMember/; #needed for permissions checking for changing basketgroup of a basket > use C4::Items; > use C4::Suggestions; >+use C4::Csv; > use Koha::Libraries; > use Date::Calc qw/Add_Delta_Days/; > use Koha::Database; >@@ -163,7 +164,26 @@ if ( $op eq 'delete_confirm' ) { > -type => 'text/csv', > -attachment => 'basket' . $basket->{'basketno'} . '.csv', > ); >- print GetBasketAsCSV($query->param('basketno'), $query); >+ if ( $query->param('csv_profile') eq 'default'){ >+ print GetBasketAsCSV($query->param('basketno'), $query); >+ } else { >+ my $csv_profile_id = $query->param('csv_profile'); >+ my $csv_profile = C4::Csv::GetCsvProfile( $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 $basket_info = get_basket_csv_profile_info($csv_profile_content, $query->param('basketno')); >+ >+ print join( $csv_profile->{csv_separator}, @{$basket_info->{headers}} ) . "\n"; >+ >+ for my $row ( @{$basket_info->{rows}} ) { >+ $csv->combine(@$row); >+ my $string = $csv->string; >+ print $string, "\n"; >+ } >+ } > exit; > } elsif ($op eq 'close') { > my $confirm = $query->param('confirm') || $confirm_pref eq '2'; >@@ -403,6 +423,7 @@ elsif ( $op eq 'ediorder' ) { > unclosable => @orders ? $basket->{is_standing} : 1, > has_budgets => $has_budgets, > duplinbatch => $duplinbatch, >+ csv_profiles => C4::Csv::GetCsvProfiles( "sql" ), > ); > } > >@@ -481,6 +502,62 @@ sub get_order_infos { > return \%line; > } > >+sub get_basket_DB_info{ >+ my ( $basketno ) = @_; >+ return () unless $basketno; >+ my $dbh = C4::Context->dbh; >+ my $query =" >+ SELECT biblio.*,biblioitems.*, aqbasket.*,aqcontract.*, >+ aqorders.*, >+ aqbudgets.* >+ FROM aqorders >+ LEFT JOIN aqbasket ON aqorders.basketno = aqbasket.basketno >+ LEFT JOIN aqcontract ON aqbasket.contractnumber = aqcontract.contractnumber >+ LEFT JOIN aqbudgets ON aqbudgets.budget_id = aqorders.budget_id >+ LEFT JOIN biblio ON biblio.biblionumber = aqorders.biblionumber >+ LEFT JOIN biblioitems ON biblioitems.biblionumber =biblio.biblionumber >+ WHERE aqorders.basketno=? >+ AND (datecancellationprinted IS NULL OR datecancellationprinted='0000-00-00') >+ ORDER BY biblioitems.publishercode,biblio.title >+ "; >+ my $result_set = >+ $dbh->selectall_arrayref( $query, { Slice => {} }, $basketno ); >+ return @{$result_set}; >+} >+ >+sub get_basket_csv_profile_info{ >+ my ($csv_profile_content,$basketno) = @_; >+ >+ my ( @headers, @fields ); >+ while ( $csv_profile_content =~ / >+ ([^=]+) # header >+ = >+ ([^\|]+) # fieldname (table.row or row) >+ \|? /gxms >+ ) { >+ push @headers, $1; >+ my $field = $2; >+ $field =~ s/[^\.]*\.?//; # Remove the table name if exists. >+ push @fields, $field; >+ } >+ >+ my @rows; >+ my @basket_info = get_basket_DB_info($basketno); >+ >+ for my $basket_info ( @basket_info ) { >+ my @row; >+ for my $field ( @fields ) { >+ push @row, $basket_info->{$field}; >+ } >+ push @rows, \@row; >+ } >+ my $hash_ref; >+ $hash_ref->{ 'headers' } = \@headers; >+ $hash_ref->{ 'rows' } = \@rows; >+ >+ return $hash_ref; >+} >+ > output_html_with_http_headers $query, $cookie, $template->output; > > >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/basket.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/basket.tt >index d43a959..ec3710f 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/basket.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/basket.tt >@@ -121,6 +121,16 @@ > e.preventDefault(); > confirm_reopen(); > }); >+ // Generates a dynamic link for exporting the selections data as CSV >+ $("#exportbutton").click(function() { >+ // Building the url from currently checked boxes >+ var url = '/cgi-bin/koha/acqui/basket.pl'; >+ url += $('#exportbutton').attr('href'); >+ url += '&csv_profile=' + $("#csv_profile_for_export option:selected").val(); >+ // And redirecting to the CSV page >+ location.href = url; >+ return false; >+ }); > }); > > function UserSearchPopup(f) { >@@ -197,11 +207,26 @@ > <a href="/cgi-bin/koha/acqui/basket.pl?op=close&basketno=[% basketno %]&booksellerid=[% booksellerid %]" class="btn btn-small" id="closebutton"><i class="fa fa-times-circle"></i> Close this basket</a> > </div> > [% END %] >- <div class="btn-group"><a href="/cgi-bin/koha/acqui/basket.pl?op=export&basketno=[% basketno %]&booksellerid=[% booksellerid %]" class="btn btn-small" id="exportbutton"><i class="fa fa-download"></i> Export this basket as CSV</a></div> >+ <div class="btn-group"> >+ <fieldset class="action"> >+ <label for="csv_code">Select CSV profile:</label> >+ <select id="csv_profile_for_export"> >+ <option value="default">default</option> >+ [% IF csv_profiles %] >+ [% FOR csv IN csv_profiles %] >+ <option value="[% csv.export_format_id %]">[% csv.profile %]</option> >+ [% END %] >+ [% END %] >+ </select> >+ </fieldset> >+ </div> >+ <div class="btn-group"><a href="[% script_name %]?op=export&basketno=[% basketno %]&booksellerid=[% booksellerid %]" class="btn btn-small" id="exportbutton"><i class="fa fa-download"></i> Export as CSV</a></div> >+ > [% IF ediaccount %] > <div class="btn-group"><a href="/cgi-bin/koha/acqui/edi_ean.pl?op=ediorder&basketno=[% basketno %]&booksellerid=[% booksellerid %]" class="btn btn-small" id="ediorderbutton"><i class="fa fa-download"></i> Create EDIFACT order</a></div> > [% END %] >- </div> >+ >+ </div> > <!-- Modal for confirm deletion box--> > <div class="modal hide" id="deleteBasketModal" tabindex="-1" role="dialog" aria-labelledby="delbasketModalLabel" aria-hidden="true"> > <div class="modal-header"> >@@ -255,8 +280,22 @@ > [% ELSE %] > [% UNLESS ( grouped ) %] > <div id="toolbar" class="btn-toolbar"> >+ > <div class="btn-group"><a href="#" class="btn btn-small" id="reopenbutton"><i class="fa fa-refresh"></i> Reopen this basket</a></div> >- <div class="btn-group"><a href="/cgi-bin/koha/acqui/basket.pl?op=export&basketno=[% basketno %]&booksellerid=[% booksellerid %]" class="btn btn-small" id="exportbutton"><i class="fa fa-download"></i> Export this basket as CSV</a></div> >+ <div class="btn-group"> >+ <fieldset class="action"> >+ <label for="csv_code">Select CSV profile:</label> >+ <select id="csv_profile_for_export"> >+ <option value="default">default</option> >+ [% IF csv_profiles %] >+ [% FOR csv IN csv_profiles %] >+ <option value="[% csv.export_format_id %]">[% csv.profile %]</option> >+ [% END %] >+ [% END %] >+ </select> >+ </fieldset> >+ </div> >+ <div class="btn-group"><a href="[% script_name %]?op=export&basketno=[% basketno %]&booksellerid=[% booksellerid %]" class="btn btn-small" id="exportbutton"><i class="fa fa-download"></i> Export this basket as CSV</a></div> > </div> > [% END %] > [% END %] >-- >2.1.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 8612
:
11514
|
36860
|
37289
|
37293
|
41224
|
41225
|
41226
|
41227
|
42532
|
42533
|
42534
|
47591
|
47592
|
47593
|
56222
|
56223
|
56224
|
56225
|
57012
|
57013
|
57024
|
57025
|
57026
|
57027
|
57028
|
57029
|
57079
|
58073
|
58074
|
58075
|
58076
|
58077
|
58078
|
58079
|
58985
|
58986
|
58987
|
58988
|
58989
|
58990
|
58991
|
58992
|
59757
|
60480
|
61264
|
61265
|
61266
|
61267
|
61405
|
61520
|
63048
|
63049
|
63050
|
63051
|
63052
|
63053
|
63054
|
63055
|
63056
|
63104
|
63158
|
63279
|
63910
|
63911
|
63912
|
63913
|
63914
|
63915
|
63964
|
63966