Merge commit 'biblibre/3.2_community' into to-push
[koha.git] / C4 / Items.pm
index a060c36..3a4ec91 100644 (file)
@@ -30,6 +30,7 @@ use C4::Log;
 use C4::Branch;
 require C4::Reserves;
 use C4::Charset;
+use C4::Acquisition;
 
 use vars qw($VERSION @ISA @EXPORT);
 
@@ -1078,7 +1079,7 @@ END_SQL
         $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 );
 
@@ -1266,11 +1267,12 @@ sub GetItemsInfo {
            items.notforloan as itemnotforloan,
            itemtypes.description
      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;
@@ -2030,8 +2032,11 @@ Returns undef if the move failed or the biblionumber of the destination record o
 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
@@ -2060,6 +2065,14 @@ sub MoveItemFromBiblio {
        # If we found an item (should always true, except in case of database-marcxml inconsistency)
        if ($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, $frombiblio, $frameworkcode);