|
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 |
- |
|
|