TimeTrex integration: Moved discussion from previous post

I tried putting in the action “e:[:BATfile]” and using {:CURRENTUSER}.bat still wont find the file.

So for now I think ill use my workaround. It is working just dont like having to call so many .bat files and scripts seems overkill.

@Jesse, I experienced the same thing… {:CURRENTUSER} seems to be blank. However, after I’m finished altering the Rules/Actions, if I logout and log back in, then try the automation command, the setting is indeed populated!

Thought I would update you on my progress… I have it working perfectly with Samba right now. Its rather complex how I set it up but its working great. My only issues now are with TimeTrex API getting it to behave correctly. Its been frustrating because its perfectly capable of doing what I want but I cannot get any support from the developers because they want me to buy their quick punch solution they implemented.

It is working fine except it is making a double punch when clocking out… ie its imediately clocking back in on clock out. Its a problem in my API code i just cant pinpoint why its looping back to clock in.

That aside here is how I finally got the integration to work.

First here is how it works:

Here is how I got it to work.
I found a script someone on their forums used to make a punch station from a Raspberry Pi, monitor, scanner.
I modified the script to hide most of the terminal functions because I am not using an actual terminal.
I made a batch file to call the cmd to execute the script.
I converted the batch file to an exe so I can kill the process and made it invisible using the following code: and saving it as a vbs file

Set WshShell = CreateObject(“WScript.Shell”)
WshShell.Run chr(34) & “C:\Batch Files\syncfiles.bat” & Chr(34), 0
Set WshShell = Nothing

I call the vbs file when a user logs in to SambaPOS. It launches a specific VBS file with their login using the [:USERNAME]

The cmd is now running in the background invisible only way to see it is ctrl alt delete and view process.

When the user hits clock in it calls a batch file that loads a hotkey script telling it to press an assigned key within the specific cmd terminal that is running in background. This triggers the automatic clock function in my timeclock script and will clock them in and will do nothing if already clocked in.

When they log out of samba it loads another hidden batch file that kills the hidden cmd process so it doesnt fill the computer with alot of running processes for no reason.

They would follow the same process to clock out.


Ideally eventually once I get better understanding of TimeTrex API I will integrate it with Samba using just the API and eliminate the crazy batch/vbs file method.

UPDATE: I finally got my TimeTrex API code correct now I can start eliminating my batch files and try to integrate with a leaner package.

If interested (This is for TimeTrex payroll management software) the script would be punch.php and it just needs to be called from a web browser to clock someone in or out. You have to make a copy of the script for each employee and put their login/password into the script.

Once I get this ironed out to a smooth integration with Samba ill post a quick tutorial if anyone is interested in this Open Source Time Clock/payroll solution.

Here is the code for punch.php

<?php require_once('../../classes/modules/api/client/TimeTrexClientAPI.class.php'); /*  Global variables */ $TIMETREX_URL = 'http://localhost/api/soap/api.php'; $TIMETREX_USERNAME = 'login'; $TIMETREX_PASSWORD = 'password';

$api_session = new TimeTrexClientAPI();
   echo “Login Failed!

$punch_obj = new TimeTrexClientAPI( ‘Punch’ );

$punch_data = array(
        ‘user_id’ => 4, //Active
        ‘station_id’ => 1,
        ‘type_id’ => 10,
      //‘status_id’ => 20, //status type of in 10 , out 20
        //‘created_by’ => 1,
        ‘time_stamp’ => time()

$result = $punch_obj->setPunch( $punch_data );
if ( $result->isValid() === TRUE ) {
   echo “Punch added successfully.
   $insert_id = $result->getResult(); //Get punch new ID on success.
} else {
   echo “Punch save failed.
   print $result; //Show error messages
}catch(Exception $e){
   echo $e->getMessage();


With this code I can eliminate the requirement of the CMD as its just a basic clock and not a hack of a punch station as I was using. This can can be called from the web browser and it will make the employee punch.

So basically now I just need to get some rules setup to map this script to my automation command buttons and eliminate all this batch file mess.

It took me almost 8 solid hours today of reading through their API to finally type this script up from scratch.

@ Kendash


if this punch clock is working than can you please provide clean step by step Guide?


I will but I am waiting until the HTML5 official release so I can give a full integration tutorial. It is working great I will show you a few screenshots of it now.

The reason I am waiting is because the current interface used by TimeTrex is built in Adobe Flex which will not work with the custom entity screen portion of my setup. They are discontinuing the flex interface and are releasing a full HTML5 version of TimeTrex which will be fully compatible with the entity screen and even Mobile Phones VERY soon it has been in beta since February I am anticipating it any day.

I will give a few screenshots of just the punch function and how it is working as if it is part of Samba in a few moments.
A 100% clean tutorial for this setup will take some time. TimeTrex is third party open source software and has to be installed on the server and setup correctly first. All that said it will probably be a week or so before I can get a decent tutorial up because I will be writing it and then posting it so I make sure I cover it all and format it cleanly.

Its rather complex so I dont want to miss anything and I want to make sure everyone can understand it.

In the mean time if you think you may be interested in doing this… It would help if you get some basic knowledge of TimeTrex by installing it and getting familiar with it before you try the integration. Go to http://sourceforge.net/projects/timetrex/files/TimeTrex%20Community%20Edition/v7.3.10/ for the download of the most recent version. If your on a windows machine and your novice with Apache, PHP, and MySQL or PostreSQL I recommend getting the windows installer package it sets up the server and database server automatically for you.

The Time Clock screen I have made:
REMINDER The error with flash is because it is not compatible yet. Remember it will be fully working once HTML5 version releases.

Here is the screenshot of TimeTrex recording the punches:

I will probably switch it so the Clock In and Clock Out buttons are moved to a popup at login and Time Clock Screen will be only for checking schedules, paystubs, requesting time off. Just waiting on more clarification before I do that.

UPDATE: I have now implemented the popup on Log In.
Behavior: When user first logs in for the work period it will show the popup warning them they must be clocked in to use the terminal and it will display the Clock In button. Clicking the button will clock them in and take them to the assigned screen for their role.

Hovering the button turns it Red.