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

(-)a/C4/Items.pm (+2 lines)
Lines 2459-2464 sub PrepareItemrecordDisplay { Link Here
2459
    my $itemrecord;
2459
    my $itemrecord;
2460
    if ($itemnum) {
2460
    if ($itemnum) {
2461
        $itemrecord = C4::Items::GetMarcItem( $bibnum, $itemnum );
2461
        $itemrecord = C4::Items::GetMarcItem( $bibnum, $itemnum );
2462
    }elsif ($defaultvalues && $defaultvalues->{'itemrecord'} ) {
2463
        $itemrecord = $defaultvalues->{'itemrecord'};
2462
    }
2464
    }
2463
    my @loop_data;
2465
    my @loop_data;
2464
2466
(-)a/acqui/neworderempty.pl (+191 lines)
Lines 306-311 if ( not $ordernumber or $biblionumber ) { Link Here
306
    }
306
    }
307
}
307
}
308
308
309
our $usebreedingid = $input->param('use_breedingid');
310
if ( $usebreedingid ) {
311
    my $item_list = staged_items_field( $usebreedingid );
312
    $listprice = $item_list->{'price'};
313
    $template->param( item_list => $item_list->{'iteminfos'} );
314
}
315
309
$template->param( catalog_details => \@catalog_details, );
316
$template->param( catalog_details => \@catalog_details, );
310
317
311
my $suggestion;
318
my $suggestion;
Lines 599-601 sub Load_Duplicate { Link Here
599
606
600
  output_html_with_http_headers $input, $cookie, $template->output;
607
  output_html_with_http_headers $input, $cookie, $template->output;
601
}
608
}
609
610
sub staged_items_field {
611
    my ($breedingid) = @_;
612
    my %cellrecord = ();
613
614
    my ($marcrecord, $encoding) = MARCfindbreeding($breedingid);
615
    die("Could not find the selected record in the reservoir, bailing") unless $marcrecord;
616
617
    my $infos = get_infos_syspref('MarcFieldsToOrder', $marcrecord, ['price', 'quantity', 'budget_code', 'discount', 'sort1', 'sort2']);
618
    my $price = $infos->{price};
619
    my $quantity = $infos->{quantity};
620
    my $budget_code = $infos->{budget_code};
621
    my $discount = $infos->{discount};
622
    my $sort1 = $infos->{sort1};
623
    my $sort2 = $infos->{sort2};
624
    my $budget_id;
625
    if($budget_code) {
626
        my $biblio_budget = GetBudgetByCode($budget_code);
627
        if($biblio_budget) {
628
            $budget_id = $biblio_budget->{budget_id};
629
        }
630
    }
631
    # Items
632
    my @itemlist = ();
633
    my $all_items_quantity = 0;
634
    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']);
635
    if ($alliteminfos != -1) {
636
        foreach my $iteminfos (@$alliteminfos) {
637
            my %itemrecord=(
638
                'homebranch' => _trim( $iteminfos->{homebranch} ),
639
                'holdingbranch' => _trim( $iteminfos->{holdingbranch} ),
640
                'itype' => _trim( $iteminfos->{itype} ),
641
                'itemnotes_nonpublic' => $iteminfos->{nonpublic_note},
642
                'itemnotes' => $iteminfos->{public_note},
643
                'location' => _trim( $iteminfos->{loc} ),
644
                'ccode' => _trim( $iteminfos->{ccode} ),
645
                'notforloan' => _trim( $iteminfos->{notforloan} ),
646
                'uri' => $iteminfos->{uri},
647
                'copynumber' => $iteminfos->{copyno},
648
                'price' => $iteminfos->{price},
649
                'replacementprice' => $iteminfos->{replacementprice},
650
                'itemcallnumber' => $iteminfos->{itemcallnumber},
651
            );
652
653
            my $item_quantity = $iteminfos->{quantity} || 1;
654
655
            for (my $i = 0; $i < $item_quantity; $i++) {
656
                my %defaultvalues=(
657
                    'itemrecord'=> C4::Items::Item2Marc( \%itemrecord),
658
                    'branchcode'=>_trim($iteminfos->{homebranch})
659
                );
660
                $all_items_quantity++;
661
                my $itemprocessed = PrepareItemrecordDisplay('', '', \%defaultvalues , 'ACQ');
662
                push @itemlist, $itemprocessed->{'iteminformation'};
663
664
            }
665
        }
666
667
        $cellrecord{'iteminfos'} = \@itemlist;
668
    } else {
669
        $cellrecord{'item_error'} = 1;
670
    }
671
    $cellrecord{price} = $price || '';
672
    $cellrecord{quantity} = $quantity || '';
673
    $cellrecord{budget_id} = $budget_id || '';
674
    $cellrecord{discount} = $discount || '';
675
    $cellrecord{sort1} = $sort1 || '';
676
    $cellrecord{sort2} = $sort2 || '';
677
    unless ($alliteminfos == -1 && scalar(@$alliteminfos) == 0) {
678
        $cellrecord{quantity} = $all_items_quantity;
679
    }
680
681
    return (\%cellrecord);
682
}
683
684
sub get_infos_syspref {
685
    my ($syspref_name, $record, $field_list) = @_;
686
    my $syspref = C4::Context->preference($syspref_name);
687
    $syspref = "$syspref\n\n"; # YAML is anal on ending \n. Surplus does not hurt
688
    my $yaml = eval {
689
        YAML::Load($syspref);
690
    };
691
    if ( $@ ) {
692
        warn "Unable to parse $syspref syspref : $@";
693
        return ();
694
    }
695
    my $r;
696
    for my $field_name ( @$field_list ) {
697
        next unless exists $yaml->{$field_name};
698
        my @fields = split /\|/, $yaml->{$field_name};
699
        for my $field ( @fields ) {
700
            my ( $f, $sf ) = split /\$/, $field;
701
            next unless $f and $sf;
702
            if ( my $v = $record->subfield( $f, $sf ) ) {
703
                $r->{$field_name} = $v;
704
            }
705
            last if $yaml->{$field};
706
        }
707
    }
708
    return $r;
709
}
710
sub equal_number_of_fields {
711
    my ($tags_list, $record) = @_;
712
    my $tag_fields_count;
713
    for my $tag (@$tags_list) {
714
        my @fields = $record->field($tag);
715
        $tag_fields_count->{$tag} = scalar @fields;
716
    }
717
718
    my $tags_count;
719
    foreach my $key ( keys %$tag_fields_count ) {
720
        if ( $tag_fields_count->{$key} > 0 ) { # Having 0 of a field is ok
721
            $tags_count //= $tag_fields_count->{$key}; # Start with the count from the first occurrence
722
            return -1 if $tag_fields_count->{$key} != $tags_count; # All counts of various fields should be equal if they exist
723
        }
724
    }
725
726
    return $tags_count;
727
}
728
729
sub get_infos_syspref_on_item {
730
    my ($syspref_name, $record, $field_list) = @_;
731
    my $syspref = C4::Context->preference($syspref_name);
732
    $syspref = "$syspref\n\n"; # YAML is anal on ending \n. Surplus does not hurt
733
    my $yaml = eval {
734
        YAML::Load($syspref);
735
    };
736
    if ( $@ ) {
737
        warn "Unable to parse $syspref syspref : $@";
738
        return ();
739
    }
740
    my @result;
741
    my @tags_list;
742
743
    # Check tags in syspref definition
744
    for my $field_name ( @$field_list ) {
745
        next unless exists $yaml->{$field_name};
746
        my @fields = split /\|/, $yaml->{$field_name};
747
        for my $field ( @fields ) {
748
            my ( $f, $sf ) = split /\$/, $field;
749
            next unless $f and $sf;
750
            push @tags_list, $f;
751
        }
752
    }
753
    @tags_list = List::MoreUtils::uniq(@tags_list);
754
755
    my $tags_count = equal_number_of_fields(\@tags_list, $record);
756
    # Return if the number of these fields in the record is not the same.
757
    return -1 if $tags_count == -1;
758
759
    # Gather the fields
760
    my $fields_hash;
761
    foreach my $tag (@tags_list) {
762
        my @tmp_fields;
763
        foreach my $field ($record->field($tag)) {
764
            push @tmp_fields, $field;
765
        }
766
        $fields_hash->{$tag} = \@tmp_fields;
767
    }
768
769
    for (my $i = 0; $i < $tags_count; $i++) {
770
        my $r;
771
        for my $field_name ( @$field_list ) {
772
            next unless exists $yaml->{$field_name};
773
            my @fields = split /\|/, $yaml->{$field_name};
774
            for my $field ( @fields ) {
775
                my ( $f, $sf ) = split /\$/, $field;
776
                next unless $f and $sf;
777
                my $v = $fields_hash->{$f}[$i] ? $fields_hash->{$f}[$i]->subfield( $sf ) : undef;
778
                $r->{$field_name} = $v if (defined $v);
779
                last if $yaml->{$field};
780
            }
781
        }
782
        push @result, $r;
783
    }
784
    return \@result;
785
}
786
787
sub _trim {
788
    return $_[0] unless $_[0];
789
    $_[0] =~ s/^\s+//;
790
    $_[0] =~ s/\s+$//;
791
    $_[0];
792
}
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/neworderempty.tt (-2 / +67 lines)
Lines 4-9 Link Here
4
[% USE KohaDates %]
4
[% USE KohaDates %]
5
[% USE Price %]
5
[% USE Price %]
6
[% SET footerjs = 1 %]
6
[% SET footerjs = 1 %]
7
8
[% IF item_list %]
9
    [% SET footerjs = 0 %]
