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

(-)a/acqui/basket.pl (-1 / +78 lines)
Lines 33-38 use C4::Biblio; Link Here
33
use C4::Members qw/GetMember/;  #needed for permissions checking for changing basketgroup of a basket
33
use C4::Members qw/GetMember/;  #needed for permissions checking for changing basketgroup of a basket
34
use C4::Items;
34
use C4::Items;
35
use C4::Suggestions;
35
use C4::Suggestions;
36
use C4::Csv;
36
use Koha::Biblios;
37
use Koha::Biblios;
37
use Koha::Acquisition::Booksellers;
38
use Koha::Acquisition::Booksellers;
38
use Koha::Libraries;
39
use Koha::Libraries;
Lines 164-170 if ( $op eq 'delete_confirm' ) { Link Here
164
        -type       => 'text/csv',
165
        -type       => 'text/csv',
165
        -attachment => 'basket' . $basket->{'basketno'} . '.csv',
166
        -attachment => 'basket' . $basket->{'basketno'} . '.csv',
166
    );
167
    );
167
    print GetBasketAsCSV($query->param('basketno'), $query);
168
    if ( $query->param('csv_profile') eq 'default'){
169
        print GetBasketAsCSV($query->param('basketno'), $query);
170
    } else {
171
        my $csv_profile_id = $query->param('csv_profile');
172
        my $csv_profile = C4::Csv::GetCsvProfile( $csv_profile_id );
173
        die "There is no valid csv profile given" unless $csv_profile;
174
175
        my $csv = Text::CSV_XS->new({'quote_char'=>'"','escape_char'=>'"','sep_char'=>$csv_profile->{csv_separator},'binary'=>1});
176
        my $csv_profile_content = $csv_profile->{content};
177
178
        my $basket_info = get_basket_csv_profile_info($csv_profile_content, $query->param('basketno'));
179
180
        print join( $csv_profile->{csv_separator}, @{$basket_info->{headers}} ) . "\n";
181
182
        for my $row ( @{$basket_info->{rows}} ) {
183
            $csv->combine(@$row);
184
            my $string = $csv->string;
185
            print $string, "\n";
186
        }
187
    }
168
    exit;
188
    exit;
