0) { $where .= " and project_client_id=$x"; } elseif (isset ($_REQUEST["client_id"])) { $where .= " and project_client_id is null"; } if (($x = $_REQUEST["project_id"] + 0) > 0) { $where .= " and iv_project_id=$x"; } elseif (isset ($_REQUEST["project_id"])) { $where .= " and iv_project_id is null"; } $q = mysql_query (" select *, date_add(iv_starttime,interval iv_duration second) iv_endtime from iv left join project on project_id=iv_project_id left join client on client_id=project_client_id where $where order by iv_starttime desc "); print templator ("iv_top"); while ($row = mysql_fetch_assoc ($q)) { $dollars = ""; $rate = $row["iv_hourly_rate"]; if (!$rate) $rate = $row["project_hourly_rate"]; if (!$rate) $rate = $row["client_hourly_rate"]; if (!$rate) $rate = 100; if ($row["iv_billable"] && $rate) { $dollars = $row["iv_duration"] * $rate / 3600; $row["rate"] = $rate; $row["dollars"] = sprintf ("%.2f", $dollars); } $tot["dollars"] += $dollars; $tot["duration"] += $row["iv_duration"]; if (!$row["iv_invoice_id"]) { $tot["unbilled_dollars"] += $dollars; $tot["unbilled_duration"] += $row["iv_duration"]; } $row["duration"] = s2hms ($row["iv_duration"]); list ($x, $row["endtime"]) = explode (" ", $row["iv_endtime"]); $row["endtime"] = preg_replace ('/:\d\d$/', '', $row["endtime"]); $row["starttime"] = preg_replace ('/:\d\d$/', '', $row["iv_starttime"]); print templator ("iv", $row); } $tot["rate_average"] = floor (3600*$tot["dollars"]/$tot["duration"]); $tot["dollars"] = sprintf ("%.2f", $tot["dollars"]); $tot["duration"] = s2hms ($tot["duration"]); $tot["unbilled_rate_average"] = floor (3600*$tot["unbilled_dollars"]/$tot["unbilled_duration"]); $tot["unbilled_dollars"] = sprintf ("%.2f", $tot["unbilled_dollars"]); $tot["unbilled_duration"] = s2hms ($tot["unbilled_duration"]); print templator ("iv_bottom", $tot); ?>