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

(-)a/acqui/basket.pl (-1 / +78 lines)
Lines 34-39 use C4::Biblio; Link Here
34
use C4::Members qw/GetMember/;  #needed for permissions checking for changing basketgroup of a basket
34
use C4::Members qw/GetMember/;  #needed for permissions checking for changing basketgroup of a basket
35
use C4::Items;
35
use C4::Items;
36
use C4::Suggestions;
36
use C4::Suggestions;
37
use C4::Csv;
37
use Koha::Libraries;
38
use Koha::Libraries;
38
use Date::Calc qw/Add_Delta_Days/;
39
use Date::Calc qw/Add_Delta_Days/;
39
use Koha::Database;
40
use Koha::Database;
Lines 163-169 if ( $op eq 'delete_confirm' ) { Link Here
163
        -type       => 'text/csv',
164
        -type       => 'text/csv',
164
        -attachment => 'basket' . $basket->{'basketno'} . '.csv',
165
        -attachment => 'basket' . $basket->{'basketno'} . '.csv',
165
    );
166
    );
166
    print GetBasketAsCSV($query->param('basketno'), $query);
167
    if ( $query->param('csv_profile') eq 'default'){
168
        print GetBasketAsCSV($query->param('basketno'), $query);
169
    } else {
170
        my $csv_profile_id = $query->param('csv_profile');
171
        my $csv_profile = C4::Csv::GetCsvProfile( $csv_profile_id );
172
        die "There is no valid csv profile given" unless $csv_profile;
173
174
        my $csv = Text::CSV_XS->new({'quote_char'=>'"','escape_char'=>'"','sep_char'=>$csv_profile->{csv_separator},'binary'=>1});
175
        my $csv_profile_content = $csv_profile->{content};
176
177
        my $basket_info = get_basket_csv_profile_info($csv_profile_content, $query->param('basketno'));
178
179
        print join( $csv_profile->{csv_separator}, @{$basket_info->{headers}} ) . "\n";
180
181
        for my $row ( @{$basket_info->{rows}} ) {
182
            $csv->combine(@$row);
183
            my $string = $csv->string;
184
            print $string, "\n";
185
        }
186
    }
167
    exit;
187
    exit;
168
} elsif ($op eq 'close') {
188
} elsif ($op eq 'close') {
169
    my $confirm = $query->param('confirm') || $confirm_pref eq '2';
189
    my $confirm = $query->param('confirm') || $confirm_pref eq '2';
Lines 403-408 elsif ( $op eq 'ediorder' ) { Link Here
403
        unclosable           => @orders ? $basket->{is_standing} : 1,
423
        unclosable           => @orders ? $basket->{is_standing} : 1,
404
        has_budgets          => $has_budgets,
424
        has_budgets          => $has_budgets,
405
        duplinbatch          => $duplinbatch,
425
        duplinbatch          => $duplinbatch,
426
        csv_profiles         => C4::Csv::GetCsvProfiles( "sql" ),
406
    );
427
    );
407
}
428
}
408
429
Lines 481-486 sub get_order_infos { Link Here
481
    return \%line;
502
    return \%line;
482
}
503
}
483
504
505
sub get_basket_DB_info{
506
    my ( $basketno ) = @_;
507
    return () unless $basketno;
508
    my $dbh   = C4::Context->dbh;
509
    my $query  ="
510
    SELECT biblio.*,biblioitems.*, aqbasket.*,aqcontract.*,
511
                aqorders.*,
512
                aqbudgets.*
513
        FROM    aqorders
514
            LEFT JOIN aqbasket         ON aqorders.basketno = aqbasket.basketno
515
            LEFT JOIN aqcontract       ON aqbasket.contractnumber = aqcontract.contractnumber
516
            LEFT JOIN aqbudgets        ON aqbudgets.budget_id = aqorders.budget_id
517
            LEFT JOIN biblio           ON biblio.biblionumber = aqorders.biblionumber
518
            LEFT JOIN biblioitems      ON biblioitems.biblionumber =biblio.biblionumber
519
        WHERE   aqorders.basketno=?
520
            AND (datecancellationprinted IS NULL OR datecancellationprinted='0000-00-00')
521
            ORDER BY biblioitems.publishercode,biblio.title
522
    ";
523
    my $result_set =
524
      $dbh->selectall_arrayref( $query, { Slice => {} }, $basketno );
525
    return @{$result_set};
526
}
527
528
sub get_basket_csv_profile_info{
529
    my ($csv_profile_content,$basketno) = @_;
530
531
    my ( @headers, @fields );
532
    while ( $csv_profile_content =~ /
533
        ([^=]+) # header
534
        =
535
        ([^\|]+) # fieldname (table.row or row)
536
        \|? /gxms
537
    ) {
538
        push @headers, $1;
539
        my $field = $2;
540
        $field =~ s/[^\.]*\.?//; # Remove the table name if exists.
541
        push @fields, $field;
542
    }
543
544
    my @rows;
545
    my @basket_info = get_basket_DB_info($basketno);
546
547
    for my $basket_info ( @basket_info ) {
548
        my @row;
549
        for my $field ( @fields ) {
550
            push @row, $basket_info->{$field};
551
        }
552
        push @rows, \@row;
553
    }
554
    my $hash_ref;
555
    $hash_ref->{ 'headers' } = \@headers;
556
    $hash_ref->{ 'rows' } = \@rows;
557
558
    return $hash_ref;
559
}
560
484
output_html_with_http_headers $query, $cookie, $template->output;
561
output_html_with_http_headers $query, $cookie, $template->output;
485
562
486
563
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/basket.tt (-4 / +42 lines)
Lines 121-126 Link Here
121
            e.preventDefault();
