View | Details | Raw Unified | Return to bug 40391
Collapse All | Expand All

(-)a/Koha/EDI.pm (-3 / +110 lines)
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
(-)a/Koha/Edifact/Line.pm (+1 lines)
Lines 658-663 sub extract_gir { Link Here
658
        LRS => 'record_sublocation',
658
        LRS => 'record_sublocation',
659
        LSM => 'shelfmark',
659
        LSM => 'shelfmark',
660
        LSQ => 'sequence_code',
660
        LSQ => 'sequence_code',
661
        LSL => 'sub_location_code',
661
        LST => 'stock_category',
662
        LST => 'stock_category',
662
        LSZ => 'size_code',
663
        LSZ => 'size_code',
663
        LVC => 'coded_servicing_instruction',
664
        LVC => 'coded_servicing_instruction',
(-)a/Koha/Edifact/Order.pm (-7 / +38 lines)
Lines 388-393 sub order_line { Link Here
388
    #     we dont currently support this in koha
388
    #     we dont currently support this in koha
389
    # GIR copy-related data
389
    # GIR copy-related data
390
    my $lsq_field = C4::Context->preference('EdifactLSQ');
390
    my $lsq_field = C4::Context->preference('EdifactLSQ');
391
    my $lsl_field = C4::Context->preference('EdifactLSL');
391
    my @items;
392
    my @items;
392
    if ( $basket->effective_create_items eq 'ordering' ) {
393
    if ( $basket->effective_create_items eq 'ordering' ) {
393
394
Lines 395-406 sub order_line { Link Here
395
        foreach my $item (@linked_itemnumbers) {
396
        foreach my $item (@linked_itemnumbers) {
396
            my $i_obj = $schema->resultset('Item')->find( $item->itemnumber );
397
            my $i_obj = $schema->resultset('Item')->find( $item->itemnumber );
397
            if ( defined $i_obj ) {
398
            if ( defined $i_obj ) {
398
                push @items, {
399
                my $item_data = {
399
                    branchcode     => $i_obj->get_column('homebranch'),
400
                    branchcode     => $i_obj->get_column('homebranch'),
400
                    itype          => $i_obj->effective_itemtype,
401
                    itype          => $i_obj->effective_itemtype,
401
                    $lsq_field     => $i_obj->$lsq_field,
402
                    itemcallnumber => $i_obj->itemcallnumber,
402
                    itemcallnumber => $i_obj->itemcallnumber,
403
                };
403
                };
404
405
                # Handle LSQ mapping
406
                if ($lsq_field) {
407
                    $item_data->{$lsq_field} = $i_obj->$lsq_field;
408
                }
409
410
                # Handle LSL mapping
411
                if ($lsl_field) {
412
                    $item_data->{$lsl_field} = $i_obj->$lsl_field;
413
                }
414
415
                push @items, $item_data;
404
            }
416
            }
405
        }
417
        }
406
    } else {
418
    } else {
Lines 421-433 sub order_line { Link Here
421
433
422
    my $item_fields = [];
434
    my $item_fields = [];
423
    for my $item (@items) {
435
    for my $item (@items) {
424
        push @{$item_fields},
436
        my $item_field_data = {
425
            {
426
            branchcode     => $item->{branchcode},
437
            branchcode     => $item->{branchcode},
427
            itype          => $item->{itype},
438
            itype          => $item->{itype},
428
            $lsq_field     => $item->{$lsq_field},
429
            itemcallnumber => $item->{itemcallnumber},
439
            itemcallnumber => $item->{itemcallnumber},
430
            };
440
        };
441
442
        # Handle LSQ mapping
443
        if ( $lsq_field && $item->{$lsq_field} ) {
444
            $item_field_data->{$lsq_field} = $item->{$lsq_field};
445
        }
446
447
        # Handle LSL mapping
448
        if ( $lsl_field && $item->{$lsl_field} ) {
449
            $item_field_data->{$lsl_field} = $item->{$lsl_field};
450
        }
451
452
        push @{$item_fields}, $item_field_data;
431
    }
453
    }
432
    $self->add_seg(
454
    $self->add_seg(
433
        gir_segments(
455
        gir_segments(
Lines 558-563 sub gir_segments { Link Here
558
    my @segments;
580
    my @segments;
559
    my $sequence_no = 1;
581
    my $sequence_no = 1;
560
    my $lsq_field   = C4::Context->preference('EdifactLSQ');
582
    my $lsq_field   = C4::Context->preference('EdifactLSQ');
583
    my $lsl_field   = C4::Context->preference('EdifactLSL');
561
    foreach my $item (@onorderitems) {
584
    foreach my $item (@onorderitems) {
562
        my $elements_added = 0;
585
        my $elements_added = 0;
563
        my @gir_elements;
586
        my @gir_elements;
Lines 573-582 sub gir_segments { Link Here
573
            push @gir_elements,
596
            push @gir_elements,
574
                { identity_number => 'LST', data => $item->{itype} };
597
                { identity_number => 'LST', data => $item->{itype} };
575
        }
598
        }
576
        if ( $item->{$lsq_field} ) {
599
600
        # Handle LSQ mapping
601
        if ( $lsq_field && $item->{$lsq_field} ) {
577
            push @gir_elements,
602
            push @gir_elements,
578
                { identity_number => 'LSQ', data => $item->{$lsq_field} };
603
                { identity_number => 'LSQ', data => $item->{$lsq_field} };
579
        }
604
        }
605
606
        # Handle LSL mapping
607
        if ( $lsl_field && $item->{$lsl_field} ) {
608
            push @gir_elements,
609
                { identity_number => 'LSL', data => $item->{$lsl_field} };
610
        }
580
        if ( $item->{itemcallnumber} ) {
611
        if ( $item->{itemcallnumber} ) {
581
            push @gir_elements,
612
            push @gir_elements,
582
                { identity_number => 'LSM', data => $item->{itemcallnumber} };
613
                { identity_number => 'LSM', data => $item->{itemcallnumber} };
(-)a/installer/data/mysql/atomicupdate/bug_40391.pl (+31 lines)
Line 0 Link Here
1
use Modern::Perl;
2
use Koha::Installer::Output qw(say_warning say_success say_info);
3
4
return {
5
    bug_number  => "40391",
6
    description => "Add EdifactLSL system preference for GIR:LSL (Library Sub-Location) field mapping",
7
    up          => sub {
8
        my ($args) = @_;
9
        my ( $dbh, $out ) = @$args{qw(dbh out)};
10
11
        # Update existing EdifactLSQ preference to include empty option
12
        $dbh->do(
13
            q{
14
            UPDATE systempreferences
15
            SET options = 'location|ccode|', explanation = 'Map EDI sequence code (GIR+LSQ) to Koha Item field, empty to ignore'
16
            WHERE variable = 'EdifactLSQ'
17
        }
18
        );
19
20
        # Add new EdifactLSL preference
21
        $dbh->do(
22
            q{
23
            INSERT IGNORE INTO systempreferences (variable, value, options, explanation, type)
24
            VALUES ('EdifactLSL', '', 'location|ccode|', 'Map EDI sub-location code (GIR+LSL) to Koha Item field, empty to ignore', 'Choice')
25
        }
26
        );
27
28
        say_success( $out, "Updated EdifactLSQ system preference to include empty option" );
29
        say_success( $out, "Added EdifactLSL system preference for GIR:LSL field mapping" );
30
    },
31
};
(-)a/installer/data/mysql/mandatory/sysprefs.sql (-1 / +2 lines)
Lines 236-242 INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` Link Here
236
('EasyAnalyticalRecords','0','','If on, display in the catalogue screens tools to easily setup analytical record relationships','YesNo'),
236
('EasyAnalyticalRecords','0','','If on, display in the catalogue screens tools to easily setup analytical record relationships','YesNo'),
237
('EDIFACT','0',NULL,'Enables EDIFACT acquisitions functions','YesNo'),
237
('EDIFACT','0',NULL,'Enables EDIFACT acquisitions functions','YesNo'),
238
('EdifactInvoiceImport', 'automatic', 'automatic|manual', "If on, don't auto-import EDI invoices, just keep them in the database with the status 'new'", 'Choice'),
238
('EdifactInvoiceImport', 'automatic', 'automatic|manual', "If on, don't auto-import EDI invoices, just keep them in the database with the status 'new'", 'Choice'),
239
('EdifactLSQ', 'location', 'location|ccode', 'Map EDI sequence code (GIR+LSQ) to Koha Item field', 'Choice'),
239
('EdifactLSL', 'ccode', 'location|ccode|', 'Map EDI sub-location code (GIR+LSL) to Koha Item field, empty to ignore', 'Choice'),
240
('EdifactLSQ', 'location', 'location|ccode|', 'Map EDI sequence code (GIR+LSQ) to Koha Item field, empty to ignore', 'Choice'),
240
('ElasticsearchBoostFieldMatch', '0', NULL, 'Add a "match" query to es when searching, will follow indexes chosen in advanced search, or use title-cover for generic keyword or title index search', 'YesNo'),
241
('ElasticsearchBoostFieldMatch', '0', NULL, 'Add a "match" query to es when searching, will follow indexes chosen in advanced search, or use title-cover for generic keyword or title index search', 'YesNo'),
241
('ElasticsearchCrossFields', '1', '', 'Enable "cross_fields" option for searches using Elastic search.', 'YesNo'),
242
('ElasticsearchCrossFields', '1', '', 'Enable "cross_fields" option for searches using Elastic search.', 'YesNo'),
242
('ElasticsearchIndexStatus_authorities', '0', 'Authorities index status', NULL, NULL),
243
('ElasticsearchIndexStatus_authorities', '0', 'Authorities index status', NULL, NULL),
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/acquisitions.pref (-1 / +10 lines)
Lines 185-188 Acquisitions: Link Here
185
              choices:
185
              choices:
186
                location: "location"
186
                location: "location"
187
                ccode: "collection"
187
                ccode: "collection"
188
                "": "ignore"
189
            - " in items."
190
        -
191
            - "Map sub-location code (GIR:LSL) field to "
192
            - pref: EdifactLSL
193
              default: ""
194
              choices:
195
                location: "location"
196
                ccode: "collection"
197
                "": "ignore"
188
            - " in items."
198
            - " in items."
189
- 

Return to bug 40391