<?php

require_once dirname(__FILE__) . '/../../../src/PHPSQLParser.php';
require_once dirname(__FILE__) . '/../../../src/PHPSQLCreator.php';
require_once dirname(__FILE__) . '/../../test-more.php';

$sql = "SELECT dbo.fn_GetDayOfWeekMonIs0(DATEADD(SECOND, -21600, calls_cstm.date_logged_c)) AS 'Date'
FROM calls
LEFT JOIN calls_cstm ON calls.id = calls_cstm.id_c
LEFT JOIN users users0 ON calls.assigned_user_id = users0.id
LEFT JOIN contacts contacts2 ON calls.contact_id = contacts2.id
WHERE calls.deleted = 0
	AND (
		(dbo.fn_GetDayOfWeekMonIs0(DATEADD(SECOND, 0, calls_cstm.date_logged_c)) IN ('4'))
		AND DATENAME(YEAR, DATEADD(SECOND, 0, calls_cstm.date_logged_c)) = '2013'
		AND (DATEPART(MONTH, DATEADD(SECOND, 0, calls_cstm.date_logged_c)) IN ('10'))
		)
GROUP BY dbo.fn_GetDayOfWeekMonIs0(DATEADD(SECOND, -21600, calls_cstm.date_logged_c))
ORDER BY dbo.fn_GetDayOfWeekMonIs0(DATEADD(SECOND, -21600, calls_cstm.date_logged_c)) ASC";

$parser = new PHPSQLParser($sql);
$creator = new PHPSQLCreator($parser->parsed);
$created = $creator->created;
$expected = getExpectedValue(dirname(__FILE__), 'issue106.sql', false);
ok($created === $expected, 'function within group-by');

?>
