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 196-202 if ( $op eq 'delete_confirm' ) { Link Here
196
        -type       => 'text/csv',
197
        -type       => 'text/csv',
197
        -attachment => 'basket' . $basket->{'basketno'} . '.csv',
198
        -attachment => 'basket' . $basket->{'basketno'} . '.csv',
198
    );
199
    );
199
    print GetBasketAsCSV($query->param('basketno'), $query);
200
    if ( $query->param('csv_profile') eq 'default'){
201
        print GetBasketAsCSV($query->param('basketno'), $query);
202
    } else {
203
        my $csv_profile_id = $query->param('csv_profile');
204
        my $csv_profile = C4::Csv::GetCsvProfile( $csv_profile_id );
205
        die "There is no valid csv profile given" unless $csv_profile;
206
207
        my $csv = Text::CSV_XS->new({'quote_char'=>'"','escape_char'=>'"','sep_char'=>$csv_profile->{csv_separator},'binary'=>1});
208
        my $csv_profile_content = $csv_profile->{content};
209
210
        my $basket_info = get_basket_csv_profile_info($csv_profile_content, $query->param('basketno'));
211
212
        print join( $csv_profile->{csv_separator}, @{$basket_info->{headers}} ) . "\n";
213
214
        for my $row ( @{$basket_info->{rows}} ) {
215
            $csv->combine(@$row);
216
            my $string = $csv->string;
217
            print $string, "\n";
218
        }
219
    }
200
    exit;
220
    exit;
201
} elsif ($op eq 'close') {
221
} elsif ($op eq 'close') {
202
    my $confirm = $query->param('confirm') || $confirm_pref eq '2';
222
    my $confirm = $query->param('confirm') || $confirm_pref eq '2';
Lines 431-436 if ( $op eq 'delete_confirm' ) { Link Here
431
        grouped              => $basket->{basketgroupid},
451
        grouped              => $basket->{basketgroupid},
432
        unclosable           => @orders ? 0 : 1, 
452
        unclosable           => @orders ? 0 : 1, 
433
        has_budgets          => $has_budgets,
453
        has_budgets          => $has_budgets,
454
        csv_profiles         => C4::Csv::GetCsvProfiles( "sql" ),
434
    );
455
    );
435
}
456
}
436
457
Lines 510-513 sub get_order_infos { Link Here
510
    return \%line;
531
    return \%line;
511
}
532
}
512
533
534
sub get_basket_DB_info{
535
    my ( $basketno ) = @_;
536
    return () unless $basketno;
537
    my $dbh   = C4::Context->dbh;
538
    my $query  ="
539
    SELECT biblio.*,biblioitems.*, aqbasket.*,aqcontract.*,
540
                aqorders.*,
541
                aqbudgets.*
542
        FROM    aqorders
543
            LEFT JOIN aqbasket         ON aqorders.basketno = aqbasket.basketno
544
            LEFT JOIN aqcontract       ON aqbasket.contractnumber = aqcontract.contractnumber
545
            LEFT JOIN aqbudgets        ON aqbudgets.budget_id = aqorders.budget_id
546
            LEFT JOIN biblio           ON biblio.biblionumber = aqorders.biblionumber
547
            LEFT JOIN biblioitems      ON biblioitems.biblionumber =biblio.biblionumber
548
        WHERE   aqorders.basketno=?
549
            AND (datecancellationprinted IS NULL OR datecancellationprinted='0000-00-00')
550
            ORDER BY biblioitems.publishercode,biblio.title
551
    ";
552
    my $result_set =
553
      $dbh->selectall_arrayref( $query, { Slice => {} }, $basketno );
554
    return @{$result_set};
555
}
556
557
sub get_basket_csv_profile_info{
558
    my ($csv_profile_content,$basketno) = @_;
559
560
    my ( @headers, @fields );
561
    while ( $csv_profile_content =~ /
562
        ([^=]+) # header
563
        =
564
        ([^\|]+) # fieldname (table.row or row)
565
        \|? /gxms
566
    ) {
567
        push @headers, $1;
568
        my $field = $2;
569
        $field =~ s/[^\.]*\.?//; # Remove the table name if exists.
570
        push @fields, $field;
571
    }
572
573
    my @rows;
574
    my @basket_info = get_basket_DB_info($basketno);
575
576
    for my $basket_info ( @basket_info ) {
577
        my @row;
578
        for my $field ( @fields ) {
579
            push @row, $basket_info->{$field};
580
        }
581
        push @rows, \@row;
582
    }
583
    my $hash_ref;
584
    $hash_ref->{ 'headers' } = \@headers;
585
    $hash_ref->{ 'rows' } = \@rows;
586
587
    return $hash_ref;
588
}
589
513
output_html_with_http_headers $query, $cookie, $template->output;
590
output_html_with_http_headers $query, $cookie, $template->output;
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/basket.tt (-4 / +39 lines)
Lines 105-110 Link Here
105
            e.preventDefault();
