Bugzilla – Attachment 103585 Details for
Bug 24163
Add ability to define a CSV profile for late orders export
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 24163: Allow to define CSV profile for late orders export
Bug-24163-Allow-to-define-CSV-profile-for-late-ord.patch (text/plain), 12.94 KB, created by
PTFS Europe Sandboxes
on 2020-04-23 11:55:30 UTC
(
hide
)
Description:
Bug 24163: Allow to define CSV profile for late orders export
Filename:
MIME Type:
Creator:
PTFS Europe Sandboxes
Created:
2020-04-23 11:55:30 UTC
Size:
12.94 KB
patch
obsolete
>From dd234dedc3b9cfaee55cae487db8aef04d81692f Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Wed, 18 Dec 2019 17:24:17 +0100 >Subject: [PATCH] Bug 24163: Allow to define CSV profile for late orders export >MIME-Version: 1.0 >Content-Type: text/plain; charset=UTF-8 >Content-Transfer-Encoding: 8bit > >This new enhancement adds the ability to create a CSV profile for the late >orders export. >Prior to this, the CSV profile was hardcoded in a template and not >editable (unless you modify the .tt file of course). > >The main difficulty of the request was to make the multiple claims dates >accessible from the CSV profile. So far we only accept columns from the >database. However we would like to use the Koha::Acquisition::Order >object to make things easier (it had a ->claims method to access the >different claims). >To acchieve this, we are going to accept the TT syntax for that CSV profile. >It means that only CSV profiles created for 'late_orders' will have the >capability to use the TT syntax (can be extended later of course if >needed). >The alternative was to use specific placeholders, like %claims_count%, >%claimed_date%, but it sounded more powerful and flexible to allow the >TT syntax instead. > >Note that the former export (template based) still exists and is the >default option. > >Test plan: >0. Apply the patches and execute the update database entry >1. Create some orders, close the basket >2. Claim some of the orders >3. Note the new button at the bottom of the table that have several >entries. >=> The first entry will generate a CSV file using the previous method >=> The second entry will generate it using the new CSV profile, note >that the number of claims as well as the different claims date are >displayed. > >4. Bonus point: Edit the CSV profile (Home ⺠Tools ⺠CSV export >profiles) that is named "Late orders (csv profile)", or create a new >one, and modify it. >Export the late orders using this CSV profile and confirm that the >generated CSV file is the one you expect. > >Sponsored-by: Institute of Technology Tralee > >Signed-off-by: David Nind <david@davidnind.com> > >Signed-off-by: Angela O'Connor Desmond <angela.oconnordesmond@staff.ittralee.ie> >--- > acqui/lateorders-export.pl | 91 +++++++++++++--------- > acqui/lateorders.pl | 2 + > .../prog/en/modules/acqui/lateorders.tt | 23 +++++- > .../prog/en/modules/tools/csv-profiles.tt | 8 +- > 4 files changed, 82 insertions(+), 42 deletions(-) > >diff --git a/acqui/lateorders-export.pl b/acqui/lateorders-export.pl >index eb04ba7635..31e21a8e75 100755 >--- a/acqui/lateorders-export.pl >+++ b/acqui/lateorders-export.pl >@@ -33,40 +33,61 @@ my ($template, $loggedinuser, $cookie) = get_template_and_user({ > }); > my @ordernumbers = $input->multi_param('ordernumber'); > >-my @orders; >-for my $ordernumber ( @ordernumbers ) { >- my $order = GetOrder $ordernumber; >- my $order_object = Koha::Acquisition::Orders->find($ordernumber); >- my $claims = $order_object->claims; >- push @orders, { >- orderdate => $order->{orderdate}, >- latesince => $order->{latesince}, >- estimateddeliverydate => $order->{estimateddeliverydate}, >- supplier => $order->{supplier}, >- supplierid => $order->{supplierid}, >- title => $order->{title}, >- author => $order->{author}, >- publisher => $order->{publisher}, >- unitpricesupplier => $order->{unitpricesupplier}, >- quantity_to_receive => $order->{quantity_to_receive}, >- subtotal => $order->{subtotal}, >- budget => $order->{budget}, >- basketname => $order->{basketname}, >- basketno => $order->{basketno}, >- claims_count => $claims->count, >- claimed_date => $claims->count ? $claims->last->claimed_on : undef, >- internalnote => $order->{order_internalnote}, >- vendornote => $order->{order_vendornote}, >- isbn => $order->{isbn}, >- } >- ; >-} >+my $csv_profile_id = $input->param('csv_profile'); >+ >+unless ( $csv_profile_id ) { >+ my @orders; >+ for my $ordernumber ( @ordernumbers ) { >+ my $order = GetOrder $ordernumber; >+ my $order_object = Koha::Acquisition::Orders->find($ordernumber); >+ my $claims = $order_object->claims; >+ push @orders, { >+ orderdate => $order->{orderdate}, >+ latesince => $order->{latesince}, >+ estimateddeliverydate => $order->{estimateddeliverydate}, >+ supplier => $order->{supplier}, >+ supplierid => $order->{supplierid}, >+ title => $order->{title}, >+ author => $order->{author}, >+ publisher => $order->{publisher}, >+ unitpricesupplier => $order->{unitpricesupplier}, >+ quantity_to_receive => $order->{quantity_to_receive}, >+ subtotal => $order->{subtotal}, >+ budget => $order->{budget}, >+ basketname => $order->{basketname}, >+ basketno => $order->{basketno}, >+ claims_count => $claims->count, >+ claimed_date => $claims->count ? $claims->last->claimed_on : undef, >+ internalnote => $order->{order_internalnote}, >+ vendornote => $order->{order_vendornote}, >+ isbn => $order->{isbn}, >+ } >+ ; >+ } >+ >+ # We want to export using the default profile, using the template acqui/csv/lateorders.tt >+ print $input->header( >+ -type => 'text/csv', >+ -attachment => 'lateorders.csv', >+ ); >+ $template->param( orders => \@orders ); >+ for my $line ( split '\n', $template->output ) { >+ print "$line\n" unless $line =~ m|^\s*$|; >+ } >+ exit; >+} else { >+ my $csv_profile = Koha::CsvProfiles->find($csv_profile_id); >+ my $content = '[% SET separator = "'.$csv_profile->csv_separator.'" ~%]' . $csv_profile->content; >+ >+ my $csv = C4::Letters::_process_tt({ >+ content => $content, >+ loops => { aqorders => \@ordernumbers }, >+ }); > >-print $input->header( >- -type => 'text/csv', >- -attachment => 'lateorders.csv', >-); >-$template->param( orders => \@orders ); >-for my $line ( split '\n', $template->output ) { >- print "$line\n" unless $line =~ m|^\s*$|; >+ print $input->header( >+ -type => 'text/csv', >+ -attachment => 'lateorders.csv', >+ ); >+ print $csv; >+ exit; > } >diff --git a/acqui/lateorders.pl b/acqui/lateorders.pl >index 8bf7da2f6c..0750de6915 100755 >--- a/acqui/lateorders.pl >+++ b/acqui/lateorders.pl >@@ -54,6 +54,7 @@ use C4::Acquisition; > use C4::Letters; > use Koha::DateUtils; > use Koha::Acquisition::Orders; >+use Koha::CsvProfiles; > > my $input = new CGI; > my ($template, $loggedinuser, $cookie) = get_template_and_user( >@@ -172,5 +173,6 @@ $template->param( > estimateddeliverydatefrom => $estimateddeliverydatefrom, > estimateddeliverydateto => $estimateddeliverydateto, > intranetcolorstylesheet => C4::Context->preference("intranetcolorstylesheet"), >+ csv_profiles => [ Koha::CsvProfiles->search({ type => 'sql', used_for => 'late_orders' }) ], > ); > output_html_with_http_headers $input, $cookie, $template->output; >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/lateorders.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/lateorders.tt >index d29539bafe..ddf3abeb04 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/lateorders.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/lateorders.tt >@@ -181,8 +181,20 @@ > <div class="spacer"></div> > > <p style="display:block;"> >- <input type="button" value="Export as CSV" id="ExportSelected" /> >- <input type="submit" value="Claim order" /> >+ <div class="btn-group"> >+ <a id="exportbutton" class="btn btn-default" href="/cgi-bin/koha/acqui/lateorders-export.pl"><i class="fa fa-download"></i> Export as CSV</a> >+ <a class="btn btn-default dropdown-toggle" data-toggle="dropdown"><span class="caret"></span></a> >+ <ul class="dropdown-menu" id="export-csv-menu"> >+ <li><a href="#">Default</a></li> >+ [% IF csv_profiles %] >+ [% FOR csv IN csv_profiles %] >+ <li><a href="#" data-value="[% csv.export_format_id | html %]">[% csv.profile | html %]</a></li> >+ [% END %] >+ [% END %] >+ </ul> >+ </div> >+ >+ <input type="submit" class="btn btn-default" value="Claim order" /> > </p> > </form> > [% ELSE %]<p>There are no late orders.</p> >@@ -292,7 +304,7 @@ > $('#CheckNone').click(function(){ $(late_orderst.fnGetNodes()).find("td").unCheckCheckboxes();}); > > // Generates a dynamic link for exporting the selection's data as CSV >- $("#ExportSelected").click(function() { >+ $("#exportbutton, #export-csv-menu a").click(function() { > var all_nodes = $(late_orderst.fnGetNodes()); > var selected = $(all_nodes).find("input[name='ordernumber']:checked"); > >@@ -301,11 +313,14 @@ > return false; > } > >+ var url = $('#exportbutton').attr('href') + '?'; > // Building the url from currently checked boxes >- var url = '/cgi-bin/koha/acqui/lateorders-export.pl?op=export'; > for (var i = 0; i < selected.length; i++) { > url += '&ordernumber=' + selected[i].value; > } >+ if($(this).attr("data-value")) { >+ url += '&csv_profile=' + $(this).attr("data-value"); >+ } > // And redirecting to the CSV page > location.href = url; > return false; >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 8a1bea429d..6365ede514 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 >@@ -92,6 +92,7 @@ > [% BLOCK used_for_description %] > [% IF used_for_code == 'export_records' %] Export records > [% ELSIF used_for_code == 'late_issues' %] Late serial issues claims >+ [% ELSIF used_for_code == 'late_orders' %] Export late orders > [% 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 >@@ -134,7 +135,7 @@ > <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' 'export_lost_items' ] %] >+ [% FOREACH used_for IN [ 'late_issues' 'late_orders', 'export_basket' 'export_lost_items' ] %] > [% IF csv_profile.used_for == used_for %] > <option value="[% used_for | html %]" selected="selected">[% PROCESS used_for_description used_for_code = used_for %]</option> > [% ELSE %] >@@ -202,13 +203,14 @@ > </li> > > <li class="sql_specific"> >- <label for="late_issues_content" class="required">Profile SQL fields: </label> >+ <label for="sql_content" class="required">Profile SQL fields: </label> > <textarea cols="50" rows="2" name="sql_content" id="sql_content">[% csv_profile.content | html %]</textarea> > <p>You have to define which fields you want to export, separated by pipes.</p> > <p>You can also use your own headers (instead of the ones from Koha) by prefixing the field name with an header, followed by the equal sign.</p> > <p>Example: Name=subscription.name|Title=subscription.title|Issue number=serial.serialseq</p> > <p>For late issues claims you can use data from following tables: serial, subscription, biblio, biblioitems and aqbookseller.</p> > <p>For basket exports you can use data from following tables: biblio, biblioitems, aqorders, aqbudgets and aqbasket.</p> >+ <p>For late orders exports you must provide a Template Toolkit syntax that will generate the whole CSV file..</p> > </li> > </ol> > </fieldset> >@@ -263,7 +265,7 @@ > <td>[% csv_profile.export_format_id | html %]</td> > <td>[% csv_profile.profile | html %]</td> > <td>[% csv_profile.description | html %]</td> >- <td>[% csv_profile.content | html %]</td> >+ <td>[% csv_profile.content | html | html_line_break %]</td> > <td>[% csv_profile.csv_separator | html %]</td> > <td>[% PROCESS type_description type_code = csv_profile.type %]</td> > <td>[% PROCESS used_for_description used_for_code = csv_profile.used_for %]</td> >-- >2.11.0
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 24163
:
97120
|
97121
|
97122
|
97123
|
98691
|
98692
|
102185
|
102186
|
102257
|
102258
|
103585
|
103586
|
104192
|
104193
|
104194
|
104252
|
104337
|
104338
|
104339
|
104340
|
104341