display barcode for item
[koha-dla] / barcode-seen.pl
1 #!/usr/bin/env perl
2 use Mojolicious::Lite;
3
4 use lib '/srv/koha_ffzg';
5 BEGIN {
6         $ENV{KOHA_CONF} = '/etc/koha/sites/ffzg/koha-conf.xml';
7 }
8 use C4::Context;
9 use C4::Circulation;
10
11 use Data::Dump qw(dump);
12
13
14
15 get '/' => sub {
16         my $c = shift;
17
18         my $barcode = $c->param('barcode');
19         $c->stash( barcode => $barcode );
20
21         my $dbh = C4::Context->dbh;
22         my $sth_items = $dbh->prepare(qq{
23 select
24         itemnumber,
25         items.biblionumber,
26         title,
27         author
28 from items
29 join biblio on biblio.biblionumber = items.biblionumber where barcode = ?
30 });
31
32         warn "# $barcode";
33         $sth_items->execute( $barcode );
34         while ( my $row = $sth_items->fetchrow_hashref ) {
35                 warn "# items row ",dump($row);
36                 $c->stash( $_ => $row->{$_} ) foreach keys %$row;
37         }
38
39 my $sth_update = $dbh->prepare(qq{
40 update items set datelastseen = now() where barcode = ?
41 });
42
43 my $sth_inventura = $dbh->prepare(qq{
44 insert ignore into ffzg_inventura (date_scanned,barcode,source_id) values (date(now()), ?, 'abc')
45 });
46
47 my $sth_issues = $dbh->prepare(qq{
48 select firstname,surname,userid,email from issues join borrowers on issues.borrowernumber = borrowers.borrowernumber where itemnumber = ?
49 });
50
51         $sth_update->execute( $barcode );
52         $sth_inventura->execute( $barcode );
53
54         $sth_issues->execute( $c->stash('itemnumber') );
55         while ( my $row = $sth_issues->fetchrow_hashref ) {
56                 warn "# issues row ",dump($row);
57                 $c->stash( $_ => $row->{$_} ) foreach keys %$row;
58                 AddReturn( $barcode, 'FFZG' );
59         }
60
61         $c->render(template => 'index');
62 };
63
64 app->start;
65 __DATA__
66
67 @@ index.html.ep
68 % layout 'default';
69
70 %= form_for '/' => begin
71         %#= text_field 'barcode'
72         <input name=barcode size=10 autofocus>
73         %= submit_button 'Scan'
74 % end
75
76 % if ( stash('title') ) {
77 <%= stash('author') %>
78 <b><%= stash('title') %></b>
79 <%= stash('barcode') %>
80 % } else {
81 <big style="color:red"><%= stash('barcode') %> not found</big>
82 % }
83
84 % if ( stash('userid') ) {
85 <br>Borrower:
86
87 <tt><%= stash('userid') %></tt>
88 <%= stash('firstname') %>
89 <%= stash('surname') %>
90 <tt><%= stash('email') %></tt>
91
92 % }
93
94 @@ layouts/default.html.ep
95 <!DOCTYPE html>
96 <html>
97   <head>
98   <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
99   <style>
100         body {
101                 font-size: 200%;
102         }
103   </style>
104   <title>Inventura</title>
105 </head>
106   <body><%= content %></body>
107 </html>