121
            e.preventDefault();
122
            confirm_reopen();
122
            confirm_reopen();
123
        });
123
        });
124
        // Generates a dynamic link for exporting the selections data as CSV
125
        $("#exportbutton").click(function() {
126
            // Building the url from currently checked boxes
127
            var url = '/cgi-bin/koha/acqui/basket.pl';
128
            url += $('#exportbutton').attr('href');
129
            url += '&csv_profile=' + $("#csv_profile_for_export option:selected").val();
130
            // And redirecting to the CSV page
131
            location.href = url;
132
            return false;
133
        });
124
    });
134
    });
125
135
126
    function UserSearchPopup(f) {
136
    function UserSearchPopup(f) {
Lines 197-207 Link Here
197
                            <a href="/cgi-bin/koha/acqui/basket.pl?op=close&amp;basketno=[% basketno %]&amp;booksellerid=[% booksellerid %]" class="btn btn-small" id="closebutton"><i class="fa fa-times-circle"></i> Close this basket</a>
207
                            <a href="/cgi-bin/koha/acqui/basket.pl?op=close&amp;basketno=[% basketno %]&amp;booksellerid=[% booksellerid %]" class="btn btn-small" id="closebutton"><i class="fa fa-times-circle"></i> Close this basket</a>
198
                        </div>
208
                        </div>
199
                    [% END %]
209
                    [% END %]
200
                        <div class="btn-group"><a href="/cgi-bin/koha/acqui/basket.pl?op=export&amp;basketno=[% basketno %]&amp;booksellerid=[% booksellerid %]" class="btn btn-small" id="exportbutton"><i class="fa fa-download"></i> Export this basket as CSV</a></div>
210
                       <div class="btn-group">
211
                       <fieldset class="action">
212
                          <label for="csv_code">Select CSV profile:</label>
213
                          <select id="csv_profile_for_export">
214
                             <option value="default">default</option>
215
                             [% IF csv_profiles %]
216
                                [% FOR csv IN csv_profiles %]
217
                                   <option value="[% csv.export_format_id %]">[% csv.profile %]</option>
218
                                [% END %]
219
                             [% END %]
220
                          </select>
221
                       </fieldset>
222
                       </div>
223
                       <div class="btn-group"><a href="[% script_name %]?op=export&amp;basketno=[% basketno %]&amp;booksellerid=[% booksellerid %]" class="btn btn-small" id="exportbutton"><i class="fa fa-download"></i> Export as CSV</a></div>
224
201
                        [% IF ediaccount %]
225
                        [% IF ediaccount %]
202
                        <div class="btn-group"><a href="/cgi-bin/koha/acqui/edi_ean.pl?op=ediorder&amp;basketno=[% basketno %]&amp;booksellerid=[% booksellerid %]" class="btn btn-small" id="ediorderbutton"><i class="fa fa-download"></i> Create EDIFACT order</a></div>
226
                        <div class="btn-group"><a href="/cgi-bin/koha/acqui/edi_ean.pl?op=ediorder&amp;basketno=[% basketno %]&amp;booksellerid=[% booksellerid %]" class="btn btn-small" id="ediorderbutton"><i class="fa fa-download"></i> Create EDIFACT order</a></div>
203
                        [% END %]
227
                        [% END %]
204
                </div>
228
229
                   </div>
205
<!-- Modal for confirm deletion box-->
230
<!-- Modal for confirm deletion box-->
206
                <div class="modal hide" id="deleteBasketModal" tabindex="-1" role="dialog" aria-labelledby="delbasketModalLabel" aria-hidden="true">
231
                <div class="modal hide" id="deleteBasketModal" tabindex="-1" role="dialog" aria-labelledby="delbasketModalLabel" aria-hidden="true">
207
                    <div class="modal-header">
232
                    <div class="modal-header">
Lines 255-262 Link Here
255
            [% ELSE %]
280
            [% ELSE %]
256
                [% UNLESS ( grouped ) %]
281
                [% UNLESS ( grouped ) %]
257
                <div id="toolbar" class="btn-toolbar">
282
                <div id="toolbar" class="btn-toolbar">
283
258
                    <div class="btn-group"><a href="#" class="btn btn-small" id="reopenbutton"><i class="fa fa-refresh"></i> Reopen this basket</a></div>
284
                    <div class="btn-group"><a href="#" class="btn btn-small" id="reopenbutton"><i class="fa fa-refresh"></i> Reopen this basket</a></div>
259
                    <div class="btn-group"><a href="/cgi-bin/koha/acqui/basket.pl?op=export&amp;basketno=[% basketno %]&amp;booksellerid=[% booksellerid %]" class="btn btn-small" id="exportbutton"><i class="fa fa-download"></i> Export this basket as CSV</a></div>
285
                    <div class="btn-group">
286
                    <fieldset class="action">
287
                       <label for="csv_code">Select CSV profile:</label>
288
                       <select id="csv_profile_for_export">
289
                          <option value="default">default</option>
290
                          [% IF csv_profiles %]
291
                             [% FOR csv IN csv_profiles %]
292
                                <option value="[% csv.export_format_id %]">[% csv.profile %]</option>
293
                             [% END %]
294
                          [% END %]
295
                       </select>
296
                    </fieldset>
297
                    </div>
298
                    <div class="btn-group"><a href="[% script_name %]?op=export&amp;basketno=[% basketno %]&amp;booksellerid=[% booksellerid %]" class="btn btn-small" id="exportbutton"><i class="fa fa-download"></i> Export this basket as CSV</a></div>
260
                </div>
299
                </div>
261
                [% END %]
300
                [% END %]
262
            [% END %]
301
            [% END %]
263
- 

Return to bug 8612