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

(-)a/acqui/basket.pl (-1 / +78 lines)
Lines 35-40 use C4::Biblio; Link Here
35
use C4::Members qw/GetMember/;  #needed for permissions checking for changing basketgroup of a basket
35
use C4::Members qw/GetMember/;  #needed for permissions checking for changing basketgroup of a basket
36
use C4::Items;
36
use C4::Items;
37
use C4::Suggestions;
37
use C4::Suggestions;
38
use C4::Csv;
38
use Date::Calc qw/Add_Delta_Days/;
39
use Date::Calc qw/Add_Delta_Days/;
39
40
40
=head1 NAME
41
=head1 NAME
Lines 156-162 if ( $op eq 'delete_confirm' ) { Link Here
156
        -type       => 'text/csv',
157
        -type       => 'text/csv',
157
        -attachment => 'basket' . $basket->{'basketno'} . '.csv',
158
        -attachment => 'basket' . $basket->{'basketno'} . '.csv',
158
    );
159
    );
159
    print GetBasketAsCSV($query->param('basketno'), $query);
160
    if ( $query->param('csv_profile') eq 'default'){
161
        print GetBasketAsCSV($query->param('basketno'), $query);
162
    } else {
163
        my $csv_profile_id = $query->param('csv_profile');
164
        my $csv_profile = C4::Csv::GetCsvProfile( $csv_profile_id );
165
        die "There is no valid csv profile given" unless $csv_profile;
166
167
        my $csv = Text::CSV_XS->new({'quote_char'=>'"','escape_char'=>'"','sep_char'=>$csv_profile->{csv_separator},'binary'=>1});
168
        my $csv_profile_content = $csv_profile->{content};
169
170
        my $basket_info = get_basket_csv_profile_info($csv_profile_content, $query->param('basketno'));
171
172
        print join( $csv_profile->{csv_separator}, @{$basket_info->{headers}} ) . "\n";
173
174
        for my $row ( @{$basket_info->{rows}} ) {
175
            $csv->combine(@$row);
176
            my $string = $csv->string;
177
            print $string, "\n";
178
        }
179
    }
160
    exit;
180
    exit;
161
} elsif ($op eq 'close') {
181
} elsif ($op eq 'close') {
162
    my $confirm = $query->param('confirm') || $confirm_pref eq '2';
182
    my $confirm = $query->param('confirm') || $confirm_pref eq '2';
Lines 392-397 if ( $op eq 'delete_confirm' ) { Link Here
392
        unclosable           => @orders ? 0 : 1, 
412
        unclosable           => @orders ? 0 : 1, 
393
        has_budgets          => $has_budgets,
413
        has_budgets          => $has_budgets,
394
        duplinbatch          => $duplinbatch,
414
        duplinbatch          => $duplinbatch,
415
        csv_profiles         => C4::Csv::GetCsvProfiles( "sql" ),
395
    );
416
    );
396
}
417
}
397
418
Lines 471-474 sub get_order_infos { Link Here
471
    return \%line;
492
    return \%line;
472
}
493
}
473
494
495
sub get_basket_DB_info{
496
    my ( $basketno ) = @_;
497
    return () unless $basketno;
498
    my $dbh   = C4::Context->dbh;
499
    my $query  ="
500
    SELECT biblio.*,biblioitems.*, aqbasket.*,aqcontract.*,
501
                aqorders.*,
502
                aqbudgets.*
503
        FROM    aqorders
504
            LEFT JOIN aqbasket         ON aqorders.basketno = aqbasket.basketno
505
            LEFT JOIN aqcontract       ON aqbasket.contractnumber = aqcontract.contractnumber
506
            LEFT JOIN aqbudgets        ON aqbudgets.budget_id = aqorders.budget_id
507
            LEFT JOIN biblio           ON biblio.biblionumber = aqorders.biblionumber
508
            LEFT JOIN biblioitems      ON biblioitems.biblionumber =biblio.biblionumber
509
        WHERE   aqorders.basketno=?
510
            AND (datecancellationprinted IS NULL OR datecancellationprinted='0000-00-00')
511
            ORDER BY biblioitems.publishercode,biblio.title
512
    ";
513
    my $result_set =
514
      $dbh->selectall_arrayref( $query, { Slice => {} }, $basketno );
515
    return @{$result_set};
516
}
517
518
sub get_basket_csv_profile_info{
519
    my ($csv_profile_content,$basketno) = @_;
520
521
    my ( @headers, @fields );
522
    while ( $csv_profile_content =~ /
523
        ([^=]+) # header
524
        =
525
        ([^\|]+) # fieldname (table.row or row)
526
        \|? /gxms
527
    ) {
528
        push @headers, $1;
529
        my $field = $2;
530
        $field =~ s/[^\.]*\.?//; # Remove the table name if exists.
531
        push @fields, $field;
532
    }
533
534
    my @rows;
535
    my @basket_info = get_basket_DB_info($basketno);
536
537
    for my $basket_info ( @basket_info ) {
538
        my @row;
539
        for my $field ( @fields ) {
540
            push @row, $basket_info->{$field};
541
        }
542
        push @rows, \@row;
543
    }
544
    my $hash_ref;
545
    $hash_ref->{ 'headers' } = \@headers;
546
    $hash_ref->{ 'rows' } = \@rows;
547
548
    return $hash_ref;
549
}
550
474
output_html_with_http_headers $query, $cookie, $template->output;
551
output_html_with_http_headers $query, $cookie, $template->output;
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/basket.tt (-4 / +39 lines)
Lines 99-104 Link Here
99
            e.preventDefault();
