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 469-472 sub get_order_infos { Link Here
469
    return \%line;
490
    return \%line;
470
}
491
}
471
492
493
sub get_basket_DB_info{
494
    my ( $basketno ) = @_;
495
    return () unless $basketno;
496
    my $dbh   = C4::Context->dbh;
497
    my $query  ="
498
    SELECT biblio.*,biblioitems.*, aqbasket.*,aqcontract.*,
499
                aqorders.*,
500
                aqbudgets.*
501
        FROM    aqorders
502
            LEFT JOIN aqbasket         ON aqorders.basketno = aqbasket.basketno
503
            LEFT JOIN aqcontract       ON aqbasket.contractnumber = aqcontract.contractnumber
504
            LEFT JOIN aqbudgets        ON aqbudgets.budget_id = aqorders.budget_id
505
            LEFT JOIN biblio           ON biblio.biblionumber = aqorders.biblionumber
506
            LEFT JOIN biblioitems      ON biblioitems.biblionumber =biblio.biblionumber
507
        WHERE   aqorders.basketno=?
508
            AND (datecancellationprinted IS NULL OR datecancellationprinted='0000-00-00')
509
            ORDER BY biblioitems.publishercode,biblio.title
510
    ";
511
    my $result_set =
512
      $dbh->selectall_arrayref( $query, { Slice => {} }, $basketno );
513
    return @{$result_set};
514
}
515
516
sub get_basket_csv_profile_info{
517
    my ($csv_profile_content,$basketno) = @_;
518
519
    my ( @headers, @fields );
520
    while ( $csv_profile_content =~ /
521
        ([^=]+) # header
522
        =
523
        ([^\|]+) # fieldname (table.row or row)
524
        \|? /gxms
525
    ) {
526
        push @headers, $1;
527
        my $field = $2;
528
        $field =~ s/[^\.]*\.?//; # Remove the table name if exists.
529
        push @fields, $field;
530
    }
531
532
    my @rows;
533
    my @basket_info = get_basket_DB_info($basketno);
534
535
    for my $basket_info ( @basket_info ) {
536
        my @row;
537
        for my $field ( @fields ) {
538
            push @row, $basket_info->{$field};
539
        }
540
        push @rows, \@row;
541
    }
542
    my $hash_ref;
543
    $hash_ref->{ 'headers' } = \@headers;
544
    $hash_ref->{ 'rows' } = \@rows;
545
546
    return $hash_ref;
547
}
548
472
output_html_with_http_headers $query, $cookie, $template->output;
549
output_html_with_http_headers $query, $cookie, $template->output;
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/basket.tt (-3 / +40 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="fa fa-times-circle"></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="fa fa-times-circle"></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="fa fa-download"></i> Export this basket as CSV</a></div>
188
179
                </div>
189
                       <div class="btn-group">
190
                       <fieldset class="action">
191
                          <label for="csv_code">Select CSV profile:</label>
192
                          <select id="csv_profile_for_export">
193
                             <option value="default">default</option>
194
                             [% IF csv_profiles %]
195
                                [% FOR csv IN csv_profiles %]
196
                                   <option value="[% csv.export_format_id %]">[% csv.profile %]</option>
197
                                [% END %]
198
                             [% END %]
199
                          </select>
200
                       </fieldset>
201
                       </div>
202
                       <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 </a></div>
203
                   </div>
180
<!-- Modal for confirm deletion box-->
204
<!-- Modal for confirm deletion box-->
181
                <div class="modal hide" id="deleteBasketModal" tabindex="-1" role="dialog" aria-labelledby="delbasketModalLabel" aria-hidden="true">
205
                <div class="modal hide" id="deleteBasketModal" tabindex="-1" role="dialog" aria-labelledby="delbasketModalLabel" aria-hidden="true">
182
                    <div class="modal-header">
206
                    <div class="modal-header">
Lines 210-216 Link Here
210
            [% ELSE %]
234
            [% ELSE %]
211
                [% UNLESS ( grouped ) %]
235
                [% UNLESS ( grouped ) %]
212
                <div id="toolbar" class="btn-toolbar">
236
                <div id="toolbar" class="btn-toolbar">
237
213
                    <div class="btn-group"><a href="#" class="btn btn-small" id="reopenbutton"><i class="fa fa-refresh"></i> Reopen this basket</a></div>
238
                    <div class="btn-group"><a href="#" class="btn btn-small" id="reopenbutton"><i class="fa fa-refresh"></i> Reopen this basket</a></div>
239
                    <div class="btn-group">
240
                    <fieldset class="action">
241
                       <label for="csv_code">Select CSV profile:</label>
242
                       <select id="csv_profile_for_export">
243
                          <option value="default">default</option>
244
                          [% IF csv_profiles %]
245
                             [% FOR csv IN csv_profiles %]
246
                                <option value="[% csv.export_format_id %]">[% csv.profile %]</option>
247
                             [% END %]
248
                          [% END %]
249
                       </select>
250
                    </fieldset>
251
                    </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="fa fa-download"></i> Export this basket as CSV</a></div>
252
                    <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>
215
                </div>
253
                </div>
216
                [% END %]
254
                [% END %]
217
- 

Return to bug 8612