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

(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/csv_headers/reports/cash_register_stats.tt (+1 lines)
Line 0 Link Here
1
mfirstname[% sep %]cardnumber[% sep %]bfirstname[% sep %]branchname[% sep %]date[% sep %]accounttype[% sep %]amount[% sep %]title[% sep %]barcode[% sep %]"itype"
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/reports/csv/cash_register_stats.tt (+14 lines)
Line 0 Link Here
1
[% USE ItemTypes %]
2
[% INCLUDE csv_headers/reports/cash_register_stats.tt %]
3
[%- FOREACH row IN rows %]
4
    [%- FOREACH field IN row;
5
       field IF !loop.last;
6
       ItemTypes.GetDescription(field) IF loop.last;
7
       sep IF !loop.last;
8
    END %]
9
[% END -%]
10
TOTAL
11
[%- FOREACH field IN total;
12
    field;
13
    sep IF !loop.last;
14
END %]
(-)a/reports/cash_register_stats.pl (-38 / +14 lines)
Lines 137-143 if ($do_it) { Link Here
137
            total => $grantotal,
137
            total => $grantotal,
138
        );
138
        );
139
    } else{
139
    } else{
140
        binmode STDOUT, ':encoding(UTF-8)';
141
        my $q_errors;
140
        my $q_errors;
142
        my $format = 'csv';
141
        my $format = 'csv';
143
        my $reportname = $input->param('basename');
142
        my $reportname = $input->param('basename');
Lines 145-171 if ($do_it) { Link Here
145
        #my $reportfilename = "$reportname.html" ;
144
        #my $reportfilename = "$reportname.html" ;
146
        my $delimiter = C4::Context->preference('delimiter') || ',';
145
        my $delimiter = C4::Context->preference('delimiter') || ',';
147
        my ( $content );
146
        my ( $content );
148
        if ( $format eq 'csv' ) {
147
            my @rows;
149
            my $csv = Text::CSV::Encoded->new({ encoding_out => 'UTF-8', sep_char => $delimiter});
150
            $csv or die "Text::CSV::Encoded->new({binary => 1}) FAILED: " . Text::CSV::Encoded->error_diag();
151
            my @headers = ();
152
            push @headers, "mfirstname",
153
                        "cardnumber",
154
                        "bfirstname",
155
                        "branchname",
156
                        "date",
157
                        "accounttype",
158
                        "amount",
159
                        "title",
160
                        "barcode",
161
                        "itype";
162
            if ($csv->combine(@headers)) {
163
                $content .= Encode::decode('UTF-8', $csv->string()) . "\n";
164
            } else {
165
                push @$q_errors, { combine => 'HEADER ROW: ' . $csv->error_diag() } ;
166
            }
167
            foreach my $row (@loopresult) {
148
            foreach my $row (@loopresult) {
168
                my @rowValues = ();
149
                my @rowValues;
169
                push @rowValues, $row->{mfirstname},
150
                push @rowValues, $row->{mfirstname},
170
                        $row->{cardnumber},
151
                        $row->{cardnumber},
171
                        $row->{bfirstname},
152
                        $row->{bfirstname},
Lines 176-199 if ($do_it) { Link Here
176
                        $row->{title},
157
                        $row->{title},
177
                        $row->{barcode},
158
                        $row->{barcode},
178
                        $row->{itype};
159
                        $row->{itype};
179
                if ($csv->combine(@rowValues)) {
160
                    push (@rows, \@rowValues) ;
180
                    $content .= Encode::decode('UTF-8',$csv->string()) . "\n";
181
                } else {
182
                    push @$q_errors, { combine => $csv->error_diag() } ;
183
                }
161
                }
184
            }
162
                my @total;
185
        }
163
                for (1..6){push(@total,"")};
164
                push(@total, $grantotal);
186
        print $input->header(
165
        print $input->header(
187
            -type => 'text/csv',
166
            -type       => 'text/csv',
188
            -attachment=> $reportfilename
167
            -encoding    => 'utf-8',
189
        );
168
            -attachment => $reportfilename,
190
        print $content;
169
            -name       => $reportfilename
191
170
         );
192
        print $delimiter x 6;
171
        my $csvTemplate = C4::Templates::gettemplate('reports/csv/cash_register_stats.tt', 'intranet', $input);
193
        print $grantotal."\n";
172
            $csvTemplate->param(sep => $delimiter, rows => \@rows, total => \@total );
194
        foreach my $err (@$q_errors) {
173
        print $csvTemplate->output;
195
            print "# ERROR: " . (map {$_ . ": " . $err->{$_}} keys %$err) . "\n";
196
        }   # here we print all the non-fatal errors at the end.  Not super smooth, but better than nothing.
197
        exit(1);
174
        exit(1);
198
    }
175
    }
199
176
200
- 

Return to bug 6934