|
Lines 44-49
use Koha::Plugins; # Adds plugin dirs to @INC
Link Here
|
| 44 |
use Koha::Plugins::Handler; |
44 |
use Koha::Plugins::Handler; |
| 45 |
use Koha::Acquisition::Baskets; |
45 |
use Koha::Acquisition::Baskets; |
| 46 |
use Koha::Acquisition::Booksellers; |
46 |
use Koha::Acquisition::Booksellers; |
|
|
47 |
use Koha::AuthorisedValues; |
| 47 |
use Koha::Util::FrameworkPlugin qw( biblio_008 ); |
48 |
use Koha::Util::FrameworkPlugin qw( biblio_008 ); |
| 48 |
|
49 |
|
| 49 |
our $VERSION = 1.1; |
50 |
our $VERSION = 1.1; |
|
Lines 993-999
sub quote_item {
Link Here
|
| 993 |
}; |
994 |
}; |
| 994 |
|
995 |
|
| 995 |
my $lsq_field = C4::Context->preference('EdifactLSQ'); |
996 |
my $lsq_field = C4::Context->preference('EdifactLSQ'); |
| 996 |
$new_item->{$lsq_field} = $item->girfield( 'sequence_code', $occurrence ); |
997 |
my $lsl_field = C4::Context->preference('EdifactLSL'); |
|
|
998 |
|
| 999 |
# Handle LSQ field |
| 1000 |
if ( $lsq_field && $item->girfield( 'sequence_code', $occurrence ) ) { |
| 1001 |
my $lsq_value = $item->girfield( 'sequence_code', $occurrence ); |
| 1002 |
my $valid = |
| 1003 |
( $lsq_field eq 'location' ) |
| 1004 |
? _validate_location_code( $lsq_value, $quote_message ) |
| 1005 |
: _validate_collection_code( $lsq_value, $quote_message ); |
| 1006 |
|
| 1007 |
$new_item->{$lsq_field} = $lsq_value if $valid; |
| 1008 |
} |
| 1009 |
|
| 1010 |
# Handle LSL field |
| 1011 |
if ( $lsl_field && $item->girfield( 'sub_location_code', $occurrence ) ) { |
| 1012 |
my $lsl_value = $item->girfield( 'sub_location_code', $occurrence ); |
| 1013 |
my $valid = |
| 1014 |
( $lsl_field eq 'location' ) |
| 1015 |
? _validate_location_code( $lsl_value, $quote_message ) |
| 1016 |
: _validate_collection_code( $lsl_value, $quote_message ); |
| 1017 |
|
| 1018 |
$new_item->{$lsl_field} = $lsl_value if $valid; |
| 1019 |
} |
| 997 |
|
1020 |
|
| 998 |
if ( $new_item->{itype} ) { |
1021 |
if ( $new_item->{itype} ) { |
| 999 |
$item_hash->{itype} = $new_item->{itype}; |
1022 |
$item_hash->{itype} = $new_item->{itype}; |
|
Lines 1077-1083
sub quote_item {
Link Here
|
| 1077 |
homebranch => $item->girfield( 'branch', $occurrence ), |
1100 |
homebranch => $item->girfield( 'branch', $occurrence ), |
| 1078 |
}; |
1101 |
}; |
| 1079 |
my $lsq_field = C4::Context->preference('EdifactLSQ'); |
1102 |
my $lsq_field = C4::Context->preference('EdifactLSQ'); |
| 1080 |
$new_item->{$lsq_field} = $item->girfield( 'sequence_code', $occurrence ); |
1103 |
my $lsl_field = C4::Context->preference('EdifactLSL'); |
|
|
1104 |
|
| 1105 |
# Handle LSQ mapping with validation |
| 1106 |
if ( $lsq_field && $item->girfield( 'sequence_code', $occurrence ) ) { |
| 1107 |
my $lsq_value = $item->girfield( 'sequence_code', $occurrence ); |
| 1108 |
my $valid = |
| 1109 |
( $lsq_field eq 'location' ) |
| 1110 |
? _validate_location_code( $lsq_value, $quote_message ) |
| 1111 |
: _validate_collection_code( $lsq_value, $quote_message ); |
| 1112 |
|
| 1113 |
$new_item->{$lsq_field} = $lsq_value if $valid; |
| 1114 |
} |
| 1115 |
|
| 1116 |
# Handle LSL mapping with validation |
| 1117 |
if ( $lsl_field && $item->girfield( 'sub_location_code', $occurrence ) ) { |
| 1118 |
my $lsl_value = $item->girfield( 'sub_location_code', $occurrence ); |
| 1119 |
my $valid = |
| 1120 |
( $lsl_field eq 'location' ) |
| 1121 |
? _validate_location_code( $lsl_value, $quote_message ) |
| 1122 |
: _validate_collection_code( $lsl_value, $quote_message ); |
| 1123 |
|
| 1124 |
$new_item->{$lsl_field} = $lsl_value if $valid; |
| 1125 |
} |
| 1081 |
$new_item->{biblionumber} = $bib->{biblionumber}; |
1126 |
$new_item->{biblionumber} = $bib->{biblionumber}; |
| 1082 |
$new_item->{biblioitemnumber} = $bib->{biblioitemnumber}; |
1127 |
$new_item->{biblioitemnumber} = $bib->{biblioitemnumber}; |
| 1083 |
my $kitem = Koha::Item->new($new_item)->store; |
1128 |
my $kitem = Koha::Item->new($new_item)->store; |
|
Lines 1127-1132
sub get_edifact_ean {
Link Here
|
| 1127 |
return $eans->[0]; |
1172 |
return $eans->[0]; |
| 1128 |
} |
1173 |
} |
| 1129 |
|
1174 |
|
|
|
1175 |
sub _validate_location_code { |
| 1176 |
my ( $location_code, $quote_message ) = @_; |
| 1177 |
|
| 1178 |
return 1 unless $location_code; # Skip if empty |
| 1179 |
|
| 1180 |
my $av = Koha::AuthorisedValues->find( |
| 1181 |
{ |
| 1182 |
category => 'LOC', |
| 1183 |
authorised_value => $location_code |
| 1184 |
} |
| 1185 |
); |
| 1186 |
|
| 1187 |
unless ($av) { |
| 1188 |
$quote_message->add_to_edifact_errors( |
| 1189 |
{ |
| 1190 |
section => "GIR+LSQ/LSL validation", |
| 1191 |
details => "Invalid location code '$location_code' - not found in LOC authorized values" |
| 1192 |
} |
| 1193 |
); |
| 1194 |
return 0; |
| 1195 |
} |
| 1196 |
return 1; |
| 1197 |
} |
| 1198 |
|
| 1199 |
sub _validate_collection_code { |
| 1200 |
my ( $ccode, $quote_message ) = @_; |
| 1201 |
|
| 1202 |
return 1 unless $ccode; # Skip if empty |
| 1203 |
|
| 1204 |
my $av = Koha::AuthorisedValues->find( |
| 1205 |
{ |
| 1206 |
category => 'CCODE', |
| 1207 |
authorised_value => $ccode |
| 1208 |
} |
| 1209 |
); |
| 1210 |
|
| 1211 |
unless ($av) { |
| 1212 |
$quote_message->add_to_edifact_errors( |
| 1213 |
{ |
| 1214 |
section => "GIR+LSQ/LSL validation", |
| 1215 |
details => "Invalid collection code '$ccode' - not found in CCODE authorized values" |
| 1216 |
} |
| 1217 |
); |
| 1218 |
return 0; |
| 1219 |
} |
| 1220 |
return 1; |
| 1221 |
} |
| 1222 |
|
| 1130 |
# We should not need to have a routine to do this here |
1223 |
# We should not need to have a routine to do this here |
| 1131 |
sub _discounted_price { |
1224 |
sub _discounted_price { |
| 1132 |
my ( $discount, $price, $discounted_price ) = @_; |
1225 |
my ( $discount, $price, $discounted_price ) = @_; |
|
Lines 1280-1287
sub _create_item_from_quote {
Link Here
|
| 1280 |
$item_hash->{booksellerid} = $quote->vendor_id; |
1373 |
$item_hash->{booksellerid} = $quote->vendor_id; |
| 1281 |
$item_hash->{price} = $item_hash->{replacementprice} = $item->price; |
1374 |
$item_hash->{price} = $item_hash->{replacementprice} = $item->price; |
| 1282 |
$item_hash->{itype} = $item->girfield('stock_category'); |
1375 |
$item_hash->{itype} = $item->girfield('stock_category'); |
|
|
1376 |
|
| 1283 |
my $lsq_field = C4::Context->preference('EdifactLSQ'); |
1377 |
my $lsq_field = C4::Context->preference('EdifactLSQ'); |
| 1284 |
$item_hash->{$lsq_field} = $item->girfield('sequence_code'); |
1378 |
my $lsl_field = C4::Context->preference('EdifactLSL'); |
|
|
1379 |
|
| 1380 |
# Handle LSQ mapping |
| 1381 |
if ( $lsq_field && $item->girfield('sequence_code') ) { |
| 1382 |
$item_hash->{$lsq_field} = $item->girfield('sequence_code'); |
| 1383 |
} |
| 1384 |
|
| 1385 |
# Handle LSL mapping |
| 1386 |
if ( $lsl_field && $item->girfield('sub_location_code') ) { |
| 1387 |
$item_hash->{$lsl_field} = $item->girfield('sub_location_code'); |
| 1388 |
} |
| 1285 |
|
1389 |
|
| 1286 |
my $note = {}; |
1390 |
my $note = {}; |
| 1287 |
|
1391 |
|