# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
#
-# You should have received a copy of the GNU General Public License along with
-# Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
-# Suite 330, Boston, MA 02111-1307 USA
+# You should have received a copy of the GNU General Public License along
+# with Koha; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
use strict;
+#use warnings; FIXME - Bug 2505
use Carp;
use C4::Context;
use C4::Branch;
require C4::Reserves;
use C4::Charset;
+use C4::Acquisition;
use vars qw($VERSION @ISA @EXPORT);
GetItemsInfo
get_itemnumbers_of
GetItemnumberFromBarcode
+ GetBarcodeFromItemnumber
DelItemCheck
MoveItemFromBiblio
# parse item hash from MARC
my $frameworkcode = GetFrameworkCode( $biblionumber );
- my $item = &TransformMarcToKoha( $dbh, $source_item_marc, $frameworkcode );
- my $unlinked_item_subfields = _get_unlinked_item_subfields($source_item_marc, $frameworkcode);
+ my ($itemtag,$itemsubfield)=GetMarcFromKohaField("items.itemnumber",$frameworkcode);
+
+ my $localitemmarc=MARC::Record->new;
+ $localitemmarc->append_fields($source_item_marc->field($itemtag));
+ my $item = &TransformMarcToKoha( $dbh, $localitemmarc, $frameworkcode ,'items');
+ my $unlinked_item_subfields = _get_unlinked_item_subfields($localitemmarc, $frameworkcode);
return AddItem($item, $biblionumber, $dbh, $frameworkcode, $unlinked_item_subfields);
}
replacementpricedate => undef,
restricted => undef,
stack => undef,
+ stocknumber => undef,
uri => undef,
wthdrawn => 0,
);
my $localitemmarc=MARC::Record->new;
$localitemmarc->append_fields($item_marc->field($itemtag));
- my $item = &TransformMarcToKoha( $dbh, $item_marc, $frameworkcode ,'items');
+ 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($item_marc, $frameworkcode);
+ my $unlinked_item_subfields = _get_unlinked_item_subfields($localitemmarc, $frameworkcode);
return ModItem($item, $biblionumber, $itemnumber, $dbh, $frameworkcode, $unlinked_item_subfields);
}
=over 4
-DelItem($biblionumber, $itemnumber);
+DelItem($dbh, $biblionumber, $itemnumber);
=back
$query .= 'WHERE ';
$query .= join ' AND ', @where_strings;
}
- $query .= ' ORDER BY itemcallnumber, title';
+ $query .= ' ORDER BY items.cn_sort, itemcallnumber, title';
my $sth = $dbh->prepare($query);
$sth->execute( @bind_params );
biblioitems.lccn,
biblioitems.url,
items.notforloan as itemnotforloan,
- itemtypes.description
+ itemtypes.description,
+ itemtypes.notforloan as notforloan_per_itemtype,
+ branchurl
FROM items
+ LEFT JOIN branches ON items.homebranch = branches.branchcode
LEFT JOIN biblio ON biblio.biblionumber = items.biblionumber
LEFT JOIN biblioitems ON biblioitems.biblioitemnumber = items.biblioitemnumber
LEFT JOIN itemtypes ON itemtypes.itemtype = "
. (C4::Context->preference('item-level_itypes') ? 'items.itype' : 'biblioitems.itemtype');
- $query .= " WHERE items.biblionumber = ? ORDER BY items.dateaccessioned desc" ;
+ $query .= " WHERE items.biblionumber = ? ORDER BY branches.branchname,items.dateaccessioned desc" ;
my $sth = $dbh->prepare($query);
$sth->execute($biblionumber);
my $i = 0;
my ($lib) = $sthnflstatus->fetchrow;
$data->{notforloanvalue} = $lib;
}
- $data->{itypenotforloan} = $data->{notforloan} if (C4::Context->preference('item-level_itypes'));
# my stack procedures
my $stackstatus = $dbh->prepare(
return ($result);
}
+=head2 GetBarcodeFromItemnumber
+
+=over 4
+
+$result = GetBarcodeFromItemnumber($itemnumber);
+
+=back
+
+=cut
+
+sub GetBarcodeFromItemnumber {
+ my ($itemnumber) = @_;
+ my $dbh = C4::Context->dbh;
+
+ my $rq =
+ $dbh->prepare("SELECT barcode FROM items WHERE items.itemnumber=?");
+ $rq->execute($itemnumber);
+ my ($result) = $rq->fetchrow;
+ return ($result);
+}
+
=head3 get_item_authorised_values
find the types and values for all authorised values assigned to this item.
Moves an item from a biblio to another
+Returns undef if the move failed or the biblionumber of the destination record otherwise
=cut
sub MoveItemFromBiblio {
my ($itemnumber, $frombiblio, $tobiblio) = @_;
my $dbh = C4::Context->dbh;
- my $sth = $dbh->prepare("UPDATE items SET biblioitemnumber = ?, biblionumber = ? WHERE itemnumber = ? AND biblionumber = ?");
- my $return = $sth->execute($tobiblio, $tobiblio, $itemnumber, $frombiblio);
+ my $sth = $dbh->prepare("SELECT biblioitemnumber FROM biblioitems WHERE biblionumber = ?");
+ $sth->execute( $tobiblio );
+ my ( $tobiblioitem ) = $sth->fetchrow();
+ $sth = $dbh->prepare("UPDATE items SET biblioitemnumber = ?, biblionumber = ? WHERE itemnumber = ? AND biblionumber = ?");
+ my $return = $sth->execute($tobiblioitem, $tobiblio, $itemnumber, $frombiblio);
if ($return == 1) {
# Getting framework
$record->delete_field($fielditem)
}
}
- # Saving the modification
- ModBiblioMarc($record, $frombiblio, $frameworkcode);
- # Getting the record we want to move the item to
- $record = GetMarcBiblio($tobiblio);
+ # If we found an item (should always true, except in case of database-marcxml inconsistency)
+ if ($item) {
- # Inserting the previously saved item
- $record->insert_fields_ordered($item);
+ # Checking if the item we want to move is in an order
+ my $order = GetOrderFromItemnumber($itemnumber);
+ if ($order) {
+ # Replacing the biblionumber within the order if necessary
+ $order->{'biblionumber'} = $tobiblio;
+ ModOrder($order);
+ }
- # Saving the modification
- ModBiblioMarc($record, $tobiblio, $frameworkcode);
+ # Saving the modification
+ ModBiblioMarc($record, $frombiblio, $frameworkcode);
+
+ # Getting the record we want to move the item to
+ $record = GetMarcBiblio($tobiblio);
+
+ # Inserting the previously saved item
+ $record->insert_fields_ordered($item);
+
+ # Saving the modification
+ ModBiblioMarc($record, $tobiblio, $frameworkcode);
+
+ } else {
+ return undef;
+ }
} else {
- return -1;
+ return undef;
}
}