});
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;
}
<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>
$('#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");
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;
[% 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
<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 %]
</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>
<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>