X-Git-Url: http://koha-dev.rot13.org:8081/gitweb/?a=blobdiff_plain;f=C4%2FItems.pm;h=05df0c56f03a8e5244165123315dbc35d583e92b;hb=b5ee2f201bed91a38ff2c1c527cbf19adc76fabc;hp=a7c190ca45ebd490bc3cb5ddefcc5fc1720046c7;hpb=8902ee5684719b7b7ff936272dcbb96dd558b411;p=koha_gimpoz diff --git a/C4/Items.pm b/C4/Items.pm index a7c190ca45..05df0c56f0 100644 --- a/C4/Items.pm +++ b/C4/Items.pm @@ -1,6 +1,7 @@ package C4::Items; # Copyright 2007 LibLime, Inc. +# Parts Copyright Biblibre 2010 # # This file is part of Koha. # @@ -402,7 +403,7 @@ my %default_values_for_mod_from_marc = ( 'items.cn_source' => undef, copynumber => undef, damaged => 0, - dateaccessioned => undef, +# dateaccessioned => undef, enumchron => undef, holdingbranch => undef, homebranch => undef, @@ -429,18 +430,18 @@ sub ModItemFromMarc { my $biblionumber = shift; my $itemnumber = shift; - my $dbh = C4::Context->dbh; - my $frameworkcode = GetFrameworkCode( $biblionumber ); - my ($itemtag,$itemsubfield)=GetMarcFromKohaField("items.itemnumber",$frameworkcode); - - my $localitemmarc=MARC::Record->new; - $localitemmarc->append_fields($item_marc->field($itemtag)); - my $item = &TransformMarcToKoha( $dbh, $localitemmarc, $frameworkcode, 'items'); - foreach my $item_field (keys %default_values_for_mod_from_marc) { - $item->{$item_field} = $default_values_for_mod_from_marc{$item_field} unless exists $item->{$item_field}; + my $dbh = C4::Context->dbh; + my $frameworkcode = GetFrameworkCode($biblionumber); + my ( $itemtag, $itemsubfield ) = GetMarcFromKohaField( "items.itemnumber", $frameworkcode ); + + my $localitemmarc = MARC::Record->new; + $localitemmarc->append_fields( $item_marc->field($itemtag) ); + my $item = &TransformMarcToKoha( $dbh, $localitemmarc, $frameworkcode, 'items' ); + foreach my $item_field ( keys %default_values_for_mod_from_marc ) { + $item->{$item_field} = $default_values_for_mod_from_marc{$item_field} unless (exists $item->{$item_field}); } - my $unlinked_item_subfields = _get_unlinked_item_subfields($localitemmarc, $frameworkcode); - + my $unlinked_item_subfields = _get_unlinked_item_subfields( $localitemmarc, $frameworkcode ); + return ModItem($item, $biblionumber, $itemnumber, $dbh, $frameworkcode, $unlinked_item_subfields); } @@ -954,7 +955,7 @@ $statushash requires a hashref that has the authorized values fieldname (intems. =cut sub GetItemsForInventory { - my ( $minlocation, $maxlocation,$location, $itemtype, $ignoreissued, $datelastseen, $branch, $offset, $size, $statushash ) = @_; + my ( $minlocation, $maxlocation,$location, $itemtype, $ignoreissued, $datelastseen, $branchcode, $branch, $offset, $size, $statushash ) = @_; my $dbh = C4::Context->dbh; my ( @bind_params, @where_strings ); @@ -993,10 +994,14 @@ END_SQL push @where_strings, 'items.location = ?'; push @bind_params, $location; } - - if ( $branch ) { + + if ( $branchcode ) { + if($branch eq "homebranch"){ push @where_strings, 'items.homebranch = ?'; - push @bind_params, $branch; + }else{ + push @where_strings, 'items.holdingbranch = ?'; + } + push @bind_params, $branchcode; } if ( $itemtype ) { @@ -1763,6 +1768,9 @@ sub _do_column_fixes_for_mod { if (exists $item->{'location'} && !exists $item->{'permanent_location'}) { $item->{'permanent_location'} = $item->{'location'}; } + if (exists $item->{'timestamp'}) { + delete $item->{'timestamp'}; + } } =head2 _get_single_item_column @@ -2024,21 +2032,31 @@ sub DelItemCheck { my $sth=$dbh->prepare("select * from issues i where i.itemnumber=?"); $sth->execute($itemnumber); - my $onloan=$sth->fetchrow; - - if ($onloan){ - $error = "book_on_loan" - }else{ - # check it doesnt have a waiting reserve - $sth=$dbh->prepare("SELECT * FROM reserves WHERE (found = 'W' or found = 'T') AND itemnumber = ?"); - $sth->execute($itemnumber); - my $reserve=$sth->fetchrow; - if ($reserve){ - $error = "book_reserved"; - }else{ - DelItem($dbh, $biblionumber, $itemnumber); - return 1; - } + my $item = GetItem($itemnumber); + my $onloan = $sth->fetchrow; + if ($onloan) { + $error = "book_on_loan"; + } + elsif (C4::Context->preference("IndependantBranches") and (C4::Context->userenv->{branch} ne $item->{C4::Context->preference("HomeOrHoldingBranch")||'homebranch'})){ + $error = "not_same_branch"; + } + else { + if ($onloan){ + $error = "book_on_loan" + } + else { + # check it doesnt have a waiting reserve + $sth=$dbh->prepare("SELECT * FROM reserves WHERE (found = 'W' or found = 'T') AND itemnumber = ?"); + $sth->execute($itemnumber); + my $reserve=$sth->fetchrow; + if ($reserve) { + $error = "book_reserved"; + } + else { + DelItem($dbh, $biblionumber, $itemnumber); + return 1; + } + } } return $error; } @@ -2136,17 +2154,20 @@ sub _marc_from_item_hash { : () } keys %{ $item } }; my $item_marc = MARC::Record->new(); - foreach my $item_field (keys %{ $mungeditem }) { - my ($tag, $subfield) = GetMarcFromKohaField($item_field, $frameworkcode); - next unless defined $tag and defined $subfield; # skip if not mapped to MARC field - if (my $field = $item_marc->field($tag)) { - $field->add_subfields($subfield => $mungeditem->{$item_field}); - } else { - my $add_subfields = []; - if (defined $unlinked_item_subfields and ref($unlinked_item_subfields) eq 'ARRAY' and $#$unlinked_item_subfields > -1) { - $add_subfields = $unlinked_item_subfields; + foreach my $item_field ( keys %{$mungeditem} ) { + my ( $tag, $subfield ) = GetMarcFromKohaField( $item_field, $frameworkcode ); + next unless defined $tag and defined $subfield; # skip if not mapped to MARC field + my @values = split(/\s?\|\s?/, $mungeditem->{$item_field}, -1); + foreach my $value (@values){ + if ( my $field = $item_marc->field($tag) ) { + $field->add_subfields( $subfield => $value ); + } else { + my $add_subfields = []; + if (defined $unlinked_item_subfields and ref($unlinked_item_subfields) eq 'ARRAY' and $#$unlinked_item_subfields > -1) { + $add_subfields = $unlinked_item_subfields; + } + $item_marc->add_fields( $tag, " ", " ", $subfield => $value, @$add_subfields ); } - $item_marc->add_fields( $tag, " ", " ", $subfield => $mungeditem->{$item_field}, @$add_subfields); } }