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

(-)a/acqui/addorderiso2709.pl (-56 / +30 lines)
Lines 503-511 sub import_biblios_list { Link Here
503
        my $sort1 = $infos->{sort1};
503
        my $sort1 = $infos->{sort1};
504
        my $sort2 = $infos->{sort2};
504
        my $sort2 = $infos->{sort2};
505
        my $budget_id;
505
        my $budget_id;
506
        if($budget_code) {
506
507
        if ($budget_code) {
507
            my $biblio_budget = GetBudgetByCode($budget_code);
508
            my $biblio_budget = GetBudgetByCode($budget_code);
508
            if($biblio_budget) {
509
            if ($biblio_budget) {
509
                $budget_id = $biblio_budget->{budget_id};
510
                $budget_id = $biblio_budget->{budget_id};
510
            }
511
            }
511
        }
512
        }
Lines 513-568 sub import_biblios_list { Link Here
513
        # Items
514
        # Items
514
        my @itemlist = ();
515
        my @itemlist = ();
515
        my $all_items_quantity = 0;
516
        my $all_items_quantity = 0;
516
        my $alliteminfos = get_infos_syspref_on_item('MarcItemFieldsToOrder', $marcrecord, ['homebranch', 'holdingbranch', 'itype', 'nonpublic_note', 'public_note', 'loc', 'ccode', 'notforloan', 'uri', 'copyno', 'price', 'replacementprice', 'itemcallnumber', 'quantity', 'budget_code']);
517
        my $alliteminfos = get_marc_item_fields_to_order($marcrecord);
517
        if ($alliteminfos != -1) {
518
        if ($alliteminfos != -1) {
518
            foreach my $iteminfos (@$alliteminfos) {
519
            foreach my $iteminfos (@$alliteminfos) {
519
                my $item_homebranch = $iteminfos->{homebranch};
520
                # Quantity is required, default to one if not supplied
520
                my $item_holdingbranch = $iteminfos->{holdingbranch};
521
                my $quantity = delete $iteminfos->{quantity} || 1;
521
                my $item_itype = $iteminfos->{itype};
522
522
                my $item_nonpublic_note = $iteminfos->{nonpublic_note};
523
                # Handle incorrectly named original parameters for MarcItemFieldsToOrder
523
                my $item_public_note = $iteminfos->{public_note};
524
                $iteminfos->{location}   = delete $iteminfos->{loc}    if $iteminfos->{loc};
524
                my $item_loc = $iteminfos->{loc};
525
                $iteminfos->{copynumber} = delete $iteminfos->{copyno} if $iteminfos->{copyno};
525
                my $item_ccode = $iteminfos->{ccode};
526
526
                my $item_notforloan = $iteminfos->{notforloan};
527
                # Convert budge code to a budget id
527
                my $item_uri = $iteminfos->{uri};
528
                my $item_budget_code = delete $iteminfos->{budget_code};
528
                my $item_copyno = $iteminfos->{copyno};
529
                if ( $item_budget_code ) {
529
                my $item_quantity = $iteminfos->{quantity} || 1;
530
                    my $item_budget = GetBudgetByCode( $item_budget_code );
530
                my $item_budget_code = $iteminfos->{budget_code};
531
                    $iteminfos->{budget_id} = $item_budget->{budget_id} || $budget_id;
531
                my $item_budget_id;
532
                if ( $iteminfos->{budget_code} ) {
533
                    my $item_budget = GetBudgetByCode( $iteminfos->{budget_code} );
534
                    if ( $item_budget ) {
535
                        $item_budget_id = $item_budget->{budget_id};
536
                    }
537
                }
532
                }
538
                my $item_price = $iteminfos->{price};
539
                my $item_replacement_price = $iteminfos->{replacementprice};
540
                my $item_callnumber = $iteminfos->{itemcallnumber};
541
542
                for (my $i = 0; $i < $item_quantity; $i++) {
543
544
                    my %itemrecord = (
545
                        'item_id' => $item_id++,
546
                        'biblio_count' => $biblio_count,
547
                        'homebranch' => $item_homebranch,
548
                        'holdingbranch' => $item_holdingbranch,
549
                        'itype' => $item_itype,
550
                        'nonpublic_note' => $item_nonpublic_note,
551
                        'public_note' => $item_public_note,
552
                        'loc' => $item_loc,
553
                        'ccode' => $item_ccode,
554
                        'notforloan' => $item_notforloan,
555
                        'uri' => $item_uri,
556
                        'copyno' => $item_copyno,
557
                        'quantity' => $item_quantity,
558
                        'budget_id' => $item_budget_id || $budget_id,
559
                        'itemprice' => $item_price || $price,
560
                        'replacementprice' => $item_replacement_price || $replacementprice,
561
                        'itemcallnumber' => $item_callnumber,
562
                    );
563
                    $all_items_quantity++;
564
                    push @itemlist, \%itemrecord;
565
533
534
                # Clone the item data for the needed quantity
535
                # Add the incremented item id for each item in that quantity
536
                for (my $i = 0; $i < $quantity; $i++) {
537
                    my $itemrecord = { %$iteminfos };
538
                    $itemrecord->{item_id} = $item_id++;
539
                    $all_items_quantity++;
540
                    push @itemlist, $itemrecord;
566
                }
541
                }
567
            }
542
            }
568
543
Lines 695-703 sub equal_number_of_fields { Link Here
695
    return $tags_count;
670
    return $tags_count;
696
}
671
}
697
672
698
sub get_infos_syspref_on_item {
673
sub get_marc_item_fields_to_order {
699
    my ($syspref_name, $record, $field_list) = @_;
674
    my ($record) = @_;
700
    my $syspref = C4::Context->preference($syspref_name);
675
676
    my $syspref = C4::Context->preference('MarcItemFieldsToOrder');
701
    $syspref = "$syspref\n\n"; # YAML is anal on ending \n. Surplus does not hurt
677
    $syspref = "$syspref\n\n"; # YAML is anal on ending \n. Surplus does not hurt
702
    my $yaml = eval {
678
    my $yaml = eval {
703
        YAML::XS::Load(Encode::encode_utf8($syspref));
679
        YAML::XS::Load(Encode::encode_utf8($syspref));
Lines 706-717 sub get_infos_syspref_on_item { Link Here
706
        warn "Unable to parse $syspref syspref : $@";
682
        warn "Unable to parse $syspref syspref : $@";
707
        return ();
683
        return ();
708
    }
684
    }
685
709
    my @result;
686
    my @result;
710
    my @tags_list;
687
    my @tags_list;
711
688
712
    # Check tags in syspref definition
689
    # Check tags in syspref definition
713
    for my $field_name ( @$field_list ) {
690
    for my $field_name ( keys %$yaml ) {
714
        next unless exists $yaml->{$field_name};
715
        my @fields = split /\|/, $yaml->{$field_name};
691
        my @fields = split /\|/, $yaml->{$field_name};
716
        for my $field ( @fields ) {
692
        for my $field ( @fields ) {
717
            my ( $f, $sf ) = split /\$/, $field;
693
            my ( $f, $sf ) = split /\$/, $field;
Lines 737-744 sub get_infos_syspref_on_item { Link Here
737
713
738
    for (my $i = 0; $i < $tags_count; $i++) {
714
    for (my $i = 0; $i < $tags_count; $i++) {
739
        my $r;
715
        my $r;
740
        for my $field_name ( @$field_list ) {
716
        for my $field_name ( keys %$yaml ) {
741
            next unless exists $yaml->{$field_name};
742
            my @fields = split /\|/, $yaml->{$field_name};
717
            my @fields = split /\|/, $yaml->{$field_name};
743
            for my $field ( @fields ) {
718
            for my $field ( @fields ) {
744
                my ( $f, $sf ) = split /\$/, $field;
719
                my ( $f, $sf ) = split /\$/, $field;
745
- 

Return to bug 33170