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

(-)a/C4/Items.pm (+2 lines)
Lines 2362-2367 sub PrepareItemrecordDisplay { Link Here
2362
    my $itemrecord;
2362
    my $itemrecord;
2363
    if ($itemnum) {
2363
    if ($itemnum) {
2364
        $itemrecord = C4::Items::GetMarcItem( $bibnum, $itemnum );
2364
        $itemrecord = C4::Items::GetMarcItem( $bibnum, $itemnum );
2365
    }elsif ($defaultvalues && $defaultvalues->{'itemrecord'} ) {
2366
        $itemrecord = $defaultvalues->{'itemrecord'};
2365
    }
2367
    }
2366
    my @loop_data;
2368
    my @loop_data;
2367
2369
(-)a/acqui/neworderempty.pl (+198 lines)
Lines 304-309 if ( not $ordernumber or $biblionumber ) { Link Here
304
    }
304
    }
305
}
305
}
306
306
307
my $usebreedingid = $input->param('use_breedingid');
308
if ( $usebreedingid ) {
309
    my $item_list = staged_items_field( $usebreedingid );
310
    $listprice = $item_list->{'price'};
311
    $budget_id = $item_list->{'budget_id'};
312
    $data->{replacementprice} = $item_list->{'replacementprice'};
313
    $data->{'sort1'} = $item_list->{'sort1'};
314
    $data->{'sort2'} = $item_list->{'sort2'};
315
    $data->{'discount'} = $item_list->{'discount'};
316
    $data->{quantity}       = $item_list->{quantity};
317
    $template->param( item_list => $item_list->{'iteminfos'} );
318
}
319
307
$template->param( catalog_details => \@catalog_details, );
320
$template->param( catalog_details => \@catalog_details, );
308
321
309
my $suggestion;
322
my $suggestion;
Lines 599-601 sub Load_Duplicate { Link Here
599
612
600
  output_html_with_http_headers $input, $cookie, $template->output;
613
  output_html_with_http_headers $input, $cookie, $template->output;
601
}
614
}
615
616
sub staged_items_field {
617
    my ($breedingid) = @_;
618
    my %cellrecord = ();
619
620
    my ($marcrecord, $encoding) = MARCfindbreeding($breedingid);
621
    die("Could not find the selected record in the reservoir, bailing") unless $marcrecord;
622
623
    my $infos = get_infos_syspref('MarcFieldsToOrder', $marcrecord, ['price', 'quantity', 'budget_code', 'discount', 'sort1', 'sort2', 'replacementprice']);
624
    my $price = $infos->{price};
625
    my $replacementprice = $infos->{replacementprice};
626
    my $quantity = $infos->{quantity};
627
    my $budget_code = $infos->{budget_code};
628
    my $discount = $infos->{discount};
629
    my $sort1 = $infos->{sort1};
630
    my $sort2 = $infos->{sort2};
631
    my $budget_id;
632
    if($budget_code) {
633
        my $biblio_budget = GetBudgetByCode($budget_code);
634
        if($biblio_budget) {
635
            $budget_id = $biblio_budget->{budget_id};
636
        }
637
    }
638
    # Items
639
    my @itemlist = ();
640
    my $all_items_quantity = 0;
641
    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']);
642
    if ($alliteminfos != -1) {
643
        foreach my $iteminfos (@$alliteminfos) {
644
            my %itemrecord=(
645
                'homebranch' => _trim( $iteminfos->{homebranch} ),
646
                'holdingbranch' => _trim( $iteminfos->{holdingbranch} ),
647
                'itype' => _trim( $iteminfos->{itype} ),
648
                'itemnotes_nonpublic' => $iteminfos->{nonpublic_note},
649
                'itemnotes' => $iteminfos->{public_note},
650
                'location' => _trim( $iteminfos->{loc} ),
651
                'ccode' => _trim( $iteminfos->{ccode} ),
652
                'notforloan' => _trim( $iteminfos->{notforloan} ),
653
                'uri' => $iteminfos->{uri},
654
                'copynumber' => $iteminfos->{copyno},
655
                'price' => $iteminfos->{price},
656
                'replacementprice' => $iteminfos->{replacementprice},
657
                'itemcallnumber' => $iteminfos->{itemcallnumber},
658
            );
659
660
            my $item_quantity = $iteminfos->{quantity} || 1;
661
662
            for (my $i = 0; $i < $item_quantity; $i++) {
663
                my %defaultvalues=(
664
                    'itemrecord'=> C4::Items::Item2Marc( \%itemrecord),
665
                    'branchcode'=>_trim($iteminfos->{homebranch})
666
                );
667
                $all_items_quantity++;
668
                my $itemprocessed = PrepareItemrecordDisplay('', '', \%defaultvalues , 'ACQ');
669
                push @itemlist, $itemprocessed->{'iteminformation'};
670
            }
671
        }
672
        $cellrecord{'iteminfos'} = \@itemlist;
673
    } else {
674
        $cellrecord{'item_error'} = 1;
675
    }
676
    $cellrecord{price} = $price || '';
677
    $cellrecord{replacementprice} = $replacementprice || '';
678
    $cellrecord{quantity} = $quantity || '';
679
    $cellrecord{budget_id} = $budget_id || '';
680
    $cellrecord{discount} = $discount || '';
681
    $cellrecord{sort1} = $sort1 || '';
682
    $cellrecord{sort2} = $sort2 || '';
683
    unless ($alliteminfos == -1 && scalar(@$alliteminfos) == 0) {
684
        $cellrecord{quantity} = $all_items_quantity;
685
    }
686
687
    return (\%cellrecord);
688
}
689
690
sub get_infos_syspref {
691
    my ($syspref_name, $record, $field_list) = @_;
692
    my $syspref = C4::Context->preference($syspref_name);
693
    $syspref = "$syspref\n\n"; # YAML is anal on ending \n. Surplus does not hurt
694
    my $yaml = eval {
695
        YAML::Load($syspref);
696
    };
697
    if ( $@ ) {
698
        warn "Unable to parse $syspref syspref : $@";
699
        return ();
700
    }
701
    my $r;
702
    for my $field_name ( @$field_list ) {
703
        next unless exists $yaml->{$field_name};
704
        my @fields = split /\|/, $yaml->{$field_name};
705
        for my $field ( @fields ) {
706
            my ( $f, $sf ) = split /\$/, $field;
707
            next unless $f and $sf;
708
            if ( my $v = $record->subfield( $f, $sf ) ) {
709
                $r->{$field_name} = $v;
710
            }
711
            last if $yaml->{$field};
712
        }
713
    }
714
    return $r;
715
}
716
717
sub equal_number_of_fields {
718
    my ($tags_list, $record) = @_;
719
    my $tag_fields_count;
720
    for my $tag (@$tags_list) {
721
        my @fields = $record->field($tag);
722
        $tag_fields_count->{$tag} = scalar @fields;
723
    }
724
725
    my $tags_count;
726
    foreach my $key ( keys %$tag_fields_count ) {
727
        if ( $tag_fields_count->{$key} > 0 ) { # Having 0 of a field is ok
728
            $tags_count //= $tag_fields_count->{$key}; # Start with the count from the first occurrence
729
            return -1 if $tag_fields_count->{$key} != $tags_count; # All counts of various fields should be equal if they exist
730
        }
731
    }
732
733
    return $tags_count;
734
}
735
736
sub get_infos_syspref_on_item {
737
    my ($syspref_name, $record, $field_list) = @_;
738
    my $syspref = C4::Context->preference($syspref_name);
739
    $syspref = "$syspref\n\n"; # YAML is anal on ending \n. Surplus does not hurt
740
    my $yaml = eval {
741
        YAML::Load($syspref);
742
    };
743
    if ( $@ ) {
744
        warn "Unable to parse $syspref syspref : $@";
745
        return ();
746
    }
747
    my @result;
748
    my @tags_list;
749
750
    # Check tags in syspref definition
751
    for my $field_name ( @$field_list ) {
752
        next unless exists $yaml->{$field_name};
753
        my @fields = split /\|/, $yaml->{$field_name};
754
        for my $field ( @fields ) {
755
            my ( $f, $sf ) = split /\$/, $field;
756
            next unless $f and $sf;
757
            push @tags_list, $f;
758
        }
759
    }
760
    @tags_list = List::MoreUtils::uniq(@tags_list);
761
762
    my $tags_count = equal_number_of_fields(\@tags_list, $record);
763
    # Return if the number of these fields in the record is not the same.
764
    return -1 if $tags_count == -1;
765
766
    # Gather the fields
767
    my $fields_hash;
768
    foreach my $tag (@tags_list) {
769
        my @tmp_fields;
770
        foreach my $field ($record->field($tag)) {
771
            push @tmp_fields, $field;
772
        }
773
        $fields_hash->{$tag} = \@tmp_fields;
774
    }
775
776
    for (my $i = 0; $i < $tags_count; $i++) {
777
        my $r;
778
        for my $field_name ( @$field_list ) {
779
            next unless exists $yaml->{$field_name};
780
            my @fields = split /\|/, $yaml->{$field_name};
781
            for my $field ( @fields ) {
782
                my ( $f, $sf ) = split /\$/, $field;
783
                next unless $f and $sf;
784
                my $v = $fields_hash->{$f}[$i] ? $fields_hash->{$f}[$i]->subfield( $sf ) : undef;
785
                $r->{$field_name} = $v if (defined $v);
786
                last if $yaml->{$field};
787
            }
788
        }
789
        push @result, $r;
790
    }
791
    return \@result;
792
}
793
794
sub _trim {
795
    return $_[0] unless $_[0];
796
    $_[0] =~ s/^\s+//;
797
    $_[0] =~ s/\s+$//;
798
    $_[0];
799
}
(-)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 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 | html %]" >
300
                    <ol>
