From d8dbd0d82346622cab2e1275f380d062fed58e9e Mon Sep 17 00:00:00 2001 From: Dobrica Pavlinusic Date: Mon, 1 Feb 2021 15:25:31 +0100 Subject: [PATCH] added inventura barcode scanner --- intranet/cgi-bin/fer/fer_inventura.sql | 8 ++ intranet/cgi-bin/fer/inventura.pl | 122 +++++++++++++++++++++++++ 2 files changed, 130 insertions(+) create mode 100644 intranet/cgi-bin/fer/fer_inventura.sql create mode 100755 intranet/cgi-bin/fer/inventura.pl diff --git a/intranet/cgi-bin/fer/fer_inventura.sql b/intranet/cgi-bin/fer/fer_inventura.sql new file mode 100644 index 0000000..e9a5c6f --- /dev/null +++ b/intranet/cgi-bin/fer/fer_inventura.sql @@ -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 index 0000000..4efea4c --- /dev/null +++ b/intranet/cgi-bin/fer/inventura.pl @@ -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{ + + + + + + Inventura + + +}; + +# 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| + + | +; + +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: $barcode
+TITLE: $row->{title}
+AUTHOR: $row->{author}
+ |; + + 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{ + + +}; -- 2.20.1