Lines 25-39
use C4::Circulation;
Link Here
|
25 |
use DateTime; |
25 |
use DateTime; |
26 |
use Koha::DateUtils; |
26 |
use Koha::DateUtils; |
27 |
use C4::Budgets qw/GetCurrency GetCurrencies/; |
27 |
use C4::Budgets qw/GetCurrency GetCurrencies/; |
|
|
28 |
use Text::CSV::Encoded; |
28 |
#use Data::Dumper; |
29 |
#use Data::Dumper; |
29 |
#use Smart::Comments; |
30 |
#use Smart::Comments; |
30 |
|
31 |
|
31 |
my $input = new CGI; |
32 |
my $input = new CGI; |
32 |
my $dbh = C4::Context->dbh; |
33 |
my $dbh = C4::Context->dbh; |
33 |
my $fullreportname = "reports/cash_register_stats.tt"; |
|
|
34 |
|
34 |
|
35 |
my ($template, $borrowernumber, $cookie) = get_template_and_user({ |
35 |
my ($template, $borrowernumber, $cookie) = get_template_and_user({ |
36 |
template_name => $fullreportname, |
36 |
template_name => "reports/cash_register_stats.tt", |
37 |
query => $input, |
37 |
query => $input, |
38 |
type => "intranet", |
38 |
type => "intranet", |
39 |
authnotrequired => 0, |
39 |
authnotrequired => 0, |
Lines 46-53
my $output = $input->param("output");
Link Here
|
46 |
my $basename = $input->param("basename"); |
46 |
my $basename = $input->param("basename"); |
47 |
my $transaction_type = $input->param("transaction_type") || 'ACT'; |
47 |
my $transaction_type = $input->param("transaction_type") || 'ACT'; |
48 |
my $manager_branchcode = $input->param("branch") || C4::Context->userenv->{'branch'}; |
48 |
my $manager_branchcode = $input->param("branch") || C4::Context->userenv->{'branch'}; |
49 |
our $sep = $input->param("sep") // ','; |
|
|
50 |
$sep = "\t" if ($sep eq 'tabulation'); |
51 |
|
49 |
|
52 |
$template->param( |
50 |
$template->param( |
53 |
do_it => $do_it, |
51 |
do_it => $do_it, |
Lines 57-70
$template->param(
Link Here
|
57 |
#Initialize date pickers to today |
55 |
#Initialize date pickers to today |
58 |
my $fromDate = dt_from_string; |
56 |
my $fromDate = dt_from_string; |
59 |
my $toDate = dt_from_string; |
57 |
my $toDate = dt_from_string; |
60 |
### fromdate today: $fromDate |
|
|
61 |
|
58 |
|
62 |
my $query_manualinv = "SELECT id, authorised_value FROM authorised_values WHERE category = 'MANUAL_INV'"; |
59 |
my $query_manualinv = "SELECT id, authorised_value FROM authorised_values WHERE category = 'MANUAL_INV'"; |
63 |
my $sth_manualinv = $dbh->prepare($query_manualinv) or die "Unable to prepare query" . $dbh->errstr; |
60 |
my $sth_manualinv = $dbh->prepare($query_manualinv) or die "Unable to prepare query" . $dbh->errstr; |
64 |
$sth_manualinv->execute() or die "Unable to execute query " . $sth_manualinv->errstr; |
61 |
$sth_manualinv->execute() or die "Unable to execute query " . $sth_manualinv->errstr; |
65 |
my $manualinv_types = $sth_manualinv->fetchall_arrayref({}); |
62 |
my $manualinv_types = $sth_manualinv->fetchall_arrayref({}); |
66 |
|
63 |
|
67 |
### $manualinv_types |
|
|
68 |
|
64 |
|
69 |
if ($do_it) { |
65 |
if ($do_it) { |
70 |
|
66 |
|
Lines 92-98
if ($do_it) {
Link Here
|
92 |
$whereBranchCode = "AND m.branchcode = '$manager_branchcode'"; |
88 |
$whereBranchCode = "AND m.branchcode = '$manager_branchcode'"; |
93 |
} |
89 |
} |
94 |
|
90 |
|
95 |
### $transaction_type; |
|
|
96 |
|
91 |
|
97 |
my $query = " |
92 |
my $query = " |
98 |
SELECT round(amount,2) AS amount, description, |
93 |
SELECT round(amount,2) AS amount, description, |
Lines 121-127
if ($do_it) {
Link Here
|
121 |
#if ((abs($row->{amount}) - $row->{amountoutstanding}) > 0) { |
116 |
#if ((abs($row->{amount}) - $row->{amountoutstanding}) > 0) { |
122 |
$row->{amount} = sprintf("%.2f", abs ($row->{amount})); |
117 |
$row->{amount} = sprintf("%.2f", abs ($row->{amount})); |
123 |
$row->{date} = dt_from_string($row->{date}, 'sql'); |
118 |
$row->{date} = dt_from_string($row->{date}, 'sql'); |
124 |
### date : $row->{date} |
|
|
125 |
|
119 |
|
126 |
push (@loopresult, $row); |
120 |
push (@loopresult, $row); |
127 |
if($transaction_type eq 'ACT' && ($row->{accounttype} !~ /^C$|^CR$|^LR$|^Pay$/)){ |
121 |
if($transaction_type eq 'ACT' && ($row->{accounttype} !~ /^C$|^CR$|^LR$|^Pay$/)){ |
Lines 148-196
if ($do_it) {
Link Here
|
148 |
); |
142 |
); |
149 |
} else{ |
143 |
} else{ |
150 |
binmode STDOUT, ':encoding(UTF-8)'; |
144 |
binmode STDOUT, ':encoding(UTF-8)'; |
|
|
145 |
my $q_errors; |
146 |
my $format = 'csv'; |
147 |
my $reportname = $input->param('basename'); |
148 |
my $reportfilename = $reportname ? "$reportname.$format" : "reportresults.$format" ; |
149 |
#my $reportfilename = "$reportname.html" ; |
150 |
my $delimiter = C4::Context->preference('delimiter') || ','; |
151 |
my ( $type, $content ); |
152 |
if ( $format eq 'csv' ) { |
153 |
my $type = 'application/csv'; |
154 |
my $csv = Text::CSV::Encoded->new({ encoding_out => 'UTF-8', sep_char => $delimiter}); |
155 |
$csv or die "Text::CSV::Encoded->new({binary => 1}) FAILED: " . Text::CSV::Encoded->error_diag(); |
156 |
my @headers = (); |
157 |
push @headers, "mfirstname", |
158 |
"cardnumber", |
159 |
"bfirstname", |
160 |
"branchname", |
161 |
"date", |
162 |
"accounttype", |
163 |
"amount", |
164 |
"title", |
165 |
"barcode", |
166 |
"itype"; |
167 |
if ($csv->combine(@headers)) { |
168 |
$content .= Encode::decode('UTF-8', $csv->string()) . "\n"; |
169 |
} else { |
170 |
push @$q_errors, { combine => 'HEADER ROW: ' . $csv->error_diag() } ; |
171 |
} |
172 |
foreach my $row (@loopresult) { |
173 |
my @rowValues = (); |
174 |
push @rowValues, $row->{mfirstname}, |
175 |
$row->{cardnumber}, |
176 |
$row->{bfirstname}, |
177 |
$row->{branchname}, |
178 |
$row->{date}, |
179 |
$row->{accounttype}, |
180 |
$row->{amount}, |
181 |
$row->{title}, |
182 |
$row->{barcode}; |
183 |
$row->{itype}; |
184 |
if ($csv->combine(@rowValues)) { |
185 |
$content .= $csv->string() . "\n"; |
186 |
} else { |
187 |
push @$q_errors, { combine => $csv->error_diag() } ; |
188 |
} |
189 |
} |
190 |
} |
151 |
print $input->header( |
191 |
print $input->header( |
152 |
-type => 'application/vnd.sun.xml.calc', |
192 |
-type => $type, |
153 |
-encoding => 'utf-8', |
193 |
-attachment=> $reportfilename |
154 |
-name => "$basename.csv", |
|
|
155 |
-attachment => "$basename.csv" |
156 |
); |
194 |
); |
|
|
195 |
print $content; |
157 |
|
196 |
|
158 |
print "Manager name".$sep; |
197 |
print $delimiter x 6; |
159 |
print "Borrower cardnumber".$sep; |
|
|
160 |
print "Borrower name".$sep; |
161 |
print "Branch".$sep; |
162 |
print "Transaction date".$sep; |
163 |
print "Transaction type".$sep; |
164 |
print "Amount".$sep; |
165 |
print "Biblio title".$sep; |
166 |
print "Barcode".$sep; |
167 |
print "Document type"."\n"; |
168 |
|
169 |
foreach my $item (@loopresult){ |
170 |
print $item->{mfirstname}. ' ' . $item->{msurname} . $sep; |
171 |
print $item->{cardnumber}.$sep; |
172 |
print $item->{bfirstname}. ' ' . $item->{bsurname} . $sep; |
173 |
print $item->{branchname}.$sep; |
174 |
print $item->{date}.$sep; |
175 |
print $item->{accounttype}.$sep; |
176 |
print $item->{amount}.$sep; |
177 |
print $item->{title}.$sep; |
178 |
print $item->{barcode}.$sep; |
179 |
print $item->{itype}."\n"; |
180 |
} |
181 |
|
182 |
print $sep x 6; |
183 |
print $grantotal."\n"; |
198 |
print $grantotal."\n"; |
|
|
199 |
foreach my $err (@$q_errors) { |
200 |
print "# ERROR: " . (map {$_ . ": " . $err->{$_}} keys %$err) . "\n"; |
201 |
} # here we print all the non-fatal errors at the end. Not super smooth, but better than nothing. |
184 |
exit(1); |
202 |
exit(1); |
185 |
} |
203 |
} |
186 |
|
204 |
|
187 |
} |
205 |
} |
188 |
|
206 |
|
189 |
### fromdate final: $fromDate |
|
|
190 |
### toDate final: $toDate |
191 |
$template->param( |
207 |
$template->param( |
192 |
beginDate => dt_from_string($fromDate), |
208 |
beginDate => $fromDate, |
193 |
endDate => dt_from_string($toDate), |
209 |
endDate => $toDate, |
194 |
transaction_type => $transaction_type, |
210 |
transaction_type => $transaction_type, |
195 |
branchloop => C4::Branch::GetBranchesLoop($manager_branchcode), |
211 |
branchloop => C4::Branch::GetBranchesLoop($manager_branchcode), |
196 |
manualinv_types => $manualinv_types, |
212 |
manualinv_types => $manualinv_types, |
197 |
- |
|
|