3 # Move an item from a biblio to another
5 # Copyright 2009 BibLibre
7 # This file is part of Koha.
9 # Koha is free software; you can redistribute it and/or modify it under the
10 # terms of the GNU General Public License as published by the Free Software
11 # Foundation; either version 2 of the License, or (at your option) any later
14 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
15 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
16 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License along with
19 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
20 # Suite 330, Boston, MA 02111-1307 USA
32 use C4::Acquisition qw/GetOrderFromItemnumber ModOrder GetOrder ModOrderItem/;
34 use Date::Calc qw(Today);
39 # The biblio to move the item to
40 my $biblionumber = $query->param('biblionumber');
42 # The barcode of the item to move
43 my $barcode = $query->param('barcode');
45 my ($template, $loggedinuser, $cookie)
46 = get_template_and_user({template_name => "cataloguing/moveitem.tmpl",
50 flagsrequired => {editcatalogue => 1},
56 my $biblio = GetBiblioData($biblionumber);
57 $template->param(bibliotitle => $biblio->{'title'});
58 $template->param(biblionumber => $biblionumber);
60 # If we already have the barcode of the item to move and the biblionumber to move the item to
61 if ($barcode && $biblionumber) {
63 # We get his itemnumber
64 my $itemnumber = GetItemnumberFromBarcode($barcode);
67 # And then, we get the item
68 my $item = GetItem($itemnumber);
72 # We delete the item from the old record (we can't delete afterwards, because of constraint on barcode duplicity)
73 my $results = GetBiblioFromItemNumber($itemnumber, $barcode);
74 my $frombiblionumber = $results->{'biblionumber'};
76 my $order = GetOrderFromItemnumber($itemnumber);
78 $order->{'biblionumber'} = $biblionumber;
82 if ($frombiblionumber) {
83 DelItem(C4::Context->dbh, $frombiblionumber, $itemnumber);
86 # We add the item to the requested record
87 my ($biblionumber, $biblioitemnumber, $newitemnumber) = AddItem($item, $biblionumber);
91 ordernumber => $order->{'ordernumber'},
92 itemnumber => $itemnumber,
93 newitemnumber => $newitemnumber,
95 ModOrderItem($orderitem);
99 $template->param(success => 1);
101 $template->param(error => 1,
102 errornonewitem => 1);
105 $template->param(error => 1,
109 $template->param(error => 1,
110 errornoitemnumber => 1);
114 itemnumber => $itemnumber,
117 $template->param(missingparameter => 1);
118 if (!$barcode) { $template->param(missingbarcode => 1); }
119 if (!$biblionumber) { $template->param(missingbiblionumber => 1); }
123 output_html_with_http_headers $query, $cookie, $template->output;