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

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