301
                        [% FOREACH iteminfo IN item %]
302
                            [% IF ( iteminfo.hidden ) %]
303
                                <li style="[% iteminfo.hidden | html %];">
304
                            [% ELSE %]
305
                                <li>
306
                            [% END %]
307
                            <div class="subfield_line" id="subfield[% iteminfo.serialid | html %][% iteminfo.countitems | html %][% iteminfo.subfield | html %][% iteminfo.random | html %]">
308
                                [% IF (iteminfo.mandatory) %]
309
                                    <label class="required">[% iteminfo.subfield | html %] - [% iteminfo.marc_lib | $raw %]</label>
310
                                [% ELSE %]
311
                                    <label>[% iteminfo.subfield | html %] - [% iteminfo.marc_lib | $raw %]</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 | html %]" selected="selected">[% iteminfo.marc_value.labels.$value | html %]</option>
318
                                            [% ELSE %]
319
                                                <option value="[% value | html %]">[% iteminfo.marc_value.labels.$value | html %]</option>
320
                                            [% END %]
321
                                        [% END %]
322
                                    </select>
323
                                [% ELSE %]
324
                                    [% iteminfo.marc_value | $raw %]
325
                                [% END %]
326
                                <input type="hidden" name="itemid" value="[% itemID | html %]" />
