Lines 74-80
if ( $get_orders ) {
Link Here
|
74 |
else { |
74 |
else { |
75 |
if ($budgetfilter eq 'activebudgets') { |
75 |
if ($budgetfilter eq 'activebudgets') { |
76 |
# If all active budgets's option was selected, get the orders of all active budgets |
76 |
# If all active budgets's option was selected, get the orders of all active budgets |
77 |
my @active_budgets = C4::Budgets::GetActiveBudgetsReport(); |
77 |
my @active_budgets = C4::Budgets::GetBudgetsReport(1); |
78 |
foreach my $active_budget (@active_budgets) |
78 |
foreach my $active_budget (@active_budgets) |
79 |
{ |
79 |
{ |
80 |
push(@orders, $active_budget); |
80 |
push(@orders, $active_budget); |
Lines 142-157
if ( $get_orders ) {
Link Here
|
142 |
else { |
142 |
else { |
143 |
my $basename = $params->{"basename"}; |
143 |
my $basename = $params->{"basename"}; |
144 |
my $sep = $params->{"sep"}; |
144 |
my $sep = $params->{"sep"}; |
145 |
$sep = "\t" if ($sep == 'tabulation'); |
145 |
$sep = "\t" if ($sep eq 'tabulation'); |
146 |
|
146 |
|
147 |
print $query->header( |
147 |
print $query->header( |
148 |
-type => 'application/vnd.sun.xml.calc', |
148 |
-type => 'application/vnd.sun.xml.calc', |
149 |
-encoding => 'utf-8', |
149 |
-encoding => 'utf-8', |
150 |
-attachment => "$basename.csv", |
150 |
-attachment => "$basename.csv", |
151 |
-name => "$basename.csv" |
151 |
-name => "$basename.csv" |
152 |
); |
152 |
); |
153 |
|
153 |
|
154 |
binmode STDOUT, ":encoding(UTF-8)"; |
154 |
#binmode STDOUT, ":encoding(UTF-8)"; |
155 |
|
155 |
|
156 |
# Surrounds a string with double-quotes and escape the double-quotes inside |
156 |
# Surrounds a string with double-quotes and escape the double-quotes inside |
157 |
sub _surround { |
157 |
sub _surround { |
Lines 159-225
if ( $get_orders ) {
Link Here
|
159 |
$string =~ s/"/""/g; |
159 |
$string =~ s/"/""/g; |
160 |
return "\"$string\""; |
160 |
return "\"$string\""; |
161 |
} |
161 |
} |
162 |
|
162 |
my @rows; |
163 |
# Create the CSV file |
|
|
164 |
print '"Budget"' . $sep; |
165 |
print '"Basket"' . $sep; |
166 |
print '"Basket by"' . $sep; |
167 |
print '"biblionumber"' . $sep; |
168 |
print '"Title"' . $sep; |
169 |
print '"Currency"' . $sep; |
170 |
print '"Vendor Price"' . $sep; |
171 |
print '"RRP"' . $sep; |
172 |
print '"Budgeted cost"' . $sep; |
173 |
print '"Quantity"' . $sep; |
174 |
print '"Total RRP"' . $sep; |
175 |
print '"Total cost"' . $sep; |
176 |
print '"Entry date"' . $sep; |
177 |
print '"Date received"' . $sep; |
178 |
print '"Notes"' . "\n"; |
179 |
|
180 |
foreach my $order (@orders) { |
163 |
foreach my $order (@orders) { |
181 |
print _surround($order->{'budget_name'}) . $sep; |
164 |
my @row; |
182 |
print _surround($order->{'basketno'}) . $sep; |
165 |
push(@row, _surround($order->{'budget_name'})); |
183 |
print _surround($order->{'authorisedbyname'}) . $sep; |
166 |
push(@row, _surround($order->{'basketno'})); |
184 |
print _surround($order->{'biblionumber'}) . $sep; |
167 |
push(@row, _surround($order->{'authorisedbyname'})); |
185 |
print _surround($order->{'title'}) . $sep; |
168 |
push(@row, _surround($order->{'biblionumber'})); |
186 |
print _surround($order->{'currency'}) . $sep; |
169 |
push(@row, _surround($order->{'title'})); |
187 |
print _surround($order->{'listprice'}) . $sep; |
170 |
push(@row, _surround($order->{'currency'})); |
188 |
print _surround($order->{'rrp'}) . $sep; |
171 |
push(@row, _surround($order->{'listprice'})); |
189 |
print _surround($order->{'ecost'}) . $sep; |
172 |
push(@row, _surround($order->{'rrp'})); |
190 |
print _surround($order->{'quantity'}) . $sep; |
173 |
push(@row, _surround($order->{'ecost'})); |
191 |
print _surround($order->{'total_rrp'}) . $sep; |
174 |
push(@row, _surround($order->{'quantity'})); |
192 |
print _surround($order->{'total_ecost'}) . $sep; |
175 |
push(@row, _surround($order->{'total_rrp'})); |
193 |
print _surround($order->{'entrydate'}) . $sep; |
176 |
push(@row, _surround($order->{'total_ecost'})); |
194 |
print _surround($order->{'datereceived'}) . $sep; |
177 |
push(@row, _surround($order->{'entrydate'})); |
195 |
print _surround($order->{'notes'}) . "\n"; |
178 |
push(@row, _surround($order->{'datereceived'})); |
|
|
179 |
push(@row, _surround($order->{'notes'})); |
180 |
push(@rows, \@row); |
196 |
} |
181 |
} |
197 |
|
182 |
|
198 |
print '"TOTAL"'. ($sep x 8); |
183 |
my @totalrow; |
199 |
print _surround($total_quantity) . $sep; |
184 |
for(1..9){push(@totalrow, "")}; |
200 |
print _surround($total_rrp) . $sep; |
185 |
push(@totalrow, _surround($total_quantity)); |
201 |
print _surround($total_ecost); |
186 |
push(@totalrow, _surround($total_rrp)); |
|
|
187 |
push(@totalrow, _surround($total_ecost)); |
188 |
|
189 |
my $csvTemplate = C4::Templates::gettemplate('reports/csv/orders_by_budget.tt', 'intranet', $query); |
190 |
$csvTemplate->param(sep => $sep, rows => \@rows, totalrow => \@totalrow); |
191 |
print $csvTemplate->output; |
202 |
|
192 |
|
203 |
exit(0); |
193 |
exit(0); |
204 |
} |
194 |
} |
205 |
} |
195 |
} |
206 |
else { |
196 |
else { |
207 |
# Set file export choices |
197 |
# Set file export choices |
208 |
my $CGIextChoice = CGI::scrolling_list( |
198 |
my @outputFormats = ('CSV'); |
209 |
-name => 'MIME', |
199 |
my @CSVdelimiters = qw(; tabulation , \\ / #); |
210 |
-id => 'MIME', |
|
|
211 |
-values => ['CSV'], # FIXME translation |
212 |
-size => 1, |
213 |
-multiple => 0 |
214 |
); |
215 |
|
216 |
my $CGIsepChoice = GetDelimiterChoices; |
217 |
|
200 |
|
218 |
# getting all budgets |
201 |
# getting all budgets |
219 |
# active budgets |
202 |
# active budgets |
220 |
my @active_budgets = C4::Budgets::GetActiveBudgets(1); |
203 |
my @active_budgets = C4::Budgets::GetBudgetsByActivity(1); |
221 |
# non active budgets |
204 |
# non active budgets |
222 |
my @non_active_budgets = C4::Budgets::GetActiveBudgets(0); |
205 |
my @non_active_budgets = C4::Budgets::GetBudgetsByActivity(0); |
223 |
my @budgetsloop; |
206 |
my @budgetsloop; |
224 |
foreach my $thisbudget ( sort {$a->{budget_name} cmp $b->{budget_name}} @active_budgets ) { |
207 |
foreach my $thisbudget ( sort {$a->{budget_name} cmp $b->{budget_name}} @active_budgets ) { |
225 |
my $budget_period_desc = C4::Budgets::GetBudgetPeriodDescription($thisbudget->{budget_id}); |
208 |
my $budget_period_desc = C4::Budgets::GetBudgetPeriodDescription($thisbudget->{budget_id}); |
Lines 241-248
else {
Link Here
|
241 |
} |
224 |
} |
242 |
|
225 |
|
243 |
$template->param( budgetsloop => \@budgetsloop, |
226 |
$template->param( budgetsloop => \@budgetsloop, |
244 |
CGIextChoice => $CGIextChoice, |
227 |
outputFormatloop => \@outputFormats, |
245 |
CGIsepChoice => $CGIsepChoice, |
228 |
delimiterloop => \@CSVdelimiters |
246 |
); |
229 |
); |
247 |
} |
230 |
} |
248 |
|
231 |
|