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 (-3 / +25 lines)
Lines 103-108 Link Here
103
            e.preventDefault();
103
            e.preventDefault();
104
            confirm_reopen();
104
            confirm_reopen();
105
        });
105
        });
106
        // Generates a dynamic link for exporting the selections data as CSV
107
        $("#exportbutton").click(function() {
108
            // Building the url from currently checked boxes
109
            var url = '/cgi-bin/koha/acqui/basket.pl';
110
            url += $('#exportbutton').attr('href');
111
            url += '&csv_profile=' + $("#csv_profile_for_export option:selected").val();
112
            // And redirecting to the CSV page
113
            location.href = url;
114
            return false;
115
        });
106
    });
116
    });
107
117
108
    function UserSearchPopup(f) {
118
    function UserSearchPopup(f) {
Lines 176-183 Link Here
176
                            <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>
186
                            <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>
177
                        </div>
187
                        </div>
178
                    [% END %]
188
                    [% END %]
179
                        <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>
189
                       <div class="btn-group">
180
                </div>
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="icon-download"></i> Export </a></div></a></div>
203
                   </div>
181
<!-- Modal for confirm deletion box-->
204
<!-- Modal for confirm deletion box-->
182
                <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">
183
                    <div class="modal-header">
206
                    <div class="modal-header">
184
- 

Return to bug 8612