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

(-)a/C4/Items.pm (+2 lines)
Lines 1559-1564 sub PrepareItemrecordDisplay { Link Here
1559
    my $itemrecord;
1559
    my $itemrecord;
1560
    if ($itemnum) {
1560
    if ($itemnum) {
1561
        $itemrecord = C4::Items::GetMarcItem( $bibnum, $itemnum );
1561
        $itemrecord = C4::Items::GetMarcItem( $bibnum, $itemnum );
1562
    }elsif ($defaultvalues && $defaultvalues->{'itemrecord'} ) {
1563
        $itemrecord = $defaultvalues->{'itemrecord'};
1562
    }
1564
    }
1563
    my @loop_data;
1565
    my @loop_data;
1564
1566
(-)a/acqui/neworderempty.pl (+198 lines)
Lines 321-326 if ( not $ordernumber or $biblionumber ) { Link Here
321
    }
321
    }
322
}
322
}
323
323
324
my $usebreedingid = $input->param('use_breedingid');
325
if ( $usebreedingid ) {
326
    my $item_list = staged_items_field( $usebreedingid );
327
    $listprice = $item_list->{'price'};
328
    $budget_id = $item_list->{'budget_id'};
329
    $data->{replacementprice} = $item_list->{'replacementprice'};
330
    $data->{'sort1'} = $item_list->{'sort1'};
331
    $data->{'sort2'} = $item_list->{'sort2'};
332
    $data->{'discount'} = $item_list->{'discount'};
333
    $data->{quantity}       = $item_list->{quantity};
334
    $template->param( item_list => $item_list->{'iteminfos'} );
335
}
336
324
$template->param( catalog_details => \@catalog_details, );
337
$template->param( catalog_details => \@catalog_details, );
325
338
326
my $suggestion;
339
my $suggestion;
Lines 610-612 sub Load_Duplicate { Link Here
610
623
611
  output_html_with_http_headers $input, $cookie, $template->output;
624
  output_html_with_http_headers $input, $cookie, $template->output;
612
}
625
}
626
627
sub staged_items_field {
628
    my ($breedingid) = @_;
629
    my %cellrecord = ();
630
631
    my ($marcrecord, $encoding) = MARCfindbreeding($breedingid);
632
    die("Could not find the selected record in the reservoir, bailing") unless $marcrecord;
633
634
    my $infos = get_infos_syspref('MarcFieldsToOrder', $marcrecord, ['price', 'quantity', 'budget_code', 'discount', 'sort1', 'sort2', 'replacementprice']);
635
    my $price = $infos->{price};
636
    my $replacementprice = $infos->{replacementprice};
637
    my $quantity = $infos->{quantity};
638
    my $budget_code = $infos->{budget_code};
639
    my $discount = $infos->{discount};
640
    my $sort1 = $infos->{sort1};
641
    my $sort2 = $infos->{sort2};
642
    my $budget_id;
643
    if($budget_code) {
644
        my $biblio_budget = GetBudgetByCode($budget_code);
645
        if($biblio_budget) {
646
            $budget_id = $biblio_budget->{budget_id};
647
        }
648
    }
649
    # Items
650
    my @itemlist = ();
651
    my $all_items_quantity = 0;
652
    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']);
653
    if ($alliteminfos != -1) {
654
        foreach my $iteminfos (@$alliteminfos) {
655
            my %itemrecord=(
656
                'homebranch' => _trim( $iteminfos->{homebranch} ),
657
                'holdingbranch' => _trim( $iteminfos->{holdingbranch} ),
658
                'itype' => _trim( $iteminfos->{itype} ),
659
                'itemnotes_nonpublic' => $iteminfos->{nonpublic_note},
660
                'itemnotes' => $iteminfos->{public_note},
661
                'location' => _trim( $iteminfos->{loc} ),
662
                'ccode' => _trim( $iteminfos->{ccode} ),
663
                'notforloan' => _trim( $iteminfos->{notforloan} ),
664
                'uri' => $iteminfos->{uri},
665
                'copynumber' => $iteminfos->{copyno},
666
                'price' => $iteminfos->{price},
667
                'replacementprice' => $iteminfos->{replacementprice},
668
                'itemcallnumber' => $iteminfos->{itemcallnumber},
669
            );
670
671
            my $item_quantity = $iteminfos->{quantity} || 1;
672
673
            for (my $i = 0; $i < $item_quantity; $i++) {
674
                my %defaultvalues=(
675
                    'itemrecord'=> C4::Items::Item2Marc( \%itemrecord),
676
                    'branchcode'=>_trim($iteminfos->{homebranch})
677
                );
678
                $all_items_quantity++;
679
                my $itemprocessed = PrepareItemrecordDisplay('', '', \%defaultvalues , 'ACQ');
680
                push @itemlist, $itemprocessed->{'iteminformation'};
681
            }
682
        }
683
        $cellrecord{'iteminfos'} = \@itemlist;
684
    } else {
685
        $cellrecord{'item_error'} = 1;
686
    }
687
    $cellrecord{price} = $price || '';
688
    $cellrecord{replacementprice} = $replacementprice || '';
689
    $cellrecord{quantity} = $quantity || '';
690
    $cellrecord{budget_id} = $budget_id || '';
691
    $cellrecord{discount} = $discount || '';
692
    $cellrecord{sort1} = $sort1 || '';
693
    $cellrecord{sort2} = $sort2 || '';
694
    unless ($alliteminfos == -1 && scalar(@$alliteminfos) == 0) {
695
        $cellrecord{quantity} = $all_items_quantity;
696
    }
697
698
    return (\%cellrecord);
699
}
700
701
sub get_infos_syspref {
702
    my ($syspref_name, $record, $field_list) = @_;
703
    my $syspref = C4::Context->preference($syspref_name);
704
    $syspref = "$syspref\n\n"; # YAML is anal on ending \n. Surplus does not hurt
705
    my $yaml = eval {
706
        YAML::Load($syspref);
707
    };
708
    if ( $@ ) {
709
        warn "Unable to parse $syspref syspref : $@";
710
        return ();
711
    }
712
    my $r;
713
    for my $field_name ( @$field_list ) {
714
        next unless exists $yaml->{$field_name};
715
        my @fields = split /\|/, $yaml->{$field_name};
716
        for my $field ( @fields ) {
717
            my ( $f, $sf ) = split /\$/, $field;
718
            next unless $f and $sf;
719
            if ( my $v = $record->subfield( $f, $sf ) ) {
720
                $r->{$field_name} = $v;
721
            }
722
            last if $yaml->{$field};
723
        }
724
    }
725
    return $r;
726
}
727
728
sub equal_number_of_fields {
729
    my ($tags_list, $record) = @_;
730
    my $tag_fields_count;
731
    for my $tag (@$tags_list) {
732
        my @fields = $record->field($tag);
733
        $tag_fields_count->{$tag} = scalar @fields;
734
    }
735
736
    my $tags_count;
737
    foreach my $key ( keys %$tag_fields_count ) {
738
        if ( $tag_fields_count->{$key} > 0 ) { # Having 0 of a field is ok
739
            $tags_count //= $tag_fields_count->{$key}; # Start with the count from the first occurrence
740
            return -1 if $tag_fields_count->{$key} != $tags_count; # All counts of various fields should be equal if they exist
741
        }
742
    }
743
744
    return $tags_count;
745
}
746
747
sub get_infos_syspref_on_item {
748
    my ($syspref_name, $record, $field_list) = @_;
749
    my $syspref = C4::Context->preference($syspref_name);
750
    $syspref = "$syspref\n\n"; # YAML is anal on ending \n. Surplus does not hurt
751
    my $yaml = eval {
752
        YAML::Load($syspref);
753
    };
754
    if ( $@ ) {
755
        warn "Unable to parse $syspref syspref : $@";
756
        return ();
757
    }
758
    my @result;
759
    my @tags_list;
760
761
    # Check tags in syspref definition
762
    for my $field_name ( @$field_list ) {
763
        next unless exists $yaml->{$field_name};
764
        my @fields = split /\|/, $yaml->{$field_name};
765
        for my $field ( @fields ) {
766
            my ( $f, $sf ) = split /\$/, $field;
767
            next unless $f and $sf;
768
            push @tags_list, $f;
769
        }
770
    }
771
    @tags_list = List::MoreUtils::uniq(@tags_list);
772
773
    my $tags_count = equal_number_of_fields(\@tags_list, $record);
774
    # Return if the number of these fields in the record is not the same.
775
    return -1 if $tags_count == -1;
776
777
    # Gather the fields
778
    my $fields_hash;
779
    foreach my $tag (@tags_list) {
780
        my @tmp_fields;
781
        foreach my $field ($record->field($tag)) {
782
            push @tmp_fields, $field;
783
        }
784
        $fields_hash->{$tag} = \@tmp_fields;
785
    }
786
787
    for (my $i = 0; $i < $tags_count; $i++) {
788
        my $r;
789
        for my $field_name ( @$field_list ) {
790
            next unless exists $yaml->{$field_name};
791
            my @fields = split /\|/, $yaml->{$field_name};
792
            for my $field ( @fields ) {
793
                my ( $f, $sf ) = split /\$/, $field;
794
                next unless $f and $sf;
795
                my $v = $fields_hash->{$f}[$i] ? $fields_hash->{$f}[$i]->subfield( $sf ) : undef;
796
                $r->{$field_name} = $v if (defined $v);
797
                last if $yaml->{$field};
798
            }
799
        }
800
        push @result, $r;
801
    }
802
    return \@result;
803
}
804
805
sub _trim {
806
    return $_[0] unless $_[0];
807
    $_[0] =~ s/^\s+//;
808
    $_[0] =~ s/\s+$//;
809
    $_[0];
810
}
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/neworderempty.tt (-2 / +67 lines)
Lines 5-10 Link Here
5
[% USE Price %]
5
[% USE Price %]
6
[% USE ItemTypes %]
6
[% USE ItemTypes %]
7
[% SET footerjs = 1 %]
7
[% SET footerjs = 1 %]
8
9
[% IF item_list %]
10
    [% SET footerjs = 0 %]
