7shifts integrated time clock

#1

So I have integrated 7 shifts into SambaPOS and using it along the time clock Emre had built recently. It works really well I will share it with you here.

For those wondering about the time clock here it is: Time Clock.zip (10.4 KB)

This is a configuration task you will import using DB Tools in Settings. Once imported you go to Settings > Configuration Tasks and click on Time Clock.

3 Likes
#2

First thing you will need is the script:
You can ignore Method 2 they removed that method from their api because they want it for internal use only (Bastards) anyway.

var apikey = 'YOUR API KEY HERE'; 
var method1 = 'locations';
var method2 = 'time_punches/punch';
var method3 = 'time_punches';
var method4 = 'users';

function getuser(pincode) {
  var getusers = web.PostData('https://api.7shifts.com/v1/'+method4+'/','',''+apikey+'','');
  var user = JSON.parse(getusers);
  for(var i=0; i<user.data.length; i++){
   if(user.data[i].user.employee_id == pincode)
   return user.data[i].user.id;
   }  
}

function getlocation() {
  var location = web.PostData('https://api.7shifts.com/v1/locations','',''+apikey+'','');
  var getlocations = JSON.parse(location);
  return getlocations.data[0].location.id;
}

function punch(pincode,timein,timeout) {
  var eid = getuser(pincode);
  var loc = getlocation();
  var execpunch = web.PostJson('https://api.7shifts.com/v1/'+method3+'/','{ "time_punch": { "user_id": '+eid+', "location_id": '+loc+', "clocked_in": "'+timein+'", "clocked_out": "'+timeout+'" } }',''+apikey+'','');
  var getpid = JSON.parse(execpunch);
  return getpid.data.time_punch.id;
}

5 Likes
#3

All you need to do is create an Execute Script action:

image

Add the action as the first one in this Rule:

Put this in for function variable:

7shiftcreate.punch('{REPORT SQL DETAILS:SELECT PinCode FROM Users WHERE Name ='{SETTING:CURRENTUSER}':F.PinCode}','[=FD(ADS('{REPORT OPEN TASK DETAILS:=FD([T.StartDate],'yyyy-MM-dd'),T.StartTime,:(TSC.User={SETTING:CURRENTUSER}) and (TST=Punch):{0} {1}}',+18000),'yyyy-MM-dd HH:mm:ss')]','[=FD(ADS('{DATE:yyyy-MM-dd HH:mm:ss}',+18000),'yyyy-MM-dd HH:mm:ss')]')

Now what is important is in that script call you have to offset the timezone difference with yours and 7shifts servers they refuse to fix that issue. In my case i had a +5 hour difference so you will see I added 18000 seconds. Just replace the 18000 with whatever offset you need from their servers.

3 Likes
#4

That is it really other than opening 7 shifts account and getting your API key.

Whatever Pin you set for users in SambaPOS is the pin that needs to be set for 7shifts.

2 Likes
#5

What this does is it records the punch when the user clocks out for the day. The reason for this is because of how the Create method in 7shifts API works. You want to do the punch in and out at the same time or else its even more complicated with needing to use 2 calls one to create and one to update.

It uses the task from the SambaPOS time clock for the punch in time and then just uses current date/time for punch out.

2 Likes
#6

Next up is how to sync SambaPOS sales into 7shifts for forecasting. They recently opened up the API for that.

2 Likes
#7

Eventually I will spend the time to completely integrate it where SambaPOS reads punches from 7shifts for reports etc and it will be fully synced even when editing punches from inside SambaPOS. I would also like to fully sync the scheduling portion of it so we can do some cool automation in SambaPOS based on employee schedules. Like not allowing someone to clock in or use the pos if they are not scheduled etc.

4 Likes
#8

Thank you @Jesse for sharing your integration.

1 Like