ffzg/barcode/invetura: scan barcodes
authorDobrica Pavlinusic <dpavlin@rot13.org>
Thu, 6 Dec 2018 16:35:34 +0000 (17:35 +0100)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Mon, 25 Mar 2019 14:43:16 +0000 (15:43 +0100)
ffzg/barcode/inventura.pl [new file with mode: 0755]
koha-tmpl/intranet-tmpl/prog/en/modules/tools/tools-home.tt

diff --git a/ffzg/barcode/inventura.pl b/ffzg/barcode/inventura.pl
new file mode 100755 (executable)
index 0000000..a9fc541
--- /dev/null
@@ -0,0 +1,121 @@
+#!/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 ffzg_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, 'FFZG' );
+                       }
+       } else {
+                       warn "ERROR: can't find $barcode\n";
+       }
+
+}
+
+end_body:
+
+print qq{
+</body>
+</html>
+};
index b46e282..10c0d24 100644 (file)
     [% END %]
 
     [% IF ( CAN_user_tools_inventory ) %]
-    <dt><a href="/cgi-bin/koha/ffzg/barcode/dla.pl">DLA import</a></dt>
+    <dt><a href="/cgi-bin/koha/ffzg/barcode/dla.pl">FFZG DLA import</a></dt>
     <dd>Import from share RFID reader dump</dd>
+    <dt><a href="/cgi-bin/koha/ffzg/barcode/inventura.pl">FFZG barcode inventura</a></dt>
+    <dd>Use Android wifi barcode reader</dd>
     <dt><a href="/cgi-bin/koha/tools/inventory.pl">Inventory</a></dt>
     <dd>Perform inventory of your catalog</dd>
     [% END %]