105
            e.preventDefault();
106
            confirm_reopen();
106
            confirm_reopen();
107
        });
107
        });
108
        // Generates a dynamic link for exporting the selections data as CSV
109
        $("#exportbutton").click(function() {
110
            // Building the url from currently checked boxes
111
            var url = '/cgi-bin/koha/acqui/basket.pl';
112
            url += $('#exportbutton').attr('href');
113
            url += '&csv_profile=' + $("#csv_profile_for_export option:selected").val();
114
            // And redirecting to the CSV page
115
            location.href = url;
116
            return false;
117
        });
108
    });
118
    });
109
119
110
    function UserSearchPopup(f) {
120
    function UserSearchPopup(f) {
Lines 178-185 Link Here
178
                            <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>
188
                            <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>
179
                        </div>
189
                        </div>
180
                    [% END %]
190
                    [% END %]
181
                        <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>
191
                       <div class="btn-group">
182
                </div>
192
                       <fieldset class="action">
193
                          <label for="csv_code">Select CSV profile:</label>
194
                          <select id="csv_profile_for_export">
195
                             <option value="default">default</option>
196
                             [% IF csv_profiles %]
197
                                [% FOR csv IN csv_profiles %]
198
                                   <option value="[% csv.export_format_id %]">[% csv.profile %]</option>
199
                                [% END %]
200
                             [% END %]
201
                          </select>
202
                       </fieldset>
203
                       </div>
204
                       <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>
205
                   </div>
183
<!-- Modal for confirm deletion box-->
206
<!-- Modal for confirm deletion box-->
184
                <div class="modal hide" id="deleteBasketModal" tabindex="-1" role="dialog" aria-labelledby="delbasketModalLabel" aria-hidden="true">
207
                <div class="modal hide" id="deleteBasketModal" tabindex="-1" role="dialog" aria-labelledby="delbasketModalLabel" aria-hidden="true">
185
                    <div class="modal-header">
208
                    <div class="modal-header">
Lines 214-220 Link Here
214
                [% UNLESS ( grouped ) %]
237
                [% UNLESS ( grouped ) %]
215
                <div id="toolbar" class="btn-toolbar">
238
                <div id="toolbar" class="btn-toolbar">
216
                    <div class="btn-group"><a href="#" class="btn btn-small" id="reopenbutton"><i class="icon-refresh"></i> Reopen this basket</a></div>
239
                    <div class="btn-group"><a href="#" class="btn btn-small" id="reopenbutton"><i class="icon-refresh"></i> Reopen this basket</a></div>
217
                    <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>
240
                    <div class="btn-group">
241
                    <fieldset class="action">
242
                       <label for="csv_code">Select CSV profile:</label>
243
                       <select id="csv_profile_for_export">
244
                          <option value="default">default</option>
245
                          [% IF csv_profiles %]
246
                             [% FOR csv IN csv_profiles %]
247
                                <option value="[% csv.export_format_id %]">[% csv.profile %]</option>
248
                             [% END %]
249
                          [% END %]
250
                       </select>
251
                    </fieldset>
252
                    </div>
253
                    <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>
218
                </div>
254
                </div>
219
                [% END %]
255
                [% END %]
220
            [% END %]
256
            [% END %]
221
- 

Return to bug 8612