|
Lines 21-31
Link Here
|
| 21 |
# with Koha; if not, write to the Free Software Foundation, Inc., |
21 |
# with Koha; if not, write to the Free Software Foundation, Inc., |
| 22 |
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
22 |
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 23 |
|
23 |
|
| 24 |
use strict; |
24 |
use Modern::Perl; |
| 25 |
use warnings; |
|
|
| 26 |
use CGI; |
25 |
use CGI; |
| 27 |
use Carp; |
26 |
use Carp; |
| 28 |
use Number::Format qw(:all); |
27 |
use Number::Format qw(:all); |
|
|
28 |
use YAML qw/Load/; |
| 29 |
|
29 |
|
| 30 |
use C4::Context; |
30 |
use C4::Context; |
| 31 |
use C4::Auth; |
31 |
use C4::Auth; |
|
Lines 56-62
my ($template, $loggedinuser, $cookie, $userflags) = get_template_and_user({
Link Here
|
| 56 |
}); |
56 |
}); |
| 57 |
|
57 |
|
| 58 |
my $cgiparams = $input->Vars; |
58 |
my $cgiparams = $input->Vars; |
| 59 |
my $op = $cgiparams->{'op'}; |
59 |
my $op = $cgiparams->{'op'} || ''; |
| 60 |
my $booksellerid = $input->param('booksellerid'); |
60 |
my $booksellerid = $input->param('booksellerid'); |
| 61 |
my $bookseller = GetBookSellerFromId($booksellerid); |
61 |
my $bookseller = GetBookSellerFromId($booksellerid); |
| 62 |
my $data; |
62 |
my $data; |
|
Lines 65-71
$template->param(scriptname => "/cgi-bin/koha/acqui/addorderiso2709.pl",
Link Here
|
| 65 |
booksellerid => $booksellerid, |
65 |
booksellerid => $booksellerid, |
| 66 |
booksellername => $bookseller->{name}, |
66 |
booksellername => $bookseller->{name}, |
| 67 |
); |
67 |
); |
| 68 |
my $ordernumber; |
|
|
| 69 |
|
68 |
|
| 70 |
if ($cgiparams->{'import_batch_id'} && $op eq ""){ |
69 |
if ($cgiparams->{'import_batch_id'} && $op eq ""){ |
| 71 |
$op = "batch_details"; |
70 |
$op = "batch_details"; |
|
Lines 124-130
if ($op eq ""){
Link Here
|
| 124 |
loop_currencies => \@loop_currency, |
123 |
loop_currencies => \@loop_currency, |
| 125 |
); |
124 |
); |
| 126 |
import_biblios_list($template, $cgiparams->{'import_batch_id'}); |
125 |
import_biblios_list($template, $cgiparams->{'import_batch_id'}); |
| 127 |
if ( C4::Context->preference('AcqCreateItem') eq 'ordering' && !$ordernumber ) { |
126 |
if ( C4::Context->preference('AcqCreateItem') eq 'ordering' ) { |
| 128 |
# prepare empty item form |
127 |
# prepare empty item form |
| 129 |
my $cell = PrepareItemrecordDisplay( '', '', '', 'ACQ' ); |
128 |
my $cell = PrepareItemrecordDisplay( '', '', '', 'ACQ' ); |
| 130 |
|
129 |
|
|
Lines 157-175
if ($op eq ""){
Link Here
|
| 157 |
# retrieve the file you want to import |
156 |
# retrieve the file you want to import |
| 158 |
my $import_batch_id = $cgiparams->{'import_batch_id'}; |
157 |
my $import_batch_id = $cgiparams->{'import_batch_id'}; |
| 159 |
my $biblios = GetImportRecordsRange($import_batch_id); |
158 |
my $biblios = GetImportRecordsRange($import_batch_id); |
|
|
159 |
my @import_record_id_selected = $input->param("import_record_id"); |
| 160 |
my @quantities = $input->param('quantity'); |
| 161 |
my @prices = $input->param('price'); |
| 162 |
my @budgets_id = $input->param('budget_id'); |
| 163 |
my @rrp = $input->param('rrp'); |
| 164 |
my @discount = $input->param('discount'); |
| 165 |
my @sort1 = $input->param('sort1'); |
| 166 |
my @sort2 = $input->param('sort2'); |
| 167 |
my $cur = GetCurrency(); |
| 160 |
for my $biblio (@$biblios){ |
168 |
for my $biblio (@$biblios){ |
| 161 |
# 1st insert the biblio, or find it through matcher |
169 |
# Check if this import_record_id was selected |
|
|
170 |
next if not grep { $_ eq $$biblio{import_record_id} } @import_record_id_selected; |
| 162 |
my ( $marcblob, $encoding ) = GetImportRecordMarc( $biblio->{'import_record_id'} ); |
171 |
my ( $marcblob, $encoding ) = GetImportRecordMarc( $biblio->{'import_record_id'} ); |
| 163 |
my $marcrecord = MARC::Record->new_from_usmarc($marcblob) || die "couldn't translate marc information"; |
172 |
my $marcrecord = MARC::Record->new_from_usmarc($marcblob) || die "couldn't translate marc information"; |
| 164 |
my $match = GetImportRecordMatches( $biblio->{'import_record_id'}, 1 ); |
173 |
my $match = GetImportRecordMatches( $biblio->{'import_record_id'}, 1 ); |
| 165 |
my $biblionumber=$#$match > -1?$match->[0]->{'biblionumber'}:0; |
174 |
my $biblionumber=$#$match > -1?$match->[0]->{'biblionumber'}:0; |
|
|
175 |
my $c_quantity = shift( @quantities ) || GetMarcQuantity($marcrecord, C4::Context->preference('marcflavour') ) || 1; |
| 176 |
my $c_budget_id = shift( @budgets_id ) || $input->param('all_budget_id') || $budget_id; |
| 177 |
my $c_rrp = shift( @rrp ); # rrp include tax |
| 178 |
my $c_discount = shift ( @discount); |
| 179 |
$c_discount = $c_discount / 100 if $c_discount > 100; |
| 180 |
my $c_sort1 = shift( @sort1 ) || $input->param('all_sort1') || ''; |
| 181 |
my $c_sort2 = shift( @sort2 ) || $input->param('all_sort2') || ''; |
| 166 |
|
182 |
|
|
|
183 |
# 1st insert the biblio, or find it through matcher |
| 167 |
unless ( $biblionumber ) { |
184 |
unless ( $biblionumber ) { |
| 168 |
# add the biblio |
185 |
# add the biblio |
| 169 |
my $bibitemnum; |
186 |
my $bibitemnum; |
| 170 |
|
187 |
|
| 171 |
# remove ISBN - |
188 |
# remove ISBN - |
| 172 |
my ( $isbnfield, $isbnsubfield ) = GetMarcFromKohaField( 'biblioitems.isbn', '' ); |
189 |
my ( $isbnfield, $isbnsubfield ) = GetMarcFromKohaField( 'biblioitems.isbn', '' ); |
| 173 |
if ( $marcrecord->field($isbnfield) ) { |
190 |
if ( $marcrecord->field($isbnfield) ) { |
| 174 |
foreach my $field ( $marcrecord->field($isbnfield) ) { |
191 |
foreach my $field ( $marcrecord->field($isbnfield) ) { |
| 175 |
foreach my $subfield ( $field->subfield($isbnsubfield) ) { |
192 |
foreach my $subfield ( $field->subfield($isbnsubfield) ) { |
|
Lines 180-186
if ($op eq ""){
Link Here
|
| 180 |
} |
197 |
} |
| 181 |
} |
198 |
} |
| 182 |
( $biblionumber, $bibitemnum ) = AddBiblio( $marcrecord, $cgiparams->{'frameworkcode'} || '' ); |
199 |
( $biblionumber, $bibitemnum ) = AddBiblio( $marcrecord, $cgiparams->{'frameworkcode'} || '' ); |
| 183 |
SetImportRecordStatus( $biblio->{'import_record_id'}, 'imported' ); |
|
|
| 184 |
# 2nd add authorities if applicable |
200 |
# 2nd add authorities if applicable |
| 185 |
if (C4::Context->preference("BiblioAddsAuthorities")){ |
201 |
if (C4::Context->preference("BiblioAddsAuthorities")){ |
| 186 |
my $headings_linked =BiblioAutoLink($marcrecord, $cgiparams->{'frameworkcode'}); |
202 |
my $headings_linked =BiblioAutoLink($marcrecord, $cgiparams->{'frameworkcode'}); |
|
Lines 194-240
if ($op eq ""){
Link Here
|
| 194 |
# get quantity in the MARC record (1 if none) |
210 |
# get quantity in the MARC record (1 if none) |
| 195 |
my $quantity = GetMarcQuantity($marcrecord, C4::Context->preference('marcflavour')) || 1; |
211 |
my $quantity = GetMarcQuantity($marcrecord, C4::Context->preference('marcflavour')) || 1; |
| 196 |
my %orderinfo = ( |
212 |
my %orderinfo = ( |
| 197 |
"biblionumber", $biblionumber, "basketno", $cgiparams->{'basketno'}, |
213 |
biblionumber => $biblionumber, |
| 198 |
"quantity", $quantity, "branchcode", $branch, |
214 |
basketno => $cgiparams->{'basketno'}, |
| 199 |
"budget_id", $budget_id, "uncertainprice", 1, |
215 |
quantity => $c_quantity, |
| 200 |
"sort1", $cgiparams->{'sort1'},"sort2", $cgiparams->{'sort2'}, |
216 |
branchcode => $patron->{branchcode}, |
| 201 |
"notes", $cgiparams->{'notes'}, "budget_id", $cgiparams->{'budget_id'}, |
217 |
budget_id => $c_budget_id, |
| 202 |
"currency",$cgiparams->{'currency'}, |
218 |
uncertainprice => 1, |
|
|
219 |
sort1 => $c_sort1, |
| 220 |
sort2 => $c_sort2, |
| 221 |
notes => $cgiparams->{'all_notes'}, |
| 222 |
currency => $cgiparams->{'all_currency'}, |
| 203 |
); |
223 |
); |
| 204 |
|
224 |
# get the price if there is one. |
| 205 |
my $price = GetMarcPrice($marcrecord, C4::Context->preference('marcflavour')); |
225 |
my $price= shift( @prices ) || GetMarcPrice($marcrecord, C4::Context->preference('marcflavour')); |
| 206 |
|
|
|
| 207 |
if ($price){ |
226 |
if ($price){ |
| 208 |
eval { |
227 |
# in France, the cents separator is the , but sometimes, ppl use a . |
| 209 |
require C4::Acquisition; |
228 |
# in this case, the price will be x100 when unformatted ! Replace the . by a , to get a proper price calculation |
| 210 |
import C4::Acquisition qw/GetBasket/; |
229 |
$price =~ s/\./,/ if C4::Context->preference("CurrencyFormat") eq "FR"; |
| 211 |
}; |
230 |
$price = $num->unformat_number($price); |
| 212 |
if ($@){ |
|
|
| 213 |
croak $@; |
| 214 |
} |
| 215 |
eval { |
| 216 |
require C4::Bookseller; |
| 217 |
import C4::Bookseller qw/GetBookSellerFromId/; |
| 218 |
}; |
| 219 |
if ($@){ |
| 220 |
croak $@; |
| 221 |
} |
| 222 |
my $basket = GetBasket( $orderinfo{basketno} ); |
| 223 |
my $bookseller = GetBookSellerFromId( $basket->{booksellerid} ); |
| 224 |
$orderinfo{gstrate} = $bookseller->{gstrate}; |
231 |
$orderinfo{gstrate} = $bookseller->{gstrate}; |
| 225 |
$orderinfo{rrp} = $price; |
232 |
my $c = $c_discount ? $c_discount / 100 : $bookseller->{discount} / 100; |
| 226 |
$orderinfo{ecost} = $orderinfo{rrp} * ( 1 - $bookseller->{discount} / 100 ); |
233 |
if ( $bookseller->{listincgst} ) { |
| 227 |
$orderinfo{listprice} = $orderinfo{rrp}; |
234 |
if ( $c_discount ) { |
|
|
235 |
$orderinfo{ecost} = $price; |
| 236 |
$orderinfo{rrp} = $orderinfo{ecost} / ( 1 - $c ); |
| 237 |
} else { |
| 238 |
$orderinfo{ecost} = $price * ( 1 - $c ); |
| 239 |
$orderinfo{rrp} = $price; |
| 240 |
} |
| 241 |
} else { |
| 242 |
if ( $c_discount ) { |
| 243 |
$orderinfo{ecost} = $price / ( 1 + $orderinfo{gstrate} ); |
| 244 |
$orderinfo{rrp} = $orderinfo{ecost} / ( 1 - $c ); |
| 245 |
} else { |
| 246 |
$orderinfo{rrp} = $price / ( 1 + $orderinfo{gstrate} ); |
| 247 |
$orderinfo{ecost} = $orderinfo{rrp} * ( 1 - $c ); |
| 248 |
} |
| 249 |
} |
| 250 |
$orderinfo{listprice} = $orderinfo{rrp} / $cur->{rate}; |
| 228 |
$orderinfo{unitprice} = $orderinfo{ecost}; |
251 |
$orderinfo{unitprice} = $orderinfo{ecost}; |
| 229 |
$orderinfo{total} = $orderinfo{ecost}; |
252 |
$orderinfo{total} = $orderinfo{ecost} * $c_quantity; |
| 230 |
} else { |
253 |
} else { |
| 231 |
$orderinfo{'listprice'} = 0; |
254 |
$orderinfo{listprice} = 0; |
| 232 |
} |
255 |
} |
| 233 |
|
256 |
|
| 234 |
# remove uncertainprice flag if we have found a price in the MARC record |
257 |
# remove uncertainprice flag if we have found a price in the MARC record |
| 235 |
$orderinfo{uncertainprice} = 0 if $orderinfo{listprice}; |
258 |
$orderinfo{uncertainprice} = 0 if $orderinfo{listprice}; |
| 236 |
my $basketno; |
259 |
my ( $basketno, $ordernumber ) = NewOrder( \%orderinfo ); |
| 237 |
( $basketno, $ordernumber ) = NewOrder( \%orderinfo ); |
|
|
| 238 |
|
260 |
|
| 239 |
# 4th, add items if applicable |
261 |
# 4th, add items if applicable |
| 240 |
# parse the item sent by the form, and create an item just for the import_record_id we are dealing with |
262 |
# parse the item sent by the form, and create an item just for the import_record_id we are dealing with |
|
Lines 254-265
if ($op eq ""){
Link Here
|
| 254 |
push @{ $item->{indicator} }, $indicator[0]; |
276 |
push @{ $item->{indicator} }, $indicator[0]; |
| 255 |
my $xml = TransformHtmlToXml( \@tags, \@subfields, \@field_values, \@ind_tag, \@indicator ); |
277 |
my $xml = TransformHtmlToXml( \@tags, \@subfields, \@field_values, \@ind_tag, \@indicator ); |
| 256 |
my $record = MARC::Record::new_from_xml( $xml, 'UTF-8' ); |
278 |
my $record = MARC::Record::new_from_xml( $xml, 'UTF-8' ); |
| 257 |
for (my $qtyloop=1;$qtyloop <=$quantity;$qtyloop++) { |
279 |
for (my $qtyloop=1;$qtyloop <= $c_quantity;$qtyloop++) { |
| 258 |
my ( $biblionumber, $bibitemnum, $itemnumber ) = AddItemFromMarc( $record, $biblionumber ); |
280 |
my ( $biblionumber, $bibitemnum, $itemnumber ) = AddItemFromMarc( $record, $biblionumber ); |
| 259 |
NewOrderItem( $itemnumber, $ordernumber ); |
281 |
NewOrderItem( $itemnumber, $ordernumber ); |
| 260 |
} |
282 |
} |
| 261 |
} else { |
|
|
| 262 |
SetImportRecordStatus( $biblio->{'import_record_id'}, 'imported' ); |
| 263 |
} |
283 |
} |
| 264 |
} |
284 |
} |
| 265 |
# go to basket page |
285 |
# go to basket page |
|
Lines 276-283
my $budget = GetBudget($budget_id);
Link Here
|
| 276 |
|
296 |
|
| 277 |
# build budget list |
297 |
# build budget list |
| 278 |
my $budget_loop = []; |
298 |
my $budget_loop = []; |
| 279 |
$budgets = GetBudgetHierarchy; |
299 |
my $budgets_hierarchy = GetBudgetHierarchy; |
| 280 |
foreach my $r ( @{$budgets} ) { |
300 |
foreach my $r ( @{$budgets_hierarchy} ) { |
| 281 |
next unless (CanUserUseBudget($borrower, $r, $userflags)); |
301 |
next unless (CanUserUseBudget($borrower, $r, $userflags)); |
| 282 |
if ( !defined $r->{budget_amount} || $r->{budget_amount} == 0 ) { |
302 |
if ( !defined $r->{budget_amount} || $r->{budget_amount} == 0 ) { |
| 283 |
next; |
303 |
next; |
|
Lines 285-290
foreach my $r ( @{$budgets} ) {
Link Here
|
| 285 |
push @{$budget_loop}, |
305 |
push @{$budget_loop}, |
| 286 |
{ b_id => $r->{budget_id}, |
306 |
{ b_id => $r->{budget_id}, |
| 287 |
b_txt => $r->{budget_name}, |
307 |
b_txt => $r->{budget_name}, |
|
|
308 |
b_sort1_authcat => $r->{'sort1_authcat'}, |
| 309 |
b_sort2_authcat => $r->{'sort2_authcat'}, |
| 288 |
b_sel => ( $r->{budget_id} == $budget_id ) ? 1 : 0, |
310 |
b_sel => ( $r->{budget_id} == $budget_id ) ? 1 : 0, |
| 289 |
}; |
311 |
}; |
| 290 |
} |
312 |
} |
|
Lines 296-302
if ($budget) { # its a mod ..
Link Here
|
| 296 |
$CGIsort1 = GetAuthvalueDropbox( $budget->{'sort1_authcat'}, $data->{'sort1'} ); |
318 |
$CGIsort1 = GetAuthvalueDropbox( $budget->{'sort1_authcat'}, $data->{'sort1'} ); |
| 297 |
} |
319 |
} |
| 298 |
} elsif ( scalar(@$budgets) ) { |
320 |
} elsif ( scalar(@$budgets) ) { |
| 299 |
$CGIsort1 = GetAuthvalueDropbox( @$budgets[0]->{'sort1_authcat'}, '' ); |
321 |
} elsif ( scalar(@$budgets_hierarchy) ) { |
|
|
322 |
$CGIsort1 = GetAuthvalueDropbox( @$budgets_hierarchy[0]->{'sort1_authcat'}, '' ); |
| 300 |
} |
323 |
} |
| 301 |
# if CGIsort is successfully fetched, the use it |
324 |
# if CGIsort is successfully fetched, the use it |
| 302 |
# else - failback to plain input-field |
325 |
# else - failback to plain input-field |
|
Lines 311-318
if ($budget) {
Link Here
|
| 311 |
if ( defined $budget->{'sort2_authcat'} ) { |
334 |
if ( defined $budget->{'sort2_authcat'} ) { |
| 312 |
$CGIsort2 = GetAuthvalueDropbox( $budget->{'sort2_authcat'}, $data->{'sort2'} ); |
335 |
$CGIsort2 = GetAuthvalueDropbox( $budget->{'sort2_authcat'}, $data->{'sort2'} ); |
| 313 |
} |
336 |
} |
| 314 |
} elsif ( scalar(@$budgets) ) { |
337 |
} elsif ( scalar(@$budgets_hierarchy) ) { |
| 315 |
$CGIsort2 = GetAuthvalueDropbox( @$budgets[0]->{sort2_authcat}, '' ); |
338 |
$CGIsort2 = GetAuthvalueDropbox( @$budgets_hierarchy[0]->{sort2_authcat}, '' ); |
| 316 |
} |
339 |
} |
| 317 |
if ($CGIsort2) { |
340 |
if ($CGIsort2) { |
| 318 |
$template->param( CGIsort2 => $CGIsort2 ); |
341 |
$template->param( CGIsort2 => $CGIsort2 ); |
|
Lines 378-386
sub import_biblios_list {
Link Here
|
| 378 |
record_sequence => $biblio->{'record_sequence'}, |
401 |
record_sequence => $biblio->{'record_sequence'}, |
| 379 |
overlay_status => $biblio->{'overlay_status'}, |
402 |
overlay_status => $biblio->{'overlay_status'}, |
| 380 |
match_biblionumber => $#$match > -1 ? $match->[0]->{'biblionumber'} : 0, |
403 |
match_biblionumber => $#$match > -1 ? $match->[0]->{'biblionumber'} : 0, |
| 381 |
match_citation => $#$match > -1 ? $match->[0]->{'title'} . ' ' . $match->[0]->{'author'} : '', |
404 |
match_citation => $#$match > -1 ? $match->[0]->{'title'} || '' . ' ' . $match->[0]->{'author'} || '': '', |
| 382 |
match_score => $#$match > -1 ? $match->[0]->{'score'} : 0, |
405 |
match_score => $#$match > -1 ? $match->[0]->{'score'} : 0, |
| 383 |
); |
406 |
); |
|
|
407 |
my ( $marcblob, $encoding ) = GetImportRecordMarc( $biblio->{'import_record_id'} ); |
| 408 |
my $marcrecord = MARC::Record->new_from_usmarc($marcblob) || die "couldn't translate marc information"; |
| 409 |
my $infos = get_infos_syspref($marcrecord, ['price', 'quantity', 'budget_code', 'rrp', 'discount', 'sort1', 'sort2']); |
| 410 |
my $price = $infos->{price}; |
| 411 |
my $quantity = $infos->{quantity}; |
| 412 |
my $budget_code = $infos->{budget_code}; |
| 413 |
my $rrp = $infos->{rrp}; |
| 414 |
my $discount = $infos->{discount}; |
| 415 |
my $sort1 = $infos->{sort1}; |
| 416 |
my $sort2 = $infos->{sort2}; |
| 417 |
my $budget_id; |
| 418 |
if($budget_code) { |
| 419 |
my $biblio_budget = GetBudgetByCode("budget_code"); |
| 420 |
if($biblio_budget) { |
| 421 |
$budget_id = $biblio_budget->{budget_id}; |
| 422 |
} |
| 423 |
} |
| 424 |
$cellrecord{price} = $price || ''; |
| 425 |
$cellrecord{quantity} = $quantity || ''; |
| 426 |
$cellrecord{budget_id} = $budget_id || ''; |
| 427 |
$cellrecord{rrp} = $rrp || ''; |
| 428 |
$cellrecord{discount} = $discount || ''; |
| 429 |
$cellrecord{sort1} = $sort1 || ''; |
| 430 |
$cellrecord{sort2} = $sort2 || ''; |
| 431 |
|
| 384 |
push @list, \%cellrecord; |
432 |
push @list, \%cellrecord; |
| 385 |
} |
433 |
} |
| 386 |
my $num_biblios = $batch->{'num_biblios'}; |
434 |
my $num_biblios = $batch->{'num_biblios'}; |
|
Lines 440-442
sub add_matcher_list {
Link Here
|
| 440 |
} |
488 |
} |
| 441 |
$template->param(available_matchers => \@matchers); |
489 |
$template->param(available_matchers => \@matchers); |
| 442 |
} |
490 |
} |
|
|
491 |
|
| 492 |
sub get_infos_syspref { |
| 493 |
my ($record, $field_list) = @_; |
| 494 |
my $syspref = C4::Context->preference('MarcFieldsToOrder'); |
| 495 |
my $yaml = YAML::Load($syspref); |
| 496 |
my $r; |
| 497 |
for my $field_name ( @$field_list ) { |
| 498 |
my @fields = split /\|/, $yaml->{$field_name}; |
| 499 |
for my $field ( @fields ) { |
| 500 |
my ( $f, $sf ) = split /\$/, $field; |
| 501 |
next unless $f and $sf; |
| 502 |
if ( my $v = $record->subfield( $f, $sf ) ) { |
| 503 |
$r->{$field_name} = $v; |
| 504 |
} |
| 505 |
last if $yaml->{$field}; |
| 506 |
} |
| 507 |
} |
| 508 |
return $r; |
| 509 |
} |
| 510 |
|