Time Clock & Punch Editor - Custom Navigation Flow: Uses Employee Entities not Users


#216

I put comments on the Arrays to remind myself key things like for example the format required for start and end time in schedule api.

BTW you can do anything with the open source community version that the pro versions have they just wont explain to you how to do it. The only difference is the prebuilt addons like Quick punch, and additional modules. All of that can be added to the open source version as well by using the API. Just dont ask them how because they will just say purchase pro version.


#217

Wow great advice, thanks bud. One of the main reasons I went pro was for the mobile app in which im pretty sure isn’t supported in the community edition. I love the idea of being able to create and view the schedule from your phone. I think this will be a great selling point for us with samba.


#218

Community version can definitely support a mobile app you just would have to code it yourself. The mobile app they created for the Pro version uses the API to do all of that. If you dont mind me asking what do they charge for pro now they took that information off their main website.


#219

I was wondering the same thing :confused: I never asked them on pricing

Yeah that probably sounds like a better idea. We have one developer working part time right now trying to learn samba. Soon as he gets it all down well hire a few more to start developing an app for us. Are you familiar with the “Shyft” mobile app? We are striving for something like that. Emplyees can make a shift available for another employee to pick up, with the managers consent. I think this would stream line scheduling a lot.


#220

I am playing with the mobile app now and their demo.

EDIT: So its kind of uninspiring, it wont let you create schedules, it is only for the employee to Clock in or Out, View schedule, or Submit a Time Off request. No admin functions.


#222

Hey can I ask you for a quick favor if you find the time. If you could just give me a few of your samba rules and actions and other configurations I need to get started with the time trex time clock id really appreciate it. Im finally ready to start doing some work on it but dont know where to start exactly. I dont want to follow your other setups on the forum because you mentioned you redid it and some of that may be outdated.

I got your scripts you posted above but dont know where to start with them to be honest.

Thanks for your time as always :slight_smile:


#223

Have you installed timetrex on the server? Is it up and running? I will give you the most up to date scripts and show you how to test them before you start SambaPOS side. First we need to make sure they work.


#224

I was considering using the cloud hosted version but now that I think about it the free edition can do just as much ill just go with that route now. Ill get it installed and setup in the next hour.

Thanks


#225

