Page 1 of 1

API Question

Posted: Wed Oct 31, 2012 4:18 am
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

Re: API Question

Posted: Wed Oct 31, 2012 8:37 am
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.

Re: API Question

Posted: Sun Nov 04, 2012 11:24 am
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?

Re: API Question

Posted: Sun Nov 04, 2012 12:25 pm
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'),
            )
   );

Re: API Question

Posted: Thu Nov 08, 2012 9:41 am
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"?

Re: API Question

Posted: Thu Nov 08, 2012 10:19 am
by shaunw
TimeTrex automatically cleans them up for you, it just takes a little while.

Re: API Question

Posted: Thu Nov 08, 2012 10:27 am
by rocknbrot
ah ok
im just too impatient :)

Re: API Question

Posted: Fri Nov 09, 2012 1:54 am
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?

Re: API Question

Posted: Fri Nov 09, 2012 9:07 am
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.

Re: API Question

Posted: Fri Nov 09, 2012 10:05 am
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

Re: API Question

Posted: Fri Nov 09, 2012 10:47 am
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.

Re: API Question

Posted: Fri Nov 09, 2012 11:19 am
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....

Re: API Question

Posted: Fri Nov 09, 2012 11:34 am
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.

Re: API Question

Posted: Fri Nov 09, 2012 1:00 pm
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