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

(-)a/Koha/EDI.pm (-9 / +43 lines)
Lines 34-39 use utf8; Link Here
34
use English qw{ -no_match_vars };
34
use English qw{ -no_match_vars };
35
use Business::ISBN;
35
use Business::ISBN;
36
use DateTime;
36
use DateTime;
37
use JSON qw( encode_json );
37
use C4::Context;
38
use C4::Context;
38
use Koha::Database;
39
use Koha::Database;
39
use Koha::DateUtils qw( dt_from_string );
40
use Koha::DateUtils qw( dt_from_string );
Lines 916-932 sub quote_item { Link Here
916
        $order_hash->{line_item_id} = $item->item_number_id;
917
        $order_hash->{line_item_id} = $item->item_number_id;
917
    }
918
    }
918
919
919
    if ( $item->girfield('servicing_instruction') ) {
920
    # Extract servicing instructions (LVT freetext and/or LVC coded)
920
        my $occ = 0;
921
    # Build JSON array structure: [[{type,value},...]]
921
        my $txt = q{};
922
    my @servicing_groups;
922
        my $si;
923
    my @current_group;
923
        while ( $si = $item->girfield( 'servicing_instruction', $occ ) ) {
924
924
            if ($occ) {
925
    # Read LVC (coded) instructions
925
                $txt .= q{: };
926
    my $occ = 0;
927
    my $lvc_val;
928
    while ( $lvc_val = $item->girfield( 'coded_servicing_instruction', $occ ) ) {
929
930
        # Validate against EDIFACT_SI authorized values
931
        my $av = Koha::AuthorisedValues->find(
932
            {
933
                category         => 'EDIFACT_SI',
934
                authorised_value => $lvc_val
926
            }
935
            }
927
            $txt .= $si;
936
        );
928
            ++$occ;
937
        if ($av) {
938
            push @current_group, { type => 'LVC', value => $lvc_val };
939
        } else {
940
            $quote_message->add_to_edifact_errors(
941
                {
942
                    section => "GIR+LVC validation",
943
                    details =>
944
                        "Invalid servicing instruction code '$lvc_val' - not found in EDIFACT_SI authorized values"
945
                }
946
            );
947
            $logger->trace("Invalid servicing instruction code: $lvc_val");
929
        }
948
        }
949
        ++$occ;
950
    }
951
952
    # Read LVT (freetext) instructions
953
    $occ = 0;
954
    my $lvt_val;
955
    while ( $lvt_val = $item->girfield( 'servicing_instruction', $occ ) ) {
956
        push @current_group, { type => 'LVT', value => $lvt_val };
957
        ++$occ;
958
    }
959
960
    # Store as JSON if we have any instructions
961
    if (@current_group) {
962
        push @servicing_groups, \@current_group;
963
        $order_hash->{servicing_instruction} = encode_json( \@servicing_groups );
930
    }
964
    }
931
    if ($order_note) {
965
    if ($order_note) {
932
        $order_hash->{order_vendornote} = $order_note;
966
        $order_hash->{order_vendornote} = $order_note;
(-)a/Koha/Edifact/Order.pm (-10 / +40 lines)
Lines 26-32 use DateTime; Link Here
26
use Readonly qw( Readonly );
26
use Readonly qw( Readonly );
27
use Koha::Database;
27
use Koha::Database;
28
use Koha::DateUtils qw( dt_from_string );
28
use Koha::DateUtils qw( dt_from_string );
29
use C4::Budgets     qw( GetBudget );
29
use Koha::Logger;
30
use C4::Budgets qw( GetBudget );
31
use JSON        qw( decode_json );
30
32
31
use Koha::Acquisition::Orders;
33
use Koha::Acquisition::Orders;
32
34
Lines 429-435 sub order_line { Link Here
429
        }
431
        }
430
    }
432
    }
431
    my $budget    = GetBudget( $orderline->budget_id );
433
    my $budget    = GetBudget( $orderline->budget_id );
432
    my $ol_fields = { budget_code => $budget->{budget_code}, };
434
    my $ol_fields = {
435
        budget_code           => $budget->{budget_code},
436
        servicing_instruction => $orderline->servicing_instruction,
437
    };
433
438
434
    my $item_fields = [];
439
    my $item_fields = [];
435
    for my $item (@items) {
440
    for my $item (@items) {
Lines 613-625 sub gir_segments { Link Here
613
                { identity_number => 'LSM', data => $item->{itemcallnumber} };
618
                { identity_number => 'LSM', data => $item->{itemcallnumber} };
614
        }
619
        }
615
620
616
        # itemcallnumber -> shelfmark
621
        # Servicing instructions (LVT freetext and/or LVC coded)
622
        # Format: JSON array of arrays: [[{type,value},...],[{type,value},...]]
623
        # Each inner array is a group of instructions that work together
617
        if ( $orderfields->{servicing_instruction} ) {
624
        if ( $orderfields->{servicing_instruction} ) {
618
            push @gir_elements,
625
            my $si_data = $orderfields->{servicing_instruction};
619
                {
626
            my $servicing_groups;
620
                identity_number => 'LVT',
627
621
                data            => $orderfields->{servicing_instruction}
628
            eval { $servicing_groups = decode_json($si_data); };
622
                };
629
            if ($@) {
630
                my $logger = Koha::Logger->get( { interface => 'edi' } );
631
                $logger->warn("Failed to parse servicing_instruction JSON: $@");
632
            }
633
634
            # Add all servicing instruction groups
635
            if ( ref $servicing_groups eq 'ARRAY' ) {
636
                foreach my $group (@$servicing_groups) {
637
                    if ( ref $group eq 'ARRAY' ) {
638
                        foreach my $instruction (@$group) {
639
                            if (   ref $instruction eq 'HASH'
640
                                && $instruction->{type}
641
                                && $instruction->{value} )
642
                            {
643
                                push @gir_elements,
644
                                    {
645
                                    identity_number => $instruction->{type},
646
                                    data            => $instruction->{value}
647
                                    };
648
                            }
649
                        }
650
                    }
651
                }
652
            }
623
        }
653
        }
624
        my $e_cnt   = 0;    # count number of elements so we dont exceed 5 per segment
654
        my $e_cnt   = 0;    # count number of elements so we dont exceed 5 per segment
625
        my $copy_no = sprintf 'GIR+%03d', $sequence_no;
655
        my $copy_no = sprintf 'GIR+%03d', $sequence_no;
Lines 627-633 sub gir_segments { Link Here
627
        foreach my $e (@gir_elements) {
657
        foreach my $e (@gir_elements) {
628
            if ( $e_cnt == 5 ) {
658
            if ( $e_cnt == 5 ) {
629
                push @segments, $seg;
659
                push @segments, $seg;
630
                $seg = $copy_no;
660
                $seg   = $copy_no;
661
                $e_cnt = 0;
631
            }
662
            }
632
            $seg .=
663
            $seg .=
633
                add_gir_identity_number( $e->{identity_number}, $e->{data} );
664
                add_gir_identity_number( $e->{identity_number}, $e->{data} );
634
- 

Return to bug 30144