Showing posts with label sql-ledger. Show all posts
Showing posts with label sql-ledger. Show all posts

Monday, April 3, 2017

Barcode Scanner Part I

To trace items in the Factory, I wanted to use barcodes. Since everybody has a mobile phone I began to search for a good app that can scan a barcode and has a function that you can re-route the barcode to a webpage. Mobiscan did the job. This app has the option to trigger a custom website where it adds the barcode value it scans. Also it triggers the browser from within the app. Saves a few presses on your phone.

To make it work on Sql-ledger side I used the following steps:
  • In the directory SL edit file Form.pm. Add the yellow code line. This is to force that the scrollbars are off.
<head>
 <title>$self->{titlebar}</title>
<META NAME="robots" CONTENT="noindex,nofollow" />
<META NAME="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
$favicon
$stylesheet
$charset
 </head>
  • In the directory CSS, add an extra css file, sql-ledger-mobile.css make a color scheme that is different from the normal setup.
  • In the root directory, make a copy of gl.pl and rename it to barcode.pl
  • In the directory bin/mozilla create a new file barcode.pl (this will contain the perl code).
  • In de root directory add the file custom_menu.ini
  • Create a new user in sql-ledger with minimal permission on the system.
Now we are ready the begin to make some code in the barcode.pl file in bin/mozilla! The first part of the code states all the routines that are used. You can find the all the files here for download. I know that the code is horrible, but as I said before, I am not a programmer... google was my friend to find routines in Perl. The whole trick is to catch the barcode scan push it to Perl. The link you have to make in your iPhone app is:

http://www.yoursql-ledger.com/barcode.pl?path=bin/mozilla&action=catch&level=Barcode--Setup--Catch&login=Username&password=Password&js=1&catch={barcode}