So here is the most utd script. Edit the username and password to match your administrator account save it as punch.php place it inside your TimeTrex/API/Soap folder

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

    $api_session = new TimeTrexClientAPI();
    $api_session->Login( $TIMETREX_USERNAME, $TIMETREX_PASSWORD );
    if ( $TIMETREX_SESSION_ID == FALSE ) {
       echo "Login Failed!
    \n";
       exit;
    }
    echo "Session ID: $TIMETREX_SESSION_ID
    \n";

    $punch_obj = new TimeTrexClientAPI( 'Punch' );

    $punch_data = array(
            'user_id'  => $_GET["user"],
            'station_id' => 1,
            'type_id' => 10,
            'status_id' => $_GET["status"], //PunchIn=10 PunchOut=20
            'created_by_id' => $_GET["user"],
            'time_stamp' => time()

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

    ?>

Once you have timetrex running and you have built this file and put it in correct directory we can test it. Create a user in timetrex and be sure they are not admin and have punch in/out ability.


#226

TimeTrex will assign a user_id for each employee you add. We need that number to punch them with. We can use this script in SambaPOS to find the user_id based on username and insert it into the punch script.

So in a browser it would look like this:

http://localhost:8085/api/soap/punch.php?user=2&status=10

That would punch user_id of 2 with status of 10 which as you see I documented in the script means punch in. 20 would be punch out.

Here is the SambaPOS script to get the user_id based off employee entity or username depending on how you plan to build it.

function punch(name,status){
    var u = 'http://localhost:8085/api/json/report.php?user='+name;
    var data = web.Download(u);
    var result = JSON.parse(data);
    var userid = result.id;

And here is the full script that executes the punch.

function punch(name,status){
    var u = 'http://localhost:8085/api/json/report.php?user='+name;
    var data = web.Download(u);
    var result = JSON.parse(data);
    var userid = result.id;

    if (status == 'PunchIn'){
        var status = 10;
    }
    else if (status == 'PunchOut'){
        var status = 20;
    }

    var url = 'http://localhost:8085/api/soap/punch.php?user='+userid+'&status='+status;
    web.Download(url);
}

#227

I built mine to manually choose punch type so I can control in and out punches. You could choose to not use that and just allow TimeTrex to autopunch…


#228

You can build your SambaPOS automation any way you like honestly you only need to feed the script 2 things, a username and punch status.


#229

Here is script I used to add users to TimeTrex… I never fully finished it but it does work. TimeTrex allows a LOT of information to be stored for each employee and I tried to incorporate as much of that as possible into it.

<?php
require_once('../../classes/modules/api/client/TimeTrexClientAPI.class.php');

/*
 Global variables
*/
$TIMETREX_URL = 'http://localhost:8085/api/soap/api.php';
$TIMETREX_USERNAME = 'USERNAME';
$TIMETREX_PASSWORD = 'PASSWORD';

$api_session = new TimeTrexClientAPI();
$api_session->Login( $TIMETREX_USERNAME, $TIMETREX_PASSWORD );
if ( $TIMETREX_SESSION_ID == FALSE ) {
    echo "Login Failed!<br>\n";
    exit;
}
    echo "Session ID: $TIMETREX_SESSION_ID
    \n";

$user_obj = new TimeTrexClientAPI( 'User' );

$user_data = array(
                    'status_id' => 10, //Active
                    'policy_group_id' => 2,
                    'sex_id' => $_GET["sex_id"], //Male=10 Female=20
                    'permission_control_id' => 3,
                    'province' => AR,
                    'country' => US,
                    'work_phone' => 8707993980,
                    'hire_date' => $_GET["hire_date"], //dd-mm-yyyy format
                    'pay_period_schedule_id' => 2,
                    'currency_id' => 2, //USD
                    'employee_number' => $_GET["employee_number"],
                    'first_name' => $_GET["firstname"],
                    'last_name' => $_GET["lastname"],
                    'user_name' => $_GET["username"],
                    'password' => $_GET["password"],
                    'address1' => $_GET["address"],
                    'city' => $_GET["city"],
                    'postal_code' => $_GET["zipcode"],
                    'home_phone' => $_GET["homephone"],
                    'mobile_phone' => $_GET["mobilephone"],
                    'home_email' => $_GET["email"],
                    'birth_date' => $_GET["birthdate"], // dd-mm-yyyy format
                    'sin' => $_GET["SSN"]
                    );

$result = $user_obj->setUser( $user_data );
if ( $result->isValid() === TRUE ) {
    echo "Employee added successfully.<br>\n";
    $insert_id = $result->getResult(); //Get employees new ID on success.
} else {
    echo "Employee save failed.<br>\n";
    print $result; //Show error messages
}


?>

#230

Great thanks. Do you mind sharing a little bit of how your firing all the scripts. Im not familiar with scripts yet to be honest so anything helps. Maybe a little bit of your flow on sambaPOS side, just so I have something to learn with. Only if you have the time, ill try to figure it out on my own if your busy, no worries.

Thanks.


#231

Here is one method that uses SambaPOS users

CommandValue contains the punch type which is 10 for in or 20 for out. This was simple clock in and clock out button on a custom entity screen. It reads CURRENTUSER to determine who is punching. So sambapos user is named same as the username they use in TimeTrex.


#232

So its possible to get time trex integrated using sambaPOS users? I wasn’t aware. Do you recommend using entities instead?

I actually think entity users might be easier since I can automated creating entities when they hire new workers which happens alot around our area since no workers are dependable.

Can you please show me a simple setup with entities if you have it handy. I cant really figure out how exactly your mapping user entities to tickets.


#233

Either way works just fine. I recommend Entities though so you can have more control over it. For example you could create a custom screen to add employees… we have all API stuff already to add Entities… With users we do not yet have that capability so you would need to manually create the user and then manually create the user in TimeTrex.

The custom Entity Screen you can use SambaPOS API to create Employee entity and also simultaneously create the Time Trex user as well meaning only needed to create one employee and your done.

It is also easier to do more advanced reporting with Entities.

Another advantage to Entities is the built in accounting etc you can link with them. Creating your own Employee accounts setup.


#234

I agree thats the method id like to setup then. Are there any examples I can learn for setting up user entities. Just something to start with. I cant really wrap my head around how you attach user entities to tickets.


#235

Well to be honest there are various approaches but my favorite is to only use 2 or 3 actual users for the POS. Mine for example has Admin, Manager, Employee users, it stays logged into Employee 99% of the time.

You could create your own login screen that the system defaults too but I prefer to just make my employees login when they press POS button. They use simple 4 digit pin or badge scan/swipe. I use various rules for assigning them to tickets… basically involves Change Ticket Entity action, Load Entity Action etc.

With new API I plan to try and simplify it and open up better more advanced features I just have not had time to work on it.


#236

So when a ticket is created I would run the action to select user entity? Fair enough ill give it all a try, it doesn’t sound too bad.