Skip to main content

Transfer of Attendance from primaERP

How to transfer attendance data from primaERP to Flexi

Written by Lenka Haringerová

Do you manage a large number of employees with irregular employment and hourly wages in ABRA Flexi? Would you like to avoid manually entering worked hours when processing payroll? Let your employees track their working time in an attendance system and automatically import that data into ABRA Flexi. For time tracking, you can use the handy ABRA primaERP cloud application.

The benefits of tracking attendance in ABRA primaERP are described on the Attendance module page. The following sections will show you how to transfer the resulting figures into ABRA Flexi using the REST API.

Retrieving the required payroll components from ABRA Flexi

First, you need to retrieve the payroll components from Flexi that you intend to update. To write data back, you need the IDs that Flexi has assigned to those components. The process can be simplified by adding the required ID to the data retrieved from Flexi and then sending the data back.

You retrieve the required payroll components from the mzdova-slozka record in Flexi. You can obtain the data you need by applying a simple filter. You will need to retrieve components for a specific year and month, as well as only the HOURLY WAGE components. The Flexi API query will look something like this:

GET /mzdova-slozka/(cisMzdSloz = 'code:HODINOVÁ MZDA' and rok = 2017 and mesic = 1).json?detail=custom:id,osoba(osbCis,jmeno,prijmeni,titul),hodiny,zmenaCasu,zmenaCastMzd,castkaHod,castMzd&includes=/mzdova-slozka/osoba&limit=0

This query returns all HOURLY WAGE components for January 2017. The result will contain all the fields you need in order to update these components without any issues.

The result returned from Flexi will look something like this:

{    "winstrom": {        "@version": "1.0",        "mzdova-slozka": [            {                "id": "13",                "osoba": [                    {                        "id": "1",                        "osbCis": "A02200",                        "jmeno": "K\u00e1ja",                        "prijmeni": "z Norska",                        "titul": ""                    }                ],                "hodiny": "0.0",                "zmenaCasu": "false",                "zmenaCastMzd": "false",                "castkaHod": "800.0",                "castMzd": "0.0"            }        ]    }}

Retrieving data from primaERP

Once you have all the necessary data from Flexi, you can retrieve data from the attendance system. We will demonstrate how to retrieve data from primaERP, which has an API interface — although this is not strictly required. In this step, you could also load, for example, an Excel spreadsheet containing attendance records. The only important thing is that you are able to identify each employee and know how many hours they have worked.

In the primaERP API, you need to make a request to the URL

GET https://kbel.api.primaerp.com/v1/time/timerecords/summary.json?summary=user/position;sum(duration)&$filter=start ge datetime'2017-05-01T00:00:00.000Z' and stop lt datetime'2017-06-01T00:00:00.000Z'&token=9c11cea8-c3b3-4232-bfbb-f8acefce2f5a

You will receive data in a format similar to this:

[ { "key": "A02200", "summaries": [ { "name": "sum(duration)", "value": "232777000" } ] } ]

The query uses aggregation on the duration property (task duration). The employee's position serves as the identifier and is used for the personnel number, which allows the data from primaERP to be matched with the data from Flexi. The query also applies a time period filter, which returns only tasks that started and ended within the monitored period.

In the data returned by primaERP, the key is the personnel number from Flexi, along with the aggregated duration of individual tasks. This aggregation represents the total time in milliseconds. The hours to be recorded in the HOURLY WAGE component are therefore calculated using the formula

hodiny = duration / 1000 / 60 / 60

In our example, this equals 64.66 hours. You may of course round the value — and most likely will — but that is up to each user. Flexi allows values to be entered in the component field with a precision of two decimal places.

Processing data and writing it back to ABRA Flexi

You now need to process the retrieved data and write it back to Flexi. We will iterate through the individual payroll components retrieved from Flexi and progressively fill them in with data from primaERP.

Each payroll component contains a unique identifier, which is the employee's personnel number. You will use this number to look up the correct aggregated value in the primaERP data. Once found, you convert the milliseconds to hours and write the result to the hodiny field. In the castMzd field, you enter the product of the hours worked and the value in the castkaHod field, which contains the employee's hourly wage. Finally, you must set the zmenaCasu and zmenaCastMzd fields to true instead of false, so that Flexi does not override the entered values based on the working time fund.

The data is ready and you can send it back to Flexi. This is already a fairly familiar process for regular readers of our posts. Just to confirm, the URL to which the data will be written is

PUT /mzdova-slozka.json

A few closing remarks

If a company has even just a few employees on hourly wages, we recommend building a similar tool. It does not really matter whether the data is loaded from primaERP or another attendance system. A simple Excel spreadsheet can also be used — as long as it contains columns for the personnel number and hours worked, that should be sufficient.

If you build such a bridge, your payroll accountant will surely thank you for days after every pay run. After all, who would want to manually enter worked hours for every single employee over and over again.

Did this answer your question?