Replace Username and Password with the new user you made. The link will call the sub routine below. The iPhone app will replace {barcode} with the barcode value you scan.
sub catch {
    ## trim the barcode to avoid errors
       $catching1 = $form->{catch};    
       $catching1 =~ s/^\s+//;
       $catching1 =~ s/\s+$//;
    ## Make sure the barcode is a number 
       $catching = $catching1 * 1;    
    ## perform a query to postgres
   my $dbh = $form->dbconnect(\%myconfig);
   my $query = qq|SELECT productionitem.id, 
  productionitem.barcode, 
  productionitem.date_in,
  productionitem.parts_id
  FROM productionitem
        JOIN parts ON (parts.id = productionitem.parts_id)
        WHERE productionitem.barcode = '$catching'|;
   my $sth = $dbh->prepare($query);
   $sth->execute || $form->dberror($query);
   $ref = $sth->fetchrow_hashref(NAME_lc);
   foreach $key (keys %$ref) {
      $form->{$key} = $ref->{$key};
   }
   $sth->finish;
   $dbh->disconnect;

From the code example above you can see that it queries a table that default does not exists in Sql-ledger. I added two new tables; todo this edit the file: Pg-custom_tables.sql in the sql directory.

In my case:
CREATE TABLE productionitem (
 id               int default nextval('id'),
 barcode          char(13),
 date_in          date,
 parts_id  int
);

CREATE TABLE production (
 id    int default nextval('id'),
 productionitem_id  int,
 production_date         timestamp,
 production_code         text,
 mouse_id  text,
 deeg_date  timestamp,
 deeg_id           text,
 graden   numeric
);
To get the tables in your database, run the command:
psql –U postgres yourdatabase < Pg-custom_tables.sql 

All barcodes are stored in the production item table and the actual parts name comes from the Sql-ledger parts table. I have added 'general' parts in Sql-ledger,  for example Flower, Sugar, Butter, Mouse, Cart1, Cart2, etc. From the queries in the code you can see that these 'general' parts all begin with the letter x and a space . (ie. x Flower) In that way they are all at the bottom of your parts list and not used for making invoices. To match the barcode scan it and select from the general parts-list (populated with all the parts starting with x and a space) what it is.




Monday, July 29, 2013

Install Sql-ledger on OSX


Here is a simple install for Mac users to install sql-ledger on Mac OS Mountain Lion. I will use Xcode to get all the core files needed to get it working. Osx already has perl, apache and postgres, we only need to get the extra files needed and Latex if you want to use pdf printing. 

Step 1
First we get all the files to run sql-ledger.

Go to the App Store and Install Xcode, it's free! I know it is a large download but it is the easiest way to get the tools we need.
When Xcode is installed, go to preferences of Xcode and install 'Command Line Tools'

(you can also download 'command line tools' direct from the Apple developers site without installing Xcode, but I follow the Xcode way...).  

Now we have the command line tools we can install the database drivers for Perl.

-Go to terminal and give command: 

sudo cpan DBD:Pg

Follow the prompt messages. (pressing Y a few times...)

To get pdf printing, Install MacTex, http://www.tug.org/mactex/morepackages.html

Choose this file to download and install it: BasicTex.pkg

That's it. Now we need to get sql-ledger on the Mac.

Step 2
Download latest version of sql-ledger, and place the files in directory:
/library/webserver/documents/sql-ledger 

Go to the Terminal app and make the files readable for the web server.

sudo chown -R www:www /library/webserver/documents/sql-ledger 

Now we have to tell apache where to find sql-ledger, to do this add the file sql-ledger.conf in /etc/apache2/users
The contents of this file is:
-------
Alias /sql-ledger/ /Library/WebServer/Documents/sql-ledger/
 <Directory /Library/WebServer/Documents/sql-ledger/>
AllowOverride All
AddHandler cgi-script .pl
Options ExecCGI Includes FollowSymlinks
Order Allow,Deny
Allow from All
</Directory>
<Directory /Library/WebServer/Documents/sql-ledger/users>
Order Deny,Allow
Deny from All
</Directory>
----------

To have apache read the new file, go to Terminal app and restart apache:

sudo apachectl restart

Last step is to alter a line in /Library/WebServer/Documents/sql-ledger/sql-ledger.conf. We want to tell sql-ledger where to find Latex on your Mac. That is located in /usr/texbin

Edit the file sql-ledger.conf in the sql-ledger directory, and edit the line so the line looks like:

# if the server can't find gzip, latex, dvips or pdflatex, add the path
$ENV{PATH} .= ":/usr/texbin";

Step 3
Start sql-ledger with: http://localhost/sql-ledger/admin.pl
Give an admin password and setup a dataset.
Default, sql-ledger uses the user sql-ledger for database access. Change this into postgres, if you have not setup any other users for postgres. The password for user postgres is the root password of your Mac. For host, type, localhost.

I suggest that if everything is working, Google into how to setup a sql-leder user for postgres. 

Your done! Login with user admin and the new password you created at: http://localhost/sql-ledger/login.pl

Under HR, you can setup the new users and their privileges. See install instructions at the sql-ledger website for more details.







Tuesday, February 14, 2012

Short Demo on YouTube

Short demo of how to use Pentaho Reporting for making reports on Sql-Ledger.




Tuesday, February 7, 2012

Installing The Pentaho Bi-server

When you have created several reports, it is time to share them with your team. For that we have to install the Pentaho Bi-server. Download Pentaho bi-server , unzip and place the postgres driver postgresql-9.1-901.jdbc3.jar in /biserver-ce/tomcat/lib. 
To tune the bi-server to work also with iPhone, read this and follow the instructions. 
To tune the bi-server, not to give the evaluation login link, see picture below, read this, and follow the instructions









Change biserver-ce/pentaho-solutions/system/publisher_config.xml and add pentaho as publisher password (or what you prefer..)
<publisher-config>
<publisher-password>pentaho</publisher-password>
</publisher-config>

To start the bi-server, on the Mac, first make the *.sh files in the directory biserver-ce-3 and tomcat/bin executable by doing a chmod +x to the files. Goto directory biserver-ce-3 and

sudo chmod +x *.sh

Same as in the directory biserver-ce-3/tomcat/bin Goto this directory and again

sudo chmod +x *.sh

And finally to start it, goto the directory biserver-ce-3:

sudo ./start-pentaho.sh 

To start the administration console go to the directory, administration-console and 

sudo chmod + x *.sh

then start it by 

sudo ./start-pac.sh

The bi-server is now setup for localhost on your Mac. You can find them now on localhost:8080 and the admin console on localhost:8099.


First go to localhost:8099 and login using credentials: admin password and make a user with admin rights.

If you want run it on your server, read this in Dutch (or this in a language you can read, (google translate) But first, keep on reading this blog, below, what are (better) setting....Below is the setup for Debian.

#Pentaho has it's own tomcat installation, but no Java Environment. 
#You have to install this separately. We used Sun version 1.6. 

#Debian:

aptitude install sun-java6-jdk sun-java6-jre
aptitude install sun-java6-plugin sun-java6-bin
aptitude install libcommons-beanutils-java libcommons-collections-java libcommons-collections3-java libcommons-daemon-java
aptitude install libcommons-io-java libcommons-launcher-java libcommons-logging-java libcommons-modeler-java
aptitude install libcommons-pool-java libcommons-validator-java

# Perl also needs a specific CPAN module(s):

perl -MCPAN -e "install Text::Iconv"

# On the postgresql server, add a line in the file /etc/postgresql/*/main/pg_hba.conf 
# to give access to the server where pentaho is running so that pentaho has access to the

# Postgres database it has to use.

host    <pg_username>            <pg_database>         <IP-pentaho-server>/32    md5

# In the weblink they install the software, in the home dir of root. 
# This is a NO! NO!
# Choose a subdir under /var/www/ (standard Apache dir) or a subdir under /home/. 
# In this example /home/pentaho/.

# A comment for the user where pentaho will be running under. 
# In the weblink they use root, but this is also a NO! NO!
# Create a separate user for pentaho:

useradd -u 10000 -d /home/pentaho -m pentaho

# Install pentaho now according to the weblink. 

chown -R pentaho.pentaho /home/pentaho

# Finally, the startup we do, is also different from the weblink:

vi /etc/rc.local
 su - pentaho -c "/home/pentaho/startup.sh start" >/dev/null 2>&1

vi /home/pentaho/startup.sh
#!/bin/bash
#
# Only run as user pentaho

[ $(id -u) -ne 10000 ] && exit 1

# Set the paths according to your distro.

export JAVA_HOME="/usr/lib/jvm/java-6-sun"
export JRE_HOME="/usr/lib/jvm/java-6-sun/jre"
export PATH=$PATH:$JAVA_HOME/bin

case $1 in
       start)
               /home/pentaho/biserver-ce/start-pentaho.sh &
               cd /home/pentaho/administration-console
               /home/pentaho/administration-console/start-pac.sh &
               ;;
       stop)
               /home/pentaho/biserver-ce/stop-pentaho.sh &
               cd /home/pentaho/administration-console
               /home/pentaho/administration-console/stop-pac.sh &
               ;;
       restart)
               $0 stop
               $0 start
               ;;
       *)
               echo "usage: $0 <start|stop|restart>"
               ;;
esac