|
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 1087-1093
sub quote_item {
Link Here
|
| 1087 |
}; |
1088 |
}; |
| 1088 |
|
1089 |
|
| 1089 |
my $lsq_field = C4::Context->preference('EdifactLSQ'); |
1090 |
my $lsq_field = C4::Context->preference('EdifactLSQ'); |
| 1090 |
$new_item->{$lsq_field} = $item->girfield( 'sequence_code', $occurrence ); |
1091 |
my $lsl_field = C4::Context->preference('EdifactLSL'); |
|
|
1092 |
|
| 1093 |
# Handle LSQ field |
| 1094 |
if ( $lsq_field && $item->girfield( 'sequence_code', $occurrence ) ) { |
| 1095 |
my $lsq_value = $item->girfield( 'sequence_code', $occurrence ); |
| 1096 |
my $valid = |
| 1097 |
( $lsq_field eq 'location' ) |
| 1098 |
? _validate_location_code( $lsq_value, $quote_message ) |
| 1099 |
: _validate_collection_code( $lsq_value, $quote_message ); |
| 1100 |
|
| 1101 |
$new_item->{$lsq_field} = $lsq_value if $valid; |
| 1102 |
} |
| 1103 |
|
| 1104 |
# Handle LSL field |
| 1105 |
if ( $lsl_field && $item->girfield( 'sub_location_code', $occurrence ) ) { |
| 1106 |
my $lsl_value = $item->girfield( 'sub_location_code', $occurrence ); |
| 1107 |
my $valid = |
| 1108 |
( $lsl_field eq 'location' ) |
| 1109 |
? _validate_location_code( $lsl_value, $quote_message ) |
| 1110 |
: _validate_collection_code( $lsl_value, $quote_message ); |
| 1111 |
|
| 1112 |
$new_item->{$lsl_field} = $lsl_value if $valid; |
| 1113 |
} |
| 1091 |
|
1114 |
|
| 1092 |
if ( $new_item->{itype} ) { |
1115 |
if ( $new_item->{itype} ) { |
| 1093 |
$item_hash->{itype} = $new_item->{itype}; |
1116 |
$item_hash->{itype} = $new_item->{itype}; |
|
Lines 1095-1100
sub quote_item {
Link Here
|
| 1095 |
if ( $new_item->{$lsq_field} ) { |
1118 |
if ( $new_item->{$lsq_field} ) { |
| 1096 |
$item_hash->{$lsq_field} = $new_item->{$lsq_field}; |
1119 |
$item_hash->{$lsq_field} = $new_item->{$lsq_field}; |
| 1097 |
} |
1120 |
} |
|
|
1121 |
if ( $new_item->{$lsl_field} ) { |
| 1122 |
$item_hash->{$lsl_field} = $new_item->{$lsl_field}; |
| 1123 |
} |
| 1098 |
if ( $new_item->{itemcallnumber} ) { |
1124 |
if ( $new_item->{itemcallnumber} ) { |
| 1099 |
$item_hash->{itemcallnumber} = $new_item->{itemcallnumber}; |
1125 |
$item_hash->{itemcallnumber} = $new_item->{itemcallnumber}; |
| 1100 |
} |
1126 |
} |
|
Lines 1171-1177
sub quote_item {
Link Here
|
| 1171 |
homebranch => $item->girfield( 'branch', $occurrence ), |
1197 |
homebranch => $item->girfield( 'branch', $occurrence ), |
| 1172 |
}; |
1198 |
}; |
| 1173 |
my $lsq_field = C4::Context->preference('EdifactLSQ'); |
1199 |
my $lsq_field = C4::Context->preference('EdifactLSQ'); |
| 1174 |
$new_item->{$lsq_field} = $item->girfield( 'sequence_code', $occurrence ); |
1200 |
my $lsl_field = C4::Context->preference('EdifactLSL'); |
|
|
1201 |
|
| 1202 |
# Handle LSQ mapping with validation |
| 1203 |
if ( $lsq_field && $item->girfield( 'sequence_code', $occurrence ) ) { |
| 1204 |
my $lsq_value = $item->girfield( 'sequence_code', $occurrence ); |
| 1205 |
my $valid = |
| 1206 |
( $lsq_field eq 'location' ) |
| 1207 |
? _validate_location_code( $lsq_value, $quote_message ) |
| 1208 |
: _validate_collection_code( $lsq_value, $quote_message ); |
| 1209 |
|
| 1210 |
$new_item->{$lsq_field} = $lsq_value if $valid; |
| 1211 |
} |
| 1212 |
|
| 1213 |
# Handle LSL mapping with validation |
| 1214 |
if ( $lsl_field && $item->girfield( 'sub_location_code', $occurrence ) ) { |
| 1215 |
my $lsl_value = $item->girfield( 'sub_location_code', $occurrence ); |
| 1216 |
my $valid = |
| 1217 |
( $lsl_field eq 'location' ) |
| 1218 |
? _validate_location_code( $lsl_value, $quote_message ) |
| 1219 |
: _validate_collection_code( $lsl_value, $quote_message ); |
| 1220 |
|
| 1221 |
$new_item->{$lsl_field} = $lsl_value if $valid; |
| 1222 |
} |
| 1175 |
$new_item->{biblionumber} = $bib->{biblionumber}; |
1223 |
$new_item->{biblionumber} = $bib->{biblionumber}; |
| 1176 |
$new_item->{biblioitemnumber} = $bib->{biblioitemnumber}; |
1224 |
$new_item->{biblioitemnumber} = $bib->{biblioitemnumber}; |
| 1177 |
my $kitem = Koha::Item->new($new_item)->store; |
1225 |
my $kitem = Koha::Item->new($new_item)->store; |
|
Lines 1221-1226
sub get_edifact_ean {
Link Here
|
| 1221 |
return $eans->[0]; |
1269 |
return $eans->[0]; |
| 1222 |
} |
1270 |
} |
| 1223 |
|
1271 |
|
|
|
1272 |
sub _validate_location_code { |
| 1273 |
my ( $location_code, $quote_message ) = @_; |
| 1274 |
|
| 1275 |
return 1 unless $location_code; # Skip if empty |
| 1276 |
|
| 1277 |
my $av = Koha::AuthorisedValues->find( |
| 1278 |
{ |
| 1279 |
category => 'LOC', |
| 1280 |
authorised_value => $location_code |
| 1281 |
} |
| 1282 |
); |
| 1283 |
|
| 1284 |
unless ($av) { |
| 1285 |
$quote_message->add_to_edifact_errors( |
| 1286 |
{ |
| 1287 |
section => "GIR+LSQ/LSL validation", |
| 1288 |
details => "Invalid location code '$location_code' - not found in LOC authorized values" |
| 1289 |
} |
| 1290 |
); |
| 1291 |
return 0; |
| 1292 |
} |
| 1293 |
return 1; |
| 1294 |
} |
| 1295 |
|
| 1296 |
sub _validate_collection_code { |
| 1297 |
my ( $ccode, $quote_message ) = @_; |
| 1298 |
|
| 1299 |
return 1 unless $ccode; # Skip if empty |
| 1300 |
|
| 1301 |
my $av = Koha::AuthorisedValues->find( |
| 1302 |
{ |
| 1303 |
category => 'CCODE', |
| 1304 |
authorised_value => $ccode |
| 1305 |
} |
| 1306 |
); |
| 1307 |
|
| 1308 |
unless ($av) { |
| 1309 |
$quote_message->add_to_edifact_errors( |
| 1310 |
{ |
| 1311 |
section => "GIR+LSQ/LSL validation", |
| 1312 |
details => "Invalid collection code '$ccode' - not found in CCODE authorized values" |
| 1313 |
} |
| 1314 |
); |
| 1315 |
return 0; |
| 1316 |
} |
| 1317 |
return 1; |
| 1318 |
} |
| 1319 |
|
| 1224 |
# We should not need to have a routine to do this here |
1320 |
# We should not need to have a routine to do this here |
| 1225 |
sub _discounted_price { |
1321 |
sub _discounted_price { |
| 1226 |
my ( $discount, $price, $discounted_price ) = @_; |
1322 |
my ( $discount, $price, $discounted_price ) = @_; |
|
Lines 1374-1381
sub _create_item_from_quote {
Link Here
|
| 1374 |
$item_hash->{booksellerid} = $quote->vendor_id; |
1470 |
$item_hash->{booksellerid} = $quote->vendor_id; |
| 1375 |
$item_hash->{price} = $item_hash->{replacementprice} = $item->price; |
1471 |
$item_hash->{price} = $item_hash->{replacementprice} = $item->price; |
| 1376 |
$item_hash->{itype} = $item->girfield('stock_category'); |
1472 |
$item_hash->{itype} = $item->girfield('stock_category'); |
|
|
1473 |
|
| 1377 |
my $lsq_field = C4::Context->preference('EdifactLSQ'); |
1474 |
my $lsq_field = C4::Context->preference('EdifactLSQ'); |
| 1378 |
$item_hash->{$lsq_field} = $item->girfield('sequence_code'); |
1475 |
my $lsl_field = C4::Context->preference('EdifactLSL'); |
|
|
1476 |
|
| 1477 |
# Handle LSQ mapping |
| 1478 |
if ( $lsq_field && $item->girfield('sequence_code') ) { |
| 1479 |
$item_hash->{$lsq_field} = $item->girfield('sequence_code'); |
| 1480 |
} |
| 1481 |
|
| 1482 |
# Handle LSL mapping |
| 1483 |
if ( $lsl_field && $item->girfield('sub_location_code') ) { |
| 1484 |
$item_hash->{$lsl_field} = $item->girfield('sub_location_code'); |
| 1485 |
} |
| 1379 |
|
1486 |
|
| 1380 |
my $note = {}; |
1487 |
my $note = {}; |
| 1381 |
|
1488 |
|