169
} elsif ($op eq 'email') {
189
} elsif ($op eq 'email') {
170
    my $err = eval {
190
    my $err = eval {
Lines 420-425 if ( $op eq 'list' ) { Link Here
420
        unclosable           => @orders ? $basket->{is_standing} : 1,
440
        unclosable           => @orders ? $basket->{is_standing} : 1,
421
        has_budgets          => $has_budgets,
441
        has_budgets          => $has_budgets,
422
        duplinbatch          => $duplinbatch,
442
        duplinbatch          => $duplinbatch,
443
        csv_profiles         => C4::Csv::GetCsvProfiles( "sql" ),
423
    );
444
    );
424
}
445
}
425
446
Lines 507-512 sub get_order_infos { Link Here
507
    return \%line;
528
    return \%line;
508
}
529
}
509
530
531
sub get_basket_DB_info{
532
    my ( $basketno ) = @_;
533
    return () unless $basketno;
534
    my $dbh   = C4::Context->dbh;
535
    my $query  ="
536
    SELECT biblio.*,biblioitems.*, aqbasket.*,aqcontract.*,
537
                aqorders.*,
538
                aqbudgets.*
539
        FROM    aqorders
540
            LEFT JOIN aqbasket         ON aqorders.basketno = aqbasket.basketno
541
            LEFT JOIN aqcontract       ON aqbasket.contractnumber = aqcontract.contractnumber
542
            LEFT JOIN aqbudgets        ON aqbudgets.budget_id = aqorders.budget_id
543
            LEFT JOIN biblio           ON biblio.biblionumber = aqorders.biblionumber
544
            LEFT JOIN biblioitems      ON biblioitems.biblionumber =biblio.biblionumber
545
        WHERE   aqorders.basketno=?
546
            AND (datecancellationprinted IS NULL OR datecancellationprinted='0000-00-00')
547
            ORDER BY biblioitems.publishercode,biblio.title
548
    ";
549
    my $result_set =
550
      $dbh->selectall_arrayref( $query, { Slice => {} }, $basketno );
551
    return @{$result_set};
552
}
553
554
sub get_basket_csv_profile_info{
555
    my ($csv_profile_content,$basketno) = @_;
556
557
    my ( @headers, @fields );
558
    while ( $csv_profile_content =~ /
559
        ([^=]+) # header
560
        =
561
        ([^\|]+) # fieldname (table.row or row)
562
        \|? /gxms
563
    ) {
564
        push @headers, $1;
565
        my $field = $2;
566
        $field =~ s/[^\.]*\.?//; # Remove the table name if exists.
567
        push @fields, $field;
568
    }
569
570
    my @rows;
571
    my @basket_info = get_basket_DB_info($basketno);
572
573
    for my $basket_info ( @basket_info ) {
574
        my @row;
575
        for my $field ( @fields ) {
576
            push @row, $basket_info->{$field};
577
        }
578
        push @rows, \@row;
579
    }
580
    my $hash_ref;
581
    $hash_ref->{ 'headers' } = \@headers;
582
    $hash_ref->{ 'rows' } = \@rows;
583
584
    return $hash_ref;
585
}
586
510
sub edi_close_and_order {
587
sub edi_close_and_order {
511
    my $confirm = $query->param('confirm') || $confirm_pref eq '2';
588
    my $confirm = $query->param('confirm') || $confirm_pref eq '2';
512
    if ($confirm) {
589
    if ($confirm) {
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/basket.tt (-3 / +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-206 Link Here
197
                            <a href="/cgi-bin/koha/acqui/basket.pl?op=close&amp;basketno=[% basketno %]&amp;booksellerid=[% booksellerid %]" class="btn btn-default btn-sm" 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-default btn-sm" 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-default btn-sm" 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-default btn-sm" 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-default btn-sm" 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-default btn-sm" id="ediorderbutton"><i class="fa fa-download"></i> Create EDIFACT order</a></div>
203
                        [% END %]
227
                        [% END %]
228
204
                        [% IF ( active && books_loop ) %]
229
                        [% IF ( active && books_loop ) %]
205
                            <div class="btn-group">
230
                            <div class="btn-group">
206
                                <form action="/cgi-bin/koha/acqui/basket.pl" method="post">
231
                                <form action="/cgi-bin/koha/acqui/basket.pl" method="post">
Lines 211-216 Link Here
211
                            </div>
236
                            </div>
212
                        [% END %]
237
                        [% END %]
213
                </div>
238
                </div>
239
214
<!-- Modal for confirm deletion box-->
240
<!-- Modal for confirm deletion box-->
215
                <div class="modal" id="deleteBasketModal" tabindex="-1" role="dialog" aria-labelledby="delbasketModalLabel" aria-hidden="true">
241
                <div class="modal" id="deleteBasketModal" tabindex="-1" role="dialog" aria-labelledby="delbasketModalLabel" aria-hidden="true">
216
                    <div class="modal-dialog">
242
                    <div class="modal-dialog">
Lines 268-275 Link Here
268
            [% ELSE %]
294
            [% ELSE %]
269
                [% UNLESS ( grouped ) %]
295
                [% UNLESS ( grouped ) %]
270
                <div id="toolbar" class="btn-toolbar">
296
                <div id="toolbar" class="btn-toolbar">
297
271
                    <div class="btn-group"><a href="#" class="btn btn-default btn-sm" id="reopenbutton"><i class="fa fa-refresh"></i> Reopen this basket</a></div>
298
                    <div class="btn-group"><a href="#" class="btn btn-default btn-sm" id="reopenbutton"><i class="fa fa-refresh"></i> Reopen this basket</a></div>
272
                    <div class="btn-group"><a href="/cgi-bin/koha/acqui/basket.pl?op=export&amp;basketno=[% basketno %]&amp;booksellerid=[% booksellerid %]" class="btn btn-default btn-sm" id="exportbutton"><i class="fa fa-download"></i> Export this basket as CSV</a></div>
299
                    <div class="btn-group">
300
                    <fieldset class="action">
301
                       <label for="csv_code">Select CSV profile:</label>
302
                       <select id="csv_profile_for_export">
303
                          <option value="default">default</option>
304
                          [% IF csv_profiles %]
305
                             [% FOR csv IN csv_profiles %]
306
                                <option value="[% csv.export_format_id %]">[% csv.profile %]</option>
307
                             [% END %]
308
                          [% END %]
309
                       </select>
310
                    </fieldset>
311
                    </div>
312
                    <div class="btn-group"><a href="[% script_name %]?op=export&amp;basketno=[% basketno %]&amp;booksellerid=[% booksellerid %]" class="btn btn-default btn-sm" id="exportbutton"><i class="fa fa-download"></i> Export this basket as CSV</a></div>
273
                </div>
313
                </div>
274
                [% END %]
314
                [% END %]
275
            [% END %]
315
            [% END %]
276
- 

Return to bug 8612