11
[% END %]
12
8
[% INCLUDE 'doc-head-open.inc' %]
13
[% INCLUDE 'doc-head-open.inc' %]
9
<title>[% IF ( ordernumber ) %]Modify order details (line #[% ordernumber | html %])[% ELSE %]New order[% END %] &rsaquo; Basket [% basketno | html %] &rsaquo; Acquisitions &rsaquo; Koha</title>
14
<title>[% IF ( ordernumber ) %]Modify order details (line #[% ordernumber | html %])[% ELSE %]New order[% END %] &rsaquo; Basket [% basketno | html %] &rsaquo; Acquisitions &rsaquo; Koha</title>
10
[% INCLUDE 'doc-head-close.inc' %]
15
[% INCLUDE 'doc-head-close.inc' %]
Lines 319-325 Link Here
319
              <div class="dialog message">The autoBarcode system preference is set to [% Koha.Preference('autoBarcode') | html %] and items with blank barcodes will have barcodes generated upon save to database</div>
324
              <div class="dialog message">The autoBarcode system preference is set to [% Koha.Preference('autoBarcode') | html %] and items with blank barcodes will have barcodes generated upon save to database</div>
320
          [% END %]
325
          [% END %]
321
326
322
          <div id="outeritemblock"></div>
327
          <div id="outeritemblock">
328
              [% FOREACH item IN item_list %]
329
                [% SET itemID = loop.count %]
330
                <div id="itemblock[% itemID | html %]" >
331
                    <ol>
332
                        [% FOREACH iteminfo IN item %]
333
                            [% IF ( iteminfo.hidden ) %]
334
                                <li style="[% iteminfo.hidden | html %];">
335
                            [% ELSE %]
336
                                <li>
337
                            [% END %]
338
                            <div class="subfield_line" id="subfield[% iteminfo.serialid | html %][% iteminfo.countitems | html %][% iteminfo.subfield | html %][% iteminfo.random | html %]">
339
                                [% IF (iteminfo.mandatory) %]
340
                                    <label class="required">[% iteminfo.subfield | html %] - [% iteminfo.marc_lib | $raw %]</label>
341
                                [% ELSE %]
342
                                    <label>[% iteminfo.subfield | html %] - [% iteminfo.marc_lib | $raw %]</label>
343
                                [% END %]
344
                                [% IF ( iteminfo.marc_value.type == 'select' ) %]
345
                                    <select name="field_value" size="1">
346
                                        [% FOREACH value IN iteminfo.marc_value.values %]
347
                                            [% IF ( value == iteminfo.marc_value.default ) %]
348
                                                <option value="[% value | html %]" selected="selected">[% iteminfo.marc_value.labels.$value | html %]</option>
349
                                            [% ELSE %]
350
                                                <option value="[% value | html %]">[% iteminfo.marc_value.labels.$value | html %]</option>
351
                                            [% END %]
352
                                        [% END %]
353
                                    </select>
354
                                [% ELSE %]
355
                                    [% iteminfo.marc_value | $raw %]
356
                                [% END %]
357
                                <input type="hidden" name="itemid" value="[% itemID | html %]" />
358
                                <input type="hidden" name="kohafield" value="[% iteminfo.kohafield | html %]" />
359
                                <input type="hidden" name="tag" value="[% iteminfo.tag | html %]" />
360
                                <input type="hidden" name="subfield" value="[% iteminfo.subfield | html %]" />
361
                                <input type="hidden" name="mandatory" value="[% iteminfo.mandatory | html %]" />
362
                                [% IF (iteminfo.mandatory) %] <span class="required">Required</span>[% END %]
363
                            </div>
364
                                </li>
365
                        [% END %]
366
                    </ol>
367
                    <fieldset class="action">
368
                        <input class="addItemControl" name="buttonPlus" style="cursor:pointer; margin:0 1em;" onclick="addItem(this,'[% UniqueItemFields | html %]')" value="Add item" type="button">
369
                        <input class="addItemControl cancel" name="buttonClear" style="cursor:pointer;" onclick="clearItemBlock(this)" value="Clear" type="button">
370
                        <input class="addItemControl" name="buttonPlusMulti" onclick="javascript:this.nextElementSibling.style.display='inline'; return false;" style="cursor:pointer; margin:0 1em;" value="Add multiple items" type="button">
371
                        <span id="add_multiple_copies" style="display:none">
372
                            <input class="addItemControl" id="multiValue" name="multiValue" placeholder="Number of items to add" type="number">
373
                            <input class="addItemControl" name="buttonAddMulti&quot;" style="cursor:pointer; margin:0 1em;" onclick="checkCount( this ,'[% UniqueItemFields | html %]')" value="Add" type="button">
374
                            <div class="dialog message">NOTE: Fields listed in the 'UniqueItemsFields' system preference will not be copied</div>
375
                        </span>
376
                    </fieldset>
377
                </div>
378
            [% END %]
379
          </div>
323
380
324
      </fieldset>
381
      </fieldset>
325
      [% END %][%# | html UNLESS subscriptionid %]
382
      [% END %][%# | html UNLESS subscriptionid %]
Lines 617-623 Link Here
617
        }
674
        }
618
675
619
        $(document).ready(function(){
676
        $(document).ready(function(){
620
            [% IF AcqCreateItemOrdering and not basket.is_standing %]
677
            var events = $('#outeritemblock > div').filter(function () {
678
                var el = BindPluginEvents(this.innerHTML);
679
                return el;
680
            });
681
682
            [% IF AcqCreateItemOrdering and not basket.is_standing and not item_list %]
621
                cloneItemBlock(0, '[% UniqueItemFields | html %]');
683
                cloneItemBlock(0, '[% UniqueItemFields | html %]');
622
            [% END %]
684
            [% END %]
623
685
Lines 714-719 Link Here
714
    </script>
776
    </script>
715
[% END %]
777
[% END %]
716
778
779
[% UNLESS ( footerjs ) %]
780
    [% jsinclude | $raw # Parse the page template's JavaScript block if necessary %]
781
[% END %]
717
[% INCLUDE 'intranet-bottom.inc' %]
782
[% INCLUDE 'intranet-bottom.inc' %]
718
783
719
[% BLOCK display_subfield %]
784
[% BLOCK display_subfield %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/neworderempty_duplicate.tt (-1 / +2 lines)
Lines 50-55 Link Here
50
<input type="hidden" name="basketno" value="[% basketno | html %]" />
50
<input type="hidden" name="basketno" value="[% basketno | html %]" />
51
<input type="hidden" name="biblionumber" value="[% biblionumber | html %]" />
51
<input type="hidden" name="biblionumber" value="[% biblionumber | html %]" />
52
<input type="submit" value="Use existing" />
52
<input type="submit" value="Use existing" />
53
<input type="hidden" name="use_breedingid" value="[% breedingid | html %]" />
53
</form>
54
</form>
54
</div>
55
</div>
55
</div>
56
</div>
Lines 74-80 Link Here
74
<input type="hidden" name="basketno" value="[% basketno | html %]" />
75
<input type="hidden" name="basketno" value="[% basketno | html %]" />
75
<input type="hidden" name="breedingid" value="[% breedingid | html %]" />
76
<input type="hidden" name="breedingid" value="[% breedingid | html %]" />
76
<input type="hidden" name="use_external_source" value="1" />
77
<input type="hidden" name="use_external_source" value="1" />
77
<input type="submit" value="Create new" />
78
<input type="hidden" name="use_breedingid" value="[% breedingid | html%]" />
78
</form>
79
</form>
79
</div>
80
</div>
80
</div>
81
</div>
(-)a/koha-tmpl/intranet-tmpl/prog/js/additem.js (-2 / +1 lines)
Lines 11-17 function addItem( node, unique_item_fields ) { Link Here
11
    }
11
    }
12
    if ( $("#items_list table").find('tr[idblock="' + index + '"]').length == 0 ) {
12
    if ( $("#items_list table").find('tr[idblock="' + index + '"]').length == 0 ) {
13
        if ( current_qty < max_qty ) {
13
        if ( current_qty < max_qty ) {
14
            if ( current_qty < max_qty - 1 )
14
            if ( current_qty < max_qty - 1 && $('#outeritemblock > div:visible').length == 1 )
15
                cloneItemBlock(index, unique_item_fields);
15
                cloneItemBlock(index, unique_item_fields);
16
            addItemInList(index, unique_item_fields);
16
            addItemInList(index, unique_item_fields);
17
            $("#" + index).find("input[name='buttonPlus']").val( __("Update item") );
17
            $("#" + index).find("input[name='buttonPlus']").val( __("Update item") );
18
- 

Return to bug 20817