View | Details | Raw Unified | Return to bug 24163
Collapse All | Expand All

(-)a/acqui/lateorders-export.pl (-35 / +56 lines)
Lines 33-72 my ($template, $loggedinuser, $cookie) = get_template_and_user({ Link Here
33
});
33
});
34
my @ordernumbers = $input->multi_param('ordernumber');
34
my @ordernumbers = $input->multi_param('ordernumber');
35
35
36
my @orders;
36
my $csv_profile_id = $input->param('csv_profile');
37
for my $ordernumber ( @ordernumbers ) {
37
38
    my $order = GetOrder $ordernumber;
38
unless ( $csv_profile_id ) {
39
    my $order_object = Koha::Acquisition::Orders->find($ordernumber);
39
    my @orders;
40
    my $claims = $order_object->claims;
40
    for my $ordernumber ( @ordernumbers ) {
41
    push @orders, {
41
        my $order = GetOrder $ordernumber;
42
            orderdate => $order->{orderdate},
42
        my $order_object = Koha::Acquisition::Orders->find($ordernumber);
43
            latesince => $order->{latesince},
43
        my $claims = $order_object->claims;
44
            estimateddeliverydate => $order->{estimateddeliverydate},
44
        push @orders, {
45
            supplier => $order->{supplier},
45
                orderdate => $order->{orderdate},
46
            supplierid => $order->{supplierid},
46
                latesince => $order->{latesince},
47
            title => $order->{title},
47
                estimateddeliverydate => $order->{estimateddeliverydate},
48
            author => $order->{author},
48
                supplier => $order->{supplier},
49
            publisher => $order->{publisher},
49
                supplierid => $order->{supplierid},
50
            unitpricesupplier => $order->{unitpricesupplier},
50
                title => $order->{title},
51
            quantity_to_receive => $order->{quantity_to_receive},
51
                author => $order->{author},
52
            subtotal => $order->{subtotal},
52
                publisher => $order->{publisher},
53
            budget => $order->{budget},
53
                unitpricesupplier => $order->{unitpricesupplier},
54
            basketname => $order->{basketname},
54
                quantity_to_receive => $order->{quantity_to_receive},
55
            basketno => $order->{basketno},
55
                subtotal => $order->{subtotal},
56
            claims_count => $claims->count,
56
                budget => $order->{budget},
57
            claimed_date => $claims->count ? $claims->last->claimed_on : undef,
57
                basketname => $order->{basketname},
58
            internalnote => $order->{order_internalnote},
58
                basketno => $order->{basketno},
59
            vendornote   => $order->{order_vendornote},
59
                claims_count => $claims->count,
60
            isbn => $order->{isbn},
60
                claimed_date => $claims->count ? $claims->last->claimed_on : undef,
61
        }
61
                internalnote => $order->{order_internalnote},
62
    ;
62
                vendornote   => $order->{order_vendornote},
63
}
63
                isbn => $order->{isbn},
64
            }
65
        ;
66
    }
67
68
    # We want to export using the default profile, using the template acqui/csv/lateorders.tt
69
    print $input->header(
70
        -type       => 'text/csv',
71
        -attachment => 'lateorders.csv',
72
    );
73
    $template->param( orders => \@orders );
74
    for my $line ( split '\n', $template->output ) {
75
        print "$line\n" unless $line =~ m|^\s*$|;
76
    }
77
    exit;
78
} else {
79
    my $csv_profile = Koha::CsvProfiles->find($csv_profile_id);
80
    my $content = '[% SET separator = "'.$csv_profile->csv_separator.'" ~%]' . $csv_profile->content;
81
82
    my $csv = C4::Letters::_process_tt({
83
        content => $content,
84
        loops => { aqorders => \@ordernumbers },
85
    });
64
86
65
print $input->header(
87
    print $input->header(
66
    -type       => 'text/csv',
88
        -type       => 'text/csv',
67
    -attachment => 'lateorders.csv',
89
        -attachment => 'lateorders.csv',
68
);
90
    );
69
$template->param( orders => \@orders );
91
    print $csv;
70
for my $line ( split '\n', $template->output ) {
92
    exit;
71
    print "$line\n" unless $line =~ m|^\s*$|;
72
}
93
}
(-)a/acqui/lateorders.pl (+2 lines)
Lines 54-59 use C4::Acquisition; Link Here
54
use C4::Letters;
54
use C4::Letters;
55
use Koha::DateUtils;
55
use Koha::DateUtils;
56
use Koha::Acquisition::Orders;
56
use Koha::Acquisition::Orders;
57
use Koha::CsvProfiles;
57
58
58
my $input = new CGI;
59
my $input = new CGI;
59
my ($template, $loggedinuser, $cookie) = get_template_and_user(
60
my ($template, $loggedinuser, $cookie) = get_template_and_user(
Lines 172-176 $template->param( Link Here
172
    estimateddeliverydatefrom => $estimateddeliverydatefrom,
173
    estimateddeliverydatefrom => $estimateddeliverydatefrom,
173
    estimateddeliverydateto   => $estimateddeliverydateto,
174
    estimateddeliverydateto   => $estimateddeliverydateto,
174
	intranetcolorstylesheet => C4::Context->preference("intranetcolorstylesheet"),
175
	intranetcolorstylesheet => C4::Context->preference("intranetcolorstylesheet"),
176
    csv_profiles         => [ Koha::CsvProfiles->search({ type => 'sql', used_for => 'late_orders' }) ],
175
);
177
);
176
output_html_with_http_headers $input, $cookie, $template->output;
178
output_html_with_http_headers $input, $cookie, $template->output;
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/lateorders.tt (-4 / +19 lines)
Lines 181-188 Link Here
181
    <div class="spacer"></div>
181
    <div class="spacer"></div>
182
182
183
    <p style="display:block;">
183
    <p style="display:block;">
184
        <input type="button" value="Export as CSV" id="ExportSelected" />
184
        <div class="btn-group">
185
        <input type="submit"  value="Claim order" />
185
          <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>
186
          <a class="btn btn-default dropdown-toggle" data-toggle="dropdown"><span class="caret"></span></a>
187
          <ul class="dropdown-menu" id="export-csv-menu">
188
              <li><a href="#">Default</a></li>
189
              [% IF csv_profiles %]
190
                  [% FOR csv IN csv_profiles %]
191
                    <li><a href="#" data-value="[% csv.export_format_id | html %]">[% csv.profile | html %]</a></li>
192
                  [% END %]
193
              [% END %]
194
           </ul>
195
        </div>
196
197
        <input type="submit"  class="btn btn-default" value="Claim order" />
186
    </p>
198
    </p>
187
</form>
199
</form>
188
[% ELSE %]<p>There are no late orders.</p>
200
[% ELSE %]<p>There are no late orders.</p>
Lines 292-298 Link Here
292
            $('#CheckNone').click(function(){ $(late_orderst.fnGetNodes()).find("td").unCheckCheckboxes();});
304
            $('#CheckNone').click(function(){ $(late_orderst.fnGetNodes()).find("td").unCheckCheckboxes();});
293
305
294
            // Generates a dynamic link for exporting the selection's data as CSV
306
            // Generates a dynamic link for exporting the selection's data as CSV
295
            $("#ExportSelected").click(function() {
307
            $("#exportbutton, #export-csv-menu a").click(function() {
296
                var all_nodes = $(late_orderst.fnGetNodes());
308
                var all_nodes = $(late_orderst.fnGetNodes());
297
                var selected = $(all_nodes).find("input[name='ordernumber']:checked");
309
                var selected = $(all_nodes).find("input[name='ordernumber']:checked");
298
310
Lines 301-311 Link Here
301
                    return false;
313
                    return false;
302
                }
314
                }
303
315
316
                var url = $('#exportbutton').attr('href') + '?';
304
                // Building the url from currently checked boxes
317
                // Building the url from currently checked boxes
305
                var url = '/cgi-bin/koha/acqui/lateorders-export.pl?op=export';
306
                for (var i = 0; i < selected.length; i++) {
318
                for (var i = 0; i < selected.length; i++) {
307
                    url += '&amp;ordernumber=' + selected[i].value;
319
                    url += '&amp;ordernumber=' + selected[i].value;
308
                }
320
                }
321
                if($(this).attr("data-value")) {
322
                    url += '&amp;csv_profile=' + $(this).attr("data-value");
323
                }
309
                // And redirecting to the CSV page
324
                // And redirecting to the CSV page
310
                location.href = url;
325
                location.href = url;
311
                return false;
326
                return false;
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/csv-profiles.tt (-4 / +5 lines)
Lines 92-97 Link Here
92
[% BLOCK used_for_description %]
92
[% BLOCK used_for_description %]
93
    [% IF used_for_code == 'export_records' %] Export records
93
    [% IF used_for_code == 'export_records' %] Export records
94
    [% ELSIF used_for_code == 'late_issues' %] Late serial issues claims
94
    [% ELSIF used_for_code == 'late_issues' %] Late serial issues claims
95
    [% ELSIF used_for_code == 'late_orders' %] Export late orders
95
    [% ELSIF used_for_code == 'export_basket' %] Basket export in acquisition
96
    [% ELSIF used_for_code == 'export_basket' %] Basket export in acquisition
96
    [% ELSIF used_for_code == 'export_lost_items' %] Export lost items in report
97
    [% ELSIF used_for_code == 'export_lost_items' %] Export lost items in report
97
    [% ELSE %] Unknown usage
98
    [% ELSE %] Unknown usage
Lines 134-140 Link Here
134
                <li class="sql_specific">
135
                <li class="sql_specific">
135
                    <label for="used_for_sql">Usage: </label>
136
                    <label for="used_for_sql">Usage: </label>
136
                    <select id="used_for_sql" name="used_for_sql">
137
                    <select id="used_for_sql" name="used_for_sql">
137
                        [% FOREACH used_for IN [ 'late_issues' 'export_basket' 'export_lost_items' ] %]
138
                        [% FOREACH used_for IN [ 'late_issues' 'late_orders', 'export_basket' 'export_lost_items' ] %]
138
                        [% IF csv_profile.used_for == used_for %]
139
                        [% IF csv_profile.used_for == used_for %]
139
                            <option value="[% used_for | html %]" selected="selected">[% PROCESS used_for_description used_for_code = used_for %]</option>
140
                            <option value="[% used_for | html %]" selected="selected">[% PROCESS used_for_description used_for_code = used_for %]</option>
140
                        [% ELSE %]
141
                        [% ELSE %]
Lines 202-214 Link Here
202
                </li>
203
                </li>
203
204
204
                <li class="sql_specific">
205
                <li class="sql_specific">
205
                    <label for="late_issues_content" class="required">Profile SQL fields: </label>
206
                    <label for="sql_content" class="required">Profile SQL fields: </label>
206
                    <textarea cols="50" rows="2" name="sql_content" id="sql_content">[% csv_profile.content | html %]</textarea>
207
                    <textarea cols="50" rows="2" name="sql_content" id="sql_content">[% csv_profile.content | html %]</textarea>
207
                    <p>You have to define which fields you want to export, separated by pipes.</p>
208
                    <p>You have to define which fields you want to export, separated by pipes.</p>
208
                    <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>
209
                    <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>
209
                    <p>Example: Name=subscription.name|Title=subscription.title|Issue number=serial.serialseq</p>
210
                    <p>Example: Name=subscription.name|Title=subscription.title|Issue number=serial.serialseq</p>
210
                    <p>For late issues claims you can use data from following tables: serial, subscription, biblio, biblioitems and aqbookseller.</p>
211
                    <p>For late issues claims you can use data from following tables: serial, subscription, biblio, biblioitems and aqbookseller.</p>
211
                    <p>For basket exports you can use data from following tables: biblio, biblioitems, aqorders, aqbudgets and aqbasket.</p>
212
                    <p>For basket exports you can use data from following tables: biblio, biblioitems, aqorders, aqbudgets and aqbasket.</p>
213
                    <p>For late orders exports you must provide a Template Toolkit syntax that will generate the whole CSV file..</p>
212
                </li>
214
                </li>
213
            </ol>
215
            </ol>
214
        </fieldset>
216
        </fieldset>
Lines 263-269 Link Here
263
                    <td>[% csv_profile.export_format_id | html %]</td>
265
                    <td>[% csv_profile.export_format_id | html %]</td>
264
                    <td>[% csv_profile.profile | html %]</td>
266
                    <td>[% csv_profile.profile | html %]</td>
265
                    <td>[% csv_profile.description | html %]</td>
267
                    <td>[% csv_profile.description | html %]</td>
266
                    <td>[% csv_profile.content | html %]</td>
268
                    <td>[% csv_profile.content | html | html_line_break %]</td>
267
                    <td>[% csv_profile.csv_separator | html %]</td>
269
                    <td>[% csv_profile.csv_separator | html %]</td>
268
                    <td>[% PROCESS type_description type_code = csv_profile.type %]</td>
270
                    <td>[% PROCESS type_description type_code = csv_profile.type %]</td>
269
                    <td>[% PROCESS used_for_description used_for_code = csv_profile.used_for %]</td>
271
                    <td>[% PROCESS used_for_description used_for_code = csv_profile.used_for %]</td>
270
- 

Return to bug 24163