package C4::Items;
# Copyright 2007 LibLime, Inc.
+# Parts Copyright Biblibre 2010
#
# This file is part of Koha.
#
'items.cn_source' => undef,
copynumber => undef,
damaged => 0,
- dateaccessioned => undef,
+# dateaccessioned => undef,
enumchron => undef,
holdingbranch => undef,
homebranch => undef,
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);
}
=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 );
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 ) {
);
$restrictedstatus->execute;
- my ($authorised_valuecode) = $restrictedstatus->fetchrow;
+ ($authorised_valuecode) = $restrictedstatus->fetchrow;
if ($authorised_valuecode) {
$restrictedstatus = $dbh->prepare(
"SELECT lib,lib_opac FROM authorised_values
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
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;
}
: () } 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);
}
}