Merge fixes and removing warnings
[koha.git] / cataloguing / moveitem.pl
1 #!/usr/bin/perl
2
3 # Move an item from a biblio to another
4 #
5 # Copyright 2009 BibLibre
6 #
7 # This file is part of Koha.
8 #
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
12 # version.
13 #
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.
17 #
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
21
22 use CGI;
23 use strict;
24 use C4::Auth;
25 use C4::Output;
26 use C4::Biblio;
27 use C4::Items;
28 use C4::Context;
29 use C4::Koha;
30 use C4::Branch;
31 use C4::ClassSource;
32 use C4::Acquisition qw/GetOrderFromItemnumber ModOrder GetOrder ModOrderItem/;
33
34 use Date::Calc qw(Today);
35
36 use MARC::File::XML;
37 my $query = CGI->new;
38
39 # The biblio to move the item to
40 my $biblionumber = $query->param('biblionumber');
41
42 # The barcode of the item to move
43 my $barcode      = $query->param('barcode');
44
45 my ($template, $loggedinuser, $cookie)
46     = get_template_and_user({template_name => "cataloguing/moveitem.tmpl",
47                  query => $query,
48                  type => "intranet",
49                  authnotrequired => 0,
50                  flagsrequired => {editcatalogue => 1},
51                  debug => 1,
52                  });
53
54
55
56 my $biblio = GetBiblioData($biblionumber);
57 $template->param(bibliotitle => $biblio->{'title'});
58 $template->param(biblionumber => $biblionumber);
59
60 # If we already have the barcode of the item to move and the biblionumber to move the item to
61 if ($barcode && $biblionumber) { 
62     
63     # We get his itemnumber
64     my $itemnumber = GetItemnumberFromBarcode($barcode);
65
66     if ($itemnumber) {
67         # And then, we get the item
68         my $item = GetItem($itemnumber);
69
70         if ($item) {
71
72             my $results = GetBiblioFromItemNumber($itemnumber, $barcode);
73         my $frombiblionumber = $results->{'biblionumber'};
74            
75             my $moveresult = MoveItemFromBiblio($itemnumber, $frombiblionumber, $biblionumber); 
76
77             if ($moveresult) { 
78                                 my $order = GetOrderFromItemnumber($itemnumber);
79                                 if ($order){
80                                         $order->{'biblionumber'} = $biblionumber;
81                                         ModOrder($order);
82                                         my $orderitem = {
83                                                 ordernumber => $order->{'ordernumber'},
84                                                 itemnumber => $itemnumber,
85                                                 newitemnumber => $itemnumber,
86                                         };
87                                         ModOrderItem($orderitem);
88                                 }
89                      $template->param(success => 1);
90             } else {
91                 $template->param(error => 1,
92                                  errornonewitem => 1); 
93             }
94
95
96         } else {
97             $template->param(error => 1,
98                              errornoitem => 1);
99         }
100     } else {
101             $template->param(error => 1,
102                              errornoitemnumber => 1);
103
104     }
105     $template->param(
106                         barcode => $barcode,  
107                         itemnumber => $itemnumber,
108                     );
109
110 } else {
111     $template->param(missingparameter => 1);
112     if (!$barcode)      { $template->param(missingbarcode      => 1); }
113     if (!$biblionumber) { $template->param(missingbiblionumber => 1); }
114 }
115
116
117 output_html_with_http_headers $query, $cookie, $template->output;