327
                                <input type="hidden" name="kohafield" value="[% iteminfo.kohafield | html %]" />
328
                                <input type="hidden" name="tag" value="[% iteminfo.tag | html %]" />
329
                                <input type="hidden" name="subfield" value="[% iteminfo.subfield | html %]" />
330
                                <input type="hidden" name="mandatory" value="[% iteminfo.mandatory | html %]" />
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 | html %]')" 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 | html %]')" 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 614-620 Link Here
614
        }
671
        }
615
672
616
        $(document).ready(function(){
673
        $(document).ready(function(){
617
            [% IF AcqCreateItemOrdering and not basket.is_standing %]
674
            var events = $('#outeritemblock > div').filter(function () {
675
                var el = BindPluginEvents(this.innerHTML);
676
                return el;
677
            });
678
679
            [% IF AcqCreateItemOrdering and not basket.is_standing and not item_list %]
618
                cloneItemBlock(0, '[% UniqueItemFields | html %]');
680
                cloneItemBlock(0, '[% UniqueItemFields | html %]');
619
            [% END %]
681
            [% END %]
620
682
Lines 711-716 Link Here
711
    </script>
773
    </script>
712
[% END %]
774
[% END %]
713
775
776
[% UNLESS ( footerjs ) %]
777
    [% jsinclude | $raw # Parse the page template's JavaScript block if necessary %]
778
[% END %]
714
[% INCLUDE 'intranet-bottom.inc' %]
779
[% INCLUDE 'intranet-bottom.inc' %]
715
780
716
[% BLOCK display_subfield %]
781
[% 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