added inventura barcode scanner
authorDobrica Pavlinusic <dpavlin@rot13.org>
Mon, 1 Feb 2021 14:25:31 +0000 (15:25 +0100)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Mon, 1 Feb 2021 14:25:31 +0000 (15:25 +0100)
intranet/cgi-bin/fer/fer_inventura.sql [new file with mode: 0644]
intranet/cgi-bin/fer/inventura.pl [new file with mode: 0755]

diff --git a/intranet/cgi-bin/fer/fer_inventura.sql b/intranet/cgi-bin/fer/fer_inventura.sql
new file mode 100644 (file)
index 0000000..e9a5c6f
--- /dev/null
@@ -0,0 +1,8 @@
+DROP TABLE IF EXISTS `fer_inventura`;
+CREATE TABLE `fer_inventura` (
+  `date_scanned` date NOT NULL,
+  `barcode` varchar(20) NOT NULL,
+  `source_id` varchar(20) NOT NULL,
+  `timestamp` datetime DEFAULT CURRENT_TIMESTAMP,
+  UNIQUE KEY `fer_inventura_unique` (`barcode`,`date_scanned`,`source_id`)
+);
diff --git a/intranet/cgi-bin/fer/inventura.pl b/intranet/cgi-bin/fer/inventura.pl
new file mode 100755 (executable)
index 0000000..4efea4c
--- /dev/null
@@ -0,0 +1,122 @@
+#!/usr/bin/perl
+
+use Modern::Perl;
+
+use C4::Context;
+use C4::Circulation;
+use Data::Dump qw(dump);
+use CGI qw ( -utf8 );
+
+binmode STDOUT, ':encoding(UTF-8)';
+
+my $q = new CGI;
+
+my $barcode = $q->param('barcode');
+warn "# barcode: $barcode\n";
+$q->delete('barcode'); # empty form field
+
+my $row;
+
+$ENV{REQUEST_URI} =~ s{/intranet/}{/cgi-bin/koha/}; # fix plack rewrite
+
+print $q->header( -charset => 'utf-8' ), qq{
+<!DOCTYPE html>
+<html>
+  <head>
+  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
+  <style>
+       body {
+               font-size: 200%;
+       }
+  </style>
+  <title>Inventura</title>
+</head>
+  <body>
+};
+
+# Authentication
+my ($status, $cookie, $sessionId) = C4::Auth::check_api_auth($q, { tools => 'inventory' });
+if ($status ne "ok") {
+       print "This requres tools - inventory permission";
+       goto end_body;
+}
+
+
+print
+      $q->start_form( -autocomplete => 'off' )
+    , $q->textfield( -name => 'barcode', -autofocus => 'autofocus' )
+    , $q->submit( -value => 'Search' )
+#    , $q->checkbox( -name => 'izdatnice', -label => 'izdatnice' )
+#    , $q->checkbox( -name => 'proizvodi', -label => 'prozivodi', -checked => 1 )
+    , $q->end_form
+    , qq|
+<!--
+<script type="text/javascript">
+document.getElementsByName('barcode')[0].focus();
+</script>
+-->
+       |
+;
+
+if ( $barcode ) {
+
+       my $dbh = C4::Context->dbh;
+
+       my $sql = qq{
+       select
+               itemnumber,
+               items.biblionumber as biblionumber,
+               title,
+               author
+       from items
+       join biblio on items.biblionumber = biblio.biblionumber
+       where barcode = ?
+       };
+
+       #warn "# sql $sql\n";
+
+       my $sth = $dbh->prepare( $sql );
+       $sth->execute( $barcode );
+       if ( $sth->rows ) {
+
+                       $row = $sth->fetchrow_hashref;
+
+                       print qq|
+BARCODE: <tt>$barcode</tt><br>
+TITLE: <b>$row->{title}</b><br>
+AUTHOR: $row->{author}<br>
+                       |;
+
+                       my $sth_update = $dbh->prepare(qq{
+                       update items set datelastseen = now() where barcode = ?
+                       });
+                       $sth_update->execute( $barcode );
+
+                       my $sth_inventura = $dbh->prepare(qq{
+                       insert ignore into fer_inventura (date_scanned,barcode,source_id) values (date(now()), ?, ?)
+                       });
+                       $sth_inventura->execute( $barcode, C4::Context->userenv->{'id'} );
+
+                       my $sth_issues = $dbh->prepare(qq{
+                       select firstname,surname,userid,email from issues join borrowers on issues.borrowernumber = borrowers.borrowernumber where itemnumber = ?
+                       });
+
+                       $sth_issues->execute( $row->{'itemnumber'} );
+                       while ( my $row = $sth_issues->fetchrow_hashref ) {
+                               warn "# issues row ",dump($row);
+                               print "issued to ", $row->{firstname}, ' ', $row->{surname}, " returning...";
+                               AddReturn( $barcode, C4::Context->userenv->{'branch'} );
+                       }
+       } else {
+                       print "no barcode $barcode\n";
+                       warn "ERROR: can't find $barcode\n";
+       }
+
+}
+
+end_body:
+
+print qq{
+</body>
+</html>
+};