Skip to content

Instantly share code, notes, and snippets.

@Schrank
Created March 26, 2012 11:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Schrank/2204557 to your computer and use it in GitHub Desktop.
Save Schrank/2204557 to your computer and use it in GitHub Desktop.
This script imports the ticket-entries from tickspot, changes the format to the TimeLog-XML-format (which GrandTotal can read) and prints it out.
<?php
/**
* This script imports the ticket-entries from tickspot, changes the format to the TimeLog-XML-format
* (which GrandTotal can read) and prints it out.
*
* Tickspot only saves hours, so the day starts at 9:30 and the entries are concatenated. No rest between
* or something.
*
* If this code is useful for you, use it! If you earn money with it, and you want to say thank you:
* https://flattr.com/thing/424316/Fabianikono-on-Twitter
*/
$mail = "mail@example.com";
$pass = "password";
$PricePerHour = 120;
$calendar = "Arbeitszeiten";
$client = 'Company Name';
$name = 'Your Name';
$start = date('Y-m-') . '01';
$end = date('Y-m-t');
if (isset($_GET['month']) && isset($_GET['year'])) {
$start = $_GET['year'] . '-' . $_GET['month'] . '-01';
}
if (isset($_GET['month']) && isset($_GET['year'])) {
$days = date('t', mktime(0, 0, 0, $_GET['month'], 1, $_GET['year']));
$end = $_GET['year'] . '-' . $_GET['month'] . $days;
}
$api = "https://COMPANY.tickspot.com/api/entries?email=$mail&password=$pass&start_date=$start&end_date=$end";
$output = file_get_contents($api);
$simpleXml = simplexml_load_string($output);
header('Content-type: application/xml');
$xml = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<timelog version="4">
<items>';
$datetimeWalker = null;
foreach ($simpleXml->entry as $entry) {
if ($datetimeWalker === null || $datetimeWalker->format('Y-m-d') != $entry->date) {
$datetimeWalker = new DateTime($entry->date . 'T9:30');
}
$quantity = $entry->hours * 3600;
$cost = $entry->hours * $PricePerHour;
list($hours, $mins) = explode('.', $entry->hours);
$mins *= 60 / 100;
$interval = new DateInterval('PT' . $hours . 'H' . $mins . 'M');
$timestamp = new DateTime($entry->updated_at);
$xml .= <<<XML
<item type="time" status="none">
<uid>{$entry->id}</uid>
<timestamp>{$timestamp->format('Y-m-d\Th:i:sO')}</timestamp>
<calendar>$calendar</calendar>
<client>$client</client>
<project>{$entry->project_name}</project>
<category>Standard</category>
<start>{$datetimeWalker->format('Y-m-d\Th:i:sO')}</start>
<end>{$datetimeWalker->add($interval)->format('Y-m-d\Th:i:sO')}</end>
<quantity unit="seconds">$quantity</quantity>
<rate>$pricePerHour</rate>
<cost>$cost</cost>
<creator>$name</creator>
</item>
XML;
}
$xml .= '
</items>
</timelog>';
echo $xml;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment