API Question

Discussion for TimeTrex open source community developers.
Locked
rocknbrot
Posts: 23
Joined: Wed Dec 28, 2011 1:15 am

API Question

Post by rocknbrot »

can you help me with api methods and how they are feeded?
a few things i found out with trying/guessing/reading APIxxxx.class.php, but i got stuck now with the soap report api

$report_obj = new TimeTrexClientAPI( 'Report' );

$result = report_obj->getReport( how is this $config array looking like? , which $formats are available?)

....
....

Is there some general syntax help with API parameters?
The TimeTrex API Manual doesnt tell anything related to this, at least i found nothing


Thanks in Advance!


Sascha Kotanko
shaunw
Posts: 7839
Joined: Tue Sep 19, 2006 2:22 pm

Re: API Question

Post by shaunw »

Download TimeTrex v5.1.0 and take a look in the tools/export/export_report.php script, the easiest method is to create a saved report in the TimeTrex user interface then grab that config and pass it into the report. You can also use this method to determine the format of the $config array if you want to customize it further, but keep in mind it can be different for each report.

If you just want to grab a basic report out of TimeTrex, calling this export_report.php script from the command line is your best bet.
rocknbrot
Posts: 23
Joined: Wed Dec 28, 2011 1:15 am

Re: API Question

Post by rocknbrot »

Hi Shaun!

Thank you for your quick response
This file i missed before :)
It answers many questions, about how the Timetrex Client API works
but now I have one new:
How can I filter soap api data by the field 'date_stamp' with php

I tried this with holidays:

Code: Select all

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

/*
 Global variables
*/
$TIMETREX_URL = '......../soap/api.php';
$TIMETREX_USERNAME = 'validuser';
$TIMETREX_PASSWORD = 'validpwd';

$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<br>\n";



$holiday_obj = new TimeTrexClientAPI( 'Holiday' );

$holiday_config =  array(
				//'date_stamp' => '30.5.2013',
				'filter_data' => array(
						//'id' => '3',
						//'date_stamp' => strtotime('20120530'),
						'date_stamp' => '2013-May-30',
						//'name' => 'Fronleichnam',
				
				)
	);

$result = $holiday_obj->getHoliday($holiday_config);

$holiday_data = $result->getResult();

print_r($holiday_data);


?>
This always returns the whole holiday list. I tried many date formats, but none of them is working
Can you tell me which is the correct format?
shaunw
Posts: 7839
Joined: Tue Sep 19, 2006 2:22 pm

Re: API Question

Post by shaunw »

It requires a range search, try this:

Code: Select all

$holiday_config =  array(
            'filter_data' => array(
                  'start_date' => strtotime('20120530'),
                  'end_date' =>  strtotime('20120530'),
            )
   );
rocknbrot
Posts: 23
Joined: Wed Dec 28, 2011 1:15 am

Re: API Question

Post by rocknbrot »

works perfectly! thx

i already have the next one,it doesn't really belong to the api forum, but anyway:
is there a safe way to clean up the postgres database from deleted entries?
because of testing,adding/deleting all the time the db grows very quick => can i simply remove all items with "deleted=1"?
shaunw
Posts: 7839
Joined: Tue Sep 19, 2006 2:22 pm

Re: API Question

Post by shaunw »

TimeTrex automatically cleans them up for you, it just takes a little while.
rocknbrot
Posts: 23
Joined: Wed Dec 28, 2011 1:15 am

Re: API Question

Post by rocknbrot »

ah ok
im just too impatient :)
rocknbrot
Posts: 23
Joined: Wed Dec 28, 2011 1:15 am

Re: API Question

Post by rocknbrot »

now i got another issue with absences
can i update (and override) absences with the api?
i thought that has to be done with accruals
so that i can first get one by date (the range search doesn't work here as with holidays):

Code: Select all

		$accrual_get_config= array(		
							'filter_data' => array(
								//'time_stamp' => strtotime('20121108'),
								'date_stamp' => '20121108', 
								//'start_date' => strtotime('20121108'),
								//'end_date' => strtotime('20121108')',
								'user_id' => '5',
								'type_id' => '20',
								'accrual_policy_id' => '2',
								)
		);
.....and then update its accrual policy id

Code: Select all

		$accrual_set_config= array(
								'id' => 2206,
								'accrual_policy_id' => '4',
		);
..... or am i completely wrong?
shaunw
Posts: 7839
Joined: Tue Sep 19, 2006 2:22 pm

Re: API Question

Post by shaunw »

You can do anything you want through the API, but what is it that you actually trying to achieve? This seems like a strange request.
rocknbrot
Posts: 23
Joined: Wed Dec 28, 2011 1:15 am

Re: API Question

Post by rocknbrot »

Hi Shaun!

Yes, it maybe looks a bit strange
But what i want to achieve in our company is, that absences are automatically deducted by a daily evening cron job, depending on how an employee punched in or out
So i made an "other-field" called Absence-Info
for example if a user punches out with the info "out vacation" the job changes the schedule starting on the following day from "working" to "absent" and the absence-policy from "overtime pool" (the standard policy) to "vacation" until the user punches again. Of course with exceptions like weekend or holidays. This is what I have already done.

but we also have absences like consultation. In this case not the whole schedule should be changed to absent, because the employee is working that day
only the normal absence-policy "overtime pool" should be set to "override" and changed to "consultation"

I found no other way to achieve this behaviour than doing it myself
... but in general it's a very cool thing that you can adapt nearly everything with this api
shaunw
Posts: 7839
Joined: Tue Sep 19, 2006 2:22 pm

Re: API Question

Post by shaunw »

I'm confused by your use of accruals and absences. From what you described you want to manipulate the absences, not accruals. Or possibly just schedules and not absences or accruals at all.
rocknbrot
Posts: 23
Joined: Wed Dec 28, 2011 1:15 am

Re: API Question

Post by rocknbrot »

yes i want to change absences. but as i found only APIAbsencePolicy and not APIAbsence, i thought Accruals would do the same. If I override the absence manually in the timesheet, also an, for example "consultation" accrual with this amount is created, so maybe it works vice versa....
shaunw
Posts: 7839
Joined: Tue Sep 19, 2006 2:22 pm

Re: API Question

Post by shaunw »

Modifying accruals definitely does not do the same thing.

It sounds like you just want to modify the schedules, and change the absence policy assigned with a scheduled shift. Doing this will automatically enter an absence on the employees timesheet as well.
rocknbrot
Posts: 23
Joined: Wed Dec 28, 2011 1:15 am

Re: API Question

Post by rocknbrot »

yesssss, thats what i wanted :)
its a bit tricky because in the interface the absence-policy field is hidden when status working...

anyway, have a nice weekend
Locked