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

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