10
[% END %]
11
7
[% INCLUDE 'doc-head-open.inc' %]
12
[% INCLUDE 'doc-head-open.inc' %]
8
<title>Koha &rsaquo; Acquisitions &rsaquo; Basket [% basketno | html %] &rsaquo; [% IF ( ordernumber ) %]Modify order details (line #[% ordernumber | html %])[% ELSE %]New order[% END %]</title>
13
<title>Koha &rsaquo; Acquisitions &rsaquo; Basket [% basketno | html %] &rsaquo; [% IF ( ordernumber ) %]Modify order details (line #[% ordernumber | html %])[% ELSE %]New order[% END %]</title>
9
[% INCLUDE 'doc-head-close.inc' %]
14
[% INCLUDE 'doc-head-close.inc' %]
Lines 288-294 Link Here
288
              <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>
293
              <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>
289
          [% END %]
294
          [% END %]
290
295
291
          <div id="outeritemblock"></div>
296
          <div id="outeritemblock">
297
              [% FOREACH item IN item_list %]
298
                [% SET itemID = loop.count %]
299
                <div id="itemblock[% itemID %]" >
300
                    <ol>
301
                        [% FOREACH iteminfo IN item %]
302
                            [% IF ( iteminfo.hidden ) %]
303
                                <li style="[% iteminfo.hidden %];">
304
                            [% ELSE %]
305
                                <li>
306
                            [% END %]
307
                            <div class="subfield_line" id="subfield[% iteminfo.serialid %][% iteminfo.countitems %][% iteminfo.subfield %][% iteminfo.random %]">
308
                                [% IF (iteminfo.mandatory) %]
309
                                    <label class="required">[% iteminfo.subfield %] - [% iteminfo.marc_lib %]</label>
310
                                [% ELSE %]
311
                                    <label>[% iteminfo.subfield %] - [% iteminfo.marc_lib %]</label>
312
                                [% END %]
313
                                [% IF ( iteminfo.marc_value.type == 'select' ) %]
314
                                    <select name="field_value" size="1">
315
                                        [% FOREACH value IN iteminfo.marc_value.values %]
316
                                            [% IF ( value == iteminfo.marc_value.default ) %]
317
                                                <option value="[% value %]" selected="selected">[% iteminfo.marc_value.labels.$value %]</option>
318
                                            [% ELSE %]
319
                                                <option value="[% value %]">[% iteminfo.marc_value.labels.$value %]</option>
320
                                            [% END %]
321
                                        [% END %]
322
                                    </select>
323
                                [% ELSE %]
324
                                    [% iteminfo.marc_value %]
325
                                [% END %]
326
                                <input type="hidden" name="itemid" value="[% itemID %]" />
327
                                <input type="hidden" name="kohafield" value="[% iteminfo.kohafield %]" />
328
                                <input type="hidden" name="tag" value="[% iteminfo.tag %]" />
329
                                <input type="hidden" name="subfield" value="[% iteminfo.subfield %]" />
330
                                <input type="hidden" name="mandatory" value="[% iteminfo.mandatory %]" />
331
                                [% IF (iteminfo.mandatory) %] <span class="required">Required</span>[% END %]
332
                            </div>
333
                            </li>
334
                        [% END %]
335
                    </ol>
336
                    <fieldset class="action">
337
                        <input class="addItemControl" name="buttonPlus" style="cursor:pointer; margin:0 1em;" onclick="addItem(this,'[% UniqueItemFields %]')" value="Add item" type="button">
338
                        <input class="addItemControl cancel" name="buttonClear" style="cursor:pointer;" onclick="clearItemBlock(this)" value="Clear" type="button">
339
                        <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">
340
                        <span id="add_multiple_copies" style="display:none">
341
                            <input class="addItemControl" id="multiValue" name="multiValue" placeholder="Number of items to add" type="number">
342
                            <input class="addItemControl" name="buttonAddMulti&quot;" style="cursor:pointer; margin:0 1em;" onclick="checkCount( this ,'[% UniqueItemFields %]')" value="Add" type="button">
343
                            <div class="dialog message">NOTE: Fields listed in the 'UniqueItemsFields' system preference will not be copied</div>
344
                        </span>
345
                    </fieldset>
346
                </div>
347
                [% END %]
348
          </div>
292
349
293
      </fieldset>
350
      </fieldset>
294
      [% END %][%# | html UNLESS subscriptionid %]
351
      [% END %][%# | html UNLESS subscriptionid %]
Lines 611-617 Link Here
611
        }
668
        }
612
669
613
        $(document).ready(function(){
670
        $(document).ready(function(){
614
            [% IF AcqCreateItemOrdering and not basket.is_standing %]
671
            var events = $('#outeritemblock > div').filter(function () {
672
                var el = BindPluginEvents(this.innerHTML);
673
                return el;
674
            });
675
676
            [% IF AcqCreateItemOrdering and not basket.is_standing and not item_list %]
615
                cloneItemBlock(0, '[% UniqueItemFields | html %]');
677
                cloneItemBlock(0, '[% UniqueItemFields | html %]');
616
            [% END %]
678
            [% END %]
617
679
Lines 708-713 Link Here
708
    </script>
770
    </script>
709
[% END %]
771
[% END %]
710
772
773
[% UNLESS ( footerjs ) %]
774
    [% jsinclude # Parse the page template's JavaScript block if necessary %]
775
[% END %]
711
[% INCLUDE 'intranet-bottom.inc' %]
776
[% INCLUDE 'intranet-bottom.inc' %]
712
777
713
[% BLOCK display_subfield %]
778
[% BLOCK display_subfield %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/neworderempty_duplicate.tt (+2 lines)
Lines 31-36 Link Here
31
<input type="hidden" name="booksellerid" value="[% booksellerid | html %]" />
31
<input type="hidden" name="booksellerid" value="[% booksellerid | html %]" />
32
<input type="hidden" name="basketno" value="[% basketno | html %]" />
32
<input type="hidden" name="basketno" value="[% basketno | html %]" />
33
<input type="hidden" name="biblionumber" value="[% biblionumber | html %]" />
33
<input type="hidden" name="biblionumber" value="[% biblionumber | html %]" />
34
<input type="hidden" name="use_breedingid" value="[% breedingid | html %]" />
34
<input type="submit" value="Use Existing" />
35
<input type="submit" value="Use Existing" />
35
</form>
36
</form>
36
</div>
37
</div>
Lines 56-61 Link Here
56
<input type="hidden" name="basketno" value="[% basketno | html %]" />
57
<input type="hidden" name="basketno" value="[% basketno | html %]" />
57
<input type="hidden" name="breedingid" value="[% breedingid | html %]" />
58
<input type="hidden" name="breedingid" value="[% breedingid | html %]" />
58
<input type="hidden" name="use_external_source" value="1" />
59
<input type="hidden" name="use_external_source" value="1" />
60
<input type="hidden" name="use_breedingid" value="[% breedingid | html%]" />
59
<input type="submit" value="Create New" />
61
<input type="submit" value="Create New" />
60
</form>
62
</form>
61
</div>
63
</div>
(-)a/koha-tmpl/intranet-tmpl/prog/js/additem.js (-2 / +1 lines)
Lines 9-15 function addItem( node, unique_item_fields ) { Link Here
9
    }
9
    }
10
    if ( $("#items_list table").find('tr[idblock="' + index + '"]').length == 0 ) {
10
    if ( $("#items_list table").find('tr[idblock="' + index + '"]').length == 0 ) {
11
        if ( current_qty < max_qty ) {
11
        if ( current_qty < max_qty ) {
12
            if ( current_qty < max_qty - 1 )
12
            if ( current_qty < max_qty - 1 && $('#outeritemblock > div:visible').length == 1 )
13
                cloneItemBlock(index, unique_item_fields);
13
                cloneItemBlock(index, unique_item_fields);
14
            addItemInList(index, unique_item_fields);
14
            addItemInList(index, unique_item_fields);
15
            $("#" + index).find("input[name='buttonPlus']").val( (window.MSG_ADDITEM_JS_UPDATEITEM ) );
15
            $("#" + index).find("input[name='buttonPlus']").val( (window.MSG_ADDITEM_JS_UPDATEITEM ) );
16
- 

Return to bug 20817