99
            e.preventDefault();
100
            confirm_reopen();
100
            confirm_reopen();
101
        });
101
        });
102
        // Generates a dynamic link for exporting the selections data as CSV
103
        $("#exportbutton").click(function() {
104
            // Building the url from currently checked boxes
105
            var url = '/cgi-bin/koha/acqui/basket.pl';
106
            url += $('#exportbutton').attr('href');
107
            url += '&csv_profile=' + $("#csv_profile_for_export option:selected").val();
108
            // And redirecting to the CSV page
109
            location.href = url;
110
            return false;
111
        });
102
    });
112
    });
103
113
104
    function UserSearchPopup(f) {
114
    function UserSearchPopup(f) {
Lines 175-182 Link Here
175
                            <a href="[% script_name %]?op=close&amp;basketno=[% basketno %]&amp;booksellerid=[% booksellerid %]" class="btn btn-small" id="closebutton"><i class="icon-remove-sign"></i> Close this basket</a>
185
                            <a href="[% script_name %]?op=close&amp;basketno=[% basketno %]&amp;booksellerid=[% booksellerid %]" class="btn btn-small" id="closebutton"><i class="icon-remove-sign"></i> Close this basket</a>
176
                        </div>
186
                        </div>
177
                    [% END %]
187
                    [% END %]
178
                        <div class="btn-group"><a href="[% script_name %]?op=export&amp;basketno=[% basketno %]&amp;booksellerid=[% booksellerid %]" class="btn btn-small" id="exportbutton"><i class="icon-download"></i> Export this basket as CSV</a></div>
188
                       <div class="btn-group">
179
                </div>
189
                       <fieldset class="action">
190
                          <label for="csv_code">Select CSV profile:</label>
191
                          <select id="csv_profile_for_export">
192
                             <option value="default">default</option>
193
                             [% IF csv_profiles %]
194
                                [% FOR csv IN csv_profiles %]
195
                                   <option value="[% csv.export_format_id %]">[% csv.profile %]</option>
196
                                [% END %]
197
                             [% END %]
198
                          </select>
199
                       </fieldset>
200
                       </div>
201
                       <div class="btn-group"><a href="[% script_name %]?op=export&amp;basketno=[% basketno %]&amp;booksellerid=[% booksellerid %]" class="btn btn-small" id="exportbutton"><i class="icon-download"></i> Export </a></div>
202
                   </div>
180
<!-- Modal for confirm deletion box-->
203
<!-- Modal for confirm deletion box-->
181
                <div class="modal hide" id="deleteBasketModal" tabindex="-1" role="dialog" aria-labelledby="delbasketModalLabel" aria-hidden="true">
204
                <div class="modal hide" id="deleteBasketModal" tabindex="-1" role="dialog" aria-labelledby="delbasketModalLabel" aria-hidden="true">
182
                    <div class="modal-header">
205
                    <div class="modal-header">
Lines 211-217 Link Here
211
                [% UNLESS ( grouped ) %]
234
                [% UNLESS ( grouped ) %]
212
                <div id="toolbar" class="btn-toolbar">
235
                <div id="toolbar" class="btn-toolbar">
213
                    <div class="btn-group"><a href="#" class="btn btn-small" id="reopenbutton"><i class="icon-refresh"></i> Reopen this basket</a></div>
236
                    <div class="btn-group"><a href="#" class="btn btn-small" id="reopenbutton"><i class="icon-refresh"></i> Reopen this basket</a></div>
214
                    <div class="btn-group"><a href="[% script_name %]?op=export&amp;basketno=[% basketno %]&amp;booksellerid=[% booksellerid %]" class="btn btn-small" id="exportbutton"><i class="icon-download"></i> Export this basket as CSV</a></div>
237
                    <div class="btn-group">
238
                    <fieldset class="action">
239
                       <label for="csv_code">Select CSV profile:</label>
240
                       <select id="csv_profile_for_export">
241
                          <option value="default">default</option>
242
                          [% IF csv_profiles %]
243
                             [% FOR csv IN csv_profiles %]
244
                                <option value="[% csv.export_format_id %]">[% csv.profile %]</option>
245
                             [% END %]
246
                          [% END %]
247
                       </select>
248
                    </fieldset>
249
                    </div>
250
                    <div class="btn-group"><a href="[% script_name %]?op=export&amp;basketno=[% basketno %]&amp;booksellerid=[% booksellerid %]" class="btn btn-small" id="exportbutton"><i class="icon-download"></i> Export </a></div>
215
                </div>
251
                </div>
216
                [% END %]
252
                [% END %]
217
            [% END %]
253
            [% END %]
218
- 

Return to bug 8612