added old inventory number (copynumber) and statuses: withdrawn, itemlost, dameged
[share-koha-fer] / intranet / cgi-bin / fer / inventura.pl
1 #!/usr/bin/perl
2
3 use Modern::Perl;
4
5 use C4::Context;
6 use C4::Circulation;
7 use Data::Dump qw(dump);
8 use CGI qw ( -utf8 );
9 use utf8;
10
11 binmode STDOUT, ':encoding(UTF-8)';
12
13 my $q = new CGI;
14
15 my $barcode = $q->param('barcode');
16 warn "# barcode: $barcode\n";
17 $q->delete('barcode'); # empty form field
18
19 my $row;
20
21 $ENV{REQUEST_URI} =~ s{/intranet/}{/cgi-bin/koha/}; # fix plack rewrite
22
23 print $q->header( -charset => 'utf-8' ), qq{
24 <!DOCTYPE html>
25 <html>
26   <head>
27   <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
28   <style>
29         body {
30                 font-size: 200%;
31         }
32   </style>
33   <title>Inventura</title>
34 </head>
35   <body>
36 };
37
38 # Authentication
39 my ($status, $cookie, $sessionId) = C4::Auth::check_api_auth($q, { tools => 'inventory' });
40 if ($status ne "ok") {
41         print "This requres tools - inventory permission";
42         goto end_body;
43 }
44
45
46 print
47       $q->start_form( -autocomplete => 'off' )
48     , $q->textfield( -name => 'barcode', -autofocus => 'autofocus' )
49     , $q->submit( -value => 'Search' )
50 #    , $q->checkbox( -name => 'izdatnice', -label => 'izdatnice' )
51 #    , $q->checkbox( -name => 'proizvodi', -label => 'prozivodi', -checked => 1 )
52     , $q->end_form
53     , qq|
54 <!--
55 <script type="text/javascript">
56 document.getElementsByName('barcode')[0].focus();
57 </script>
58 -->
59         |
60 ;
61
62 if ( $barcode ) {
63
64         my $dbh = C4::Context->dbh;
65
66         warn "inventura barcode: $barcode ",dump($barcode);
67
68         my $sql = qq{
69         select
70                 itemnumber,
71                 items.biblionumber as biblionumber,
72                 title,
73                 author,
74                 biblioitems.publishercode,
75                 biblioitems.editionstatement,
76                 biblio.copyrightdate,
77                 items.stocknumber,
78                 items.copynumber,
79                 items.itemcallnumber,
80                 items.barcode,
81                 items.homebranch,
82                 items.location,
83                 items.withdrawn,
84                 items.itemlost,
85                 items.damaged
86         from items
87         join biblio on items.biblionumber = biblio.biblionumber
88         join biblioitems on items.biblionumber = biblioitems.biblionumber
89         where barcode = ? + 0
90         };
91
92         #warn "# sql $sql\n";
93
94         my $sth = $dbh->prepare( $sql );
95         $sth->execute( $barcode );
96         if ( $sth->rows ) {
97
98                         $row = $sth->fetchrow_hashref;
99
100                         print qq|
101 barcode: <tt>$barcode</tt><br>
102 naslov: <b>$row->{title}</b><br>
103 autor: $row->{author}<br>
104 izdavač: $row->{publishercode}<br>
105 izdanje: $row->{editionstatement}<br>
106 godina izdanja: $row->{copyrightdate}<br>
107 inventarni broj novi: $row->{stocknumber}<br>
108 inventarni broj stari: $row->{copynumber}<br>
109 signatura: $row->{itemcallnumber}<br>
110 stalna lokacija: $row->{homebranch}<br>
111 lokacija na polici: $row->{location}<br>
112 status otpisano: $row->{withdrawn}<br>
113 status izgubljeno: $row->{itemlost}<br>
114 status uništeno: $row->{damaged}<br>
115                         |;
116
117                         my $sth_update = $dbh->prepare(qq{
118                         update items set datelastseen = now() where barcode = ?
119                         });
120                         $sth_update->execute( $barcode );
121
122                         my $sth_inventura = $dbh->prepare(qq{
123                         insert ignore into fer_inventura (date_scanned,barcode,source_id) values (date(now()), ?, ?)
124                         });
125                         $sth_inventura->execute( $barcode, C4::Context->userenv->{'id'} );
126
127                         my $sth_issues = $dbh->prepare(qq{
128                         select firstname,surname,userid,email from issues join borrowers on issues.borrowernumber = borrowers.borrowernumber where itemnumber = ?
129                         });
130
131                         $sth_issues->execute( $row->{'itemnumber'} );
132                         while ( my $row = $sth_issues->fetchrow_hashref ) {
133                                 warn "# issues row ",dump($row);
134                                 print "issued to ", $row->{firstname}, ' ', $row->{surname}, " returning...";
135                                 AddReturn( $barcode, C4::Context->userenv->{'branch'} );
136                         }
137         } else {
138                         print "no barcode $barcode\n";
139                         warn "ERROR: can't find $barcode\n";
140         }
141
142 }
143
144 end_body:
145
146 print qq{
147 </body>
148 </html>
149 };