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::Libraries;
37
use Koha::Libraries;
37
use C4::Letters qw/SendAlerts/;
38
use C4::Letters qw/SendAlerts/;
38
use Date::Calc qw/Add_Delta_Days/;
39
use Date::Calc qw/Add_Delta_Days/;
Lines 162-168 if ( $op eq 'delete_confirm' ) { Link Here
162
        -type       => 'text/csv',
163
        -type       => 'text/csv',
163
        -attachment => 'basket' . $basket->{'basketno'} . '.csv',
164
        -attachment => 'basket' . $basket->{'basketno'} . '.csv',
164
    );
165
    );
165
    print GetBasketAsCSV($query->param('basketno'), $query);
166
    if ( $query->param('csv_profile') eq 'default'){
167
        print GetBasketAsCSV($query->param('basketno'), $query);
168
    } else {
169
        my $csv_profile_id = $query->param('csv_profile');
170
        my $csv_profile = C4::Csv::GetCsvProfile( $csv_profile_id );
171
        die "There is no valid csv profile given" unless $csv_profile;
172
173
        my $csv = Text::CSV_XS->new({'quote_char'=>'"','escape_char'=>'"','sep_char'=>$csv_profile->{csv_separator},'binary'=>1});
174
        my $csv_profile_content = $csv_profile->{content};
175
176
        my $basket_info = get_basket_csv_profile_info($csv_profile_content, $query->param('basketno'));
177
178
        print join( $csv_profile->{csv_separator}, @{$basket_info->{headers}} ) . "\n";
179
180
        for my $row ( @{$basket_info->{rows}} ) {
181
            $csv->combine(@$row);
182
            my $string = $csv->string;
183
            print $string, "\n";
184
        }
185
    }
166
    exit;
186
    exit;
167
} elsif ($op eq 'email') {
187
} elsif ($op eq 'email') {
168
    my $err = eval {
188
    my $err = eval {
Lines 418-423 if ( $op eq 'list' ) { Link Here
418
        unclosable           => @orders ? $basket->{is_standing} : 1,
438
        unclosable           => @orders ? $basket->{is_standing} : 1,
419
        has_budgets          => $has_budgets,
439
        has_budgets          => $has_budgets,
420
        duplinbatch          => $duplinbatch,
440
        duplinbatch          => $duplinbatch,
441
        csv_profiles         => C4::Csv::GetCsvProfiles( "sql" ),
421
    );
442
    );
422
}
443
}
423
444
Lines 504-509 sub get_order_infos { Link Here
504
    return \%line;
525
    return \%line;
505
}
526
}
506
527
528
sub get_basket_DB_info{
529
    my ( $basketno ) = @_;
530
    return () unless $basketno;
531
    my $dbh   = C4::Context->dbh;
532
    my $query  ="
533
    SELECT biblio.*,biblioitems.*, aqbasket.*,aqcontract.*,
534
                aqorders.*,
535
                aqbudgets.*
536
        FROM    aqorders
537
            LEFT JOIN aqbasket         ON aqorders.basketno = aqbasket.basketno
538
            LEFT JOIN aqcontract       ON aqbasket.contractnumber = aqcontract.contractnumber
539
            LEFT JOIN aqbudgets        ON aqbudgets.budget_id = aqorders.budget_id
540
            LEFT JOIN biblio           ON biblio.biblionumber = aqorders.biblionumber
541
            LEFT JOIN biblioitems      ON biblioitems.biblionumber =biblio.biblionumber
542
        WHERE   aqorders.basketno=?
543
            AND (datecancellationprinted IS NULL OR datecancellationprinted='0000-00-00')
544
            ORDER BY biblioitems.publishercode,biblio.title
545
    ";
546
    my $result_set =
547
      $dbh->selectall_arrayref( $query, { Slice => {} }, $basketno );
548
    return @{$result_set};
549
}
550
551
sub get_basket_csv_profile_info{
552
    my ($csv_profile_content,$basketno) = @_;
553
554
    my ( @headers, @fields );
555
    while ( $csv_profile_content =~ /
556
        ([^=]+) # header
557
        =
558
        ([^\|]+) # fieldname (table.row or row)
559
        \|? /gxms
560
    ) {
561
        push @headers, $1;
562
        my $field = $2;
563
        $field =~ s/[^\.]*\.?//; # Remove the table name if exists.
564
        push @fields, $field;
565
    }
566
567
    my @rows;
568
    my @basket_info = get_basket_DB_info($basketno);
569
570
    for my $basket_info ( @basket_info ) {
571
        my @row;
572
        for my $field ( @fields ) {
573
            push @row, $basket_info->{$field};
574
        }
575
        push @rows, \@row;
576
    }
577
    my $hash_ref;
578
    $hash_ref->{ 'headers' } = \@headers;
579
    $hash_ref->{ 'rows' } = \@rows;
580
581
    return $hash_ref;
582
}
583
507
sub edi_close_and_order {
584
sub edi_close_and_order {
508
    my $confirm = $query->param('confirm') || $confirm_pref eq '2';
585
    my $confirm = $query->param('confirm') || $confirm_pref eq '2';
509
    if ($confirm) {
586
    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-small" 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-small" 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-small" 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-small" 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-small" 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-small" 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 hide" id="deleteBasketModal" tabindex="-1" role="dialog" aria-labelledby="delbasketModalLabel" aria-hidden="true">
241
                <div class="modal hide" id="deleteBasketModal" tabindex="-1" role="dialog" aria-labelledby="delbasketModalLabel" aria-hidden="true">
216
                    <div class="modal-header">
242
                    <div class="modal-header">
Lines 264-271 Link Here
264
            [% ELSE %]
290
            [% ELSE %]
265
                [% UNLESS ( grouped ) %]
291
                [% UNLESS ( grouped ) %]
266
                <div id="toolbar" class="btn-toolbar">
292
                <div id="toolbar" class="btn-toolbar">
293
267
                    <div class="btn-group"><a href="#" class="btn btn-small" id="reopenbutton"><i class="fa fa-refresh"></i> Reopen this basket</a></div>
294
                    <div class="btn-group"><a href="#" class="btn btn-small" id="reopenbutton"><i class="fa fa-refresh"></i> Reopen this basket</a></div>
268
                    <div class="btn-group"><a href="/cgi-bin/koha/acqui/basket.pl?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>
295
                    <div class="btn-group">
296
                    <fieldset class="action">
297
                       <label for="csv_code">Select CSV profile:</label>
298
                       <select id="csv_profile_for_export">
299
                          <option value="default">default</option>
300
                          [% IF csv_profiles %]
301
                             [% FOR csv IN csv_profiles %]
302
                                <option value="[% csv.export_format_id %]">[% csv.profile %]</option>
303
                             [% END %]
304
                          [% END %]
305
                       </select>
306
                    </fieldset>
307
                    </div>
308
                    <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>
269
                </div>
309
                </div>
270
                [% END %]
310
                [% END %]
271
            [% END %]
311
            [% END %]
272
- 

Return to bug 8612